blob: 7ecc154a82746f7e43f046483410ed1827430ae7 [file] [log] [blame]
Kristian Høgsbergc781c062007-05-07 20:33:32 -04001/*
2 * SBP2 driver (SCSI over IEEE1394)
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05003 *
Kristian Høgsberg27a15e52007-02-06 14:49:39 -05004 * Copyright (C) 2005-2007 Kristian Hoegsberg <krh@bitplanet.net>
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05005 *
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øgsbergc781c062007-05-07 20:33:32 -040021/*
22 * The basic structure of this driver is based on the old storage driver,
Kristian Høgsberg27a15e52007-02-06 14:49:39 -050023 * 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øgsberg9ba136d2006-12-19 19:58:40 -050031#include <linux/kernel.h>
32#include <linux/module.h>
Stefan Richter5cd54c92007-06-17 23:55:41 +020033#include <linux/moduleparam.h>
Stefan Richterfe69ca32006-12-28 12:46:54 +010034#include <linux/mod_devicetable.h>
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -050035#include <linux/device.h>
Andrew Morton0b5b2902006-12-27 14:49:23 -080036#include <linux/scatterlist.h>
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -050037#include <linux/dma-mapping.h>
Stefan Richtercf47c7a2007-06-17 23:52:08 +020038#include <linux/blkdev.h>
Stefan Richtere7cdf232007-07-01 13:54:57 +020039#include <linux/string.h>
Kristian Høgsberg1d3d52c2007-02-06 14:49:33 -050040#include <linux/timer.h>
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -050041
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 Richter5cd54c92007-06-17 23:55:41 +020052/*
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 */
59static int sbp2_param_exclusive_login = 1;
60module_param_named(exclusive_login, sbp2_param_exclusive_login, bool, 0644);
61MODULE_PARM_DESC(exclusive_login, "Exclusive login to sbp2 device "
62 "(default = Y, use N for concurrent initiators)");
63
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -050064/* I don't know why the SCSI stack doesn't define something like this... */
Kristian Høgsberga98e2712007-05-07 20:33:34 -040065typedef void (*scsi_done_fn_t)(struct scsi_cmnd *);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -050066
67static const char sbp2_driver_name[] = "sbp2";
68
69struct sbp2_device {
Kristian Høgsbergb3d6e152007-03-14 17:34:58 -040070 struct kref kref;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -050071 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øgsbergc781c062007-05-07 20:33:32 -040079 /*
80 * We cache these addresses and only update them once we've
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -050081 * 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øgsbergc781c062007-05-07 20:33:32 -040084 * handle it (e.g. after a bus reset but before we reconnect).
85 */
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -050086 int node_id;
87 int address_high;
88 int generation;
89
Kristian Høgsberg7f37c422007-02-06 14:49:34 -050090 int retries;
91 struct delayed_work work;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -050092};
93
94#define SBP2_MAX_SG_ELEMENT_LENGTH 0xf000
95#define SBP2_MAX_SECTORS 255 /* Max sectors supported */
Kristian Høgsberg1d3d52c2007-02-06 14:49:33 -050096#define SBP2_ORB_TIMEOUT 2000 /* Timeout in ms */
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -050097
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øgsberga77754a2007-05-07 20:33:35 -0400140#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øgsberg9ba136d2006-12-19 19:58:40 -0500148
149struct sbp2_status {
150 u32 status;
151 u32 orb_low;
152 u8 data[24];
153};
154
155struct sbp2_pointer {
156 u32 high;
157 u32 low;
158};
159
160struct sbp2_orb {
161 struct fw_transaction t;
Kristian Høgsberge57d2012007-08-24 18:59:58 -0400162 struct kref kref;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500163 dma_addr_t request_bus;
164 int rcode;
165 struct sbp2_pointer pointer;
Kristian Høgsberga98e2712007-05-07 20:33:34 -0400166 void (*callback)(struct sbp2_orb * orb, struct sbp2_status * status);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500167 struct list_head link;
168};
169
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400170#define MANAGEMENT_ORB_LUN(v) ((v))
171#define MANAGEMENT_ORB_FUNCTION(v) ((v) << 16)
172#define MANAGEMENT_ORB_RECONNECT(v) ((v) << 20)
Stefan Richter5cd54c92007-06-17 23:55:41 +0200173#define MANAGEMENT_ORB_EXCLUSIVE(v) ((v) ? 1 << 28 : 0)
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400174#define MANAGEMENT_ORB_REQUEST_FORMAT(v) ((v) << 29)
175#define MANAGEMENT_ORB_NOTIFY ((1) << 31)
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500176
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400177#define MANAGEMENT_ORB_RESPONSE_LENGTH(v) ((v))
178#define MANAGEMENT_ORB_PASSWORD_LENGTH(v) ((v) << 16)
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500179
180struct 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øgsberga77754a2007-05-07 20:33:35 -0400195#define LOGIN_RESPONSE_GET_LOGIN_ID(v) ((v).misc & 0xffff)
196#define LOGIN_RESPONSE_GET_LENGTH(v) (((v).misc >> 16) & 0xffff)
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500197
198struct sbp2_login_response {
199 u32 misc;
200 struct sbp2_pointer command_block_agent;
201 u32 reconnect_hold;
202};
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400203#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øgsberg9ba136d2006-12-19 19:58:40 -0500211
212struct 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 Richter9fb2dd12007-07-01 13:55:31 +0200224 struct sbp2_pointer page_table[SG_ALL] __attribute__((aligned(8)));
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500225 dma_addr_t page_table_bus;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500226};
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 */
237static 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øgsbergc781c062007-05-07 20:33:32 -0400258
259 /*
260 * There are iPods (2nd gen, 3rd gen) with model_id == 0, but
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500261 * these iPods do not feature the read_capacity bug according
262 * to one report. Read_capacity behaviour as well as model_id
Kristian Høgsbergc781c062007-05-07 20:33:32 -0400263 * could change due to Apple-supplied firmware updates though.
264 */
265
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500266 /* 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
283static void
Kristian Høgsberge57d2012007-08-24 18:59:58 -0400284free_orb(struct kref *kref)
285{
286 struct sbp2_orb *orb = container_of(kref, struct sbp2_orb, kref);
287
288 kfree(orb);
289}
290
291static void
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500292sbp2_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øgsberg2d826cc2007-05-09 19:23:14 -0400305 length == 0 || length > sizeof(status)) {
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500306 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øgsberga77754a2007-05-07 20:33:35 -0400314 if (STATUS_GET_SOURCE(status) == 2 || STATUS_GET_SOURCE(status) == 3) {
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500315 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øgsberga77754a2007-05-07 20:33:35 -0400323 if (STATUS_GET_ORB_HIGH(status) == 0 &&
Kristian Høgsberge57d2012007-08-24 18:59:58 -0400324 STATUS_GET_ORB_LOW(status) == orb->request_bus) {
325 orb->rcode = RCODE_COMPLETE;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500326 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øgsberge57d2012007-08-24 18:59:58 -0400337 kref_put(&orb->kref, free_orb);
338
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500339 fw_send_response(card, request, RCODE_COMPLETE);
340}
341
342static void
343complete_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øgsberge57d2012007-08-24 18:59:58 -0400349 /*
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øgsberg9ba136d2006-12-19 19:58:40 -0500363 list_del(&orb->link);
Stefan Richter1b34e972007-08-25 10:40:42 +0200364 spin_unlock_irqrestore(&card->lock, flags);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500365 orb->callback(orb, NULL);
Stefan Richter1b34e972007-08-25 10:40:42 +0200366 } else {
367 spin_unlock_irqrestore(&card->lock, flags);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500368 }
Kristian Høgsberge57d2012007-08-24 18:59:58 -0400369
Kristian Høgsberge57d2012007-08-24 18:59:58 -0400370 kref_put(&orb->kref, free_orb);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500371}
372
373static void
374sbp2_send_orb(struct sbp2_orb *orb, struct fw_unit *unit,
375 int node_id, int generation, u64 offset)
376{
377 struct fw_device *device = fw_device(unit->device.parent);
378 struct sbp2_device *sd = unit->device.driver_data;
379 unsigned long flags;
380
381 orb->pointer.high = 0;
382 orb->pointer.low = orb->request_bus;
Kristian Høgsberg2d826cc2007-05-09 19:23:14 -0400383 fw_memcpy_to_be32(&orb->pointer, &orb->pointer, sizeof(orb->pointer));
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500384
385 spin_lock_irqsave(&device->card->lock, flags);
386 list_add_tail(&orb->link, &sd->orb_list);
387 spin_unlock_irqrestore(&device->card->lock, flags);
388
Kristian Høgsberge57d2012007-08-24 18:59:58 -0400389 /* Take a ref for the orb list and for the transaction callback. */
390 kref_get(&orb->kref);
391 kref_get(&orb->kref);
392
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500393 fw_send_request(device->card, &orb->t, TCODE_WRITE_BLOCK_REQUEST,
Stefan Richterf1397492007-06-10 21:31:36 +0200394 node_id, generation, device->max_speed, offset,
Kristian Høgsberg2d826cc2007-05-09 19:23:14 -0400395 &orb->pointer, sizeof(orb->pointer),
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500396 complete_transaction, orb);
397}
398
Kristian Høgsberg2aaad972007-03-07 12:12:47 -0500399static int sbp2_cancel_orbs(struct fw_unit *unit)
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500400{
401 struct fw_device *device = fw_device(unit->device.parent);
402 struct sbp2_device *sd = unit->device.driver_data;
403 struct sbp2_orb *orb, *next;
404 struct list_head list;
405 unsigned long flags;
Kristian Høgsberg2aaad972007-03-07 12:12:47 -0500406 int retval = -ENOENT;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500407
408 INIT_LIST_HEAD(&list);
409 spin_lock_irqsave(&device->card->lock, flags);
410 list_splice_init(&sd->orb_list, &list);
411 spin_unlock_irqrestore(&device->card->lock, flags);
412
413 list_for_each_entry_safe(orb, next, &list, link) {
Kristian Høgsberg2aaad972007-03-07 12:12:47 -0500414 retval = 0;
Kristian Høgsberg730c32f2007-02-06 14:49:32 -0500415 if (fw_cancel_transaction(device->card, &orb->t) == 0)
416 continue;
417
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500418 orb->rcode = RCODE_CANCELLED;
419 orb->callback(orb, NULL);
420 }
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500421
Kristian Høgsberg2aaad972007-03-07 12:12:47 -0500422 return retval;
Kristian Høgsberg1d3d52c2007-02-06 14:49:33 -0500423}
424
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500425static void
426complete_management_orb(struct sbp2_orb *base_orb, struct sbp2_status *status)
427{
428 struct sbp2_management_orb *orb =
Jay Fenlason6f061482007-06-27 16:04:33 -0400429 container_of(base_orb, struct sbp2_management_orb, base);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500430
431 if (status)
Kristian Høgsberg2d826cc2007-05-09 19:23:14 -0400432 memcpy(&orb->status, status, sizeof(*status));
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500433 complete(&orb->done);
434}
435
436static int
437sbp2_send_management_orb(struct fw_unit *unit, int node_id, int generation,
438 int function, int lun, void *response)
439{
440 struct fw_device *device = fw_device(unit->device.parent);
441 struct sbp2_device *sd = unit->device.driver_data;
442 struct sbp2_management_orb *orb;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500443 int retval = -ENOMEM;
444
Kristian Høgsberg2d826cc2007-05-09 19:23:14 -0400445 orb = kzalloc(sizeof(*orb), GFP_ATOMIC);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500446 if (orb == NULL)
447 return -ENOMEM;
448
Kristian Høgsberge57d2012007-08-24 18:59:58 -0400449 kref_init(&orb->base.kref);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500450 orb->response_bus =
451 dma_map_single(device->card->device, &orb->response,
Kristian Høgsberg2d826cc2007-05-09 19:23:14 -0400452 sizeof(orb->response), DMA_FROM_DEVICE);
Kristian Høgsberg82eff9d2007-02-06 14:49:40 -0500453 if (dma_mapping_error(orb->response_bus))
Stefan Richter7aa48482007-07-02 21:04:44 +0200454 goto fail_mapping_response;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500455
456 orb->request.response.high = 0;
457 orb->request.response.low = orb->response_bus;
458
459 orb->request.misc =
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400460 MANAGEMENT_ORB_NOTIFY |
461 MANAGEMENT_ORB_FUNCTION(function) |
462 MANAGEMENT_ORB_LUN(lun);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500463 orb->request.length =
Kristian Høgsberg2d826cc2007-05-09 19:23:14 -0400464 MANAGEMENT_ORB_RESPONSE_LENGTH(sizeof(orb->response));
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500465
466 orb->request.status_fifo.high = sd->address_handler.offset >> 32;
467 orb->request.status_fifo.low = sd->address_handler.offset;
468
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500469 if (function == SBP2_LOGIN_REQUEST) {
470 orb->request.misc |=
Stefan Richter5cd54c92007-06-17 23:55:41 +0200471 MANAGEMENT_ORB_EXCLUSIVE(sbp2_param_exclusive_login) |
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400472 MANAGEMENT_ORB_RECONNECT(0);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500473 }
474
Kristian Høgsberg2d826cc2007-05-09 19:23:14 -0400475 fw_memcpy_to_be32(&orb->request, &orb->request, sizeof(orb->request));
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500476
477 init_completion(&orb->done);
478 orb->base.callback = complete_management_orb;
Kristian Høgsberg2aaad972007-03-07 12:12:47 -0500479
Stefan Richter7aa48482007-07-02 21:04:44 +0200480 orb->base.request_bus =
481 dma_map_single(device->card->device, &orb->request,
482 sizeof(orb->request), DMA_TO_DEVICE);
483 if (dma_mapping_error(orb->base.request_bus))
484 goto fail_mapping_request;
485
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500486 sbp2_send_orb(&orb->base, unit,
487 node_id, generation, sd->management_agent_address);
488
Kristian Høgsberg2aaad972007-03-07 12:12:47 -0500489 wait_for_completion_timeout(&orb->done,
490 msecs_to_jiffies(SBP2_ORB_TIMEOUT));
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500491
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500492 retval = -EIO;
Kristian Høgsberg2aaad972007-03-07 12:12:47 -0500493 if (sbp2_cancel_orbs(unit) == 0) {
494 fw_error("orb reply timed out, rcode=0x%02x\n",
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500495 orb->base.rcode);
496 goto out;
497 }
498
Kristian Høgsberg2aaad972007-03-07 12:12:47 -0500499 if (orb->base.rcode != RCODE_COMPLETE) {
500 fw_error("management write failed, rcode 0x%02x\n",
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500501 orb->base.rcode);
502 goto out;
503 }
504
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400505 if (STATUS_GET_RESPONSE(orb->status) != 0 ||
506 STATUS_GET_SBP_STATUS(orb->status) != 0) {
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500507 fw_error("error status: %d:%d\n",
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400508 STATUS_GET_RESPONSE(orb->status),
509 STATUS_GET_SBP_STATUS(orb->status));
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500510 goto out;
511 }
512
513 retval = 0;
514 out:
515 dma_unmap_single(device->card->device, orb->base.request_bus,
Kristian Høgsberg2d826cc2007-05-09 19:23:14 -0400516 sizeof(orb->request), DMA_TO_DEVICE);
Stefan Richter7aa48482007-07-02 21:04:44 +0200517 fail_mapping_request:
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500518 dma_unmap_single(device->card->device, orb->response_bus,
Kristian Høgsberg2d826cc2007-05-09 19:23:14 -0400519 sizeof(orb->response), DMA_FROM_DEVICE);
Stefan Richter7aa48482007-07-02 21:04:44 +0200520 fail_mapping_response:
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500521 if (response)
522 fw_memcpy_from_be32(response,
Kristian Høgsberg2d826cc2007-05-09 19:23:14 -0400523 orb->response, sizeof(orb->response));
Kristian Høgsberge57d2012007-08-24 18:59:58 -0400524 kref_put(&orb->base.kref, free_orb);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500525
526 return retval;
527}
528
529static void
530complete_agent_reset_write(struct fw_card *card, int rcode,
531 void *payload, size_t length, void *data)
532{
533 struct fw_transaction *t = data;
534
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500535 kfree(t);
536}
537
538static int sbp2_agent_reset(struct fw_unit *unit)
539{
540 struct fw_device *device = fw_device(unit->device.parent);
541 struct sbp2_device *sd = unit->device.driver_data;
542 struct fw_transaction *t;
543 static u32 zero;
544
Kristian Høgsberg2d826cc2007-05-09 19:23:14 -0400545 t = kzalloc(sizeof(*t), GFP_ATOMIC);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500546 if (t == NULL)
547 return -ENOMEM;
548
549 fw_send_request(device->card, t, TCODE_WRITE_QUADLET_REQUEST,
Stefan Richterffd0db22007-07-01 13:54:24 +0200550 sd->node_id, sd->generation, device->max_speed,
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500551 sd->command_block_agent_address + SBP2_AGENT_RESET,
Kristian Høgsberg2d826cc2007-05-09 19:23:14 -0400552 &zero, sizeof(zero), complete_agent_reset_write, t);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500553
554 return 0;
555}
556
Kristian Høgsberg7f37c422007-02-06 14:49:34 -0500557static void sbp2_reconnect(struct work_struct *work);
Kristian Høgsbergad852742007-05-09 19:23:07 -0400558static struct scsi_host_template scsi_driver_template;
Kristian Høgsberg7f37c422007-02-06 14:49:34 -0500559
Stefan Richter79352e92007-06-18 18:46:49 +0200560static void release_sbp2_device(struct kref *kref)
Kristian Høgsbergb3d6e152007-03-14 17:34:58 -0400561{
562 struct sbp2_device *sd = container_of(kref, struct sbp2_device, kref);
Kristian Høgsbergad852742007-05-09 19:23:07 -0400563 struct Scsi_Host *host =
564 container_of((void *)sd, struct Scsi_Host, hostdata[0]);
Kristian Høgsbergb3d6e152007-03-14 17:34:58 -0400565
Stefan Richter79352e92007-06-18 18:46:49 +0200566 scsi_remove_host(host);
Kristian Høgsbergb3d6e152007-03-14 17:34:58 -0400567 sbp2_send_management_orb(sd->unit, sd->node_id, sd->generation,
568 SBP2_LOGOUT_REQUEST, sd->login_id, NULL);
Kristian Høgsbergb3d6e152007-03-14 17:34:58 -0400569 fw_core_remove_address_handler(&sd->address_handler);
570 fw_notify("removed sbp2 unit %s\n", sd->unit->device.bus_id);
571 put_device(&sd->unit->device);
Kristian Høgsbergad852742007-05-09 19:23:07 -0400572 scsi_host_put(host);
Kristian Høgsbergb3d6e152007-03-14 17:34:58 -0400573}
574
Kristian Høgsberg7f37c422007-02-06 14:49:34 -0500575static void sbp2_login(struct work_struct *work)
576{
577 struct sbp2_device *sd =
578 container_of(work, struct sbp2_device, work.work);
Kristian Høgsbergad852742007-05-09 19:23:07 -0400579 struct Scsi_Host *host =
580 container_of((void *)sd, struct Scsi_Host, hostdata[0]);
Kristian Høgsberg7f37c422007-02-06 14:49:34 -0500581 struct fw_unit *unit = sd->unit;
582 struct fw_device *device = fw_device(unit->device.parent);
583 struct sbp2_login_response response;
584 int generation, node_id, local_node_id, lun, retval;
585
586 /* FIXME: Make this work for multi-lun devices. */
587 lun = 0;
588
589 generation = device->card->generation;
590 node_id = device->node->node_id;
591 local_node_id = device->card->local_node->node_id;
592
593 if (sbp2_send_management_orb(unit, node_id, generation,
594 SBP2_LOGIN_REQUEST, lun, &response) < 0) {
595 if (sd->retries++ < 5) {
Kristian Høgsberg7f37c422007-02-06 14:49:34 -0500596 schedule_delayed_work(&sd->work, DIV_ROUND_UP(HZ, 5));
597 } else {
598 fw_error("failed to login to %s\n",
599 unit->device.bus_id);
Kristian Høgsbergb3d6e152007-03-14 17:34:58 -0400600 kref_put(&sd->kref, release_sbp2_device);
Kristian Høgsberg7f37c422007-02-06 14:49:34 -0500601 }
602 return;
603 }
604
605 sd->generation = generation;
606 sd->node_id = node_id;
607 sd->address_high = local_node_id << 16;
608
609 /* Get command block agent offset and login id. */
610 sd->command_block_agent_address =
Kristian Høgsberg5c5539d2007-03-07 12:12:45 -0500611 ((u64) (response.command_block_agent.high & 0xffff) << 32) |
Kristian Høgsberg7f37c422007-02-06 14:49:34 -0500612 response.command_block_agent.low;
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400613 sd->login_id = LOGIN_RESPONSE_GET_LOGIN_ID(response);
Kristian Høgsberg7f37c422007-02-06 14:49:34 -0500614
Kristian Høgsberg5c5539d2007-03-07 12:12:45 -0500615 fw_notify("logged in to sbp2 unit %s (%d retries)\n",
616 unit->device.bus_id, sd->retries);
617 fw_notify(" - management_agent_address: 0x%012llx\n",
Kristian Høgsberg7f37c422007-02-06 14:49:34 -0500618 (unsigned long long) sd->management_agent_address);
619 fw_notify(" - command_block_agent_address: 0x%012llx\n",
620 (unsigned long long) sd->command_block_agent_address);
Kristian Høgsberg5c5539d2007-03-07 12:12:45 -0500621 fw_notify(" - status write address: 0x%012llx\n",
Kristian Høgsberg7f37c422007-02-06 14:49:34 -0500622 (unsigned long long) sd->address_handler.offset);
623
624#if 0
625 /* FIXME: The linux1394 sbp2 does this last step. */
626 sbp2_set_busy_timeout(scsi_id);
627#endif
628
Kristian Høgsberg1da0c932007-03-07 12:12:40 -0500629 PREPARE_DELAYED_WORK(&sd->work, sbp2_reconnect);
Kristian Høgsberg7f37c422007-02-06 14:49:34 -0500630 sbp2_agent_reset(unit);
631
Kristian Høgsbergad852742007-05-09 19:23:07 -0400632 /* FIXME: Loop over luns here. */
633 lun = 0;
634 retval = scsi_add_device(host, 0, 0, lun);
Kristian Høgsberg7f37c422007-02-06 14:49:34 -0500635 if (retval < 0) {
636 sbp2_send_management_orb(unit, sd->node_id, sd->generation,
637 SBP2_LOGOUT_REQUEST, sd->login_id,
638 NULL);
Kristian Høgsbergc781c062007-05-07 20:33:32 -0400639 /*
640 * Set this back to sbp2_login so we fall back and
641 * retry login on bus reset.
642 */
Kristian Høgsberg1da0c932007-03-07 12:12:40 -0500643 PREPARE_DELAYED_WORK(&sd->work, sbp2_login);
Kristian Høgsberg7f37c422007-02-06 14:49:34 -0500644 }
Kristian Høgsbergb3d6e152007-03-14 17:34:58 -0400645 kref_put(&sd->kref, release_sbp2_device);
Kristian Høgsberg7f37c422007-02-06 14:49:34 -0500646}
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500647
648static int sbp2_probe(struct device *dev)
649{
650 struct fw_unit *unit = fw_unit(dev);
651 struct fw_device *device = fw_device(unit->device.parent);
652 struct sbp2_device *sd;
653 struct fw_csr_iterator ci;
Kristian Høgsbergad852742007-05-09 19:23:07 -0400654 struct Scsi_Host *host;
655 int i, key, value, err;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500656 u32 model, firmware_revision;
657
Kristian Høgsbergad852742007-05-09 19:23:07 -0400658 err = -ENOMEM;
659 host = scsi_host_alloc(&scsi_driver_template, sizeof(*sd));
660 if (host == NULL)
661 goto fail;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500662
Kristian Høgsbergad852742007-05-09 19:23:07 -0400663 sd = (struct sbp2_device *) host->hostdata;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500664 unit->device.driver_data = sd;
665 sd->unit = unit;
666 INIT_LIST_HEAD(&sd->orb_list);
Kristian Høgsbergb3d6e152007-03-14 17:34:58 -0400667 kref_init(&sd->kref);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500668
669 sd->address_handler.length = 0x100;
670 sd->address_handler.address_callback = sbp2_status_write;
671 sd->address_handler.callback_data = sd;
672
Kristian Høgsbergad852742007-05-09 19:23:07 -0400673 err = fw_core_add_address_handler(&sd->address_handler,
674 &fw_high_memory_region);
675 if (err < 0)
676 goto fail_host;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500677
Kristian Høgsbergad852742007-05-09 19:23:07 -0400678 err = fw_device_enable_phys_dma(device);
679 if (err < 0)
680 goto fail_address_handler;
681
682 err = scsi_add_host(host, &unit->device);
683 if (err < 0)
684 goto fail_address_handler;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500685
Kristian Høgsbergc781c062007-05-07 20:33:32 -0400686 /*
687 * Scan unit directory to get management agent address,
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500688 * firmware revison and model. Initialize firmware_revision
Kristian Høgsbergc781c062007-05-07 20:33:32 -0400689 * and model to values that wont match anything in our table.
690 */
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500691 firmware_revision = 0xff000000;
692 model = 0xff000000;
693 fw_csr_iterator_init(&ci, unit->directory);
694 while (fw_csr_iterator_next(&ci, &key, &value)) {
695 switch (key) {
696 case CSR_DEPENDENT_INFO | CSR_OFFSET:
697 sd->management_agent_address =
698 0xfffff0000000ULL + 4 * value;
699 break;
700 case SBP2_FIRMWARE_REVISION:
701 firmware_revision = value;
702 break;
703 case CSR_MODEL:
704 model = value;
705 break;
706 }
707 }
708
709 for (i = 0; i < ARRAY_SIZE(sbp2_workarounds_table); i++) {
710 if (sbp2_workarounds_table[i].firmware_revision !=
711 (firmware_revision & 0xffffff00))
712 continue;
713 if (sbp2_workarounds_table[i].model != model &&
714 sbp2_workarounds_table[i].model != ~0)
715 continue;
716 sd->workarounds |= sbp2_workarounds_table[i].workarounds;
717 break;
718 }
719
720 if (sd->workarounds)
721 fw_notify("Workarounds for node %s: 0x%x "
722 "(firmware_revision 0x%06x, model_id 0x%06x)\n",
723 unit->device.bus_id,
724 sd->workarounds, firmware_revision, model);
725
Kristian Høgsbergb3d6e152007-03-14 17:34:58 -0400726 get_device(&unit->device);
727
Kristian Høgsbergc781c062007-05-07 20:33:32 -0400728 /*
729 * We schedule work to do the login so we can easily
Kristian Høgsbergb3d6e152007-03-14 17:34:58 -0400730 * reschedule retries. Always get the ref before scheduling
Kristian Høgsbergc781c062007-05-07 20:33:32 -0400731 * work.
732 */
Kristian Høgsberg7f37c422007-02-06 14:49:34 -0500733 INIT_DELAYED_WORK(&sd->work, sbp2_login);
Kristian Høgsbergb3d6e152007-03-14 17:34:58 -0400734 if (schedule_delayed_work(&sd->work, 0))
735 kref_get(&sd->kref);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500736
737 return 0;
Kristian Høgsbergad852742007-05-09 19:23:07 -0400738
739 fail_address_handler:
740 fw_core_remove_address_handler(&sd->address_handler);
741 fail_host:
742 scsi_host_put(host);
743 fail:
744 return err;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500745}
746
747static int sbp2_remove(struct device *dev)
748{
749 struct fw_unit *unit = fw_unit(dev);
750 struct sbp2_device *sd = unit->device.driver_data;
751
Kristian Høgsbergb3d6e152007-03-14 17:34:58 -0400752 kref_put(&sd->kref, release_sbp2_device);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500753
754 return 0;
755}
756
757static void sbp2_reconnect(struct work_struct *work)
758{
Kristian Høgsberg7f37c422007-02-06 14:49:34 -0500759 struct sbp2_device *sd =
760 container_of(work, struct sbp2_device, work.work);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500761 struct fw_unit *unit = sd->unit;
762 struct fw_device *device = fw_device(unit->device.parent);
763 int generation, node_id, local_node_id;
764
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500765 generation = device->card->generation;
766 node_id = device->node->node_id;
767 local_node_id = device->card->local_node->node_id;
768
Kristian Høgsberg7f37c422007-02-06 14:49:34 -0500769 if (sbp2_send_management_orb(unit, node_id, generation,
770 SBP2_RECONNECT_REQUEST,
771 sd->login_id, NULL) < 0) {
Kristian Høgsberg5c5539d2007-03-07 12:12:45 -0500772 if (sd->retries++ >= 5) {
Kristian Høgsberg7f37c422007-02-06 14:49:34 -0500773 fw_error("failed to reconnect to %s\n",
774 unit->device.bus_id);
775 /* Fall back and try to log in again. */
776 sd->retries = 0;
Kristian Høgsberg1da0c932007-03-07 12:12:40 -0500777 PREPARE_DELAYED_WORK(&sd->work, sbp2_login);
Kristian Høgsberg7f37c422007-02-06 14:49:34 -0500778 }
779 schedule_delayed_work(&sd->work, DIV_ROUND_UP(HZ, 5));
780 return;
781 }
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500782
783 sd->generation = generation;
784 sd->node_id = node_id;
Stefan Richter907293d2007-01-23 21:11:43 +0100785 sd->address_high = local_node_id << 16;
Kristian Høgsberg7f37c422007-02-06 14:49:34 -0500786
Kristian Høgsberg5c5539d2007-03-07 12:12:45 -0500787 fw_notify("reconnected to unit %s (%d retries)\n",
788 unit->device.bus_id, sd->retries);
Kristian Høgsberg7f37c422007-02-06 14:49:34 -0500789 sbp2_agent_reset(unit);
790 sbp2_cancel_orbs(unit);
Kristian Høgsbergb3d6e152007-03-14 17:34:58 -0400791 kref_put(&sd->kref, release_sbp2_device);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500792}
793
794static void sbp2_update(struct fw_unit *unit)
795{
796 struct fw_device *device = fw_device(unit->device.parent);
797 struct sbp2_device *sd = unit->device.driver_data;
798
Kristian Høgsberg7f37c422007-02-06 14:49:34 -0500799 sd->retries = 0;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500800 fw_device_enable_phys_dma(device);
Kristian Høgsbergb3d6e152007-03-14 17:34:58 -0400801 if (schedule_delayed_work(&sd->work, 0))
802 kref_get(&sd->kref);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500803}
804
805#define SBP2_UNIT_SPEC_ID_ENTRY 0x0000609e
806#define SBP2_SW_VERSION_ENTRY 0x00010483
807
Stefan Richter21ebcd12007-01-14 15:29:07 +0100808static const struct fw_device_id sbp2_id_table[] = {
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500809 {
810 .match_flags = FW_MATCH_SPECIFIER_ID | FW_MATCH_VERSION,
811 .specifier_id = SBP2_UNIT_SPEC_ID_ENTRY,
Stefan Richter5af4e5e2007-01-21 20:45:32 +0100812 .version = SBP2_SW_VERSION_ENTRY,
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500813 },
814 { }
815};
816
817static struct fw_driver sbp2_driver = {
818 .driver = {
819 .owner = THIS_MODULE,
820 .name = sbp2_driver_name,
821 .bus = &fw_bus_type,
822 .probe = sbp2_probe,
823 .remove = sbp2_remove,
824 },
825 .update = sbp2_update,
826 .id_table = sbp2_id_table,
827};
828
Kristian Høgsbergfbb54232007-04-10 18:11:18 -0400829static unsigned int
830sbp2_status_to_sense_data(u8 *sbp2_status, u8 *sense_data)
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500831{
Kristian Høgsbergfbb54232007-04-10 18:11:18 -0400832 int sam_status;
833
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500834 sense_data[0] = 0x70;
835 sense_data[1] = 0x0;
836 sense_data[2] = sbp2_status[1];
837 sense_data[3] = sbp2_status[4];
838 sense_data[4] = sbp2_status[5];
839 sense_data[5] = sbp2_status[6];
840 sense_data[6] = sbp2_status[7];
841 sense_data[7] = 10;
842 sense_data[8] = sbp2_status[8];
843 sense_data[9] = sbp2_status[9];
844 sense_data[10] = sbp2_status[10];
845 sense_data[11] = sbp2_status[11];
846 sense_data[12] = sbp2_status[2];
847 sense_data[13] = sbp2_status[3];
848 sense_data[14] = sbp2_status[12];
849 sense_data[15] = sbp2_status[13];
850
Kristian Høgsbergfbb54232007-04-10 18:11:18 -0400851 sam_status = sbp2_status[0] & 0x3f;
852
853 switch (sam_status) {
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500854 case SAM_STAT_GOOD:
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500855 case SAM_STAT_CHECK_CONDITION:
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500856 case SAM_STAT_CONDITION_MET:
Kristian Høgsbergfbb54232007-04-10 18:11:18 -0400857 case SAM_STAT_BUSY:
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500858 case SAM_STAT_RESERVATION_CONFLICT:
859 case SAM_STAT_COMMAND_TERMINATED:
Kristian Høgsbergfbb54232007-04-10 18:11:18 -0400860 return DID_OK << 16 | sam_status;
861
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500862 default:
Kristian Høgsbergfbb54232007-04-10 18:11:18 -0400863 return DID_ERROR << 16;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500864 }
865}
866
867static void
868complete_command_orb(struct sbp2_orb *base_orb, struct sbp2_status *status)
869{
Jay Fenlason6f061482007-06-27 16:04:33 -0400870 struct sbp2_command_orb *orb =
871 container_of(base_orb, struct sbp2_command_orb, base);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500872 struct fw_unit *unit = orb->unit;
873 struct fw_device *device = fw_device(unit->device.parent);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500874 int result;
875
876 if (status != NULL) {
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400877 if (STATUS_GET_DEAD(*status))
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500878 sbp2_agent_reset(unit);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500879
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400880 switch (STATUS_GET_RESPONSE(*status)) {
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500881 case SBP2_STATUS_REQUEST_COMPLETE:
Kristian Høgsbergfbb54232007-04-10 18:11:18 -0400882 result = DID_OK << 16;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500883 break;
884 case SBP2_STATUS_TRANSPORT_FAILURE:
Kristian Høgsbergfbb54232007-04-10 18:11:18 -0400885 result = DID_BUS_BUSY << 16;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500886 break;
887 case SBP2_STATUS_ILLEGAL_REQUEST:
888 case SBP2_STATUS_VENDOR_DEPENDENT:
889 default:
Kristian Høgsbergfbb54232007-04-10 18:11:18 -0400890 result = DID_ERROR << 16;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500891 break;
892 }
893
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400894 if (result == DID_OK << 16 && STATUS_GET_LEN(*status) > 1)
895 result = sbp2_status_to_sense_data(STATUS_GET_DATA(*status),
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500896 orb->cmd->sense_buffer);
897 } else {
Kristian Høgsbergc781c062007-05-07 20:33:32 -0400898 /*
899 * If the orb completes with status == NULL, something
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500900 * went wrong, typically a bus reset happened mid-orb
Kristian Høgsbergc781c062007-05-07 20:33:32 -0400901 * or when sending the write (less likely).
902 */
Kristian Høgsbergfbb54232007-04-10 18:11:18 -0400903 result = DID_BUS_BUSY << 16;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500904 }
905
906 dma_unmap_single(device->card->device, orb->base.request_bus,
Kristian Høgsberg2d826cc2007-05-09 19:23:14 -0400907 sizeof(orb->request), DMA_TO_DEVICE);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500908
Stefan Richter412edf62007-07-16 21:05:41 +0200909 if (scsi_sg_count(orb->cmd) > 0)
910 dma_unmap_sg(device->card->device, scsi_sglist(orb->cmd),
911 scsi_sg_count(orb->cmd),
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500912 orb->cmd->sc_data_direction);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500913
914 if (orb->page_table_bus != 0)
915 dma_unmap_single(device->card->device, orb->page_table_bus,
Stefan Richterb4be0162007-07-02 22:07:34 +0200916 sizeof(orb->page_table), DMA_TO_DEVICE);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500917
Kristian Høgsbergfbb54232007-04-10 18:11:18 -0400918 orb->cmd->result = result;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500919 orb->done(orb->cmd);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500920}
921
Kristian Høgsberg95ffc5e2007-05-09 19:23:08 -0400922static int sbp2_command_orb_map_scatterlist(struct sbp2_command_orb *orb)
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500923{
Kristian Høgsbergad852742007-05-09 19:23:07 -0400924 struct sbp2_device *sd =
925 (struct sbp2_device *)orb->cmd->device->host->hostdata;
926 struct fw_unit *unit = sd->unit;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500927 struct fw_device *device = fw_device(unit->device.parent);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500928 struct scatterlist *sg;
929 int sg_len, l, i, j, count;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500930 dma_addr_t sg_addr;
931
Stefan Richter412edf62007-07-16 21:05:41 +0200932 sg = scsi_sglist(orb->cmd);
933 count = dma_map_sg(device->card->device, sg, scsi_sg_count(orb->cmd),
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500934 orb->cmd->sc_data_direction);
Kristian Høgsberg95ffc5e2007-05-09 19:23:08 -0400935 if (count == 0)
936 goto fail;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500937
Kristian Høgsbergc781c062007-05-07 20:33:32 -0400938 /*
939 * Handle the special case where there is only one element in
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500940 * the scatter list by converting it to an immediate block
941 * request. This is also a workaround for broken devices such
942 * as the second generation iPod which doesn't support page
Kristian Høgsbergc781c062007-05-07 20:33:32 -0400943 * tables.
944 */
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500945 if (count == 1 && sg_dma_len(sg) < SBP2_MAX_SG_ELEMENT_LENGTH) {
946 orb->request.data_descriptor.high = sd->address_high;
947 orb->request.data_descriptor.low = sg_dma_address(sg);
948 orb->request.misc |=
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400949 COMMAND_ORB_DATA_SIZE(sg_dma_len(sg));
Kristian Høgsberg95ffc5e2007-05-09 19:23:08 -0400950 return 0;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500951 }
952
Kristian Høgsbergc781c062007-05-07 20:33:32 -0400953 /*
954 * Convert the scatterlist to an sbp2 page table. If any
Kristian Høgsberg, Stefan Richter36abb3b2007-05-09 19:23:10 -0400955 * scatterlist entries are too big for sbp2, we split them as we
956 * go. Even if we ask the block I/O layer to not give us sg
957 * elements larger than 65535 bytes, some IOMMUs may merge sg elements
958 * during DMA mapping, and Linux currently doesn't prevent this.
Kristian Høgsbergc781c062007-05-07 20:33:32 -0400959 */
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500960 for (i = 0, j = 0; i < count; i++) {
961 sg_len = sg_dma_len(sg + i);
962 sg_addr = sg_dma_address(sg + i);
963 while (sg_len) {
Stefan Richter332ef332007-07-01 13:56:03 +0200964 /* FIXME: This won't get us out of the pinch. */
965 if (unlikely(j >= ARRAY_SIZE(orb->page_table))) {
966 fw_error("page table overflow\n");
967 goto fail_page_table;
968 }
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500969 l = min(sg_len, SBP2_MAX_SG_ELEMENT_LENGTH);
970 orb->page_table[j].low = sg_addr;
971 orb->page_table[j].high = (l << 16);
972 sg_addr += l;
973 sg_len -= l;
974 j++;
975 }
976 }
977
Stefan Richterb4be0162007-07-02 22:07:34 +0200978 fw_memcpy_to_be32(orb->page_table, orb->page_table,
979 sizeof(orb->page_table[0]) * j);
980 orb->page_table_bus =
981 dma_map_single(device->card->device, orb->page_table,
982 sizeof(orb->page_table), DMA_TO_DEVICE);
983 if (dma_mapping_error(orb->page_table_bus))
984 goto fail_page_table;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500985
Kristian Høgsbergc781c062007-05-07 20:33:32 -0400986 /*
987 * The data_descriptor pointer is the one case where we need
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500988 * to fill in the node ID part of the address. All other
989 * pointers assume that the data referenced reside on the
990 * initiator (i.e. us), but data_descriptor can refer to data
Kristian Høgsbergc781c062007-05-07 20:33:32 -0400991 * on other nodes so we need to put our ID in descriptor.high.
992 */
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500993 orb->request.data_descriptor.high = sd->address_high;
994 orb->request.data_descriptor.low = orb->page_table_bus;
995 orb->request.misc |=
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400996 COMMAND_ORB_PAGE_TABLE_PRESENT |
997 COMMAND_ORB_DATA_SIZE(j);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -0500998
Kristian Høgsberg95ffc5e2007-05-09 19:23:08 -0400999 return 0;
1000
1001 fail_page_table:
Stefan Richter412edf62007-07-16 21:05:41 +02001002 dma_unmap_sg(device->card->device, sg, scsi_sg_count(orb->cmd),
Kristian Høgsberg95ffc5e2007-05-09 19:23:08 -04001003 orb->cmd->sc_data_direction);
1004 fail:
1005 return -ENOMEM;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001006}
1007
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001008/* SCSI stack integration */
1009
1010static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done)
1011{
Kristian Høgsbergad852742007-05-09 19:23:07 -04001012 struct sbp2_device *sd =
1013 (struct sbp2_device *)cmd->device->host->hostdata;
1014 struct fw_unit *unit = sd->unit;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001015 struct fw_device *device = fw_device(unit->device.parent);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001016 struct sbp2_command_orb *orb;
Stefan Richter25659f72007-07-21 22:43:05 +02001017 unsigned max_payload;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001018
Kristian Høgsbergc781c062007-05-07 20:33:32 -04001019 /*
1020 * Bidirectional commands are not yet implemented, and unknown
1021 * transfer direction not handled.
1022 */
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001023 if (cmd->sc_data_direction == DMA_BIDIRECTIONAL) {
Stefan Richter8a8cea22007-06-09 19:26:22 +02001024 fw_error("Can't handle DMA_BIDIRECTIONAL, rejecting command\n");
Kristian Høgsberge1b68c42007-05-09 19:23:09 -04001025 cmd->result = DID_ERROR << 16;
1026 done(cmd);
1027 return 0;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001028 }
1029
Kristian Høgsberg2d826cc2007-05-09 19:23:14 -04001030 orb = kzalloc(sizeof(*orb), GFP_ATOMIC);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001031 if (orb == NULL) {
1032 fw_notify("failed to alloc orb\n");
Kristian Høgsberg82eff9d2007-02-06 14:49:40 -05001033 goto fail_alloc;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001034 }
1035
Kristian Høgsberg12f26aa2007-04-10 18:11:20 -04001036 /* Initialize rcode to something not RCODE_COMPLETE. */
1037 orb->base.rcode = -1;
Kristian Høgsberge57d2012007-08-24 18:59:58 -04001038 kref_init(&orb->base.kref);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001039
1040 orb->unit = unit;
1041 orb->done = done;
1042 orb->cmd = cmd;
1043
1044 orb->request.next.high = SBP2_ORB_NULL;
1045 orb->request.next.low = 0x0;
Kristian Høgsbergc781c062007-05-07 20:33:32 -04001046 /*
1047 * At speed 100 we can do 512 bytes per packet, at speed 200,
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001048 * 1024 bytes per packet etc. The SBP-2 max_payload field
1049 * specifies the max payload size as 2 ^ (max_payload + 2), so
Kristian Høgsbergc781c062007-05-07 20:33:32 -04001050 * if we set this to max_speed + 7, we get the right value.
1051 */
Stefan Richter25659f72007-07-21 22:43:05 +02001052 max_payload = min(device->max_speed + 7,
1053 device->card->max_receive - 1);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001054 orb->request.misc =
Stefan Richter25659f72007-07-21 22:43:05 +02001055 COMMAND_ORB_MAX_PAYLOAD(max_payload) |
Stefan Richterf1397492007-06-10 21:31:36 +02001056 COMMAND_ORB_SPEED(device->max_speed) |
Kristian Høgsberga77754a2007-05-07 20:33:35 -04001057 COMMAND_ORB_NOTIFY;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001058
1059 if (cmd->sc_data_direction == DMA_FROM_DEVICE)
1060 orb->request.misc |=
Kristian Høgsberga77754a2007-05-07 20:33:35 -04001061 COMMAND_ORB_DIRECTION(SBP2_DIRECTION_FROM_MEDIA);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001062 else if (cmd->sc_data_direction == DMA_TO_DEVICE)
1063 orb->request.misc |=
Kristian Høgsberga77754a2007-05-07 20:33:35 -04001064 COMMAND_ORB_DIRECTION(SBP2_DIRECTION_TO_MEDIA);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001065
Stefan Richter412edf62007-07-16 21:05:41 +02001066 if (scsi_sg_count(cmd) && sbp2_command_orb_map_scatterlist(orb) < 0)
Stefan Richter85263922007-07-02 21:04:08 +02001067 goto fail_mapping;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001068
Kristian Høgsberg2d826cc2007-05-09 19:23:14 -04001069 fw_memcpy_to_be32(&orb->request, &orb->request, sizeof(orb->request));
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001070
1071 memset(orb->request.command_block,
Kristian Høgsberg2d826cc2007-05-09 19:23:14 -04001072 0, sizeof(orb->request.command_block));
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001073 memcpy(orb->request.command_block, cmd->cmnd, COMMAND_SIZE(*cmd->cmnd));
1074
1075 orb->base.callback = complete_command_orb;
Stefan Richter85263922007-07-02 21:04:08 +02001076 orb->base.request_bus =
1077 dma_map_single(device->card->device, &orb->request,
1078 sizeof(orb->request), DMA_TO_DEVICE);
1079 if (dma_mapping_error(orb->base.request_bus))
1080 goto fail_mapping;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001081
1082 sbp2_send_orb(&orb->base, unit, sd->node_id, sd->generation,
1083 sd->command_block_agent_address + SBP2_ORB_POINTER);
1084
Kristian Høgsberge57d2012007-08-24 18:59:58 -04001085 kref_put(&orb->base.kref, free_orb);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001086 return 0;
Kristian Høgsberg82eff9d2007-02-06 14:49:40 -05001087
Kristian Høgsberg82eff9d2007-02-06 14:49:40 -05001088 fail_mapping:
Kristian Høgsberge57d2012007-08-24 18:59:58 -04001089 kref_put(&orb->base.kref, free_orb);
Kristian Høgsberg82eff9d2007-02-06 14:49:40 -05001090 fail_alloc:
Kristian Høgsberge1b68c42007-05-09 19:23:09 -04001091 return SCSI_MLQUEUE_HOST_BUSY;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001092}
1093
Stefan Richtercfb01382007-01-23 21:20:08 +01001094static int sbp2_scsi_slave_alloc(struct scsi_device *sdev)
1095{
Kristian Høgsbergad852742007-05-09 19:23:07 -04001096 struct sbp2_device *sd = (struct sbp2_device *)sdev->host->hostdata;
Stefan Richtercfb01382007-01-23 21:20:08 +01001097
1098 sdev->allow_restart = 1;
1099
1100 if (sd->workarounds & SBP2_WORKAROUND_INQUIRY_36)
1101 sdev->inquiry_len = 36;
1102 return 0;
1103}
1104
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001105static int sbp2_scsi_slave_configure(struct scsi_device *sdev)
1106{
Kristian Høgsbergad852742007-05-09 19:23:07 -04001107 struct sbp2_device *sd = (struct sbp2_device *)sdev->host->hostdata;
1108 struct fw_unit *unit = sd->unit;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001109
Stefan Richtercfb01382007-01-23 21:20:08 +01001110 sdev->use_10_for_rw = 1;
1111
1112 if (sdev->type == TYPE_ROM)
1113 sdev->use_10_for_ms = 1;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001114 if (sdev->type == TYPE_DISK &&
1115 sd->workarounds & SBP2_WORKAROUND_MODE_SENSE_8)
1116 sdev->skip_ms_page_8 = 1;
1117 if (sd->workarounds & SBP2_WORKAROUND_FIX_CAPACITY) {
1118 fw_notify("setting fix_capacity for %s\n", unit->device.bus_id);
1119 sdev->fix_capacity = 1;
1120 }
Stefan Richtercf47c7a2007-06-17 23:52:08 +02001121 if (sd->workarounds & SBP2_WORKAROUND_128K_MAX_TRANS)
1122 blk_queue_max_sectors(sdev->request_queue, 128 * 1024 / 512);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001123 return 0;
1124}
1125
1126/*
1127 * Called by scsi stack when something has really gone wrong. Usually
1128 * called when a command has timed-out for some reason.
1129 */
1130static int sbp2_scsi_abort(struct scsi_cmnd *cmd)
1131{
Kristian Høgsbergad852742007-05-09 19:23:07 -04001132 struct sbp2_device *sd =
1133 (struct sbp2_device *)cmd->device->host->hostdata;
1134 struct fw_unit *unit = sd->unit;
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001135
1136 fw_notify("sbp2_scsi_abort\n");
Kristian Høgsberg0fc7d6e2007-04-11 18:44:33 -04001137 sbp2_agent_reset(unit);
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001138 sbp2_cancel_orbs(unit);
1139
1140 return SUCCESS;
1141}
1142
Stefan Richter14e21982007-05-27 13:18:27 +02001143/*
1144 * Format of /sys/bus/scsi/devices/.../ieee1394_id:
1145 * u64 EUI-64 : u24 directory_ID : u16 LUN (all printed in hexadecimal)
1146 *
1147 * This is the concatenation of target port identifier and logical unit
1148 * identifier as per SAM-2...SAM-4 annex A.
1149 */
1150static ssize_t
1151sbp2_sysfs_ieee1394_id_show(struct device *dev, struct device_attribute *attr,
1152 char *buf)
1153{
1154 struct scsi_device *sdev = to_scsi_device(dev);
1155 struct sbp2_device *sd;
1156 struct fw_unit *unit;
1157 struct fw_device *device;
1158 u32 directory_id;
1159 struct fw_csr_iterator ci;
1160 int key, value, lun;
1161
1162 if (!sdev)
1163 return 0;
1164 sd = (struct sbp2_device *)sdev->host->hostdata;
1165 unit = sd->unit;
1166 device = fw_device(unit->device.parent);
1167
1168 /* implicit directory ID */
1169 directory_id = ((unit->directory - device->config_rom) * 4
1170 + CSR_CONFIG_ROM) & 0xffffff;
1171
1172 /* explicit directory ID, overrides implicit ID if present */
1173 fw_csr_iterator_init(&ci, unit->directory);
1174 while (fw_csr_iterator_next(&ci, &key, &value))
1175 if (key == CSR_DIRECTORY_ID) {
1176 directory_id = value;
1177 break;
1178 }
1179
1180 /* FIXME: Make this work for multi-lun devices. */
1181 lun = 0;
1182
1183 return sprintf(buf, "%08x%08x:%06x:%04x\n",
1184 device->config_rom[3], device->config_rom[4],
1185 directory_id, lun);
1186}
1187
1188static DEVICE_ATTR(ieee1394_id, S_IRUGO, sbp2_sysfs_ieee1394_id_show, NULL);
1189
1190static struct device_attribute *sbp2_scsi_sysfs_attrs[] = {
1191 &dev_attr_ieee1394_id,
1192 NULL
1193};
1194
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001195static struct scsi_host_template scsi_driver_template = {
1196 .module = THIS_MODULE,
1197 .name = "SBP-2 IEEE-1394",
Kristian Høgsbergb02b6bc2007-05-09 19:23:12 -04001198 .proc_name = sbp2_driver_name,
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001199 .queuecommand = sbp2_scsi_queuecommand,
Stefan Richtercfb01382007-01-23 21:20:08 +01001200 .slave_alloc = sbp2_scsi_slave_alloc,
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001201 .slave_configure = sbp2_scsi_slave_configure,
1202 .eh_abort_handler = sbp2_scsi_abort,
1203 .this_id = -1,
1204 .sg_tablesize = SG_ALL,
1205 .use_clustering = ENABLE_CLUSTERING,
Stefan Richter02af8e72007-01-21 20:50:11 +01001206 .cmd_per_lun = 1,
1207 .can_queue = 1,
Stefan Richter14e21982007-05-27 13:18:27 +02001208 .sdev_attrs = sbp2_scsi_sysfs_attrs,
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001209};
1210
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001211MODULE_AUTHOR("Kristian Hoegsberg <krh@bitplanet.net>");
1212MODULE_DESCRIPTION("SCSI over IEEE1394");
1213MODULE_LICENSE("GPL");
1214MODULE_DEVICE_TABLE(ieee1394, sbp2_id_table);
1215
Olaf Hering1e4c7b02007-05-05 23:17:13 +02001216/* Provide a module alias so root-on-sbp2 initrds don't break. */
1217#ifndef CONFIG_IEEE1394_SBP2_MODULE
1218MODULE_ALIAS("sbp2");
1219#endif
1220
Kristian Høgsberg9ba136d2006-12-19 19:58:40 -05001221static int __init sbp2_init(void)
1222{
1223 return driver_register(&sbp2_driver.driver);
1224}
1225
1226static void __exit sbp2_cleanup(void)
1227{
1228 driver_unregister(&sbp2_driver.driver);
1229}
1230
1231module_init(sbp2_init);
1232module_exit(sbp2_cleanup);