Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 1 | /* |
| 2 | * SBP2 driver (SCSI over IEEE1394) |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 3 | * |
Kristian Høgsberg | 27a15e5 | 2007-02-06 14:49:39 -0500 | [diff] [blame] | 4 | * Copyright (C) 2005-2007 Kristian Hoegsberg <krh@bitplanet.net> |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software Foundation, |
| 18 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 | */ |
| 20 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 21 | /* |
| 22 | * The basic structure of this driver is based on the old storage driver, |
Kristian Høgsberg | 27a15e5 | 2007-02-06 14:49:39 -0500 | [diff] [blame] | 23 | * drivers/ieee1394/sbp2.c, originally written by |
| 24 | * James Goodwin <jamesg@filanet.com> |
| 25 | * with later contributions and ongoing maintenance from |
| 26 | * Ben Collins <bcollins@debian.org>, |
| 27 | * Stefan Richter <stefanr@s5r6.in-berlin.de> |
| 28 | * and many others. |
| 29 | */ |
| 30 | |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 31 | #include <linux/kernel.h> |
| 32 | #include <linux/module.h> |
Stefan Richter | 5cd54c9 | 2007-06-17 23:55:41 +0200 | [diff] [blame] | 33 | #include <linux/moduleparam.h> |
Stefan Richter | fe69ca3 | 2006-12-28 12:46:54 +0100 | [diff] [blame] | 34 | #include <linux/mod_devicetable.h> |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 35 | #include <linux/device.h> |
Andrew Morton | 0b5b290 | 2006-12-27 14:49:23 -0800 | [diff] [blame] | 36 | #include <linux/scatterlist.h> |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 37 | #include <linux/dma-mapping.h> |
Stefan Richter | cf47c7a | 2007-06-17 23:52:08 +0200 | [diff] [blame] | 38 | #include <linux/blkdev.h> |
Stefan Richter | e7cdf23 | 2007-07-01 13:54:57 +0200 | [diff] [blame] | 39 | #include <linux/string.h> |
Kristian Høgsberg | 1d3d52c | 2007-02-06 14:49:33 -0500 | [diff] [blame] | 40 | #include <linux/timer.h> |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 41 | |
| 42 | #include <scsi/scsi.h> |
| 43 | #include <scsi/scsi_cmnd.h> |
| 44 | #include <scsi/scsi_dbg.h> |
| 45 | #include <scsi/scsi_device.h> |
| 46 | #include <scsi/scsi_host.h> |
| 47 | |
| 48 | #include "fw-transaction.h" |
| 49 | #include "fw-topology.h" |
| 50 | #include "fw-device.h" |
| 51 | |
Stefan Richter | 5cd54c9 | 2007-06-17 23:55:41 +0200 | [diff] [blame] | 52 | /* |
| 53 | * So far only bridges from Oxford Semiconductor are known to support |
| 54 | * concurrent logins. Depending on firmware, four or two concurrent logins |
| 55 | * are possible on OXFW911 and newer Oxsemi bridges. |
| 56 | * |
| 57 | * Concurrent logins are useful together with cluster filesystems. |
| 58 | */ |
| 59 | static int sbp2_param_exclusive_login = 1; |
| 60 | module_param_named(exclusive_login, sbp2_param_exclusive_login, bool, 0644); |
| 61 | MODULE_PARM_DESC(exclusive_login, "Exclusive login to sbp2 device " |
| 62 | "(default = Y, use N for concurrent initiators)"); |
| 63 | |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 64 | /* I don't know why the SCSI stack doesn't define something like this... */ |
Kristian Høgsberg | a98e271 | 2007-05-07 20:33:34 -0400 | [diff] [blame] | 65 | typedef void (*scsi_done_fn_t)(struct scsi_cmnd *); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 66 | |
| 67 | static const char sbp2_driver_name[] = "sbp2"; |
| 68 | |
| 69 | struct sbp2_device { |
Kristian Høgsberg | b3d6e15 | 2007-03-14 17:34:58 -0400 | [diff] [blame] | 70 | struct kref kref; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 71 | struct fw_unit *unit; |
| 72 | struct fw_address_handler address_handler; |
| 73 | struct list_head orb_list; |
| 74 | u64 management_agent_address; |
| 75 | u64 command_block_agent_address; |
| 76 | u32 workarounds; |
| 77 | int login_id; |
| 78 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 79 | /* |
| 80 | * We cache these addresses and only update them once we've |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 81 | * logged in or reconnected to the sbp2 device. That way, any |
| 82 | * IO to the device will automatically fail and get retried if |
| 83 | * it happens in a window where the device is not ready to |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 84 | * handle it (e.g. after a bus reset but before we reconnect). |
| 85 | */ |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 86 | int node_id; |
| 87 | int address_high; |
| 88 | int generation; |
| 89 | |
Kristian Høgsberg | 7f37c42 | 2007-02-06 14:49:34 -0500 | [diff] [blame] | 90 | int retries; |
| 91 | struct delayed_work work; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | #define SBP2_MAX_SG_ELEMENT_LENGTH 0xf000 |
| 95 | #define SBP2_MAX_SECTORS 255 /* Max sectors supported */ |
Kristian Høgsberg | 1d3d52c | 2007-02-06 14:49:33 -0500 | [diff] [blame] | 96 | #define SBP2_ORB_TIMEOUT 2000 /* Timeout in ms */ |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 97 | |
| 98 | #define SBP2_ORB_NULL 0x80000000 |
| 99 | |
| 100 | #define SBP2_DIRECTION_TO_MEDIA 0x0 |
| 101 | #define SBP2_DIRECTION_FROM_MEDIA 0x1 |
| 102 | |
| 103 | /* Unit directory keys */ |
| 104 | #define SBP2_COMMAND_SET_SPECIFIER 0x38 |
| 105 | #define SBP2_COMMAND_SET 0x39 |
| 106 | #define SBP2_COMMAND_SET_REVISION 0x3b |
| 107 | #define SBP2_FIRMWARE_REVISION 0x3c |
| 108 | |
| 109 | /* Flags for detected oddities and brokeness */ |
| 110 | #define SBP2_WORKAROUND_128K_MAX_TRANS 0x1 |
| 111 | #define SBP2_WORKAROUND_INQUIRY_36 0x2 |
| 112 | #define SBP2_WORKAROUND_MODE_SENSE_8 0x4 |
| 113 | #define SBP2_WORKAROUND_FIX_CAPACITY 0x8 |
| 114 | #define SBP2_WORKAROUND_OVERRIDE 0x100 |
| 115 | |
| 116 | /* Management orb opcodes */ |
| 117 | #define SBP2_LOGIN_REQUEST 0x0 |
| 118 | #define SBP2_QUERY_LOGINS_REQUEST 0x1 |
| 119 | #define SBP2_RECONNECT_REQUEST 0x3 |
| 120 | #define SBP2_SET_PASSWORD_REQUEST 0x4 |
| 121 | #define SBP2_LOGOUT_REQUEST 0x7 |
| 122 | #define SBP2_ABORT_TASK_REQUEST 0xb |
| 123 | #define SBP2_ABORT_TASK_SET 0xc |
| 124 | #define SBP2_LOGICAL_UNIT_RESET 0xe |
| 125 | #define SBP2_TARGET_RESET_REQUEST 0xf |
| 126 | |
| 127 | /* Offsets for command block agent registers */ |
| 128 | #define SBP2_AGENT_STATE 0x00 |
| 129 | #define SBP2_AGENT_RESET 0x04 |
| 130 | #define SBP2_ORB_POINTER 0x08 |
| 131 | #define SBP2_DOORBELL 0x10 |
| 132 | #define SBP2_UNSOLICITED_STATUS_ENABLE 0x14 |
| 133 | |
| 134 | /* Status write response codes */ |
| 135 | #define SBP2_STATUS_REQUEST_COMPLETE 0x0 |
| 136 | #define SBP2_STATUS_TRANSPORT_FAILURE 0x1 |
| 137 | #define SBP2_STATUS_ILLEGAL_REQUEST 0x2 |
| 138 | #define SBP2_STATUS_VENDOR_DEPENDENT 0x3 |
| 139 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 140 | #define STATUS_GET_ORB_HIGH(v) ((v).status & 0xffff) |
| 141 | #define STATUS_GET_SBP_STATUS(v) (((v).status >> 16) & 0xff) |
| 142 | #define STATUS_GET_LEN(v) (((v).status >> 24) & 0x07) |
| 143 | #define STATUS_GET_DEAD(v) (((v).status >> 27) & 0x01) |
| 144 | #define STATUS_GET_RESPONSE(v) (((v).status >> 28) & 0x03) |
| 145 | #define STATUS_GET_SOURCE(v) (((v).status >> 30) & 0x03) |
| 146 | #define STATUS_GET_ORB_LOW(v) ((v).orb_low) |
| 147 | #define STATUS_GET_DATA(v) ((v).data) |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 148 | |
| 149 | struct sbp2_status { |
| 150 | u32 status; |
| 151 | u32 orb_low; |
| 152 | u8 data[24]; |
| 153 | }; |
| 154 | |
| 155 | struct sbp2_pointer { |
| 156 | u32 high; |
| 157 | u32 low; |
| 158 | }; |
| 159 | |
| 160 | struct sbp2_orb { |
| 161 | struct fw_transaction t; |
Kristian Høgsberg | e57d201 | 2007-08-24 18:59:58 -0400 | [diff] [blame^] | 162 | struct kref kref; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 163 | dma_addr_t request_bus; |
| 164 | int rcode; |
| 165 | struct sbp2_pointer pointer; |
Kristian Høgsberg | a98e271 | 2007-05-07 20:33:34 -0400 | [diff] [blame] | 166 | void (*callback)(struct sbp2_orb * orb, struct sbp2_status * status); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 167 | struct list_head link; |
| 168 | }; |
| 169 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 170 | #define MANAGEMENT_ORB_LUN(v) ((v)) |
| 171 | #define MANAGEMENT_ORB_FUNCTION(v) ((v) << 16) |
| 172 | #define MANAGEMENT_ORB_RECONNECT(v) ((v) << 20) |
Stefan Richter | 5cd54c9 | 2007-06-17 23:55:41 +0200 | [diff] [blame] | 173 | #define MANAGEMENT_ORB_EXCLUSIVE(v) ((v) ? 1 << 28 : 0) |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 174 | #define MANAGEMENT_ORB_REQUEST_FORMAT(v) ((v) << 29) |
| 175 | #define MANAGEMENT_ORB_NOTIFY ((1) << 31) |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 176 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 177 | #define MANAGEMENT_ORB_RESPONSE_LENGTH(v) ((v)) |
| 178 | #define MANAGEMENT_ORB_PASSWORD_LENGTH(v) ((v) << 16) |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 179 | |
| 180 | struct sbp2_management_orb { |
| 181 | struct sbp2_orb base; |
| 182 | struct { |
| 183 | struct sbp2_pointer password; |
| 184 | struct sbp2_pointer response; |
| 185 | u32 misc; |
| 186 | u32 length; |
| 187 | struct sbp2_pointer status_fifo; |
| 188 | } request; |
| 189 | __be32 response[4]; |
| 190 | dma_addr_t response_bus; |
| 191 | struct completion done; |
| 192 | struct sbp2_status status; |
| 193 | }; |
| 194 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 195 | #define LOGIN_RESPONSE_GET_LOGIN_ID(v) ((v).misc & 0xffff) |
| 196 | #define LOGIN_RESPONSE_GET_LENGTH(v) (((v).misc >> 16) & 0xffff) |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 197 | |
| 198 | struct sbp2_login_response { |
| 199 | u32 misc; |
| 200 | struct sbp2_pointer command_block_agent; |
| 201 | u32 reconnect_hold; |
| 202 | }; |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 203 | #define COMMAND_ORB_DATA_SIZE(v) ((v)) |
| 204 | #define COMMAND_ORB_PAGE_SIZE(v) ((v) << 16) |
| 205 | #define COMMAND_ORB_PAGE_TABLE_PRESENT ((1) << 19) |
| 206 | #define COMMAND_ORB_MAX_PAYLOAD(v) ((v) << 20) |
| 207 | #define COMMAND_ORB_SPEED(v) ((v) << 24) |
| 208 | #define COMMAND_ORB_DIRECTION(v) ((v) << 27) |
| 209 | #define COMMAND_ORB_REQUEST_FORMAT(v) ((v) << 29) |
| 210 | #define COMMAND_ORB_NOTIFY ((1) << 31) |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 211 | |
| 212 | struct sbp2_command_orb { |
| 213 | struct sbp2_orb base; |
| 214 | struct { |
| 215 | struct sbp2_pointer next; |
| 216 | struct sbp2_pointer data_descriptor; |
| 217 | u32 misc; |
| 218 | u8 command_block[12]; |
| 219 | } request; |
| 220 | struct scsi_cmnd *cmd; |
| 221 | scsi_done_fn_t done; |
| 222 | struct fw_unit *unit; |
| 223 | |
Stefan Richter | 9fb2dd1 | 2007-07-01 13:55:31 +0200 | [diff] [blame] | 224 | struct sbp2_pointer page_table[SG_ALL] __attribute__((aligned(8))); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 225 | dma_addr_t page_table_bus; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 226 | }; |
| 227 | |
| 228 | /* |
| 229 | * List of devices with known bugs. |
| 230 | * |
| 231 | * The firmware_revision field, masked with 0xffff00, is the best |
| 232 | * indicator for the type of bridge chip of a device. It yields a few |
| 233 | * false positives but this did not break correctly behaving devices |
| 234 | * so far. We use ~0 as a wildcard, since the 24 bit values we get |
| 235 | * from the config rom can never match that. |
| 236 | */ |
| 237 | static const struct { |
| 238 | u32 firmware_revision; |
| 239 | u32 model; |
| 240 | unsigned workarounds; |
| 241 | } sbp2_workarounds_table[] = { |
| 242 | /* DViCO Momobay CX-1 with TSB42AA9 bridge */ { |
| 243 | .firmware_revision = 0x002800, |
| 244 | .model = 0x001010, |
| 245 | .workarounds = SBP2_WORKAROUND_INQUIRY_36 | |
| 246 | SBP2_WORKAROUND_MODE_SENSE_8, |
| 247 | }, |
| 248 | /* Initio bridges, actually only needed for some older ones */ { |
| 249 | .firmware_revision = 0x000200, |
| 250 | .model = ~0, |
| 251 | .workarounds = SBP2_WORKAROUND_INQUIRY_36, |
| 252 | }, |
| 253 | /* Symbios bridge */ { |
| 254 | .firmware_revision = 0xa0b800, |
| 255 | .model = ~0, |
| 256 | .workarounds = SBP2_WORKAROUND_128K_MAX_TRANS, |
| 257 | }, |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 258 | |
| 259 | /* |
| 260 | * There are iPods (2nd gen, 3rd gen) with model_id == 0, but |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 261 | * these iPods do not feature the read_capacity bug according |
| 262 | * to one report. Read_capacity behaviour as well as model_id |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 263 | * could change due to Apple-supplied firmware updates though. |
| 264 | */ |
| 265 | |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 266 | /* iPod 4th generation. */ { |
| 267 | .firmware_revision = 0x0a2700, |
| 268 | .model = 0x000021, |
| 269 | .workarounds = SBP2_WORKAROUND_FIX_CAPACITY, |
| 270 | }, |
| 271 | /* iPod mini */ { |
| 272 | .firmware_revision = 0x0a2700, |
| 273 | .model = 0x000023, |
| 274 | .workarounds = SBP2_WORKAROUND_FIX_CAPACITY, |
| 275 | }, |
| 276 | /* iPod Photo */ { |
| 277 | .firmware_revision = 0x0a2700, |
| 278 | .model = 0x00007e, |
| 279 | .workarounds = SBP2_WORKAROUND_FIX_CAPACITY, |
| 280 | } |
| 281 | }; |
| 282 | |
| 283 | static void |
Kristian Høgsberg | e57d201 | 2007-08-24 18:59:58 -0400 | [diff] [blame^] | 284 | free_orb(struct kref *kref) |
| 285 | { |
| 286 | struct sbp2_orb *orb = container_of(kref, struct sbp2_orb, kref); |
| 287 | |
| 288 | kfree(orb); |
| 289 | } |
| 290 | |
| 291 | static void |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 292 | sbp2_status_write(struct fw_card *card, struct fw_request *request, |
| 293 | int tcode, int destination, int source, |
| 294 | int generation, int speed, |
| 295 | unsigned long long offset, |
| 296 | void *payload, size_t length, void *callback_data) |
| 297 | { |
| 298 | struct sbp2_device *sd = callback_data; |
| 299 | struct sbp2_orb *orb; |
| 300 | struct sbp2_status status; |
| 301 | size_t header_size; |
| 302 | unsigned long flags; |
| 303 | |
| 304 | if (tcode != TCODE_WRITE_BLOCK_REQUEST || |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 305 | length == 0 || length > sizeof(status)) { |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 306 | fw_send_response(card, request, RCODE_TYPE_ERROR); |
| 307 | return; |
| 308 | } |
| 309 | |
| 310 | header_size = min(length, 2 * sizeof(u32)); |
| 311 | fw_memcpy_from_be32(&status, payload, header_size); |
| 312 | if (length > header_size) |
| 313 | memcpy(status.data, payload + 8, length - header_size); |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 314 | if (STATUS_GET_SOURCE(status) == 2 || STATUS_GET_SOURCE(status) == 3) { |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 315 | fw_notify("non-orb related status write, not handled\n"); |
| 316 | fw_send_response(card, request, RCODE_COMPLETE); |
| 317 | return; |
| 318 | } |
| 319 | |
| 320 | /* Lookup the orb corresponding to this status write. */ |
| 321 | spin_lock_irqsave(&card->lock, flags); |
| 322 | list_for_each_entry(orb, &sd->orb_list, link) { |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 323 | if (STATUS_GET_ORB_HIGH(status) == 0 && |
Kristian Høgsberg | e57d201 | 2007-08-24 18:59:58 -0400 | [diff] [blame^] | 324 | STATUS_GET_ORB_LOW(status) == orb->request_bus) { |
| 325 | orb->rcode = RCODE_COMPLETE; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 326 | list_del(&orb->link); |
| 327 | break; |
| 328 | } |
| 329 | } |
| 330 | spin_unlock_irqrestore(&card->lock, flags); |
| 331 | |
| 332 | if (&orb->link != &sd->orb_list) |
| 333 | orb->callback(orb, &status); |
| 334 | else |
| 335 | fw_error("status write for unknown orb\n"); |
| 336 | |
Kristian Høgsberg | e57d201 | 2007-08-24 18:59:58 -0400 | [diff] [blame^] | 337 | kref_put(&orb->kref, free_orb); |
| 338 | |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 339 | fw_send_response(card, request, RCODE_COMPLETE); |
| 340 | } |
| 341 | |
| 342 | static void |
| 343 | complete_transaction(struct fw_card *card, int rcode, |
| 344 | void *payload, size_t length, void *data) |
| 345 | { |
| 346 | struct sbp2_orb *orb = data; |
| 347 | unsigned long flags; |
| 348 | |
Kristian Høgsberg | e57d201 | 2007-08-24 18:59:58 -0400 | [diff] [blame^] | 349 | /* |
| 350 | * This is a little tricky. We can get the status write for |
| 351 | * the orb before we get this callback. The status write |
| 352 | * handler above will assume the orb pointer transaction was |
| 353 | * successful and set the rcode to RCODE_COMPLETE for the orb. |
| 354 | * So this callback only sets the rcode if it hasn't already |
| 355 | * been set and only does the cleanup if the transaction |
| 356 | * failed and we didn't already get a status write. |
| 357 | */ |
| 358 | spin_lock_irqsave(&card->lock, flags); |
| 359 | |
| 360 | if (orb->rcode == -1) |
| 361 | orb->rcode = rcode; |
| 362 | if (orb->rcode != RCODE_COMPLETE) { |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 363 | list_del(&orb->link); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 364 | orb->callback(orb, NULL); |
| 365 | } |
Kristian Høgsberg | e57d201 | 2007-08-24 18:59:58 -0400 | [diff] [blame^] | 366 | |
| 367 | spin_unlock_irqrestore(&card->lock, flags); |
| 368 | |
| 369 | kref_put(&orb->kref, free_orb); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | static void |
| 373 | sbp2_send_orb(struct sbp2_orb *orb, struct fw_unit *unit, |
| 374 | int node_id, int generation, u64 offset) |
| 375 | { |
| 376 | struct fw_device *device = fw_device(unit->device.parent); |
| 377 | struct sbp2_device *sd = unit->device.driver_data; |
| 378 | unsigned long flags; |
| 379 | |
| 380 | orb->pointer.high = 0; |
| 381 | orb->pointer.low = orb->request_bus; |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 382 | fw_memcpy_to_be32(&orb->pointer, &orb->pointer, sizeof(orb->pointer)); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 383 | |
| 384 | spin_lock_irqsave(&device->card->lock, flags); |
| 385 | list_add_tail(&orb->link, &sd->orb_list); |
| 386 | spin_unlock_irqrestore(&device->card->lock, flags); |
| 387 | |
Kristian Høgsberg | e57d201 | 2007-08-24 18:59:58 -0400 | [diff] [blame^] | 388 | /* Take a ref for the orb list and for the transaction callback. */ |
| 389 | kref_get(&orb->kref); |
| 390 | kref_get(&orb->kref); |
| 391 | |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 392 | fw_send_request(device->card, &orb->t, TCODE_WRITE_BLOCK_REQUEST, |
Stefan Richter | f139749 | 2007-06-10 21:31:36 +0200 | [diff] [blame] | 393 | node_id, generation, device->max_speed, offset, |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 394 | &orb->pointer, sizeof(orb->pointer), |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 395 | complete_transaction, orb); |
| 396 | } |
| 397 | |
Kristian Høgsberg | 2aaad97 | 2007-03-07 12:12:47 -0500 | [diff] [blame] | 398 | static int sbp2_cancel_orbs(struct fw_unit *unit) |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 399 | { |
| 400 | struct fw_device *device = fw_device(unit->device.parent); |
| 401 | struct sbp2_device *sd = unit->device.driver_data; |
| 402 | struct sbp2_orb *orb, *next; |
| 403 | struct list_head list; |
| 404 | unsigned long flags; |
Kristian Høgsberg | 2aaad97 | 2007-03-07 12:12:47 -0500 | [diff] [blame] | 405 | int retval = -ENOENT; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 406 | |
| 407 | INIT_LIST_HEAD(&list); |
| 408 | spin_lock_irqsave(&device->card->lock, flags); |
| 409 | list_splice_init(&sd->orb_list, &list); |
| 410 | spin_unlock_irqrestore(&device->card->lock, flags); |
| 411 | |
| 412 | list_for_each_entry_safe(orb, next, &list, link) { |
Kristian Høgsberg | 2aaad97 | 2007-03-07 12:12:47 -0500 | [diff] [blame] | 413 | retval = 0; |
Kristian Høgsberg | 730c32f | 2007-02-06 14:49:32 -0500 | [diff] [blame] | 414 | if (fw_cancel_transaction(device->card, &orb->t) == 0) |
| 415 | continue; |
| 416 | |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 417 | orb->rcode = RCODE_CANCELLED; |
| 418 | orb->callback(orb, NULL); |
| 419 | } |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 420 | |
Kristian Høgsberg | 2aaad97 | 2007-03-07 12:12:47 -0500 | [diff] [blame] | 421 | return retval; |
Kristian Høgsberg | 1d3d52c | 2007-02-06 14:49:33 -0500 | [diff] [blame] | 422 | } |
| 423 | |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 424 | static void |
| 425 | complete_management_orb(struct sbp2_orb *base_orb, struct sbp2_status *status) |
| 426 | { |
| 427 | struct sbp2_management_orb *orb = |
Jay Fenlason | 6f06148 | 2007-06-27 16:04:33 -0400 | [diff] [blame] | 428 | container_of(base_orb, struct sbp2_management_orb, base); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 429 | |
| 430 | if (status) |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 431 | memcpy(&orb->status, status, sizeof(*status)); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 432 | complete(&orb->done); |
| 433 | } |
| 434 | |
| 435 | static int |
| 436 | sbp2_send_management_orb(struct fw_unit *unit, int node_id, int generation, |
| 437 | int function, int lun, void *response) |
| 438 | { |
| 439 | struct fw_device *device = fw_device(unit->device.parent); |
| 440 | struct sbp2_device *sd = unit->device.driver_data; |
| 441 | struct sbp2_management_orb *orb; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 442 | int retval = -ENOMEM; |
| 443 | |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 444 | orb = kzalloc(sizeof(*orb), GFP_ATOMIC); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 445 | if (orb == NULL) |
| 446 | return -ENOMEM; |
| 447 | |
Kristian Høgsberg | e57d201 | 2007-08-24 18:59:58 -0400 | [diff] [blame^] | 448 | kref_init(&orb->base.kref); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 449 | orb->response_bus = |
| 450 | dma_map_single(device->card->device, &orb->response, |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 451 | sizeof(orb->response), DMA_FROM_DEVICE); |
Kristian Høgsberg | 82eff9d | 2007-02-06 14:49:40 -0500 | [diff] [blame] | 452 | if (dma_mapping_error(orb->response_bus)) |
Stefan Richter | 7aa4848 | 2007-07-02 21:04:44 +0200 | [diff] [blame] | 453 | goto fail_mapping_response; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 454 | |
| 455 | orb->request.response.high = 0; |
| 456 | orb->request.response.low = orb->response_bus; |
| 457 | |
| 458 | orb->request.misc = |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 459 | MANAGEMENT_ORB_NOTIFY | |
| 460 | MANAGEMENT_ORB_FUNCTION(function) | |
| 461 | MANAGEMENT_ORB_LUN(lun); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 462 | orb->request.length = |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 463 | MANAGEMENT_ORB_RESPONSE_LENGTH(sizeof(orb->response)); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 464 | |
| 465 | orb->request.status_fifo.high = sd->address_handler.offset >> 32; |
| 466 | orb->request.status_fifo.low = sd->address_handler.offset; |
| 467 | |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 468 | if (function == SBP2_LOGIN_REQUEST) { |
| 469 | orb->request.misc |= |
Stefan Richter | 5cd54c9 | 2007-06-17 23:55:41 +0200 | [diff] [blame] | 470 | MANAGEMENT_ORB_EXCLUSIVE(sbp2_param_exclusive_login) | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 471 | MANAGEMENT_ORB_RECONNECT(0); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 472 | } |
| 473 | |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 474 | fw_memcpy_to_be32(&orb->request, &orb->request, sizeof(orb->request)); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 475 | |
| 476 | init_completion(&orb->done); |
| 477 | orb->base.callback = complete_management_orb; |
Kristian Høgsberg | 2aaad97 | 2007-03-07 12:12:47 -0500 | [diff] [blame] | 478 | |
Stefan Richter | 7aa4848 | 2007-07-02 21:04:44 +0200 | [diff] [blame] | 479 | orb->base.request_bus = |
| 480 | dma_map_single(device->card->device, &orb->request, |
| 481 | sizeof(orb->request), DMA_TO_DEVICE); |
| 482 | if (dma_mapping_error(orb->base.request_bus)) |
| 483 | goto fail_mapping_request; |
| 484 | |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 485 | sbp2_send_orb(&orb->base, unit, |
| 486 | node_id, generation, sd->management_agent_address); |
| 487 | |
Kristian Høgsberg | 2aaad97 | 2007-03-07 12:12:47 -0500 | [diff] [blame] | 488 | wait_for_completion_timeout(&orb->done, |
| 489 | msecs_to_jiffies(SBP2_ORB_TIMEOUT)); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 490 | |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 491 | retval = -EIO; |
Kristian Høgsberg | 2aaad97 | 2007-03-07 12:12:47 -0500 | [diff] [blame] | 492 | if (sbp2_cancel_orbs(unit) == 0) { |
| 493 | fw_error("orb reply timed out, rcode=0x%02x\n", |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 494 | orb->base.rcode); |
| 495 | goto out; |
| 496 | } |
| 497 | |
Kristian Høgsberg | 2aaad97 | 2007-03-07 12:12:47 -0500 | [diff] [blame] | 498 | if (orb->base.rcode != RCODE_COMPLETE) { |
| 499 | fw_error("management write failed, rcode 0x%02x\n", |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 500 | orb->base.rcode); |
| 501 | goto out; |
| 502 | } |
| 503 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 504 | if (STATUS_GET_RESPONSE(orb->status) != 0 || |
| 505 | STATUS_GET_SBP_STATUS(orb->status) != 0) { |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 506 | fw_error("error status: %d:%d\n", |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 507 | STATUS_GET_RESPONSE(orb->status), |
| 508 | STATUS_GET_SBP_STATUS(orb->status)); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 509 | goto out; |
| 510 | } |
| 511 | |
| 512 | retval = 0; |
| 513 | out: |
| 514 | dma_unmap_single(device->card->device, orb->base.request_bus, |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 515 | sizeof(orb->request), DMA_TO_DEVICE); |
Stefan Richter | 7aa4848 | 2007-07-02 21:04:44 +0200 | [diff] [blame] | 516 | fail_mapping_request: |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 517 | dma_unmap_single(device->card->device, orb->response_bus, |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 518 | sizeof(orb->response), DMA_FROM_DEVICE); |
Stefan Richter | 7aa4848 | 2007-07-02 21:04:44 +0200 | [diff] [blame] | 519 | fail_mapping_response: |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 520 | if (response) |
| 521 | fw_memcpy_from_be32(response, |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 522 | orb->response, sizeof(orb->response)); |
Kristian Høgsberg | e57d201 | 2007-08-24 18:59:58 -0400 | [diff] [blame^] | 523 | kref_put(&orb->base.kref, free_orb); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 524 | |
| 525 | return retval; |
| 526 | } |
| 527 | |
| 528 | static void |
| 529 | complete_agent_reset_write(struct fw_card *card, int rcode, |
| 530 | void *payload, size_t length, void *data) |
| 531 | { |
| 532 | struct fw_transaction *t = data; |
| 533 | |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 534 | kfree(t); |
| 535 | } |
| 536 | |
| 537 | static int sbp2_agent_reset(struct fw_unit *unit) |
| 538 | { |
| 539 | struct fw_device *device = fw_device(unit->device.parent); |
| 540 | struct sbp2_device *sd = unit->device.driver_data; |
| 541 | struct fw_transaction *t; |
| 542 | static u32 zero; |
| 543 | |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 544 | t = kzalloc(sizeof(*t), GFP_ATOMIC); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 545 | if (t == NULL) |
| 546 | return -ENOMEM; |
| 547 | |
| 548 | fw_send_request(device->card, t, TCODE_WRITE_QUADLET_REQUEST, |
Stefan Richter | ffd0db2 | 2007-07-01 13:54:24 +0200 | [diff] [blame] | 549 | sd->node_id, sd->generation, device->max_speed, |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 550 | sd->command_block_agent_address + SBP2_AGENT_RESET, |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 551 | &zero, sizeof(zero), complete_agent_reset_write, t); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 552 | |
| 553 | return 0; |
| 554 | } |
| 555 | |
Kristian Høgsberg | 7f37c42 | 2007-02-06 14:49:34 -0500 | [diff] [blame] | 556 | static void sbp2_reconnect(struct work_struct *work); |
Kristian Høgsberg | ad85274f | 2007-05-09 19:23:07 -0400 | [diff] [blame] | 557 | static struct scsi_host_template scsi_driver_template; |
Kristian Høgsberg | 7f37c42 | 2007-02-06 14:49:34 -0500 | [diff] [blame] | 558 | |
Stefan Richter | 79352e9 | 2007-06-18 18:46:49 +0200 | [diff] [blame] | 559 | static void release_sbp2_device(struct kref *kref) |
Kristian Høgsberg | b3d6e15 | 2007-03-14 17:34:58 -0400 | [diff] [blame] | 560 | { |
| 561 | struct sbp2_device *sd = container_of(kref, struct sbp2_device, kref); |
Kristian Høgsberg | ad85274f | 2007-05-09 19:23:07 -0400 | [diff] [blame] | 562 | struct Scsi_Host *host = |
| 563 | container_of((void *)sd, struct Scsi_Host, hostdata[0]); |
Kristian Høgsberg | b3d6e15 | 2007-03-14 17:34:58 -0400 | [diff] [blame] | 564 | |
Stefan Richter | 79352e9 | 2007-06-18 18:46:49 +0200 | [diff] [blame] | 565 | scsi_remove_host(host); |
Kristian Høgsberg | b3d6e15 | 2007-03-14 17:34:58 -0400 | [diff] [blame] | 566 | sbp2_send_management_orb(sd->unit, sd->node_id, sd->generation, |
| 567 | SBP2_LOGOUT_REQUEST, sd->login_id, NULL); |
Kristian Høgsberg | b3d6e15 | 2007-03-14 17:34:58 -0400 | [diff] [blame] | 568 | fw_core_remove_address_handler(&sd->address_handler); |
| 569 | fw_notify("removed sbp2 unit %s\n", sd->unit->device.bus_id); |
| 570 | put_device(&sd->unit->device); |
Kristian Høgsberg | ad85274f | 2007-05-09 19:23:07 -0400 | [diff] [blame] | 571 | scsi_host_put(host); |
Kristian Høgsberg | b3d6e15 | 2007-03-14 17:34:58 -0400 | [diff] [blame] | 572 | } |
| 573 | |
Kristian Høgsberg | 7f37c42 | 2007-02-06 14:49:34 -0500 | [diff] [blame] | 574 | static void sbp2_login(struct work_struct *work) |
| 575 | { |
| 576 | struct sbp2_device *sd = |
| 577 | container_of(work, struct sbp2_device, work.work); |
Kristian Høgsberg | ad85274f | 2007-05-09 19:23:07 -0400 | [diff] [blame] | 578 | struct Scsi_Host *host = |
| 579 | container_of((void *)sd, struct Scsi_Host, hostdata[0]); |
Kristian Høgsberg | 7f37c42 | 2007-02-06 14:49:34 -0500 | [diff] [blame] | 580 | struct fw_unit *unit = sd->unit; |
| 581 | struct fw_device *device = fw_device(unit->device.parent); |
| 582 | struct sbp2_login_response response; |
| 583 | int generation, node_id, local_node_id, lun, retval; |
| 584 | |
| 585 | /* FIXME: Make this work for multi-lun devices. */ |
| 586 | lun = 0; |
| 587 | |
| 588 | generation = device->card->generation; |
| 589 | node_id = device->node->node_id; |
| 590 | local_node_id = device->card->local_node->node_id; |
| 591 | |
| 592 | if (sbp2_send_management_orb(unit, node_id, generation, |
| 593 | SBP2_LOGIN_REQUEST, lun, &response) < 0) { |
| 594 | if (sd->retries++ < 5) { |
Kristian Høgsberg | 7f37c42 | 2007-02-06 14:49:34 -0500 | [diff] [blame] | 595 | schedule_delayed_work(&sd->work, DIV_ROUND_UP(HZ, 5)); |
| 596 | } else { |
| 597 | fw_error("failed to login to %s\n", |
| 598 | unit->device.bus_id); |
Kristian Høgsberg | b3d6e15 | 2007-03-14 17:34:58 -0400 | [diff] [blame] | 599 | kref_put(&sd->kref, release_sbp2_device); |
Kristian Høgsberg | 7f37c42 | 2007-02-06 14:49:34 -0500 | [diff] [blame] | 600 | } |
| 601 | return; |
| 602 | } |
| 603 | |
| 604 | sd->generation = generation; |
| 605 | sd->node_id = node_id; |
| 606 | sd->address_high = local_node_id << 16; |
| 607 | |
| 608 | /* Get command block agent offset and login id. */ |
| 609 | sd->command_block_agent_address = |
Kristian Høgsberg | 5c5539d | 2007-03-07 12:12:45 -0500 | [diff] [blame] | 610 | ((u64) (response.command_block_agent.high & 0xffff) << 32) | |
Kristian Høgsberg | 7f37c42 | 2007-02-06 14:49:34 -0500 | [diff] [blame] | 611 | response.command_block_agent.low; |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 612 | sd->login_id = LOGIN_RESPONSE_GET_LOGIN_ID(response); |
Kristian Høgsberg | 7f37c42 | 2007-02-06 14:49:34 -0500 | [diff] [blame] | 613 | |
Kristian Høgsberg | 5c5539d | 2007-03-07 12:12:45 -0500 | [diff] [blame] | 614 | fw_notify("logged in to sbp2 unit %s (%d retries)\n", |
| 615 | unit->device.bus_id, sd->retries); |
| 616 | fw_notify(" - management_agent_address: 0x%012llx\n", |
Kristian Høgsberg | 7f37c42 | 2007-02-06 14:49:34 -0500 | [diff] [blame] | 617 | (unsigned long long) sd->management_agent_address); |
| 618 | fw_notify(" - command_block_agent_address: 0x%012llx\n", |
| 619 | (unsigned long long) sd->command_block_agent_address); |
Kristian Høgsberg | 5c5539d | 2007-03-07 12:12:45 -0500 | [diff] [blame] | 620 | fw_notify(" - status write address: 0x%012llx\n", |
Kristian Høgsberg | 7f37c42 | 2007-02-06 14:49:34 -0500 | [diff] [blame] | 621 | (unsigned long long) sd->address_handler.offset); |
| 622 | |
| 623 | #if 0 |
| 624 | /* FIXME: The linux1394 sbp2 does this last step. */ |
| 625 | sbp2_set_busy_timeout(scsi_id); |
| 626 | #endif |
| 627 | |
Kristian Høgsberg | 1da0c93 | 2007-03-07 12:12:40 -0500 | [diff] [blame] | 628 | PREPARE_DELAYED_WORK(&sd->work, sbp2_reconnect); |
Kristian Høgsberg | 7f37c42 | 2007-02-06 14:49:34 -0500 | [diff] [blame] | 629 | sbp2_agent_reset(unit); |
| 630 | |
Kristian Høgsberg | ad85274f | 2007-05-09 19:23:07 -0400 | [diff] [blame] | 631 | /* FIXME: Loop over luns here. */ |
| 632 | lun = 0; |
| 633 | retval = scsi_add_device(host, 0, 0, lun); |
Kristian Høgsberg | 7f37c42 | 2007-02-06 14:49:34 -0500 | [diff] [blame] | 634 | if (retval < 0) { |
| 635 | sbp2_send_management_orb(unit, sd->node_id, sd->generation, |
| 636 | SBP2_LOGOUT_REQUEST, sd->login_id, |
| 637 | NULL); |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 638 | /* |
| 639 | * Set this back to sbp2_login so we fall back and |
| 640 | * retry login on bus reset. |
| 641 | */ |
Kristian Høgsberg | 1da0c93 | 2007-03-07 12:12:40 -0500 | [diff] [blame] | 642 | PREPARE_DELAYED_WORK(&sd->work, sbp2_login); |
Kristian Høgsberg | 7f37c42 | 2007-02-06 14:49:34 -0500 | [diff] [blame] | 643 | } |
Kristian Høgsberg | b3d6e15 | 2007-03-14 17:34:58 -0400 | [diff] [blame] | 644 | kref_put(&sd->kref, release_sbp2_device); |
Kristian Høgsberg | 7f37c42 | 2007-02-06 14:49:34 -0500 | [diff] [blame] | 645 | } |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 646 | |
| 647 | static int sbp2_probe(struct device *dev) |
| 648 | { |
| 649 | struct fw_unit *unit = fw_unit(dev); |
| 650 | struct fw_device *device = fw_device(unit->device.parent); |
| 651 | struct sbp2_device *sd; |
| 652 | struct fw_csr_iterator ci; |
Kristian Høgsberg | ad85274f | 2007-05-09 19:23:07 -0400 | [diff] [blame] | 653 | struct Scsi_Host *host; |
| 654 | int i, key, value, err; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 655 | u32 model, firmware_revision; |
| 656 | |
Kristian Høgsberg | ad85274f | 2007-05-09 19:23:07 -0400 | [diff] [blame] | 657 | err = -ENOMEM; |
| 658 | host = scsi_host_alloc(&scsi_driver_template, sizeof(*sd)); |
| 659 | if (host == NULL) |
| 660 | goto fail; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 661 | |
Kristian Høgsberg | ad85274f | 2007-05-09 19:23:07 -0400 | [diff] [blame] | 662 | sd = (struct sbp2_device *) host->hostdata; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 663 | unit->device.driver_data = sd; |
| 664 | sd->unit = unit; |
| 665 | INIT_LIST_HEAD(&sd->orb_list); |
Kristian Høgsberg | b3d6e15 | 2007-03-14 17:34:58 -0400 | [diff] [blame] | 666 | kref_init(&sd->kref); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 667 | |
| 668 | sd->address_handler.length = 0x100; |
| 669 | sd->address_handler.address_callback = sbp2_status_write; |
| 670 | sd->address_handler.callback_data = sd; |
| 671 | |
Kristian Høgsberg | ad85274f | 2007-05-09 19:23:07 -0400 | [diff] [blame] | 672 | err = fw_core_add_address_handler(&sd->address_handler, |
| 673 | &fw_high_memory_region); |
| 674 | if (err < 0) |
| 675 | goto fail_host; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 676 | |
Kristian Høgsberg | ad85274f | 2007-05-09 19:23:07 -0400 | [diff] [blame] | 677 | err = fw_device_enable_phys_dma(device); |
| 678 | if (err < 0) |
| 679 | goto fail_address_handler; |
| 680 | |
| 681 | err = scsi_add_host(host, &unit->device); |
| 682 | if (err < 0) |
| 683 | goto fail_address_handler; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 684 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 685 | /* |
| 686 | * Scan unit directory to get management agent address, |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 687 | * firmware revison and model. Initialize firmware_revision |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 688 | * and model to values that wont match anything in our table. |
| 689 | */ |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 690 | firmware_revision = 0xff000000; |
| 691 | model = 0xff000000; |
| 692 | fw_csr_iterator_init(&ci, unit->directory); |
| 693 | while (fw_csr_iterator_next(&ci, &key, &value)) { |
| 694 | switch (key) { |
| 695 | case CSR_DEPENDENT_INFO | CSR_OFFSET: |
| 696 | sd->management_agent_address = |
| 697 | 0xfffff0000000ULL + 4 * value; |
| 698 | break; |
| 699 | case SBP2_FIRMWARE_REVISION: |
| 700 | firmware_revision = value; |
| 701 | break; |
| 702 | case CSR_MODEL: |
| 703 | model = value; |
| 704 | break; |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | for (i = 0; i < ARRAY_SIZE(sbp2_workarounds_table); i++) { |
| 709 | if (sbp2_workarounds_table[i].firmware_revision != |
| 710 | (firmware_revision & 0xffffff00)) |
| 711 | continue; |
| 712 | if (sbp2_workarounds_table[i].model != model && |
| 713 | sbp2_workarounds_table[i].model != ~0) |
| 714 | continue; |
| 715 | sd->workarounds |= sbp2_workarounds_table[i].workarounds; |
| 716 | break; |
| 717 | } |
| 718 | |
| 719 | if (sd->workarounds) |
| 720 | fw_notify("Workarounds for node %s: 0x%x " |
| 721 | "(firmware_revision 0x%06x, model_id 0x%06x)\n", |
| 722 | unit->device.bus_id, |
| 723 | sd->workarounds, firmware_revision, model); |
| 724 | |
Kristian Høgsberg | b3d6e15 | 2007-03-14 17:34:58 -0400 | [diff] [blame] | 725 | get_device(&unit->device); |
| 726 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 727 | /* |
| 728 | * We schedule work to do the login so we can easily |
Kristian Høgsberg | b3d6e15 | 2007-03-14 17:34:58 -0400 | [diff] [blame] | 729 | * reschedule retries. Always get the ref before scheduling |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 730 | * work. |
| 731 | */ |
Kristian Høgsberg | 7f37c42 | 2007-02-06 14:49:34 -0500 | [diff] [blame] | 732 | INIT_DELAYED_WORK(&sd->work, sbp2_login); |
Kristian Høgsberg | b3d6e15 | 2007-03-14 17:34:58 -0400 | [diff] [blame] | 733 | if (schedule_delayed_work(&sd->work, 0)) |
| 734 | kref_get(&sd->kref); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 735 | |
| 736 | return 0; |
Kristian Høgsberg | ad85274f | 2007-05-09 19:23:07 -0400 | [diff] [blame] | 737 | |
| 738 | fail_address_handler: |
| 739 | fw_core_remove_address_handler(&sd->address_handler); |
| 740 | fail_host: |
| 741 | scsi_host_put(host); |
| 742 | fail: |
| 743 | return err; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | static int sbp2_remove(struct device *dev) |
| 747 | { |
| 748 | struct fw_unit *unit = fw_unit(dev); |
| 749 | struct sbp2_device *sd = unit->device.driver_data; |
| 750 | |
Kristian Høgsberg | b3d6e15 | 2007-03-14 17:34:58 -0400 | [diff] [blame] | 751 | kref_put(&sd->kref, release_sbp2_device); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 752 | |
| 753 | return 0; |
| 754 | } |
| 755 | |
| 756 | static void sbp2_reconnect(struct work_struct *work) |
| 757 | { |
Kristian Høgsberg | 7f37c42 | 2007-02-06 14:49:34 -0500 | [diff] [blame] | 758 | struct sbp2_device *sd = |
| 759 | container_of(work, struct sbp2_device, work.work); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 760 | struct fw_unit *unit = sd->unit; |
| 761 | struct fw_device *device = fw_device(unit->device.parent); |
| 762 | int generation, node_id, local_node_id; |
| 763 | |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 764 | generation = device->card->generation; |
| 765 | node_id = device->node->node_id; |
| 766 | local_node_id = device->card->local_node->node_id; |
| 767 | |
Kristian Høgsberg | 7f37c42 | 2007-02-06 14:49:34 -0500 | [diff] [blame] | 768 | if (sbp2_send_management_orb(unit, node_id, generation, |
| 769 | SBP2_RECONNECT_REQUEST, |
| 770 | sd->login_id, NULL) < 0) { |
Kristian Høgsberg | 5c5539d | 2007-03-07 12:12:45 -0500 | [diff] [blame] | 771 | if (sd->retries++ >= 5) { |
Kristian Høgsberg | 7f37c42 | 2007-02-06 14:49:34 -0500 | [diff] [blame] | 772 | fw_error("failed to reconnect to %s\n", |
| 773 | unit->device.bus_id); |
| 774 | /* Fall back and try to log in again. */ |
| 775 | sd->retries = 0; |
Kristian Høgsberg | 1da0c93 | 2007-03-07 12:12:40 -0500 | [diff] [blame] | 776 | PREPARE_DELAYED_WORK(&sd->work, sbp2_login); |
Kristian Høgsberg | 7f37c42 | 2007-02-06 14:49:34 -0500 | [diff] [blame] | 777 | } |
| 778 | schedule_delayed_work(&sd->work, DIV_ROUND_UP(HZ, 5)); |
| 779 | return; |
| 780 | } |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 781 | |
| 782 | sd->generation = generation; |
| 783 | sd->node_id = node_id; |
Stefan Richter | 907293d | 2007-01-23 21:11:43 +0100 | [diff] [blame] | 784 | sd->address_high = local_node_id << 16; |
Kristian Høgsberg | 7f37c42 | 2007-02-06 14:49:34 -0500 | [diff] [blame] | 785 | |
Kristian Høgsberg | 5c5539d | 2007-03-07 12:12:45 -0500 | [diff] [blame] | 786 | fw_notify("reconnected to unit %s (%d retries)\n", |
| 787 | unit->device.bus_id, sd->retries); |
Kristian Høgsberg | 7f37c42 | 2007-02-06 14:49:34 -0500 | [diff] [blame] | 788 | sbp2_agent_reset(unit); |
| 789 | sbp2_cancel_orbs(unit); |
Kristian Høgsberg | b3d6e15 | 2007-03-14 17:34:58 -0400 | [diff] [blame] | 790 | kref_put(&sd->kref, release_sbp2_device); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | static void sbp2_update(struct fw_unit *unit) |
| 794 | { |
| 795 | struct fw_device *device = fw_device(unit->device.parent); |
| 796 | struct sbp2_device *sd = unit->device.driver_data; |
| 797 | |
Kristian Høgsberg | 7f37c42 | 2007-02-06 14:49:34 -0500 | [diff] [blame] | 798 | sd->retries = 0; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 799 | fw_device_enable_phys_dma(device); |
Kristian Høgsberg | b3d6e15 | 2007-03-14 17:34:58 -0400 | [diff] [blame] | 800 | if (schedule_delayed_work(&sd->work, 0)) |
| 801 | kref_get(&sd->kref); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | #define SBP2_UNIT_SPEC_ID_ENTRY 0x0000609e |
| 805 | #define SBP2_SW_VERSION_ENTRY 0x00010483 |
| 806 | |
Stefan Richter | 21ebcd1 | 2007-01-14 15:29:07 +0100 | [diff] [blame] | 807 | static const struct fw_device_id sbp2_id_table[] = { |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 808 | { |
| 809 | .match_flags = FW_MATCH_SPECIFIER_ID | FW_MATCH_VERSION, |
| 810 | .specifier_id = SBP2_UNIT_SPEC_ID_ENTRY, |
Stefan Richter | 5af4e5e | 2007-01-21 20:45:32 +0100 | [diff] [blame] | 811 | .version = SBP2_SW_VERSION_ENTRY, |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 812 | }, |
| 813 | { } |
| 814 | }; |
| 815 | |
| 816 | static struct fw_driver sbp2_driver = { |
| 817 | .driver = { |
| 818 | .owner = THIS_MODULE, |
| 819 | .name = sbp2_driver_name, |
| 820 | .bus = &fw_bus_type, |
| 821 | .probe = sbp2_probe, |
| 822 | .remove = sbp2_remove, |
| 823 | }, |
| 824 | .update = sbp2_update, |
| 825 | .id_table = sbp2_id_table, |
| 826 | }; |
| 827 | |
Kristian Høgsberg | fbb5423 | 2007-04-10 18:11:18 -0400 | [diff] [blame] | 828 | static unsigned int |
| 829 | sbp2_status_to_sense_data(u8 *sbp2_status, u8 *sense_data) |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 830 | { |
Kristian Høgsberg | fbb5423 | 2007-04-10 18:11:18 -0400 | [diff] [blame] | 831 | int sam_status; |
| 832 | |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 833 | sense_data[0] = 0x70; |
| 834 | sense_data[1] = 0x0; |
| 835 | sense_data[2] = sbp2_status[1]; |
| 836 | sense_data[3] = sbp2_status[4]; |
| 837 | sense_data[4] = sbp2_status[5]; |
| 838 | sense_data[5] = sbp2_status[6]; |
| 839 | sense_data[6] = sbp2_status[7]; |
| 840 | sense_data[7] = 10; |
| 841 | sense_data[8] = sbp2_status[8]; |
| 842 | sense_data[9] = sbp2_status[9]; |
| 843 | sense_data[10] = sbp2_status[10]; |
| 844 | sense_data[11] = sbp2_status[11]; |
| 845 | sense_data[12] = sbp2_status[2]; |
| 846 | sense_data[13] = sbp2_status[3]; |
| 847 | sense_data[14] = sbp2_status[12]; |
| 848 | sense_data[15] = sbp2_status[13]; |
| 849 | |
Kristian Høgsberg | fbb5423 | 2007-04-10 18:11:18 -0400 | [diff] [blame] | 850 | sam_status = sbp2_status[0] & 0x3f; |
| 851 | |
| 852 | switch (sam_status) { |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 853 | case SAM_STAT_GOOD: |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 854 | case SAM_STAT_CHECK_CONDITION: |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 855 | case SAM_STAT_CONDITION_MET: |
Kristian Høgsberg | fbb5423 | 2007-04-10 18:11:18 -0400 | [diff] [blame] | 856 | case SAM_STAT_BUSY: |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 857 | case SAM_STAT_RESERVATION_CONFLICT: |
| 858 | case SAM_STAT_COMMAND_TERMINATED: |
Kristian Høgsberg | fbb5423 | 2007-04-10 18:11:18 -0400 | [diff] [blame] | 859 | return DID_OK << 16 | sam_status; |
| 860 | |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 861 | default: |
Kristian Høgsberg | fbb5423 | 2007-04-10 18:11:18 -0400 | [diff] [blame] | 862 | return DID_ERROR << 16; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 863 | } |
| 864 | } |
| 865 | |
| 866 | static void |
| 867 | complete_command_orb(struct sbp2_orb *base_orb, struct sbp2_status *status) |
| 868 | { |
Jay Fenlason | 6f06148 | 2007-06-27 16:04:33 -0400 | [diff] [blame] | 869 | struct sbp2_command_orb *orb = |
| 870 | container_of(base_orb, struct sbp2_command_orb, base); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 871 | struct fw_unit *unit = orb->unit; |
| 872 | struct fw_device *device = fw_device(unit->device.parent); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 873 | int result; |
| 874 | |
| 875 | if (status != NULL) { |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 876 | if (STATUS_GET_DEAD(*status)) |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 877 | sbp2_agent_reset(unit); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 878 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 879 | switch (STATUS_GET_RESPONSE(*status)) { |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 880 | case SBP2_STATUS_REQUEST_COMPLETE: |
Kristian Høgsberg | fbb5423 | 2007-04-10 18:11:18 -0400 | [diff] [blame] | 881 | result = DID_OK << 16; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 882 | break; |
| 883 | case SBP2_STATUS_TRANSPORT_FAILURE: |
Kristian Høgsberg | fbb5423 | 2007-04-10 18:11:18 -0400 | [diff] [blame] | 884 | result = DID_BUS_BUSY << 16; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 885 | break; |
| 886 | case SBP2_STATUS_ILLEGAL_REQUEST: |
| 887 | case SBP2_STATUS_VENDOR_DEPENDENT: |
| 888 | default: |
Kristian Høgsberg | fbb5423 | 2007-04-10 18:11:18 -0400 | [diff] [blame] | 889 | result = DID_ERROR << 16; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 890 | break; |
| 891 | } |
| 892 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 893 | if (result == DID_OK << 16 && STATUS_GET_LEN(*status) > 1) |
| 894 | result = sbp2_status_to_sense_data(STATUS_GET_DATA(*status), |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 895 | orb->cmd->sense_buffer); |
| 896 | } else { |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 897 | /* |
| 898 | * If the orb completes with status == NULL, something |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 899 | * went wrong, typically a bus reset happened mid-orb |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 900 | * or when sending the write (less likely). |
| 901 | */ |
Kristian Høgsberg | fbb5423 | 2007-04-10 18:11:18 -0400 | [diff] [blame] | 902 | result = DID_BUS_BUSY << 16; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | dma_unmap_single(device->card->device, orb->base.request_bus, |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 906 | sizeof(orb->request), DMA_TO_DEVICE); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 907 | |
Stefan Richter | 412edf6 | 2007-07-16 21:05:41 +0200 | [diff] [blame] | 908 | if (scsi_sg_count(orb->cmd) > 0) |
| 909 | dma_unmap_sg(device->card->device, scsi_sglist(orb->cmd), |
| 910 | scsi_sg_count(orb->cmd), |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 911 | orb->cmd->sc_data_direction); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 912 | |
| 913 | if (orb->page_table_bus != 0) |
| 914 | dma_unmap_single(device->card->device, orb->page_table_bus, |
Stefan Richter | b4be016 | 2007-07-02 22:07:34 +0200 | [diff] [blame] | 915 | sizeof(orb->page_table), DMA_TO_DEVICE); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 916 | |
Kristian Høgsberg | fbb5423 | 2007-04-10 18:11:18 -0400 | [diff] [blame] | 917 | orb->cmd->result = result; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 918 | orb->done(orb->cmd); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 919 | } |
| 920 | |
Kristian Høgsberg | 95ffc5e | 2007-05-09 19:23:08 -0400 | [diff] [blame] | 921 | static int sbp2_command_orb_map_scatterlist(struct sbp2_command_orb *orb) |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 922 | { |
Kristian Høgsberg | ad85274f | 2007-05-09 19:23:07 -0400 | [diff] [blame] | 923 | struct sbp2_device *sd = |
| 924 | (struct sbp2_device *)orb->cmd->device->host->hostdata; |
| 925 | struct fw_unit *unit = sd->unit; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 926 | struct fw_device *device = fw_device(unit->device.parent); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 927 | struct scatterlist *sg; |
| 928 | int sg_len, l, i, j, count; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 929 | dma_addr_t sg_addr; |
| 930 | |
Stefan Richter | 412edf6 | 2007-07-16 21:05:41 +0200 | [diff] [blame] | 931 | sg = scsi_sglist(orb->cmd); |
| 932 | count = dma_map_sg(device->card->device, sg, scsi_sg_count(orb->cmd), |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 933 | orb->cmd->sc_data_direction); |
Kristian Høgsberg | 95ffc5e | 2007-05-09 19:23:08 -0400 | [diff] [blame] | 934 | if (count == 0) |
| 935 | goto fail; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 936 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 937 | /* |
| 938 | * Handle the special case where there is only one element in |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 939 | * the scatter list by converting it to an immediate block |
| 940 | * request. This is also a workaround for broken devices such |
| 941 | * as the second generation iPod which doesn't support page |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 942 | * tables. |
| 943 | */ |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 944 | if (count == 1 && sg_dma_len(sg) < SBP2_MAX_SG_ELEMENT_LENGTH) { |
| 945 | orb->request.data_descriptor.high = sd->address_high; |
| 946 | orb->request.data_descriptor.low = sg_dma_address(sg); |
| 947 | orb->request.misc |= |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 948 | COMMAND_ORB_DATA_SIZE(sg_dma_len(sg)); |
Kristian Høgsberg | 95ffc5e | 2007-05-09 19:23:08 -0400 | [diff] [blame] | 949 | return 0; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 950 | } |
| 951 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 952 | /* |
| 953 | * Convert the scatterlist to an sbp2 page table. If any |
Kristian Høgsberg, Stefan Richter | 36abb3b | 2007-05-09 19:23:10 -0400 | [diff] [blame] | 954 | * scatterlist entries are too big for sbp2, we split them as we |
| 955 | * go. Even if we ask the block I/O layer to not give us sg |
| 956 | * elements larger than 65535 bytes, some IOMMUs may merge sg elements |
| 957 | * during DMA mapping, and Linux currently doesn't prevent this. |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 958 | */ |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 959 | for (i = 0, j = 0; i < count; i++) { |
| 960 | sg_len = sg_dma_len(sg + i); |
| 961 | sg_addr = sg_dma_address(sg + i); |
| 962 | while (sg_len) { |
Stefan Richter | 332ef33 | 2007-07-01 13:56:03 +0200 | [diff] [blame] | 963 | /* FIXME: This won't get us out of the pinch. */ |
| 964 | if (unlikely(j >= ARRAY_SIZE(orb->page_table))) { |
| 965 | fw_error("page table overflow\n"); |
| 966 | goto fail_page_table; |
| 967 | } |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 968 | l = min(sg_len, SBP2_MAX_SG_ELEMENT_LENGTH); |
| 969 | orb->page_table[j].low = sg_addr; |
| 970 | orb->page_table[j].high = (l << 16); |
| 971 | sg_addr += l; |
| 972 | sg_len -= l; |
| 973 | j++; |
| 974 | } |
| 975 | } |
| 976 | |
Stefan Richter | b4be016 | 2007-07-02 22:07:34 +0200 | [diff] [blame] | 977 | fw_memcpy_to_be32(orb->page_table, orb->page_table, |
| 978 | sizeof(orb->page_table[0]) * j); |
| 979 | orb->page_table_bus = |
| 980 | dma_map_single(device->card->device, orb->page_table, |
| 981 | sizeof(orb->page_table), DMA_TO_DEVICE); |
| 982 | if (dma_mapping_error(orb->page_table_bus)) |
| 983 | goto fail_page_table; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 984 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 985 | /* |
| 986 | * The data_descriptor pointer is the one case where we need |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 987 | * to fill in the node ID part of the address. All other |
| 988 | * pointers assume that the data referenced reside on the |
| 989 | * initiator (i.e. us), but data_descriptor can refer to data |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 990 | * on other nodes so we need to put our ID in descriptor.high. |
| 991 | */ |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 992 | orb->request.data_descriptor.high = sd->address_high; |
| 993 | orb->request.data_descriptor.low = orb->page_table_bus; |
| 994 | orb->request.misc |= |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 995 | COMMAND_ORB_PAGE_TABLE_PRESENT | |
| 996 | COMMAND_ORB_DATA_SIZE(j); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 997 | |
Kristian Høgsberg | 95ffc5e | 2007-05-09 19:23:08 -0400 | [diff] [blame] | 998 | return 0; |
| 999 | |
| 1000 | fail_page_table: |
Stefan Richter | 412edf6 | 2007-07-16 21:05:41 +0200 | [diff] [blame] | 1001 | dma_unmap_sg(device->card->device, sg, scsi_sg_count(orb->cmd), |
Kristian Høgsberg | 95ffc5e | 2007-05-09 19:23:08 -0400 | [diff] [blame] | 1002 | orb->cmd->sc_data_direction); |
| 1003 | fail: |
| 1004 | return -ENOMEM; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1005 | } |
| 1006 | |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1007 | /* SCSI stack integration */ |
| 1008 | |
| 1009 | static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done) |
| 1010 | { |
Kristian Høgsberg | ad85274f | 2007-05-09 19:23:07 -0400 | [diff] [blame] | 1011 | struct sbp2_device *sd = |
| 1012 | (struct sbp2_device *)cmd->device->host->hostdata; |
| 1013 | struct fw_unit *unit = sd->unit; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1014 | struct fw_device *device = fw_device(unit->device.parent); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1015 | struct sbp2_command_orb *orb; |
Stefan Richter | 25659f7 | 2007-07-21 22:43:05 +0200 | [diff] [blame] | 1016 | unsigned max_payload; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1017 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 1018 | /* |
| 1019 | * Bidirectional commands are not yet implemented, and unknown |
| 1020 | * transfer direction not handled. |
| 1021 | */ |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1022 | if (cmd->sc_data_direction == DMA_BIDIRECTIONAL) { |
Stefan Richter | 8a8cea2 | 2007-06-09 19:26:22 +0200 | [diff] [blame] | 1023 | fw_error("Can't handle DMA_BIDIRECTIONAL, rejecting command\n"); |
Kristian Høgsberg | e1b68c4 | 2007-05-09 19:23:09 -0400 | [diff] [blame] | 1024 | cmd->result = DID_ERROR << 16; |
| 1025 | done(cmd); |
| 1026 | return 0; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1027 | } |
| 1028 | |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 1029 | orb = kzalloc(sizeof(*orb), GFP_ATOMIC); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1030 | if (orb == NULL) { |
| 1031 | fw_notify("failed to alloc orb\n"); |
Kristian Høgsberg | 82eff9d | 2007-02-06 14:49:40 -0500 | [diff] [blame] | 1032 | goto fail_alloc; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1033 | } |
| 1034 | |
Kristian Høgsberg | 12f26aa | 2007-04-10 18:11:20 -0400 | [diff] [blame] | 1035 | /* Initialize rcode to something not RCODE_COMPLETE. */ |
| 1036 | orb->base.rcode = -1; |
Kristian Høgsberg | e57d201 | 2007-08-24 18:59:58 -0400 | [diff] [blame^] | 1037 | kref_init(&orb->base.kref); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1038 | |
| 1039 | orb->unit = unit; |
| 1040 | orb->done = done; |
| 1041 | orb->cmd = cmd; |
| 1042 | |
| 1043 | orb->request.next.high = SBP2_ORB_NULL; |
| 1044 | orb->request.next.low = 0x0; |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 1045 | /* |
| 1046 | * At speed 100 we can do 512 bytes per packet, at speed 200, |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1047 | * 1024 bytes per packet etc. The SBP-2 max_payload field |
| 1048 | * specifies the max payload size as 2 ^ (max_payload + 2), so |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 1049 | * if we set this to max_speed + 7, we get the right value. |
| 1050 | */ |
Stefan Richter | 25659f7 | 2007-07-21 22:43:05 +0200 | [diff] [blame] | 1051 | max_payload = min(device->max_speed + 7, |
| 1052 | device->card->max_receive - 1); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1053 | orb->request.misc = |
Stefan Richter | 25659f7 | 2007-07-21 22:43:05 +0200 | [diff] [blame] | 1054 | COMMAND_ORB_MAX_PAYLOAD(max_payload) | |
Stefan Richter | f139749 | 2007-06-10 21:31:36 +0200 | [diff] [blame] | 1055 | COMMAND_ORB_SPEED(device->max_speed) | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 1056 | COMMAND_ORB_NOTIFY; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1057 | |
| 1058 | if (cmd->sc_data_direction == DMA_FROM_DEVICE) |
| 1059 | orb->request.misc |= |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 1060 | COMMAND_ORB_DIRECTION(SBP2_DIRECTION_FROM_MEDIA); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1061 | else if (cmd->sc_data_direction == DMA_TO_DEVICE) |
| 1062 | orb->request.misc |= |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 1063 | COMMAND_ORB_DIRECTION(SBP2_DIRECTION_TO_MEDIA); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1064 | |
Stefan Richter | 412edf6 | 2007-07-16 21:05:41 +0200 | [diff] [blame] | 1065 | if (scsi_sg_count(cmd) && sbp2_command_orb_map_scatterlist(orb) < 0) |
Stefan Richter | 8526392 | 2007-07-02 21:04:08 +0200 | [diff] [blame] | 1066 | goto fail_mapping; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1067 | |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 1068 | fw_memcpy_to_be32(&orb->request, &orb->request, sizeof(orb->request)); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1069 | |
| 1070 | memset(orb->request.command_block, |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 1071 | 0, sizeof(orb->request.command_block)); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1072 | memcpy(orb->request.command_block, cmd->cmnd, COMMAND_SIZE(*cmd->cmnd)); |
| 1073 | |
| 1074 | orb->base.callback = complete_command_orb; |
Stefan Richter | 8526392 | 2007-07-02 21:04:08 +0200 | [diff] [blame] | 1075 | orb->base.request_bus = |
| 1076 | dma_map_single(device->card->device, &orb->request, |
| 1077 | sizeof(orb->request), DMA_TO_DEVICE); |
| 1078 | if (dma_mapping_error(orb->base.request_bus)) |
| 1079 | goto fail_mapping; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1080 | |
| 1081 | sbp2_send_orb(&orb->base, unit, sd->node_id, sd->generation, |
| 1082 | sd->command_block_agent_address + SBP2_ORB_POINTER); |
| 1083 | |
Kristian Høgsberg | e57d201 | 2007-08-24 18:59:58 -0400 | [diff] [blame^] | 1084 | kref_put(&orb->base.kref, free_orb); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1085 | return 0; |
Kristian Høgsberg | 82eff9d | 2007-02-06 14:49:40 -0500 | [diff] [blame] | 1086 | |
Kristian Høgsberg | 82eff9d | 2007-02-06 14:49:40 -0500 | [diff] [blame] | 1087 | fail_mapping: |
Kristian Høgsberg | e57d201 | 2007-08-24 18:59:58 -0400 | [diff] [blame^] | 1088 | kref_put(&orb->base.kref, free_orb); |
Kristian Høgsberg | 82eff9d | 2007-02-06 14:49:40 -0500 | [diff] [blame] | 1089 | fail_alloc: |
Kristian Høgsberg | e1b68c4 | 2007-05-09 19:23:09 -0400 | [diff] [blame] | 1090 | return SCSI_MLQUEUE_HOST_BUSY; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1091 | } |
| 1092 | |
Stefan Richter | cfb0138 | 2007-01-23 21:20:08 +0100 | [diff] [blame] | 1093 | static int sbp2_scsi_slave_alloc(struct scsi_device *sdev) |
| 1094 | { |
Kristian Høgsberg | ad85274f | 2007-05-09 19:23:07 -0400 | [diff] [blame] | 1095 | struct sbp2_device *sd = (struct sbp2_device *)sdev->host->hostdata; |
Stefan Richter | cfb0138 | 2007-01-23 21:20:08 +0100 | [diff] [blame] | 1096 | |
| 1097 | sdev->allow_restart = 1; |
| 1098 | |
| 1099 | if (sd->workarounds & SBP2_WORKAROUND_INQUIRY_36) |
| 1100 | sdev->inquiry_len = 36; |
| 1101 | return 0; |
| 1102 | } |
| 1103 | |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1104 | static int sbp2_scsi_slave_configure(struct scsi_device *sdev) |
| 1105 | { |
Kristian Høgsberg | ad85274f | 2007-05-09 19:23:07 -0400 | [diff] [blame] | 1106 | struct sbp2_device *sd = (struct sbp2_device *)sdev->host->hostdata; |
| 1107 | struct fw_unit *unit = sd->unit; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1108 | |
Stefan Richter | cfb0138 | 2007-01-23 21:20:08 +0100 | [diff] [blame] | 1109 | sdev->use_10_for_rw = 1; |
| 1110 | |
| 1111 | if (sdev->type == TYPE_ROM) |
| 1112 | sdev->use_10_for_ms = 1; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1113 | if (sdev->type == TYPE_DISK && |
| 1114 | sd->workarounds & SBP2_WORKAROUND_MODE_SENSE_8) |
| 1115 | sdev->skip_ms_page_8 = 1; |
| 1116 | if (sd->workarounds & SBP2_WORKAROUND_FIX_CAPACITY) { |
| 1117 | fw_notify("setting fix_capacity for %s\n", unit->device.bus_id); |
| 1118 | sdev->fix_capacity = 1; |
| 1119 | } |
Stefan Richter | cf47c7a | 2007-06-17 23:52:08 +0200 | [diff] [blame] | 1120 | if (sd->workarounds & SBP2_WORKAROUND_128K_MAX_TRANS) |
| 1121 | blk_queue_max_sectors(sdev->request_queue, 128 * 1024 / 512); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1122 | return 0; |
| 1123 | } |
| 1124 | |
| 1125 | /* |
| 1126 | * Called by scsi stack when something has really gone wrong. Usually |
| 1127 | * called when a command has timed-out for some reason. |
| 1128 | */ |
| 1129 | static int sbp2_scsi_abort(struct scsi_cmnd *cmd) |
| 1130 | { |
Kristian Høgsberg | ad85274f | 2007-05-09 19:23:07 -0400 | [diff] [blame] | 1131 | struct sbp2_device *sd = |
| 1132 | (struct sbp2_device *)cmd->device->host->hostdata; |
| 1133 | struct fw_unit *unit = sd->unit; |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1134 | |
| 1135 | fw_notify("sbp2_scsi_abort\n"); |
Kristian Høgsberg | 0fc7d6e | 2007-04-11 18:44:33 -0400 | [diff] [blame] | 1136 | sbp2_agent_reset(unit); |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1137 | sbp2_cancel_orbs(unit); |
| 1138 | |
| 1139 | return SUCCESS; |
| 1140 | } |
| 1141 | |
Stefan Richter | 14e2198 | 2007-05-27 13:18:27 +0200 | [diff] [blame] | 1142 | /* |
| 1143 | * Format of /sys/bus/scsi/devices/.../ieee1394_id: |
| 1144 | * u64 EUI-64 : u24 directory_ID : u16 LUN (all printed in hexadecimal) |
| 1145 | * |
| 1146 | * This is the concatenation of target port identifier and logical unit |
| 1147 | * identifier as per SAM-2...SAM-4 annex A. |
| 1148 | */ |
| 1149 | static ssize_t |
| 1150 | sbp2_sysfs_ieee1394_id_show(struct device *dev, struct device_attribute *attr, |
| 1151 | char *buf) |
| 1152 | { |
| 1153 | struct scsi_device *sdev = to_scsi_device(dev); |
| 1154 | struct sbp2_device *sd; |
| 1155 | struct fw_unit *unit; |
| 1156 | struct fw_device *device; |
| 1157 | u32 directory_id; |
| 1158 | struct fw_csr_iterator ci; |
| 1159 | int key, value, lun; |
| 1160 | |
| 1161 | if (!sdev) |
| 1162 | return 0; |
| 1163 | sd = (struct sbp2_device *)sdev->host->hostdata; |
| 1164 | unit = sd->unit; |
| 1165 | device = fw_device(unit->device.parent); |
| 1166 | |
| 1167 | /* implicit directory ID */ |
| 1168 | directory_id = ((unit->directory - device->config_rom) * 4 |
| 1169 | + CSR_CONFIG_ROM) & 0xffffff; |
| 1170 | |
| 1171 | /* explicit directory ID, overrides implicit ID if present */ |
| 1172 | fw_csr_iterator_init(&ci, unit->directory); |
| 1173 | while (fw_csr_iterator_next(&ci, &key, &value)) |
| 1174 | if (key == CSR_DIRECTORY_ID) { |
| 1175 | directory_id = value; |
| 1176 | break; |
| 1177 | } |
| 1178 | |
| 1179 | /* FIXME: Make this work for multi-lun devices. */ |
| 1180 | lun = 0; |
| 1181 | |
| 1182 | return sprintf(buf, "%08x%08x:%06x:%04x\n", |
| 1183 | device->config_rom[3], device->config_rom[4], |
| 1184 | directory_id, lun); |
| 1185 | } |
| 1186 | |
| 1187 | static DEVICE_ATTR(ieee1394_id, S_IRUGO, sbp2_sysfs_ieee1394_id_show, NULL); |
| 1188 | |
| 1189 | static struct device_attribute *sbp2_scsi_sysfs_attrs[] = { |
| 1190 | &dev_attr_ieee1394_id, |
| 1191 | NULL |
| 1192 | }; |
| 1193 | |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1194 | static struct scsi_host_template scsi_driver_template = { |
| 1195 | .module = THIS_MODULE, |
| 1196 | .name = "SBP-2 IEEE-1394", |
Kristian Høgsberg | b02b6bc | 2007-05-09 19:23:12 -0400 | [diff] [blame] | 1197 | .proc_name = sbp2_driver_name, |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1198 | .queuecommand = sbp2_scsi_queuecommand, |
Stefan Richter | cfb0138 | 2007-01-23 21:20:08 +0100 | [diff] [blame] | 1199 | .slave_alloc = sbp2_scsi_slave_alloc, |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1200 | .slave_configure = sbp2_scsi_slave_configure, |
| 1201 | .eh_abort_handler = sbp2_scsi_abort, |
| 1202 | .this_id = -1, |
| 1203 | .sg_tablesize = SG_ALL, |
| 1204 | .use_clustering = ENABLE_CLUSTERING, |
Stefan Richter | 02af8e7 | 2007-01-21 20:50:11 +0100 | [diff] [blame] | 1205 | .cmd_per_lun = 1, |
| 1206 | .can_queue = 1, |
Stefan Richter | 14e2198 | 2007-05-27 13:18:27 +0200 | [diff] [blame] | 1207 | .sdev_attrs = sbp2_scsi_sysfs_attrs, |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1208 | }; |
| 1209 | |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1210 | MODULE_AUTHOR("Kristian Hoegsberg <krh@bitplanet.net>"); |
| 1211 | MODULE_DESCRIPTION("SCSI over IEEE1394"); |
| 1212 | MODULE_LICENSE("GPL"); |
| 1213 | MODULE_DEVICE_TABLE(ieee1394, sbp2_id_table); |
| 1214 | |
Olaf Hering | 1e4c7b0 | 2007-05-05 23:17:13 +0200 | [diff] [blame] | 1215 | /* Provide a module alias so root-on-sbp2 initrds don't break. */ |
| 1216 | #ifndef CONFIG_IEEE1394_SBP2_MODULE |
| 1217 | MODULE_ALIAS("sbp2"); |
| 1218 | #endif |
| 1219 | |
Kristian Høgsberg | 9ba136d | 2006-12-19 19:58:40 -0500 | [diff] [blame] | 1220 | static int __init sbp2_init(void) |
| 1221 | { |
| 1222 | return driver_register(&sbp2_driver.driver); |
| 1223 | } |
| 1224 | |
| 1225 | static void __exit sbp2_cleanup(void) |
| 1226 | { |
| 1227 | driver_unregister(&sbp2_driver.driver); |
| 1228 | } |
| 1229 | |
| 1230 | module_init(sbp2_init); |
| 1231 | module_exit(sbp2_cleanup); |