diff options
Diffstat (limited to 'drivers/ieee1394/sbp2.c')
| -rw-r--r-- | drivers/ieee1394/sbp2.c | 2190 |
1 files changed, 815 insertions, 1375 deletions
diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c index cd156d4e779e..e68b80b7340d 100644 --- a/drivers/ieee1394/sbp2.c +++ b/drivers/ieee1394/sbp2.c | |||
| @@ -29,13 +29,26 @@ | |||
| 29 | * driver. It also registers as a SCSI lower-level driver in order to accept | 29 | * driver. It also registers as a SCSI lower-level driver in order to accept |
| 30 | * SCSI commands for transport using SBP-2. | 30 | * SCSI commands for transport using SBP-2. |
| 31 | * | 31 | * |
| 32 | * You may access any attached SBP-2 storage devices as if they were SCSI | 32 | * You may access any attached SBP-2 (usually storage devices) as regular |
| 33 | * devices (e.g. mount /dev/sda1, fdisk, mkfs, etc.). | 33 | * SCSI devices. E.g. mount /dev/sda1, fdisk, mkfs, etc.. |
| 34 | * | 34 | * |
| 35 | * Current Issues: | 35 | * See http://www.t10.org/drafts.htm#sbp2 for the final draft of the SBP-2 |
| 36 | * specification and for where to purchase the official standard. | ||
| 36 | * | 37 | * |
| 37 | * - Error Handling: SCSI aborts and bus reset requests are handled somewhat | 38 | * TODO: |
| 38 | * but the code needs additional debugging. | 39 | * - look into possible improvements of the SCSI error handlers |
| 40 | * - handle Unit_Characteristics.mgt_ORB_timeout and .ORB_size | ||
| 41 | * - handle Logical_Unit_Number.ordered | ||
| 42 | * - handle src == 1 in status blocks | ||
| 43 | * - reimplement the DMA mapping in absence of physical DMA so that | ||
| 44 | * bus_to_virt is no longer required | ||
| 45 | * - debug the handling of absent physical DMA | ||
| 46 | * - replace CONFIG_IEEE1394_SBP2_PHYS_DMA by automatic detection | ||
| 47 | * (this is easy but depends on the previous two TODO items) | ||
| 48 | * - make the parameter serialize_io configurable per device | ||
| 49 | * - move all requests to fetch agent registers into non-atomic context, | ||
| 50 | * replace all usages of sbp2util_node_write_no_wait by true transactions | ||
| 51 | * Grep for inline FIXME comments below. | ||
| 39 | */ | 52 | */ |
| 40 | 53 | ||
| 41 | #include <linux/blkdev.h> | 54 | #include <linux/blkdev.h> |
| @@ -49,7 +62,6 @@ | |||
| 49 | #include <linux/list.h> | 62 | #include <linux/list.h> |
| 50 | #include <linux/module.h> | 63 | #include <linux/module.h> |
| 51 | #include <linux/moduleparam.h> | 64 | #include <linux/moduleparam.h> |
| 52 | #include <linux/pci.h> | ||
| 53 | #include <linux/slab.h> | 65 | #include <linux/slab.h> |
| 54 | #include <linux/spinlock.h> | 66 | #include <linux/spinlock.h> |
| 55 | #include <linux/stat.h> | 67 | #include <linux/stat.h> |
| @@ -98,20 +110,20 @@ | |||
| 98 | * (probably due to PCI latency/throughput issues with the part). You can | 110 | * (probably due to PCI latency/throughput issues with the part). You can |
| 99 | * bump down the speed if you are running into problems. | 111 | * bump down the speed if you are running into problems. |
| 100 | */ | 112 | */ |
| 101 | static int max_speed = IEEE1394_SPEED_MAX; | 113 | static int sbp2_max_speed = IEEE1394_SPEED_MAX; |
| 102 | module_param(max_speed, int, 0644); | 114 | module_param_named(max_speed, sbp2_max_speed, int, 0644); |
| 103 | MODULE_PARM_DESC(max_speed, "Force max speed (3 = 800mb, 2 = 400mb, 1 = 200mb, 0 = 100mb)"); | 115 | MODULE_PARM_DESC(max_speed, "Force max speed " |
| 116 | "(3 = 800Mb/s, 2 = 400Mb/s, 1 = 200Mb/s, 0 = 100Mb/s)"); | ||
| 104 | 117 | ||
| 105 | /* | 118 | /* |
| 106 | * Set serialize_io to 1 if you'd like only one scsi command sent | 119 | * Set serialize_io to 1 if you'd like only one scsi command sent |
| 107 | * down to us at a time (debugging). This might be necessary for very | 120 | * down to us at a time (debugging). This might be necessary for very |
| 108 | * badly behaved sbp2 devices. | 121 | * badly behaved sbp2 devices. |
| 109 | * | ||
| 110 | * TODO: Make this configurable per device. | ||
| 111 | */ | 122 | */ |
| 112 | static int serialize_io = 1; | 123 | static int sbp2_serialize_io = 1; |
| 113 | module_param(serialize_io, int, 0444); | 124 | module_param_named(serialize_io, sbp2_serialize_io, int, 0444); |
| 114 | MODULE_PARM_DESC(serialize_io, "Serialize I/O coming from scsi drivers (default = 1, faster = 0)"); | 125 | MODULE_PARM_DESC(serialize_io, "Serialize I/O coming from scsi drivers " |
| 126 | "(default = 1, faster = 0)"); | ||
| 115 | 127 | ||
| 116 | /* | 128 | /* |
| 117 | * Bump up max_sectors if you'd like to support very large sized | 129 | * Bump up max_sectors if you'd like to support very large sized |
| @@ -121,10 +133,10 @@ MODULE_PARM_DESC(serialize_io, "Serialize I/O coming from scsi drivers (default | |||
| 121 | * the Oxsemi sbp2 chipsets have no problems supporting very large | 133 | * the Oxsemi sbp2 chipsets have no problems supporting very large |
| 122 | * transfer sizes. | 134 | * transfer sizes. |
| 123 | */ | 135 | */ |
| 124 | static int max_sectors = SBP2_MAX_SECTORS; | 136 | static int sbp2_max_sectors = SBP2_MAX_SECTORS; |
| 125 | module_param(max_sectors, int, 0444); | 137 | module_param_named(max_sectors, sbp2_max_sectors, int, 0444); |
| 126 | MODULE_PARM_DESC(max_sectors, "Change max sectors per I/O supported (default = " | 138 | MODULE_PARM_DESC(max_sectors, "Change max sectors per I/O supported " |
| 127 | __stringify(SBP2_MAX_SECTORS) ")"); | 139 | "(default = " __stringify(SBP2_MAX_SECTORS) ")"); |
| 128 | 140 | ||
| 129 | /* | 141 | /* |
| 130 | * Exclusive login to sbp2 device? In most cases, the sbp2 driver should | 142 | * Exclusive login to sbp2 device? In most cases, the sbp2 driver should |
| @@ -139,9 +151,10 @@ MODULE_PARM_DESC(max_sectors, "Change max sectors per I/O supported (default = " | |||
| 139 | * concurrent logins. Depending on firmware, four or two concurrent logins | 151 | * concurrent logins. Depending on firmware, four or two concurrent logins |
| 140 | * are possible on OXFW911 and newer Oxsemi bridges. | 152 | * are possible on OXFW911 and newer Oxsemi bridges. |
| 141 | */ | 153 | */ |
| 142 | static int exclusive_login = 1; | 154 | static int sbp2_exclusive_login = 1; |
| 143 | module_param(exclusive_login, int, 0644); | 155 | module_param_named(exclusive_login, sbp2_exclusive_login, int, 0644); |
| 144 | MODULE_PARM_DESC(exclusive_login, "Exclusive login to sbp2 device (default = 1)"); | 156 | MODULE_PARM_DESC(exclusive_login, "Exclusive login to sbp2 device " |
| 157 | "(default = 1)"); | ||
| 145 | 158 | ||
| 146 | /* | 159 | /* |
| 147 | * If any of the following workarounds is required for your device to work, | 160 | * If any of the following workarounds is required for your device to work, |
| @@ -179,123 +192,123 @@ MODULE_PARM_DESC(workarounds, "Work around device bugs (default = 0" | |||
| 179 | ", override internal blacklist = " __stringify(SBP2_WORKAROUND_OVERRIDE) | 192 | ", override internal blacklist = " __stringify(SBP2_WORKAROUND_OVERRIDE) |
| 180 | ", or a combination)"); | 193 | ", or a combination)"); |
| 181 | 194 | ||
| 182 | /* | ||
| 183 | * Export information about protocols/devices supported by this driver. | ||
| 184 | */ | ||
| 185 | static struct ieee1394_device_id sbp2_id_table[] = { | ||
| 186 | { | ||
| 187 | .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION, | ||
| 188 | .specifier_id = SBP2_UNIT_SPEC_ID_ENTRY & 0xffffff, | ||
| 189 | .version = SBP2_SW_VERSION_ENTRY & 0xffffff}, | ||
| 190 | {} | ||
| 191 | }; | ||
| 192 | |||
| 193 | MODULE_DEVICE_TABLE(ieee1394, sbp2_id_table); | ||
| 194 | |||
| 195 | /* | ||
| 196 | * Debug levels, configured via kernel config, or enable here. | ||
| 197 | */ | ||
| 198 | |||
| 199 | #define CONFIG_IEEE1394_SBP2_DEBUG 0 | ||
| 200 | /* #define CONFIG_IEEE1394_SBP2_DEBUG_ORBS */ | ||
| 201 | /* #define CONFIG_IEEE1394_SBP2_DEBUG_DMA */ | ||
| 202 | /* #define CONFIG_IEEE1394_SBP2_DEBUG 1 */ | ||
| 203 | /* #define CONFIG_IEEE1394_SBP2_DEBUG 2 */ | ||
| 204 | /* #define CONFIG_IEEE1394_SBP2_PACKET_DUMP */ | ||
| 205 | |||
| 206 | #ifdef CONFIG_IEEE1394_SBP2_DEBUG_ORBS | ||
| 207 | #define SBP2_ORB_DEBUG(fmt, args...) HPSB_ERR("sbp2(%s): "fmt, __FUNCTION__, ## args) | ||
| 208 | static u32 global_outstanding_command_orbs = 0; | ||
| 209 | #define outstanding_orb_incr global_outstanding_command_orbs++ | ||
| 210 | #define outstanding_orb_decr global_outstanding_command_orbs-- | ||
| 211 | #else | ||
| 212 | #define SBP2_ORB_DEBUG(fmt, args...) do {} while (0) | ||
| 213 | #define outstanding_orb_incr do {} while (0) | ||
| 214 | #define outstanding_orb_decr do {} while (0) | ||
| 215 | #endif | ||
| 216 | |||
| 217 | #ifdef CONFIG_IEEE1394_SBP2_DEBUG_DMA | ||
| 218 | #define SBP2_DMA_ALLOC(fmt, args...) \ | ||
| 219 | HPSB_ERR("sbp2(%s)alloc(%d): "fmt, __FUNCTION__, \ | ||
| 220 | ++global_outstanding_dmas, ## args) | ||
| 221 | #define SBP2_DMA_FREE(fmt, args...) \ | ||
| 222 | HPSB_ERR("sbp2(%s)free(%d): "fmt, __FUNCTION__, \ | ||
| 223 | --global_outstanding_dmas, ## args) | ||
| 224 | static u32 global_outstanding_dmas = 0; | ||
| 225 | #else | ||
| 226 | #define SBP2_DMA_ALLOC(fmt, args...) do {} while (0) | ||
| 227 | #define SBP2_DMA_FREE(fmt, args...) do {} while (0) | ||
| 228 | #endif | ||
| 229 | 195 | ||
| 230 | #if CONFIG_IEEE1394_SBP2_DEBUG >= 2 | 196 | #define SBP2_INFO(fmt, args...) HPSB_INFO("sbp2: "fmt, ## args) |
| 231 | #define SBP2_DEBUG(fmt, args...) HPSB_ERR("sbp2: "fmt, ## args) | 197 | #define SBP2_ERR(fmt, args...) HPSB_ERR("sbp2: "fmt, ## args) |
| 232 | #define SBP2_INFO(fmt, args...) HPSB_ERR("sbp2: "fmt, ## args) | ||
| 233 | #define SBP2_NOTICE(fmt, args...) HPSB_ERR("sbp2: "fmt, ## args) | ||
| 234 | #define SBP2_WARN(fmt, args...) HPSB_ERR("sbp2: "fmt, ## args) | ||
| 235 | #elif CONFIG_IEEE1394_SBP2_DEBUG == 1 | ||
| 236 | #define SBP2_DEBUG(fmt, args...) HPSB_DEBUG("sbp2: "fmt, ## args) | ||
| 237 | #define SBP2_INFO(fmt, args...) HPSB_INFO("sbp2: "fmt, ## args) | ||
| 238 | #define SBP2_NOTICE(fmt, args...) HPSB_NOTICE("sbp2: "fmt, ## args) | ||
| 239 | #define SBP2_WARN(fmt, args...) HPSB_WARN("sbp2: "fmt, ## args) | ||
| 240 | #else | ||
| 241 | #define SBP2_DEBUG(fmt, args...) do {} while (0) | ||
| 242 | #define SBP2_INFO(fmt, args...) HPSB_INFO("sbp2: "fmt, ## args) | ||
| 243 | #define SBP2_NOTICE(fmt, args...) HPSB_NOTICE("sbp2: "fmt, ## args) | ||
| 244 | #define SBP2_WARN(fmt, args...) HPSB_WARN("sbp2: "fmt, ## args) | ||
| 245 | #endif | ||
| 246 | |||
| 247 | #define SBP2_ERR(fmt, args...) HPSB_ERR("sbp2: "fmt, ## args) | ||
| 248 | #define SBP2_DEBUG_ENTER() SBP2_DEBUG("%s", __FUNCTION__) | ||
| 249 | 198 | ||
| 250 | /* | 199 | /* |
| 251 | * Globals | 200 | * Globals |
| 252 | */ | 201 | */ |
| 202 | static void sbp2scsi_complete_all_commands(struct sbp2_lu *, u32); | ||
| 203 | static void sbp2scsi_complete_command(struct sbp2_lu *, u32, struct scsi_cmnd *, | ||
| 204 | void (*)(struct scsi_cmnd *)); | ||
| 205 | static struct sbp2_lu *sbp2_alloc_device(struct unit_directory *); | ||
| 206 | static int sbp2_start_device(struct sbp2_lu *); | ||
| 207 | static void sbp2_remove_device(struct sbp2_lu *); | ||
| 208 | static int sbp2_login_device(struct sbp2_lu *); | ||
| 209 | static int sbp2_reconnect_device(struct sbp2_lu *); | ||
| 210 | static int sbp2_logout_device(struct sbp2_lu *); | ||
| 211 | static void sbp2_host_reset(struct hpsb_host *); | ||
| 212 | static int sbp2_handle_status_write(struct hpsb_host *, int, int, quadlet_t *, | ||
| 213 | u64, size_t, u16); | ||
| 214 | static int sbp2_agent_reset(struct sbp2_lu *, int); | ||
| 215 | static void sbp2_parse_unit_directory(struct sbp2_lu *, | ||
| 216 | struct unit_directory *); | ||
| 217 | static int sbp2_set_busy_timeout(struct sbp2_lu *); | ||
| 218 | static int sbp2_max_speed_and_size(struct sbp2_lu *); | ||
| 253 | 219 | ||
| 254 | static void sbp2scsi_complete_all_commands(struct scsi_id_instance_data *scsi_id, | ||
| 255 | u32 status); | ||
| 256 | |||
| 257 | static void sbp2scsi_complete_command(struct scsi_id_instance_data *scsi_id, | ||
| 258 | u32 scsi_status, struct scsi_cmnd *SCpnt, | ||
| 259 | void (*done)(struct scsi_cmnd *)); | ||
| 260 | |||
| 261 | static struct scsi_host_template scsi_driver_template; | ||
| 262 | 220 | ||
| 263 | static const u8 sbp2_speedto_max_payload[] = { 0x7, 0x8, 0x9, 0xA, 0xB, 0xC }; | 221 | static const u8 sbp2_speedto_max_payload[] = { 0x7, 0x8, 0x9, 0xA, 0xB, 0xC }; |
| 264 | 222 | ||
| 265 | static void sbp2_host_reset(struct hpsb_host *host); | ||
| 266 | |||
| 267 | static int sbp2_probe(struct device *dev); | ||
| 268 | static int sbp2_remove(struct device *dev); | ||
| 269 | static int sbp2_update(struct unit_directory *ud); | ||
| 270 | |||
| 271 | static struct hpsb_highlevel sbp2_highlevel = { | 223 | static struct hpsb_highlevel sbp2_highlevel = { |
| 272 | .name = SBP2_DEVICE_NAME, | 224 | .name = SBP2_DEVICE_NAME, |
| 273 | .host_reset = sbp2_host_reset, | 225 | .host_reset = sbp2_host_reset, |
| 274 | }; | 226 | }; |
| 275 | 227 | ||
| 276 | static struct hpsb_address_ops sbp2_ops = { | 228 | static struct hpsb_address_ops sbp2_ops = { |
| 277 | .write = sbp2_handle_status_write | 229 | .write = sbp2_handle_status_write |
| 278 | }; | 230 | }; |
| 279 | 231 | ||
| 280 | #ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA | 232 | #ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA |
| 233 | static int sbp2_handle_physdma_write(struct hpsb_host *, int, int, quadlet_t *, | ||
| 234 | u64, size_t, u16); | ||
| 235 | static int sbp2_handle_physdma_read(struct hpsb_host *, int, quadlet_t *, u64, | ||
| 236 | size_t, u16); | ||
| 237 | |||
| 281 | static struct hpsb_address_ops sbp2_physdma_ops = { | 238 | static struct hpsb_address_ops sbp2_physdma_ops = { |
| 282 | .read = sbp2_handle_physdma_read, | 239 | .read = sbp2_handle_physdma_read, |
| 283 | .write = sbp2_handle_physdma_write, | 240 | .write = sbp2_handle_physdma_write, |
| 284 | }; | 241 | }; |
| 285 | #endif | 242 | #endif |
| 286 | 243 | ||
| 244 | |||
| 245 | /* | ||
| 246 | * Interface to driver core and IEEE 1394 core | ||
| 247 | */ | ||
| 248 | static struct ieee1394_device_id sbp2_id_table[] = { | ||
| 249 | { | ||
| 250 | .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION, | ||
| 251 | .specifier_id = SBP2_UNIT_SPEC_ID_ENTRY & 0xffffff, | ||
| 252 | .version = SBP2_SW_VERSION_ENTRY & 0xffffff}, | ||
| 253 | {} | ||
| 254 | }; | ||
| 255 | MODULE_DEVICE_TABLE(ieee1394, sbp2_id_table); | ||
| 256 | |||
| 257 | static int sbp2_probe(struct device *); | ||
| 258 | static int sbp2_remove(struct device *); | ||
| 259 | static int sbp2_update(struct unit_directory *); | ||
| 260 | |||
| 287 | static struct hpsb_protocol_driver sbp2_driver = { | 261 | static struct hpsb_protocol_driver sbp2_driver = { |
| 288 | .name = "SBP2 Driver", | 262 | .name = SBP2_DEVICE_NAME, |
| 289 | .id_table = sbp2_id_table, | 263 | .id_table = sbp2_id_table, |
| 290 | .update = sbp2_update, | 264 | .update = sbp2_update, |
| 291 | .driver = { | 265 | .driver = { |
| 292 | .name = SBP2_DEVICE_NAME, | ||
| 293 | .bus = &ieee1394_bus_type, | ||
| 294 | .probe = sbp2_probe, | 266 | .probe = sbp2_probe, |
| 295 | .remove = sbp2_remove, | 267 | .remove = sbp2_remove, |
| 296 | }, | 268 | }, |
| 297 | }; | 269 | }; |
| 298 | 270 | ||
| 271 | |||
| 272 | /* | ||
| 273 | * Interface to SCSI core | ||
| 274 | */ | ||
| 275 | static int sbp2scsi_queuecommand(struct scsi_cmnd *, | ||
| 276 | void (*)(struct scsi_cmnd *)); | ||
| 277 | static int sbp2scsi_abort(struct scsi_cmnd *); | ||
| 278 | static int sbp2scsi_reset(struct scsi_cmnd *); | ||
| 279 | static int sbp2scsi_slave_alloc(struct scsi_device *); | ||
| 280 | static int sbp2scsi_slave_configure(struct scsi_device *); | ||
| 281 | static void sbp2scsi_slave_destroy(struct scsi_device *); | ||
| 282 | static ssize_t sbp2_sysfs_ieee1394_id_show(struct device *, | ||
| 283 | struct device_attribute *, char *); | ||
| 284 | |||
| 285 | static DEVICE_ATTR(ieee1394_id, S_IRUGO, sbp2_sysfs_ieee1394_id_show, NULL); | ||
| 286 | |||
| 287 | static struct device_attribute *sbp2_sysfs_sdev_attrs[] = { | ||
| 288 | &dev_attr_ieee1394_id, | ||
| 289 | NULL | ||
| 290 | }; | ||
| 291 | |||
| 292 | static struct scsi_host_template sbp2_shost_template = { | ||
| 293 | .module = THIS_MODULE, | ||
| 294 | .name = "SBP-2 IEEE-1394", | ||
| 295 | .proc_name = SBP2_DEVICE_NAME, | ||
| 296 | .queuecommand = sbp2scsi_queuecommand, | ||
| 297 | .eh_abort_handler = sbp2scsi_abort, | ||
| 298 | .eh_device_reset_handler = sbp2scsi_reset, | ||
| 299 | .slave_alloc = sbp2scsi_slave_alloc, | ||
| 300 | .slave_configure = sbp2scsi_slave_configure, | ||
| 301 | .slave_destroy = sbp2scsi_slave_destroy, | ||
| 302 | .this_id = -1, | ||
| 303 | .sg_tablesize = SG_ALL, | ||
| 304 | .use_clustering = ENABLE_CLUSTERING, | ||
| 305 | .cmd_per_lun = SBP2_MAX_CMDS, | ||
| 306 | .can_queue = SBP2_MAX_CMDS, | ||
| 307 | .emulated = 1, | ||
| 308 | .sdev_attrs = sbp2_sysfs_sdev_attrs, | ||
| 309 | }; | ||
| 310 | |||
| 311 | |||
| 299 | /* | 312 | /* |
| 300 | * List of devices with known bugs. | 313 | * List of devices with known bugs. |
| 301 | * | 314 | * |
| @@ -363,8 +376,6 @@ static inline void sbp2util_be32_to_cpu_buffer(void *buffer, int length) | |||
| 363 | 376 | ||
| 364 | for (length = (length >> 2); length--; ) | 377 | for (length = (length >> 2); length--; ) |
| 365 | temp[length] = be32_to_cpu(temp[length]); | 378 | temp[length] = be32_to_cpu(temp[length]); |
| 366 | |||
| 367 | return; | ||
| 368 | } | 379 | } |
| 369 | 380 | ||
| 370 | /* | 381 | /* |
| @@ -376,8 +387,6 @@ static inline void sbp2util_cpu_to_be32_buffer(void *buffer, int length) | |||
| 376 | 387 | ||
| 377 | for (length = (length >> 2); length--; ) | 388 | for (length = (length >> 2); length--; ) |
| 378 | temp[length] = cpu_to_be32(temp[length]); | 389 | temp[length] = cpu_to_be32(temp[length]); |
| 379 | |||
| 380 | return; | ||
| 381 | } | 390 | } |
| 382 | #else /* BIG_ENDIAN */ | 391 | #else /* BIG_ENDIAN */ |
| 383 | /* Why waste the cpu cycles? */ | 392 | /* Why waste the cpu cycles? */ |
| @@ -385,344 +394,246 @@ static inline void sbp2util_cpu_to_be32_buffer(void *buffer, int length) | |||
| 385 | #define sbp2util_cpu_to_be32_buffer(x,y) do {} while (0) | 394 | #define sbp2util_cpu_to_be32_buffer(x,y) do {} while (0) |
| 386 | #endif | 395 | #endif |
| 387 | 396 | ||
| 388 | #ifdef CONFIG_IEEE1394_SBP2_PACKET_DUMP | 397 | static DECLARE_WAIT_QUEUE_HEAD(sbp2_access_wq); |
| 389 | /* | ||
| 390 | * Debug packet dump routine. Length is in bytes. | ||
| 391 | */ | ||
| 392 | static void sbp2util_packet_dump(void *buffer, int length, char *dump_name, | ||
| 393 | u32 dump_phys_addr) | ||
| 394 | { | ||
| 395 | int i; | ||
| 396 | unsigned char *dump = buffer; | ||
| 397 | |||
| 398 | if (!dump || !length || !dump_name) | ||
| 399 | return; | ||
| 400 | |||
| 401 | if (dump_phys_addr) | ||
| 402 | printk("[%s, 0x%x]", dump_name, dump_phys_addr); | ||
| 403 | else | ||
| 404 | printk("[%s]", dump_name); | ||
| 405 | for (i = 0; i < length; i++) { | ||
| 406 | if (i > 0x3f) { | ||
| 407 | printk("\n ..."); | ||
| 408 | break; | ||
| 409 | } | ||
| 410 | if ((i & 0x3) == 0) | ||
| 411 | printk(" "); | ||
| 412 | if ((i & 0xf) == 0) | ||
| 413 | printk("\n "); | ||
| 414 | printk("%02x ", (int)dump[i]); | ||
| 415 | } | ||
| 416 | printk("\n"); | ||
| 417 | |||
| 418 | return; | ||
| 419 | } | ||
| 420 | #else | ||
| 421 | #define sbp2util_packet_dump(w,x,y,z) do {} while (0) | ||
| 422 | #endif | ||
| 423 | |||
| 424 | static DECLARE_WAIT_QUEUE_HEAD(access_wq); | ||
| 425 | 398 | ||
| 426 | /* | 399 | /* |
| 427 | * Waits for completion of an SBP-2 access request. | 400 | * Waits for completion of an SBP-2 access request. |
| 428 | * Returns nonzero if timed out or prematurely interrupted. | 401 | * Returns nonzero if timed out or prematurely interrupted. |
| 429 | */ | 402 | */ |
| 430 | static int sbp2util_access_timeout(struct scsi_id_instance_data *scsi_id, | 403 | static int sbp2util_access_timeout(struct sbp2_lu *lu, int timeout) |
| 431 | int timeout) | ||
| 432 | { | 404 | { |
| 433 | long leftover = wait_event_interruptible_timeout( | 405 | long leftover; |
| 434 | access_wq, scsi_id->access_complete, timeout); | ||
| 435 | 406 | ||
| 436 | scsi_id->access_complete = 0; | 407 | leftover = wait_event_interruptible_timeout( |
| 408 | sbp2_access_wq, lu->access_complete, timeout); | ||
| 409 | lu->access_complete = 0; | ||
| 437 | return leftover <= 0; | 410 | return leftover <= 0; |
| 438 | } | 411 | } |
| 439 | 412 | ||
| 440 | /* Frees an allocated packet */ | 413 | static void sbp2_free_packet(void *packet) |
| 441 | static void sbp2_free_packet(struct hpsb_packet *packet) | ||
| 442 | { | 414 | { |
| 443 | hpsb_free_tlabel(packet); | 415 | hpsb_free_tlabel(packet); |
| 444 | hpsb_free_packet(packet); | 416 | hpsb_free_packet(packet); |
| 445 | } | 417 | } |
| 446 | 418 | ||
| 447 | /* This is much like hpsb_node_write(), except it ignores the response | 419 | /* |
| 448 | * subaction and returns immediately. Can be used from interrupts. | 420 | * This is much like hpsb_node_write(), except it ignores the response |
| 421 | * subaction and returns immediately. Can be used from atomic context. | ||
| 449 | */ | 422 | */ |
| 450 | static int sbp2util_node_write_no_wait(struct node_entry *ne, u64 addr, | 423 | static int sbp2util_node_write_no_wait(struct node_entry *ne, u64 addr, |
| 451 | quadlet_t *buffer, size_t length) | 424 | quadlet_t *buf, size_t len) |
| 452 | { | 425 | { |
| 453 | struct hpsb_packet *packet; | 426 | struct hpsb_packet *packet; |
| 454 | 427 | ||
| 455 | packet = hpsb_make_writepacket(ne->host, ne->nodeid, | 428 | packet = hpsb_make_writepacket(ne->host, ne->nodeid, addr, buf, len); |
| 456 | addr, buffer, length); | ||
| 457 | if (!packet) | 429 | if (!packet) |
| 458 | return -ENOMEM; | 430 | return -ENOMEM; |
| 459 | 431 | ||
| 460 | hpsb_set_packet_complete_task(packet, | 432 | hpsb_set_packet_complete_task(packet, sbp2_free_packet, packet); |
| 461 | (void (*)(void *))sbp2_free_packet, | ||
| 462 | packet); | ||
| 463 | |||
| 464 | hpsb_node_fill_packet(ne, packet); | 433 | hpsb_node_fill_packet(ne, packet); |
| 465 | |||
| 466 | if (hpsb_send_packet(packet) < 0) { | 434 | if (hpsb_send_packet(packet) < 0) { |
| 467 | sbp2_free_packet(packet); | 435 | sbp2_free_packet(packet); |
| 468 | return -EIO; | 436 | return -EIO; |
| 469 | } | 437 | } |
| 470 | |||
| 471 | return 0; | 438 | return 0; |
| 472 | } | 439 | } |
| 473 | 440 | ||
| 474 | static void sbp2util_notify_fetch_agent(struct scsi_id_instance_data *scsi_id, | 441 | static void sbp2util_notify_fetch_agent(struct sbp2_lu *lu, u64 offset, |
| 475 | u64 offset, quadlet_t *data, size_t len) | 442 | quadlet_t *data, size_t len) |
| 476 | { | 443 | { |
| 477 | /* | 444 | /* There is a small window after a bus reset within which the node |
| 478 | * There is a small window after a bus reset within which the node | 445 | * entry's generation is current but the reconnect wasn't completed. */ |
| 479 | * entry's generation is current but the reconnect wasn't completed. | 446 | if (unlikely(atomic_read(&lu->state) == SBP2LU_STATE_IN_RESET)) |
| 480 | */ | ||
| 481 | if (unlikely(atomic_read(&scsi_id->state) == SBP2LU_STATE_IN_RESET)) | ||
| 482 | return; | 447 | return; |
| 483 | 448 | ||
| 484 | if (hpsb_node_write(scsi_id->ne, | 449 | if (hpsb_node_write(lu->ne, lu->command_block_agent_addr + offset, |
| 485 | scsi_id->sbp2_command_block_agent_addr + offset, | ||
| 486 | data, len)) | 450 | data, len)) |
| 487 | SBP2_ERR("sbp2util_notify_fetch_agent failed."); | 451 | SBP2_ERR("sbp2util_notify_fetch_agent failed."); |
| 488 | /* | 452 | |
| 489 | * Now accept new SCSI commands, unless a bus reset happended during | 453 | /* Now accept new SCSI commands, unless a bus reset happended during |
| 490 | * hpsb_node_write. | 454 | * hpsb_node_write. */ |
| 491 | */ | 455 | if (likely(atomic_read(&lu->state) != SBP2LU_STATE_IN_RESET)) |
| 492 | if (likely(atomic_read(&scsi_id->state) != SBP2LU_STATE_IN_RESET)) | 456 | scsi_unblock_requests(lu->shost); |
| 493 | scsi_unblock_requests(scsi_id->scsi_host); | ||
| 494 | } | 457 | } |
| 495 | 458 | ||
| 496 | static void sbp2util_write_orb_pointer(struct work_struct *work) | 459 | static void sbp2util_write_orb_pointer(struct work_struct *work) |
| 497 | { | 460 | { |
| 498 | struct scsi_id_instance_data *scsi_id = | 461 | struct sbp2_lu *lu = container_of(work, struct sbp2_lu, protocol_work); |
| 499 | container_of(work, struct scsi_id_instance_data, | ||
| 500 | protocol_work.work); | ||
| 501 | quadlet_t data[2]; | 462 | quadlet_t data[2]; |
| 502 | 463 | ||
| 503 | data[0] = ORB_SET_NODE_ID(scsi_id->hi->host->node_id); | 464 | data[0] = ORB_SET_NODE_ID(lu->hi->host->node_id); |
| 504 | data[1] = scsi_id->last_orb_dma; | 465 | data[1] = lu->last_orb_dma; |
| 505 | sbp2util_cpu_to_be32_buffer(data, 8); | 466 | sbp2util_cpu_to_be32_buffer(data, 8); |
| 506 | sbp2util_notify_fetch_agent(scsi_id, SBP2_ORB_POINTER_OFFSET, data, 8); | 467 | sbp2util_notify_fetch_agent(lu, SBP2_ORB_POINTER_OFFSET, data, 8); |
| 507 | } | 468 | } |
| 508 | 469 | ||
| 509 | static void sbp2util_write_doorbell(struct work_struct *work) | 470 | static void sbp2util_write_doorbell(struct work_struct *work) |
| 510 | { | 471 | { |
| 511 | struct scsi_id_instance_data *scsi_id = | 472 | struct sbp2_lu *lu = container_of(work, struct sbp2_lu, protocol_work); |
| 512 | container_of(work, struct scsi_id_instance_data, | 473 | |
| 513 | protocol_work.work); | 474 | sbp2util_notify_fetch_agent(lu, SBP2_DOORBELL_OFFSET, NULL, 4); |
| 514 | sbp2util_notify_fetch_agent(scsi_id, SBP2_DOORBELL_OFFSET, NULL, 4); | ||
| 515 | } | 475 | } |
| 516 | 476 | ||
| 517 | /* | 477 | static int sbp2util_create_command_orb_pool(struct sbp2_lu *lu) |
| 518 | * This function is called to create a pool of command orbs used for | ||
| 519 | * command processing. It is called when a new sbp2 device is detected. | ||
| 520 | */ | ||
| 521 | static int sbp2util_create_command_orb_pool(struct scsi_id_instance_data *scsi_id) | ||
| 522 | { | 478 | { |
| 523 | struct sbp2scsi_host_info *hi = scsi_id->hi; | 479 | struct sbp2_fwhost_info *hi = lu->hi; |
| 524 | int i; | 480 | int i; |
| 525 | unsigned long flags, orbs; | 481 | unsigned long flags, orbs; |
| 526 | struct sbp2_command_info *command; | 482 | struct sbp2_command_info *cmd; |
| 527 | 483 | ||
| 528 | orbs = serialize_io ? 2 : SBP2_MAX_CMDS; | 484 | orbs = sbp2_serialize_io ? 2 : SBP2_MAX_CMDS; |
| 529 | 485 | ||
| 530 | spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); | 486 | spin_lock_irqsave(&lu->cmd_orb_lock, flags); |
| 531 | for (i = 0; i < orbs; i++) { | 487 | for (i = 0; i < orbs; i++) { |
| 532 | command = kzalloc(sizeof(*command), GFP_ATOMIC); | 488 | cmd = kzalloc(sizeof(*cmd), GFP_ATOMIC); |
| 533 | if (!command) { | 489 | if (!cmd) { |
| 534 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, | 490 | spin_unlock_irqrestore(&lu->cmd_orb_lock, flags); |
| 535 | flags); | ||
| 536 | return -ENOMEM; | 491 | return -ENOMEM; |
| 537 | } | 492 | } |
| 538 | command->command_orb_dma = | 493 | cmd->command_orb_dma = dma_map_single(&hi->host->device, |
| 539 | pci_map_single(hi->host->pdev, &command->command_orb, | 494 | &cmd->command_orb, |
| 540 | sizeof(struct sbp2_command_orb), | 495 | sizeof(struct sbp2_command_orb), |
| 541 | PCI_DMA_TODEVICE); | 496 | DMA_TO_DEVICE); |
| 542 | SBP2_DMA_ALLOC("single command orb DMA"); | 497 | cmd->sge_dma = dma_map_single(&hi->host->device, |
| 543 | command->sge_dma = | 498 | &cmd->scatter_gather_element, |
| 544 | pci_map_single(hi->host->pdev, | 499 | sizeof(cmd->scatter_gather_element), |
| 545 | &command->scatter_gather_element, | 500 | DMA_BIDIRECTIONAL); |
| 546 | sizeof(command->scatter_gather_element), | 501 | INIT_LIST_HEAD(&cmd->list); |
| 547 | PCI_DMA_BIDIRECTIONAL); | 502 | list_add_tail(&cmd->list, &lu->cmd_orb_completed); |
| 548 | SBP2_DMA_ALLOC("scatter_gather_element"); | 503 | } |
| 549 | INIT_LIST_HEAD(&command->list); | 504 | spin_unlock_irqrestore(&lu->cmd_orb_lock, flags); |
| 550 | list_add_tail(&command->list, &scsi_id->sbp2_command_orb_completed); | ||
| 551 | } | ||
| 552 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); | ||
| 553 | return 0; | 505 | return 0; |
| 554 | } | 506 | } |
| 555 | 507 | ||
| 556 | /* | 508 | static void sbp2util_remove_command_orb_pool(struct sbp2_lu *lu) |
| 557 | * This function is called to delete a pool of command orbs. | ||
| 558 | */ | ||
| 559 | static void sbp2util_remove_command_orb_pool(struct scsi_id_instance_data *scsi_id) | ||
| 560 | { | 509 | { |
| 561 | struct hpsb_host *host = scsi_id->hi->host; | 510 | struct hpsb_host *host = lu->hi->host; |
| 562 | struct list_head *lh, *next; | 511 | struct list_head *lh, *next; |
| 563 | struct sbp2_command_info *command; | 512 | struct sbp2_command_info *cmd; |
| 564 | unsigned long flags; | 513 | unsigned long flags; |
| 565 | 514 | ||
| 566 | spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); | 515 | spin_lock_irqsave(&lu->cmd_orb_lock, flags); |
| 567 | if (!list_empty(&scsi_id->sbp2_command_orb_completed)) { | 516 | if (!list_empty(&lu->cmd_orb_completed)) |
| 568 | list_for_each_safe(lh, next, &scsi_id->sbp2_command_orb_completed) { | 517 | list_for_each_safe(lh, next, &lu->cmd_orb_completed) { |
| 569 | command = list_entry(lh, struct sbp2_command_info, list); | 518 | cmd = list_entry(lh, struct sbp2_command_info, list); |
| 570 | 519 | dma_unmap_single(&host->device, cmd->command_orb_dma, | |
| 571 | /* Release our generic DMA's */ | ||
| 572 | pci_unmap_single(host->pdev, command->command_orb_dma, | ||
| 573 | sizeof(struct sbp2_command_orb), | 520 | sizeof(struct sbp2_command_orb), |
| 574 | PCI_DMA_TODEVICE); | 521 | DMA_TO_DEVICE); |
| 575 | SBP2_DMA_FREE("single command orb DMA"); | 522 | dma_unmap_single(&host->device, cmd->sge_dma, |
| 576 | pci_unmap_single(host->pdev, command->sge_dma, | 523 | sizeof(cmd->scatter_gather_element), |
| 577 | sizeof(command->scatter_gather_element), | 524 | DMA_BIDIRECTIONAL); |
| 578 | PCI_DMA_BIDIRECTIONAL); | 525 | kfree(cmd); |
| 579 | SBP2_DMA_FREE("scatter_gather_element"); | ||
| 580 | |||
| 581 | kfree(command); | ||
| 582 | } | 526 | } |
| 583 | } | 527 | spin_unlock_irqrestore(&lu->cmd_orb_lock, flags); |
| 584 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); | ||
| 585 | return; | 528 | return; |
| 586 | } | 529 | } |
| 587 | 530 | ||
| 588 | /* | 531 | /* |
| 589 | * This function finds the sbp2_command for a given outstanding command | 532 | * Finds the sbp2_command for a given outstanding command ORB. |
| 590 | * orb.Only looks at the inuse list. | 533 | * Only looks at the in-use list. |
| 591 | */ | 534 | */ |
| 592 | static struct sbp2_command_info *sbp2util_find_command_for_orb( | 535 | static struct sbp2_command_info *sbp2util_find_command_for_orb( |
| 593 | struct scsi_id_instance_data *scsi_id, dma_addr_t orb) | 536 | struct sbp2_lu *lu, dma_addr_t orb) |
| 594 | { | 537 | { |
| 595 | struct sbp2_command_info *command; | 538 | struct sbp2_command_info *cmd; |
| 596 | unsigned long flags; | 539 | unsigned long flags; |
| 597 | 540 | ||
| 598 | spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); | 541 | spin_lock_irqsave(&lu->cmd_orb_lock, flags); |
| 599 | if (!list_empty(&scsi_id->sbp2_command_orb_inuse)) { | 542 | if (!list_empty(&lu->cmd_orb_inuse)) |
| 600 | list_for_each_entry(command, &scsi_id->sbp2_command_orb_inuse, list) { | 543 | list_for_each_entry(cmd, &lu->cmd_orb_inuse, list) |
| 601 | if (command->command_orb_dma == orb) { | 544 | if (cmd->command_orb_dma == orb) { |
| 602 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); | 545 | spin_unlock_irqrestore( |
| 603 | return command; | 546 | &lu->cmd_orb_lock, flags); |
| 547 | return cmd; | ||
| 604 | } | 548 | } |
| 605 | } | 549 | spin_unlock_irqrestore(&lu->cmd_orb_lock, flags); |
| 606 | } | ||
| 607 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); | ||
| 608 | |||
| 609 | SBP2_ORB_DEBUG("could not match command orb %x", (unsigned int)orb); | ||
| 610 | |||
| 611 | return NULL; | 550 | return NULL; |
| 612 | } | 551 | } |
| 613 | 552 | ||
| 614 | /* | 553 | /* |
| 615 | * This function finds the sbp2_command for a given outstanding SCpnt. | 554 | * Finds the sbp2_command for a given outstanding SCpnt. |
| 616 | * Only looks at the inuse list. | 555 | * Only looks at the in-use list. |
| 617 | * Must be called with scsi_id->sbp2_command_orb_lock held. | 556 | * Must be called with lu->cmd_orb_lock held. |
| 618 | */ | 557 | */ |
| 619 | static struct sbp2_command_info *sbp2util_find_command_for_SCpnt( | 558 | static struct sbp2_command_info *sbp2util_find_command_for_SCpnt( |
| 620 | struct scsi_id_instance_data *scsi_id, void *SCpnt) | 559 | struct sbp2_lu *lu, void *SCpnt) |
| 621 | { | 560 | { |
| 622 | struct sbp2_command_info *command; | 561 | struct sbp2_command_info *cmd; |
| 623 | 562 | ||
| 624 | if (!list_empty(&scsi_id->sbp2_command_orb_inuse)) | 563 | if (!list_empty(&lu->cmd_orb_inuse)) |
| 625 | list_for_each_entry(command, &scsi_id->sbp2_command_orb_inuse, list) | 564 | list_for_each_entry(cmd, &lu->cmd_orb_inuse, list) |
| 626 | if (command->Current_SCpnt == SCpnt) | 565 | if (cmd->Current_SCpnt == SCpnt) |
| 627 | return command; | 566 | return cmd; |
| 628 | return NULL; | 567 | return NULL; |
| 629 | } | 568 | } |
| 630 | 569 | ||
| 631 | /* | ||
| 632 | * This function allocates a command orb used to send a scsi command. | ||
| 633 | */ | ||
| 634 | static struct sbp2_command_info *sbp2util_allocate_command_orb( | 570 | static struct sbp2_command_info *sbp2util_allocate_command_orb( |
| 635 | struct scsi_id_instance_data *scsi_id, | 571 | struct sbp2_lu *lu, |
| 636 | struct scsi_cmnd *Current_SCpnt, | 572 | struct scsi_cmnd *Current_SCpnt, |
| 637 | void (*Current_done)(struct scsi_cmnd *)) | 573 | void (*Current_done)(struct scsi_cmnd *)) |
| 638 | { | 574 | { |
| 639 | struct list_head *lh; | 575 | struct list_head *lh; |
| 640 | struct sbp2_command_info *command = NULL; | 576 | struct sbp2_command_info *cmd = NULL; |
| 641 | unsigned long flags; | 577 | unsigned long flags; |
| 642 | 578 | ||
| 643 | spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); | 579 | spin_lock_irqsave(&lu->cmd_orb_lock, flags); |
| 644 | if (!list_empty(&scsi_id->sbp2_command_orb_completed)) { | 580 | if (!list_empty(&lu->cmd_orb_completed)) { |
| 645 | lh = scsi_id->sbp2_command_orb_completed.next; | 581 | lh = lu->cmd_orb_completed.next; |
| 646 | list_del(lh); | 582 | list_del(lh); |
| 647 | command = list_entry(lh, struct sbp2_command_info, list); | 583 | cmd = list_entry(lh, struct sbp2_command_info, list); |
| 648 | command->Current_done = Current_done; | 584 | cmd->Current_done = Current_done; |
| 649 | command->Current_SCpnt = Current_SCpnt; | 585 | cmd->Current_SCpnt = Current_SCpnt; |
| 650 | list_add_tail(&command->list, &scsi_id->sbp2_command_orb_inuse); | 586 | list_add_tail(&cmd->list, &lu->cmd_orb_inuse); |
| 651 | } else { | 587 | } else |
| 652 | SBP2_ERR("%s: no orbs available", __FUNCTION__); | 588 | SBP2_ERR("%s: no orbs available", __FUNCTION__); |
| 653 | } | 589 | spin_unlock_irqrestore(&lu->cmd_orb_lock, flags); |
| 654 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); | 590 | return cmd; |
| 655 | return command; | ||
| 656 | } | ||
| 657 | |||
| 658 | /* Free our DMA's */ | ||
| 659 | static void sbp2util_free_command_dma(struct sbp2_command_info *command) | ||
| 660 | { | ||
| 661 | struct scsi_id_instance_data *scsi_id = | ||
| 662 | (struct scsi_id_instance_data *)command->Current_SCpnt->device->host->hostdata[0]; | ||
| 663 | struct hpsb_host *host; | ||
| 664 | |||
| 665 | if (!scsi_id) { | ||
| 666 | SBP2_ERR("%s: scsi_id == NULL", __FUNCTION__); | ||
| 667 | return; | ||
| 668 | } | ||
| 669 | |||
| 670 | host = scsi_id->ud->ne->host; | ||
| 671 | |||
| 672 | if (command->cmd_dma) { | ||
| 673 | if (command->dma_type == CMD_DMA_SINGLE) { | ||
| 674 | pci_unmap_single(host->pdev, command->cmd_dma, | ||
| 675 | command->dma_size, command->dma_dir); | ||
| 676 | SBP2_DMA_FREE("single bulk"); | ||
| 677 | } else if (command->dma_type == CMD_DMA_PAGE) { | ||
| 678 | pci_unmap_page(host->pdev, command->cmd_dma, | ||
| 679 | command->dma_size, command->dma_dir); | ||
| 680 | SBP2_DMA_FREE("single page"); | ||
| 681 | } /* XXX: Check for CMD_DMA_NONE bug */ | ||
| 682 | command->dma_type = CMD_DMA_NONE; | ||
| 683 | command->cmd_dma = 0; | ||
| 684 | } | ||
| 685 | |||
| 686 | if (command->sge_buffer) { | ||
| 687 | pci_unmap_sg(host->pdev, command->sge_buffer, | ||
| 688 | command->dma_size, command->dma_dir); | ||
| 689 | SBP2_DMA_FREE("scatter list"); | ||
| 690 | command->sge_buffer = NULL; | ||
| 691 | } | ||
| 692 | } | 591 | } |
| 693 | 592 | ||
| 694 | /* | 593 | /* |
| 695 | * This function moves a command to the completed orb list. | 594 | * Unmaps the DMAs of a command and moves the command to the completed ORB list. |
| 696 | * Must be called with scsi_id->sbp2_command_orb_lock held. | 595 | * Must be called with lu->cmd_orb_lock held. |
| 697 | */ | 596 | */ |
| 698 | static void sbp2util_mark_command_completed( | 597 | static void sbp2util_mark_command_completed(struct sbp2_lu *lu, |
| 699 | struct scsi_id_instance_data *scsi_id, | 598 | struct sbp2_command_info *cmd) |
| 700 | struct sbp2_command_info *command) | ||
| 701 | { | 599 | { |
| 702 | list_del(&command->list); | 600 | struct hpsb_host *host = lu->ud->ne->host; |
| 703 | sbp2util_free_command_dma(command); | 601 | |
| 704 | list_add_tail(&command->list, &scsi_id->sbp2_command_orb_completed); | 602 | if (cmd->cmd_dma) { |
| 603 | if (cmd->dma_type == CMD_DMA_SINGLE) | ||
| 604 | dma_unmap_single(&host->device, cmd->cmd_dma, | ||
| 605 | cmd->dma_size, cmd->dma_dir); | ||
| 606 | else if (cmd->dma_type == CMD_DMA_PAGE) | ||
| 607 | dma_unmap_page(&host->device, cmd->cmd_dma, | ||
| 608 | cmd->dma_size, cmd->dma_dir); | ||
| 609 | /* XXX: Check for CMD_DMA_NONE bug */ | ||
| 610 | cmd->dma_type = CMD_DMA_NONE; | ||
| 611 | cmd->cmd_dma = 0; | ||
| 612 | } | ||
| 613 | if (cmd->sge_buffer) { | ||
| 614 | dma_unmap_sg(&host->device, cmd->sge_buffer, | ||
| 615 | cmd->dma_size, cmd->dma_dir); | ||
| 616 | cmd->sge_buffer = NULL; | ||
| 617 | } | ||
| 618 | list_move_tail(&cmd->list, &lu->cmd_orb_completed); | ||
| 705 | } | 619 | } |
| 706 | 620 | ||
| 707 | /* | 621 | /* |
| 708 | * Is scsi_id valid? Is the 1394 node still present? | 622 | * Is lu valid? Is the 1394 node still present? |
| 709 | */ | 623 | */ |
| 710 | static inline int sbp2util_node_is_available(struct scsi_id_instance_data *scsi_id) | 624 | static inline int sbp2util_node_is_available(struct sbp2_lu *lu) |
| 711 | { | 625 | { |
| 712 | return scsi_id && scsi_id->ne && !scsi_id->ne->in_limbo; | 626 | return lu && lu->ne && !lu->ne->in_limbo; |
| 713 | } | 627 | } |
| 714 | 628 | ||
| 715 | /********************************************* | 629 | /********************************************* |
| 716 | * IEEE-1394 core driver stack related section | 630 | * IEEE-1394 core driver stack related section |
| 717 | *********************************************/ | 631 | *********************************************/ |
| 718 | static struct scsi_id_instance_data *sbp2_alloc_device(struct unit_directory *ud); | ||
| 719 | 632 | ||
| 720 | static int sbp2_probe(struct device *dev) | 633 | static int sbp2_probe(struct device *dev) |
| 721 | { | 634 | { |
| 722 | struct unit_directory *ud; | 635 | struct unit_directory *ud; |
| 723 | struct scsi_id_instance_data *scsi_id; | 636 | struct sbp2_lu *lu; |
| 724 | |||
| 725 | SBP2_DEBUG_ENTER(); | ||
| 726 | 637 | ||
| 727 | ud = container_of(dev, struct unit_directory, device); | 638 | ud = container_of(dev, struct unit_directory, device); |
| 728 | 639 | ||
| @@ -731,67 +642,58 @@ static int sbp2_probe(struct device *dev) | |||
| 731 | if (ud->flags & UNIT_DIRECTORY_HAS_LUN_DIRECTORY) | 642 | if (ud->flags & UNIT_DIRECTORY_HAS_LUN_DIRECTORY) |
| 732 | return -ENODEV; | 643 | return -ENODEV; |
| 733 | 644 | ||
| 734 | scsi_id = sbp2_alloc_device(ud); | 645 | lu = sbp2_alloc_device(ud); |
| 735 | 646 | if (!lu) | |
| 736 | if (!scsi_id) | ||
| 737 | return -ENOMEM; | 647 | return -ENOMEM; |
| 738 | 648 | ||
| 739 | sbp2_parse_unit_directory(scsi_id, ud); | 649 | sbp2_parse_unit_directory(lu, ud); |
| 740 | 650 | return sbp2_start_device(lu); | |
| 741 | return sbp2_start_device(scsi_id); | ||
| 742 | } | 651 | } |
| 743 | 652 | ||
| 744 | static int sbp2_remove(struct device *dev) | 653 | static int sbp2_remove(struct device *dev) |
| 745 | { | 654 | { |
| 746 | struct unit_directory *ud; | 655 | struct unit_directory *ud; |
| 747 | struct scsi_id_instance_data *scsi_id; | 656 | struct sbp2_lu *lu; |
| 748 | struct scsi_device *sdev; | 657 | struct scsi_device *sdev; |
| 749 | 658 | ||
| 750 | SBP2_DEBUG_ENTER(); | ||
| 751 | |||
| 752 | ud = container_of(dev, struct unit_directory, device); | 659 | ud = container_of(dev, struct unit_directory, device); |
| 753 | scsi_id = ud->device.driver_data; | 660 | lu = ud->device.driver_data; |
| 754 | if (!scsi_id) | 661 | if (!lu) |
| 755 | return 0; | 662 | return 0; |
| 756 | 663 | ||
| 757 | if (scsi_id->scsi_host) { | 664 | if (lu->shost) { |
| 758 | /* Get rid of enqueued commands if there is no chance to | 665 | /* Get rid of enqueued commands if there is no chance to |
| 759 | * send them. */ | 666 | * send them. */ |
| 760 | if (!sbp2util_node_is_available(scsi_id)) | 667 | if (!sbp2util_node_is_available(lu)) |
| 761 | sbp2scsi_complete_all_commands(scsi_id, DID_NO_CONNECT); | 668 | sbp2scsi_complete_all_commands(lu, DID_NO_CONNECT); |
| 762 | /* scsi_remove_device() will trigger shutdown functions of SCSI | 669 | /* scsi_remove_device() may trigger shutdown functions of SCSI |
| 763 | * highlevel drivers which would deadlock if blocked. */ | 670 | * highlevel drivers which would deadlock if blocked. */ |
| 764 | atomic_set(&scsi_id->state, SBP2LU_STATE_IN_SHUTDOWN); | 671 | atomic_set(&lu->state, SBP2LU_STATE_IN_SHUTDOWN); |
| 765 | scsi_unblock_requests(scsi_id->scsi_host); | 672 | scsi_unblock_requests(lu->shost); |
| 766 | } | 673 | } |
| 767 | sdev = scsi_id->sdev; | 674 | sdev = lu->sdev; |
| 768 | if (sdev) { | 675 | if (sdev) { |
| 769 | scsi_id->sdev = NULL; | 676 | lu->sdev = NULL; |
| 770 | scsi_remove_device(sdev); | 677 | scsi_remove_device(sdev); |
| 771 | } | 678 | } |
| 772 | 679 | ||
| 773 | sbp2_logout_device(scsi_id); | 680 | sbp2_logout_device(lu); |
| 774 | sbp2_remove_device(scsi_id); | 681 | sbp2_remove_device(lu); |
| 775 | 682 | ||
| 776 | return 0; | 683 | return 0; |
| 777 | } | 684 | } |
| 778 | 685 | ||
| 779 | static int sbp2_update(struct unit_directory *ud) | 686 | static int sbp2_update(struct unit_directory *ud) |
| 780 | { | 687 | { |
| 781 | struct scsi_id_instance_data *scsi_id = ud->device.driver_data; | 688 | struct sbp2_lu *lu = ud->device.driver_data; |
| 782 | |||
| 783 | SBP2_DEBUG_ENTER(); | ||
| 784 | 689 | ||
| 785 | if (sbp2_reconnect_device(scsi_id)) { | 690 | if (sbp2_reconnect_device(lu)) { |
| 691 | /* Reconnect has failed. Perhaps we didn't reconnect fast | ||
| 692 | * enough. Try a regular login, but first log out just in | ||
| 693 | * case of any weirdness. */ | ||
| 694 | sbp2_logout_device(lu); | ||
| 786 | 695 | ||
| 787 | /* | 696 | if (sbp2_login_device(lu)) { |
| 788 | * Ok, reconnect has failed. Perhaps we didn't | ||
| 789 | * reconnect fast enough. Try doing a regular login, but | ||
| 790 | * first do a logout just in case of any weirdness. | ||
| 791 | */ | ||
| 792 | sbp2_logout_device(scsi_id); | ||
| 793 | |||
| 794 | if (sbp2_login_device(scsi_id)) { | ||
| 795 | /* Login failed too, just fail, and the backend | 697 | /* Login failed too, just fail, and the backend |
| 796 | * will call our sbp2_remove for us */ | 698 | * will call our sbp2_remove for us */ |
| 797 | SBP2_ERR("Failed to reconnect to sbp2 device!"); | 699 | SBP2_ERR("Failed to reconnect to sbp2 device!"); |
| @@ -799,69 +701,59 @@ static int sbp2_update(struct unit_directory *ud) | |||
| 799 | } | 701 | } |
| 800 | } | 702 | } |
| 801 | 703 | ||
| 802 | /* Set max retries to something large on the device. */ | 704 | sbp2_set_busy_timeout(lu); |
| 803 | sbp2_set_busy_timeout(scsi_id); | 705 | sbp2_agent_reset(lu, 1); |
| 706 | sbp2_max_speed_and_size(lu); | ||
| 804 | 707 | ||
| 805 | /* Do a SBP-2 fetch agent reset. */ | 708 | /* Complete any pending commands with busy (so they get retried) |
| 806 | sbp2_agent_reset(scsi_id, 1); | 709 | * and remove them from our queue. */ |
| 807 | 710 | sbp2scsi_complete_all_commands(lu, DID_BUS_BUSY); | |
| 808 | /* Get the max speed and packet size that we can use. */ | ||
| 809 | sbp2_max_speed_and_size(scsi_id); | ||
| 810 | |||
| 811 | /* Complete any pending commands with busy (so they get | ||
| 812 | * retried) and remove them from our queue | ||
| 813 | */ | ||
| 814 | sbp2scsi_complete_all_commands(scsi_id, DID_BUS_BUSY); | ||
| 815 | 711 | ||
| 816 | /* Accept new commands unless there was another bus reset in the | 712 | /* Accept new commands unless there was another bus reset in the |
| 817 | * meantime. */ | 713 | * meantime. */ |
| 818 | if (hpsb_node_entry_valid(scsi_id->ne)) { | 714 | if (hpsb_node_entry_valid(lu->ne)) { |
| 819 | atomic_set(&scsi_id->state, SBP2LU_STATE_RUNNING); | 715 | atomic_set(&lu->state, SBP2LU_STATE_RUNNING); |
| 820 | scsi_unblock_requests(scsi_id->scsi_host); | 716 | scsi_unblock_requests(lu->shost); |
| 821 | } | 717 | } |
| 822 | return 0; | 718 | return 0; |
| 823 | } | 719 | } |
| 824 | 720 | ||
| 825 | /* This functions is called by the sbp2_probe, for each new device. We now | 721 | static struct sbp2_lu *sbp2_alloc_device(struct unit_directory *ud) |
| 826 | * allocate one scsi host for each scsi_id (unit directory). */ | ||
| 827 | static struct scsi_id_instance_data *sbp2_alloc_device(struct unit_directory *ud) | ||
| 828 | { | 722 | { |
| 829 | struct sbp2scsi_host_info *hi; | 723 | struct sbp2_fwhost_info *hi; |
| 830 | struct Scsi_Host *scsi_host = NULL; | 724 | struct Scsi_Host *shost = NULL; |
| 831 | struct scsi_id_instance_data *scsi_id = NULL; | 725 | struct sbp2_lu *lu = NULL; |
| 832 | 726 | ||
| 833 | SBP2_DEBUG_ENTER(); | 727 | lu = kzalloc(sizeof(*lu), GFP_KERNEL); |
| 834 | 728 | if (!lu) { | |
| 835 | scsi_id = kzalloc(sizeof(*scsi_id), GFP_KERNEL); | 729 | SBP2_ERR("failed to create lu"); |
| 836 | if (!scsi_id) { | ||
| 837 | SBP2_ERR("failed to create scsi_id"); | ||
| 838 | goto failed_alloc; | 730 | goto failed_alloc; |
| 839 | } | 731 | } |
| 840 | 732 | ||
| 841 | scsi_id->ne = ud->ne; | 733 | lu->ne = ud->ne; |
| 842 | scsi_id->ud = ud; | 734 | lu->ud = ud; |
| 843 | scsi_id->speed_code = IEEE1394_SPEED_100; | 735 | lu->speed_code = IEEE1394_SPEED_100; |
| 844 | scsi_id->max_payload_size = sbp2_speedto_max_payload[IEEE1394_SPEED_100]; | 736 | lu->max_payload_size = sbp2_speedto_max_payload[IEEE1394_SPEED_100]; |
| 845 | scsi_id->status_fifo_addr = CSR1212_INVALID_ADDR_SPACE; | 737 | lu->status_fifo_addr = CSR1212_INVALID_ADDR_SPACE; |
| 846 | INIT_LIST_HEAD(&scsi_id->sbp2_command_orb_inuse); | 738 | INIT_LIST_HEAD(&lu->cmd_orb_inuse); |
| 847 | INIT_LIST_HEAD(&scsi_id->sbp2_command_orb_completed); | 739 | INIT_LIST_HEAD(&lu->cmd_orb_completed); |
| 848 | INIT_LIST_HEAD(&scsi_id->scsi_list); | 740 | INIT_LIST_HEAD(&lu->lu_list); |
| 849 | spin_lock_init(&scsi_id->sbp2_command_orb_lock); | 741 | spin_lock_init(&lu->cmd_orb_lock); |
| 850 | atomic_set(&scsi_id->state, SBP2LU_STATE_RUNNING); | 742 | atomic_set(&lu->state, SBP2LU_STATE_RUNNING); |
| 851 | INIT_DELAYED_WORK(&scsi_id->protocol_work, NULL); | 743 | INIT_WORK(&lu->protocol_work, NULL); |
| 852 | 744 | ||
| 853 | ud->device.driver_data = scsi_id; | 745 | ud->device.driver_data = lu; |
| 854 | 746 | ||
| 855 | hi = hpsb_get_hostinfo(&sbp2_highlevel, ud->ne->host); | 747 | hi = hpsb_get_hostinfo(&sbp2_highlevel, ud->ne->host); |
| 856 | if (!hi) { | 748 | if (!hi) { |
| 857 | hi = hpsb_create_hostinfo(&sbp2_highlevel, ud->ne->host, sizeof(*hi)); | 749 | hi = hpsb_create_hostinfo(&sbp2_highlevel, ud->ne->host, |
| 750 | sizeof(*hi)); | ||
| 858 | if (!hi) { | 751 | if (!hi) { |
| 859 | SBP2_ERR("failed to allocate hostinfo"); | 752 | SBP2_ERR("failed to allocate hostinfo"); |
| 860 | goto failed_alloc; | 753 | goto failed_alloc; |
| 861 | } | 754 | } |
| 862 | SBP2_DEBUG("sbp2_alloc_device: allocated hostinfo"); | ||
| 863 | hi->host = ud->ne->host; | 755 | hi->host = ud->ne->host; |
| 864 | INIT_LIST_HEAD(&hi->scsi_ids); | 756 | INIT_LIST_HEAD(&hi->logical_units); |
| 865 | 757 | ||
| 866 | #ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA | 758 | #ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA |
| 867 | /* Handle data movement if physical dma is not | 759 | /* Handle data movement if physical dma is not |
| @@ -881,9 +773,9 @@ static struct scsi_id_instance_data *sbp2_alloc_device(struct unit_directory *ud | |||
| 881 | goto failed_alloc; | 773 | goto failed_alloc; |
| 882 | } | 774 | } |
| 883 | 775 | ||
| 884 | scsi_id->hi = hi; | 776 | lu->hi = hi; |
| 885 | 777 | ||
| 886 | list_add_tail(&scsi_id->scsi_list, &hi->scsi_ids); | 778 | list_add_tail(&lu->lu_list, &hi->logical_units); |
| 887 | 779 | ||
| 888 | /* Register the status FIFO address range. We could use the same FIFO | 780 | /* Register the status FIFO address range. We could use the same FIFO |
| 889 | * for targets at different nodes. However we need different FIFOs per | 781 | * for targets at different nodes. However we need different FIFOs per |
| @@ -893,302 +785,214 @@ static struct scsi_id_instance_data *sbp2_alloc_device(struct unit_directory *ud | |||
| 893 | * then be performed as unified transactions. This slightly reduces | 785 | * then be performed as unified transactions. This slightly reduces |
| 894 | * bandwidth usage, and some Prolific based devices seem to require it. | 786 | * bandwidth usage, and some Prolific based devices seem to require it. |
| 895 | */ | 787 | */ |
| 896 | scsi_id->status_fifo_addr = hpsb_allocate_and_register_addrspace( | 788 | lu->status_fifo_addr = hpsb_allocate_and_register_addrspace( |
| 897 | &sbp2_highlevel, ud->ne->host, &sbp2_ops, | 789 | &sbp2_highlevel, ud->ne->host, &sbp2_ops, |
| 898 | sizeof(struct sbp2_status_block), sizeof(quadlet_t), | 790 | sizeof(struct sbp2_status_block), sizeof(quadlet_t), |
| 899 | ud->ne->host->low_addr_space, CSR1212_ALL_SPACE_END); | 791 | ud->ne->host->low_addr_space, CSR1212_ALL_SPACE_END); |
| 900 | if (scsi_id->status_fifo_addr == CSR1212_INVALID_ADDR_SPACE) { | 792 | if (lu->status_fifo_addr == CSR1212_INVALID_ADDR_SPACE) { |
| 901 | SBP2_ERR("failed to allocate status FIFO address range"); | 793 | SBP2_ERR("failed to allocate status FIFO address range"); |
| 902 | goto failed_alloc; | 794 | goto failed_alloc; |
| 903 | } | 795 | } |
| 904 | 796 | ||
| 905 | /* Register our host with the SCSI stack. */ | 797 | shost = scsi_host_alloc(&sbp2_shost_template, sizeof(unsigned long)); |
| 906 | scsi_host = scsi_host_alloc(&scsi_driver_template, | 798 | if (!shost) { |
| 907 | sizeof(unsigned long)); | ||
| 908 | if (!scsi_host) { | ||
| 909 | SBP2_ERR("failed to register scsi host"); | 799 | SBP2_ERR("failed to register scsi host"); |
| 910 | goto failed_alloc; | 800 | goto failed_alloc; |
| 911 | } | 801 | } |
| 912 | 802 | ||
| 913 | scsi_host->hostdata[0] = (unsigned long)scsi_id; | 803 | shost->hostdata[0] = (unsigned long)lu; |
| 914 | 804 | ||
| 915 | if (!scsi_add_host(scsi_host, &ud->device)) { | 805 | if (!scsi_add_host(shost, &ud->device)) { |
| 916 | scsi_id->scsi_host = scsi_host; | 806 | lu->shost = shost; |
| 917 | return scsi_id; | 807 | return lu; |
| 918 | } | 808 | } |
| 919 | 809 | ||
| 920 | SBP2_ERR("failed to add scsi host"); | 810 | SBP2_ERR("failed to add scsi host"); |
| 921 | scsi_host_put(scsi_host); | 811 | scsi_host_put(shost); |
| 922 | 812 | ||
| 923 | failed_alloc: | 813 | failed_alloc: |
| 924 | sbp2_remove_device(scsi_id); | 814 | sbp2_remove_device(lu); |
| 925 | return NULL; | 815 | return NULL; |
| 926 | } | 816 | } |
| 927 | 817 | ||
| 928 | static void sbp2_host_reset(struct hpsb_host *host) | 818 | static void sbp2_host_reset(struct hpsb_host *host) |
| 929 | { | 819 | { |
| 930 | struct sbp2scsi_host_info *hi; | 820 | struct sbp2_fwhost_info *hi; |
| 931 | struct scsi_id_instance_data *scsi_id; | 821 | struct sbp2_lu *lu; |
| 932 | 822 | ||
| 933 | hi = hpsb_get_hostinfo(&sbp2_highlevel, host); | 823 | hi = hpsb_get_hostinfo(&sbp2_highlevel, host); |
| 934 | if (!hi) | 824 | if (!hi) |
| 935 | return; | 825 | return; |
| 936 | list_for_each_entry(scsi_id, &hi->scsi_ids, scsi_list) | 826 | list_for_each_entry(lu, &hi->logical_units, lu_list) |
| 937 | if (likely(atomic_read(&scsi_id->state) != | 827 | if (likely(atomic_read(&lu->state) != |
| 938 | SBP2LU_STATE_IN_SHUTDOWN)) { | 828 | SBP2LU_STATE_IN_SHUTDOWN)) { |
| 939 | atomic_set(&scsi_id->state, SBP2LU_STATE_IN_RESET); | 829 | atomic_set(&lu->state, SBP2LU_STATE_IN_RESET); |
| 940 | scsi_block_requests(scsi_id->scsi_host); | 830 | scsi_block_requests(lu->shost); |
| 941 | } | 831 | } |
| 942 | } | 832 | } |
| 943 | 833 | ||
| 944 | /* | 834 | static int sbp2_start_device(struct sbp2_lu *lu) |
| 945 | * This function is where we first pull the node unique ids, and then | ||
| 946 | * allocate memory and register a SBP-2 device. | ||
| 947 | */ | ||
| 948 | static int sbp2_start_device(struct scsi_id_instance_data *scsi_id) | ||
| 949 | { | 835 | { |
| 950 | struct sbp2scsi_host_info *hi = scsi_id->hi; | 836 | struct sbp2_fwhost_info *hi = lu->hi; |
| 951 | int error; | 837 | int error; |
| 952 | 838 | ||
| 953 | SBP2_DEBUG_ENTER(); | 839 | lu->login_response = dma_alloc_coherent(&hi->host->device, |
| 954 | |||
| 955 | /* Login FIFO DMA */ | ||
| 956 | scsi_id->login_response = | ||
| 957 | pci_alloc_consistent(hi->host->pdev, | ||
| 958 | sizeof(struct sbp2_login_response), | 840 | sizeof(struct sbp2_login_response), |
| 959 | &scsi_id->login_response_dma); | 841 | &lu->login_response_dma, GFP_KERNEL); |
| 960 | if (!scsi_id->login_response) | 842 | if (!lu->login_response) |
| 961 | goto alloc_fail; | 843 | goto alloc_fail; |
| 962 | SBP2_DMA_ALLOC("consistent DMA region for login FIFO"); | ||
| 963 | 844 | ||
| 964 | /* Query logins ORB DMA */ | 845 | lu->query_logins_orb = dma_alloc_coherent(&hi->host->device, |
| 965 | scsi_id->query_logins_orb = | ||
| 966 | pci_alloc_consistent(hi->host->pdev, | ||
| 967 | sizeof(struct sbp2_query_logins_orb), | 846 | sizeof(struct sbp2_query_logins_orb), |
| 968 | &scsi_id->query_logins_orb_dma); | 847 | &lu->query_logins_orb_dma, GFP_KERNEL); |
| 969 | if (!scsi_id->query_logins_orb) | 848 | if (!lu->query_logins_orb) |
| 970 | goto alloc_fail; | 849 | goto alloc_fail; |
| 971 | SBP2_DMA_ALLOC("consistent DMA region for query logins ORB"); | ||
| 972 | 850 | ||
| 973 | /* Query logins response DMA */ | 851 | lu->query_logins_response = dma_alloc_coherent(&hi->host->device, |
| 974 | scsi_id->query_logins_response = | ||
| 975 | pci_alloc_consistent(hi->host->pdev, | ||
| 976 | sizeof(struct sbp2_query_logins_response), | 852 | sizeof(struct sbp2_query_logins_response), |
| 977 | &scsi_id->query_logins_response_dma); | 853 | &lu->query_logins_response_dma, GFP_KERNEL); |
| 978 | if (!scsi_id->query_logins_response) | 854 | if (!lu->query_logins_response) |
| 979 | goto alloc_fail; | 855 | goto alloc_fail; |
| 980 | SBP2_DMA_ALLOC("consistent DMA region for query logins response"); | ||
| 981 | 856 | ||
| 982 | /* Reconnect ORB DMA */ | 857 | lu->reconnect_orb = dma_alloc_coherent(&hi->host->device, |
| 983 | scsi_id->reconnect_orb = | ||
| 984 | pci_alloc_consistent(hi->host->pdev, | ||
| 985 | sizeof(struct sbp2_reconnect_orb), | 858 | sizeof(struct sbp2_reconnect_orb), |
| 986 | &scsi_id->reconnect_orb_dma); | 859 | &lu->reconnect_orb_dma, GFP_KERNEL); |
| 987 | if (!scsi_id->reconnect_orb) | 860 | if (!lu->reconnect_orb) |
| 988 | goto alloc_fail; | 861 | goto alloc_fail; |
| 989 | SBP2_DMA_ALLOC("consistent DMA region for reconnect ORB"); | ||
| 990 | 862 | ||
| 991 | /* Logout ORB DMA */ | 863 | lu->logout_orb = dma_alloc_coherent(&hi->host->device, |
| 992 | scsi_id->logout_orb = | ||
| 993 | pci_alloc_consistent(hi->host->pdev, | ||
| 994 | sizeof(struct sbp2_logout_orb), | 864 | sizeof(struct sbp2_logout_orb), |
| 995 | &scsi_id->logout_orb_dma); | 865 | &lu->logout_orb_dma, GFP_KERNEL); |
| 996 | if (!scsi_id->logout_orb) | 866 | if (!lu->logout_orb) |
| 997 | goto alloc_fail; | 867 | goto alloc_fail; |
| 998 | SBP2_DMA_ALLOC("consistent DMA region for logout ORB"); | ||
| 999 | 868 | ||
| 1000 | /* Login ORB DMA */ | 869 | lu->login_orb = dma_alloc_coherent(&hi->host->device, |
| 1001 | scsi_id->login_orb = | ||
| 1002 | pci_alloc_consistent(hi->host->pdev, | ||
| 1003 | sizeof(struct sbp2_login_orb), | 870 | sizeof(struct sbp2_login_orb), |
| 1004 | &scsi_id->login_orb_dma); | 871 | &lu->login_orb_dma, GFP_KERNEL); |
| 1005 | if (!scsi_id->login_orb) | 872 | if (!lu->login_orb) |
| 1006 | goto alloc_fail; | 873 | goto alloc_fail; |
| 1007 | SBP2_DMA_ALLOC("consistent DMA region for login ORB"); | ||
| 1008 | |||
| 1009 | SBP2_DEBUG("New SBP-2 device inserted, SCSI ID = %x", scsi_id->ud->id); | ||
| 1010 | 874 | ||
| 1011 | /* | 875 | if (sbp2util_create_command_orb_pool(lu)) { |
| 1012 | * Create our command orb pool | ||
| 1013 | */ | ||
| 1014 | if (sbp2util_create_command_orb_pool(scsi_id)) { | ||
| 1015 | SBP2_ERR("sbp2util_create_command_orb_pool failed!"); | 876 | SBP2_ERR("sbp2util_create_command_orb_pool failed!"); |
| 1016 | sbp2_remove_device(scsi_id); | 877 | sbp2_remove_device(lu); |
| 1017 | return -ENOMEM; | 878 | return -ENOMEM; |
| 1018 | } | 879 | } |
| 1019 | 880 | ||
| 1020 | /* Schedule a timeout here. The reason is that we may be so close | 881 | /* Wait a second before trying to log in. Previously logged in |
| 1021 | * to a bus reset, that the device is not available for logins. | 882 | * initiators need a chance to reconnect. */ |
| 1022 | * This can happen when the bus reset is caused by the host | ||
| 1023 | * connected to the sbp2 device being removed. That host would | ||
| 1024 | * have a certain amount of time to relogin before the sbp2 device | ||
| 1025 | * allows someone else to login instead. One second makes sense. */ | ||
| 1026 | if (msleep_interruptible(1000)) { | 883 | if (msleep_interruptible(1000)) { |
| 1027 | sbp2_remove_device(scsi_id); | 884 | sbp2_remove_device(lu); |
| 1028 | return -EINTR; | 885 | return -EINTR; |
| 1029 | } | 886 | } |
| 1030 | 887 | ||
| 1031 | /* | 888 | if (sbp2_login_device(lu)) { |
| 1032 | * Login to the sbp-2 device | 889 | sbp2_remove_device(lu); |
| 1033 | */ | ||
| 1034 | if (sbp2_login_device(scsi_id)) { | ||
| 1035 | /* Login failed, just remove the device. */ | ||
| 1036 | sbp2_remove_device(scsi_id); | ||
| 1037 | return -EBUSY; | 890 | return -EBUSY; |
| 1038 | } | 891 | } |
| 1039 | 892 | ||
| 1040 | /* | 893 | sbp2_set_busy_timeout(lu); |
| 1041 | * Set max retries to something large on the device | 894 | sbp2_agent_reset(lu, 1); |
| 1042 | */ | 895 | sbp2_max_speed_and_size(lu); |
| 1043 | sbp2_set_busy_timeout(scsi_id); | ||
| 1044 | |||
| 1045 | /* | ||
| 1046 | * Do a SBP-2 fetch agent reset | ||
| 1047 | */ | ||
| 1048 | sbp2_agent_reset(scsi_id, 1); | ||
| 1049 | 896 | ||
| 1050 | /* | 897 | error = scsi_add_device(lu->shost, 0, lu->ud->id, 0); |
| 1051 | * Get the max speed and packet size that we can use | ||
| 1052 | */ | ||
| 1053 | sbp2_max_speed_and_size(scsi_id); | ||
| 1054 | |||
| 1055 | /* Add this device to the scsi layer now */ | ||
| 1056 | error = scsi_add_device(scsi_id->scsi_host, 0, scsi_id->ud->id, 0); | ||
| 1057 | if (error) { | 898 | if (error) { |
| 1058 | SBP2_ERR("scsi_add_device failed"); | 899 | SBP2_ERR("scsi_add_device failed"); |
| 1059 | sbp2_logout_device(scsi_id); | 900 | sbp2_logout_device(lu); |
| 1060 | sbp2_remove_device(scsi_id); | 901 | sbp2_remove_device(lu); |
| 1061 | return error; | 902 | return error; |
| 1062 | } | 903 | } |
| 1063 | 904 | ||
| 1064 | return 0; | 905 | return 0; |
| 1065 | 906 | ||
| 1066 | alloc_fail: | 907 | alloc_fail: |
| 1067 | SBP2_ERR("Could not allocate memory for scsi_id"); | 908 | SBP2_ERR("Could not allocate memory for lu"); |
| 1068 | sbp2_remove_device(scsi_id); | 909 | sbp2_remove_device(lu); |
| 1069 | return -ENOMEM; | 910 | return -ENOMEM; |
| 1070 | } | 911 | } |
| 1071 | 912 | ||
| 1072 | /* | 913 | static void sbp2_remove_device(struct sbp2_lu *lu) |
| 1073 | * This function removes an sbp2 device from the sbp2scsi_host_info struct. | ||
| 1074 | */ | ||
| 1075 | static void sbp2_remove_device(struct scsi_id_instance_data *scsi_id) | ||
| 1076 | { | 914 | { |
| 1077 | struct sbp2scsi_host_info *hi; | 915 | struct sbp2_fwhost_info *hi; |
| 1078 | |||
| 1079 | SBP2_DEBUG_ENTER(); | ||
| 1080 | 916 | ||
| 1081 | if (!scsi_id) | 917 | if (!lu) |
| 1082 | return; | 918 | return; |
| 1083 | 919 | ||
| 1084 | hi = scsi_id->hi; | 920 | hi = lu->hi; |
| 1085 | 921 | ||
| 1086 | /* This will remove our scsi device aswell */ | 922 | if (lu->shost) { |
| 1087 | if (scsi_id->scsi_host) { | 923 | scsi_remove_host(lu->shost); |
| 1088 | scsi_remove_host(scsi_id->scsi_host); | 924 | scsi_host_put(lu->shost); |
| 1089 | scsi_host_put(scsi_id->scsi_host); | ||
| 1090 | } | 925 | } |
| 1091 | flush_scheduled_work(); | 926 | flush_scheduled_work(); |
| 1092 | sbp2util_remove_command_orb_pool(scsi_id); | 927 | sbp2util_remove_command_orb_pool(lu); |
| 1093 | 928 | ||
| 1094 | list_del(&scsi_id->scsi_list); | 929 | list_del(&lu->lu_list); |
| 1095 | 930 | ||
| 1096 | if (scsi_id->login_response) { | 931 | if (lu->login_response) |
| 1097 | pci_free_consistent(hi->host->pdev, | 932 | dma_free_coherent(&hi->host->device, |
| 1098 | sizeof(struct sbp2_login_response), | 933 | sizeof(struct sbp2_login_response), |
| 1099 | scsi_id->login_response, | 934 | lu->login_response, |
| 1100 | scsi_id->login_response_dma); | 935 | lu->login_response_dma); |
| 1101 | SBP2_DMA_FREE("single login FIFO"); | 936 | if (lu->login_orb) |
| 1102 | } | 937 | dma_free_coherent(&hi->host->device, |
| 1103 | |||
| 1104 | if (scsi_id->login_orb) { | ||
| 1105 | pci_free_consistent(hi->host->pdev, | ||
| 1106 | sizeof(struct sbp2_login_orb), | 938 | sizeof(struct sbp2_login_orb), |
| 1107 | scsi_id->login_orb, | 939 | lu->login_orb, |
| 1108 | scsi_id->login_orb_dma); | 940 | lu->login_orb_dma); |
| 1109 | SBP2_DMA_FREE("single login ORB"); | 941 | if (lu->reconnect_orb) |
| 1110 | } | 942 | dma_free_coherent(&hi->host->device, |
| 1111 | |||
| 1112 | if (scsi_id->reconnect_orb) { | ||
| 1113 | pci_free_consistent(hi->host->pdev, | ||
| 1114 | sizeof(struct sbp2_reconnect_orb), | 943 | sizeof(struct sbp2_reconnect_orb), |
| 1115 | scsi_id->reconnect_orb, | 944 | lu->reconnect_orb, |
| 1116 | scsi_id->reconnect_orb_dma); | 945 | lu->reconnect_orb_dma); |
| 1117 | SBP2_DMA_FREE("single reconnect orb"); | 946 | if (lu->logout_orb) |
| 1118 | } | 947 | dma_free_coherent(&hi->host->device, |
| 1119 | |||
| 1120 | if (scsi_id->logout_orb) { | ||
| 1121 | pci_free_consistent(hi->host->pdev, | ||
| 1122 | sizeof(struct sbp2_logout_orb), | 948 | sizeof(struct sbp2_logout_orb), |
| 1123 | scsi_id->logout_orb, | 949 | lu->logout_orb, |
| 1124 | scsi_id->logout_orb_dma); | 950 | lu->logout_orb_dma); |
| 1125 | SBP2_DMA_FREE("single logout orb"); | 951 | if (lu->query_logins_orb) |
| 1126 | } | 952 | dma_free_coherent(&hi->host->device, |
| 1127 | |||
| 1128 | if (scsi_id->query_logins_orb) { | ||
| 1129 | pci_free_consistent(hi->host->pdev, | ||
| 1130 | sizeof(struct sbp2_query_logins_orb), | 953 | sizeof(struct sbp2_query_logins_orb), |
| 1131 | scsi_id->query_logins_orb, | 954 | lu->query_logins_orb, |
| 1132 | scsi_id->query_logins_orb_dma); | 955 | lu->query_logins_orb_dma); |
| 1133 | SBP2_DMA_FREE("single query logins orb"); | 956 | if (lu->query_logins_response) |
| 1134 | } | 957 | dma_free_coherent(&hi->host->device, |
| 1135 | |||
| 1136 | if (scsi_id->query_logins_response) { | ||
| 1137 | pci_free_consistent(hi->host->pdev, | ||
| 1138 | sizeof(struct sbp2_query_logins_response), | 958 | sizeof(struct sbp2_query_logins_response), |
| 1139 | scsi_id->query_logins_response, | 959 | lu->query_logins_response, |
| 1140 | scsi_id->query_logins_response_dma); | 960 | lu->query_logins_response_dma); |
| 1141 | SBP2_DMA_FREE("single query logins data"); | ||
| 1142 | } | ||
| 1143 | 961 | ||
| 1144 | if (scsi_id->status_fifo_addr != CSR1212_INVALID_ADDR_SPACE) | 962 | if (lu->status_fifo_addr != CSR1212_INVALID_ADDR_SPACE) |
| 1145 | hpsb_unregister_addrspace(&sbp2_highlevel, hi->host, | 963 | hpsb_unregister_addrspace(&sbp2_highlevel, hi->host, |
| 1146 | scsi_id->status_fifo_addr); | 964 | lu->status_fifo_addr); |
| 1147 | 965 | ||
| 1148 | scsi_id->ud->device.driver_data = NULL; | 966 | lu->ud->device.driver_data = NULL; |
| 1149 | 967 | ||
| 1150 | if (hi) | 968 | if (hi) |
| 1151 | module_put(hi->host->driver->owner); | 969 | module_put(hi->host->driver->owner); |
| 1152 | 970 | ||
| 1153 | SBP2_DEBUG("SBP-2 device removed, SCSI ID = %d", scsi_id->ud->id); | 971 | kfree(lu); |
| 1154 | |||
| 1155 | kfree(scsi_id); | ||
| 1156 | } | 972 | } |
| 1157 | 973 | ||
| 1158 | #ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA | 974 | #ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA |
| 1159 | /* | 975 | /* |
| 1160 | * This function deals with physical dma write requests (for adapters that do not support | 976 | * Deal with write requests on adapters which do not support physical DMA or |
| 1161 | * physical dma in hardware). Mostly just here for debugging... | 977 | * have it switched off. |
| 1162 | */ | 978 | */ |
| 1163 | static int sbp2_handle_physdma_write(struct hpsb_host *host, int nodeid, | 979 | static int sbp2_handle_physdma_write(struct hpsb_host *host, int nodeid, |
| 1164 | int destid, quadlet_t *data, u64 addr, | 980 | int destid, quadlet_t *data, u64 addr, |
| 1165 | size_t length, u16 flags) | 981 | size_t length, u16 flags) |
| 1166 | { | 982 | { |
| 1167 | |||
| 1168 | /* | ||
| 1169 | * Manually put the data in the right place. | ||
| 1170 | */ | ||
| 1171 | memcpy(bus_to_virt((u32) addr), data, length); | 983 | memcpy(bus_to_virt((u32) addr), data, length); |
| 1172 | sbp2util_packet_dump(data, length, "sbp2 phys dma write by device", | ||
| 1173 | (u32) addr); | ||
| 1174 | return RCODE_COMPLETE; | 984 | return RCODE_COMPLETE; |
| 1175 | } | 985 | } |
| 1176 | 986 | ||
| 1177 | /* | 987 | /* |
| 1178 | * This function deals with physical dma read requests (for adapters that do not support | 988 | * Deal with read requests on adapters which do not support physical DMA or |
| 1179 | * physical dma in hardware). Mostly just here for debugging... | 989 | * have it switched off. |
| 1180 | */ | 990 | */ |
| 1181 | static int sbp2_handle_physdma_read(struct hpsb_host *host, int nodeid, | 991 | static int sbp2_handle_physdma_read(struct hpsb_host *host, int nodeid, |
| 1182 | quadlet_t *data, u64 addr, size_t length, | 992 | quadlet_t *data, u64 addr, size_t length, |
| 1183 | u16 flags) | 993 | u16 flags) |
| 1184 | { | 994 | { |
| 1185 | |||
| 1186 | /* | ||
| 1187 | * Grab data from memory and send a read response. | ||
| 1188 | */ | ||
| 1189 | memcpy(data, bus_to_virt((u32) addr), length); | 995 | memcpy(data, bus_to_virt((u32) addr), length); |
| 1190 | sbp2util_packet_dump(data, length, "sbp2 phys dma read by device", | ||
| 1191 | (u32) addr); | ||
| 1192 | return RCODE_COMPLETE; | 996 | return RCODE_COMPLETE; |
| 1193 | } | 997 | } |
| 1194 | #endif | 998 | #endif |
| @@ -1197,74 +1001,69 @@ static int sbp2_handle_physdma_read(struct hpsb_host *host, int nodeid, | |||
| 1197 | * SBP-2 protocol related section | 1001 | * SBP-2 protocol related section |
| 1198 | **************************************/ | 1002 | **************************************/ |
| 1199 | 1003 | ||
| 1200 | /* | 1004 | static int sbp2_query_logins(struct sbp2_lu *lu) |
| 1201 | * This function queries the device for the maximum concurrent logins it | ||
| 1202 | * supports. | ||
| 1203 | */ | ||
| 1204 | static int sbp2_query_logins(struct scsi_id_instance_data *scsi_id) | ||
| 1205 | { | 1005 | { |
| 1206 | struct sbp2scsi_host_info *hi = scsi_id->hi; | 1006 | struct sbp2_fwhost_info *hi = lu->hi; |
| 1207 | quadlet_t data[2]; | 1007 | quadlet_t data[2]; |
| 1208 | int max_logins; | 1008 | int max_logins; |
| 1209 | int active_logins; | 1009 | int active_logins; |
| 1210 | 1010 | ||
| 1211 | SBP2_DEBUG_ENTER(); | 1011 | lu->query_logins_orb->reserved1 = 0x0; |
| 1212 | 1012 | lu->query_logins_orb->reserved2 = 0x0; | |
| 1213 | scsi_id->query_logins_orb->reserved1 = 0x0; | ||
| 1214 | scsi_id->query_logins_orb->reserved2 = 0x0; | ||
| 1215 | |||
| 1216 | scsi_id->query_logins_orb->query_response_lo = scsi_id->query_logins_response_dma; | ||
| 1217 | scsi_id->query_logins_orb->query_response_hi = ORB_SET_NODE_ID(hi->host->node_id); | ||
| 1218 | 1013 | ||
| 1219 | scsi_id->query_logins_orb->lun_misc = ORB_SET_FUNCTION(SBP2_QUERY_LOGINS_REQUEST); | 1014 | lu->query_logins_orb->query_response_lo = lu->query_logins_response_dma; |
| 1220 | scsi_id->query_logins_orb->lun_misc |= ORB_SET_NOTIFY(1); | 1015 | lu->query_logins_orb->query_response_hi = |
| 1221 | scsi_id->query_logins_orb->lun_misc |= ORB_SET_LUN(scsi_id->sbp2_lun); | 1016 | ORB_SET_NODE_ID(hi->host->node_id); |
| 1017 | lu->query_logins_orb->lun_misc = | ||
| 1018 | ORB_SET_FUNCTION(SBP2_QUERY_LOGINS_REQUEST); | ||
| 1019 | lu->query_logins_orb->lun_misc |= ORB_SET_NOTIFY(1); | ||
| 1020 | lu->query_logins_orb->lun_misc |= ORB_SET_LUN(lu->lun); | ||
| 1222 | 1021 | ||
| 1223 | scsi_id->query_logins_orb->reserved_resp_length = | 1022 | lu->query_logins_orb->reserved_resp_length = |
| 1224 | ORB_SET_QUERY_LOGINS_RESP_LENGTH(sizeof(struct sbp2_query_logins_response)); | 1023 | ORB_SET_QUERY_LOGINS_RESP_LENGTH( |
| 1024 | sizeof(struct sbp2_query_logins_response)); | ||
| 1225 | 1025 | ||
| 1226 | scsi_id->query_logins_orb->status_fifo_hi = | 1026 | lu->query_logins_orb->status_fifo_hi = |
| 1227 | ORB_SET_STATUS_FIFO_HI(scsi_id->status_fifo_addr, hi->host->node_id); | 1027 | ORB_SET_STATUS_FIFO_HI(lu->status_fifo_addr, hi->host->node_id); |
| 1228 | scsi_id->query_logins_orb->status_fifo_lo = | 1028 | lu->query_logins_orb->status_fifo_lo = |
| 1229 | ORB_SET_STATUS_FIFO_LO(scsi_id->status_fifo_addr); | 1029 | ORB_SET_STATUS_FIFO_LO(lu->status_fifo_addr); |
| 1230 | 1030 | ||
| 1231 | sbp2util_cpu_to_be32_buffer(scsi_id->query_logins_orb, sizeof(struct sbp2_query_logins_orb)); | 1031 | sbp2util_cpu_to_be32_buffer(lu->query_logins_orb, |
| 1032 | sizeof(struct sbp2_query_logins_orb)); | ||
| 1232 | 1033 | ||
| 1233 | sbp2util_packet_dump(scsi_id->query_logins_orb, sizeof(struct sbp2_query_logins_orb), | 1034 | memset(lu->query_logins_response, 0, |
| 1234 | "sbp2 query logins orb", scsi_id->query_logins_orb_dma); | 1035 | sizeof(struct sbp2_query_logins_response)); |
| 1235 | |||
| 1236 | memset(scsi_id->query_logins_response, 0, sizeof(struct sbp2_query_logins_response)); | ||
| 1237 | 1036 | ||
| 1238 | data[0] = ORB_SET_NODE_ID(hi->host->node_id); | 1037 | data[0] = ORB_SET_NODE_ID(hi->host->node_id); |
| 1239 | data[1] = scsi_id->query_logins_orb_dma; | 1038 | data[1] = lu->query_logins_orb_dma; |
| 1240 | sbp2util_cpu_to_be32_buffer(data, 8); | 1039 | sbp2util_cpu_to_be32_buffer(data, 8); |
| 1241 | 1040 | ||
| 1242 | hpsb_node_write(scsi_id->ne, scsi_id->sbp2_management_agent_addr, data, 8); | 1041 | hpsb_node_write(lu->ne, lu->management_agent_addr, data, 8); |
| 1243 | 1042 | ||
| 1244 | if (sbp2util_access_timeout(scsi_id, 2*HZ)) { | 1043 | if (sbp2util_access_timeout(lu, 2*HZ)) { |
| 1245 | SBP2_INFO("Error querying logins to SBP-2 device - timed out"); | 1044 | SBP2_INFO("Error querying logins to SBP-2 device - timed out"); |
| 1246 | return -EIO; | 1045 | return -EIO; |
| 1247 | } | 1046 | } |
| 1248 | 1047 | ||
| 1249 | if (scsi_id->status_block.ORB_offset_lo != scsi_id->query_logins_orb_dma) { | 1048 | if (lu->status_block.ORB_offset_lo != lu->query_logins_orb_dma) { |
| 1250 | SBP2_INFO("Error querying logins to SBP-2 device - timed out"); | 1049 | SBP2_INFO("Error querying logins to SBP-2 device - timed out"); |
| 1251 | return -EIO; | 1050 | return -EIO; |
| 1252 | } | 1051 | } |
| 1253 | 1052 | ||
| 1254 | if (STATUS_TEST_RDS(scsi_id->status_block.ORB_offset_hi_misc)) { | 1053 | if (STATUS_TEST_RDS(lu->status_block.ORB_offset_hi_misc)) { |
| 1255 | SBP2_INFO("Error querying logins to SBP-2 device - failed"); | 1054 | SBP2_INFO("Error querying logins to SBP-2 device - failed"); |
| 1256 | return -EIO; | 1055 | return -EIO; |
| 1257 | } | 1056 | } |
| 1258 | 1057 | ||
| 1259 | sbp2util_cpu_to_be32_buffer(scsi_id->query_logins_response, sizeof(struct sbp2_query_logins_response)); | 1058 | sbp2util_cpu_to_be32_buffer(lu->query_logins_response, |
| 1260 | 1059 | sizeof(struct sbp2_query_logins_response)); | |
| 1261 | SBP2_DEBUG("length_max_logins = %x", | ||
| 1262 | (unsigned int)scsi_id->query_logins_response->length_max_logins); | ||
| 1263 | 1060 | ||
| 1264 | max_logins = RESPONSE_GET_MAX_LOGINS(scsi_id->query_logins_response->length_max_logins); | 1061 | max_logins = RESPONSE_GET_MAX_LOGINS( |
| 1062 | lu->query_logins_response->length_max_logins); | ||
| 1265 | SBP2_INFO("Maximum concurrent logins supported: %d", max_logins); | 1063 | SBP2_INFO("Maximum concurrent logins supported: %d", max_logins); |
| 1266 | 1064 | ||
| 1267 | active_logins = RESPONSE_GET_ACTIVE_LOGINS(scsi_id->query_logins_response->length_max_logins); | 1065 | active_logins = RESPONSE_GET_ACTIVE_LOGINS( |
| 1066 | lu->query_logins_response->length_max_logins); | ||
| 1268 | SBP2_INFO("Number of active logins: %d", active_logins); | 1067 | SBP2_INFO("Number of active logins: %d", active_logins); |
| 1269 | 1068 | ||
| 1270 | if (active_logins >= max_logins) { | 1069 | if (active_logins >= max_logins) { |
| @@ -1274,332 +1073,231 @@ static int sbp2_query_logins(struct scsi_id_instance_data *scsi_id) | |||
| 1274 | return 0; | 1073 | return 0; |
| 1275 | } | 1074 | } |
| 1276 | 1075 | ||
| 1277 | /* | 1076 | static int sbp2_login_device(struct sbp2_lu *lu) |
| 1278 | * This function is called in order to login to a particular SBP-2 device, | ||
| 1279 | * after a bus reset. | ||
| 1280 | */ | ||
| 1281 | static int sbp2_login_device(struct scsi_id_instance_data *scsi_id) | ||
| 1282 | { | 1077 | { |
| 1283 | struct sbp2scsi_host_info *hi = scsi_id->hi; | 1078 | struct sbp2_fwhost_info *hi = lu->hi; |
| 1284 | quadlet_t data[2]; | 1079 | quadlet_t data[2]; |
| 1285 | 1080 | ||
| 1286 | SBP2_DEBUG_ENTER(); | 1081 | if (!lu->login_orb) |
| 1287 | |||
| 1288 | if (!scsi_id->login_orb) { | ||
| 1289 | SBP2_DEBUG("%s: login_orb not alloc'd!", __FUNCTION__); | ||
| 1290 | return -EIO; | 1082 | return -EIO; |
| 1291 | } | ||
| 1292 | 1083 | ||
| 1293 | if (!exclusive_login) { | 1084 | if (!sbp2_exclusive_login && sbp2_query_logins(lu)) { |
| 1294 | if (sbp2_query_logins(scsi_id)) { | 1085 | SBP2_INFO("Device does not support any more concurrent logins"); |
| 1295 | SBP2_INFO("Device does not support any more concurrent logins"); | 1086 | return -EIO; |
| 1296 | return -EIO; | ||
| 1297 | } | ||
| 1298 | } | 1087 | } |
| 1299 | 1088 | ||
| 1300 | /* Set-up login ORB, assume no password */ | 1089 | /* assume no password */ |
| 1301 | scsi_id->login_orb->password_hi = 0; | 1090 | lu->login_orb->password_hi = 0; |
| 1302 | scsi_id->login_orb->password_lo = 0; | 1091 | lu->login_orb->password_lo = 0; |
| 1303 | 1092 | ||
| 1304 | scsi_id->login_orb->login_response_lo = scsi_id->login_response_dma; | 1093 | lu->login_orb->login_response_lo = lu->login_response_dma; |
| 1305 | scsi_id->login_orb->login_response_hi = ORB_SET_NODE_ID(hi->host->node_id); | 1094 | lu->login_orb->login_response_hi = ORB_SET_NODE_ID(hi->host->node_id); |
| 1095 | lu->login_orb->lun_misc = ORB_SET_FUNCTION(SBP2_LOGIN_REQUEST); | ||
| 1306 | 1096 | ||
| 1307 | scsi_id->login_orb->lun_misc = ORB_SET_FUNCTION(SBP2_LOGIN_REQUEST); | 1097 | /* one second reconnect time */ |
| 1308 | scsi_id->login_orb->lun_misc |= ORB_SET_RECONNECT(0); /* One second reconnect time */ | 1098 | lu->login_orb->lun_misc |= ORB_SET_RECONNECT(0); |
| 1309 | scsi_id->login_orb->lun_misc |= ORB_SET_EXCLUSIVE(exclusive_login); /* Exclusive access to device */ | 1099 | lu->login_orb->lun_misc |= ORB_SET_EXCLUSIVE(sbp2_exclusive_login); |
| 1310 | scsi_id->login_orb->lun_misc |= ORB_SET_NOTIFY(1); /* Notify us of login complete */ | 1100 | lu->login_orb->lun_misc |= ORB_SET_NOTIFY(1); |
| 1311 | scsi_id->login_orb->lun_misc |= ORB_SET_LUN(scsi_id->sbp2_lun); | 1101 | lu->login_orb->lun_misc |= ORB_SET_LUN(lu->lun); |
| 1312 | 1102 | ||
| 1313 | scsi_id->login_orb->passwd_resp_lengths = | 1103 | lu->login_orb->passwd_resp_lengths = |
| 1314 | ORB_SET_LOGIN_RESP_LENGTH(sizeof(struct sbp2_login_response)); | 1104 | ORB_SET_LOGIN_RESP_LENGTH(sizeof(struct sbp2_login_response)); |
| 1315 | 1105 | ||
| 1316 | scsi_id->login_orb->status_fifo_hi = | 1106 | lu->login_orb->status_fifo_hi = |
| 1317 | ORB_SET_STATUS_FIFO_HI(scsi_id->status_fifo_addr, hi->host->node_id); | 1107 | ORB_SET_STATUS_FIFO_HI(lu->status_fifo_addr, hi->host->node_id); |
| 1318 | scsi_id->login_orb->status_fifo_lo = | 1108 | lu->login_orb->status_fifo_lo = |
| 1319 | ORB_SET_STATUS_FIFO_LO(scsi_id->status_fifo_addr); | 1109 | ORB_SET_STATUS_FIFO_LO(lu->status_fifo_addr); |
| 1320 | 1110 | ||
| 1321 | sbp2util_cpu_to_be32_buffer(scsi_id->login_orb, sizeof(struct sbp2_login_orb)); | 1111 | sbp2util_cpu_to_be32_buffer(lu->login_orb, |
| 1112 | sizeof(struct sbp2_login_orb)); | ||
| 1322 | 1113 | ||
| 1323 | sbp2util_packet_dump(scsi_id->login_orb, sizeof(struct sbp2_login_orb), | 1114 | memset(lu->login_response, 0, sizeof(struct sbp2_login_response)); |
| 1324 | "sbp2 login orb", scsi_id->login_orb_dma); | ||
| 1325 | |||
| 1326 | memset(scsi_id->login_response, 0, sizeof(struct sbp2_login_response)); | ||
| 1327 | 1115 | ||
| 1328 | data[0] = ORB_SET_NODE_ID(hi->host->node_id); | 1116 | data[0] = ORB_SET_NODE_ID(hi->host->node_id); |
| 1329 | data[1] = scsi_id->login_orb_dma; | 1117 | data[1] = lu->login_orb_dma; |
| 1330 | sbp2util_cpu_to_be32_buffer(data, 8); | 1118 | sbp2util_cpu_to_be32_buffer(data, 8); |
| 1331 | 1119 | ||
| 1332 | hpsb_node_write(scsi_id->ne, scsi_id->sbp2_management_agent_addr, data, 8); | 1120 | hpsb_node_write(lu->ne, lu->management_agent_addr, data, 8); |
| 1333 | 1121 | ||
| 1334 | /* | 1122 | /* wait up to 20 seconds for login status */ |
| 1335 | * Wait for login status (up to 20 seconds)... | 1123 | if (sbp2util_access_timeout(lu, 20*HZ)) { |
| 1336 | */ | ||
| 1337 | if (sbp2util_access_timeout(scsi_id, 20*HZ)) { | ||
| 1338 | SBP2_ERR("Error logging into SBP-2 device - timed out"); | 1124 | SBP2_ERR("Error logging into SBP-2 device - timed out"); |
| 1339 | return -EIO; | 1125 | return -EIO; |
| 1340 | } | 1126 | } |
| 1341 | 1127 | ||
| 1342 | /* | 1128 | /* make sure that the returned status matches the login ORB */ |
| 1343 | * Sanity. Make sure status returned matches login orb. | 1129 | if (lu->status_block.ORB_offset_lo != lu->login_orb_dma) { |
| 1344 | */ | ||
| 1345 | if (scsi_id->status_block.ORB_offset_lo != scsi_id->login_orb_dma) { | ||
| 1346 | SBP2_ERR("Error logging into SBP-2 device - timed out"); | 1130 | SBP2_ERR("Error logging into SBP-2 device - timed out"); |
| 1347 | return -EIO; | 1131 | return -EIO; |
| 1348 | } | 1132 | } |
| 1349 | 1133 | ||
| 1350 | if (STATUS_TEST_RDS(scsi_id->status_block.ORB_offset_hi_misc)) { | 1134 | if (STATUS_TEST_RDS(lu->status_block.ORB_offset_hi_misc)) { |
| 1351 | SBP2_ERR("Error logging into SBP-2 device - failed"); | 1135 | SBP2_ERR("Error logging into SBP-2 device - failed"); |
| 1352 | return -EIO; | 1136 | return -EIO; |
| 1353 | } | 1137 | } |
| 1354 | 1138 | ||
| 1355 | /* | 1139 | sbp2util_cpu_to_be32_buffer(lu->login_response, |
| 1356 | * Byte swap the login response, for use when reconnecting or | 1140 | sizeof(struct sbp2_login_response)); |
| 1357 | * logging out. | 1141 | lu->command_block_agent_addr = |
| 1358 | */ | 1142 | ((u64)lu->login_response->command_block_agent_hi) << 32; |
| 1359 | sbp2util_cpu_to_be32_buffer(scsi_id->login_response, sizeof(struct sbp2_login_response)); | 1143 | lu->command_block_agent_addr |= |
| 1360 | 1144 | ((u64)lu->login_response->command_block_agent_lo); | |
| 1361 | /* | 1145 | lu->command_block_agent_addr &= 0x0000ffffffffffffULL; |
| 1362 | * Grab our command block agent address from the login response. | ||
| 1363 | */ | ||
| 1364 | SBP2_DEBUG("command_block_agent_hi = %x", | ||
| 1365 | (unsigned int)scsi_id->login_response->command_block_agent_hi); | ||
| 1366 | SBP2_DEBUG("command_block_agent_lo = %x", | ||
| 1367 | (unsigned int)scsi_id->login_response->command_block_agent_lo); | ||
| 1368 | |||
| 1369 | scsi_id->sbp2_command_block_agent_addr = | ||
| 1370 | ((u64)scsi_id->login_response->command_block_agent_hi) << 32; | ||
| 1371 | scsi_id->sbp2_command_block_agent_addr |= ((u64)scsi_id->login_response->command_block_agent_lo); | ||
| 1372 | scsi_id->sbp2_command_block_agent_addr &= 0x0000ffffffffffffULL; | ||
| 1373 | 1146 | ||
| 1374 | SBP2_INFO("Logged into SBP-2 device"); | 1147 | SBP2_INFO("Logged into SBP-2 device"); |
| 1375 | return 0; | 1148 | return 0; |
| 1376 | } | 1149 | } |
| 1377 | 1150 | ||
| 1378 | /* | 1151 | static int sbp2_logout_device(struct sbp2_lu *lu) |
| 1379 | * This function is called in order to logout from a particular SBP-2 | ||
| 1380 | * device, usually called during driver unload. | ||
| 1381 | */ | ||
| 1382 | static int sbp2_logout_device(struct scsi_id_instance_data *scsi_id) | ||
| 1383 | { | 1152 | { |
| 1384 | struct sbp2scsi_host_info *hi = scsi_id->hi; | 1153 | struct sbp2_fwhost_info *hi = lu->hi; |
| 1385 | quadlet_t data[2]; | 1154 | quadlet_t data[2]; |
| 1386 | int error; | 1155 | int error; |
| 1387 | 1156 | ||
| 1388 | SBP2_DEBUG_ENTER(); | 1157 | lu->logout_orb->reserved1 = 0x0; |
| 1389 | 1158 | lu->logout_orb->reserved2 = 0x0; | |
| 1390 | /* | 1159 | lu->logout_orb->reserved3 = 0x0; |
| 1391 | * Set-up logout ORB | 1160 | lu->logout_orb->reserved4 = 0x0; |
| 1392 | */ | ||
| 1393 | scsi_id->logout_orb->reserved1 = 0x0; | ||
| 1394 | scsi_id->logout_orb->reserved2 = 0x0; | ||
| 1395 | scsi_id->logout_orb->reserved3 = 0x0; | ||
| 1396 | scsi_id->logout_orb->reserved4 = 0x0; | ||
| 1397 | |||
| 1398 | scsi_id->logout_orb->login_ID_misc = ORB_SET_FUNCTION(SBP2_LOGOUT_REQUEST); | ||
| 1399 | scsi_id->logout_orb->login_ID_misc |= ORB_SET_LOGIN_ID(scsi_id->login_response->length_login_ID); | ||
| 1400 | |||
| 1401 | /* Notify us when complete */ | ||
| 1402 | scsi_id->logout_orb->login_ID_misc |= ORB_SET_NOTIFY(1); | ||
| 1403 | 1161 | ||
| 1404 | scsi_id->logout_orb->reserved5 = 0x0; | 1162 | lu->logout_orb->login_ID_misc = ORB_SET_FUNCTION(SBP2_LOGOUT_REQUEST); |
| 1405 | scsi_id->logout_orb->status_fifo_hi = | 1163 | lu->logout_orb->login_ID_misc |= |
| 1406 | ORB_SET_STATUS_FIFO_HI(scsi_id->status_fifo_addr, hi->host->node_id); | 1164 | ORB_SET_LOGIN_ID(lu->login_response->length_login_ID); |
| 1407 | scsi_id->logout_orb->status_fifo_lo = | 1165 | lu->logout_orb->login_ID_misc |= ORB_SET_NOTIFY(1); |
| 1408 | ORB_SET_STATUS_FIFO_LO(scsi_id->status_fifo_addr); | ||
| 1409 | 1166 | ||
| 1410 | /* | 1167 | lu->logout_orb->reserved5 = 0x0; |
| 1411 | * Byte swap ORB if necessary | 1168 | lu->logout_orb->status_fifo_hi = |
| 1412 | */ | 1169 | ORB_SET_STATUS_FIFO_HI(lu->status_fifo_addr, hi->host->node_id); |
| 1413 | sbp2util_cpu_to_be32_buffer(scsi_id->logout_orb, sizeof(struct sbp2_logout_orb)); | 1170 | lu->logout_orb->status_fifo_lo = |
| 1171 | ORB_SET_STATUS_FIFO_LO(lu->status_fifo_addr); | ||
| 1414 | 1172 | ||
| 1415 | sbp2util_packet_dump(scsi_id->logout_orb, sizeof(struct sbp2_logout_orb), | 1173 | sbp2util_cpu_to_be32_buffer(lu->logout_orb, |
| 1416 | "sbp2 logout orb", scsi_id->logout_orb_dma); | 1174 | sizeof(struct sbp2_logout_orb)); |
| 1417 | 1175 | ||
| 1418 | /* | ||
| 1419 | * Ok, let's write to the target's management agent register | ||
| 1420 | */ | ||
| 1421 | data[0] = ORB_SET_NODE_ID(hi->host->node_id); | 1176 | data[0] = ORB_SET_NODE_ID(hi->host->node_id); |
| 1422 | data[1] = scsi_id->logout_orb_dma; | 1177 | data[1] = lu->logout_orb_dma; |
| 1423 | sbp2util_cpu_to_be32_buffer(data, 8); | 1178 | sbp2util_cpu_to_be32_buffer(data, 8); |
| 1424 | 1179 | ||
| 1425 | error = hpsb_node_write(scsi_id->ne, | 1180 | error = hpsb_node_write(lu->ne, lu->management_agent_addr, data, 8); |
| 1426 | scsi_id->sbp2_management_agent_addr, data, 8); | ||
| 1427 | if (error) | 1181 | if (error) |
| 1428 | return error; | 1182 | return error; |
| 1429 | 1183 | ||
| 1430 | /* Wait for device to logout...1 second. */ | 1184 | /* wait up to 1 second for the device to complete logout */ |
| 1431 | if (sbp2util_access_timeout(scsi_id, HZ)) | 1185 | if (sbp2util_access_timeout(lu, HZ)) |
| 1432 | return -EIO; | 1186 | return -EIO; |
| 1433 | 1187 | ||
| 1434 | SBP2_INFO("Logged out of SBP-2 device"); | 1188 | SBP2_INFO("Logged out of SBP-2 device"); |
| 1435 | return 0; | 1189 | return 0; |
| 1436 | } | 1190 | } |
| 1437 | 1191 | ||
| 1438 | /* | 1192 | static int sbp2_reconnect_device(struct sbp2_lu *lu) |
| 1439 | * This function is called in order to reconnect to a particular SBP-2 | ||
| 1440 | * device, after a bus reset. | ||
| 1441 | */ | ||
| 1442 | static int sbp2_reconnect_device(struct scsi_id_instance_data *scsi_id) | ||
| 1443 | { | 1193 | { |
| 1444 | struct sbp2scsi_host_info *hi = scsi_id->hi; | 1194 | struct sbp2_fwhost_info *hi = lu->hi; |
| 1445 | quadlet_t data[2]; | 1195 | quadlet_t data[2]; |
| 1446 | int error; | 1196 | int error; |
| 1447 | 1197 | ||
| 1448 | SBP2_DEBUG_ENTER(); | 1198 | lu->reconnect_orb->reserved1 = 0x0; |
| 1199 | lu->reconnect_orb->reserved2 = 0x0; | ||
| 1200 | lu->reconnect_orb->reserved3 = 0x0; | ||
| 1201 | lu->reconnect_orb->reserved4 = 0x0; | ||
| 1449 | 1202 | ||
| 1450 | /* | 1203 | lu->reconnect_orb->login_ID_misc = |
| 1451 | * Set-up reconnect ORB | 1204 | ORB_SET_FUNCTION(SBP2_RECONNECT_REQUEST); |
| 1452 | */ | 1205 | lu->reconnect_orb->login_ID_misc |= |
| 1453 | scsi_id->reconnect_orb->reserved1 = 0x0; | 1206 | ORB_SET_LOGIN_ID(lu->login_response->length_login_ID); |
| 1454 | scsi_id->reconnect_orb->reserved2 = 0x0; | 1207 | lu->reconnect_orb->login_ID_misc |= ORB_SET_NOTIFY(1); |
| 1455 | scsi_id->reconnect_orb->reserved3 = 0x0; | ||
| 1456 | scsi_id->reconnect_orb->reserved4 = 0x0; | ||
| 1457 | |||
| 1458 | scsi_id->reconnect_orb->login_ID_misc = ORB_SET_FUNCTION(SBP2_RECONNECT_REQUEST); | ||
| 1459 | scsi_id->reconnect_orb->login_ID_misc |= | ||
| 1460 | ORB_SET_LOGIN_ID(scsi_id->login_response->length_login_ID); | ||
| 1461 | 1208 | ||
| 1462 | /* Notify us when complete */ | 1209 | lu->reconnect_orb->reserved5 = 0x0; |
| 1463 | scsi_id->reconnect_orb->login_ID_misc |= ORB_SET_NOTIFY(1); | 1210 | lu->reconnect_orb->status_fifo_hi = |
| 1211 | ORB_SET_STATUS_FIFO_HI(lu->status_fifo_addr, hi->host->node_id); | ||
| 1212 | lu->reconnect_orb->status_fifo_lo = | ||
| 1213 | ORB_SET_STATUS_FIFO_LO(lu->status_fifo_addr); | ||
| 1464 | 1214 | ||
| 1465 | scsi_id->reconnect_orb->reserved5 = 0x0; | 1215 | sbp2util_cpu_to_be32_buffer(lu->reconnect_orb, |
| 1466 | scsi_id->reconnect_orb->status_fifo_hi = | 1216 | sizeof(struct sbp2_reconnect_orb)); |
| 1467 | ORB_SET_STATUS_FIFO_HI(scsi_id->status_fifo_addr, hi->host->node_id); | ||
| 1468 | scsi_id->reconnect_orb->status_fifo_lo = | ||
| 1469 | ORB_SET_STATUS_FIFO_LO(scsi_id->status_fifo_addr); | ||
| 1470 | |||
| 1471 | /* | ||
| 1472 | * Byte swap ORB if necessary | ||
| 1473 | */ | ||
| 1474 | sbp2util_cpu_to_be32_buffer(scsi_id->reconnect_orb, sizeof(struct sbp2_reconnect_orb)); | ||
| 1475 | |||
| 1476 | sbp2util_packet_dump(scsi_id->reconnect_orb, sizeof(struct sbp2_reconnect_orb), | ||
| 1477 | "sbp2 reconnect orb", scsi_id->reconnect_orb_dma); | ||
| 1478 | 1217 | ||
| 1479 | data[0] = ORB_SET_NODE_ID(hi->host->node_id); | 1218 | data[0] = ORB_SET_NODE_ID(hi->host->node_id); |
| 1480 | data[1] = scsi_id->reconnect_orb_dma; | 1219 | data[1] = lu->reconnect_orb_dma; |
| 1481 | sbp2util_cpu_to_be32_buffer(data, 8); | 1220 | sbp2util_cpu_to_be32_buffer(data, 8); |
| 1482 | 1221 | ||
| 1483 | error = hpsb_node_write(scsi_id->ne, | 1222 | error = hpsb_node_write(lu->ne, lu->management_agent_addr, data, 8); |
| 1484 | scsi_id->sbp2_management_agent_addr, data, 8); | ||
| 1485 | if (error) | 1223 | if (error) |
| 1486 | return error; | 1224 | return error; |
| 1487 | 1225 | ||
| 1488 | /* | 1226 | /* wait up to 1 second for reconnect status */ |
| 1489 | * Wait for reconnect status (up to 1 second)... | 1227 | if (sbp2util_access_timeout(lu, HZ)) { |
| 1490 | */ | ||
| 1491 | if (sbp2util_access_timeout(scsi_id, HZ)) { | ||
| 1492 | SBP2_ERR("Error reconnecting to SBP-2 device - timed out"); | 1228 | SBP2_ERR("Error reconnecting to SBP-2 device - timed out"); |
| 1493 | return -EIO; | 1229 | return -EIO; |
| 1494 | } | 1230 | } |
| 1495 | 1231 | ||
| 1496 | /* | 1232 | /* make sure that the returned status matches the reconnect ORB */ |
| 1497 | * Sanity. Make sure status returned matches reconnect orb. | 1233 | if (lu->status_block.ORB_offset_lo != lu->reconnect_orb_dma) { |
| 1498 | */ | ||
| 1499 | if (scsi_id->status_block.ORB_offset_lo != scsi_id->reconnect_orb_dma) { | ||
| 1500 | SBP2_ERR("Error reconnecting to SBP-2 device - timed out"); | 1234 | SBP2_ERR("Error reconnecting to SBP-2 device - timed out"); |
| 1501 | return -EIO; | 1235 | return -EIO; |
| 1502 | } | 1236 | } |
| 1503 | 1237 | ||
| 1504 | if (STATUS_TEST_RDS(scsi_id->status_block.ORB_offset_hi_misc)) { | 1238 | if (STATUS_TEST_RDS(lu->status_block.ORB_offset_hi_misc)) { |
| 1505 | SBP2_ERR("Error reconnecting to SBP-2 device - failed"); | 1239 | SBP2_ERR("Error reconnecting to SBP-2 device - failed"); |
| 1506 | return -EIO; | 1240 | return -EIO; |
| 1507 | } | 1241 | } |
| 1508 | 1242 | ||
| 1509 | HPSB_DEBUG("Reconnected to SBP-2 device"); | 1243 | SBP2_INFO("Reconnected to SBP-2 device"); |
| 1510 | return 0; | 1244 | return 0; |
| 1511 | } | 1245 | } |
| 1512 | 1246 | ||
| 1513 | /* | 1247 | /* |
| 1514 | * This function is called in order to set the busy timeout (number of | 1248 | * Set the target node's Single Phase Retry limit. Affects the target's retry |
| 1515 | * retries to attempt) on the sbp2 device. | 1249 | * behaviour if our node is too busy to accept requests. |
| 1516 | */ | 1250 | */ |
| 1517 | static int sbp2_set_busy_timeout(struct scsi_id_instance_data *scsi_id) | 1251 | static int sbp2_set_busy_timeout(struct sbp2_lu *lu) |
| 1518 | { | 1252 | { |
| 1519 | quadlet_t data; | 1253 | quadlet_t data; |
| 1520 | 1254 | ||
| 1521 | SBP2_DEBUG_ENTER(); | ||
| 1522 | |||
| 1523 | data = cpu_to_be32(SBP2_BUSY_TIMEOUT_VALUE); | 1255 | data = cpu_to_be32(SBP2_BUSY_TIMEOUT_VALUE); |
| 1524 | if (hpsb_node_write(scsi_id->ne, SBP2_BUSY_TIMEOUT_ADDRESS, &data, 4)) | 1256 | if (hpsb_node_write(lu->ne, SBP2_BUSY_TIMEOUT_ADDRESS, &data, 4)) |
| 1525 | SBP2_ERR("%s error", __FUNCTION__); | 1257 | SBP2_ERR("%s error", __FUNCTION__); |
| 1526 | return 0; | 1258 | return 0; |
| 1527 | } | 1259 | } |
| 1528 | 1260 | ||
| 1529 | /* | 1261 | static void sbp2_parse_unit_directory(struct sbp2_lu *lu, |
| 1530 | * This function is called to parse sbp2 device's config rom unit | ||
| 1531 | * directory. Used to determine things like sbp2 management agent offset, | ||
| 1532 | * and command set used (SCSI or RBC). | ||
| 1533 | */ | ||
| 1534 | static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id, | ||
| 1535 | struct unit_directory *ud) | 1262 | struct unit_directory *ud) |
| 1536 | { | 1263 | { |
| 1537 | struct csr1212_keyval *kv; | 1264 | struct csr1212_keyval *kv; |
| 1538 | struct csr1212_dentry *dentry; | 1265 | struct csr1212_dentry *dentry; |
| 1539 | u64 management_agent_addr; | 1266 | u64 management_agent_addr; |
| 1540 | u32 command_set_spec_id, command_set, unit_characteristics, | 1267 | u32 unit_characteristics, firmware_revision; |
| 1541 | firmware_revision; | ||
| 1542 | unsigned workarounds; | 1268 | unsigned workarounds; |
| 1543 | int i; | 1269 | int i; |
| 1544 | 1270 | ||
| 1545 | SBP2_DEBUG_ENTER(); | 1271 | management_agent_addr = 0; |
| 1272 | unit_characteristics = 0; | ||
| 1273 | firmware_revision = 0; | ||
| 1546 | 1274 | ||
| 1547 | management_agent_addr = 0x0; | ||
| 1548 | command_set_spec_id = 0x0; | ||
| 1549 | command_set = 0x0; | ||
| 1550 | unit_characteristics = 0x0; | ||
| 1551 | firmware_revision = 0x0; | ||
| 1552 | |||
| 1553 | /* Handle different fields in the unit directory, based on keys */ | ||
| 1554 | csr1212_for_each_dir_entry(ud->ne->csr, kv, ud->ud_kv, dentry) { | 1275 | csr1212_for_each_dir_entry(ud->ne->csr, kv, ud->ud_kv, dentry) { |
| 1555 | switch (kv->key.id) { | 1276 | switch (kv->key.id) { |
| 1556 | case CSR1212_KV_ID_DEPENDENT_INFO: | 1277 | case CSR1212_KV_ID_DEPENDENT_INFO: |
| 1557 | if (kv->key.type == CSR1212_KV_TYPE_CSR_OFFSET) { | 1278 | if (kv->key.type == CSR1212_KV_TYPE_CSR_OFFSET) |
| 1558 | /* Save off the management agent address */ | ||
| 1559 | management_agent_addr = | 1279 | management_agent_addr = |
| 1560 | CSR1212_REGISTER_SPACE_BASE + | 1280 | CSR1212_REGISTER_SPACE_BASE + |
| 1561 | (kv->value.csr_offset << 2); | 1281 | (kv->value.csr_offset << 2); |
| 1562 | 1282 | ||
| 1563 | SBP2_DEBUG("sbp2_management_agent_addr = %x", | 1283 | else if (kv->key.type == CSR1212_KV_TYPE_IMMEDIATE) |
| 1564 | (unsigned int)management_agent_addr); | 1284 | lu->lun = ORB_SET_LUN(kv->value.immediate); |
| 1565 | } else if (kv->key.type == CSR1212_KV_TYPE_IMMEDIATE) { | ||
| 1566 | scsi_id->sbp2_lun = | ||
| 1567 | ORB_SET_LUN(kv->value.immediate); | ||
| 1568 | } | ||
| 1569 | break; | ||
| 1570 | |||
| 1571 | case SBP2_COMMAND_SET_SPEC_ID_KEY: | ||
| 1572 | /* Command spec organization */ | ||
| 1573 | command_set_spec_id = kv->value.immediate; | ||
| 1574 | SBP2_DEBUG("sbp2_command_set_spec_id = %x", | ||
| 1575 | (unsigned int)command_set_spec_id); | ||
| 1576 | break; | ||
| 1577 | |||
| 1578 | case SBP2_COMMAND_SET_KEY: | ||
| 1579 | /* Command set used by sbp2 device */ | ||
| 1580 | command_set = kv->value.immediate; | ||
| 1581 | SBP2_DEBUG("sbp2_command_set = %x", | ||
| 1582 | (unsigned int)command_set); | ||
| 1583 | break; | 1285 | break; |
| 1584 | 1286 | ||
| 1585 | case SBP2_UNIT_CHARACTERISTICS_KEY: | 1287 | case SBP2_UNIT_CHARACTERISTICS_KEY: |
| 1586 | /* | 1288 | /* FIXME: This is ignored so far. |
| 1587 | * Unit characterisitcs (orb related stuff | 1289 | * See SBP-2 clause 7.4.8. */ |
| 1588 | * that I'm not yet paying attention to) | ||
| 1589 | */ | ||
| 1590 | unit_characteristics = kv->value.immediate; | 1290 | unit_characteristics = kv->value.immediate; |
| 1591 | SBP2_DEBUG("sbp2_unit_characteristics = %x", | ||
| 1592 | (unsigned int)unit_characteristics); | ||
| 1593 | break; | 1291 | break; |
| 1594 | 1292 | ||
| 1595 | case SBP2_FIRMWARE_REVISION_KEY: | 1293 | case SBP2_FIRMWARE_REVISION_KEY: |
| 1596 | /* Firmware revision */ | ||
| 1597 | firmware_revision = kv->value.immediate; | 1294 | firmware_revision = kv->value.immediate; |
| 1598 | SBP2_DEBUG("sbp2_firmware_revision = %x", | ||
| 1599 | (unsigned int)firmware_revision); | ||
| 1600 | break; | 1295 | break; |
| 1601 | 1296 | ||
| 1602 | default: | 1297 | default: |
| 1298 | /* FIXME: Check for SBP2_DEVICE_TYPE_AND_LUN_KEY. | ||
| 1299 | * Its "ordered" bit has consequences for command ORB | ||
| 1300 | * list handling. See SBP-2 clauses 4.6, 7.4.11, 10.2 */ | ||
| 1603 | break; | 1301 | break; |
| 1604 | } | 1302 | } |
| 1605 | } | 1303 | } |
| @@ -1631,28 +1329,24 @@ static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id, | |||
| 1631 | /* We would need one SCSI host template for each target to adjust | 1329 | /* We would need one SCSI host template for each target to adjust |
| 1632 | * max_sectors on the fly, therefore warn only. */ | 1330 | * max_sectors on the fly, therefore warn only. */ |
| 1633 | if (workarounds & SBP2_WORKAROUND_128K_MAX_TRANS && | 1331 | if (workarounds & SBP2_WORKAROUND_128K_MAX_TRANS && |
| 1634 | (max_sectors * 512) > (128 * 1024)) | 1332 | (sbp2_max_sectors * 512) > (128 * 1024)) |
| 1635 | SBP2_WARN("Node " NODE_BUS_FMT ": Bridge only supports 128KB " | 1333 | SBP2_INFO("Node " NODE_BUS_FMT ": Bridge only supports 128KB " |
| 1636 | "max transfer size. WARNING: Current max_sectors " | 1334 | "max transfer size. WARNING: Current max_sectors " |
| 1637 | "setting is larger than 128KB (%d sectors)", | 1335 | "setting is larger than 128KB (%d sectors)", |
| 1638 | NODE_BUS_ARGS(ud->ne->host, ud->ne->nodeid), | 1336 | NODE_BUS_ARGS(ud->ne->host, ud->ne->nodeid), |
| 1639 | max_sectors); | 1337 | sbp2_max_sectors); |
| 1640 | 1338 | ||
| 1641 | /* If this is a logical unit directory entry, process the parent | 1339 | /* If this is a logical unit directory entry, process the parent |
| 1642 | * to get the values. */ | 1340 | * to get the values. */ |
| 1643 | if (ud->flags & UNIT_DIRECTORY_LUN_DIRECTORY) { | 1341 | if (ud->flags & UNIT_DIRECTORY_LUN_DIRECTORY) { |
| 1644 | struct unit_directory *parent_ud = | 1342 | struct unit_directory *parent_ud = container_of( |
| 1645 | container_of(ud->device.parent, struct unit_directory, device); | 1343 | ud->device.parent, struct unit_directory, device); |
| 1646 | sbp2_parse_unit_directory(scsi_id, parent_ud); | 1344 | sbp2_parse_unit_directory(lu, parent_ud); |
| 1647 | } else { | 1345 | } else { |
| 1648 | scsi_id->sbp2_management_agent_addr = management_agent_addr; | 1346 | lu->management_agent_addr = management_agent_addr; |
| 1649 | scsi_id->sbp2_command_set_spec_id = command_set_spec_id; | 1347 | lu->workarounds = workarounds; |
| 1650 | scsi_id->sbp2_command_set = command_set; | ||
| 1651 | scsi_id->sbp2_unit_characteristics = unit_characteristics; | ||
| 1652 | scsi_id->sbp2_firmware_revision = firmware_revision; | ||
| 1653 | scsi_id->workarounds = workarounds; | ||
| 1654 | if (ud->flags & UNIT_DIRECTORY_HAS_LUN) | 1348 | if (ud->flags & UNIT_DIRECTORY_HAS_LUN) |
| 1655 | scsi_id->sbp2_lun = ORB_SET_LUN(ud->lun); | 1349 | lu->lun = ORB_SET_LUN(ud->lun); |
| 1656 | } | 1350 | } |
| 1657 | } | 1351 | } |
| 1658 | 1352 | ||
| @@ -1667,133 +1361,114 @@ static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id, | |||
| 1667 | * the speed that it needs to use, and the max_rec the host supports, and | 1361 | * the speed that it needs to use, and the max_rec the host supports, and |
| 1668 | * it takes care of the rest. | 1362 | * it takes care of the rest. |
| 1669 | */ | 1363 | */ |
| 1670 | static int sbp2_max_speed_and_size(struct scsi_id_instance_data *scsi_id) | 1364 | static int sbp2_max_speed_and_size(struct sbp2_lu *lu) |
| 1671 | { | 1365 | { |
| 1672 | struct sbp2scsi_host_info *hi = scsi_id->hi; | 1366 | struct sbp2_fwhost_info *hi = lu->hi; |
| 1673 | u8 payload; | 1367 | u8 payload; |
| 1674 | 1368 | ||
| 1675 | SBP2_DEBUG_ENTER(); | 1369 | lu->speed_code = hi->host->speed[NODEID_TO_NODE(lu->ne->nodeid)]; |
| 1676 | |||
| 1677 | scsi_id->speed_code = | ||
| 1678 | hi->host->speed[NODEID_TO_NODE(scsi_id->ne->nodeid)]; | ||
| 1679 | 1370 | ||
| 1680 | /* Bump down our speed if the user requested it */ | 1371 | if (lu->speed_code > sbp2_max_speed) { |
| 1681 | if (scsi_id->speed_code > max_speed) { | 1372 | lu->speed_code = sbp2_max_speed; |
| 1682 | scsi_id->speed_code = max_speed; | 1373 | SBP2_INFO("Reducing speed to %s", |
| 1683 | SBP2_ERR("Forcing SBP-2 max speed down to %s", | 1374 | hpsb_speedto_str[sbp2_max_speed]); |
| 1684 | hpsb_speedto_str[scsi_id->speed_code]); | ||
| 1685 | } | 1375 | } |
| 1686 | 1376 | ||
| 1687 | /* Payload size is the lesser of what our speed supports and what | 1377 | /* Payload size is the lesser of what our speed supports and what |
| 1688 | * our host supports. */ | 1378 | * our host supports. */ |
| 1689 | payload = min(sbp2_speedto_max_payload[scsi_id->speed_code], | 1379 | payload = min(sbp2_speedto_max_payload[lu->speed_code], |
| 1690 | (u8) (hi->host->csr.max_rec - 1)); | 1380 | (u8) (hi->host->csr.max_rec - 1)); |
| 1691 | 1381 | ||
| 1692 | /* If physical DMA is off, work around limitation in ohci1394: | 1382 | /* If physical DMA is off, work around limitation in ohci1394: |
| 1693 | * packet size must not exceed PAGE_SIZE */ | 1383 | * packet size must not exceed PAGE_SIZE */ |
| 1694 | if (scsi_id->ne->host->low_addr_space < (1ULL << 32)) | 1384 | if (lu->ne->host->low_addr_space < (1ULL << 32)) |
| 1695 | while (SBP2_PAYLOAD_TO_BYTES(payload) + 24 > PAGE_SIZE && | 1385 | while (SBP2_PAYLOAD_TO_BYTES(payload) + 24 > PAGE_SIZE && |
| 1696 | payload) | 1386 | payload) |
| 1697 | payload--; | 1387 | payload--; |
| 1698 | 1388 | ||
| 1699 | HPSB_DEBUG("Node " NODE_BUS_FMT ": Max speed [%s] - Max payload [%u]", | 1389 | SBP2_INFO("Node " NODE_BUS_FMT ": Max speed [%s] - Max payload [%u]", |
| 1700 | NODE_BUS_ARGS(hi->host, scsi_id->ne->nodeid), | 1390 | NODE_BUS_ARGS(hi->host, lu->ne->nodeid), |
| 1701 | hpsb_speedto_str[scsi_id->speed_code], | 1391 | hpsb_speedto_str[lu->speed_code], |
| 1702 | SBP2_PAYLOAD_TO_BYTES(payload)); | 1392 | SBP2_PAYLOAD_TO_BYTES(payload)); |
| 1703 | 1393 | ||
| 1704 | scsi_id->max_payload_size = payload; | 1394 | lu->max_payload_size = payload; |
| 1705 | return 0; | 1395 | return 0; |
| 1706 | } | 1396 | } |
| 1707 | 1397 | ||
| 1708 | /* | 1398 | static int sbp2_agent_reset(struct sbp2_lu *lu, int wait) |
| 1709 | * This function is called in order to perform a SBP-2 agent reset. | ||
| 1710 | */ | ||
| 1711 | static int sbp2_agent_reset(struct scsi_id_instance_data *scsi_id, int wait) | ||
| 1712 | { | 1399 | { |
| 1713 | quadlet_t data; | 1400 | quadlet_t data; |
| 1714 | u64 addr; | 1401 | u64 addr; |
| 1715 | int retval; | 1402 | int retval; |
| 1716 | unsigned long flags; | 1403 | unsigned long flags; |
| 1717 | 1404 | ||
| 1718 | SBP2_DEBUG_ENTER(); | 1405 | /* flush lu->protocol_work */ |
| 1719 | |||
| 1720 | cancel_delayed_work(&scsi_id->protocol_work); | ||
| 1721 | if (wait) | 1406 | if (wait) |
| 1722 | flush_scheduled_work(); | 1407 | flush_scheduled_work(); |
| 1723 | 1408 | ||
| 1724 | data = ntohl(SBP2_AGENT_RESET_DATA); | 1409 | data = ntohl(SBP2_AGENT_RESET_DATA); |
| 1725 | addr = scsi_id->sbp2_command_block_agent_addr + SBP2_AGENT_RESET_OFFSET; | 1410 | addr = lu->command_block_agent_addr + SBP2_AGENT_RESET_OFFSET; |
| 1726 | 1411 | ||
| 1727 | if (wait) | 1412 | if (wait) |
| 1728 | retval = hpsb_node_write(scsi_id->ne, addr, &data, 4); | 1413 | retval = hpsb_node_write(lu->ne, addr, &data, 4); |
| 1729 | else | 1414 | else |
| 1730 | retval = sbp2util_node_write_no_wait(scsi_id->ne, addr, &data, 4); | 1415 | retval = sbp2util_node_write_no_wait(lu->ne, addr, &data, 4); |
| 1731 | 1416 | ||
| 1732 | if (retval < 0) { | 1417 | if (retval < 0) { |
| 1733 | SBP2_ERR("hpsb_node_write failed.\n"); | 1418 | SBP2_ERR("hpsb_node_write failed.\n"); |
| 1734 | return -EIO; | 1419 | return -EIO; |
| 1735 | } | 1420 | } |
| 1736 | 1421 | ||
| 1737 | /* | 1422 | /* make sure that the ORB_POINTER is written on next command */ |
| 1738 | * Need to make sure orb pointer is written on next command | 1423 | spin_lock_irqsave(&lu->cmd_orb_lock, flags); |
| 1739 | */ | 1424 | lu->last_orb = NULL; |
| 1740 | spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); | 1425 | spin_unlock_irqrestore(&lu->cmd_orb_lock, flags); |
| 1741 | scsi_id->last_orb = NULL; | ||
| 1742 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); | ||
| 1743 | 1426 | ||
| 1744 | return 0; | 1427 | return 0; |
| 1745 | } | 1428 | } |
| 1746 | 1429 | ||
| 1747 | static void sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb, | 1430 | static void sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb, |
| 1748 | struct sbp2scsi_host_info *hi, | 1431 | struct sbp2_fwhost_info *hi, |
| 1749 | struct sbp2_command_info *command, | 1432 | struct sbp2_command_info *cmd, |
| 1750 | unsigned int scsi_use_sg, | 1433 | unsigned int scsi_use_sg, |
| 1751 | struct scatterlist *sgpnt, | 1434 | struct scatterlist *sgpnt, |
| 1752 | u32 orb_direction, | 1435 | u32 orb_direction, |
| 1753 | enum dma_data_direction dma_dir) | 1436 | enum dma_data_direction dma_dir) |
| 1754 | { | 1437 | { |
| 1755 | command->dma_dir = dma_dir; | 1438 | cmd->dma_dir = dma_dir; |
| 1756 | orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id); | 1439 | orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id); |
| 1757 | orb->misc |= ORB_SET_DIRECTION(orb_direction); | 1440 | orb->misc |= ORB_SET_DIRECTION(orb_direction); |
| 1758 | 1441 | ||
| 1759 | /* Special case if only one element (and less than 64KB in size) */ | 1442 | /* special case if only one element (and less than 64KB in size) */ |
| 1760 | if ((scsi_use_sg == 1) && | 1443 | if ((scsi_use_sg == 1) && |
| 1761 | (sgpnt[0].length <= SBP2_MAX_SG_ELEMENT_LENGTH)) { | 1444 | (sgpnt[0].length <= SBP2_MAX_SG_ELEMENT_LENGTH)) { |
| 1762 | 1445 | ||
| 1763 | SBP2_DEBUG("Only one s/g element"); | 1446 | cmd->dma_size = sgpnt[0].length; |
| 1764 | command->dma_size = sgpnt[0].length; | 1447 | cmd->dma_type = CMD_DMA_PAGE; |
| 1765 | command->dma_type = CMD_DMA_PAGE; | 1448 | cmd->cmd_dma = dma_map_page(&hi->host->device, |
| 1766 | command->cmd_dma = pci_map_page(hi->host->pdev, | 1449 | sgpnt[0].page, sgpnt[0].offset, |
| 1767 | sgpnt[0].page, | 1450 | cmd->dma_size, cmd->dma_dir); |
| 1768 | sgpnt[0].offset, | ||
| 1769 | command->dma_size, | ||
| 1770 | command->dma_dir); | ||
| 1771 | SBP2_DMA_ALLOC("single page scatter element"); | ||
| 1772 | 1451 | ||
| 1773 | orb->data_descriptor_lo = command->cmd_dma; | 1452 | orb->data_descriptor_lo = cmd->cmd_dma; |
| 1774 | orb->misc |= ORB_SET_DATA_SIZE(command->dma_size); | 1453 | orb->misc |= ORB_SET_DATA_SIZE(cmd->dma_size); |
| 1775 | 1454 | ||
| 1776 | } else { | 1455 | } else { |
| 1777 | struct sbp2_unrestricted_page_table *sg_element = | 1456 | struct sbp2_unrestricted_page_table *sg_element = |
| 1778 | &command->scatter_gather_element[0]; | 1457 | &cmd->scatter_gather_element[0]; |
| 1779 | u32 sg_count, sg_len; | 1458 | u32 sg_count, sg_len; |
| 1780 | dma_addr_t sg_addr; | 1459 | dma_addr_t sg_addr; |
| 1781 | int i, count = pci_map_sg(hi->host->pdev, sgpnt, scsi_use_sg, | 1460 | int i, count = dma_map_sg(&hi->host->device, sgpnt, scsi_use_sg, |
| 1782 | dma_dir); | 1461 | dma_dir); |
| 1783 | 1462 | ||
| 1784 | SBP2_DMA_ALLOC("scatter list"); | 1463 | cmd->dma_size = scsi_use_sg; |
| 1785 | 1464 | cmd->sge_buffer = sgpnt; | |
| 1786 | command->dma_size = scsi_use_sg; | ||
| 1787 | command->sge_buffer = sgpnt; | ||
| 1788 | 1465 | ||
| 1789 | /* use page tables (s/g) */ | 1466 | /* use page tables (s/g) */ |
| 1790 | orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1); | 1467 | orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1); |
| 1791 | orb->data_descriptor_lo = command->sge_dma; | 1468 | orb->data_descriptor_lo = cmd->sge_dma; |
| 1792 | 1469 | ||
| 1793 | /* | 1470 | /* loop through and fill out our SBP-2 page tables |
| 1794 | * Loop through and fill out our sbp-2 page tables | 1471 | * (and split up anything too large) */ |
| 1795 | * (and split up anything too large) | ||
| 1796 | */ | ||
| 1797 | for (i = 0, sg_count = 0 ; i < count; i++, sgpnt++) { | 1472 | for (i = 0, sg_count = 0 ; i < count; i++, sgpnt++) { |
| 1798 | sg_len = sg_dma_len(sgpnt); | 1473 | sg_len = sg_dma_len(sgpnt); |
| 1799 | sg_addr = sg_dma_address(sgpnt); | 1474 | sg_addr = sg_dma_address(sgpnt); |
| @@ -1813,70 +1488,53 @@ static void sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb, | |||
| 1813 | } | 1488 | } |
| 1814 | } | 1489 | } |
| 1815 | 1490 | ||
| 1816 | /* Number of page table (s/g) elements */ | ||
| 1817 | orb->misc |= ORB_SET_DATA_SIZE(sg_count); | 1491 | orb->misc |= ORB_SET_DATA_SIZE(sg_count); |
| 1818 | 1492 | ||
| 1819 | sbp2util_packet_dump(sg_element, | ||
| 1820 | (sizeof(struct sbp2_unrestricted_page_table)) * sg_count, | ||
| 1821 | "sbp2 s/g list", command->sge_dma); | ||
| 1822 | |||
| 1823 | /* Byte swap page tables if necessary */ | ||
| 1824 | sbp2util_cpu_to_be32_buffer(sg_element, | 1493 | sbp2util_cpu_to_be32_buffer(sg_element, |
| 1825 | (sizeof(struct sbp2_unrestricted_page_table)) * | 1494 | (sizeof(struct sbp2_unrestricted_page_table)) * |
| 1826 | sg_count); | 1495 | sg_count); |
| 1827 | } | 1496 | } |
| 1828 | } | 1497 | } |
| 1829 | 1498 | ||
| 1830 | static void sbp2_prep_command_orb_no_sg(struct sbp2_command_orb *orb, | 1499 | static void sbp2_prep_command_orb_no_sg(struct sbp2_command_orb *orb, |
| 1831 | struct sbp2scsi_host_info *hi, | 1500 | struct sbp2_fwhost_info *hi, |
| 1832 | struct sbp2_command_info *command, | 1501 | struct sbp2_command_info *cmd, |
| 1833 | struct scatterlist *sgpnt, | 1502 | struct scatterlist *sgpnt, |
| 1834 | u32 orb_direction, | 1503 | u32 orb_direction, |
| 1835 | unsigned int scsi_request_bufflen, | 1504 | unsigned int scsi_request_bufflen, |
| 1836 | void *scsi_request_buffer, | 1505 | void *scsi_request_buffer, |
| 1837 | enum dma_data_direction dma_dir) | 1506 | enum dma_data_direction dma_dir) |
| 1838 | { | 1507 | { |
| 1839 | command->dma_dir = dma_dir; | 1508 | cmd->dma_dir = dma_dir; |
| 1840 | command->dma_size = scsi_request_bufflen; | 1509 | cmd->dma_size = scsi_request_bufflen; |
| 1841 | command->dma_type = CMD_DMA_SINGLE; | 1510 | cmd->dma_type = CMD_DMA_SINGLE; |
| 1842 | command->cmd_dma = pci_map_single(hi->host->pdev, scsi_request_buffer, | 1511 | cmd->cmd_dma = dma_map_single(&hi->host->device, scsi_request_buffer, |
| 1843 | command->dma_size, command->dma_dir); | 1512 | cmd->dma_size, cmd->dma_dir); |
| 1844 | orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id); | 1513 | orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id); |
| 1845 | orb->misc |= ORB_SET_DIRECTION(orb_direction); | 1514 | orb->misc |= ORB_SET_DIRECTION(orb_direction); |
| 1846 | 1515 | ||
| 1847 | SBP2_DMA_ALLOC("single bulk"); | 1516 | /* handle case where we get a command w/o s/g enabled |
| 1848 | 1517 | * (but check for transfers larger than 64K) */ | |
| 1849 | /* | ||
| 1850 | * Handle case where we get a command w/o s/g enabled (but | ||
| 1851 | * check for transfers larger than 64K) | ||
| 1852 | */ | ||
| 1853 | if (scsi_request_bufflen <= SBP2_MAX_SG_ELEMENT_LENGTH) { | 1518 | if (scsi_request_bufflen <= SBP2_MAX_SG_ELEMENT_LENGTH) { |
| 1854 | 1519 | ||
| 1855 | orb->data_descriptor_lo = command->cmd_dma; | 1520 | orb->data_descriptor_lo = cmd->cmd_dma; |
| 1856 | orb->misc |= ORB_SET_DATA_SIZE(scsi_request_bufflen); | 1521 | orb->misc |= ORB_SET_DATA_SIZE(scsi_request_bufflen); |
| 1857 | 1522 | ||
| 1858 | } else { | 1523 | } else { |
| 1524 | /* The buffer is too large. Turn this into page tables. */ | ||
| 1525 | |||
| 1859 | struct sbp2_unrestricted_page_table *sg_element = | 1526 | struct sbp2_unrestricted_page_table *sg_element = |
| 1860 | &command->scatter_gather_element[0]; | 1527 | &cmd->scatter_gather_element[0]; |
| 1861 | u32 sg_count, sg_len; | 1528 | u32 sg_count, sg_len; |
| 1862 | dma_addr_t sg_addr; | 1529 | dma_addr_t sg_addr; |
| 1863 | 1530 | ||
| 1864 | /* | 1531 | orb->data_descriptor_lo = cmd->sge_dma; |
| 1865 | * Need to turn this into page tables, since the | ||
| 1866 | * buffer is too large. | ||
| 1867 | */ | ||
| 1868 | orb->data_descriptor_lo = command->sge_dma; | ||
| 1869 | |||
| 1870 | /* Use page tables (s/g) */ | ||
| 1871 | orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1); | 1532 | orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1); |
| 1872 | 1533 | ||
| 1873 | /* | 1534 | /* fill out our SBP-2 page tables; split up the large buffer */ |
| 1874 | * fill out our sbp-2 page tables (and split up | ||
| 1875 | * the large buffer) | ||
| 1876 | */ | ||
| 1877 | sg_count = 0; | 1535 | sg_count = 0; |
| 1878 | sg_len = scsi_request_bufflen; | 1536 | sg_len = scsi_request_bufflen; |
| 1879 | sg_addr = command->cmd_dma; | 1537 | sg_addr = cmd->cmd_dma; |
| 1880 | while (sg_len) { | 1538 | while (sg_len) { |
| 1881 | sg_element[sg_count].segment_base_lo = sg_addr; | 1539 | sg_element[sg_count].segment_base_lo = sg_addr; |
| 1882 | if (sg_len > SBP2_MAX_SG_ELEMENT_LENGTH) { | 1540 | if (sg_len > SBP2_MAX_SG_ELEMENT_LENGTH) { |
| @@ -1892,50 +1550,40 @@ static void sbp2_prep_command_orb_no_sg(struct sbp2_command_orb *orb, | |||
| 1892 | sg_count++; | 1550 | sg_count++; |
| 1893 | } | 1551 | } |
| 1894 | 1552 | ||
| 1895 | /* Number of page table (s/g) elements */ | ||
| 1896 | orb->misc |= ORB_SET_DATA_SIZE(sg_count); | 1553 | orb->misc |= ORB_SET_DATA_SIZE(sg_count); |
| 1897 | 1554 | ||
| 1898 | sbp2util_packet_dump(sg_element, | ||
| 1899 | (sizeof(struct sbp2_unrestricted_page_table)) * sg_count, | ||
| 1900 | "sbp2 s/g list", command->sge_dma); | ||
| 1901 | |||
| 1902 | /* Byte swap page tables if necessary */ | ||
| 1903 | sbp2util_cpu_to_be32_buffer(sg_element, | 1555 | sbp2util_cpu_to_be32_buffer(sg_element, |
| 1904 | (sizeof(struct sbp2_unrestricted_page_table)) * | 1556 | (sizeof(struct sbp2_unrestricted_page_table)) * |
| 1905 | sg_count); | 1557 | sg_count); |
| 1906 | } | 1558 | } |
| 1907 | } | 1559 | } |
| 1908 | 1560 | ||
| 1909 | /* | 1561 | static void sbp2_create_command_orb(struct sbp2_lu *lu, |
| 1910 | * This function is called to create the actual command orb and s/g list | 1562 | struct sbp2_command_info *cmd, |
| 1911 | * out of the scsi command itself. | ||
| 1912 | */ | ||
| 1913 | static void sbp2_create_command_orb(struct scsi_id_instance_data *scsi_id, | ||
| 1914 | struct sbp2_command_info *command, | ||
| 1915 | unchar *scsi_cmd, | 1563 | unchar *scsi_cmd, |
| 1916 | unsigned int scsi_use_sg, | 1564 | unsigned int scsi_use_sg, |
| 1917 | unsigned int scsi_request_bufflen, | 1565 | unsigned int scsi_request_bufflen, |
| 1918 | void *scsi_request_buffer, | 1566 | void *scsi_request_buffer, |
| 1919 | enum dma_data_direction dma_dir) | 1567 | enum dma_data_direction dma_dir) |
| 1920 | { | 1568 | { |
| 1921 | struct sbp2scsi_host_info *hi = scsi_id->hi; | 1569 | struct sbp2_fwhost_info *hi = lu->hi; |
| 1922 | struct scatterlist *sgpnt = (struct scatterlist *)scsi_request_buffer; | 1570 | struct scatterlist *sgpnt = (struct scatterlist *)scsi_request_buffer; |
| 1923 | struct sbp2_command_orb *command_orb = &command->command_orb; | 1571 | struct sbp2_command_orb *orb = &cmd->command_orb; |
| 1924 | u32 orb_direction; | 1572 | u32 orb_direction; |
| 1925 | 1573 | ||
| 1926 | /* | 1574 | /* |
| 1927 | * Set-up our command ORB.. | 1575 | * Set-up our command ORB. |
| 1928 | * | 1576 | * |
| 1929 | * NOTE: We're doing unrestricted page tables (s/g), as this is | 1577 | * NOTE: We're doing unrestricted page tables (s/g), as this is |
| 1930 | * best performance (at least with the devices I have). This means | 1578 | * best performance (at least with the devices I have). This means |
| 1931 | * that data_size becomes the number of s/g elements, and | 1579 | * that data_size becomes the number of s/g elements, and |
| 1932 | * page_size should be zero (for unrestricted). | 1580 | * page_size should be zero (for unrestricted). |
| 1933 | */ | 1581 | */ |
| 1934 | command_orb->next_ORB_hi = ORB_SET_NULL_PTR(1); | 1582 | orb->next_ORB_hi = ORB_SET_NULL_PTR(1); |
| 1935 | command_orb->next_ORB_lo = 0x0; | 1583 | orb->next_ORB_lo = 0x0; |
| 1936 | command_orb->misc = ORB_SET_MAX_PAYLOAD(scsi_id->max_payload_size); | 1584 | orb->misc = ORB_SET_MAX_PAYLOAD(lu->max_payload_size); |
| 1937 | command_orb->misc |= ORB_SET_SPEED(scsi_id->speed_code); | 1585 | orb->misc |= ORB_SET_SPEED(lu->speed_code); |
| 1938 | command_orb->misc |= ORB_SET_NOTIFY(1); /* Notify us when complete */ | 1586 | orb->misc |= ORB_SET_NOTIFY(1); |
| 1939 | 1587 | ||
| 1940 | if (dma_dir == DMA_NONE) | 1588 | if (dma_dir == DMA_NONE) |
| 1941 | orb_direction = ORB_DIRECTION_NO_DATA_TRANSFER; | 1589 | orb_direction = ORB_DIRECTION_NO_DATA_TRANSFER; |
| @@ -1944,66 +1592,51 @@ static void sbp2_create_command_orb(struct scsi_id_instance_data *scsi_id, | |||
| 1944 | else if (dma_dir == DMA_FROM_DEVICE && scsi_request_bufflen) | 1592 | else if (dma_dir == DMA_FROM_DEVICE && scsi_request_bufflen) |
| 1945 | orb_direction = ORB_DIRECTION_READ_FROM_MEDIA; | 1593 | orb_direction = ORB_DIRECTION_READ_FROM_MEDIA; |
| 1946 | else { | 1594 | else { |
| 1947 | SBP2_WARN("Falling back to DMA_NONE"); | 1595 | SBP2_INFO("Falling back to DMA_NONE"); |
| 1948 | orb_direction = ORB_DIRECTION_NO_DATA_TRANSFER; | 1596 | orb_direction = ORB_DIRECTION_NO_DATA_TRANSFER; |
| 1949 | } | 1597 | } |
| 1950 | 1598 | ||
| 1951 | /* Set-up our pagetable stuff */ | 1599 | /* set up our page table stuff */ |
| 1952 | if (orb_direction == ORB_DIRECTION_NO_DATA_TRANSFER) { | 1600 | if (orb_direction == ORB_DIRECTION_NO_DATA_TRANSFER) { |
| 1953 | SBP2_DEBUG("No data transfer"); | 1601 | orb->data_descriptor_hi = 0x0; |
| 1954 | command_orb->data_descriptor_hi = 0x0; | 1602 | orb->data_descriptor_lo = 0x0; |
| 1955 | command_orb->data_descriptor_lo = 0x0; | 1603 | orb->misc |= ORB_SET_DIRECTION(1); |
| 1956 | command_orb->misc |= ORB_SET_DIRECTION(1); | 1604 | } else if (scsi_use_sg) |
| 1957 | } else if (scsi_use_sg) { | 1605 | sbp2_prep_command_orb_sg(orb, hi, cmd, scsi_use_sg, sgpnt, |
| 1958 | SBP2_DEBUG("Use scatter/gather"); | 1606 | orb_direction, dma_dir); |
| 1959 | sbp2_prep_command_orb_sg(command_orb, hi, command, scsi_use_sg, | 1607 | else |
| 1960 | sgpnt, orb_direction, dma_dir); | 1608 | sbp2_prep_command_orb_no_sg(orb, hi, cmd, sgpnt, orb_direction, |
| 1961 | } else { | 1609 | scsi_request_bufflen, |
| 1962 | SBP2_DEBUG("No scatter/gather"); | ||
| 1963 | sbp2_prep_command_orb_no_sg(command_orb, hi, command, sgpnt, | ||
| 1964 | orb_direction, scsi_request_bufflen, | ||
| 1965 | scsi_request_buffer, dma_dir); | 1610 | scsi_request_buffer, dma_dir); |
| 1966 | } | ||
| 1967 | 1611 | ||
| 1968 | /* Byte swap command ORB if necessary */ | 1612 | sbp2util_cpu_to_be32_buffer(orb, sizeof(*orb)); |
| 1969 | sbp2util_cpu_to_be32_buffer(command_orb, sizeof(struct sbp2_command_orb)); | ||
| 1970 | 1613 | ||
| 1971 | /* Put our scsi command in the command ORB */ | 1614 | memset(orb->cdb, 0, 12); |
| 1972 | memset(command_orb->cdb, 0, 12); | 1615 | memcpy(orb->cdb, scsi_cmd, COMMAND_SIZE(*scsi_cmd)); |
| 1973 | memcpy(command_orb->cdb, scsi_cmd, COMMAND_SIZE(*scsi_cmd)); | ||
| 1974 | } | 1616 | } |
| 1975 | 1617 | ||
| 1976 | /* | 1618 | static void sbp2_link_orb_command(struct sbp2_lu *lu, |
| 1977 | * This function is called in order to begin a regular SBP-2 command. | 1619 | struct sbp2_command_info *cmd) |
| 1978 | */ | ||
| 1979 | static void sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id, | ||
| 1980 | struct sbp2_command_info *command) | ||
| 1981 | { | 1620 | { |
| 1982 | struct sbp2scsi_host_info *hi = scsi_id->hi; | 1621 | struct sbp2_fwhost_info *hi = lu->hi; |
| 1983 | struct sbp2_command_orb *command_orb = &command->command_orb; | ||
| 1984 | struct sbp2_command_orb *last_orb; | 1622 | struct sbp2_command_orb *last_orb; |
| 1985 | dma_addr_t last_orb_dma; | 1623 | dma_addr_t last_orb_dma; |
| 1986 | u64 addr = scsi_id->sbp2_command_block_agent_addr; | 1624 | u64 addr = lu->command_block_agent_addr; |
| 1987 | quadlet_t data[2]; | 1625 | quadlet_t data[2]; |
| 1988 | size_t length; | 1626 | size_t length; |
| 1989 | unsigned long flags; | 1627 | unsigned long flags; |
| 1990 | 1628 | ||
| 1991 | outstanding_orb_incr; | 1629 | dma_sync_single_for_device(&hi->host->device, cmd->command_orb_dma, |
| 1992 | SBP2_ORB_DEBUG("sending command orb %p, total orbs = %x", | 1630 | sizeof(struct sbp2_command_orb), |
| 1993 | command_orb, global_outstanding_command_orbs); | 1631 | DMA_TO_DEVICE); |
| 1994 | 1632 | dma_sync_single_for_device(&hi->host->device, cmd->sge_dma, | |
| 1995 | pci_dma_sync_single_for_device(hi->host->pdev, command->command_orb_dma, | 1633 | sizeof(cmd->scatter_gather_element), |
| 1996 | sizeof(struct sbp2_command_orb), | 1634 | DMA_BIDIRECTIONAL); |
| 1997 | PCI_DMA_TODEVICE); | 1635 | |
| 1998 | pci_dma_sync_single_for_device(hi->host->pdev, command->sge_dma, | 1636 | /* check to see if there are any previous orbs to use */ |
| 1999 | sizeof(command->scatter_gather_element), | 1637 | spin_lock_irqsave(&lu->cmd_orb_lock, flags); |
| 2000 | PCI_DMA_BIDIRECTIONAL); | 1638 | last_orb = lu->last_orb; |
| 2001 | /* | 1639 | last_orb_dma = lu->last_orb_dma; |
| 2002 | * Check to see if there are any previous orbs to use | ||
| 2003 | */ | ||
| 2004 | spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); | ||
| 2005 | last_orb = scsi_id->last_orb; | ||
| 2006 | last_orb_dma = scsi_id->last_orb_dma; | ||
| 2007 | if (!last_orb) { | 1640 | if (!last_orb) { |
| 2008 | /* | 1641 | /* |
| 2009 | * last_orb == NULL means: We know that the target's fetch agent | 1642 | * last_orb == NULL means: We know that the target's fetch agent |
| @@ -2011,7 +1644,7 @@ static void sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id, | |||
| 2011 | */ | 1644 | */ |
| 2012 | addr += SBP2_ORB_POINTER_OFFSET; | 1645 | addr += SBP2_ORB_POINTER_OFFSET; |
| 2013 | data[0] = ORB_SET_NODE_ID(hi->host->node_id); | 1646 | data[0] = ORB_SET_NODE_ID(hi->host->node_id); |
| 2014 | data[1] = command->command_orb_dma; | 1647 | data[1] = cmd->command_orb_dma; |
| 2015 | sbp2util_cpu_to_be32_buffer(data, 8); | 1648 | sbp2util_cpu_to_be32_buffer(data, 8); |
| 2016 | length = 8; | 1649 | length = 8; |
| 2017 | } else { | 1650 | } else { |
| @@ -2022,27 +1655,25 @@ static void sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id, | |||
| 2022 | * The target's fetch agent may or may not have read this | 1655 | * The target's fetch agent may or may not have read this |
| 2023 | * previous ORB yet. | 1656 | * previous ORB yet. |
| 2024 | */ | 1657 | */ |
| 2025 | pci_dma_sync_single_for_cpu(hi->host->pdev, last_orb_dma, | 1658 | dma_sync_single_for_cpu(&hi->host->device, last_orb_dma, |
| 2026 | sizeof(struct sbp2_command_orb), | 1659 | sizeof(struct sbp2_command_orb), |
| 2027 | PCI_DMA_TODEVICE); | 1660 | DMA_TO_DEVICE); |
| 2028 | last_orb->next_ORB_lo = cpu_to_be32(command->command_orb_dma); | 1661 | last_orb->next_ORB_lo = cpu_to_be32(cmd->command_orb_dma); |
| 2029 | wmb(); | 1662 | wmb(); |
| 2030 | /* Tells hardware that this pointer is valid */ | 1663 | /* Tells hardware that this pointer is valid */ |
| 2031 | last_orb->next_ORB_hi = 0; | 1664 | last_orb->next_ORB_hi = 0; |
| 2032 | pci_dma_sync_single_for_device(hi->host->pdev, last_orb_dma, | 1665 | dma_sync_single_for_device(&hi->host->device, last_orb_dma, |
| 2033 | sizeof(struct sbp2_command_orb), | 1666 | sizeof(struct sbp2_command_orb), |
| 2034 | PCI_DMA_TODEVICE); | 1667 | DMA_TO_DEVICE); |
| 2035 | addr += SBP2_DOORBELL_OFFSET; | 1668 | addr += SBP2_DOORBELL_OFFSET; |
| 2036 | data[0] = 0; | 1669 | data[0] = 0; |
| 2037 | length = 4; | 1670 | length = 4; |
| 2038 | } | 1671 | } |
| 2039 | scsi_id->last_orb = command_orb; | 1672 | lu->last_orb = &cmd->command_orb; |
| 2040 | scsi_id->last_orb_dma = command->command_orb_dma; | 1673 | lu->last_orb_dma = cmd->command_orb_dma; |
| 2041 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); | 1674 | spin_unlock_irqrestore(&lu->cmd_orb_lock, flags); |
| 2042 | 1675 | ||
| 2043 | SBP2_ORB_DEBUG("write to %s register, command orb %p", | 1676 | if (sbp2util_node_write_no_wait(lu->ne, addr, data, length)) { |
| 2044 | last_orb ? "DOORBELL" : "ORB_POINTER", command_orb); | ||
| 2045 | if (sbp2util_node_write_no_wait(scsi_id->ne, addr, data, length)) { | ||
| 2046 | /* | 1677 | /* |
| 2047 | * sbp2util_node_write_no_wait failed. We certainly ran out | 1678 | * sbp2util_node_write_no_wait failed. We certainly ran out |
| 2048 | * of transaction labels, perhaps just because there were no | 1679 | * of transaction labels, perhaps just because there were no |
| @@ -2051,51 +1682,29 @@ static void sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id, | |||
| 2051 | * the workqueue job will sleep to guaranteedly get a tlabel. | 1682 | * the workqueue job will sleep to guaranteedly get a tlabel. |
| 2052 | * We do not accept new commands until the job is over. | 1683 | * We do not accept new commands until the job is over. |
| 2053 | */ | 1684 | */ |
| 2054 | scsi_block_requests(scsi_id->scsi_host); | 1685 | scsi_block_requests(lu->shost); |
| 2055 | PREPARE_DELAYED_WORK(&scsi_id->protocol_work, | 1686 | PREPARE_WORK(&lu->protocol_work, |
| 2056 | last_orb ? sbp2util_write_doorbell: | 1687 | last_orb ? sbp2util_write_doorbell: |
| 2057 | sbp2util_write_orb_pointer); | 1688 | sbp2util_write_orb_pointer); |
| 2058 | schedule_delayed_work(&scsi_id->protocol_work, 0); | 1689 | schedule_work(&lu->protocol_work); |
| 2059 | } | 1690 | } |
| 2060 | } | 1691 | } |
| 2061 | 1692 | ||
| 2062 | /* | 1693 | static int sbp2_send_command(struct sbp2_lu *lu, struct scsi_cmnd *SCpnt, |
| 2063 | * This function is called in order to begin a regular SBP-2 command. | ||
| 2064 | */ | ||
| 2065 | static int sbp2_send_command(struct scsi_id_instance_data *scsi_id, | ||
| 2066 | struct scsi_cmnd *SCpnt, | ||
| 2067 | void (*done)(struct scsi_cmnd *)) | 1694 | void (*done)(struct scsi_cmnd *)) |
| 2068 | { | 1695 | { |
| 2069 | unchar *cmd = (unchar *) SCpnt->cmnd; | 1696 | unchar *scsi_cmd = (unchar *)SCpnt->cmnd; |
| 2070 | unsigned int request_bufflen = SCpnt->request_bufflen; | 1697 | unsigned int request_bufflen = SCpnt->request_bufflen; |
| 2071 | struct sbp2_command_info *command; | 1698 | struct sbp2_command_info *cmd; |
| 2072 | 1699 | ||
| 2073 | SBP2_DEBUG_ENTER(); | 1700 | cmd = sbp2util_allocate_command_orb(lu, SCpnt, done); |
| 2074 | SBP2_DEBUG("SCSI transfer size = %x", request_bufflen); | 1701 | if (!cmd) |
| 2075 | SBP2_DEBUG("SCSI s/g elements = %x", (unsigned int)SCpnt->use_sg); | ||
| 2076 | |||
| 2077 | /* | ||
| 2078 | * Allocate a command orb and s/g structure | ||
| 2079 | */ | ||
| 2080 | command = sbp2util_allocate_command_orb(scsi_id, SCpnt, done); | ||
| 2081 | if (!command) { | ||
| 2082 | return -EIO; | 1702 | return -EIO; |
| 2083 | } | ||
| 2084 | 1703 | ||
| 2085 | /* | 1704 | sbp2_create_command_orb(lu, cmd, scsi_cmd, SCpnt->use_sg, |
| 2086 | * Now actually fill in the comamnd orb and sbp2 s/g list | ||
| 2087 | */ | ||
| 2088 | sbp2_create_command_orb(scsi_id, command, cmd, SCpnt->use_sg, | ||
| 2089 | request_bufflen, SCpnt->request_buffer, | 1705 | request_bufflen, SCpnt->request_buffer, |
| 2090 | SCpnt->sc_data_direction); | 1706 | SCpnt->sc_data_direction); |
| 2091 | 1707 | sbp2_link_orb_command(lu, cmd); | |
| 2092 | sbp2util_packet_dump(&command->command_orb, sizeof(struct sbp2_command_orb), | ||
| 2093 | "sbp2 command orb", command->command_orb_dma); | ||
| 2094 | |||
| 2095 | /* | ||
| 2096 | * Link up the orb, and ring the doorbell if needed | ||
| 2097 | */ | ||
| 2098 | sbp2_link_orb_command(scsi_id, command); | ||
| 2099 | 1708 | ||
| 2100 | return 0; | 1709 | return 0; |
| 2101 | } | 1710 | } |
| @@ -2103,13 +1712,10 @@ static int sbp2_send_command(struct scsi_id_instance_data *scsi_id, | |||
| 2103 | /* | 1712 | /* |
| 2104 | * Translates SBP-2 status into SCSI sense data for check conditions | 1713 | * Translates SBP-2 status into SCSI sense data for check conditions |
| 2105 | */ | 1714 | */ |
| 2106 | static unsigned int sbp2_status_to_sense_data(unchar *sbp2_status, unchar *sense_data) | 1715 | static unsigned int sbp2_status_to_sense_data(unchar *sbp2_status, |
| 1716 | unchar *sense_data) | ||
| 2107 | { | 1717 | { |
| 2108 | SBP2_DEBUG_ENTER(); | 1718 | /* OK, it's pretty ugly... ;-) */ |
| 2109 | |||
| 2110 | /* | ||
| 2111 | * Ok, it's pretty ugly... ;-) | ||
| 2112 | */ | ||
| 2113 | sense_data[0] = 0x70; | 1719 | sense_data[0] = 0x70; |
| 2114 | sense_data[1] = 0x0; | 1720 | sense_data[1] = 0x0; |
| 2115 | sense_data[2] = sbp2_status[9]; | 1721 | sense_data[2] = sbp2_status[9]; |
| @@ -2127,28 +1733,21 @@ static unsigned int sbp2_status_to_sense_data(unchar *sbp2_status, unchar *sense | |||
| 2127 | sense_data[14] = sbp2_status[20]; | 1733 | sense_data[14] = sbp2_status[20]; |
| 2128 | sense_data[15] = sbp2_status[21]; | 1734 | sense_data[15] = sbp2_status[21]; |
| 2129 | 1735 | ||
| 2130 | return sbp2_status[8] & 0x3f; /* return scsi status */ | 1736 | return sbp2_status[8] & 0x3f; |
| 2131 | } | 1737 | } |
| 2132 | 1738 | ||
| 2133 | /* | ||
| 2134 | * This function deals with status writes from the SBP-2 device | ||
| 2135 | */ | ||
| 2136 | static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, | 1739 | static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, |
| 2137 | int destid, quadlet_t *data, u64 addr, | 1740 | int destid, quadlet_t *data, u64 addr, |
| 2138 | size_t length, u16 fl) | 1741 | size_t length, u16 fl) |
| 2139 | { | 1742 | { |
| 2140 | struct sbp2scsi_host_info *hi; | 1743 | struct sbp2_fwhost_info *hi; |
| 2141 | struct scsi_id_instance_data *scsi_id = NULL, *scsi_id_tmp; | 1744 | struct sbp2_lu *lu = NULL, *lu_tmp; |
| 2142 | struct scsi_cmnd *SCpnt = NULL; | 1745 | struct scsi_cmnd *SCpnt = NULL; |
| 2143 | struct sbp2_status_block *sb; | 1746 | struct sbp2_status_block *sb; |
| 2144 | u32 scsi_status = SBP2_SCSI_STATUS_GOOD; | 1747 | u32 scsi_status = SBP2_SCSI_STATUS_GOOD; |
| 2145 | struct sbp2_command_info *command; | 1748 | struct sbp2_command_info *cmd; |
| 2146 | unsigned long flags; | 1749 | unsigned long flags; |
| 2147 | 1750 | ||
| 2148 | SBP2_DEBUG_ENTER(); | ||
| 2149 | |||
| 2150 | sbp2util_packet_dump(data, length, "sbp2 status write by device", (u32)addr); | ||
| 2151 | |||
| 2152 | if (unlikely(length < 8 || length > sizeof(struct sbp2_status_block))) { | 1751 | if (unlikely(length < 8 || length > sizeof(struct sbp2_status_block))) { |
| 2153 | SBP2_ERR("Wrong size of status block"); | 1752 | SBP2_ERR("Wrong size of status block"); |
| 2154 | return RCODE_ADDRESS_ERROR; | 1753 | return RCODE_ADDRESS_ERROR; |
| @@ -2162,131 +1761,97 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, | |||
| 2162 | SBP2_ERR("host info is NULL - this is bad!"); | 1761 | SBP2_ERR("host info is NULL - this is bad!"); |
| 2163 | return RCODE_ADDRESS_ERROR; | 1762 | return RCODE_ADDRESS_ERROR; |
| 2164 | } | 1763 | } |
| 2165 | /* | 1764 | |
| 2166 | * Find our scsi_id structure by looking at the status fifo address | 1765 | /* Find the unit which wrote the status. */ |
| 2167 | * written to by the sbp2 device. | 1766 | list_for_each_entry(lu_tmp, &hi->logical_units, lu_list) { |
| 2168 | */ | 1767 | if (lu_tmp->ne->nodeid == nodeid && |
| 2169 | list_for_each_entry(scsi_id_tmp, &hi->scsi_ids, scsi_list) { | 1768 | lu_tmp->status_fifo_addr == addr) { |
| 2170 | if (scsi_id_tmp->ne->nodeid == nodeid && | 1769 | lu = lu_tmp; |
| 2171 | scsi_id_tmp->status_fifo_addr == addr) { | ||
| 2172 | scsi_id = scsi_id_tmp; | ||
| 2173 | break; | 1770 | break; |
| 2174 | } | 1771 | } |
| 2175 | } | 1772 | } |
| 2176 | if (unlikely(!scsi_id)) { | 1773 | if (unlikely(!lu)) { |
| 2177 | SBP2_ERR("scsi_id is NULL - device is gone?"); | 1774 | SBP2_ERR("lu is NULL - device is gone?"); |
| 2178 | return RCODE_ADDRESS_ERROR; | 1775 | return RCODE_ADDRESS_ERROR; |
| 2179 | } | 1776 | } |
| 2180 | 1777 | ||
| 2181 | /* | 1778 | /* Put response into lu status fifo buffer. The first two bytes |
| 2182 | * Put response into scsi_id status fifo buffer. The first two bytes | ||
| 2183 | * come in big endian bit order. Often the target writes only a | 1779 | * come in big endian bit order. Often the target writes only a |
| 2184 | * truncated status block, minimally the first two quadlets. The rest | 1780 | * truncated status block, minimally the first two quadlets. The rest |
| 2185 | * is implied to be zeros. | 1781 | * is implied to be zeros. */ |
| 2186 | */ | 1782 | sb = &lu->status_block; |
| 2187 | sb = &scsi_id->status_block; | ||
| 2188 | memset(sb->command_set_dependent, 0, sizeof(sb->command_set_dependent)); | 1783 | memset(sb->command_set_dependent, 0, sizeof(sb->command_set_dependent)); |
| 2189 | memcpy(sb, data, length); | 1784 | memcpy(sb, data, length); |
| 2190 | sbp2util_be32_to_cpu_buffer(sb, 8); | 1785 | sbp2util_be32_to_cpu_buffer(sb, 8); |
| 2191 | 1786 | ||
| 2192 | /* | 1787 | /* Ignore unsolicited status. Handle command ORB status. */ |
| 2193 | * Ignore unsolicited status. Handle command ORB status. | ||
| 2194 | */ | ||
| 2195 | if (unlikely(STATUS_GET_SRC(sb->ORB_offset_hi_misc) == 2)) | 1788 | if (unlikely(STATUS_GET_SRC(sb->ORB_offset_hi_misc) == 2)) |
| 2196 | command = NULL; | 1789 | cmd = NULL; |
| 2197 | else | 1790 | else |
| 2198 | command = sbp2util_find_command_for_orb(scsi_id, | 1791 | cmd = sbp2util_find_command_for_orb(lu, sb->ORB_offset_lo); |
| 2199 | sb->ORB_offset_lo); | 1792 | if (cmd) { |
| 2200 | if (command) { | 1793 | dma_sync_single_for_cpu(&hi->host->device, cmd->command_orb_dma, |
| 2201 | SBP2_DEBUG("Found status for command ORB"); | 1794 | sizeof(struct sbp2_command_orb), |
| 2202 | pci_dma_sync_single_for_cpu(hi->host->pdev, command->command_orb_dma, | 1795 | DMA_TO_DEVICE); |
| 2203 | sizeof(struct sbp2_command_orb), | 1796 | dma_sync_single_for_cpu(&hi->host->device, cmd->sge_dma, |
| 2204 | PCI_DMA_TODEVICE); | 1797 | sizeof(cmd->scatter_gather_element), |
| 2205 | pci_dma_sync_single_for_cpu(hi->host->pdev, command->sge_dma, | 1798 | DMA_BIDIRECTIONAL); |
| 2206 | sizeof(command->scatter_gather_element), | 1799 | /* Grab SCSI command pointers and check status. */ |
| 2207 | PCI_DMA_BIDIRECTIONAL); | ||
| 2208 | |||
| 2209 | SBP2_ORB_DEBUG("matched command orb %p", &command->command_orb); | ||
| 2210 | outstanding_orb_decr; | ||
| 2211 | |||
| 2212 | /* | ||
| 2213 | * Matched status with command, now grab scsi command pointers | ||
| 2214 | * and check status. | ||
| 2215 | */ | ||
| 2216 | /* | 1800 | /* |
| 2217 | * FIXME: If the src field in the status is 1, the ORB DMA must | 1801 | * FIXME: If the src field in the status is 1, the ORB DMA must |
| 2218 | * not be reused until status for a subsequent ORB is received. | 1802 | * not be reused until status for a subsequent ORB is received. |
| 2219 | */ | 1803 | */ |
| 2220 | SCpnt = command->Current_SCpnt; | 1804 | SCpnt = cmd->Current_SCpnt; |
| 2221 | spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); | 1805 | spin_lock_irqsave(&lu->cmd_orb_lock, flags); |
| 2222 | sbp2util_mark_command_completed(scsi_id, command); | 1806 | sbp2util_mark_command_completed(lu, cmd); |
| 2223 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); | 1807 | spin_unlock_irqrestore(&lu->cmd_orb_lock, flags); |
| 2224 | 1808 | ||
| 2225 | if (SCpnt) { | 1809 | if (SCpnt) { |
| 2226 | u32 h = sb->ORB_offset_hi_misc; | 1810 | u32 h = sb->ORB_offset_hi_misc; |
| 2227 | u32 r = STATUS_GET_RESP(h); | 1811 | u32 r = STATUS_GET_RESP(h); |
| 2228 | 1812 | ||
| 2229 | if (r != RESP_STATUS_REQUEST_COMPLETE) { | 1813 | if (r != RESP_STATUS_REQUEST_COMPLETE) { |
| 2230 | SBP2_WARN("resp 0x%x, sbp_status 0x%x", | 1814 | SBP2_INFO("resp 0x%x, sbp_status 0x%x", |
| 2231 | r, STATUS_GET_SBP_STATUS(h)); | 1815 | r, STATUS_GET_SBP_STATUS(h)); |
| 2232 | scsi_status = | 1816 | scsi_status = |
| 2233 | r == RESP_STATUS_TRANSPORT_FAILURE ? | 1817 | r == RESP_STATUS_TRANSPORT_FAILURE ? |
| 2234 | SBP2_SCSI_STATUS_BUSY : | 1818 | SBP2_SCSI_STATUS_BUSY : |
| 2235 | SBP2_SCSI_STATUS_COMMAND_TERMINATED; | 1819 | SBP2_SCSI_STATUS_COMMAND_TERMINATED; |
| 2236 | } | 1820 | } |
| 2237 | /* | 1821 | |
| 2238 | * See if the target stored any scsi status information. | 1822 | if (STATUS_GET_LEN(h) > 1) |
| 2239 | */ | ||
| 2240 | if (STATUS_GET_LEN(h) > 1) { | ||
| 2241 | SBP2_DEBUG("CHECK CONDITION"); | ||
| 2242 | scsi_status = sbp2_status_to_sense_data( | 1823 | scsi_status = sbp2_status_to_sense_data( |
| 2243 | (unchar *)sb, SCpnt->sense_buffer); | 1824 | (unchar *)sb, SCpnt->sense_buffer); |
| 2244 | } | 1825 | |
| 2245 | /* | 1826 | if (STATUS_TEST_DEAD(h)) |
| 2246 | * Check to see if the dead bit is set. If so, we'll | 1827 | sbp2_agent_reset(lu, 0); |
| 2247 | * have to initiate a fetch agent reset. | ||
| 2248 | */ | ||
| 2249 | if (STATUS_TEST_DEAD(h)) { | ||
| 2250 | SBP2_DEBUG("Dead bit set - " | ||
| 2251 | "initiating fetch agent reset"); | ||
| 2252 | sbp2_agent_reset(scsi_id, 0); | ||
| 2253 | } | ||
| 2254 | SBP2_ORB_DEBUG("completing command orb %p", &command->command_orb); | ||
| 2255 | } | 1828 | } |
| 2256 | 1829 | ||
| 2257 | /* | 1830 | /* Check here to see if there are no commands in-use. If there |
| 2258 | * Check here to see if there are no commands in-use. If there | ||
| 2259 | * are none, we know that the fetch agent left the active state | 1831 | * are none, we know that the fetch agent left the active state |
| 2260 | * _and_ that we did not reactivate it yet. Therefore clear | 1832 | * _and_ that we did not reactivate it yet. Therefore clear |
| 2261 | * last_orb so that next time we write directly to the | 1833 | * last_orb so that next time we write directly to the |
| 2262 | * ORB_POINTER register. That way the fetch agent does not need | 1834 | * ORB_POINTER register. That way the fetch agent does not need |
| 2263 | * to refetch the next_ORB. | 1835 | * to refetch the next_ORB. */ |
| 2264 | */ | 1836 | spin_lock_irqsave(&lu->cmd_orb_lock, flags); |
| 2265 | spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); | 1837 | if (list_empty(&lu->cmd_orb_inuse)) |
| 2266 | if (list_empty(&scsi_id->sbp2_command_orb_inuse)) | 1838 | lu->last_orb = NULL; |
| 2267 | scsi_id->last_orb = NULL; | 1839 | spin_unlock_irqrestore(&lu->cmd_orb_lock, flags); |
| 2268 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); | ||
| 2269 | 1840 | ||
| 2270 | } else { | 1841 | } else { |
| 2271 | /* | 1842 | /* It's probably status after a management request. */ |
| 2272 | * It's probably a login/logout/reconnect status. | 1843 | if ((sb->ORB_offset_lo == lu->reconnect_orb_dma) || |
| 2273 | */ | 1844 | (sb->ORB_offset_lo == lu->login_orb_dma) || |
| 2274 | if ((sb->ORB_offset_lo == scsi_id->reconnect_orb_dma) || | 1845 | (sb->ORB_offset_lo == lu->query_logins_orb_dma) || |
| 2275 | (sb->ORB_offset_lo == scsi_id->login_orb_dma) || | 1846 | (sb->ORB_offset_lo == lu->logout_orb_dma)) { |
| 2276 | (sb->ORB_offset_lo == scsi_id->query_logins_orb_dma) || | 1847 | lu->access_complete = 1; |
| 2277 | (sb->ORB_offset_lo == scsi_id->logout_orb_dma)) { | 1848 | wake_up_interruptible(&sbp2_access_wq); |
| 2278 | scsi_id->access_complete = 1; | ||
| 2279 | wake_up_interruptible(&access_wq); | ||
| 2280 | } | 1849 | } |
| 2281 | } | 1850 | } |
| 2282 | 1851 | ||
| 2283 | if (SCpnt) { | 1852 | if (SCpnt) |
| 2284 | SBP2_DEBUG("Completing SCSI command"); | 1853 | sbp2scsi_complete_command(lu, scsi_status, SCpnt, |
| 2285 | sbp2scsi_complete_command(scsi_id, scsi_status, SCpnt, | 1854 | cmd->Current_done); |
| 2286 | command->Current_done); | ||
| 2287 | SBP2_ORB_DEBUG("command orb completed"); | ||
| 2288 | } | ||
| 2289 | |||
| 2290 | return RCODE_COMPLETE; | 1855 | return RCODE_COMPLETE; |
| 2291 | } | 1856 | } |
| 2292 | 1857 | ||
| @@ -2294,77 +1859,57 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, | |||
| 2294 | * SCSI interface related section | 1859 | * SCSI interface related section |
| 2295 | **************************************/ | 1860 | **************************************/ |
| 2296 | 1861 | ||
| 2297 | /* | ||
| 2298 | * This routine is the main request entry routine for doing I/O. It is | ||
| 2299 | * called from the scsi stack directly. | ||
| 2300 | */ | ||
| 2301 | static int sbp2scsi_queuecommand(struct scsi_cmnd *SCpnt, | 1862 | static int sbp2scsi_queuecommand(struct scsi_cmnd *SCpnt, |
| 2302 | void (*done)(struct scsi_cmnd *)) | 1863 | void (*done)(struct scsi_cmnd *)) |
| 2303 | { | 1864 | { |
| 2304 | struct scsi_id_instance_data *scsi_id = | 1865 | struct sbp2_lu *lu = (struct sbp2_lu *)SCpnt->device->host->hostdata[0]; |
| 2305 | (struct scsi_id_instance_data *)SCpnt->device->host->hostdata[0]; | 1866 | struct sbp2_fwhost_info *hi; |
| 2306 | struct sbp2scsi_host_info *hi; | ||
| 2307 | int result = DID_NO_CONNECT << 16; | 1867 | int result = DID_NO_CONNECT << 16; |
| 2308 | 1868 | ||
| 2309 | SBP2_DEBUG_ENTER(); | 1869 | if (unlikely(!sbp2util_node_is_available(lu))) |
| 2310 | #if (CONFIG_IEEE1394_SBP2_DEBUG >= 2) || defined(CONFIG_IEEE1394_SBP2_PACKET_DUMP) | ||
| 2311 | scsi_print_command(SCpnt); | ||
| 2312 | #endif | ||
| 2313 | |||
| 2314 | if (!sbp2util_node_is_available(scsi_id)) | ||
| 2315 | goto done; | 1870 | goto done; |
| 2316 | 1871 | ||
| 2317 | hi = scsi_id->hi; | 1872 | hi = lu->hi; |
| 2318 | 1873 | ||
| 2319 | if (!hi) { | 1874 | if (unlikely(!hi)) { |
| 2320 | SBP2_ERR("sbp2scsi_host_info is NULL - this is bad!"); | 1875 | SBP2_ERR("sbp2_fwhost_info is NULL - this is bad!"); |
| 2321 | goto done; | 1876 | goto done; |
| 2322 | } | 1877 | } |
| 2323 | 1878 | ||
| 2324 | /* | 1879 | /* Multiple units are currently represented to the SCSI core as separate |
| 2325 | * Until we handle multiple luns, just return selection time-out | 1880 | * targets, not as one target with multiple LUs. Therefore return |
| 2326 | * to any IO directed at non-zero LUNs | 1881 | * selection time-out to any IO directed at non-zero LUNs. */ |
| 2327 | */ | 1882 | if (unlikely(SCpnt->device->lun)) |
| 2328 | if (SCpnt->device->lun) | ||
| 2329 | goto done; | 1883 | goto done; |
| 2330 | 1884 | ||
| 2331 | /* | 1885 | /* handle the request sense command here (auto-request sense) */ |
| 2332 | * Check for request sense command, and handle it here | ||
| 2333 | * (autorequest sense) | ||
| 2334 | */ | ||
| 2335 | if (SCpnt->cmnd[0] == REQUEST_SENSE) { | 1886 | if (SCpnt->cmnd[0] == REQUEST_SENSE) { |
| 2336 | SBP2_DEBUG("REQUEST_SENSE"); | 1887 | memcpy(SCpnt->request_buffer, SCpnt->sense_buffer, |
| 2337 | memcpy(SCpnt->request_buffer, SCpnt->sense_buffer, SCpnt->request_bufflen); | 1888 | SCpnt->request_bufflen); |
| 2338 | memset(SCpnt->sense_buffer, 0, sizeof(SCpnt->sense_buffer)); | 1889 | memset(SCpnt->sense_buffer, 0, sizeof(SCpnt->sense_buffer)); |
| 2339 | sbp2scsi_complete_command(scsi_id, SBP2_SCSI_STATUS_GOOD, SCpnt, done); | 1890 | sbp2scsi_complete_command(lu, SBP2_SCSI_STATUS_GOOD, SCpnt, |
| 1891 | done); | ||
| 2340 | return 0; | 1892 | return 0; |
| 2341 | } | 1893 | } |
| 2342 | 1894 | ||
| 2343 | /* | 1895 | if (unlikely(!hpsb_node_entry_valid(lu->ne))) { |
| 2344 | * Check to see if we are in the middle of a bus reset. | ||
| 2345 | */ | ||
| 2346 | if (!hpsb_node_entry_valid(scsi_id->ne)) { | ||
| 2347 | SBP2_ERR("Bus reset in progress - rejecting command"); | 1896 | SBP2_ERR("Bus reset in progress - rejecting command"); |
| 2348 | result = DID_BUS_BUSY << 16; | 1897 | result = DID_BUS_BUSY << 16; |
| 2349 | goto done; | 1898 | goto done; |
| 2350 | } | 1899 | } |
| 2351 | 1900 | ||
| 2352 | /* | 1901 | /* Bidirectional commands are not yet implemented, |
| 2353 | * Bidirectional commands are not yet implemented, | 1902 | * and unknown transfer direction not handled. */ |
| 2354 | * and unknown transfer direction not handled. | 1903 | if (unlikely(SCpnt->sc_data_direction == DMA_BIDIRECTIONAL)) { |
| 2355 | */ | ||
| 2356 | if (SCpnt->sc_data_direction == DMA_BIDIRECTIONAL) { | ||
| 2357 | SBP2_ERR("Cannot handle DMA_BIDIRECTIONAL - rejecting command"); | 1904 | SBP2_ERR("Cannot handle DMA_BIDIRECTIONAL - rejecting command"); |
| 2358 | result = DID_ERROR << 16; | 1905 | result = DID_ERROR << 16; |
| 2359 | goto done; | 1906 | goto done; |
| 2360 | } | 1907 | } |
| 2361 | 1908 | ||
| 2362 | /* | 1909 | if (sbp2_send_command(lu, SCpnt, done)) { |
| 2363 | * Try and send our SCSI command | ||
| 2364 | */ | ||
| 2365 | if (sbp2_send_command(scsi_id, SCpnt, done)) { | ||
| 2366 | SBP2_ERR("Error sending SCSI command"); | 1910 | SBP2_ERR("Error sending SCSI command"); |
| 2367 | sbp2scsi_complete_command(scsi_id, SBP2_SCSI_STATUS_SELECTION_TIMEOUT, | 1911 | sbp2scsi_complete_command(lu, |
| 1912 | SBP2_SCSI_STATUS_SELECTION_TIMEOUT, | ||
| 2368 | SCpnt, done); | 1913 | SCpnt, done); |
| 2369 | } | 1914 | } |
| 2370 | return 0; | 1915 | return 0; |
| @@ -2375,75 +1920,46 @@ done: | |||
| 2375 | return 0; | 1920 | return 0; |
| 2376 | } | 1921 | } |
| 2377 | 1922 | ||
| 2378 | /* | 1923 | static void sbp2scsi_complete_all_commands(struct sbp2_lu *lu, u32 status) |
| 2379 | * This function is called in order to complete all outstanding SBP-2 | ||
| 2380 | * commands (in case of resets, etc.). | ||
| 2381 | */ | ||
| 2382 | static void sbp2scsi_complete_all_commands(struct scsi_id_instance_data *scsi_id, | ||
| 2383 | u32 status) | ||
| 2384 | { | 1924 | { |
| 2385 | struct sbp2scsi_host_info *hi = scsi_id->hi; | 1925 | struct sbp2_fwhost_info *hi = lu->hi; |
| 2386 | struct list_head *lh; | 1926 | struct list_head *lh; |
| 2387 | struct sbp2_command_info *command; | 1927 | struct sbp2_command_info *cmd; |
| 2388 | unsigned long flags; | 1928 | unsigned long flags; |
| 2389 | 1929 | ||
| 2390 | SBP2_DEBUG_ENTER(); | 1930 | spin_lock_irqsave(&lu->cmd_orb_lock, flags); |
| 2391 | 1931 | while (!list_empty(&lu->cmd_orb_inuse)) { | |
| 2392 | spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); | 1932 | lh = lu->cmd_orb_inuse.next; |
| 2393 | while (!list_empty(&scsi_id->sbp2_command_orb_inuse)) { | 1933 | cmd = list_entry(lh, struct sbp2_command_info, list); |
| 2394 | SBP2_DEBUG("Found pending command to complete"); | 1934 | dma_sync_single_for_cpu(&hi->host->device, cmd->command_orb_dma, |
| 2395 | lh = scsi_id->sbp2_command_orb_inuse.next; | 1935 | sizeof(struct sbp2_command_orb), |
| 2396 | command = list_entry(lh, struct sbp2_command_info, list); | 1936 | DMA_TO_DEVICE); |
| 2397 | pci_dma_sync_single_for_cpu(hi->host->pdev, command->command_orb_dma, | 1937 | dma_sync_single_for_cpu(&hi->host->device, cmd->sge_dma, |
| 2398 | sizeof(struct sbp2_command_orb), | 1938 | sizeof(cmd->scatter_gather_element), |
| 2399 | PCI_DMA_TODEVICE); | 1939 | DMA_BIDIRECTIONAL); |
| 2400 | pci_dma_sync_single_for_cpu(hi->host->pdev, command->sge_dma, | 1940 | sbp2util_mark_command_completed(lu, cmd); |
| 2401 | sizeof(command->scatter_gather_element), | 1941 | if (cmd->Current_SCpnt) { |
| 2402 | PCI_DMA_BIDIRECTIONAL); | 1942 | cmd->Current_SCpnt->result = status << 16; |
| 2403 | sbp2util_mark_command_completed(scsi_id, command); | 1943 | cmd->Current_done(cmd->Current_SCpnt); |
| 2404 | if (command->Current_SCpnt) { | ||
| 2405 | command->Current_SCpnt->result = status << 16; | ||
| 2406 | command->Current_done(command->Current_SCpnt); | ||
| 2407 | } | 1944 | } |
| 2408 | } | 1945 | } |
| 2409 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); | 1946 | spin_unlock_irqrestore(&lu->cmd_orb_lock, flags); |
| 2410 | 1947 | ||
| 2411 | return; | 1948 | return; |
| 2412 | } | 1949 | } |
| 2413 | 1950 | ||
| 2414 | /* | 1951 | /* |
| 2415 | * This function is called in order to complete a regular SBP-2 command. | 1952 | * Complete a regular SCSI command. Can be called in atomic context. |
| 2416 | * | ||
| 2417 | * This can be called in interrupt context. | ||
| 2418 | */ | 1953 | */ |
| 2419 | static void sbp2scsi_complete_command(struct scsi_id_instance_data *scsi_id, | 1954 | static void sbp2scsi_complete_command(struct sbp2_lu *lu, u32 scsi_status, |
| 2420 | u32 scsi_status, struct scsi_cmnd *SCpnt, | 1955 | struct scsi_cmnd *SCpnt, |
| 2421 | void (*done)(struct scsi_cmnd *)) | 1956 | void (*done)(struct scsi_cmnd *)) |
| 2422 | { | 1957 | { |
| 2423 | SBP2_DEBUG_ENTER(); | ||
| 2424 | |||
| 2425 | /* | ||
| 2426 | * Sanity | ||
| 2427 | */ | ||
| 2428 | if (!SCpnt) { | 1958 | if (!SCpnt) { |
| 2429 | SBP2_ERR("SCpnt is NULL"); | 1959 | SBP2_ERR("SCpnt is NULL"); |
| 2430 | return; | 1960 | return; |
| 2431 | } | 1961 | } |
| 2432 | 1962 | ||
| 2433 | /* | ||
| 2434 | * If a bus reset is in progress and there was an error, don't | ||
| 2435 | * complete the command, just let it get retried at the end of the | ||
| 2436 | * bus reset. | ||
| 2437 | */ | ||
| 2438 | if (!hpsb_node_entry_valid(scsi_id->ne) | ||
| 2439 | && (scsi_status != SBP2_SCSI_STATUS_GOOD)) { | ||
| 2440 | SBP2_ERR("Bus reset in progress - retry command later"); | ||
| 2441 | return; | ||
| 2442 | } | ||
| 2443 | |||
| 2444 | /* | ||
| 2445 | * Switch on scsi status | ||
| 2446 | */ | ||
| 2447 | switch (scsi_status) { | 1963 | switch (scsi_status) { |
| 2448 | case SBP2_SCSI_STATUS_GOOD: | 1964 | case SBP2_SCSI_STATUS_GOOD: |
| 2449 | SCpnt->result = DID_OK << 16; | 1965 | SCpnt->result = DID_OK << 16; |
| @@ -2455,12 +1971,7 @@ static void sbp2scsi_complete_command(struct scsi_id_instance_data *scsi_id, | |||
| 2455 | break; | 1971 | break; |
| 2456 | 1972 | ||
| 2457 | case SBP2_SCSI_STATUS_CHECK_CONDITION: | 1973 | case SBP2_SCSI_STATUS_CHECK_CONDITION: |
| 2458 | SBP2_DEBUG("SBP2_SCSI_STATUS_CHECK_CONDITION"); | ||
| 2459 | SCpnt->result = CHECK_CONDITION << 1 | DID_OK << 16; | 1974 | SCpnt->result = CHECK_CONDITION << 1 | DID_OK << 16; |
| 2460 | #if CONFIG_IEEE1394_SBP2_DEBUG >= 1 | ||
| 2461 | scsi_print_command(SCpnt); | ||
| 2462 | scsi_print_sense(SBP2_DEVICE_NAME, SCpnt); | ||
| 2463 | #endif | ||
| 2464 | break; | 1975 | break; |
| 2465 | 1976 | ||
| 2466 | case SBP2_SCSI_STATUS_SELECTION_TIMEOUT: | 1977 | case SBP2_SCSI_STATUS_SELECTION_TIMEOUT: |
| @@ -2482,118 +1993,88 @@ static void sbp2scsi_complete_command(struct scsi_id_instance_data *scsi_id, | |||
| 2482 | SCpnt->result = DID_ERROR << 16; | 1993 | SCpnt->result = DID_ERROR << 16; |
| 2483 | } | 1994 | } |
| 2484 | 1995 | ||
| 2485 | /* | 1996 | /* If a bus reset is in progress and there was an error, complete |
| 2486 | * If a bus reset is in progress and there was an error, complete | 1997 | * the command as busy so that it will get retried. */ |
| 2487 | * the command as busy so that it will get retried. | 1998 | if (!hpsb_node_entry_valid(lu->ne) |
| 2488 | */ | ||
| 2489 | if (!hpsb_node_entry_valid(scsi_id->ne) | ||
| 2490 | && (scsi_status != SBP2_SCSI_STATUS_GOOD)) { | 1999 | && (scsi_status != SBP2_SCSI_STATUS_GOOD)) { |
| 2491 | SBP2_ERR("Completing command with busy (bus reset)"); | 2000 | SBP2_ERR("Completing command with busy (bus reset)"); |
| 2492 | SCpnt->result = DID_BUS_BUSY << 16; | 2001 | SCpnt->result = DID_BUS_BUSY << 16; |
| 2493 | } | 2002 | } |
| 2494 | 2003 | ||
| 2495 | /* | 2004 | /* Tell the SCSI stack that we're done with this command. */ |
| 2496 | * If a unit attention occurs, return busy status so it gets | ||
| 2497 | * retried... it could have happened because of a 1394 bus reset | ||
| 2498 | * or hot-plug... | ||
| 2499 | * XXX DID_BUS_BUSY is actually a bad idea because it will defy | ||
| 2500 | * the scsi layer's retry logic. | ||
| 2501 | */ | ||
| 2502 | #if 0 | ||
| 2503 | if ((scsi_status == SBP2_SCSI_STATUS_CHECK_CONDITION) && | ||
| 2504 | (SCpnt->sense_buffer[2] == UNIT_ATTENTION)) { | ||
| 2505 | SBP2_DEBUG("UNIT ATTENTION - return busy"); | ||
| 2506 | SCpnt->result = DID_BUS_BUSY << 16; | ||
| 2507 | } | ||
| 2508 | #endif | ||
| 2509 | |||
| 2510 | /* | ||
| 2511 | * Tell scsi stack that we're done with this command | ||
| 2512 | */ | ||
| 2513 | done(SCpnt); | 2005 | done(SCpnt); |
| 2514 | } | 2006 | } |
| 2515 | 2007 | ||
| 2516 | static int sbp2scsi_slave_alloc(struct scsi_device *sdev) | 2008 | static int sbp2scsi_slave_alloc(struct scsi_device *sdev) |
| 2517 | { | 2009 | { |
| 2518 | struct scsi_id_instance_data *scsi_id = | 2010 | struct sbp2_lu *lu = (struct sbp2_lu *)sdev->host->hostdata[0]; |
| 2519 | (struct scsi_id_instance_data *)sdev->host->hostdata[0]; | ||
| 2520 | 2011 | ||
| 2521 | scsi_id->sdev = sdev; | 2012 | lu->sdev = sdev; |
| 2522 | sdev->allow_restart = 1; | 2013 | sdev->allow_restart = 1; |
| 2523 | 2014 | ||
| 2524 | if (scsi_id->workarounds & SBP2_WORKAROUND_INQUIRY_36) | 2015 | if (lu->workarounds & SBP2_WORKAROUND_INQUIRY_36) |
| 2525 | sdev->inquiry_len = 36; | 2016 | sdev->inquiry_len = 36; |
| 2526 | return 0; | 2017 | return 0; |
| 2527 | } | 2018 | } |
| 2528 | 2019 | ||
| 2529 | static int sbp2scsi_slave_configure(struct scsi_device *sdev) | 2020 | static int sbp2scsi_slave_configure(struct scsi_device *sdev) |
| 2530 | { | 2021 | { |
| 2531 | struct scsi_id_instance_data *scsi_id = | 2022 | struct sbp2_lu *lu = (struct sbp2_lu *)sdev->host->hostdata[0]; |
| 2532 | (struct scsi_id_instance_data *)sdev->host->hostdata[0]; | ||
| 2533 | 2023 | ||
| 2534 | blk_queue_dma_alignment(sdev->request_queue, (512 - 1)); | 2024 | blk_queue_dma_alignment(sdev->request_queue, (512 - 1)); |
| 2535 | sdev->use_10_for_rw = 1; | 2025 | sdev->use_10_for_rw = 1; |
| 2536 | 2026 | ||
| 2537 | if (sdev->type == TYPE_DISK && | 2027 | if (sdev->type == TYPE_DISK && |
| 2538 | scsi_id->workarounds & SBP2_WORKAROUND_MODE_SENSE_8) | 2028 | lu->workarounds & SBP2_WORKAROUND_MODE_SENSE_8) |
| 2539 | sdev->skip_ms_page_8 = 1; | 2029 | sdev->skip_ms_page_8 = 1; |
| 2540 | if (scsi_id->workarounds & SBP2_WORKAROUND_FIX_CAPACITY) | 2030 | if (lu->workarounds & SBP2_WORKAROUND_FIX_CAPACITY) |
| 2541 | sdev->fix_capacity = 1; | 2031 | sdev->fix_capacity = 1; |
| 2542 | return 0; | 2032 | return 0; |
| 2543 | } | 2033 | } |
| 2544 | 2034 | ||
| 2545 | static void sbp2scsi_slave_destroy(struct scsi_device *sdev) | 2035 | static void sbp2scsi_slave_destroy(struct scsi_device *sdev) |
| 2546 | { | 2036 | { |
| 2547 | ((struct scsi_id_instance_data *)sdev->host->hostdata[0])->sdev = NULL; | 2037 | ((struct sbp2_lu *)sdev->host->hostdata[0])->sdev = NULL; |
| 2548 | return; | 2038 | return; |
| 2549 | } | 2039 | } |
| 2550 | 2040 | ||
| 2551 | /* | 2041 | /* |
| 2552 | * Called by scsi stack when something has really gone wrong. Usually | 2042 | * Called by scsi stack when something has really gone wrong. |
| 2553 | * called when a command has timed-out for some reason. | 2043 | * Usually called when a command has timed-out for some reason. |
| 2554 | */ | 2044 | */ |
| 2555 | static int sbp2scsi_abort(struct scsi_cmnd *SCpnt) | 2045 | static int sbp2scsi_abort(struct scsi_cmnd *SCpnt) |
| 2556 | { | 2046 | { |
| 2557 | struct scsi_id_instance_data *scsi_id = | 2047 | struct sbp2_lu *lu = (struct sbp2_lu *)SCpnt->device->host->hostdata[0]; |
| 2558 | (struct scsi_id_instance_data *)SCpnt->device->host->hostdata[0]; | 2048 | struct sbp2_fwhost_info *hi = lu->hi; |
| 2559 | struct sbp2scsi_host_info *hi = scsi_id->hi; | 2049 | struct sbp2_command_info *cmd; |
| 2560 | struct sbp2_command_info *command; | ||
| 2561 | unsigned long flags; | 2050 | unsigned long flags; |
| 2562 | 2051 | ||
| 2563 | SBP2_ERR("aborting sbp2 command"); | 2052 | SBP2_INFO("aborting sbp2 command"); |
| 2564 | scsi_print_command(SCpnt); | 2053 | scsi_print_command(SCpnt); |
| 2565 | 2054 | ||
| 2566 | if (sbp2util_node_is_available(scsi_id)) { | 2055 | if (sbp2util_node_is_available(lu)) { |
| 2567 | 2056 | sbp2_agent_reset(lu, 1); | |
| 2568 | /* | 2057 | |
| 2569 | * Right now, just return any matching command structures | 2058 | /* Return a matching command structure to the free pool. */ |
| 2570 | * to the free pool. | 2059 | spin_lock_irqsave(&lu->cmd_orb_lock, flags); |
| 2571 | */ | 2060 | cmd = sbp2util_find_command_for_SCpnt(lu, SCpnt); |
| 2572 | spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); | 2061 | if (cmd) { |
| 2573 | command = sbp2util_find_command_for_SCpnt(scsi_id, SCpnt); | 2062 | dma_sync_single_for_cpu(&hi->host->device, |
| 2574 | if (command) { | 2063 | cmd->command_orb_dma, |
| 2575 | SBP2_DEBUG("Found command to abort"); | 2064 | sizeof(struct sbp2_command_orb), |
| 2576 | pci_dma_sync_single_for_cpu(hi->host->pdev, | 2065 | DMA_TO_DEVICE); |
| 2577 | command->command_orb_dma, | 2066 | dma_sync_single_for_cpu(&hi->host->device, cmd->sge_dma, |
| 2578 | sizeof(struct sbp2_command_orb), | 2067 | sizeof(cmd->scatter_gather_element), |
| 2579 | PCI_DMA_TODEVICE); | 2068 | DMA_BIDIRECTIONAL); |
| 2580 | pci_dma_sync_single_for_cpu(hi->host->pdev, | 2069 | sbp2util_mark_command_completed(lu, cmd); |
| 2581 | command->sge_dma, | 2070 | if (cmd->Current_SCpnt) { |
| 2582 | sizeof(command->scatter_gather_element), | 2071 | cmd->Current_SCpnt->result = DID_ABORT << 16; |
| 2583 | PCI_DMA_BIDIRECTIONAL); | 2072 | cmd->Current_done(cmd->Current_SCpnt); |
| 2584 | sbp2util_mark_command_completed(scsi_id, command); | ||
| 2585 | if (command->Current_SCpnt) { | ||
| 2586 | command->Current_SCpnt->result = DID_ABORT << 16; | ||
| 2587 | command->Current_done(command->Current_SCpnt); | ||
| 2588 | } | 2073 | } |
| 2589 | } | 2074 | } |
| 2590 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); | 2075 | spin_unlock_irqrestore(&lu->cmd_orb_lock, flags); |
| 2591 | 2076 | ||
| 2592 | /* | 2077 | sbp2scsi_complete_all_commands(lu, DID_BUS_BUSY); |
| 2593 | * Initiate a fetch agent reset. | ||
| 2594 | */ | ||
| 2595 | sbp2_agent_reset(scsi_id, 1); | ||
| 2596 | sbp2scsi_complete_all_commands(scsi_id, DID_BUS_BUSY); | ||
| 2597 | } | 2078 | } |
| 2598 | 2079 | ||
| 2599 | return SUCCESS; | 2080 | return SUCCESS; |
| @@ -2604,14 +2085,13 @@ static int sbp2scsi_abort(struct scsi_cmnd *SCpnt) | |||
| 2604 | */ | 2085 | */ |
| 2605 | static int sbp2scsi_reset(struct scsi_cmnd *SCpnt) | 2086 | static int sbp2scsi_reset(struct scsi_cmnd *SCpnt) |
| 2606 | { | 2087 | { |
| 2607 | struct scsi_id_instance_data *scsi_id = | 2088 | struct sbp2_lu *lu = (struct sbp2_lu *)SCpnt->device->host->hostdata[0]; |
| 2608 | (struct scsi_id_instance_data *)SCpnt->device->host->hostdata[0]; | ||
| 2609 | 2089 | ||
| 2610 | SBP2_ERR("reset requested"); | 2090 | SBP2_INFO("reset requested"); |
| 2611 | 2091 | ||
| 2612 | if (sbp2util_node_is_available(scsi_id)) { | 2092 | if (sbp2util_node_is_available(lu)) { |
| 2613 | SBP2_ERR("Generating sbp2 fetch agent reset"); | 2093 | SBP2_INFO("generating sbp2 fetch agent reset"); |
| 2614 | sbp2_agent_reset(scsi_id, 1); | 2094 | sbp2_agent_reset(lu, 1); |
| 2615 | } | 2095 | } |
| 2616 | 2096 | ||
| 2617 | return SUCCESS; | 2097 | return SUCCESS; |
| @@ -2622,90 +2102,50 @@ static ssize_t sbp2_sysfs_ieee1394_id_show(struct device *dev, | |||
| 2622 | char *buf) | 2102 | char *buf) |
| 2623 | { | 2103 | { |
| 2624 | struct scsi_device *sdev; | 2104 | struct scsi_device *sdev; |
| 2625 | struct scsi_id_instance_data *scsi_id; | 2105 | struct sbp2_lu *lu; |
| 2626 | int lun; | ||
| 2627 | 2106 | ||
| 2628 | if (!(sdev = to_scsi_device(dev))) | 2107 | if (!(sdev = to_scsi_device(dev))) |
| 2629 | return 0; | 2108 | return 0; |
| 2630 | 2109 | ||
| 2631 | if (!(scsi_id = (struct scsi_id_instance_data *)sdev->host->hostdata[0])) | 2110 | if (!(lu = (struct sbp2_lu *)sdev->host->hostdata[0])) |
| 2632 | return 0; | 2111 | return 0; |
| 2633 | 2112 | ||
| 2634 | lun = ORB_SET_LUN(scsi_id->sbp2_lun); | 2113 | return sprintf(buf, "%016Lx:%d:%d\n", (unsigned long long)lu->ne->guid, |
| 2635 | 2114 | lu->ud->id, ORB_SET_LUN(lu->lun)); | |
| 2636 | return sprintf(buf, "%016Lx:%d:%d\n", (unsigned long long)scsi_id->ne->guid, | ||
| 2637 | scsi_id->ud->id, lun); | ||
| 2638 | } | 2115 | } |
| 2639 | static DEVICE_ATTR(ieee1394_id, S_IRUGO, sbp2_sysfs_ieee1394_id_show, NULL); | ||
| 2640 | |||
| 2641 | static struct device_attribute *sbp2_sysfs_sdev_attrs[] = { | ||
| 2642 | &dev_attr_ieee1394_id, | ||
| 2643 | NULL | ||
| 2644 | }; | ||
| 2645 | 2116 | ||
| 2646 | MODULE_AUTHOR("Ben Collins <bcollins@debian.org>"); | 2117 | MODULE_AUTHOR("Ben Collins <bcollins@debian.org>"); |
| 2647 | MODULE_DESCRIPTION("IEEE-1394 SBP-2 protocol driver"); | 2118 | MODULE_DESCRIPTION("IEEE-1394 SBP-2 protocol driver"); |
| 2648 | MODULE_SUPPORTED_DEVICE(SBP2_DEVICE_NAME); | 2119 | MODULE_SUPPORTED_DEVICE(SBP2_DEVICE_NAME); |
| 2649 | MODULE_LICENSE("GPL"); | 2120 | MODULE_LICENSE("GPL"); |
| 2650 | 2121 | ||
| 2651 | /* SCSI host template */ | ||
| 2652 | static struct scsi_host_template scsi_driver_template = { | ||
| 2653 | .module = THIS_MODULE, | ||
| 2654 | .name = "SBP-2 IEEE-1394", | ||
| 2655 | .proc_name = SBP2_DEVICE_NAME, | ||
| 2656 | .queuecommand = sbp2scsi_queuecommand, | ||
| 2657 | .eh_abort_handler = sbp2scsi_abort, | ||
| 2658 | .eh_device_reset_handler = sbp2scsi_reset, | ||
| 2659 | .slave_alloc = sbp2scsi_slave_alloc, | ||
| 2660 | .slave_configure = sbp2scsi_slave_configure, | ||
| 2661 | .slave_destroy = sbp2scsi_slave_destroy, | ||
| 2662 | .this_id = -1, | ||
| 2663 | .sg_tablesize = SG_ALL, | ||
| 2664 | .use_clustering = ENABLE_CLUSTERING, | ||
| 2665 | .cmd_per_lun = SBP2_MAX_CMDS, | ||
| 2666 | .can_queue = SBP2_MAX_CMDS, | ||
| 2667 | .emulated = 1, | ||
| 2668 | .sdev_attrs = sbp2_sysfs_sdev_attrs, | ||
| 2669 | }; | ||
| 2670 | |||
| 2671 | static int sbp2_module_init(void) | 2122 | static int sbp2_module_init(void) |
| 2672 | { | 2123 | { |
| 2673 | int ret; | 2124 | int ret; |
| 2674 | 2125 | ||
| 2675 | SBP2_DEBUG_ENTER(); | 2126 | if (sbp2_serialize_io) { |
| 2676 | 2127 | sbp2_shost_template.can_queue = 1; | |
| 2677 | /* Module load debug option to force one command at a time (serializing I/O) */ | 2128 | sbp2_shost_template.cmd_per_lun = 1; |
| 2678 | if (serialize_io) { | ||
| 2679 | SBP2_INFO("Driver forced to serialize I/O (serialize_io=1)"); | ||
| 2680 | SBP2_INFO("Try serialize_io=0 for better performance"); | ||
| 2681 | scsi_driver_template.can_queue = 1; | ||
| 2682 | scsi_driver_template.cmd_per_lun = 1; | ||
| 2683 | } | 2129 | } |
| 2684 | 2130 | ||
| 2685 | if (sbp2_default_workarounds & SBP2_WORKAROUND_128K_MAX_TRANS && | 2131 | if (sbp2_default_workarounds & SBP2_WORKAROUND_128K_MAX_TRANS && |
| 2686 | (max_sectors * 512) > (128 * 1024)) | 2132 | (sbp2_max_sectors * 512) > (128 * 1024)) |
| 2687 | max_sectors = 128 * 1024 / 512; | 2133 | sbp2_max_sectors = 128 * 1024 / 512; |
| 2688 | scsi_driver_template.max_sectors = max_sectors; | 2134 | sbp2_shost_template.max_sectors = sbp2_max_sectors; |
| 2689 | 2135 | ||
| 2690 | /* Register our high level driver with 1394 stack */ | ||
| 2691 | hpsb_register_highlevel(&sbp2_highlevel); | 2136 | hpsb_register_highlevel(&sbp2_highlevel); |
| 2692 | |||
| 2693 | ret = hpsb_register_protocol(&sbp2_driver); | 2137 | ret = hpsb_register_protocol(&sbp2_driver); |
| 2694 | if (ret) { | 2138 | if (ret) { |
| 2695 | SBP2_ERR("Failed to register protocol"); | 2139 | SBP2_ERR("Failed to register protocol"); |
| 2696 | hpsb_unregister_highlevel(&sbp2_highlevel); | 2140 | hpsb_unregister_highlevel(&sbp2_highlevel); |
| 2697 | return ret; | 2141 | return ret; |
| 2698 | } | 2142 | } |
| 2699 | |||
| 2700 | return 0; | 2143 | return 0; |
| 2701 | } | 2144 | } |
| 2702 | 2145 | ||
| 2703 | static void __exit sbp2_module_exit(void) | 2146 | static void __exit sbp2_module_exit(void) |
| 2704 | { | 2147 | { |
| 2705 | SBP2_DEBUG_ENTER(); | ||
| 2706 | |||
| 2707 | hpsb_unregister_protocol(&sbp2_driver); | 2148 | hpsb_unregister_protocol(&sbp2_driver); |
| 2708 | |||
| 2709 | hpsb_unregister_highlevel(&sbp2_highlevel); | 2149 | hpsb_unregister_highlevel(&sbp2_highlevel); |
| 2710 | } | 2150 | } |
| 2711 | 2151 | ||
