aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-16 19:52:21 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-16 19:52:21 -0400
commit1316ff5d52a8caf76da3c5fb351699f9fcc07b4a (patch)
tree8868d16f8cda814ae0804c7ef1b61b895df8a470
parentf563d53c30f3e60cde3a194cc1a87284ee0b3366 (diff)
parent83431cba3d847fc2296d3f38ce7feb623a1cfc45 (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394-2.6
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394-2.6: (25 commits) firewire: fw-cdev: reorder wakeup vs. spinlock firewire: in-code doc updates. firewire: a header cleanup firewire: adopt read cycle timer ABI from raw1394 firewire: fw-ohci: check for misconfigured bus (phyID == 63) firewire: fw-ohci: missing dma_unmap_single firewire: fw-ohci: log posted write errors firewire: fw-ohci: reorder includes firewire: fw-ohci: fix includes firewire: fw-ohci: enforce read order for selfID generation firewire: fw-sbp2: use an own workqueue (fix system responsiveness) firewire: fw-sbp2: expose module parameter for workarounds firewire: fw-sbp2: add support for multiple logical units per target firewire: fw-sbp2: always enable IRQs before calling command ORB callback firewire: fw-core: local variable shadows a global one firewire: optimize fw_core_add_address_handler ieee1394: ieee1394_core.c: use DEFINE_SPINLOCK for spinlock definition ieee1394: csr1212: proper refcounting ieee1394: nodemgr: fix leak of struct csr1212_keyval ieee1394: pcilynx: I2C cleanups ...
-rw-r--r--drivers/firewire/fw-cdev.c52
-rw-r--r--drivers/firewire/fw-device.h5
-rw-r--r--drivers/firewire/fw-ohci.c41
-rw-r--r--drivers/firewire/fw-ohci.h2
-rw-r--r--drivers/firewire/fw-sbp2.c647
-rw-r--r--drivers/firewire/fw-topology.c10
-rw-r--r--drivers/firewire/fw-topology.h6
-rw-r--r--drivers/firewire/fw-transaction.c12
-rw-r--r--drivers/ieee1394/csr1212.c57
-rw-r--r--drivers/ieee1394/csr1212.h6
-rw-r--r--drivers/ieee1394/eth1394.c16
-rw-r--r--drivers/ieee1394/ieee1394_core.c2
-rw-r--r--drivers/ieee1394/nodemgr.c22
-rw-r--r--drivers/ieee1394/pcilynx.c29
-rw-r--r--drivers/ieee1394/sbp2.c15
-rw-r--r--include/linux/firewire-cdev.h15
16 files changed, 560 insertions, 377 deletions
diff --git a/drivers/firewire/fw-cdev.c b/drivers/firewire/fw-cdev.c
index 06471302200f..60f1a8924a95 100644
--- a/drivers/firewire/fw-cdev.c
+++ b/drivers/firewire/fw-cdev.c
@@ -25,11 +25,14 @@
25#include <linux/device.h> 25#include <linux/device.h>
26#include <linux/vmalloc.h> 26#include <linux/vmalloc.h>
27#include <linux/poll.h> 27#include <linux/poll.h>
28#include <linux/preempt.h>
29#include <linux/time.h>
28#include <linux/delay.h> 30#include <linux/delay.h>
29#include <linux/mm.h> 31#include <linux/mm.h>
30#include <linux/idr.h> 32#include <linux/idr.h>
31#include <linux/compat.h> 33#include <linux/compat.h>
32#include <linux/firewire-cdev.h> 34#include <linux/firewire-cdev.h>
35#include <asm/system.h>
33#include <asm/uaccess.h> 36#include <asm/uaccess.h>
34#include "fw-transaction.h" 37#include "fw-transaction.h"
35#include "fw-topology.h" 38#include "fw-topology.h"
@@ -140,11 +143,10 @@ static void queue_event(struct client *client, struct event *event,
140 event->v[1].size = size1; 143 event->v[1].size = size1;
141 144
142 spin_lock_irqsave(&client->lock, flags); 145 spin_lock_irqsave(&client->lock, flags);
143
144 list_add_tail(&event->link, &client->event_list); 146 list_add_tail(&event->link, &client->event_list);
145 wake_up_interruptible(&client->wait);
146
147 spin_unlock_irqrestore(&client->lock, flags); 147 spin_unlock_irqrestore(&client->lock, flags);
148
149 wake_up_interruptible(&client->wait);
148} 150}
149 151
150static int 152static int
@@ -621,20 +623,19 @@ iso_callback(struct fw_iso_context *context, u32 cycle,
621 size_t header_length, void *header, void *data) 623 size_t header_length, void *header, void *data)
622{ 624{
623 struct client *client = data; 625 struct client *client = data;
624 struct iso_interrupt *interrupt; 626 struct iso_interrupt *irq;
625 627
626 interrupt = kzalloc(sizeof(*interrupt) + header_length, GFP_ATOMIC); 628 irq = kzalloc(sizeof(*irq) + header_length, GFP_ATOMIC);
627 if (interrupt == NULL) 629 if (irq == NULL)
628 return; 630 return;
629 631
630 interrupt->interrupt.type = FW_CDEV_EVENT_ISO_INTERRUPT; 632 irq->interrupt.type = FW_CDEV_EVENT_ISO_INTERRUPT;
631 interrupt->interrupt.closure = client->iso_closure; 633 irq->interrupt.closure = client->iso_closure;
632 interrupt->interrupt.cycle = cycle; 634 irq->interrupt.cycle = cycle;
633 interrupt->interrupt.header_length = header_length; 635 irq->interrupt.header_length = header_length;
634 memcpy(interrupt->interrupt.header, header, header_length); 636 memcpy(irq->interrupt.header, header, header_length);
635 queue_event(client, &interrupt->event, 637 queue_event(client, &irq->event, &irq->interrupt,
636 &interrupt->interrupt, 638 sizeof(irq->interrupt) + header_length, NULL, 0);
637 sizeof(interrupt->interrupt) + header_length, NULL, 0);
638} 639}
639 640
640static int ioctl_create_iso_context(struct client *client, void *buffer) 641static int ioctl_create_iso_context(struct client *client, void *buffer)
@@ -812,6 +813,28 @@ static int ioctl_stop_iso(struct client *client, void *buffer)
812 return fw_iso_context_stop(client->iso_context); 813 return fw_iso_context_stop(client->iso_context);
813} 814}
814 815
816static int ioctl_get_cycle_timer(struct client *client, void *buffer)
817{
818 struct fw_cdev_get_cycle_timer *request = buffer;
819 struct fw_card *card = client->device->card;
820 unsigned long long bus_time;
821 struct timeval tv;
822 unsigned long flags;
823
824 preempt_disable();
825 local_irq_save(flags);
826
827 bus_time = card->driver->get_bus_time(card);
828 do_gettimeofday(&tv);
829
830 local_irq_restore(flags);
831 preempt_enable();
832
833 request->local_time = tv.tv_sec * 1000000ULL + tv.tv_usec;
834 request->cycle_timer = bus_time & 0xffffffff;
835 return 0;
836}
837
815static int (* const ioctl_handlers[])(struct client *client, void *buffer) = { 838static int (* const ioctl_handlers[])(struct client *client, void *buffer) = {
816 ioctl_get_info, 839 ioctl_get_info,
817 ioctl_send_request, 840 ioctl_send_request,
@@ -825,6 +848,7 @@ static int (* const ioctl_handlers[])(struct client *client, void *buffer) = {
825 ioctl_queue_iso, 848 ioctl_queue_iso,
826 ioctl_start_iso, 849 ioctl_start_iso,
827 ioctl_stop_iso, 850 ioctl_stop_iso,
851 ioctl_get_cycle_timer,
828}; 852};
829 853
830static int 854static int
diff --git a/drivers/firewire/fw-device.h b/drivers/firewire/fw-device.h
index d13e6a69707f..894d4a92a18e 100644
--- a/drivers/firewire/fw-device.h
+++ b/drivers/firewire/fw-device.h
@@ -102,11 +102,6 @@ fw_unit(struct device *dev)
102#define CSR_INSTANCE 0x18 102#define CSR_INSTANCE 0x18
103#define CSR_DIRECTORY_ID 0x20 103#define CSR_DIRECTORY_ID 0x20
104 104
105#define SBP2_COMMAND_SET_SPECIFIER 0x38
106#define SBP2_COMMAND_SET 0x39
107#define SBP2_COMMAND_SET_REVISION 0x3b
108#define SBP2_FIRMWARE_REVISION 0x3c
109
110struct fw_csr_iterator { 105struct fw_csr_iterator {
111 u32 *p; 106 u32 *p;
112 u32 *end; 107 u32 *end;
diff --git a/drivers/firewire/fw-ohci.c b/drivers/firewire/fw-ohci.c
index e14c1ca7813e..2f307c4df335 100644
--- a/drivers/firewire/fw-ohci.c
+++ b/drivers/firewire/fw-ohci.c
@@ -18,21 +18,23 @@
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */ 19 */
20 20
21#include <linux/kernel.h> 21#include <linux/compiler.h>
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/interrupt.h>
25#include <linux/pci.h>
26#include <linux/delay.h> 22#include <linux/delay.h>
27#include <linux/poll.h>
28#include <linux/dma-mapping.h> 23#include <linux/dma-mapping.h>
24#include <linux/gfp.h>
25#include <linux/init.h>
26#include <linux/interrupt.h>
27#include <linux/kernel.h>
29#include <linux/mm.h> 28#include <linux/mm.h>
29#include <linux/module.h>
30#include <linux/pci.h>
31#include <linux/spinlock.h>
30 32
31#include <asm/uaccess.h> 33#include <asm/page.h>
32#include <asm/semaphore.h> 34#include <asm/system.h>
33 35
34#include "fw-transaction.h"
35#include "fw-ohci.h" 36#include "fw-ohci.h"
37#include "fw-transaction.h"
36 38
37#define DESCRIPTOR_OUTPUT_MORE 0 39#define DESCRIPTOR_OUTPUT_MORE 0
38#define DESCRIPTOR_OUTPUT_LAST (1 << 12) 40#define DESCRIPTOR_OUTPUT_LAST (1 << 12)
@@ -678,6 +680,9 @@ at_context_queue_packet(struct context *ctx, struct fw_packet *packet)
678 680
679 /* FIXME: Document how the locking works. */ 681 /* FIXME: Document how the locking works. */
680 if (ohci->generation != packet->generation) { 682 if (ohci->generation != packet->generation) {
683 if (packet->payload_length > 0)
684 dma_unmap_single(ohci->card.device, payload_bus,
685 packet->payload_length, DMA_TO_DEVICE);
681 packet->ack = RCODE_GENERATION; 686 packet->ack = RCODE_GENERATION;
682 return -1; 687 return -1;
683 } 688 }
@@ -912,10 +917,15 @@ static void bus_reset_tasklet(unsigned long data)
912 917
913 reg = reg_read(ohci, OHCI1394_NodeID); 918 reg = reg_read(ohci, OHCI1394_NodeID);
914 if (!(reg & OHCI1394_NodeID_idValid)) { 919 if (!(reg & OHCI1394_NodeID_idValid)) {
915 fw_error("node ID not valid, new bus reset in progress\n"); 920 fw_notify("node ID not valid, new bus reset in progress\n");
916 return; 921 return;
917 } 922 }
918 ohci->node_id = reg & 0xffff; 923 if ((reg & OHCI1394_NodeID_nodeNumber) == 63) {
924 fw_notify("malconfigured bus\n");
925 return;
926 }
927 ohci->node_id = reg & (OHCI1394_NodeID_busNumber |
928 OHCI1394_NodeID_nodeNumber);
919 929
920 /* 930 /*
921 * The count in the SelfIDCount register is the number of 931 * The count in the SelfIDCount register is the number of
@@ -926,12 +936,14 @@ static void bus_reset_tasklet(unsigned long data)
926 936
927 self_id_count = (reg_read(ohci, OHCI1394_SelfIDCount) >> 3) & 0x3ff; 937 self_id_count = (reg_read(ohci, OHCI1394_SelfIDCount) >> 3) & 0x3ff;
928 generation = (le32_to_cpu(ohci->self_id_cpu[0]) >> 16) & 0xff; 938 generation = (le32_to_cpu(ohci->self_id_cpu[0]) >> 16) & 0xff;
939 rmb();
929 940
930 for (i = 1, j = 0; j < self_id_count; i += 2, j++) { 941 for (i = 1, j = 0; j < self_id_count; i += 2, j++) {
931 if (ohci->self_id_cpu[i] != ~ohci->self_id_cpu[i + 1]) 942 if (ohci->self_id_cpu[i] != ~ohci->self_id_cpu[i + 1])
932 fw_error("inconsistent self IDs\n"); 943 fw_error("inconsistent self IDs\n");
933 ohci->self_id_buffer[j] = le32_to_cpu(ohci->self_id_cpu[i]); 944 ohci->self_id_buffer[j] = le32_to_cpu(ohci->self_id_cpu[i]);
934 } 945 }
946 rmb();
935 947
936 /* 948 /*
937 * Check the consistency of the self IDs we just read. The 949 * Check the consistency of the self IDs we just read. The
@@ -1046,6 +1058,9 @@ static irqreturn_t irq_handler(int irq, void *data)
1046 iso_event &= ~(1 << i); 1058 iso_event &= ~(1 << i);
1047 } 1059 }
1048 1060
1061 if (unlikely(event & OHCI1394_postedWriteErr))
1062 fw_error("PCI posted write error\n");
1063
1049 if (event & OHCI1394_cycle64Seconds) { 1064 if (event & OHCI1394_cycle64Seconds) {
1050 cycle_time = reg_read(ohci, OHCI1394_IsochronousCycleTimer); 1065 cycle_time = reg_read(ohci, OHCI1394_IsochronousCycleTimer);
1051 if ((cycle_time & 0x80000000) == 0) 1066 if ((cycle_time & 0x80000000) == 0)
@@ -1119,8 +1134,8 @@ static int ohci_enable(struct fw_card *card, u32 *config_rom, size_t length)
1119 OHCI1394_RQPkt | OHCI1394_RSPkt | 1134 OHCI1394_RQPkt | OHCI1394_RSPkt |
1120 OHCI1394_reqTxComplete | OHCI1394_respTxComplete | 1135 OHCI1394_reqTxComplete | OHCI1394_respTxComplete |
1121 OHCI1394_isochRx | OHCI1394_isochTx | 1136 OHCI1394_isochRx | OHCI1394_isochTx |
1122 OHCI1394_masterIntEnable | 1137 OHCI1394_postedWriteErr | OHCI1394_cycle64Seconds |
1123 OHCI1394_cycle64Seconds); 1138 OHCI1394_masterIntEnable);
1124 1139
1125 /* Activate link_on bit and contender bit in our self ID packets.*/ 1140 /* Activate link_on bit and contender bit in our self ID packets.*/
1126 if (ohci_update_phy_reg(card, 4, 0, 1141 if (ohci_update_phy_reg(card, 4, 0,
diff --git a/drivers/firewire/fw-ohci.h b/drivers/firewire/fw-ohci.h
index fa15706397d7..dec4f04e6b24 100644
--- a/drivers/firewire/fw-ohci.h
+++ b/drivers/firewire/fw-ohci.h
@@ -59,6 +59,8 @@
59#define OHCI1394_LinkControl_cycleSource (1 << 22) 59#define OHCI1394_LinkControl_cycleSource (1 << 22)
60#define OHCI1394_NodeID 0x0E8 60#define OHCI1394_NodeID 0x0E8
61#define OHCI1394_NodeID_idValid 0x80000000 61#define OHCI1394_NodeID_idValid 0x80000000
62#define OHCI1394_NodeID_nodeNumber 0x0000003f
63#define OHCI1394_NodeID_busNumber 0x0000ffc0
62#define OHCI1394_PhyControl 0x0EC 64#define OHCI1394_PhyControl 0x0EC
63#define OHCI1394_PhyControl_Read(addr) (((addr) << 8) | 0x00008000) 65#define OHCI1394_PhyControl_Read(addr) (((addr) << 8) | 0x00008000)
64#define OHCI1394_PhyControl_ReadDone 0x80000000 66#define OHCI1394_PhyControl_ReadDone 0x80000000
diff --git a/drivers/firewire/fw-sbp2.c b/drivers/firewire/fw-sbp2.c
index 238730f75db1..5596df65c8ed 100644
--- a/drivers/firewire/fw-sbp2.c
+++ b/drivers/firewire/fw-sbp2.c
@@ -37,11 +37,12 @@
37#include <linux/dma-mapping.h> 37#include <linux/dma-mapping.h>
38#include <linux/blkdev.h> 38#include <linux/blkdev.h>
39#include <linux/string.h> 39#include <linux/string.h>
40#include <linux/stringify.h>
40#include <linux/timer.h> 41#include <linux/timer.h>
42#include <linux/workqueue.h>
41 43
42#include <scsi/scsi.h> 44#include <scsi/scsi.h>
43#include <scsi/scsi_cmnd.h> 45#include <scsi/scsi_cmnd.h>
44#include <scsi/scsi_dbg.h>
45#include <scsi/scsi_device.h> 46#include <scsi/scsi_device.h>
46#include <scsi/scsi_host.h> 47#include <scsi/scsi_host.h>
47 48
@@ -61,36 +62,94 @@ module_param_named(exclusive_login, sbp2_param_exclusive_login, bool, 0644);
61MODULE_PARM_DESC(exclusive_login, "Exclusive login to sbp2 device " 62MODULE_PARM_DESC(exclusive_login, "Exclusive login to sbp2 device "
62 "(default = Y, use N for concurrent initiators)"); 63 "(default = Y, use N for concurrent initiators)");
63 64
65/*
66 * Flags for firmware oddities
67 *
68 * - 128kB max transfer
69 * Limit transfer size. Necessary for some old bridges.
70 *
71 * - 36 byte inquiry
72 * When scsi_mod probes the device, let the inquiry command look like that
73 * from MS Windows.
74 *
75 * - skip mode page 8
76 * Suppress sending of mode_sense for mode page 8 if the device pretends to
77 * support the SCSI Primary Block commands instead of Reduced Block Commands.
78 *
79 * - fix capacity
80 * Tell sd_mod to correct the last sector number reported by read_capacity.
81 * Avoids access beyond actual disk limits on devices with an off-by-one bug.
82 * Don't use this with devices which don't have this bug.
83 *
84 * - override internal blacklist
85 * Instead of adding to the built-in blacklist, use only the workarounds
86 * specified in the module load parameter.
87 * Useful if a blacklist entry interfered with a non-broken device.
88 */
89#define SBP2_WORKAROUND_128K_MAX_TRANS 0x1
90#define SBP2_WORKAROUND_INQUIRY_36 0x2
91#define SBP2_WORKAROUND_MODE_SENSE_8 0x4
92#define SBP2_WORKAROUND_FIX_CAPACITY 0x8
93#define SBP2_WORKAROUND_OVERRIDE 0x100
94
95static int sbp2_param_workarounds;
96module_param_named(workarounds, sbp2_param_workarounds, int, 0644);
97MODULE_PARM_DESC(workarounds, "Work around device bugs (default = 0"
98 ", 128kB max transfer = " __stringify(SBP2_WORKAROUND_128K_MAX_TRANS)
99 ", 36 byte inquiry = " __stringify(SBP2_WORKAROUND_INQUIRY_36)
100 ", skip mode page 8 = " __stringify(SBP2_WORKAROUND_MODE_SENSE_8)
101 ", fix capacity = " __stringify(SBP2_WORKAROUND_FIX_CAPACITY)
102 ", override internal blacklist = " __stringify(SBP2_WORKAROUND_OVERRIDE)
103 ", or a combination)");
104
64/* I don't know why the SCSI stack doesn't define something like this... */ 105/* I don't know why the SCSI stack doesn't define something like this... */
65typedef void (*scsi_done_fn_t)(struct scsi_cmnd *); 106typedef void (*scsi_done_fn_t)(struct scsi_cmnd *);
66 107
67static const char sbp2_driver_name[] = "sbp2"; 108static const char sbp2_driver_name[] = "sbp2";
68 109
69struct sbp2_device { 110/*
70 struct kref kref; 111 * We create one struct sbp2_logical_unit per SBP-2 Logical Unit Number Entry
71 struct fw_unit *unit; 112 * and one struct scsi_device per sbp2_logical_unit.
113 */
114struct sbp2_logical_unit {
115 struct sbp2_target *tgt;
116 struct list_head link;
117 struct scsi_device *sdev;
72 struct fw_address_handler address_handler; 118 struct fw_address_handler address_handler;
73 struct list_head orb_list; 119 struct list_head orb_list;
74 u64 management_agent_address; 120
75 u64 command_block_agent_address; 121 u64 command_block_agent_address;
76 u32 workarounds; 122 u16 lun;
77 int login_id; 123 int login_id;
78 124
79 /* 125 /*
80 * We cache these addresses and only update them once we've 126 * The generation is updated once we've logged in or reconnected
81 * logged in or reconnected to the sbp2 device. That way, any 127 * to the logical unit. Thus, I/O to the device will automatically
82 * IO to the device will automatically fail and get retried if 128 * fail and get retried if it happens in a window where the device
83 * it happens in a window where the device is not ready to 129 * is not ready, e.g. after a bus reset but before we reconnect.
84 * handle it (e.g. after a bus reset but before we reconnect).
85 */ 130 */
86 int node_id;
87 int address_high;
88 int generation; 131 int generation;
89
90 int retries; 132 int retries;
91 struct delayed_work work; 133 struct delayed_work work;
92}; 134};
93 135
136/*
137 * We create one struct sbp2_target per IEEE 1212 Unit Directory
138 * and one struct Scsi_Host per sbp2_target.
139 */
140struct sbp2_target {
141 struct kref kref;
142 struct fw_unit *unit;
143
144 u64 management_agent_address;
145 int directory_id;
146 int node_id;
147 int address_high;
148
149 unsigned workarounds;
150 struct list_head lu_list;
151};
152
94#define SBP2_MAX_SG_ELEMENT_LENGTH 0xf000 153#define SBP2_MAX_SG_ELEMENT_LENGTH 0xf000
95#define SBP2_MAX_SECTORS 255 /* Max sectors supported */ 154#define SBP2_MAX_SECTORS 255 /* Max sectors supported */
96#define SBP2_ORB_TIMEOUT 2000 /* Timeout in ms */ 155#define SBP2_ORB_TIMEOUT 2000 /* Timeout in ms */
@@ -101,17 +160,9 @@ struct sbp2_device {
101#define SBP2_DIRECTION_FROM_MEDIA 0x1 160#define SBP2_DIRECTION_FROM_MEDIA 0x1
102 161
103/* Unit directory keys */ 162/* Unit directory keys */
104#define SBP2_COMMAND_SET_SPECIFIER 0x38 163#define SBP2_CSR_FIRMWARE_REVISION 0x3c
105#define SBP2_COMMAND_SET 0x39 164#define SBP2_CSR_LOGICAL_UNIT_NUMBER 0x14
106#define SBP2_COMMAND_SET_REVISION 0x3b 165#define SBP2_CSR_LOGICAL_UNIT_DIRECTORY 0xd4
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 166
116/* Management orb opcodes */ 167/* Management orb opcodes */
117#define SBP2_LOGIN_REQUEST 0x0 168#define SBP2_LOGIN_REQUEST 0x0
@@ -219,7 +270,7 @@ struct sbp2_command_orb {
219 } request; 270 } request;
220 struct scsi_cmnd *cmd; 271 struct scsi_cmnd *cmd;
221 scsi_done_fn_t done; 272 scsi_done_fn_t done;
222 struct fw_unit *unit; 273 struct sbp2_logical_unit *lu;
223 274
224 struct sbp2_pointer page_table[SG_ALL] __attribute__((aligned(8))); 275 struct sbp2_pointer page_table[SG_ALL] __attribute__((aligned(8)));
225 dma_addr_t page_table_bus; 276 dma_addr_t page_table_bus;
@@ -295,7 +346,7 @@ sbp2_status_write(struct fw_card *card, struct fw_request *request,
295 unsigned long long offset, 346 unsigned long long offset,
296 void *payload, size_t length, void *callback_data) 347 void *payload, size_t length, void *callback_data)
297{ 348{
298 struct sbp2_device *sd = callback_data; 349 struct sbp2_logical_unit *lu = callback_data;
299 struct sbp2_orb *orb; 350 struct sbp2_orb *orb;
300 struct sbp2_status status; 351 struct sbp2_status status;
301 size_t header_size; 352 size_t header_size;
@@ -319,7 +370,7 @@ sbp2_status_write(struct fw_card *card, struct fw_request *request,
319 370
320 /* Lookup the orb corresponding to this status write. */ 371 /* Lookup the orb corresponding to this status write. */
321 spin_lock_irqsave(&card->lock, flags); 372 spin_lock_irqsave(&card->lock, flags);
322 list_for_each_entry(orb, &sd->orb_list, link) { 373 list_for_each_entry(orb, &lu->orb_list, link) {
323 if (STATUS_GET_ORB_HIGH(status) == 0 && 374 if (STATUS_GET_ORB_HIGH(status) == 0 &&
324 STATUS_GET_ORB_LOW(status) == orb->request_bus) { 375 STATUS_GET_ORB_LOW(status) == orb->request_bus) {
325 orb->rcode = RCODE_COMPLETE; 376 orb->rcode = RCODE_COMPLETE;
@@ -329,7 +380,7 @@ sbp2_status_write(struct fw_card *card, struct fw_request *request,
329 } 380 }
330 spin_unlock_irqrestore(&card->lock, flags); 381 spin_unlock_irqrestore(&card->lock, flags);
331 382
332 if (&orb->link != &sd->orb_list) 383 if (&orb->link != &lu->orb_list)
333 orb->callback(orb, &status); 384 orb->callback(orb, &status);
334 else 385 else
335 fw_error("status write for unknown orb\n"); 386 fw_error("status write for unknown orb\n");
@@ -361,20 +412,20 @@ complete_transaction(struct fw_card *card, int rcode,
361 orb->rcode = rcode; 412 orb->rcode = rcode;
362 if (orb->rcode != RCODE_COMPLETE) { 413 if (orb->rcode != RCODE_COMPLETE) {
363 list_del(&orb->link); 414 list_del(&orb->link);
415 spin_unlock_irqrestore(&card->lock, flags);
364 orb->callback(orb, NULL); 416 orb->callback(orb, NULL);
417 } else {
418 spin_unlock_irqrestore(&card->lock, flags);
365 } 419 }
366 420
367 spin_unlock_irqrestore(&card->lock, flags);
368
369 kref_put(&orb->kref, free_orb); 421 kref_put(&orb->kref, free_orb);
370} 422}
371 423
372static void 424static void
373sbp2_send_orb(struct sbp2_orb *orb, struct fw_unit *unit, 425sbp2_send_orb(struct sbp2_orb *orb, struct sbp2_logical_unit *lu,
374 int node_id, int generation, u64 offset) 426 int node_id, int generation, u64 offset)
375{ 427{
376 struct fw_device *device = fw_device(unit->device.parent); 428 struct fw_device *device = fw_device(lu->tgt->unit->device.parent);
377 struct sbp2_device *sd = unit->device.driver_data;
378 unsigned long flags; 429 unsigned long flags;
379 430
380 orb->pointer.high = 0; 431 orb->pointer.high = 0;
@@ -382,7 +433,7 @@ sbp2_send_orb(struct sbp2_orb *orb, struct fw_unit *unit,
382 fw_memcpy_to_be32(&orb->pointer, &orb->pointer, sizeof(orb->pointer)); 433 fw_memcpy_to_be32(&orb->pointer, &orb->pointer, sizeof(orb->pointer));
383 434
384 spin_lock_irqsave(&device->card->lock, flags); 435 spin_lock_irqsave(&device->card->lock, flags);
385 list_add_tail(&orb->link, &sd->orb_list); 436 list_add_tail(&orb->link, &lu->orb_list);
386 spin_unlock_irqrestore(&device->card->lock, flags); 437 spin_unlock_irqrestore(&device->card->lock, flags);
387 438
388 /* Take a ref for the orb list and for the transaction callback. */ 439 /* Take a ref for the orb list and for the transaction callback. */
@@ -395,10 +446,9 @@ sbp2_send_orb(struct sbp2_orb *orb, struct fw_unit *unit,
395 complete_transaction, orb); 446 complete_transaction, orb);
396} 447}
397 448
398static int sbp2_cancel_orbs(struct fw_unit *unit) 449static int sbp2_cancel_orbs(struct sbp2_logical_unit *lu)
399{ 450{
400 struct fw_device *device = fw_device(unit->device.parent); 451 struct fw_device *device = fw_device(lu->tgt->unit->device.parent);
401 struct sbp2_device *sd = unit->device.driver_data;
402 struct sbp2_orb *orb, *next; 452 struct sbp2_orb *orb, *next;
403 struct list_head list; 453 struct list_head list;
404 unsigned long flags; 454 unsigned long flags;
@@ -406,7 +456,7 @@ static int sbp2_cancel_orbs(struct fw_unit *unit)
406 456
407 INIT_LIST_HEAD(&list); 457 INIT_LIST_HEAD(&list);
408 spin_lock_irqsave(&device->card->lock, flags); 458 spin_lock_irqsave(&device->card->lock, flags);
409 list_splice_init(&sd->orb_list, &list); 459 list_splice_init(&lu->orb_list, &list);
410 spin_unlock_irqrestore(&device->card->lock, flags); 460 spin_unlock_irqrestore(&device->card->lock, flags);
411 461
412 list_for_each_entry_safe(orb, next, &list, link) { 462 list_for_each_entry_safe(orb, next, &list, link) {
@@ -433,11 +483,11 @@ complete_management_orb(struct sbp2_orb *base_orb, struct sbp2_status *status)
433} 483}
434 484
435static int 485static int
436sbp2_send_management_orb(struct fw_unit *unit, int node_id, int generation, 486sbp2_send_management_orb(struct sbp2_logical_unit *lu, int node_id,
437 int function, int lun, void *response) 487 int generation, int function, int lun_or_login_id,
488 void *response)
438{ 489{
439 struct fw_device *device = fw_device(unit->device.parent); 490 struct fw_device *device = fw_device(lu->tgt->unit->device.parent);
440 struct sbp2_device *sd = unit->device.driver_data;
441 struct sbp2_management_orb *orb; 491 struct sbp2_management_orb *orb;
442 int retval = -ENOMEM; 492 int retval = -ENOMEM;
443 493
@@ -458,12 +508,12 @@ sbp2_send_management_orb(struct fw_unit *unit, int node_id, int generation,
458 orb->request.misc = 508 orb->request.misc =
459 MANAGEMENT_ORB_NOTIFY | 509 MANAGEMENT_ORB_NOTIFY |
460 MANAGEMENT_ORB_FUNCTION(function) | 510 MANAGEMENT_ORB_FUNCTION(function) |
461 MANAGEMENT_ORB_LUN(lun); 511 MANAGEMENT_ORB_LUN(lun_or_login_id);
462 orb->request.length = 512 orb->request.length =
463 MANAGEMENT_ORB_RESPONSE_LENGTH(sizeof(orb->response)); 513 MANAGEMENT_ORB_RESPONSE_LENGTH(sizeof(orb->response));
464 514
465 orb->request.status_fifo.high = sd->address_handler.offset >> 32; 515 orb->request.status_fifo.high = lu->address_handler.offset >> 32;
466 orb->request.status_fifo.low = sd->address_handler.offset; 516 orb->request.status_fifo.low = lu->address_handler.offset;
467 517
468 if (function == SBP2_LOGIN_REQUEST) { 518 if (function == SBP2_LOGIN_REQUEST) {
469 orb->request.misc |= 519 orb->request.misc |=
@@ -482,14 +532,14 @@ sbp2_send_management_orb(struct fw_unit *unit, int node_id, int generation,
482 if (dma_mapping_error(orb->base.request_bus)) 532 if (dma_mapping_error(orb->base.request_bus))
483 goto fail_mapping_request; 533 goto fail_mapping_request;
484 534
485 sbp2_send_orb(&orb->base, unit, 535 sbp2_send_orb(&orb->base, lu, node_id, generation,
486 node_id, generation, sd->management_agent_address); 536 lu->tgt->management_agent_address);
487 537
488 wait_for_completion_timeout(&orb->done, 538 wait_for_completion_timeout(&orb->done,
489 msecs_to_jiffies(SBP2_ORB_TIMEOUT)); 539 msecs_to_jiffies(SBP2_ORB_TIMEOUT));
490 540
491 retval = -EIO; 541 retval = -EIO;
492 if (sbp2_cancel_orbs(unit) == 0) { 542 if (sbp2_cancel_orbs(lu) == 0) {
493 fw_error("orb reply timed out, rcode=0x%02x\n", 543 fw_error("orb reply timed out, rcode=0x%02x\n",
494 orb->base.rcode); 544 orb->base.rcode);
495 goto out; 545 goto out;
@@ -534,10 +584,9 @@ complete_agent_reset_write(struct fw_card *card, int rcode,
534 kfree(t); 584 kfree(t);
535} 585}
536 586
537static int sbp2_agent_reset(struct fw_unit *unit) 587static int sbp2_agent_reset(struct sbp2_logical_unit *lu)
538{ 588{
539 struct fw_device *device = fw_device(unit->device.parent); 589 struct fw_device *device = fw_device(lu->tgt->unit->device.parent);
540 struct sbp2_device *sd = unit->device.driver_data;
541 struct fw_transaction *t; 590 struct fw_transaction *t;
542 static u32 zero; 591 static u32 zero;
543 592
@@ -546,181 +595,272 @@ static int sbp2_agent_reset(struct fw_unit *unit)
546 return -ENOMEM; 595 return -ENOMEM;
547 596
548 fw_send_request(device->card, t, TCODE_WRITE_QUADLET_REQUEST, 597 fw_send_request(device->card, t, TCODE_WRITE_QUADLET_REQUEST,
549 sd->node_id, sd->generation, device->max_speed, 598 lu->tgt->node_id, lu->generation, device->max_speed,
550 sd->command_block_agent_address + SBP2_AGENT_RESET, 599 lu->command_block_agent_address + SBP2_AGENT_RESET,
551 &zero, sizeof(zero), complete_agent_reset_write, t); 600 &zero, sizeof(zero), complete_agent_reset_write, t);
552 601
553 return 0; 602 return 0;
554} 603}
555 604
556static void sbp2_reconnect(struct work_struct *work); 605static void sbp2_release_target(struct kref *kref)
557static struct scsi_host_template scsi_driver_template;
558
559static void release_sbp2_device(struct kref *kref)
560{ 606{
561 struct sbp2_device *sd = container_of(kref, struct sbp2_device, kref); 607 struct sbp2_target *tgt = container_of(kref, struct sbp2_target, kref);
562 struct Scsi_Host *host = 608 struct sbp2_logical_unit *lu, *next;
563 container_of((void *)sd, struct Scsi_Host, hostdata[0]); 609 struct Scsi_Host *shost =
564 610 container_of((void *)tgt, struct Scsi_Host, hostdata[0]);
565 scsi_remove_host(host); 611
566 sbp2_send_management_orb(sd->unit, sd->node_id, sd->generation, 612 list_for_each_entry_safe(lu, next, &tgt->lu_list, link) {
567 SBP2_LOGOUT_REQUEST, sd->login_id, NULL); 613 if (lu->sdev)
568 fw_core_remove_address_handler(&sd->address_handler); 614 scsi_remove_device(lu->sdev);
569 fw_notify("removed sbp2 unit %s\n", sd->unit->device.bus_id); 615
570 put_device(&sd->unit->device); 616 sbp2_send_management_orb(lu, tgt->node_id, lu->generation,
571 scsi_host_put(host); 617 SBP2_LOGOUT_REQUEST, lu->login_id, NULL);
618 fw_core_remove_address_handler(&lu->address_handler);
619 list_del(&lu->link);
620 kfree(lu);
621 }
622 scsi_remove_host(shost);
623 fw_notify("released %s\n", tgt->unit->device.bus_id);
624
625 put_device(&tgt->unit->device);
626 scsi_host_put(shost);
572} 627}
573 628
629static struct workqueue_struct *sbp2_wq;
630
631static void sbp2_reconnect(struct work_struct *work);
632
574static void sbp2_login(struct work_struct *work) 633static void sbp2_login(struct work_struct *work)
575{ 634{
576 struct sbp2_device *sd = 635 struct sbp2_logical_unit *lu =
577 container_of(work, struct sbp2_device, work.work); 636 container_of(work, struct sbp2_logical_unit, work.work);
578 struct Scsi_Host *host = 637 struct Scsi_Host *shost =
579 container_of((void *)sd, struct Scsi_Host, hostdata[0]); 638 container_of((void *)lu->tgt, struct Scsi_Host, hostdata[0]);
580 struct fw_unit *unit = sd->unit; 639 struct scsi_device *sdev;
640 struct scsi_lun eight_bytes_lun;
641 struct fw_unit *unit = lu->tgt->unit;
581 struct fw_device *device = fw_device(unit->device.parent); 642 struct fw_device *device = fw_device(unit->device.parent);
582 struct sbp2_login_response response; 643 struct sbp2_login_response response;
583 int generation, node_id, local_node_id, lun, retval; 644 int generation, node_id, local_node_id;
584
585 /* FIXME: Make this work for multi-lun devices. */
586 lun = 0;
587 645
588 generation = device->card->generation; 646 generation = device->card->generation;
589 node_id = device->node->node_id; 647 node_id = device->node->node_id;
590 local_node_id = device->card->local_node->node_id; 648 local_node_id = device->card->local_node->node_id;
591 649
592 if (sbp2_send_management_orb(unit, node_id, generation, 650 if (sbp2_send_management_orb(lu, node_id, generation,
593 SBP2_LOGIN_REQUEST, lun, &response) < 0) { 651 SBP2_LOGIN_REQUEST, lu->lun, &response) < 0) {
594 if (sd->retries++ < 5) { 652 if (lu->retries++ < 5) {
595 schedule_delayed_work(&sd->work, DIV_ROUND_UP(HZ, 5)); 653 queue_delayed_work(sbp2_wq, &lu->work,
654 DIV_ROUND_UP(HZ, 5));
596 } else { 655 } else {
597 fw_error("failed to login to %s\n", 656 fw_error("failed to login to %s LUN %04x\n",
598 unit->device.bus_id); 657 unit->device.bus_id, lu->lun);
599 kref_put(&sd->kref, release_sbp2_device); 658 kref_put(&lu->tgt->kref, sbp2_release_target);
600 } 659 }
601 return; 660 return;
602 } 661 }
603 662
604 sd->generation = generation; 663 lu->generation = generation;
605 sd->node_id = node_id; 664 lu->tgt->node_id = node_id;
606 sd->address_high = local_node_id << 16; 665 lu->tgt->address_high = local_node_id << 16;
607 666
608 /* Get command block agent offset and login id. */ 667 /* Get command block agent offset and login id. */
609 sd->command_block_agent_address = 668 lu->command_block_agent_address =
610 ((u64) (response.command_block_agent.high & 0xffff) << 32) | 669 ((u64) (response.command_block_agent.high & 0xffff) << 32) |
611 response.command_block_agent.low; 670 response.command_block_agent.low;
612 sd->login_id = LOGIN_RESPONSE_GET_LOGIN_ID(response); 671 lu->login_id = LOGIN_RESPONSE_GET_LOGIN_ID(response);
613 672
614 fw_notify("logged in to sbp2 unit %s (%d retries)\n", 673 fw_notify("logged in to %s LUN %04x (%d retries)\n",
615 unit->device.bus_id, sd->retries); 674 unit->device.bus_id, lu->lun, lu->retries);
616 fw_notify(" - management_agent_address: 0x%012llx\n",
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);
620 fw_notify(" - status write address: 0x%012llx\n",
621 (unsigned long long) sd->address_handler.offset);
622 675
623#if 0 676#if 0
624 /* FIXME: The linux1394 sbp2 does this last step. */ 677 /* FIXME: The linux1394 sbp2 does this last step. */
625 sbp2_set_busy_timeout(scsi_id); 678 sbp2_set_busy_timeout(scsi_id);
626#endif 679#endif
627 680
628 PREPARE_DELAYED_WORK(&sd->work, sbp2_reconnect); 681 PREPARE_DELAYED_WORK(&lu->work, sbp2_reconnect);
629 sbp2_agent_reset(unit); 682 sbp2_agent_reset(lu);
683
684 memset(&eight_bytes_lun, 0, sizeof(eight_bytes_lun));
685 eight_bytes_lun.scsi_lun[0] = (lu->lun >> 8) & 0xff;
686 eight_bytes_lun.scsi_lun[1] = lu->lun & 0xff;
630 687
631 /* FIXME: Loop over luns here. */ 688 sdev = __scsi_add_device(shost, 0, 0,
632 lun = 0; 689 scsilun_to_int(&eight_bytes_lun), lu);
633 retval = scsi_add_device(host, 0, 0, lun); 690 if (IS_ERR(sdev)) {
634 if (retval < 0) { 691 sbp2_send_management_orb(lu, node_id, generation,
635 sbp2_send_management_orb(unit, sd->node_id, sd->generation, 692 SBP2_LOGOUT_REQUEST, lu->login_id, NULL);
636 SBP2_LOGOUT_REQUEST, sd->login_id,
637 NULL);
638 /* 693 /*
639 * Set this back to sbp2_login so we fall back and 694 * Set this back to sbp2_login so we fall back and
640 * retry login on bus reset. 695 * retry login on bus reset.
641 */ 696 */
642 PREPARE_DELAYED_WORK(&sd->work, sbp2_login); 697 PREPARE_DELAYED_WORK(&lu->work, sbp2_login);
698 } else {
699 lu->sdev = sdev;
700 scsi_device_put(sdev);
643 } 701 }
644 kref_put(&sd->kref, release_sbp2_device); 702 kref_put(&lu->tgt->kref, sbp2_release_target);
645} 703}
646 704
647static int sbp2_probe(struct device *dev) 705static int sbp2_add_logical_unit(struct sbp2_target *tgt, int lun_entry)
648{ 706{
649 struct fw_unit *unit = fw_unit(dev); 707 struct sbp2_logical_unit *lu;
650 struct fw_device *device = fw_device(unit->device.parent);
651 struct sbp2_device *sd;
652 struct fw_csr_iterator ci;
653 struct Scsi_Host *host;
654 int i, key, value, err;
655 u32 model, firmware_revision;
656 708
657 err = -ENOMEM; 709 lu = kmalloc(sizeof(*lu), GFP_KERNEL);
658 host = scsi_host_alloc(&scsi_driver_template, sizeof(*sd)); 710 if (!lu)
659 if (host == NULL) 711 return -ENOMEM;
660 goto fail;
661 712
662 sd = (struct sbp2_device *) host->hostdata; 713 lu->address_handler.length = 0x100;
663 unit->device.driver_data = sd; 714 lu->address_handler.address_callback = sbp2_status_write;
664 sd->unit = unit; 715 lu->address_handler.callback_data = lu;
665 INIT_LIST_HEAD(&sd->orb_list);
666 kref_init(&sd->kref);
667 716
668 sd->address_handler.length = 0x100; 717 if (fw_core_add_address_handler(&lu->address_handler,
669 sd->address_handler.address_callback = sbp2_status_write; 718 &fw_high_memory_region) < 0) {
670 sd->address_handler.callback_data = sd; 719 kfree(lu);
720 return -ENOMEM;
721 }
671 722
672 err = fw_core_add_address_handler(&sd->address_handler, 723 lu->tgt = tgt;
673 &fw_high_memory_region); 724 lu->sdev = NULL;
674 if (err < 0) 725 lu->lun = lun_entry & 0xffff;
675 goto fail_host; 726 lu->retries = 0;
727 INIT_LIST_HEAD(&lu->orb_list);
728 INIT_DELAYED_WORK(&lu->work, sbp2_login);
676 729
677 err = fw_device_enable_phys_dma(device); 730 list_add_tail(&lu->link, &tgt->lu_list);
678 if (err < 0) 731 return 0;
679 goto fail_address_handler; 732}
680 733
681 err = scsi_add_host(host, &unit->device); 734static int sbp2_scan_logical_unit_dir(struct sbp2_target *tgt, u32 *directory)
682 if (err < 0) 735{
683 goto fail_address_handler; 736 struct fw_csr_iterator ci;
737 int key, value;
684 738
685 /* 739 fw_csr_iterator_init(&ci, directory);
686 * Scan unit directory to get management agent address, 740 while (fw_csr_iterator_next(&ci, &key, &value))
687 * firmware revison and model. Initialize firmware_revision 741 if (key == SBP2_CSR_LOGICAL_UNIT_NUMBER &&
688 * and model to values that wont match anything in our table. 742 sbp2_add_logical_unit(tgt, value) < 0)
689 */ 743 return -ENOMEM;
690 firmware_revision = 0xff000000; 744 return 0;
691 model = 0xff000000; 745}
692 fw_csr_iterator_init(&ci, unit->directory); 746
747static int sbp2_scan_unit_dir(struct sbp2_target *tgt, u32 *directory,
748 u32 *model, u32 *firmware_revision)
749{
750 struct fw_csr_iterator ci;
751 int key, value;
752
753 fw_csr_iterator_init(&ci, directory);
693 while (fw_csr_iterator_next(&ci, &key, &value)) { 754 while (fw_csr_iterator_next(&ci, &key, &value)) {
694 switch (key) { 755 switch (key) {
756
695 case CSR_DEPENDENT_INFO | CSR_OFFSET: 757 case CSR_DEPENDENT_INFO | CSR_OFFSET:
696 sd->management_agent_address = 758 tgt->management_agent_address =
697 0xfffff0000000ULL + 4 * value; 759 CSR_REGISTER_BASE + 4 * value;
698 break; 760 break;
699 case SBP2_FIRMWARE_REVISION: 761
700 firmware_revision = value; 762 case CSR_DIRECTORY_ID:
763 tgt->directory_id = value;
701 break; 764 break;
765
702 case CSR_MODEL: 766 case CSR_MODEL:
703 model = value; 767 *model = value;
768 break;
769
770 case SBP2_CSR_FIRMWARE_REVISION:
771 *firmware_revision = value;
772 break;
773
774 case SBP2_CSR_LOGICAL_UNIT_NUMBER:
775 if (sbp2_add_logical_unit(tgt, value) < 0)
776 return -ENOMEM;
777 break;
778
779 case SBP2_CSR_LOGICAL_UNIT_DIRECTORY:
780 if (sbp2_scan_logical_unit_dir(tgt, ci.p + value) < 0)
781 return -ENOMEM;
704 break; 782 break;
705 } 783 }
706 } 784 }
785 return 0;
786}
787
788static void sbp2_init_workarounds(struct sbp2_target *tgt, u32 model,
789 u32 firmware_revision)
790{
791 int i;
792 unsigned w = sbp2_param_workarounds;
793
794 if (w)
795 fw_notify("Please notify linux1394-devel@lists.sourceforge.net "
796 "if you need the workarounds parameter for %s\n",
797 tgt->unit->device.bus_id);
798
799 if (w & SBP2_WORKAROUND_OVERRIDE)
800 goto out;
707 801
708 for (i = 0; i < ARRAY_SIZE(sbp2_workarounds_table); i++) { 802 for (i = 0; i < ARRAY_SIZE(sbp2_workarounds_table); i++) {
803
709 if (sbp2_workarounds_table[i].firmware_revision != 804 if (sbp2_workarounds_table[i].firmware_revision !=
710 (firmware_revision & 0xffffff00)) 805 (firmware_revision & 0xffffff00))
711 continue; 806 continue;
807
712 if (sbp2_workarounds_table[i].model != model && 808 if (sbp2_workarounds_table[i].model != model &&
713 sbp2_workarounds_table[i].model != ~0) 809 sbp2_workarounds_table[i].model != ~0)
714 continue; 810 continue;
715 sd->workarounds |= sbp2_workarounds_table[i].workarounds; 811
812 w |= sbp2_workarounds_table[i].workarounds;
716 break; 813 break;
717 } 814 }
718 815 out:
719 if (sd->workarounds) 816 if (w)
720 fw_notify("Workarounds for node %s: 0x%x " 817 fw_notify("Workarounds for %s: 0x%x "
721 "(firmware_revision 0x%06x, model_id 0x%06x)\n", 818 "(firmware_revision 0x%06x, model_id 0x%06x)\n",
722 unit->device.bus_id, 819 tgt->unit->device.bus_id,
723 sd->workarounds, firmware_revision, model); 820 w, firmware_revision, model);
821 tgt->workarounds = w;
822}
823
824static struct scsi_host_template scsi_driver_template;
825
826static int sbp2_probe(struct device *dev)
827{
828 struct fw_unit *unit = fw_unit(dev);
829 struct fw_device *device = fw_device(unit->device.parent);
830 struct sbp2_target *tgt;
831 struct sbp2_logical_unit *lu;
832 struct Scsi_Host *shost;
833 u32 model, firmware_revision;
834
835 shost = scsi_host_alloc(&scsi_driver_template, sizeof(*tgt));
836 if (shost == NULL)
837 return -ENOMEM;
838
839 tgt = (struct sbp2_target *)shost->hostdata;
840 unit->device.driver_data = tgt;
841 tgt->unit = unit;
842 kref_init(&tgt->kref);
843 INIT_LIST_HEAD(&tgt->lu_list);
844
845 if (fw_device_enable_phys_dma(device) < 0)
846 goto fail_shost_put;
847
848 if (scsi_add_host(shost, &unit->device) < 0)
849 goto fail_shost_put;
850
851 /* Initialize to values that won't match anything in our table. */
852 firmware_revision = 0xff000000;
853 model = 0xff000000;
854
855 /* implicit directory ID */
856 tgt->directory_id = ((unit->directory - device->config_rom) * 4
857 + CSR_CONFIG_ROM) & 0xffffff;
858
859 if (sbp2_scan_unit_dir(tgt, unit->directory, &model,
860 &firmware_revision) < 0)
861 goto fail_tgt_put;
862
863 sbp2_init_workarounds(tgt, model, firmware_revision);
724 864
725 get_device(&unit->device); 865 get_device(&unit->device);
726 866
@@ -729,35 +869,34 @@ static int sbp2_probe(struct device *dev)
729 * reschedule retries. Always get the ref before scheduling 869 * reschedule retries. Always get the ref before scheduling
730 * work. 870 * work.
731 */ 871 */
732 INIT_DELAYED_WORK(&sd->work, sbp2_login); 872 list_for_each_entry(lu, &tgt->lu_list, link)
733 if (schedule_delayed_work(&sd->work, 0)) 873 if (queue_delayed_work(sbp2_wq, &lu->work, 0))
734 kref_get(&sd->kref); 874 kref_get(&tgt->kref);
735
736 return 0; 875 return 0;
737 876
738 fail_address_handler: 877 fail_tgt_put:
739 fw_core_remove_address_handler(&sd->address_handler); 878 kref_put(&tgt->kref, sbp2_release_target);
740 fail_host: 879 return -ENOMEM;
741 scsi_host_put(host); 880
742 fail: 881 fail_shost_put:
743 return err; 882 scsi_host_put(shost);
883 return -ENOMEM;
744} 884}
745 885
746static int sbp2_remove(struct device *dev) 886static int sbp2_remove(struct device *dev)
747{ 887{
748 struct fw_unit *unit = fw_unit(dev); 888 struct fw_unit *unit = fw_unit(dev);
749 struct sbp2_device *sd = unit->device.driver_data; 889 struct sbp2_target *tgt = unit->device.driver_data;
750
751 kref_put(&sd->kref, release_sbp2_device);
752 890
891 kref_put(&tgt->kref, sbp2_release_target);
753 return 0; 892 return 0;
754} 893}
755 894
756static void sbp2_reconnect(struct work_struct *work) 895static void sbp2_reconnect(struct work_struct *work)
757{ 896{
758 struct sbp2_device *sd = 897 struct sbp2_logical_unit *lu =
759 container_of(work, struct sbp2_device, work.work); 898 container_of(work, struct sbp2_logical_unit, work.work);
760 struct fw_unit *unit = sd->unit; 899 struct fw_unit *unit = lu->tgt->unit;
761 struct fw_device *device = fw_device(unit->device.parent); 900 struct fw_device *device = fw_device(unit->device.parent);
762 int generation, node_id, local_node_id; 901 int generation, node_id, local_node_id;
763 902
@@ -765,40 +904,49 @@ static void sbp2_reconnect(struct work_struct *work)
765 node_id = device->node->node_id; 904 node_id = device->node->node_id;
766 local_node_id = device->card->local_node->node_id; 905 local_node_id = device->card->local_node->node_id;
767 906
768 if (sbp2_send_management_orb(unit, node_id, generation, 907 if (sbp2_send_management_orb(lu, node_id, generation,
769 SBP2_RECONNECT_REQUEST, 908 SBP2_RECONNECT_REQUEST,
770 sd->login_id, NULL) < 0) { 909 lu->login_id, NULL) < 0) {
771 if (sd->retries++ >= 5) { 910 if (lu->retries++ >= 5) {
772 fw_error("failed to reconnect to %s\n", 911 fw_error("failed to reconnect to %s\n",
773 unit->device.bus_id); 912 unit->device.bus_id);
774 /* Fall back and try to log in again. */ 913 /* Fall back and try to log in again. */
775 sd->retries = 0; 914 lu->retries = 0;
776 PREPARE_DELAYED_WORK(&sd->work, sbp2_login); 915 PREPARE_DELAYED_WORK(&lu->work, sbp2_login);
777 } 916 }
778 schedule_delayed_work(&sd->work, DIV_ROUND_UP(HZ, 5)); 917 queue_delayed_work(sbp2_wq, &lu->work, DIV_ROUND_UP(HZ, 5));
779 return; 918 return;
780 } 919 }
781 920
782 sd->generation = generation; 921 lu->generation = generation;
783 sd->node_id = node_id; 922 lu->tgt->node_id = node_id;
784 sd->address_high = local_node_id << 16; 923 lu->tgt->address_high = local_node_id << 16;
785 924
786 fw_notify("reconnected to unit %s (%d retries)\n", 925 fw_notify("reconnected to %s LUN %04x (%d retries)\n",
787 unit->device.bus_id, sd->retries); 926 unit->device.bus_id, lu->lun, lu->retries);
788 sbp2_agent_reset(unit); 927
789 sbp2_cancel_orbs(unit); 928 sbp2_agent_reset(lu);
790 kref_put(&sd->kref, release_sbp2_device); 929 sbp2_cancel_orbs(lu);
930
931 kref_put(&lu->tgt->kref, sbp2_release_target);
791} 932}
792 933
793static void sbp2_update(struct fw_unit *unit) 934static void sbp2_update(struct fw_unit *unit)
794{ 935{
795 struct fw_device *device = fw_device(unit->device.parent); 936 struct sbp2_target *tgt = unit->device.driver_data;
796 struct sbp2_device *sd = unit->device.driver_data; 937 struct sbp2_logical_unit *lu;
797 938
798 sd->retries = 0; 939 fw_device_enable_phys_dma(fw_device(unit->device.parent));
799 fw_device_enable_phys_dma(device); 940
800 if (schedule_delayed_work(&sd->work, 0)) 941 /*
801 kref_get(&sd->kref); 942 * Fw-core serializes sbp2_update() against sbp2_remove().
943 * Iteration over tgt->lu_list is therefore safe here.
944 */
945 list_for_each_entry(lu, &tgt->lu_list, link) {
946 lu->retries = 0;
947 if (queue_delayed_work(sbp2_wq, &lu->work, 0))
948 kref_get(&tgt->kref);
949 }
802} 950}
803 951
804#define SBP2_UNIT_SPEC_ID_ENTRY 0x0000609e 952#define SBP2_UNIT_SPEC_ID_ENTRY 0x0000609e
@@ -868,13 +1016,12 @@ complete_command_orb(struct sbp2_orb *base_orb, struct sbp2_status *status)
868{ 1016{
869 struct sbp2_command_orb *orb = 1017 struct sbp2_command_orb *orb =
870 container_of(base_orb, struct sbp2_command_orb, base); 1018 container_of(base_orb, struct sbp2_command_orb, base);
871 struct fw_unit *unit = orb->unit; 1019 struct fw_device *device = fw_device(orb->lu->tgt->unit->device.parent);
872 struct fw_device *device = fw_device(unit->device.parent);
873 int result; 1020 int result;
874 1021
875 if (status != NULL) { 1022 if (status != NULL) {
876 if (STATUS_GET_DEAD(*status)) 1023 if (STATUS_GET_DEAD(*status))
877 sbp2_agent_reset(unit); 1024 sbp2_agent_reset(orb->lu);
878 1025
879 switch (STATUS_GET_RESPONSE(*status)) { 1026 switch (STATUS_GET_RESPONSE(*status)) {
880 case SBP2_STATUS_REQUEST_COMPLETE: 1027 case SBP2_STATUS_REQUEST_COMPLETE:
@@ -918,12 +1065,10 @@ complete_command_orb(struct sbp2_orb *base_orb, struct sbp2_status *status)
918 orb->done(orb->cmd); 1065 orb->done(orb->cmd);
919} 1066}
920 1067
921static int sbp2_command_orb_map_scatterlist(struct sbp2_command_orb *orb) 1068static int
1069sbp2_map_scatterlist(struct sbp2_command_orb *orb, struct fw_device *device,
1070 struct sbp2_logical_unit *lu)
922{ 1071{
923 struct sbp2_device *sd =
924 (struct sbp2_device *)orb->cmd->device->host->hostdata;
925 struct fw_unit *unit = sd->unit;
926 struct fw_device *device = fw_device(unit->device.parent);
927 struct scatterlist *sg; 1072 struct scatterlist *sg;
928 int sg_len, l, i, j, count; 1073 int sg_len, l, i, j, count;
929 dma_addr_t sg_addr; 1074 dma_addr_t sg_addr;
@@ -942,10 +1087,9 @@ static int sbp2_command_orb_map_scatterlist(struct sbp2_command_orb *orb)
942 * tables. 1087 * tables.
943 */ 1088 */
944 if (count == 1 && sg_dma_len(sg) < SBP2_MAX_SG_ELEMENT_LENGTH) { 1089 if (count == 1 && sg_dma_len(sg) < SBP2_MAX_SG_ELEMENT_LENGTH) {
945 orb->request.data_descriptor.high = sd->address_high; 1090 orb->request.data_descriptor.high = lu->tgt->address_high;
946 orb->request.data_descriptor.low = sg_dma_address(sg); 1091 orb->request.data_descriptor.low = sg_dma_address(sg);
947 orb->request.misc |= 1092 orb->request.misc |= COMMAND_ORB_DATA_SIZE(sg_dma_len(sg));
948 COMMAND_ORB_DATA_SIZE(sg_dma_len(sg));
949 return 0; 1093 return 0;
950 } 1094 }
951 1095
@@ -989,7 +1133,7 @@ static int sbp2_command_orb_map_scatterlist(struct sbp2_command_orb *orb)
989 * initiator (i.e. us), but data_descriptor can refer to data 1133 * initiator (i.e. us), but data_descriptor can refer to data
990 * on other nodes so we need to put our ID in descriptor.high. 1134 * on other nodes so we need to put our ID in descriptor.high.
991 */ 1135 */
992 orb->request.data_descriptor.high = sd->address_high; 1136 orb->request.data_descriptor.high = lu->tgt->address_high;
993 orb->request.data_descriptor.low = orb->page_table_bus; 1137 orb->request.data_descriptor.low = orb->page_table_bus;
994 orb->request.misc |= 1138 orb->request.misc |=
995 COMMAND_ORB_PAGE_TABLE_PRESENT | 1139 COMMAND_ORB_PAGE_TABLE_PRESENT |
@@ -1008,12 +1152,11 @@ static int sbp2_command_orb_map_scatterlist(struct sbp2_command_orb *orb)
1008 1152
1009static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done) 1153static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done)
1010{ 1154{
1011 struct sbp2_device *sd = 1155 struct sbp2_logical_unit *lu = cmd->device->hostdata;
1012 (struct sbp2_device *)cmd->device->host->hostdata; 1156 struct fw_device *device = fw_device(lu->tgt->unit->device.parent);
1013 struct fw_unit *unit = sd->unit;
1014 struct fw_device *device = fw_device(unit->device.parent);
1015 struct sbp2_command_orb *orb; 1157 struct sbp2_command_orb *orb;
1016 unsigned max_payload; 1158 unsigned max_payload;
1159 int retval = SCSI_MLQUEUE_HOST_BUSY;
1017 1160
1018 /* 1161 /*
1019 * Bidirectional commands are not yet implemented, and unknown 1162 * Bidirectional commands are not yet implemented, and unknown
@@ -1029,14 +1172,14 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done)
1029 orb = kzalloc(sizeof(*orb), GFP_ATOMIC); 1172 orb = kzalloc(sizeof(*orb), GFP_ATOMIC);
1030 if (orb == NULL) { 1173 if (orb == NULL) {
1031 fw_notify("failed to alloc orb\n"); 1174 fw_notify("failed to alloc orb\n");
1032 goto fail_alloc; 1175 return SCSI_MLQUEUE_HOST_BUSY;
1033 } 1176 }
1034 1177
1035 /* Initialize rcode to something not RCODE_COMPLETE. */ 1178 /* Initialize rcode to something not RCODE_COMPLETE. */
1036 orb->base.rcode = -1; 1179 orb->base.rcode = -1;
1037 kref_init(&orb->base.kref); 1180 kref_init(&orb->base.kref);
1038 1181
1039 orb->unit = unit; 1182 orb->lu = lu;
1040 orb->done = done; 1183 orb->done = done;
1041 orb->cmd = cmd; 1184 orb->cmd = cmd;
1042 1185
@@ -1062,8 +1205,8 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done)
1062 orb->request.misc |= 1205 orb->request.misc |=
1063 COMMAND_ORB_DIRECTION(SBP2_DIRECTION_TO_MEDIA); 1206 COMMAND_ORB_DIRECTION(SBP2_DIRECTION_TO_MEDIA);
1064 1207
1065 if (scsi_sg_count(cmd) && sbp2_command_orb_map_scatterlist(orb) < 0) 1208 if (scsi_sg_count(cmd) && sbp2_map_scatterlist(orb, device, lu) < 0)
1066 goto fail_mapping; 1209 goto out;
1067 1210
1068 fw_memcpy_to_be32(&orb->request, &orb->request, sizeof(orb->request)); 1211 fw_memcpy_to_be32(&orb->request, &orb->request, sizeof(orb->request));
1069 1212
@@ -1076,49 +1219,47 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done)
1076 dma_map_single(device->card->device, &orb->request, 1219 dma_map_single(device->card->device, &orb->request,
1077 sizeof(orb->request), DMA_TO_DEVICE); 1220 sizeof(orb->request), DMA_TO_DEVICE);
1078 if (dma_mapping_error(orb->base.request_bus)) 1221 if (dma_mapping_error(orb->base.request_bus))
1079 goto fail_mapping; 1222 goto out;
1080
1081 sbp2_send_orb(&orb->base, unit, sd->node_id, sd->generation,
1082 sd->command_block_agent_address + SBP2_ORB_POINTER);
1083
1084 kref_put(&orb->base.kref, free_orb);
1085 return 0;
1086 1223
1087 fail_mapping: 1224 sbp2_send_orb(&orb->base, lu, lu->tgt->node_id, lu->generation,
1225 lu->command_block_agent_address + SBP2_ORB_POINTER);
1226 retval = 0;
1227 out:
1088 kref_put(&orb->base.kref, free_orb); 1228 kref_put(&orb->base.kref, free_orb);
1089 fail_alloc: 1229 return retval;
1090 return SCSI_MLQUEUE_HOST_BUSY;
1091} 1230}
1092 1231
1093static int sbp2_scsi_slave_alloc(struct scsi_device *sdev) 1232static int sbp2_scsi_slave_alloc(struct scsi_device *sdev)
1094{ 1233{
1095 struct sbp2_device *sd = (struct sbp2_device *)sdev->host->hostdata; 1234 struct sbp2_logical_unit *lu = sdev->hostdata;
1096 1235
1097 sdev->allow_restart = 1; 1236 sdev->allow_restart = 1;
1098 1237
1099 if (sd->workarounds & SBP2_WORKAROUND_INQUIRY_36) 1238 if (lu->tgt->workarounds & SBP2_WORKAROUND_INQUIRY_36)
1100 sdev->inquiry_len = 36; 1239 sdev->inquiry_len = 36;
1240
1101 return 0; 1241 return 0;
1102} 1242}
1103 1243
1104static int sbp2_scsi_slave_configure(struct scsi_device *sdev) 1244static int sbp2_scsi_slave_configure(struct scsi_device *sdev)
1105{ 1245{
1106 struct sbp2_device *sd = (struct sbp2_device *)sdev->host->hostdata; 1246 struct sbp2_logical_unit *lu = sdev->hostdata;
1107 struct fw_unit *unit = sd->unit;
1108 1247
1109 sdev->use_10_for_rw = 1; 1248 sdev->use_10_for_rw = 1;
1110 1249
1111 if (sdev->type == TYPE_ROM) 1250 if (sdev->type == TYPE_ROM)
1112 sdev->use_10_for_ms = 1; 1251 sdev->use_10_for_ms = 1;
1252
1113 if (sdev->type == TYPE_DISK && 1253 if (sdev->type == TYPE_DISK &&
1114 sd->workarounds & SBP2_WORKAROUND_MODE_SENSE_8) 1254 lu->tgt->workarounds & SBP2_WORKAROUND_MODE_SENSE_8)
1115 sdev->skip_ms_page_8 = 1; 1255 sdev->skip_ms_page_8 = 1;
1116 if (sd->workarounds & SBP2_WORKAROUND_FIX_CAPACITY) { 1256
1117 fw_notify("setting fix_capacity for %s\n", unit->device.bus_id); 1257 if (lu->tgt->workarounds & SBP2_WORKAROUND_FIX_CAPACITY)
1118 sdev->fix_capacity = 1; 1258 sdev->fix_capacity = 1;
1119 } 1259
1120 if (sd->workarounds & SBP2_WORKAROUND_128K_MAX_TRANS) 1260 if (lu->tgt->workarounds & SBP2_WORKAROUND_128K_MAX_TRANS)
1121 blk_queue_max_sectors(sdev->request_queue, 128 * 1024 / 512); 1261 blk_queue_max_sectors(sdev->request_queue, 128 * 1024 / 512);
1262
1122 return 0; 1263 return 0;
1123} 1264}
1124 1265
@@ -1128,13 +1269,11 @@ static int sbp2_scsi_slave_configure(struct scsi_device *sdev)
1128 */ 1269 */
1129static int sbp2_scsi_abort(struct scsi_cmnd *cmd) 1270static int sbp2_scsi_abort(struct scsi_cmnd *cmd)
1130{ 1271{
1131 struct sbp2_device *sd = 1272 struct sbp2_logical_unit *lu = cmd->device->hostdata;
1132 (struct sbp2_device *)cmd->device->host->hostdata;
1133 struct fw_unit *unit = sd->unit;
1134 1273
1135 fw_notify("sbp2_scsi_abort\n"); 1274 fw_notify("sbp2_scsi_abort\n");
1136 sbp2_agent_reset(unit); 1275 sbp2_agent_reset(lu);
1137 sbp2_cancel_orbs(unit); 1276 sbp2_cancel_orbs(lu);
1138 1277
1139 return SUCCESS; 1278 return SUCCESS;
1140} 1279}
@@ -1151,37 +1290,18 @@ sbp2_sysfs_ieee1394_id_show(struct device *dev, struct device_attribute *attr,
1151 char *buf) 1290 char *buf)
1152{ 1291{
1153 struct scsi_device *sdev = to_scsi_device(dev); 1292 struct scsi_device *sdev = to_scsi_device(dev);
1154 struct sbp2_device *sd; 1293 struct sbp2_logical_unit *lu;
1155 struct fw_unit *unit;
1156 struct fw_device *device; 1294 struct fw_device *device;
1157 u32 directory_id;
1158 struct fw_csr_iterator ci;
1159 int key, value, lun;
1160 1295
1161 if (!sdev) 1296 if (!sdev)
1162 return 0; 1297 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 1298
1179 /* FIXME: Make this work for multi-lun devices. */ 1299 lu = sdev->hostdata;
1180 lun = 0; 1300 device = fw_device(lu->tgt->unit->device.parent);
1181 1301
1182 return sprintf(buf, "%08x%08x:%06x:%04x\n", 1302 return sprintf(buf, "%08x%08x:%06x:%04x\n",
1183 device->config_rom[3], device->config_rom[4], 1303 device->config_rom[3], device->config_rom[4],
1184 directory_id, lun); 1304 lu->tgt->directory_id, lu->lun);
1185} 1305}
1186 1306
1187static DEVICE_ATTR(ieee1394_id, S_IRUGO, sbp2_sysfs_ieee1394_id_show, NULL); 1307static DEVICE_ATTR(ieee1394_id, S_IRUGO, sbp2_sysfs_ieee1394_id_show, NULL);
@@ -1219,12 +1339,17 @@ MODULE_ALIAS("sbp2");
1219 1339
1220static int __init sbp2_init(void) 1340static int __init sbp2_init(void)
1221{ 1341{
1342 sbp2_wq = create_singlethread_workqueue(KBUILD_MODNAME);
1343 if (!sbp2_wq)
1344 return -ENOMEM;
1345
1222 return driver_register(&sbp2_driver.driver); 1346 return driver_register(&sbp2_driver.driver);
1223} 1347}
1224 1348
1225static void __exit sbp2_cleanup(void) 1349static void __exit sbp2_cleanup(void)
1226{ 1350{
1227 driver_unregister(&sbp2_driver.driver); 1351 driver_unregister(&sbp2_driver.driver);
1352 destroy_workqueue(sbp2_wq);
1228} 1353}
1229 1354
1230module_init(sbp2_init); 1355module_init(sbp2_init);
diff --git a/drivers/firewire/fw-topology.c b/drivers/firewire/fw-topology.c
index 39e5cd12aa52..0fc9b000e99d 100644
--- a/drivers/firewire/fw-topology.c
+++ b/drivers/firewire/fw-topology.c
@@ -152,6 +152,10 @@ static void update_hop_count(struct fw_node *node)
152 node->max_hops = max(max_child_hops, depths[0] + depths[1] + 2); 152 node->max_hops = max(max_child_hops, depths[0] + depths[1] + 2);
153} 153}
154 154
155static inline struct fw_node *fw_node(struct list_head *l)
156{
157 return list_entry(l, struct fw_node, link);
158}
155 159
156/** 160/**
157 * build_tree - Build the tree representation of the topology 161 * build_tree - Build the tree representation of the topology
@@ -162,7 +166,7 @@ static void update_hop_count(struct fw_node *node)
162 * This function builds the tree representation of the topology given 166 * This function builds the tree representation of the topology given
163 * by the self IDs from the latest bus reset. During the construction 167 * by the self IDs from the latest bus reset. During the construction
164 * of the tree, the function checks that the self IDs are valid and 168 * of the tree, the function checks that the self IDs are valid and
165 * internally consistent. On succcess this funtions returns the 169 * internally consistent. On succcess this function returns the
166 * fw_node corresponding to the local card otherwise NULL. 170 * fw_node corresponding to the local card otherwise NULL.
167 */ 171 */
168static struct fw_node *build_tree(struct fw_card *card, 172static struct fw_node *build_tree(struct fw_card *card,
@@ -211,6 +215,10 @@ static struct fw_node *build_tree(struct fw_card *card,
211 */ 215 */
212 for (i = 0, h = &stack; i < child_port_count; i++) 216 for (i = 0, h = &stack; i < child_port_count; i++)
213 h = h->prev; 217 h = h->prev;
218 /*
219 * When the stack is empty, this yields an invalid value,
220 * but that pointer will never be dereferenced.
221 */
214 child = fw_node(h); 222 child = fw_node(h);
215 223
216 node = fw_node_create(q, port_count, card->color); 224 node = fw_node_create(q, port_count, card->color);
diff --git a/drivers/firewire/fw-topology.h b/drivers/firewire/fw-topology.h
index 1b56b4ac7fb2..cedc1ec906e9 100644
--- a/drivers/firewire/fw-topology.h
+++ b/drivers/firewire/fw-topology.h
@@ -51,12 +51,6 @@ struct fw_node {
51}; 51};
52 52
53static inline struct fw_node * 53static inline struct fw_node *
54fw_node(struct list_head *l)
55{
56 return list_entry(l, struct fw_node, link);
57}
58
59static inline struct fw_node *
60fw_node_get(struct fw_node *node) 54fw_node_get(struct fw_node *node)
61{ 55{
62 atomic_inc(&node->ref_count); 56 atomic_inc(&node->ref_count);
diff --git a/drivers/firewire/fw-transaction.c b/drivers/firewire/fw-transaction.c
index 3e1cb12e43cd..9959b799dbe2 100644
--- a/drivers/firewire/fw-transaction.c
+++ b/drivers/firewire/fw-transaction.c
@@ -410,7 +410,12 @@ EXPORT_SYMBOL(fw_unit_space_region);
410 * controller. When a request is received that falls within the 410 * controller. When a request is received that falls within the
411 * specified address range, the specified callback is invoked. The 411 * specified address range, the specified callback is invoked. The
412 * parameters passed to the callback give the details of the 412 * parameters passed to the callback give the details of the
413 * particular request 413 * particular request.
414 *
415 * Return value: 0 on success, non-zero otherwise.
416 * The start offset of the handler's address region is determined by
417 * fw_core_add_address_handler() and is returned in handler->offset.
418 * The offset is quadlet-aligned.
414 */ 419 */
415int 420int
416fw_core_add_address_handler(struct fw_address_handler *handler, 421fw_core_add_address_handler(struct fw_address_handler *handler,
@@ -422,14 +427,15 @@ fw_core_add_address_handler(struct fw_address_handler *handler,
422 427
423 spin_lock_irqsave(&address_handler_lock, flags); 428 spin_lock_irqsave(&address_handler_lock, flags);
424 429
425 handler->offset = region->start; 430 handler->offset = roundup(region->start, 4);
426 while (handler->offset + handler->length <= region->end) { 431 while (handler->offset + handler->length <= region->end) {
427 other = 432 other =
428 lookup_overlapping_address_handler(&address_handler_list, 433 lookup_overlapping_address_handler(&address_handler_list,
429 handler->offset, 434 handler->offset,
430 handler->length); 435 handler->length);
431 if (other != NULL) { 436 if (other != NULL) {
432 handler->offset += other->length; 437 handler->offset =
438 roundup(other->offset + other->length, 4);
433 } else { 439 } else {
434 list_add_tail(&handler->link, &address_handler_list); 440 list_add_tail(&handler->link, &address_handler_list);
435 ret = 0; 441 ret = 0;
diff --git a/drivers/ieee1394/csr1212.c b/drivers/ieee1394/csr1212.c
index d08166bda1c5..e8122def164d 100644
--- a/drivers/ieee1394/csr1212.c
+++ b/drivers/ieee1394/csr1212.c
@@ -218,12 +218,10 @@ static struct csr1212_keyval *csr1212_new_keyval(u8 type, u8 key)
218 if (!kv) 218 if (!kv)
219 return NULL; 219 return NULL;
220 220
221 atomic_set(&kv->refcnt, 1);
221 kv->key.type = type; 222 kv->key.type = type;
222 kv->key.id = key; 223 kv->key.id = key;
223
224 kv->associate = NULL; 224 kv->associate = NULL;
225 kv->refcnt = 1;
226
227 kv->next = NULL; 225 kv->next = NULL;
228 kv->prev = NULL; 226 kv->prev = NULL;
229 kv->offset = 0; 227 kv->offset = 0;
@@ -326,12 +324,13 @@ void csr1212_associate_keyval(struct csr1212_keyval *kv,
326 if (kv->associate) 324 if (kv->associate)
327 csr1212_release_keyval(kv->associate); 325 csr1212_release_keyval(kv->associate);
328 326
329 associate->refcnt++; 327 csr1212_keep_keyval(associate);
330 kv->associate = associate; 328 kv->associate = associate;
331} 329}
332 330
333int csr1212_attach_keyval_to_directory(struct csr1212_keyval *dir, 331static int __csr1212_attach_keyval_to_directory(struct csr1212_keyval *dir,
334 struct csr1212_keyval *kv) 332 struct csr1212_keyval *kv,
333 bool keep_keyval)
335{ 334{
336 struct csr1212_dentry *dentry; 335 struct csr1212_dentry *dentry;
337 336
@@ -341,10 +340,10 @@ int csr1212_attach_keyval_to_directory(struct csr1212_keyval *dir,
341 if (!dentry) 340 if (!dentry)
342 return -ENOMEM; 341 return -ENOMEM;
343 342
343 if (keep_keyval)
344 csr1212_keep_keyval(kv);
344 dentry->kv = kv; 345 dentry->kv = kv;
345 346
346 kv->refcnt++;
347
348 dentry->next = NULL; 347 dentry->next = NULL;
349 dentry->prev = dir->value.directory.dentries_tail; 348 dentry->prev = dir->value.directory.dentries_tail;
350 349
@@ -358,6 +357,12 @@ int csr1212_attach_keyval_to_directory(struct csr1212_keyval *dir,
358 return CSR1212_SUCCESS; 357 return CSR1212_SUCCESS;
359} 358}
360 359
360int csr1212_attach_keyval_to_directory(struct csr1212_keyval *dir,
361 struct csr1212_keyval *kv)
362{
363 return __csr1212_attach_keyval_to_directory(dir, kv, true);
364}
365
361#define CSR1212_DESCRIPTOR_LEAF_DATA(kv) \ 366#define CSR1212_DESCRIPTOR_LEAF_DATA(kv) \
362 (&((kv)->value.leaf.data[1])) 367 (&((kv)->value.leaf.data[1]))
363 368
@@ -483,15 +488,18 @@ void csr1212_detach_keyval_from_directory(struct csr1212_keyval *dir,
483 488
484/* This function is used to free the memory taken by a keyval. If the given 489/* This function is used to free the memory taken by a keyval. If the given
485 * keyval is a directory type, then any keyvals contained in that directory 490 * keyval is a directory type, then any keyvals contained in that directory
486 * will be destroyed as well if their respective refcnts are 0. By means of 491 * will be destroyed as well if noone holds a reference on them. By means of
487 * list manipulation, this routine will descend a directory structure in a 492 * list manipulation, this routine will descend a directory structure in a
488 * non-recursive manner. */ 493 * non-recursive manner. */
489static void csr1212_destroy_keyval(struct csr1212_keyval *kv) 494void csr1212_release_keyval(struct csr1212_keyval *kv)
490{ 495{
491 struct csr1212_keyval *k, *a; 496 struct csr1212_keyval *k, *a;
492 struct csr1212_dentry dentry; 497 struct csr1212_dentry dentry;
493 struct csr1212_dentry *head, *tail; 498 struct csr1212_dentry *head, *tail;
494 499
500 if (!atomic_dec_and_test(&kv->refcnt))
501 return;
502
495 dentry.kv = kv; 503 dentry.kv = kv;
496 dentry.next = NULL; 504 dentry.next = NULL;
497 dentry.prev = NULL; 505 dentry.prev = NULL;
@@ -503,9 +511,8 @@ static void csr1212_destroy_keyval(struct csr1212_keyval *kv)
503 k = head->kv; 511 k = head->kv;
504 512
505 while (k) { 513 while (k) {
506 k->refcnt--; 514 /* must not dec_and_test kv->refcnt again */
507 515 if (k != kv && !atomic_dec_and_test(&k->refcnt))
508 if (k->refcnt > 0)
509 break; 516 break;
510 517
511 a = k->associate; 518 a = k->associate;
@@ -536,14 +543,6 @@ static void csr1212_destroy_keyval(struct csr1212_keyval *kv)
536 } 543 }
537} 544}
538 545
539void csr1212_release_keyval(struct csr1212_keyval *kv)
540{
541 if (kv->refcnt > 1)
542 kv->refcnt--;
543 else
544 csr1212_destroy_keyval(kv);
545}
546
547void csr1212_destroy_csr(struct csr1212_csr *csr) 546void csr1212_destroy_csr(struct csr1212_csr *csr)
548{ 547{
549 struct csr1212_csr_rom_cache *c, *oc; 548 struct csr1212_csr_rom_cache *c, *oc;
@@ -1126,6 +1125,7 @@ csr1212_parse_dir_entry(struct csr1212_keyval *dir, u32 ki, u32 kv_pos)
1126 int ret = CSR1212_SUCCESS; 1125 int ret = CSR1212_SUCCESS;
1127 struct csr1212_keyval *k = NULL; 1126 struct csr1212_keyval *k = NULL;
1128 u32 offset; 1127 u32 offset;
1128 bool keep_keyval = true;
1129 1129
1130 switch (CSR1212_KV_KEY_TYPE(ki)) { 1130 switch (CSR1212_KV_KEY_TYPE(ki)) {
1131 case CSR1212_KV_TYPE_IMMEDIATE: 1131 case CSR1212_KV_TYPE_IMMEDIATE:
@@ -1135,8 +1135,8 @@ csr1212_parse_dir_entry(struct csr1212_keyval *dir, u32 ki, u32 kv_pos)
1135 ret = -ENOMEM; 1135 ret = -ENOMEM;
1136 goto out; 1136 goto out;
1137 } 1137 }
1138 1138 /* Don't keep local reference when parsing. */
1139 k->refcnt = 0; /* Don't keep local reference when parsing. */ 1139 keep_keyval = false;
1140 break; 1140 break;
1141 1141
1142 case CSR1212_KV_TYPE_CSR_OFFSET: 1142 case CSR1212_KV_TYPE_CSR_OFFSET:
@@ -1146,7 +1146,8 @@ csr1212_parse_dir_entry(struct csr1212_keyval *dir, u32 ki, u32 kv_pos)
1146 ret = -ENOMEM; 1146 ret = -ENOMEM;
1147 goto out; 1147 goto out;
1148 } 1148 }
1149 k->refcnt = 0; /* Don't keep local reference when parsing. */ 1149 /* Don't keep local reference when parsing. */
1150 keep_keyval = false;
1150 break; 1151 break;
1151 1152
1152 default: 1153 default:
@@ -1174,8 +1175,10 @@ csr1212_parse_dir_entry(struct csr1212_keyval *dir, u32 ki, u32 kv_pos)
1174 ret = -ENOMEM; 1175 ret = -ENOMEM;
1175 goto out; 1176 goto out;
1176 } 1177 }
1177 k->refcnt = 0; /* Don't keep local reference when parsing. */ 1178 /* Don't keep local reference when parsing. */
1178 k->valid = 0; /* Contents not read yet so it's not valid. */ 1179 keep_keyval = false;
1180 /* Contents not read yet so it's not valid. */
1181 k->valid = 0;
1179 k->offset = offset; 1182 k->offset = offset;
1180 1183
1181 k->prev = dir; 1184 k->prev = dir;
@@ -1183,7 +1186,7 @@ csr1212_parse_dir_entry(struct csr1212_keyval *dir, u32 ki, u32 kv_pos)
1183 dir->next->prev = k; 1186 dir->next->prev = k;
1184 dir->next = k; 1187 dir->next = k;
1185 } 1188 }
1186 ret = csr1212_attach_keyval_to_directory(dir, k); 1189 ret = __csr1212_attach_keyval_to_directory(dir, k, keep_keyval);
1187out: 1190out:
1188 if (ret != CSR1212_SUCCESS && k != NULL) 1191 if (ret != CSR1212_SUCCESS && k != NULL)
1189 free_keyval(k); 1192 free_keyval(k);
diff --git a/drivers/ieee1394/csr1212.h b/drivers/ieee1394/csr1212.h
index df909ce66304..043039fc63ec 100644
--- a/drivers/ieee1394/csr1212.h
+++ b/drivers/ieee1394/csr1212.h
@@ -32,6 +32,7 @@
32 32
33#include <linux/types.h> 33#include <linux/types.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <asm/atomic.h>
35 36
36#define CSR1212_MALLOC(size) kmalloc((size), GFP_KERNEL) 37#define CSR1212_MALLOC(size) kmalloc((size), GFP_KERNEL)
37#define CSR1212_FREE(ptr) kfree(ptr) 38#define CSR1212_FREE(ptr) kfree(ptr)
@@ -149,7 +150,7 @@ struct csr1212_keyval {
149 struct csr1212_directory directory; 150 struct csr1212_directory directory;
150 } value; 151 } value;
151 struct csr1212_keyval *associate; 152 struct csr1212_keyval *associate;
152 int refcnt; 153 atomic_t refcnt;
153 154
154 /* used in generating and/or parsing CSR image */ 155 /* used in generating and/or parsing CSR image */
155 struct csr1212_keyval *next, *prev; /* flat list of CSR elements */ 156 struct csr1212_keyval *next, *prev; /* flat list of CSR elements */
@@ -350,7 +351,8 @@ csr1212_get_keyval(struct csr1212_csr *csr, struct csr1212_keyval *kv);
350 * need for code to retain a keyval that has been parsed. */ 351 * need for code to retain a keyval that has been parsed. */
351static inline void csr1212_keep_keyval(struct csr1212_keyval *kv) 352static inline void csr1212_keep_keyval(struct csr1212_keyval *kv)
352{ 353{
353 kv->refcnt++; 354 atomic_inc(&kv->refcnt);
355 smp_mb__after_atomic_inc();
354} 356}
355 357
356 358
diff --git a/drivers/ieee1394/eth1394.c b/drivers/ieee1394/eth1394.c
index dc9dce22f6a8..b166b3575fa6 100644
--- a/drivers/ieee1394/eth1394.c
+++ b/drivers/ieee1394/eth1394.c
@@ -1153,8 +1153,6 @@ static int ether1394_data_handler(struct net_device *dev, int srcid, int destid,
1153 pdg->sz++; 1153 pdg->sz++;
1154 lh = find_partial_datagram(pdgl, dgl); 1154 lh = find_partial_datagram(pdgl, dgl);
1155 } else { 1155 } else {
1156 struct partial_datagram *pd;
1157
1158 pd = list_entry(lh, struct partial_datagram, list); 1156 pd = list_entry(lh, struct partial_datagram, list);
1159 1157
1160 if (fragment_overlap(&pd->frag_info, fg_off, fg_len)) { 1158 if (fragment_overlap(&pd->frag_info, fg_off, fg_len)) {
@@ -1222,23 +1220,19 @@ static int ether1394_data_handler(struct net_device *dev, int srcid, int destid,
1222 priv->stats.rx_errors++; 1220 priv->stats.rx_errors++;
1223 priv->stats.rx_dropped++; 1221 priv->stats.rx_dropped++;
1224 dev_kfree_skb_any(skb); 1222 dev_kfree_skb_any(skb);
1225 goto bad_proto; 1223 } else if (netif_rx(skb) == NET_RX_DROP) {
1226 }
1227
1228 if (netif_rx(skb) == NET_RX_DROP) {
1229 priv->stats.rx_errors++; 1224 priv->stats.rx_errors++;
1230 priv->stats.rx_dropped++; 1225 priv->stats.rx_dropped++;
1231 goto bad_proto; 1226 } else {
1227 priv->stats.rx_packets++;
1228 priv->stats.rx_bytes += skb->len;
1232 } 1229 }
1233 1230
1234 /* Statistics */ 1231 spin_unlock_irqrestore(&priv->lock, flags);
1235 priv->stats.rx_packets++;
1236 priv->stats.rx_bytes += skb->len;
1237 1232
1238bad_proto: 1233bad_proto:
1239 if (netif_queue_stopped(dev)) 1234 if (netif_queue_stopped(dev))
1240 netif_wake_queue(dev); 1235 netif_wake_queue(dev);
1241 spin_unlock_irqrestore(&priv->lock, flags);
1242 1236
1243 dev->last_rx = jiffies; 1237 dev->last_rx = jiffies;
1244 1238
diff --git a/drivers/ieee1394/ieee1394_core.c b/drivers/ieee1394/ieee1394_core.c
index 98fd985a32ff..36c747b277d0 100644
--- a/drivers/ieee1394/ieee1394_core.c
+++ b/drivers/ieee1394/ieee1394_core.c
@@ -488,7 +488,7 @@ void hpsb_selfid_complete(struct hpsb_host *host, int phyid, int isroot)
488 highlevel_host_reset(host); 488 highlevel_host_reset(host);
489} 489}
490 490
491static spinlock_t pending_packets_lock = SPIN_LOCK_UNLOCKED; 491static DEFINE_SPINLOCK(pending_packets_lock);
492 492
493/** 493/**
494 * hpsb_packet_sent - notify core of sending a packet 494 * hpsb_packet_sent - notify core of sending a packet
diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c
index 1939fee616ec..90dc75be3418 100644
--- a/drivers/ieee1394/nodemgr.c
+++ b/drivers/ieee1394/nodemgr.c
@@ -1014,13 +1014,13 @@ static struct unit_directory *nodemgr_process_unit_directory
1014 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE(kv) == 0) { 1014 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE(kv) == 0) {
1015 switch (last_key_id) { 1015 switch (last_key_id) {
1016 case CSR1212_KV_ID_VENDOR: 1016 case CSR1212_KV_ID_VENDOR:
1017 ud->vendor_name_kv = kv;
1018 csr1212_keep_keyval(kv); 1017 csr1212_keep_keyval(kv);
1018 ud->vendor_name_kv = kv;
1019 break; 1019 break;
1020 1020
1021 case CSR1212_KV_ID_MODEL: 1021 case CSR1212_KV_ID_MODEL:
1022 ud->model_name_kv = kv;
1023 csr1212_keep_keyval(kv); 1022 csr1212_keep_keyval(kv);
1023 ud->model_name_kv = kv;
1024 break; 1024 break;
1025 1025
1026 } 1026 }
@@ -1112,7 +1112,7 @@ static void nodemgr_process_root_directory(struct host_info *hi, struct node_ent
1112{ 1112{
1113 unsigned int ud_id = 0; 1113 unsigned int ud_id = 0;
1114 struct csr1212_dentry *dentry; 1114 struct csr1212_dentry *dentry;
1115 struct csr1212_keyval *kv; 1115 struct csr1212_keyval *kv, *vendor_name_kv = NULL;
1116 u8 last_key_id = 0; 1116 u8 last_key_id = 0;
1117 1117
1118 ne->needs_probe = 0; 1118 ne->needs_probe = 0;
@@ -1139,8 +1139,8 @@ static void nodemgr_process_root_directory(struct host_info *hi, struct node_ent
1139 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH(kv) == 0 && 1139 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH(kv) == 0 &&
1140 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET(kv) == 0 && 1140 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET(kv) == 0 &&
1141 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE(kv) == 0) { 1141 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE(kv) == 0) {
1142 ne->vendor_name_kv = kv;
1143 csr1212_keep_keyval(kv); 1142 csr1212_keep_keyval(kv);
1143 vendor_name_kv = kv;
1144 } 1144 }
1145 } 1145 }
1146 break; 1146 break;
@@ -1149,10 +1149,13 @@ static void nodemgr_process_root_directory(struct host_info *hi, struct node_ent
1149 } 1149 }
1150 1150
1151 if (ne->vendor_name_kv) { 1151 if (ne->vendor_name_kv) {
1152 int error = device_create_file(&ne->device, 1152 kv = ne->vendor_name_kv;
1153 &dev_attr_ne_vendor_name_kv); 1153 ne->vendor_name_kv = vendor_name_kv;
1154 1154 csr1212_release_keyval(kv);
1155 if (error && error != -EEXIST) 1155 } else if (vendor_name_kv) {
1156 ne->vendor_name_kv = vendor_name_kv;
1157 if (device_create_file(&ne->device,
1158 &dev_attr_ne_vendor_name_kv) != 0)
1156 HPSB_ERR("Failed to add sysfs attribute"); 1159 HPSB_ERR("Failed to add sysfs attribute");
1157 } 1160 }
1158} 1161}
@@ -1712,7 +1715,8 @@ static int nodemgr_host_thread(void *__hi)
1712 * to make sure things settle down. */ 1715 * to make sure things settle down. */
1713 g = get_hpsb_generation(host); 1716 g = get_hpsb_generation(host);
1714 for (i = 0; i < 4 ; i++) { 1717 for (i = 0; i < 4 ; i++) {
1715 if (msleep_interruptible(63) || kthread_should_stop()) 1718 msleep_interruptible(63);
1719 if (kthread_should_stop())
1716 goto exit; 1720 goto exit;
1717 1721
1718 /* Now get the generation in which the node ID's we collect 1722 /* Now get the generation in which the node ID's we collect
diff --git a/drivers/ieee1394/pcilynx.c b/drivers/ieee1394/pcilynx.c
index d1a5bcdb5e0b..8af01ab30cc9 100644
--- a/drivers/ieee1394/pcilynx.c
+++ b/drivers/ieee1394/pcilynx.c
@@ -121,16 +121,6 @@ static int bit_getsda(void *data)
121 return reg_read((struct ti_lynx *) data, SERIAL_EEPROM_CONTROL) & 0x00000010; 121 return reg_read((struct ti_lynx *) data, SERIAL_EEPROM_CONTROL) & 0x00000010;
122} 122}
123 123
124static int bit_reg(struct i2c_client *client)
125{
126 return 0;
127}
128
129static int bit_unreg(struct i2c_client *client)
130{
131 return 0;
132}
133
134static struct i2c_algo_bit_data bit_data = { 124static struct i2c_algo_bit_data bit_data = {
135 .setsda = bit_setsda, 125 .setsda = bit_setsda,
136 .setscl = bit_setscl, 126 .setscl = bit_setscl,
@@ -140,14 +130,6 @@ static struct i2c_algo_bit_data bit_data = {
140 .timeout = 100, 130 .timeout = 100,
141}; 131};
142 132
143static struct i2c_adapter bit_ops = {
144 .id = 0xAA, //FIXME: probably we should get an id in i2c-id.h
145 .client_register = bit_reg,
146 .client_unregister = bit_unreg,
147 .name = "PCILynx I2C",
148};
149
150
151 133
152/* 134/*
153 * PCL handling functions. 135 * PCL handling functions.
@@ -765,7 +747,6 @@ static int lynx_devctl(struct hpsb_host *host, enum devctl_cmd cmd, int arg)
765 } else { 747 } else {
766 struct ti_pcl pcl; 748 struct ti_pcl pcl;
767 u32 ack; 749 u32 ack;
768 struct hpsb_packet *packet;
769 750
770 PRINT(KERN_INFO, lynx->id, "cancelling async packet, that was already in PCL"); 751 PRINT(KERN_INFO, lynx->id, "cancelling async packet, that was already in PCL");
771 752
@@ -1436,9 +1417,11 @@ static int __devinit add_card(struct pci_dev *dev,
1436 struct i2c_algo_bit_data i2c_adapter_data; 1417 struct i2c_algo_bit_data i2c_adapter_data;
1437 1418
1438 error = -ENOMEM; 1419 error = -ENOMEM;
1439 i2c_ad = kmemdup(&bit_ops, sizeof(*i2c_ad), GFP_KERNEL); 1420 i2c_ad = kzalloc(sizeof(*i2c_ad), GFP_KERNEL);
1440 if (!i2c_ad) FAIL("failed to allocate I2C adapter memory"); 1421 if (!i2c_ad) FAIL("failed to allocate I2C adapter memory");
1441 1422
1423 i2c_ad->id = I2C_HW_B_PCILYNX;
1424 strlcpy(i2c_ad->name, "PCILynx I2C", sizeof(i2c_ad->name));
1442 i2c_adapter_data = bit_data; 1425 i2c_adapter_data = bit_data;
1443 i2c_ad->algo_data = &i2c_adapter_data; 1426 i2c_ad->algo_data = &i2c_adapter_data;
1444 i2c_adapter_data.data = lynx; 1427 i2c_adapter_data.data = lynx;
@@ -1465,13 +1448,11 @@ static int __devinit add_card(struct pci_dev *dev,
1465 { 0x50, I2C_M_RD, 20, (unsigned char*) lynx->bus_info_block } 1448 { 0x50, I2C_M_RD, 20, (unsigned char*) lynx->bus_info_block }
1466 }; 1449 };
1467 1450
1468 /* we use i2c_transfer, because i2c_smbus_read_block_data does not work properly and we 1451 /* we use i2c_transfer because we have no i2c_client
1469 do it more efficiently in one transaction rather then using several reads */ 1452 at hand */
1470 if (i2c_transfer(i2c_ad, msg, 2) < 0) { 1453 if (i2c_transfer(i2c_ad, msg, 2) < 0) {
1471 PRINT(KERN_ERR, lynx->id, "unable to read bus info block from i2c"); 1454 PRINT(KERN_ERR, lynx->id, "unable to read bus info block from i2c");
1472 } else { 1455 } else {
1473 int i;
1474
1475 PRINT(KERN_INFO, lynx->id, "got bus info block from serial eeprom"); 1456 PRINT(KERN_INFO, lynx->id, "got bus info block from serial eeprom");
1476 /* FIXME: probably we shoud rewrite the max_rec, max_ROM(1394a), 1457 /* FIXME: probably we shoud rewrite the max_rec, max_ROM(1394a),
1477 * generation(1394a) and link_spd(1394a) field and recalculate 1458 * generation(1394a) and link_spd(1394a) field and recalculate
diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c
index a81ba8fca0db..1b353b964b33 100644
--- a/drivers/ieee1394/sbp2.c
+++ b/drivers/ieee1394/sbp2.c
@@ -242,6 +242,8 @@ static int sbp2_max_speed_and_size(struct sbp2_lu *);
242 242
243static const u8 sbp2_speedto_max_payload[] = { 0x7, 0x8, 0x9, 0xA, 0xB, 0xC }; 243static const u8 sbp2_speedto_max_payload[] = { 0x7, 0x8, 0x9, 0xA, 0xB, 0xC };
244 244
245static DEFINE_RWLOCK(sbp2_hi_logical_units_lock);
246
245static struct hpsb_highlevel sbp2_highlevel = { 247static struct hpsb_highlevel sbp2_highlevel = {
246 .name = SBP2_DEVICE_NAME, 248 .name = SBP2_DEVICE_NAME,
247 .host_reset = sbp2_host_reset, 249 .host_reset = sbp2_host_reset,
@@ -732,6 +734,7 @@ static struct sbp2_lu *sbp2_alloc_device(struct unit_directory *ud)
732 struct sbp2_fwhost_info *hi; 734 struct sbp2_fwhost_info *hi;
733 struct Scsi_Host *shost = NULL; 735 struct Scsi_Host *shost = NULL;
734 struct sbp2_lu *lu = NULL; 736 struct sbp2_lu *lu = NULL;
737 unsigned long flags;
735 738
736 lu = kzalloc(sizeof(*lu), GFP_KERNEL); 739 lu = kzalloc(sizeof(*lu), GFP_KERNEL);
737 if (!lu) { 740 if (!lu) {
@@ -784,7 +787,9 @@ static struct sbp2_lu *sbp2_alloc_device(struct unit_directory *ud)
784 787
785 lu->hi = hi; 788 lu->hi = hi;
786 789
790 write_lock_irqsave(&sbp2_hi_logical_units_lock, flags);
787 list_add_tail(&lu->lu_list, &hi->logical_units); 791 list_add_tail(&lu->lu_list, &hi->logical_units);
792 write_unlock_irqrestore(&sbp2_hi_logical_units_lock, flags);
788 793
789 /* Register the status FIFO address range. We could use the same FIFO 794 /* Register the status FIFO address range. We could use the same FIFO
790 * for targets at different nodes. However we need different FIFOs per 795 * for targets at different nodes. However we need different FIFOs per
@@ -828,16 +833,20 @@ static void sbp2_host_reset(struct hpsb_host *host)
828{ 833{
829 struct sbp2_fwhost_info *hi; 834 struct sbp2_fwhost_info *hi;
830 struct sbp2_lu *lu; 835 struct sbp2_lu *lu;
836 unsigned long flags;
831 837
832 hi = hpsb_get_hostinfo(&sbp2_highlevel, host); 838 hi = hpsb_get_hostinfo(&sbp2_highlevel, host);
833 if (!hi) 839 if (!hi)
834 return; 840 return;
841
842 read_lock_irqsave(&sbp2_hi_logical_units_lock, flags);
835 list_for_each_entry(lu, &hi->logical_units, lu_list) 843 list_for_each_entry(lu, &hi->logical_units, lu_list)
836 if (likely(atomic_read(&lu->state) != 844 if (likely(atomic_read(&lu->state) !=
837 SBP2LU_STATE_IN_SHUTDOWN)) { 845 SBP2LU_STATE_IN_SHUTDOWN)) {
838 atomic_set(&lu->state, SBP2LU_STATE_IN_RESET); 846 atomic_set(&lu->state, SBP2LU_STATE_IN_RESET);
839 scsi_block_requests(lu->shost); 847 scsi_block_requests(lu->shost);
840 } 848 }
849 read_unlock_irqrestore(&sbp2_hi_logical_units_lock, flags);
841} 850}
842 851
843static int sbp2_start_device(struct sbp2_lu *lu) 852static int sbp2_start_device(struct sbp2_lu *lu)
@@ -919,6 +928,7 @@ alloc_fail:
919static void sbp2_remove_device(struct sbp2_lu *lu) 928static void sbp2_remove_device(struct sbp2_lu *lu)
920{ 929{
921 struct sbp2_fwhost_info *hi; 930 struct sbp2_fwhost_info *hi;
931 unsigned long flags;
922 932
923 if (!lu) 933 if (!lu)
924 return; 934 return;
@@ -933,7 +943,9 @@ static void sbp2_remove_device(struct sbp2_lu *lu)
933 flush_scheduled_work(); 943 flush_scheduled_work();
934 sbp2util_remove_command_orb_pool(lu, hi->host); 944 sbp2util_remove_command_orb_pool(lu, hi->host);
935 945
946 write_lock_irqsave(&sbp2_hi_logical_units_lock, flags);
936 list_del(&lu->lu_list); 947 list_del(&lu->lu_list);
948 write_unlock_irqrestore(&sbp2_hi_logical_units_lock, flags);
937 949
938 if (lu->login_response) 950 if (lu->login_response)
939 dma_free_coherent(hi->host->device.parent, 951 dma_free_coherent(hi->host->device.parent,
@@ -1707,6 +1719,7 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid,
1707 } 1719 }
1708 1720
1709 /* Find the unit which wrote the status. */ 1721 /* Find the unit which wrote the status. */
1722 read_lock_irqsave(&sbp2_hi_logical_units_lock, flags);
1710 list_for_each_entry(lu_tmp, &hi->logical_units, lu_list) { 1723 list_for_each_entry(lu_tmp, &hi->logical_units, lu_list) {
1711 if (lu_tmp->ne->nodeid == nodeid && 1724 if (lu_tmp->ne->nodeid == nodeid &&
1712 lu_tmp->status_fifo_addr == addr) { 1725 lu_tmp->status_fifo_addr == addr) {
@@ -1714,6 +1727,8 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid,
1714 break; 1727 break;
1715 } 1728 }
1716 } 1729 }
1730 read_unlock_irqrestore(&sbp2_hi_logical_units_lock, flags);
1731
1717 if (unlikely(!lu)) { 1732 if (unlikely(!lu)) {
1718 SBP2_ERR("lu is NULL - device is gone?"); 1733 SBP2_ERR("lu is NULL - device is gone?");
1719 return RCODE_ADDRESS_ERROR; 1734 return RCODE_ADDRESS_ERROR;
diff --git a/include/linux/firewire-cdev.h b/include/linux/firewire-cdev.h
index 1a45d6f41b09..0f0e271f97fa 100644
--- a/include/linux/firewire-cdev.h
+++ b/include/linux/firewire-cdev.h
@@ -178,6 +178,7 @@ union fw_cdev_event {
178#define FW_CDEV_IOC_QUEUE_ISO _IOWR('#', 0x09, struct fw_cdev_queue_iso) 178#define FW_CDEV_IOC_QUEUE_ISO _IOWR('#', 0x09, struct fw_cdev_queue_iso)
179#define FW_CDEV_IOC_START_ISO _IOW('#', 0x0a, struct fw_cdev_start_iso) 179#define FW_CDEV_IOC_START_ISO _IOW('#', 0x0a, struct fw_cdev_start_iso)
180#define FW_CDEV_IOC_STOP_ISO _IOW('#', 0x0b, struct fw_cdev_stop_iso) 180#define FW_CDEV_IOC_STOP_ISO _IOW('#', 0x0b, struct fw_cdev_stop_iso)
181#define FW_CDEV_IOC_GET_CYCLE_TIMER _IOR('#', 0x0c, struct fw_cdev_get_cycle_timer)
181 182
182/* FW_CDEV_VERSION History 183/* FW_CDEV_VERSION History
183 * 184 *
@@ -459,4 +460,18 @@ struct fw_cdev_stop_iso {
459 __u32 handle; 460 __u32 handle;
460}; 461};
461 462
463/**
464 * struct fw_cdev_get_cycle_timer - read cycle timer register
465 * @local_time: system time, in microseconds since the Epoch
466 * @cycle_timer: isochronous cycle timer, as per OHCI 1.1 clause 5.13
467 *
468 * The %FW_CDEV_IOC_GET_CYCLE_TIMER ioctl reads the isochronous cycle timer
469 * and also the system clock. This allows to express the receive time of an
470 * isochronous packet as a system time with microsecond accuracy.
471 */
472struct fw_cdev_get_cycle_timer {
473 __u64 local_time;
474 __u32 cycle_timer;
475};
476
462#endif /* _LINUX_FIREWIRE_CDEV_H */ 477#endif /* _LINUX_FIREWIRE_CDEV_H */