Jesse Keating 2f82dd
linux1394-2.6.git tree vs. linus v2.6.29-rc3-git1 on 20090130 by jarod
Jesse Keating 2f82dd
Jesse Keating 2f82dd
---
Jesse Keating 2f82dd
 firewire-git/drivers/firewire/fw-card.c        |   68 -
Jesse Keating 2f82dd
 firewire-git/drivers/firewire/fw-cdev.c        | 1014 +++++++++++++++++--------
Jesse Keating 2f82dd
 firewire-git/drivers/firewire/fw-device.c      |   43 -
Jesse Keating 2f82dd
 firewire-git/drivers/firewire/fw-device.h      |    7 
Jesse Keating 2f82dd
 firewire-git/drivers/firewire/fw-iso.c         |  225 ++++-
Jesse Keating 2f82dd
 firewire-git/drivers/firewire/fw-ohci.c        |  236 ++---
Jesse Keating 2f82dd
 firewire-git/drivers/firewire/fw-sbp2.c        |   57 -
Jesse Keating 2f82dd
 firewire-git/drivers/firewire/fw-topology.c    |   28 
Jesse Keating 2f82dd
 firewire-git/drivers/firewire/fw-topology.h    |   19 
Jesse Keating 2f82dd
 firewire-git/drivers/firewire/fw-transaction.c |  151 +--
Jesse Keating 2f82dd
 firewire-git/drivers/firewire/fw-transaction.h |  125 ---
Jesse Keating 2f82dd
 include/linux/firewire-cdev.h                  |  170 +++-
Jesse Keating 2f82dd
 12 files changed, 1359 insertions(+), 784 deletions(-)
Jesse Keating 2f82dd
Jesse Keating 2f82dd
diff -Naurp linux-2.6-git/drivers/firewire/fw-card.c firewire-git/drivers/firewire/fw-card.c
Jesse Keating 2f82dd
--- linux-2.6-git/drivers/firewire/fw-card.c	2009-01-30 13:39:02.989651512 -0500
Jesse Keating 2f82dd
+++ firewire-git/drivers/firewire/fw-card.c	2009-01-30 13:35:51.859771884 -0500
Jesse Keating 2f82dd
@@ -63,8 +63,7 @@ static int descriptor_count;
Jesse Keating 2f82dd
 #define BIB_CMC			((1) << 30)
Jesse Keating 2f82dd
 #define BIB_IMC			((1) << 31)
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static u32 *
Jesse Keating 2f82dd
-generate_config_rom(struct fw_card *card, size_t *config_rom_length)
Jesse Keating 2f82dd
+static u32 *generate_config_rom(struct fw_card *card, size_t *config_rom_length)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_descriptor *desc;
Jesse Keating 2f82dd
 	static u32 config_rom[256];
Jesse Keating 2f82dd
@@ -128,8 +127,7 @@ generate_config_rom(struct fw_card *card
Jesse Keating 2f82dd
 	return config_rom;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-update_config_roms(void)
Jesse Keating 2f82dd
+static void update_config_roms(void)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_card *card;
Jesse Keating 2f82dd
 	u32 *config_rom;
Jesse Keating 2f82dd
@@ -141,8 +139,7 @@ update_config_roms(void)
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-int
Jesse Keating 2f82dd
-fw_core_add_descriptor(struct fw_descriptor *desc)
Jesse Keating 2f82dd
+int fw_core_add_descriptor(struct fw_descriptor *desc)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	size_t i;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
@@ -171,8 +168,7 @@ fw_core_add_descriptor(struct fw_descrip
Jesse Keating 2f82dd
 	return 0;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-void
Jesse Keating 2f82dd
-fw_core_remove_descriptor(struct fw_descriptor *desc)
Jesse Keating 2f82dd
+void fw_core_remove_descriptor(struct fw_descriptor *desc)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	mutex_lock(&card_mutex);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
@@ -189,8 +185,7 @@ static const char gap_count_table[] = {
Jesse Keating 2f82dd
 	63, 5, 7, 8, 10, 13, 16, 18, 21, 24, 26, 29, 32, 35, 37, 40
Jesse Keating 2f82dd
 };
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-void
Jesse Keating 2f82dd
-fw_schedule_bm_work(struct fw_card *card, unsigned long delay)
Jesse Keating 2f82dd
+void fw_schedule_bm_work(struct fw_card *card, unsigned long delay)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	int scheduled;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
@@ -200,8 +195,7 @@ fw_schedule_bm_work(struct fw_card *card
Jesse Keating 2f82dd
 		fw_card_put(card);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-fw_card_bm_work(struct work_struct *work)
Jesse Keating 2f82dd
+static void fw_card_bm_work(struct work_struct *work)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_card *card = container_of(work, struct fw_card, work.work);
Jesse Keating 2f82dd
 	struct fw_device *root_device;
Jesse Keating 2f82dd
@@ -371,17 +365,16 @@ fw_card_bm_work(struct work_struct *work
Jesse Keating 2f82dd
 	fw_card_put(card);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-flush_timer_callback(unsigned long data)
Jesse Keating 2f82dd
+static void flush_timer_callback(unsigned long data)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_card *card = (struct fw_card *)data;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	fw_flush_transactions(card);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-void
Jesse Keating 2f82dd
-fw_card_initialize(struct fw_card *card, const struct fw_card_driver *driver,
Jesse Keating 2f82dd
-		   struct device *device)
Jesse Keating 2f82dd
+void fw_card_initialize(struct fw_card *card,
Jesse Keating 2f82dd
+			const struct fw_card_driver *driver,
Jesse Keating 2f82dd
+			struct device *device)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	static atomic_t index = ATOMIC_INIT(-1);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
@@ -406,9 +399,8 @@ fw_card_initialize(struct fw_card *card,
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 EXPORT_SYMBOL(fw_card_initialize);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-int
Jesse Keating 2f82dd
-fw_card_add(struct fw_card *card,
Jesse Keating 2f82dd
-	    u32 max_receive, u32 link_speed, u64 guid)
Jesse Keating 2f82dd
+int fw_card_add(struct fw_card *card,
Jesse Keating 2f82dd
+		u32 max_receive, u32 link_speed, u64 guid)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	u32 *config_rom;
Jesse Keating 2f82dd
 	size_t length;
Jesse Keating 2f82dd
@@ -435,23 +427,20 @@ EXPORT_SYMBOL(fw_card_add);
Jesse Keating 2f82dd
  * dummy driver just fails all IO.
Jesse Keating 2f82dd
  */
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static int
Jesse Keating 2f82dd
-dummy_enable(struct fw_card *card, u32 *config_rom, size_t length)
Jesse Keating 2f82dd
+static int dummy_enable(struct fw_card *card, u32 *config_rom, size_t length)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	BUG();
Jesse Keating 2f82dd
 	return -1;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static int
Jesse Keating 2f82dd
-dummy_update_phy_reg(struct fw_card *card, int address,
Jesse Keating 2f82dd
-		     int clear_bits, int set_bits)
Jesse Keating 2f82dd
+static int dummy_update_phy_reg(struct fw_card *card, int address,
Jesse Keating 2f82dd
+				int clear_bits, int set_bits)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	return -ENODEV;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static int
Jesse Keating 2f82dd
-dummy_set_config_rom(struct fw_card *card,
Jesse Keating 2f82dd
-		     u32 *config_rom, size_t length)
Jesse Keating 2f82dd
+static int dummy_set_config_rom(struct fw_card *card,
Jesse Keating 2f82dd
+				u32 *config_rom, size_t length)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	/*
Jesse Keating 2f82dd
 	 * We take the card out of card_list before setting the dummy
Jesse Keating 2f82dd
@@ -461,27 +450,23 @@ dummy_set_config_rom(struct fw_card *car
Jesse Keating 2f82dd
 	return -1;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-dummy_send_request(struct fw_card *card, struct fw_packet *packet)
Jesse Keating 2f82dd
+static void dummy_send_request(struct fw_card *card, struct fw_packet *packet)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	packet->callback(packet, card, -ENODEV);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-dummy_send_response(struct fw_card *card, struct fw_packet *packet)
Jesse Keating 2f82dd
+static void dummy_send_response(struct fw_card *card, struct fw_packet *packet)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	packet->callback(packet, card, -ENODEV);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static int
Jesse Keating 2f82dd
-dummy_cancel_packet(struct fw_card *card, struct fw_packet *packet)
Jesse Keating 2f82dd
+static int dummy_cancel_packet(struct fw_card *card, struct fw_packet *packet)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	return -ENOENT;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static int
Jesse Keating 2f82dd
-dummy_enable_phys_dma(struct fw_card *card,
Jesse Keating 2f82dd
-		      int node_id, int generation)
Jesse Keating 2f82dd
+static int dummy_enable_phys_dma(struct fw_card *card,
Jesse Keating 2f82dd
+				 int node_id, int generation)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	return -ENODEV;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
@@ -496,16 +481,14 @@ static struct fw_card_driver dummy_drive
Jesse Keating 2f82dd
 	.enable_phys_dma = dummy_enable_phys_dma,
Jesse Keating 2f82dd
 };
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-void
Jesse Keating 2f82dd
-fw_card_release(struct kref *kref)
Jesse Keating 2f82dd
+void fw_card_release(struct kref *kref)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_card *card = container_of(kref, struct fw_card, kref);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	complete(&card->done);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-void
Jesse Keating 2f82dd
-fw_core_remove_card(struct fw_card *card)
Jesse Keating 2f82dd
+void fw_core_remove_card(struct fw_card *card)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	card->driver->update_phy_reg(card, 4,
Jesse Keating 2f82dd
 				     PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
Jesse Keating 2f82dd
@@ -529,8 +512,7 @@ fw_core_remove_card(struct fw_card *card
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 EXPORT_SYMBOL(fw_core_remove_card);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-int
Jesse Keating 2f82dd
-fw_core_initiate_bus_reset(struct fw_card *card, int short_reset)
Jesse Keating 2f82dd
+int fw_core_initiate_bus_reset(struct fw_card *card, int short_reset)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	int reg = short_reset ? 5 : 1;
Jesse Keating 2f82dd
 	int bit = short_reset ? PHY_BUS_SHORT_RESET : PHY_BUS_RESET;
Jesse Keating 2f82dd
diff -Naurp linux-2.6-git/drivers/firewire/fw-cdev.c firewire-git/drivers/firewire/fw-cdev.c
Jesse Keating 2f82dd
--- linux-2.6-git/drivers/firewire/fw-cdev.c	2008-11-04 11:19:19.000000000 -0500
Jesse Keating 2f82dd
+++ firewire-git/drivers/firewire/fw-cdev.c	2009-01-30 13:35:51.860646788 -0500
Jesse Keating 2f82dd
@@ -18,87 +18,162 @@
Jesse Keating 2f82dd
  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Jesse Keating 2f82dd
  */
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-#include <linux module.h="">
Jesse Keating 2f82dd
-#include <linux kernel.h="">
Jesse Keating 2f82dd
-#include <linux wait.h="">
Jesse Keating 2f82dd
-#include <linux errno.h="">
Jesse Keating 2f82dd
+#include <linux compat.h="">
Jesse Keating 2f82dd
+#include <linux delay.h="">
Jesse Keating 2f82dd
 #include <linux device.h="">
Jesse Keating 2f82dd
-#include <linux vmalloc.h="">
Jesse Keating 2f82dd
+#include <linux errno.h="">
Jesse Keating 2f82dd
+#include <linux firewire-cdev.h="">
Jesse Keating 2f82dd
+#include <linux idr.h="">
Jesse Keating 2f82dd
+#include <linux jiffies.h="">
Jesse Keating 2f82dd
+#include <linux kernel.h="">
Jesse Keating 2f82dd
+#include <linux kref.h="">
Jesse Keating 2f82dd
+#include <linux mm.h="">
Jesse Keating 2f82dd
+#include <linux module.h="">
Jesse Keating 2f82dd
+#include <linux mutex.h="">
Jesse Keating 2f82dd
 #include <linux poll.h="">
Jesse Keating 2f82dd
 #include <linux preempt.h="">
Jesse Keating 2f82dd
+#include <linux spinlock.h="">
Jesse Keating 2f82dd
 #include <linux time.h="">
Jesse Keating 2f82dd
-#include <linux delay.h="">
Jesse Keating 2f82dd
-#include <linux mm.h="">
Jesse Keating 2f82dd
-#include <linux idr.h="">
Jesse Keating 2f82dd
-#include <linux compat.h="">
Jesse Keating 2f82dd
-#include <linux firewire-cdev.h="">
Jesse Keating 2f82dd
+#include <linux vmalloc.h="">
Jesse Keating 2f82dd
+#include <linux wait.h="">
Jesse Keating 2f82dd
+#include <linux workqueue.h="">
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
 #include <asm system.h="">
Jesse Keating 2f82dd
 #include <asm uaccess.h="">
Jesse Keating 2f82dd
-#include "fw-transaction.h"
Jesse Keating 2f82dd
-#include "fw-topology.h"
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
 #include "fw-device.h"
Jesse Keating 2f82dd
+#include "fw-topology.h"
Jesse Keating 2f82dd
+#include "fw-transaction.h"
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+struct client {
Jesse Keating 2f82dd
+	u32 version;
Jesse Keating 2f82dd
+	struct fw_device *device;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	spinlock_t lock;
Jesse Keating 2f82dd
+	bool in_shutdown;
Jesse Keating 2f82dd
+	struct idr resource_idr;
Jesse Keating 2f82dd
+	struct list_head event_list;
Jesse Keating 2f82dd
+	wait_queue_head_t wait;
Jesse Keating 2f82dd
+	u64 bus_reset_closure;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	struct fw_iso_context *iso_context;
Jesse Keating 2f82dd
+	u64 iso_closure;
Jesse Keating 2f82dd
+	struct fw_iso_buffer buffer;
Jesse Keating 2f82dd
+	unsigned long vm_start;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-struct client;
Jesse Keating 2f82dd
-struct client_resource {
Jesse Keating 2f82dd
 	struct list_head link;
Jesse Keating 2f82dd
-	void (*release)(struct client *client, struct client_resource *r);
Jesse Keating 2f82dd
-	u32 handle;
Jesse Keating 2f82dd
+	struct kref kref;
Jesse Keating 2f82dd
+};
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+static inline void client_get(struct client *client)
Jesse Keating 2f82dd
+{
Jesse Keating 2f82dd
+	kref_get(&client->kref);
Jesse Keating 2f82dd
+}
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+static void client_release(struct kref *kref)
Jesse Keating 2f82dd
+{
Jesse Keating 2f82dd
+	struct client *client = container_of(kref, struct client, kref);
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	fw_device_put(client->device);
Jesse Keating 2f82dd
+	kfree(client);
Jesse Keating 2f82dd
+}
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+static void client_put(struct client *client)
Jesse Keating 2f82dd
+{
Jesse Keating 2f82dd
+	kref_put(&client->kref, client_release);
Jesse Keating 2f82dd
+}
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+struct client_resource;
Jesse Keating 2f82dd
+typedef void (*client_resource_release_fn_t)(struct client *,
Jesse Keating 2f82dd
+					     struct client_resource *);
Jesse Keating 2f82dd
+struct client_resource {
Jesse Keating 2f82dd
+	client_resource_release_fn_t release;
Jesse Keating 2f82dd
+	int handle;
Jesse Keating 2f82dd
+};
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+struct address_handler_resource {
Jesse Keating 2f82dd
+	struct client_resource resource;
Jesse Keating 2f82dd
+	struct fw_address_handler handler;
Jesse Keating 2f82dd
+	__u64 closure;
Jesse Keating 2f82dd
+	struct client *client;
Jesse Keating 2f82dd
+};
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+struct outbound_transaction_resource {
Jesse Keating 2f82dd
+	struct client_resource resource;
Jesse Keating 2f82dd
+	struct fw_transaction transaction;
Jesse Keating 2f82dd
+};
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+struct inbound_transaction_resource {
Jesse Keating 2f82dd
+	struct client_resource resource;
Jesse Keating 2f82dd
+	struct fw_request *request;
Jesse Keating 2f82dd
+	void *data;
Jesse Keating 2f82dd
+	size_t length;
Jesse Keating 2f82dd
 };
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
+struct descriptor_resource {
Jesse Keating 2f82dd
+	struct client_resource resource;
Jesse Keating 2f82dd
+	struct fw_descriptor descriptor;
Jesse Keating 2f82dd
+	u32 data[0];
Jesse Keating 2f82dd
+};
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+struct iso_resource {
Jesse Keating 2f82dd
+	struct client_resource resource;
Jesse Keating 2f82dd
+	struct client *client;
Jesse Keating 2f82dd
+	/* Schedule work and access todo only with client->lock held. */
Jesse Keating 2f82dd
+	struct delayed_work work;
Jesse Keating 2f82dd
+	enum {ISO_RES_ALLOC, ISO_RES_REALLOC, ISO_RES_DEALLOC,
Jesse Keating 2f82dd
+	      ISO_RES_ALLOC_ONCE, ISO_RES_DEALLOC_ONCE,} todo;
Jesse Keating 2f82dd
+	int generation;
Jesse Keating 2f82dd
+	u64 channels;
Jesse Keating 2f82dd
+	s32 bandwidth;
Jesse Keating 2f82dd
+	struct iso_resource_event *e_alloc, *e_dealloc;
Jesse Keating 2f82dd
+};
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+static void schedule_iso_resource(struct iso_resource *);
Jesse Keating 2f82dd
+static void release_iso_resource(struct client *, struct client_resource *);
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
 /*
Jesse Keating 2f82dd
  * dequeue_event() just kfree()'s the event, so the event has to be
Jesse Keating 2f82dd
- * the first field in the struct.
Jesse Keating 2f82dd
+ * the first field in a struct XYZ_event.
Jesse Keating 2f82dd
  */
Jesse Keating 2f82dd
-
Jesse Keating 2f82dd
 struct event {
Jesse Keating 2f82dd
 	struct { void *data; size_t size; } v[2];
Jesse Keating 2f82dd
 	struct list_head link;
Jesse Keating 2f82dd
 };
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-struct bus_reset {
Jesse Keating 2f82dd
+struct bus_reset_event {
Jesse Keating 2f82dd
 	struct event event;
Jesse Keating 2f82dd
 	struct fw_cdev_event_bus_reset reset;
Jesse Keating 2f82dd
 };
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-struct response {
Jesse Keating 2f82dd
+struct outbound_transaction_event {
Jesse Keating 2f82dd
 	struct event event;
Jesse Keating 2f82dd
-	struct fw_transaction transaction;
Jesse Keating 2f82dd
 	struct client *client;
Jesse Keating 2f82dd
-	struct client_resource resource;
Jesse Keating 2f82dd
+	struct outbound_transaction_resource r;
Jesse Keating 2f82dd
 	struct fw_cdev_event_response response;
Jesse Keating 2f82dd
 };
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-struct iso_interrupt {
Jesse Keating 2f82dd
+struct inbound_transaction_event {
Jesse Keating 2f82dd
 	struct event event;
Jesse Keating 2f82dd
-	struct fw_cdev_event_iso_interrupt interrupt;
Jesse Keating 2f82dd
+	struct fw_cdev_event_request request;
Jesse Keating 2f82dd
 };
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-struct client {
Jesse Keating 2f82dd
-	u32 version;
Jesse Keating 2f82dd
-	struct fw_device *device;
Jesse Keating 2f82dd
-	spinlock_t lock;
Jesse Keating 2f82dd
-	u32 resource_handle;
Jesse Keating 2f82dd
-	struct list_head resource_list;
Jesse Keating 2f82dd
-	struct list_head event_list;
Jesse Keating 2f82dd
-	wait_queue_head_t wait;
Jesse Keating 2f82dd
-	u64 bus_reset_closure;
Jesse Keating 2f82dd
-
Jesse Keating 2f82dd
-	struct fw_iso_context *iso_context;
Jesse Keating 2f82dd
-	u64 iso_closure;
Jesse Keating 2f82dd
-	struct fw_iso_buffer buffer;
Jesse Keating 2f82dd
-	unsigned long vm_start;
Jesse Keating 2f82dd
+struct iso_interrupt_event {
Jesse Keating 2f82dd
+	struct event event;
Jesse Keating 2f82dd
+	struct fw_cdev_event_iso_interrupt interrupt;
Jesse Keating 2f82dd
+};
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	struct list_head link;
Jesse Keating 2f82dd
+struct iso_resource_event {
Jesse Keating 2f82dd
+	struct event event;
Jesse Keating 2f82dd
+	struct fw_cdev_event_iso_resource resource;
Jesse Keating 2f82dd
 };
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static inline void __user *
Jesse Keating 2f82dd
-u64_to_uptr(__u64 value)
Jesse Keating 2f82dd
+static inline void __user *u64_to_uptr(__u64 value)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	return (void __user *)(unsigned long)value;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static inline __u64
Jesse Keating 2f82dd
-uptr_to_u64(void __user *ptr)
Jesse Keating 2f82dd
+static inline __u64 uptr_to_u64(void __user *ptr)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	return (__u64)(unsigned long)ptr;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
@@ -107,7 +182,6 @@ static int fw_device_op_open(struct inod
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_device *device;
Jesse Keating 2f82dd
 	struct client *client;
Jesse Keating 2f82dd
-	unsigned long flags;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	device = fw_device_get_by_devt(inode->i_rdev);
Jesse Keating 2f82dd
 	if (device == NULL)
Jesse Keating 2f82dd
@@ -125,16 +199,17 @@ static int fw_device_op_open(struct inod
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	client->device = device;
Jesse Keating 2f82dd
-	INIT_LIST_HEAD(&client->event_list);
Jesse Keating 2f82dd
-	INIT_LIST_HEAD(&client->resource_list);
Jesse Keating 2f82dd
 	spin_lock_init(&client->lock);
Jesse Keating 2f82dd
+	idr_init(&client->resource_idr);
Jesse Keating 2f82dd
+	INIT_LIST_HEAD(&client->event_list);
Jesse Keating 2f82dd
 	init_waitqueue_head(&client->wait);
Jesse Keating 2f82dd
+	kref_init(&client->kref);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	file->private_data = client;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	spin_lock_irqsave(&device->card->lock, flags);
Jesse Keating 2f82dd
+	mutex_lock(&device->client_list_mutex);
Jesse Keating 2f82dd
 	list_add_tail(&client->link, &device->client_list);
Jesse Keating 2f82dd
-	spin_unlock_irqrestore(&device->card->lock, flags);
Jesse Keating 2f82dd
+	mutex_unlock(&device->client_list_mutex);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	return 0;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
@@ -150,68 +225,69 @@ static void queue_event(struct client *c
Jesse Keating 2f82dd
 	event->v[1].size = size1;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	spin_lock_irqsave(&client->lock, flags);
Jesse Keating 2f82dd
-	list_add_tail(&event->link, &client->event_list);
Jesse Keating 2f82dd
+	if (client->in_shutdown)
Jesse Keating 2f82dd
+		kfree(event);
Jesse Keating 2f82dd
+	else
Jesse Keating 2f82dd
+		list_add_tail(&event->link, &client->event_list);
Jesse Keating 2f82dd
 	spin_unlock_irqrestore(&client->lock, flags);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	wake_up_interruptible(&client->wait);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static int
Jesse Keating 2f82dd
-dequeue_event(struct client *client, char __user *buffer, size_t count)
Jesse Keating 2f82dd
+static int dequeue_event(struct client *client,
Jesse Keating 2f82dd
+			 char __user *buffer, size_t count)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
-	unsigned long flags;
Jesse Keating 2f82dd
 	struct event *event;
Jesse Keating 2f82dd
 	size_t size, total;
Jesse Keating 2f82dd
-	int i, retval;
Jesse Keating 2f82dd
+	int i, ret;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	retval = wait_event_interruptible(client->wait,
Jesse Keating 2f82dd
-					  !list_empty(&client->event_list) ||
Jesse Keating 2f82dd
-					  fw_device_is_shutdown(client->device));
Jesse Keating 2f82dd
-	if (retval < 0)
Jesse Keating 2f82dd
-		return retval;
Jesse Keating 2f82dd
+	ret = wait_event_interruptible(client->wait,
Jesse Keating 2f82dd
+			!list_empty(&client->event_list) ||
Jesse Keating 2f82dd
+			fw_device_is_shutdown(client->device));
Jesse Keating 2f82dd
+	if (ret < 0)
Jesse Keating 2f82dd
+		return ret;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	if (list_empty(&client->event_list) &&
Jesse Keating 2f82dd
 		       fw_device_is_shutdown(client->device))
Jesse Keating 2f82dd
 		return -ENODEV;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	spin_lock_irqsave(&client->lock, flags);
Jesse Keating 2f82dd
-	event = container_of(client->event_list.next, struct event, link);
Jesse Keating 2f82dd
+	spin_lock_irq(&client->lock);
Jesse Keating 2f82dd
+	event = list_first_entry(&client->event_list, struct event, link);
Jesse Keating 2f82dd
 	list_del(&event->link);
Jesse Keating 2f82dd
-	spin_unlock_irqrestore(&client->lock, flags);
Jesse Keating 2f82dd
+	spin_unlock_irq(&client->lock);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	total = 0;
Jesse Keating 2f82dd
 	for (i = 0; i < ARRAY_SIZE(event->v) && total < count; i++) {
Jesse Keating 2f82dd
 		size = min(event->v[i].size, count - total);
Jesse Keating 2f82dd
 		if (copy_to_user(buffer + total, event->v[i].data, size)) {
Jesse Keating 2f82dd
-			retval = -EFAULT;
Jesse Keating 2f82dd
+			ret = -EFAULT;
Jesse Keating 2f82dd
 			goto out;
Jesse Keating 2f82dd
 		}
Jesse Keating 2f82dd
 		total += size;
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
-	retval = total;
Jesse Keating 2f82dd
+	ret = total;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
  out:
Jesse Keating 2f82dd
 	kfree(event);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	return retval;
Jesse Keating 2f82dd
+	return ret;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static ssize_t
Jesse Keating 2f82dd
-fw_device_op_read(struct file *file,
Jesse Keating 2f82dd
-		  char __user *buffer, size_t count, loff_t *offset)
Jesse Keating 2f82dd
+static ssize_t fw_device_op_read(struct file *file, char __user *buffer,
Jesse Keating 2f82dd
+				 size_t count, loff_t *offset)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct client *client = file->private_data;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	return dequeue_event(client, buffer, count);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-/* caller must hold card->lock so that node pointers can be dereferenced here */
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-fill_bus_reset_event(struct fw_cdev_event_bus_reset *event,
Jesse Keating 2f82dd
-		     struct client *client)
Jesse Keating 2f82dd
+static void fill_bus_reset_event(struct fw_cdev_event_bus_reset *event,
Jesse Keating 2f82dd
+				 struct client *client)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_card *card = client->device->card;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
+	spin_lock_irq(&card->lock);
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
 	event->closure	     = client->bus_reset_closure;
Jesse Keating 2f82dd
 	event->type          = FW_CDEV_EVENT_BUS_RESET;
Jesse Keating 2f82dd
 	event->generation    = client->device->generation;
Jesse Keating 2f82dd
@@ -220,39 +296,49 @@ fill_bus_reset_event(struct fw_cdev_even
Jesse Keating 2f82dd
 	event->bm_node_id    = 0; /* FIXME: We don't track the BM. */
Jesse Keating 2f82dd
 	event->irm_node_id   = card->irm_node->node_id;
Jesse Keating 2f82dd
 	event->root_node_id  = card->root_node->node_id;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	spin_unlock_irq(&card->lock);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-for_each_client(struct fw_device *device,
Jesse Keating 2f82dd
-		void (*callback)(struct client *client))
Jesse Keating 2f82dd
+static void for_each_client(struct fw_device *device,
Jesse Keating 2f82dd
+			    void (*callback)(struct client *client))
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
-	struct fw_card *card = device->card;
Jesse Keating 2f82dd
 	struct client *c;
Jesse Keating 2f82dd
-	unsigned long flags;
Jesse Keating 2f82dd
-
Jesse Keating 2f82dd
-	spin_lock_irqsave(&card->lock, flags);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
+	mutex_lock(&device->client_list_mutex);
Jesse Keating 2f82dd
 	list_for_each_entry(c, &device->client_list, link)
Jesse Keating 2f82dd
 		callback(c);
Jesse Keating 2f82dd
+	mutex_unlock(&device->client_list_mutex);
Jesse Keating 2f82dd
+}
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+static int schedule_reallocations(int id, void *p, void *data)
Jesse Keating 2f82dd
+{
Jesse Keating 2f82dd
+	struct client_resource *r = p;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	spin_unlock_irqrestore(&card->lock, flags);
Jesse Keating 2f82dd
+	if (r->release == release_iso_resource)
Jesse Keating 2f82dd
+		schedule_iso_resource(container_of(r,
Jesse Keating 2f82dd
+					struct iso_resource, resource));
Jesse Keating 2f82dd
+	return 0;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-queue_bus_reset_event(struct client *client)
Jesse Keating 2f82dd
+static void queue_bus_reset_event(struct client *client)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
-	struct bus_reset *bus_reset;
Jesse Keating 2f82dd
+	struct bus_reset_event *e;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	bus_reset = kzalloc(sizeof(*bus_reset), GFP_ATOMIC);
Jesse Keating 2f82dd
-	if (bus_reset == NULL) {
Jesse Keating 2f82dd
+	e = kzalloc(sizeof(*e), GFP_KERNEL);
Jesse Keating 2f82dd
+	if (e == NULL) {
Jesse Keating 2f82dd
 		fw_notify("Out of memory when allocating bus reset event\n");
Jesse Keating 2f82dd
 		return;
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	fill_bus_reset_event(&bus_reset->reset, client);
Jesse Keating 2f82dd
+	fill_bus_reset_event(&e->reset, client);
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	queue_event(client, &e->event,
Jesse Keating 2f82dd
+		    &e->reset, sizeof(e->reset), NULL, 0);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	queue_event(client, &bus_reset->event,
Jesse Keating 2f82dd
-		    &bus_reset->reset, sizeof(bus_reset->reset), NULL, 0);
Jesse Keating 2f82dd
+	spin_lock_irq(&client->lock);
Jesse Keating 2f82dd
+	idr_for_each(&client->resource_idr, schedule_reallocations, client);
Jesse Keating 2f82dd
+	spin_unlock_irq(&client->lock);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 void fw_device_cdev_update(struct fw_device *device)
Jesse Keating 2f82dd
@@ -274,11 +360,11 @@ static int ioctl_get_info(struct client 
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_cdev_get_info *get_info = buffer;
Jesse Keating 2f82dd
 	struct fw_cdev_event_bus_reset bus_reset;
Jesse Keating 2f82dd
-	struct fw_card *card = client->device->card;
Jesse Keating 2f82dd
 	unsigned long ret = 0;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	client->version = get_info->version;
Jesse Keating 2f82dd
 	get_info->version = FW_CDEV_VERSION;
Jesse Keating 2f82dd
+	get_info->card = client->device->card->index;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	down_read(&fw_device_rwsem);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
@@ -300,49 +386,61 @@ static int ioctl_get_info(struct client 
Jesse Keating 2f82dd
 	client->bus_reset_closure = get_info->bus_reset_closure;
Jesse Keating 2f82dd
 	if (get_info->bus_reset != 0) {
Jesse Keating 2f82dd
 		void __user *uptr = u64_to_uptr(get_info->bus_reset);
Jesse Keating 2f82dd
-		unsigned long flags;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-		spin_lock_irqsave(&card->lock, flags);
Jesse Keating 2f82dd
 		fill_bus_reset_event(&bus_reset, client);
Jesse Keating 2f82dd
-		spin_unlock_irqrestore(&card->lock, flags);
Jesse Keating 2f82dd
-
Jesse Keating 2f82dd
 		if (copy_to_user(uptr, &bus_reset, sizeof(bus_reset)))
Jesse Keating 2f82dd
 			return -EFAULT;
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	get_info->card = card->index;
Jesse Keating 2f82dd
-
Jesse Keating 2f82dd
 	return 0;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-add_client_resource(struct client *client, struct client_resource *resource)
Jesse Keating 2f82dd
+static int add_client_resource(struct client *client,
Jesse Keating 2f82dd
+			       struct client_resource *resource, gfp_t gfp_mask)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	unsigned long flags;
Jesse Keating 2f82dd
+	int ret;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+ retry:
Jesse Keating 2f82dd
+	if (idr_pre_get(&client->resource_idr, gfp_mask | __GFP_ZERO) == 0)
Jesse Keating 2f82dd
+		return -ENOMEM;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	spin_lock_irqsave(&client->lock, flags);
Jesse Keating 2f82dd
-	list_add_tail(&resource->link, &client->resource_list);
Jesse Keating 2f82dd
-	resource->handle = client->resource_handle++;
Jesse Keating 2f82dd
+	if (client->in_shutdown)
Jesse Keating 2f82dd
+		ret = -ECANCELED;
Jesse Keating 2f82dd
+	else
Jesse Keating 2f82dd
+		ret = idr_get_new(&client->resource_idr, resource,
Jesse Keating 2f82dd
+				  &resource->handle);
Jesse Keating 2f82dd
+	if (ret >= 0) {
Jesse Keating 2f82dd
+		client_get(client);
Jesse Keating 2f82dd
+		if (resource->release == release_iso_resource)
Jesse Keating 2f82dd
+			schedule_iso_resource(container_of(resource,
Jesse Keating 2f82dd
+						struct iso_resource, resource));
Jesse Keating 2f82dd
+	}
Jesse Keating 2f82dd
 	spin_unlock_irqrestore(&client->lock, flags);
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	if (ret == -EAGAIN)
Jesse Keating 2f82dd
+		goto retry;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	return ret < 0 ? ret : 0;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static int
Jesse Keating 2f82dd
-release_client_resource(struct client *client, u32 handle,
Jesse Keating 2f82dd
-			struct client_resource **resource)
Jesse Keating 2f82dd
+static int release_client_resource(struct client *client, u32 handle,
Jesse Keating 2f82dd
+				   client_resource_release_fn_t release,
Jesse Keating 2f82dd
+				   struct client_resource **resource)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct client_resource *r;
Jesse Keating 2f82dd
-	unsigned long flags;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	spin_lock_irqsave(&client->lock, flags);
Jesse Keating 2f82dd
-	list_for_each_entry(r, &client->resource_list, link) {
Jesse Keating 2f82dd
-		if (r->handle == handle) {
Jesse Keating 2f82dd
-			list_del(&r->link);
Jesse Keating 2f82dd
-			break;
Jesse Keating 2f82dd
-		}
Jesse Keating 2f82dd
-	}
Jesse Keating 2f82dd
-	spin_unlock_irqrestore(&client->lock, flags);
Jesse Keating 2f82dd
+	spin_lock_irq(&client->lock);
Jesse Keating 2f82dd
+	if (client->in_shutdown)
Jesse Keating 2f82dd
+		r = NULL;
Jesse Keating 2f82dd
+	else
Jesse Keating 2f82dd
+		r = idr_find(&client->resource_idr, handle);
Jesse Keating 2f82dd
+	if (r && r->release == release)
Jesse Keating 2f82dd
+		idr_remove(&client->resource_idr, handle);
Jesse Keating 2f82dd
+	spin_unlock_irq(&client->lock);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	if (&r->link == &client->resource_list)
Jesse Keating 2f82dd
+	if (!(r && r->release == release))
Jesse Keating 2f82dd
 		return -EINVAL;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	if (resource)
Jesse Keating 2f82dd
@@ -350,203 +448,242 @@ release_client_resource(struct client *c
Jesse Keating 2f82dd
 	else
Jesse Keating 2f82dd
 		r->release(client, r);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
+	client_put(client);
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
 	return 0;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-release_transaction(struct client *client, struct client_resource *resource)
Jesse Keating 2f82dd
+static void release_transaction(struct client *client,
Jesse Keating 2f82dd
+				struct client_resource *resource)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
-	struct response *response =
Jesse Keating 2f82dd
-		container_of(resource, struct response, resource);
Jesse Keating 2f82dd
+	struct outbound_transaction_resource *r = container_of(resource,
Jesse Keating 2f82dd
+			struct outbound_transaction_resource, resource);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	fw_cancel_transaction(client->device->card, &response->transaction);
Jesse Keating 2f82dd
+	fw_cancel_transaction(client->device->card, &r->transaction);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-complete_transaction(struct fw_card *card, int rcode,
Jesse Keating 2f82dd
-		     void *payload, size_t length, void *data)
Jesse Keating 2f82dd
+static void complete_transaction(struct fw_card *card, int rcode,
Jesse Keating 2f82dd
+				 void *payload, size_t length, void *data)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
-	struct response *response = data;
Jesse Keating 2f82dd
-	struct client *client = response->client;
Jesse Keating 2f82dd
+	struct outbound_transaction_event *e = data;
Jesse Keating 2f82dd
+	struct fw_cdev_event_response *rsp = &e->response;
Jesse Keating 2f82dd
+	struct client *client = e->client;
Jesse Keating 2f82dd
 	unsigned long flags;
Jesse Keating 2f82dd
-	struct fw_cdev_event_response *r = &response->response;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	if (length < r->length)
Jesse Keating 2f82dd
-		r->length = length;
Jesse Keating 2f82dd
+	if (length < rsp->length)
Jesse Keating 2f82dd
+		rsp->length = length;
Jesse Keating 2f82dd
 	if (rcode == RCODE_COMPLETE)
Jesse Keating 2f82dd
-		memcpy(r->data, payload, r->length);
Jesse Keating 2f82dd
+		memcpy(rsp->data, payload, rsp->length);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	spin_lock_irqsave(&client->lock, flags);
Jesse Keating 2f82dd
-	list_del(&response->resource.link);
Jesse Keating 2f82dd
+	/*
Jesse Keating 2f82dd
+	 * 1. If called while in shutdown, the idr tree must be left untouched.
Jesse Keating 2f82dd
+	 *    The idr handle will be removed and the client reference will be
Jesse Keating 2f82dd
+	 *    dropped later.
Jesse Keating 2f82dd
+	 * 2. If the call chain was release_client_resource ->
Jesse Keating 2f82dd
+	 *    release_transaction -> complete_transaction (instead of a normal
Jesse Keating 2f82dd
+	 *    conclusion of the transaction), i.e. if this resource was already
Jesse Keating 2f82dd
+	 *    unregistered from the idr, the client reference will be dropped
Jesse Keating 2f82dd
+	 *    by release_client_resource and we must not drop it here.
Jesse Keating 2f82dd
+	 */
Jesse Keating 2f82dd
+	if (!client->in_shutdown &&
Jesse Keating 2f82dd
+	    idr_find(&client->resource_idr, e->r.resource.handle)) {
Jesse Keating 2f82dd
+		idr_remove(&client->resource_idr, e->r.resource.handle);
Jesse Keating 2f82dd
+		/* Drop the idr's reference */
Jesse Keating 2f82dd
+		client_put(client);
Jesse Keating 2f82dd
+	}
Jesse Keating 2f82dd
 	spin_unlock_irqrestore(&client->lock, flags);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	r->type   = FW_CDEV_EVENT_RESPONSE;
Jesse Keating 2f82dd
-	r->rcode  = rcode;
Jesse Keating 2f82dd
+	rsp->type = FW_CDEV_EVENT_RESPONSE;
Jesse Keating 2f82dd
+	rsp->rcode = rcode;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	/*
Jesse Keating 2f82dd
-	 * In the case that sizeof(*r) doesn't align with the position of the
Jesse Keating 2f82dd
+	 * In the case that sizeof(*rsp) doesn't align with the position of the
Jesse Keating 2f82dd
 	 * data, and the read is short, preserve an extra copy of the data
Jesse Keating 2f82dd
 	 * to stay compatible with a pre-2.6.27 bug.  Since the bug is harmless
Jesse Keating 2f82dd
 	 * for short reads and some apps depended on it, this is both safe
Jesse Keating 2f82dd
 	 * and prudent for compatibility.
Jesse Keating 2f82dd
 	 */
Jesse Keating 2f82dd
-	if (r->length <= sizeof(*r) - offsetof(typeof(*r), data))
Jesse Keating 2f82dd
-		queue_event(client, &response->event, r, sizeof(*r),
Jesse Keating 2f82dd
-			    r->data, r->length);
Jesse Keating 2f82dd
+	if (rsp->length <= sizeof(*rsp) - offsetof(typeof(*rsp), data))
Jesse Keating 2f82dd
+		queue_event(client, &e->event, rsp, sizeof(*rsp),
Jesse Keating 2f82dd
+			    rsp->data, rsp->length);
Jesse Keating 2f82dd
 	else
Jesse Keating 2f82dd
-		queue_event(client, &response->event, r, sizeof(*r) + r->length,
Jesse Keating 2f82dd
+		queue_event(client, &e->event, rsp, sizeof(*rsp) + rsp->length,
Jesse Keating 2f82dd
 			    NULL, 0);
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	/* Drop the transaction callback's reference */
Jesse Keating 2f82dd
+	client_put(client);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static int ioctl_send_request(struct client *client, void *buffer)
Jesse Keating 2f82dd
+static int init_request(struct client *client,
Jesse Keating 2f82dd
+			struct fw_cdev_send_request *request,
Jesse Keating 2f82dd
+			int destination_id, int speed)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
-	struct fw_device *device = client->device;
Jesse Keating 2f82dd
-	struct fw_cdev_send_request *request = buffer;
Jesse Keating 2f82dd
-	struct response *response;
Jesse Keating 2f82dd
+	struct outbound_transaction_event *e;
Jesse Keating 2f82dd
+	int ret;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	/* What is the biggest size we'll accept, really? */
Jesse Keating 2f82dd
-	if (request->length > 4096)
Jesse Keating 2f82dd
-		return -EINVAL;
Jesse Keating 2f82dd
+	if (request->length > 4096 || request->length > 512 << speed)
Jesse Keating 2f82dd
+		return -EIO;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	response = kmalloc(sizeof(*response) + request->length, GFP_KERNEL);
Jesse Keating 2f82dd
-	if (response == NULL)
Jesse Keating 2f82dd
+	e = kmalloc(sizeof(*e) + request->length, GFP_KERNEL);
Jesse Keating 2f82dd
+	if (e == NULL)
Jesse Keating 2f82dd
 		return -ENOMEM;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	response->client = client;
Jesse Keating 2f82dd
-	response->response.length = request->length;
Jesse Keating 2f82dd
-	response->response.closure = request->closure;
Jesse Keating 2f82dd
+	e->client = client;
Jesse Keating 2f82dd
+	e->response.length = request->length;
Jesse Keating 2f82dd
+	e->response.closure = request->closure;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	if (request->data &&
Jesse Keating 2f82dd
-	    copy_from_user(response->response.data,
Jesse Keating 2f82dd
+	    copy_from_user(e->response.data,
Jesse Keating 2f82dd
 			   u64_to_uptr(request->data), request->length)) {
Jesse Keating 2f82dd
-		kfree(response);
Jesse Keating 2f82dd
-		return -EFAULT;
Jesse Keating 2f82dd
+		ret = -EFAULT;
Jesse Keating 2f82dd
+		goto failed;
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	response->resource.release = release_transaction;
Jesse Keating 2f82dd
-	add_client_resource(client, &response->resource);
Jesse Keating 2f82dd
-
Jesse Keating 2f82dd
-	fw_send_request(device->card, &response->transaction,
Jesse Keating 2f82dd
-			request->tcode & 0x1f,
Jesse Keating 2f82dd
-			device->node->node_id,
Jesse Keating 2f82dd
-			request->generation,
Jesse Keating 2f82dd
-			device->max_speed,
Jesse Keating 2f82dd
-			request->offset,
Jesse Keating 2f82dd
-			response->response.data, request->length,
Jesse Keating 2f82dd
-			complete_transaction, response);
Jesse Keating 2f82dd
+	e->r.resource.release = release_transaction;
Jesse Keating 2f82dd
+	ret = add_client_resource(client, &e->r.resource, GFP_KERNEL);
Jesse Keating 2f82dd
+	if (ret < 0)
Jesse Keating 2f82dd
+		goto failed;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	/* Get a reference for the transaction callback */
Jesse Keating 2f82dd
+	client_get(client);
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	fw_send_request(client->device->card, &e->r.transaction,
Jesse Keating 2f82dd
+			request->tcode & 0x1f, destination_id,
Jesse Keating 2f82dd
+			request->generation, speed, request->offset,
Jesse Keating 2f82dd
+			e->response.data, request->length,
Jesse Keating 2f82dd
+			complete_transaction, e);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	if (request->data)
Jesse Keating 2f82dd
 		return sizeof(request) + request->length;
Jesse Keating 2f82dd
 	else
Jesse Keating 2f82dd
 		return sizeof(request);
Jesse Keating 2f82dd
+ failed:
Jesse Keating 2f82dd
+	kfree(e);
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	return ret;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-struct address_handler {
Jesse Keating 2f82dd
-	struct fw_address_handler handler;
Jesse Keating 2f82dd
-	__u64 closure;
Jesse Keating 2f82dd
-	struct client *client;
Jesse Keating 2f82dd
-	struct client_resource resource;
Jesse Keating 2f82dd
-};
Jesse Keating 2f82dd
+static int ioctl_send_request(struct client *client, void *buffer)
Jesse Keating 2f82dd
+{
Jesse Keating 2f82dd
+	struct fw_cdev_send_request *request = buffer;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-struct request {
Jesse Keating 2f82dd
-	struct fw_request *request;
Jesse Keating 2f82dd
-	void *data;
Jesse Keating 2f82dd
-	size_t length;
Jesse Keating 2f82dd
-	struct client_resource resource;
Jesse Keating 2f82dd
-};
Jesse Keating 2f82dd
+	switch (request->tcode) {
Jesse Keating 2f82dd
+	case TCODE_WRITE_QUADLET_REQUEST:
Jesse Keating 2f82dd
+	case TCODE_WRITE_BLOCK_REQUEST:
Jesse Keating 2f82dd
+	case TCODE_READ_QUADLET_REQUEST:
Jesse Keating 2f82dd
+	case TCODE_READ_BLOCK_REQUEST:
Jesse Keating 2f82dd
+	case TCODE_LOCK_MASK_SWAP:
Jesse Keating 2f82dd
+	case TCODE_LOCK_COMPARE_SWAP:
Jesse Keating 2f82dd
+	case TCODE_LOCK_FETCH_ADD:
Jesse Keating 2f82dd
+	case TCODE_LOCK_LITTLE_ADD:
Jesse Keating 2f82dd
+	case TCODE_LOCK_BOUNDED_ADD:
Jesse Keating 2f82dd
+	case TCODE_LOCK_WRAP_ADD:
Jesse Keating 2f82dd
+	case TCODE_LOCK_VENDOR_DEPENDENT:
Jesse Keating 2f82dd
+		break;
Jesse Keating 2f82dd
+	default:
Jesse Keating 2f82dd
+		return -EINVAL;
Jesse Keating 2f82dd
+	}
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-struct request_event {
Jesse Keating 2f82dd
-	struct event event;
Jesse Keating 2f82dd
-	struct fw_cdev_event_request request;
Jesse Keating 2f82dd
-};
Jesse Keating 2f82dd
+	return init_request(client, request, client->device->node->node_id,
Jesse Keating 2f82dd
+			    client->device->max_speed);
Jesse Keating 2f82dd
+}
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-release_request(struct client *client, struct client_resource *resource)
Jesse Keating 2f82dd
+static void release_request(struct client *client,
Jesse Keating 2f82dd
+			    struct client_resource *resource)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
-	struct request *request =
Jesse Keating 2f82dd
-		container_of(resource, struct request, resource);
Jesse Keating 2f82dd
+	struct inbound_transaction_resource *r = container_of(resource,
Jesse Keating 2f82dd
+			struct inbound_transaction_resource, resource);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	fw_send_response(client->device->card, request->request,
Jesse Keating 2f82dd
+	fw_send_response(client->device->card, r->request,
Jesse Keating 2f82dd
 			 RCODE_CONFLICT_ERROR);
Jesse Keating 2f82dd
-	kfree(request);
Jesse Keating 2f82dd
+	kfree(r);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-handle_request(struct fw_card *card, struct fw_request *r,
Jesse Keating 2f82dd
-	       int tcode, int destination, int source,
Jesse Keating 2f82dd
-	       int generation, int speed,
Jesse Keating 2f82dd
-	       unsigned long long offset,
Jesse Keating 2f82dd
-	       void *payload, size_t length, void *callback_data)
Jesse Keating 2f82dd
-{
Jesse Keating 2f82dd
-	struct address_handler *handler = callback_data;
Jesse Keating 2f82dd
-	struct request *request;
Jesse Keating 2f82dd
-	struct request_event *e;
Jesse Keating 2f82dd
-	struct client *client = handler->client;
Jesse Keating 2f82dd
+static void handle_request(struct fw_card *card, struct fw_request *request,
Jesse Keating 2f82dd
+			   int tcode, int destination, int source,
Jesse Keating 2f82dd
+			   int generation, int speed,
Jesse Keating 2f82dd
+			   unsigned long long offset,
Jesse Keating 2f82dd
+			   void *payload, size_t length, void *callback_data)
Jesse Keating 2f82dd
+{
Jesse Keating 2f82dd
+	struct address_handler_resource *handler = callback_data;
Jesse Keating 2f82dd
+	struct inbound_transaction_resource *r;
Jesse Keating 2f82dd
+	struct inbound_transaction_event *e;
Jesse Keating 2f82dd
+	int ret;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	request = kmalloc(sizeof(*request), GFP_ATOMIC);
Jesse Keating 2f82dd
+	r = kmalloc(sizeof(*r), GFP_ATOMIC);
Jesse Keating 2f82dd
 	e = kmalloc(sizeof(*e), GFP_ATOMIC);
Jesse Keating 2f82dd
-	if (request == NULL || e == NULL) {
Jesse Keating 2f82dd
-		kfree(request);
Jesse Keating 2f82dd
-		kfree(e);
Jesse Keating 2f82dd
-		fw_send_response(card, r, RCODE_CONFLICT_ERROR);
Jesse Keating 2f82dd
-		return;
Jesse Keating 2f82dd
-	}
Jesse Keating 2f82dd
-
Jesse Keating 2f82dd
-	request->request = r;
Jesse Keating 2f82dd
-	request->data    = payload;
Jesse Keating 2f82dd
-	request->length  = length;
Jesse Keating 2f82dd
+	if (r == NULL || e == NULL)
Jesse Keating 2f82dd
+		goto failed;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	request->resource.release = release_request;
Jesse Keating 2f82dd
-	add_client_resource(client, &request->resource);
Jesse Keating 2f82dd
+	r->request = request;
Jesse Keating 2f82dd
+	r->data    = payload;
Jesse Keating 2f82dd
+	r->length  = length;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	r->resource.release = release_request;
Jesse Keating 2f82dd
+	ret = add_client_resource(handler->client, &r->resource, GFP_ATOMIC);
Jesse Keating 2f82dd
+	if (ret < 0)
Jesse Keating 2f82dd
+		goto failed;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	e->request.type    = FW_CDEV_EVENT_REQUEST;
Jesse Keating 2f82dd
 	e->request.tcode   = tcode;
Jesse Keating 2f82dd
 	e->request.offset  = offset;
Jesse Keating 2f82dd
 	e->request.length  = length;
Jesse Keating 2f82dd
-	e->request.handle  = request->resource.handle;
Jesse Keating 2f82dd
+	e->request.handle  = r->resource.handle;
Jesse Keating 2f82dd
 	e->request.closure = handler->closure;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	queue_event(client, &e->event,
Jesse Keating 2f82dd
+	queue_event(handler->client, &e->event,
Jesse Keating 2f82dd
 		    &e->request, sizeof(e->request), payload, length);
Jesse Keating 2f82dd
+	return;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+ failed:
Jesse Keating 2f82dd
+	kfree(r);
Jesse Keating 2f82dd
+	kfree(e);
Jesse Keating 2f82dd
+	fw_send_response(card, request, RCODE_CONFLICT_ERROR);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-release_address_handler(struct client *client,
Jesse Keating 2f82dd
-			struct client_resource *resource)
Jesse Keating 2f82dd
+static void release_address_handler(struct client *client,
Jesse Keating 2f82dd
+				    struct client_resource *resource)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
-	struct address_handler *handler =
Jesse Keating 2f82dd
-		container_of(resource, struct address_handler, resource);
Jesse Keating 2f82dd
+	struct address_handler_resource *r =
Jesse Keating 2f82dd
+	    container_of(resource, struct address_handler_resource, resource);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	fw_core_remove_address_handler(&handler->handler);
Jesse Keating 2f82dd
-	kfree(handler);
Jesse Keating 2f82dd
+	fw_core_remove_address_handler(&r->handler);
Jesse Keating 2f82dd
+	kfree(r);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 static int ioctl_allocate(struct client *client, void *buffer)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_cdev_allocate *request = buffer;
Jesse Keating 2f82dd
-	struct address_handler *handler;
Jesse Keating 2f82dd
+	struct address_handler_resource *r;
Jesse Keating 2f82dd
 	struct fw_address_region region;
Jesse Keating 2f82dd
+	int ret;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	handler = kmalloc(sizeof(*handler), GFP_KERNEL);
Jesse Keating 2f82dd
-	if (handler == NULL)
Jesse Keating 2f82dd
+	r = kmalloc(sizeof(*r), GFP_KERNEL);
Jesse Keating 2f82dd
+	if (r == NULL)
Jesse Keating 2f82dd
 		return -ENOMEM;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	region.start = request->offset;
Jesse Keating 2f82dd
 	region.end = request->offset + request->length;
Jesse Keating 2f82dd
-	handler->handler.length = request->length;
Jesse Keating 2f82dd
-	handler->handler.address_callback = handle_request;
Jesse Keating 2f82dd
-	handler->handler.callback_data = handler;
Jesse Keating 2f82dd
-	handler->closure = request->closure;
Jesse Keating 2f82dd
-	handler->client = client;
Jesse Keating 2f82dd
-
Jesse Keating 2f82dd
-	if (fw_core_add_address_handler(&handler->handler, ®ion) < 0) {
Jesse Keating 2f82dd
-		kfree(handler);
Jesse Keating 2f82dd
-		return -EBUSY;
Jesse Keating 2f82dd
+	r->handler.length = request->length;
Jesse Keating 2f82dd
+	r->handler.address_callback = handle_request;
Jesse Keating 2f82dd
+	r->handler.callback_data = r;
Jesse Keating 2f82dd
+	r->closure = request->closure;
Jesse Keating 2f82dd
+	r->client = client;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	ret = fw_core_add_address_handler(&r->handler, ®ion);
Jesse Keating 2f82dd
+	if (ret < 0) {
Jesse Keating 2f82dd
+		kfree(r);
Jesse Keating 2f82dd
+		return ret;
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	handler->resource.release = release_address_handler;
Jesse Keating 2f82dd
-	add_client_resource(client, &handler->resource);
Jesse Keating 2f82dd
-	request->handle = handler->resource.handle;
Jesse Keating 2f82dd
+	r->resource.release = release_address_handler;
Jesse Keating 2f82dd
+	ret = add_client_resource(client, &r->resource, GFP_KERNEL);
Jesse Keating 2f82dd
+	if (ret < 0) {
Jesse Keating 2f82dd
+		release_address_handler(client, &r->resource);
Jesse Keating 2f82dd
+		return ret;
Jesse Keating 2f82dd
+	}
Jesse Keating 2f82dd
+	request->handle = r->resource.handle;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	return 0;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
@@ -555,18 +692,22 @@ static int ioctl_deallocate(struct clien
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_cdev_deallocate *request = buffer;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	return release_client_resource(client, request->handle, NULL);
Jesse Keating 2f82dd
+	return release_client_resource(client, request->handle,
Jesse Keating 2f82dd
+				       release_address_handler, NULL);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 static int ioctl_send_response(struct client *client, void *buffer)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_cdev_send_response *request = buffer;
Jesse Keating 2f82dd
 	struct client_resource *resource;
Jesse Keating 2f82dd
-	struct request *r;
Jesse Keating 2f82dd
+	struct inbound_transaction_resource *r;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	if (release_client_resource(client, request->handle, &resource) < 0)
Jesse Keating 2f82dd
+	if (release_client_resource(client, request->handle,
Jesse Keating 2f82dd
+				    release_request, &resource) < 0)
Jesse Keating 2f82dd
 		return -EINVAL;
Jesse Keating 2f82dd
-	r = container_of(resource, struct request, resource);
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	r = container_of(resource, struct inbound_transaction_resource,
Jesse Keating 2f82dd
+			 resource);
Jesse Keating 2f82dd
 	if (request->length < r->length)
Jesse Keating 2f82dd
 		r->length = request->length;
Jesse Keating 2f82dd
 	if (copy_from_user(r->data, u64_to_uptr(request->data), r->length))
Jesse Keating 2f82dd
@@ -588,85 +729,84 @@ static int ioctl_initiate_bus_reset(stru
Jesse Keating 2f82dd
 	return fw_core_initiate_bus_reset(client->device->card, short_reset);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-struct descriptor {
Jesse Keating 2f82dd
-	struct fw_descriptor d;
Jesse Keating 2f82dd
-	struct client_resource resource;
Jesse Keating 2f82dd
-	u32 data[0];
Jesse Keating 2f82dd
-};
Jesse Keating 2f82dd
-
Jesse Keating 2f82dd
 static void release_descriptor(struct client *client,
Jesse Keating 2f82dd
 			       struct client_resource *resource)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
-	struct descriptor *descriptor =
Jesse Keating 2f82dd
-		container_of(resource, struct descriptor, resource);
Jesse Keating 2f82dd
+	struct descriptor_resource *r =
Jesse Keating 2f82dd
+		container_of(resource, struct descriptor_resource, resource);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	fw_core_remove_descriptor(&descriptor->d);
Jesse Keating 2f82dd
-	kfree(descriptor);
Jesse Keating 2f82dd
+	fw_core_remove_descriptor(&r->descriptor);
Jesse Keating 2f82dd
+	kfree(r);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 static int ioctl_add_descriptor(struct client *client, void *buffer)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_cdev_add_descriptor *request = buffer;
Jesse Keating 2f82dd
-	struct descriptor *descriptor;
Jesse Keating 2f82dd
-	int retval;
Jesse Keating 2f82dd
+	struct descriptor_resource *r;
Jesse Keating 2f82dd
+	int ret;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	if (request->length > 256)
Jesse Keating 2f82dd
 		return -EINVAL;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	descriptor =
Jesse Keating 2f82dd
-		kmalloc(sizeof(*descriptor) + request->length * 4, GFP_KERNEL);
Jesse Keating 2f82dd
-	if (descriptor == NULL)
Jesse Keating 2f82dd
+	r = kmalloc(sizeof(*r) + request->length * 4, GFP_KERNEL);
Jesse Keating 2f82dd
+	if (r == NULL)
Jesse Keating 2f82dd
 		return -ENOMEM;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	if (copy_from_user(descriptor->data,
Jesse Keating 2f82dd
+	if (copy_from_user(r->data,
Jesse Keating 2f82dd
 			   u64_to_uptr(request->data), request->length * 4)) {
Jesse Keating 2f82dd
-		kfree(descriptor);
Jesse Keating 2f82dd
-		return -EFAULT;
Jesse Keating 2f82dd
+		ret = -EFAULT;
Jesse Keating 2f82dd
+		goto failed;
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	descriptor->d.length = request->length;
Jesse Keating 2f82dd
-	descriptor->d.immediate = request->immediate;
Jesse Keating 2f82dd
-	descriptor->d.key = request->key;
Jesse Keating 2f82dd
-	descriptor->d.data = descriptor->data;
Jesse Keating 2f82dd
-
Jesse Keating 2f82dd
-	retval = fw_core_add_descriptor(&descriptor->d);
Jesse Keating 2f82dd
-	if (retval < 0) {
Jesse Keating 2f82dd
-		kfree(descriptor);
Jesse Keating 2f82dd
-		return retval;
Jesse Keating 2f82dd
+	r->descriptor.length    = request->length;
Jesse Keating 2f82dd
+	r->descriptor.immediate = request->immediate;
Jesse Keating 2f82dd
+	r->descriptor.key       = request->key;
Jesse Keating 2f82dd
+	r->descriptor.data      = r->data;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	ret = fw_core_add_descriptor(&r->descriptor);
Jesse Keating 2f82dd
+	if (ret < 0)
Jesse Keating 2f82dd
+		goto failed;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	r->resource.release = release_descriptor;
Jesse Keating 2f82dd
+	ret = add_client_resource(client, &r->resource, GFP_KERNEL);
Jesse Keating 2f82dd
+	if (ret < 0) {
Jesse Keating 2f82dd
+		fw_core_remove_descriptor(&r->descriptor);
Jesse Keating 2f82dd
+		goto failed;
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
-
Jesse Keating 2f82dd
-	descriptor->resource.release = release_descriptor;
Jesse Keating 2f82dd
-	add_client_resource(client, &descriptor->resource);
Jesse Keating 2f82dd
-	request->handle = descriptor->resource.handle;
Jesse Keating 2f82dd
+	request->handle = r->resource.handle;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	return 0;
Jesse Keating 2f82dd
+ failed:
Jesse Keating 2f82dd
+	kfree(r);
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	return ret;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 static int ioctl_remove_descriptor(struct client *client, void *buffer)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_cdev_remove_descriptor *request = buffer;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	return release_client_resource(client, request->handle, NULL);
Jesse Keating 2f82dd
+	return release_client_resource(client, request->handle,
Jesse Keating 2f82dd
+				       release_descriptor, NULL);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-iso_callback(struct fw_iso_context *context, u32 cycle,
Jesse Keating 2f82dd
-	     size_t header_length, void *header, void *data)
Jesse Keating 2f82dd
+static void iso_callback(struct fw_iso_context *context, u32 cycle,
Jesse Keating 2f82dd
+			 size_t header_length, void *header, void *data)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct client *client = data;
Jesse Keating 2f82dd
-	struct iso_interrupt *irq;
Jesse Keating 2f82dd
+	struct iso_interrupt_event *e;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	irq = kzalloc(sizeof(*irq) + header_length, GFP_ATOMIC);
Jesse Keating 2f82dd
-	if (irq == NULL)
Jesse Keating 2f82dd
+	e = kzalloc(sizeof(*e) + header_length, GFP_ATOMIC);
Jesse Keating 2f82dd
+	if (e == NULL)
Jesse Keating 2f82dd
 		return;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	irq->interrupt.type      = FW_CDEV_EVENT_ISO_INTERRUPT;
Jesse Keating 2f82dd
-	irq->interrupt.closure   = client->iso_closure;
Jesse Keating 2f82dd
-	irq->interrupt.cycle     = cycle;
Jesse Keating 2f82dd
-	irq->interrupt.header_length = header_length;
Jesse Keating 2f82dd
-	memcpy(irq->interrupt.header, header, header_length);
Jesse Keating 2f82dd
-	queue_event(client, &irq->event, &irq->interrupt,
Jesse Keating 2f82dd
-		    sizeof(irq->interrupt) + header_length, NULL, 0);
Jesse Keating 2f82dd
+	e->interrupt.type      = FW_CDEV_EVENT_ISO_INTERRUPT;
Jesse Keating 2f82dd
+	e->interrupt.closure   = client->iso_closure;
Jesse Keating 2f82dd
+	e->interrupt.cycle     = cycle;
Jesse Keating 2f82dd
+	e->interrupt.header_length = header_length;
Jesse Keating 2f82dd
+	memcpy(e->interrupt.header, header, header_length);
Jesse Keating 2f82dd
+	queue_event(client, &e->event, &e->interrupt,
Jesse Keating 2f82dd
+		    sizeof(e->interrupt) + header_length, NULL, 0);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 static int ioctl_create_iso_context(struct client *client, void *buffer)
Jesse Keating 2f82dd
@@ -871,6 +1011,237 @@ static int ioctl_get_cycle_timer(struct 
Jesse Keating 2f82dd
 	return 0;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
+static void iso_resource_work(struct work_struct *work)
Jesse Keating 2f82dd
+{
Jesse Keating 2f82dd
+	struct iso_resource_event *e;
Jesse Keating 2f82dd
+	struct iso_resource *r =
Jesse Keating 2f82dd
+			container_of(work, struct iso_resource, work.work);
Jesse Keating 2f82dd
+	struct client *client = r->client;
Jesse Keating 2f82dd
+	int generation, channel, bandwidth, todo;
Jesse Keating 2f82dd
+	bool skip, free, success;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	spin_lock_irq(&client->lock);
Jesse Keating 2f82dd
+	generation = client->device->generation;
Jesse Keating 2f82dd
+	todo = r->todo;
Jesse Keating 2f82dd
+	/* Allow 1000ms grace period for other reallocations. */
Jesse Keating 2f82dd
+	if (todo == ISO_RES_ALLOC &&
Jesse Keating 2f82dd
+	    time_is_after_jiffies(client->device->card->reset_jiffies + HZ)) {
Jesse Keating 2f82dd
+		if (schedule_delayed_work(&r->work, DIV_ROUND_UP(HZ, 3)))
Jesse Keating 2f82dd
+			client_get(client);
Jesse Keating 2f82dd
+		skip = true;
Jesse Keating 2f82dd
+	} else {
Jesse Keating 2f82dd
+		/* We could be called twice within the same generation. */
Jesse Keating 2f82dd
+		skip = todo == ISO_RES_REALLOC &&
Jesse Keating 2f82dd
+		       r->generation == generation;
Jesse Keating 2f82dd
+	}
Jesse Keating 2f82dd
+	free = todo == ISO_RES_DEALLOC ||
Jesse Keating 2f82dd
+	       todo == ISO_RES_ALLOC_ONCE ||
Jesse Keating 2f82dd
+	       todo == ISO_RES_DEALLOC_ONCE;
Jesse Keating 2f82dd
+	r->generation = generation;
Jesse Keating 2f82dd
+	spin_unlock_irq(&client->lock);
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	if (skip)
Jesse Keating 2f82dd
+		goto out;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	bandwidth = r->bandwidth;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	fw_iso_resource_manage(client->device->card, generation,
Jesse Keating 2f82dd
+			r->channels, &channel, &bandwidth,
Jesse Keating 2f82dd
+			todo == ISO_RES_ALLOC ||
Jesse Keating 2f82dd
+			todo == ISO_RES_REALLOC ||
Jesse Keating 2f82dd
+			todo == ISO_RES_ALLOC_ONCE);
Jesse Keating 2f82dd
+	/*
Jesse Keating 2f82dd
+	 * Is this generation outdated already?  As long as this resource sticks
Jesse Keating 2f82dd
+	 * in the idr, it will be scheduled again for a newer generation or at
Jesse Keating 2f82dd
+	 * shutdown.
Jesse Keating 2f82dd
+	 */
Jesse Keating 2f82dd
+	if (channel == -EAGAIN &&
Jesse Keating 2f82dd
+	    (todo == ISO_RES_ALLOC || todo == ISO_RES_REALLOC))
Jesse Keating 2f82dd
+		goto out;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	success = channel >= 0 || bandwidth > 0;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	spin_lock_irq(&client->lock);
Jesse Keating 2f82dd
+	/*
Jesse Keating 2f82dd
+	 * Transit from allocation to reallocation, except if the client
Jesse Keating 2f82dd
+	 * requested deallocation in the meantime.
Jesse Keating 2f82dd
+	 */
Jesse Keating 2f82dd
+	if (r->todo == ISO_RES_ALLOC)
Jesse Keating 2f82dd
+		r->todo = ISO_RES_REALLOC;
Jesse Keating 2f82dd
+	/*
Jesse Keating 2f82dd
+	 * Allocation or reallocation failure?  Pull this resource out of the
Jesse Keating 2f82dd
+	 * idr and prepare for deletion, unless the client is shutting down.
Jesse Keating 2f82dd
+	 */
Jesse Keating 2f82dd
+	if (r->todo == ISO_RES_REALLOC && !success &&
Jesse Keating 2f82dd
+	    !client->in_shutdown &&
Jesse Keating 2f82dd
+	    idr_find(&client->resource_idr, r->resource.handle)) {
Jesse Keating 2f82dd
+		idr_remove(&client->resource_idr, r->resource.handle);
Jesse Keating 2f82dd
+		client_put(client);
Jesse Keating 2f82dd
+		free = true;
Jesse Keating 2f82dd
+	}
Jesse Keating 2f82dd
+	spin_unlock_irq(&client->lock);
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	if (todo == ISO_RES_ALLOC && channel >= 0)
Jesse Keating 2f82dd
+		r->channels = 1ULL << channel;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	if (todo == ISO_RES_REALLOC && success)
Jesse Keating 2f82dd
+		goto out;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	if (todo == ISO_RES_ALLOC || todo == ISO_RES_ALLOC_ONCE) {
Jesse Keating 2f82dd
+		e = r->e_alloc;
Jesse Keating 2f82dd
+		r->e_alloc = NULL;
Jesse Keating 2f82dd
+	} else {
Jesse Keating 2f82dd
+		e = r->e_dealloc;
Jesse Keating 2f82dd
+		r->e_dealloc = NULL;
Jesse Keating 2f82dd
+	}
Jesse Keating 2f82dd
+	e->resource.handle	= r->resource.handle;
Jesse Keating 2f82dd
+	e->resource.channel	= channel;
Jesse Keating 2f82dd
+	e->resource.bandwidth	= bandwidth;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	queue_event(client, &e->event,
Jesse Keating 2f82dd
+		    &e->resource, sizeof(e->resource), NULL, 0);
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	if (free) {
Jesse Keating 2f82dd
+		cancel_delayed_work(&r->work);
Jesse Keating 2f82dd
+		kfree(r->e_alloc);
Jesse Keating 2f82dd
+		kfree(r->e_dealloc);
Jesse Keating 2f82dd
+		kfree(r);
Jesse Keating 2f82dd
+	}
Jesse Keating 2f82dd
+ out:
Jesse Keating 2f82dd
+	client_put(client);
Jesse Keating 2f82dd
+}
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+static void schedule_iso_resource(struct iso_resource *r)
Jesse Keating 2f82dd
+{
Jesse Keating 2f82dd
+	client_get(r->client);
Jesse Keating 2f82dd
+	if (!schedule_delayed_work(&r->work, 0))
Jesse Keating 2f82dd
+		client_put(r->client);
Jesse Keating 2f82dd
+}
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+static void release_iso_resource(struct client *client,
Jesse Keating 2f82dd
+				 struct client_resource *resource)
Jesse Keating 2f82dd
+{
Jesse Keating 2f82dd
+	struct iso_resource *r =
Jesse Keating 2f82dd
+		container_of(resource, struct iso_resource, resource);
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	spin_lock_irq(&client->lock);
Jesse Keating 2f82dd
+	r->todo = ISO_RES_DEALLOC;
Jesse Keating 2f82dd
+	schedule_iso_resource(r);
Jesse Keating 2f82dd
+	spin_unlock_irq(&client->lock);
Jesse Keating 2f82dd
+}
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+static int init_iso_resource(struct client *client,
Jesse Keating 2f82dd
+		struct fw_cdev_allocate_iso_resource *request, int todo)
Jesse Keating 2f82dd
+{
Jesse Keating 2f82dd
+	struct iso_resource_event *e1, *e2;
Jesse Keating 2f82dd
+	struct iso_resource *r;
Jesse Keating 2f82dd
+	int ret;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	if ((request->channels == 0 && request->bandwidth == 0) ||
Jesse Keating 2f82dd
+	    request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
Jesse Keating 2f82dd
+	    request->bandwidth < 0)
Jesse Keating 2f82dd
+		return -EINVAL;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	r  = kmalloc(sizeof(*r), GFP_KERNEL);
Jesse Keating 2f82dd
+	e1 = kmalloc(sizeof(*e1), GFP_KERNEL);
Jesse Keating 2f82dd
+	e2 = kmalloc(sizeof(*e2), GFP_KERNEL);
Jesse Keating 2f82dd
+	if (r == NULL || e1 == NULL || e2 == NULL) {
Jesse Keating 2f82dd
+		ret = -ENOMEM;
Jesse Keating 2f82dd
+		goto fail;
Jesse Keating 2f82dd
+	}
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	INIT_DELAYED_WORK(&r->work, iso_resource_work);
Jesse Keating 2f82dd
+	r->client	= client;
Jesse Keating 2f82dd
+	r->todo		= todo;
Jesse Keating 2f82dd
+	r->generation	= -1;
Jesse Keating 2f82dd
+	r->channels	= request->channels;
Jesse Keating 2f82dd
+	r->bandwidth	= request->bandwidth;
Jesse Keating 2f82dd
+	r->e_alloc	= e1;
Jesse Keating 2f82dd
+	r->e_dealloc	= e2;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	e1->resource.closure	= request->closure;
Jesse Keating 2f82dd
+	e1->resource.type	= FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED;
Jesse Keating 2f82dd
+	e2->resource.closure	= request->closure;
Jesse Keating 2f82dd
+	e2->resource.type	= FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	if (todo == ISO_RES_ALLOC) {
Jesse Keating 2f82dd
+		r->resource.release = release_iso_resource;
Jesse Keating 2f82dd
+		ret = add_client_resource(client, &r->resource, GFP_KERNEL);
Jesse Keating 2f82dd
+		if (ret < 0)
Jesse Keating 2f82dd
+			goto fail;
Jesse Keating 2f82dd
+	} else {
Jesse Keating 2f82dd
+		r->resource.release = NULL;
Jesse Keating 2f82dd
+		r->resource.handle = -1;
Jesse Keating 2f82dd
+		schedule_iso_resource(r);
Jesse Keating 2f82dd
+	}
Jesse Keating 2f82dd
+	request->handle = r->resource.handle;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	return 0;
Jesse Keating 2f82dd
+ fail:
Jesse Keating 2f82dd
+	kfree(r);
Jesse Keating 2f82dd
+	kfree(e1);
Jesse Keating 2f82dd
+	kfree(e2);
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	return ret;
Jesse Keating 2f82dd
+}
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+static int ioctl_allocate_iso_resource(struct client *client, void *buffer)
Jesse Keating 2f82dd
+{
Jesse Keating 2f82dd
+	struct fw_cdev_allocate_iso_resource *request = buffer;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	return init_iso_resource(client, request, ISO_RES_ALLOC);
Jesse Keating 2f82dd
+}
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+static int ioctl_deallocate_iso_resource(struct client *client, void *buffer)
Jesse Keating 2f82dd
+{
Jesse Keating 2f82dd
+	struct fw_cdev_deallocate *request = buffer;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	return release_client_resource(client, request->handle,
Jesse Keating 2f82dd
+				       release_iso_resource, NULL);
Jesse Keating 2f82dd
+}
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+static int ioctl_allocate_iso_resource_once(struct client *client, void *buffer)
Jesse Keating 2f82dd
+{
Jesse Keating 2f82dd
+	struct fw_cdev_allocate_iso_resource *request = buffer;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	return init_iso_resource(client, request, ISO_RES_ALLOC_ONCE);
Jesse Keating 2f82dd
+}
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+static int ioctl_deallocate_iso_resource_once(struct client *client, void *buffer)
Jesse Keating 2f82dd
+{
Jesse Keating 2f82dd
+	struct fw_cdev_allocate_iso_resource *request = buffer;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	return init_iso_resource(client, request, ISO_RES_DEALLOC_ONCE);
Jesse Keating 2f82dd
+}
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+static int ioctl_get_speed(struct client *client, void *buffer)
Jesse Keating 2f82dd
+{
Jesse Keating 2f82dd
+	struct fw_cdev_get_speed *request = buffer;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	request->max_speed = client->device->max_speed;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	return 0;
Jesse Keating 2f82dd
+}
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+static int ioctl_send_broadcast_request(struct client *client, void *buffer)
Jesse Keating 2f82dd
+{
Jesse Keating 2f82dd
+	struct fw_cdev_send_request *request = buffer;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	switch (request->tcode) {
Jesse Keating 2f82dd
+	case TCODE_WRITE_QUADLET_REQUEST:
Jesse Keating 2f82dd
+	case TCODE_WRITE_BLOCK_REQUEST:
Jesse Keating 2f82dd
+		break;
Jesse Keating 2f82dd
+	default:
Jesse Keating 2f82dd
+		return -EINVAL;
Jesse Keating 2f82dd
+	}
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	/* Security policy: Only allow accesses to Units Space. */
Jesse Keating 2f82dd
+	if (request->offset < CSR_REGISTER_BASE + CSR_CONFIG_ROM_END)
Jesse Keating 2f82dd
+		return -EACCES;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	return init_request(client, request, LOCAL_BUS | 0x3f, SCODE_100);
Jesse Keating 2f82dd
+}
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
 static int (* const ioctl_handlers[])(struct client *client, void *buffer) = {
Jesse Keating 2f82dd
 	ioctl_get_info,
Jesse Keating 2f82dd
 	ioctl_send_request,
Jesse Keating 2f82dd
@@ -885,13 +1256,19 @@ static int (* const ioctl_handlers[])(st
Jesse Keating 2f82dd
 	ioctl_start_iso,
Jesse Keating 2f82dd
 	ioctl_stop_iso,
Jesse Keating 2f82dd
 	ioctl_get_cycle_timer,
Jesse Keating 2f82dd
+	ioctl_allocate_iso_resource,
Jesse Keating 2f82dd
+	ioctl_deallocate_iso_resource,
Jesse Keating 2f82dd
+	ioctl_allocate_iso_resource_once,
Jesse Keating 2f82dd
+	ioctl_deallocate_iso_resource_once,
Jesse Keating 2f82dd
+	ioctl_get_speed,
Jesse Keating 2f82dd
+	ioctl_send_broadcast_request,
Jesse Keating 2f82dd
 };
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static int
Jesse Keating 2f82dd
-dispatch_ioctl(struct client *client, unsigned int cmd, void __user *arg)
Jesse Keating 2f82dd
+static int dispatch_ioctl(struct client *client,
Jesse Keating 2f82dd
+			  unsigned int cmd, void __user *arg)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	char buffer[256];
Jesse Keating 2f82dd
-	int retval;
Jesse Keating 2f82dd
+	int ret;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	if (_IOC_TYPE(cmd) != '#' ||
Jesse Keating 2f82dd
 	    _IOC_NR(cmd) >= ARRAY_SIZE(ioctl_handlers))
Jesse Keating 2f82dd
@@ -903,9 +1280,9 @@ dispatch_ioctl(struct client *client, un
Jesse Keating 2f82dd
 			return -EFAULT;
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	retval = ioctl_handlers[_IOC_NR(cmd)](client, buffer);
Jesse Keating 2f82dd
-	if (retval < 0)
Jesse Keating 2f82dd
-		return retval;
Jesse Keating 2f82dd
+	ret = ioctl_handlers[_IOC_NR(cmd)](client, buffer);
Jesse Keating 2f82dd
+	if (ret < 0)
Jesse Keating 2f82dd
+		return ret;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	if (_IOC_DIR(cmd) & _IOC_READ) {
Jesse Keating 2f82dd
 		if (_IOC_SIZE(cmd) > sizeof(buffer) ||
Jesse Keating 2f82dd
@@ -913,12 +1290,11 @@ dispatch_ioctl(struct client *client, un
Jesse Keating 2f82dd
 			return -EFAULT;
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	return retval;
Jesse Keating 2f82dd
+	return ret;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static long
Jesse Keating 2f82dd
-fw_device_op_ioctl(struct file *file,
Jesse Keating 2f82dd
-		   unsigned int cmd, unsigned long arg)
Jesse Keating 2f82dd
+static long fw_device_op_ioctl(struct file *file,
Jesse Keating 2f82dd
+			       unsigned int cmd, unsigned long arg)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct client *client = file->private_data;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
@@ -929,9 +1305,8 @@ fw_device_op_ioctl(struct file *file,
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 #ifdef CONFIG_COMPAT
Jesse Keating 2f82dd
-static long
Jesse Keating 2f82dd
-fw_device_op_compat_ioctl(struct file *file,
Jesse Keating 2f82dd
-			  unsigned int cmd, unsigned long arg)
Jesse Keating 2f82dd
+static long fw_device_op_compat_ioctl(struct file *file,
Jesse Keating 2f82dd
+				      unsigned int cmd, unsigned long arg)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct client *client = file->private_data;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
@@ -947,7 +1322,7 @@ static int fw_device_op_mmap(struct file
Jesse Keating 2f82dd
 	struct client *client = file->private_data;
Jesse Keating 2f82dd
 	enum dma_data_direction direction;
Jesse Keating 2f82dd
 	unsigned long size;
Jesse Keating 2f82dd
-	int page_count, retval;
Jesse Keating 2f82dd
+	int page_count, ret;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	if (fw_device_is_shutdown(client->device))
Jesse Keating 2f82dd
 		return -ENODEV;
Jesse Keating 2f82dd
@@ -973,48 +1348,57 @@ static int fw_device_op_mmap(struct file
Jesse Keating 2f82dd
 	else
Jesse Keating 2f82dd
 		direction = DMA_FROM_DEVICE;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	retval = fw_iso_buffer_init(&client->buffer, client->device->card,
Jesse Keating 2f82dd
-				    page_count, direction);
Jesse Keating 2f82dd
-	if (retval < 0)
Jesse Keating 2f82dd
-		return retval;
Jesse Keating 2f82dd
+	ret = fw_iso_buffer_init(&client->buffer, client->device->card,
Jesse Keating 2f82dd
+				 page_count, direction);
Jesse Keating 2f82dd
+	if (ret < 0)
Jesse Keating 2f82dd
+		return ret;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	retval = fw_iso_buffer_map(&client->buffer, vma);
Jesse Keating 2f82dd
-	if (retval < 0)
Jesse Keating 2f82dd
+	ret = fw_iso_buffer_map(&client->buffer, vma);
Jesse Keating 2f82dd
+	if (ret < 0)
Jesse Keating 2f82dd
 		fw_iso_buffer_destroy(&client->buffer, client->device->card);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	return retval;
Jesse Keating 2f82dd
+	return ret;
Jesse Keating 2f82dd
+}
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+static int shutdown_resource(int id, void *p, void *data)
Jesse Keating 2f82dd
+{
Jesse Keating 2f82dd
+	struct client_resource *r = p;
Jesse Keating 2f82dd
+	struct client *client = data;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	r->release(client, r);
Jesse Keating 2f82dd
+	client_put(client);
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	return 0;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 static int fw_device_op_release(struct inode *inode, struct file *file)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct client *client = file->private_data;
Jesse Keating 2f82dd
 	struct event *e, *next_e;
Jesse Keating 2f82dd
-	struct client_resource *r, *next_r;
Jesse Keating 2f82dd
-	unsigned long flags;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	if (client->buffer.pages)
Jesse Keating 2f82dd
-		fw_iso_buffer_destroy(&client->buffer, client->device->card);
Jesse Keating 2f82dd
+	mutex_lock(&client->device->client_list_mutex);
Jesse Keating 2f82dd
+	list_del(&client->link);
Jesse Keating 2f82dd
+	mutex_unlock(&client->device->client_list_mutex);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	if (client->iso_context)
Jesse Keating 2f82dd
 		fw_iso_context_destroy(client->iso_context);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	list_for_each_entry_safe(r, next_r, &client->resource_list, link)
Jesse Keating 2f82dd
-		r->release(client, r);
Jesse Keating 2f82dd
+	if (client->buffer.pages)
Jesse Keating 2f82dd
+		fw_iso_buffer_destroy(&client->buffer, client->device->card);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	/*
Jesse Keating 2f82dd
-	 * FIXME: We should wait for the async tasklets to stop
Jesse Keating 2f82dd
-	 * running before freeing the memory.
Jesse Keating 2f82dd
-	 */
Jesse Keating 2f82dd
+	/* Freeze client->resource_idr and client->event_list */
Jesse Keating 2f82dd
+	spin_lock_irq(&client->lock);
Jesse Keating 2f82dd
+	client->in_shutdown = true;
Jesse Keating 2f82dd
+	spin_unlock_irq(&client->lock);
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	idr_for_each(&client->resource_idr, shutdown_resource, client);
Jesse Keating 2f82dd
+	idr_remove_all(&client->resource_idr);
Jesse Keating 2f82dd
+	idr_destroy(&client->resource_idr);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	list_for_each_entry_safe(e, next_e, &client->event_list, link)
Jesse Keating 2f82dd
 		kfree(e);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	spin_lock_irqsave(&client->device->card->lock, flags);
Jesse Keating 2f82dd
-	list_del(&client->link);
Jesse Keating 2f82dd
-	spin_unlock_irqrestore(&client->device->card->lock, flags);
Jesse Keating 2f82dd
-
Jesse Keating 2f82dd
-	fw_device_put(client->device);
Jesse Keating 2f82dd
-	kfree(client);
Jesse Keating 2f82dd
+	client_put(client);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	return 0;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
diff -Naurp linux-2.6-git/drivers/firewire/fw-device.c firewire-git/drivers/firewire/fw-device.c
Jesse Keating 2f82dd
--- linux-2.6-git/drivers/firewire/fw-device.c	2009-01-30 13:39:02.989651512 -0500
Jesse Keating 2f82dd
+++ firewire-git/drivers/firewire/fw-device.c	2009-01-30 13:35:51.860646788 -0500
Jesse Keating 2f82dd
@@ -27,8 +27,10 @@
Jesse Keating 2f82dd
 #include <linux idr.h="">
Jesse Keating 2f82dd
 #include <linux jiffies.h="">
Jesse Keating 2f82dd
 #include <linux string.h="">
Jesse Keating 2f82dd
+#include <linux mutex.h="">
Jesse Keating 2f82dd
 #include <linux rwsem.h="">
Jesse Keating 2f82dd
 #include <linux semaphore.h="">
Jesse Keating 2f82dd
+#include <linux spinlock.h="">
Jesse Keating 2f82dd
 #include <asm system.h="">
Jesse Keating 2f82dd
 #include <linux ctype.h="">
Jesse Keating 2f82dd
 #include "fw-transaction.h"
Jesse Keating 2f82dd
@@ -132,8 +134,7 @@ static int get_modalias(struct fw_unit *
Jesse Keating 2f82dd
 			vendor, model, specifier_id, version);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static int
Jesse Keating 2f82dd
-fw_unit_uevent(struct device *dev, struct kobj_uevent_env *env)
Jesse Keating 2f82dd
+static int fw_unit_uevent(struct device *dev, struct kobj_uevent_env *env)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_unit *unit = fw_unit(dev);
Jesse Keating 2f82dd
 	char modalias[64];
Jesse Keating 2f82dd
@@ -191,8 +192,8 @@ struct config_rom_attribute {
Jesse Keating 2f82dd
 	u32 key;
Jesse Keating 2f82dd
 };
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static ssize_t
Jesse Keating 2f82dd
-show_immediate(struct device *dev, struct device_attribute *dattr, char *buf)
Jesse Keating 2f82dd
+static ssize_t show_immediate(struct device *dev,
Jesse Keating 2f82dd
+			      struct device_attribute *dattr, char *buf)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct config_rom_attribute *attr =
Jesse Keating 2f82dd
 		container_of(dattr, struct config_rom_attribute, attr);
Jesse Keating 2f82dd
@@ -223,8 +224,8 @@ show_immediate(struct device *dev, struc
Jesse Keating 2f82dd
 #define IMMEDIATE_ATTR(name, key)				\
Jesse Keating 2f82dd
 	{ __ATTR(name, S_IRUGO, show_immediate, NULL), key }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static ssize_t
Jesse Keating 2f82dd
-show_text_leaf(struct device *dev, struct device_attribute *dattr, char *buf)
Jesse Keating 2f82dd
+static ssize_t show_text_leaf(struct device *dev,
Jesse Keating 2f82dd
+			      struct device_attribute *dattr, char *buf)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct config_rom_attribute *attr =
Jesse Keating 2f82dd
 		container_of(dattr, struct config_rom_attribute, attr);
Jesse Keating 2f82dd
@@ -293,10 +294,9 @@ static struct config_rom_attribute confi
Jesse Keating 2f82dd
 	TEXT_LEAF_ATTR(hardware_version_name, CSR_HARDWARE_VERSION),
Jesse Keating 2f82dd
 };
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-init_fw_attribute_group(struct device *dev,
Jesse Keating 2f82dd
-			struct device_attribute *attrs,
Jesse Keating 2f82dd
-			struct fw_attribute_group *group)
Jesse Keating 2f82dd
+static void init_fw_attribute_group(struct device *dev,
Jesse Keating 2f82dd
+				    struct device_attribute *attrs,
Jesse Keating 2f82dd
+				    struct fw_attribute_group *group)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct device_attribute *attr;
Jesse Keating 2f82dd
 	int i, j;
Jesse Keating 2f82dd
@@ -319,9 +319,8 @@ init_fw_attribute_group(struct device *d
Jesse Keating 2f82dd
 	dev->groups = group->groups;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static ssize_t
Jesse Keating 2f82dd
-modalias_show(struct device *dev,
Jesse Keating 2f82dd
-	      struct device_attribute *attr, char *buf)
Jesse Keating 2f82dd
+static ssize_t modalias_show(struct device *dev,
Jesse Keating 2f82dd
+			     struct device_attribute *attr, char *buf)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_unit *unit = fw_unit(dev);
Jesse Keating 2f82dd
 	int length;
Jesse Keating 2f82dd
@@ -332,9 +331,8 @@ modalias_show(struct device *dev,
Jesse Keating 2f82dd
 	return length + 1;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static ssize_t
Jesse Keating 2f82dd
-rom_index_show(struct device *dev,
Jesse Keating 2f82dd
-	       struct device_attribute *attr, char *buf)
Jesse Keating 2f82dd
+static ssize_t rom_index_show(struct device *dev,
Jesse Keating 2f82dd
+			      struct device_attribute *attr, char *buf)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_device *device = fw_device(dev->parent);
Jesse Keating 2f82dd
 	struct fw_unit *unit = fw_unit(dev);
Jesse Keating 2f82dd
@@ -349,8 +347,8 @@ static struct device_attribute fw_unit_a
Jesse Keating 2f82dd
 	__ATTR_NULL,
Jesse Keating 2f82dd
 };
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static ssize_t
Jesse Keating 2f82dd
-config_rom_show(struct device *dev, struct device_attribute *attr, char *buf)
Jesse Keating 2f82dd
+static ssize_t config_rom_show(struct device *dev,
Jesse Keating 2f82dd
+			       struct device_attribute *attr, char *buf)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_device *device = fw_device(dev);
Jesse Keating 2f82dd
 	size_t length;
Jesse Keating 2f82dd
@@ -363,8 +361,8 @@ config_rom_show(struct device *dev, stru
Jesse Keating 2f82dd
 	return length;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static ssize_t
Jesse Keating 2f82dd
-guid_show(struct device *dev, struct device_attribute *attr, char *buf)
Jesse Keating 2f82dd
+static ssize_t guid_show(struct device *dev,
Jesse Keating 2f82dd
+			 struct device_attribute *attr, char *buf)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_device *device = fw_device(dev);
Jesse Keating 2f82dd
 	int ret;
Jesse Keating 2f82dd
@@ -383,8 +381,8 @@ static struct device_attribute fw_device
Jesse Keating 2f82dd
 	__ATTR_NULL,
Jesse Keating 2f82dd
 };
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static int
Jesse Keating 2f82dd
-read_rom(struct fw_device *device, int generation, int index, u32 *data)
Jesse Keating 2f82dd
+static int read_rom(struct fw_device *device,
Jesse Keating 2f82dd
+		    int generation, int index, u32 *data)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	int rcode;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
@@ -1004,6 +1002,7 @@ void fw_node_event(struct fw_card *card,
Jesse Keating 2f82dd
 		device->node = fw_node_get(node);
Jesse Keating 2f82dd
 		device->node_id = node->node_id;
Jesse Keating 2f82dd
 		device->generation = card->generation;
Jesse Keating 2f82dd
+		mutex_init(&device->client_list_mutex);
Jesse Keating 2f82dd
 		INIT_LIST_HEAD(&device->client_list);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 		/*
Jesse Keating 2f82dd
diff -Naurp linux-2.6-git/drivers/firewire/fw-device.h firewire-git/drivers/firewire/fw-device.h
Jesse Keating 2f82dd
--- linux-2.6-git/drivers/firewire/fw-device.h	2009-01-30 13:39:02.989651512 -0500
Jesse Keating 2f82dd
+++ firewire-git/drivers/firewire/fw-device.h	2009-01-30 13:35:51.860646788 -0500
Jesse Keating 2f82dd
@@ -23,6 +23,7 @@
Jesse Keating 2f82dd
 #include <linux cdev.h="">
Jesse Keating 2f82dd
 #include <linux idr.h="">
Jesse Keating 2f82dd
 #include <linux rwsem.h="">
Jesse Keating 2f82dd
+#include <linux mutex.h="">
Jesse Keating 2f82dd
 #include <asm atomic.h="">
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 enum fw_device_state {
Jesse Keating 2f82dd
@@ -64,7 +65,10 @@ struct fw_device {
Jesse Keating 2f82dd
 	bool cmc;
Jesse Keating 2f82dd
 	struct fw_card *card;
Jesse Keating 2f82dd
 	struct device device;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	struct mutex client_list_mutex;
Jesse Keating 2f82dd
 	struct list_head client_list;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
 	u32 *config_rom;
Jesse Keating 2f82dd
 	size_t config_rom_length;
Jesse Keating 2f82dd
 	int config_rom_retries;
Jesse Keating 2f82dd
@@ -176,8 +180,7 @@ struct fw_driver {
Jesse Keating 2f82dd
 	const struct fw_device_id *id_table;
Jesse Keating 2f82dd
 };
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static inline struct fw_driver *
Jesse Keating 2f82dd
-fw_driver(struct device_driver *drv)
Jesse Keating 2f82dd
+static inline struct fw_driver *fw_driver(struct device_driver *drv)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	return container_of(drv, struct fw_driver, driver);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
diff -Naurp linux-2.6-git/drivers/firewire/fw-iso.c firewire-git/drivers/firewire/fw-iso.c
Jesse Keating 2f82dd
--- linux-2.6-git/drivers/firewire/fw-iso.c	2008-11-04 11:18:33.000000000 -0500
Jesse Keating 2f82dd
+++ firewire-git/drivers/firewire/fw-iso.c	2009-01-30 13:35:51.860646788 -0500
Jesse Keating 2f82dd
@@ -1,5 +1,7 @@
Jesse Keating 2f82dd
 /*
Jesse Keating 2f82dd
- * Isochronous IO functionality
Jesse Keating 2f82dd
+ * Isochronous I/O functionality:
Jesse Keating 2f82dd
+ *   - Isochronous DMA context management
Jesse Keating 2f82dd
+ *   - Isochronous bus resource management (channels, bandwidth), client side
Jesse Keating 2f82dd
  *
Jesse Keating 2f82dd
  * Copyright (C) 2006 Kristian Hoegsberg <krh@bitplanet.net>
Jesse Keating 2f82dd
  *
Jesse Keating 2f82dd
@@ -18,21 +20,25 @@
Jesse Keating 2f82dd
  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Jesse Keating 2f82dd
  */
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-#include <linux kernel.h="">
Jesse Keating 2f82dd
-#include <linux module.h="">
Jesse Keating 2f82dd
 #include <linux dma-mapping.h="">
Jesse Keating 2f82dd
-#include <linux vmalloc.h="">
Jesse Keating 2f82dd
+#include <linux errno.h="">
Jesse Keating 2f82dd
+#include <linux firewire-constants.h="">
Jesse Keating 2f82dd
+#include <linux kernel.h="">
Jesse Keating 2f82dd
 #include <linux mm.h="">
Jesse Keating 2f82dd
+#include <linux spinlock.h="">
Jesse Keating 2f82dd
+#include <linux vmalloc.h="">
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-#include "fw-transaction.h"
Jesse Keating 2f82dd
 #include "fw-topology.h"
Jesse Keating 2f82dd
-#include "fw-device.h"
Jesse Keating 2f82dd
+#include "fw-transaction.h"
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-int
Jesse Keating 2f82dd
-fw_iso_buffer_init(struct fw_iso_buffer *buffer, struct fw_card *card,
Jesse Keating 2f82dd
-		   int page_count, enum dma_data_direction direction)
Jesse Keating 2f82dd
+/*
Jesse Keating 2f82dd
+ * Isochronous DMA context management
Jesse Keating 2f82dd
+ */
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+int fw_iso_buffer_init(struct fw_iso_buffer *buffer, struct fw_card *card,
Jesse Keating 2f82dd
+		       int page_count, enum dma_data_direction direction)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
-	int i, j, retval = -ENOMEM;
Jesse Keating 2f82dd
+	int i, j;
Jesse Keating 2f82dd
 	dma_addr_t address;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	buffer->page_count = page_count;
Jesse Keating 2f82dd
@@ -69,19 +75,19 @@ fw_iso_buffer_init(struct fw_iso_buffer 
Jesse Keating 2f82dd
 	kfree(buffer->pages);
Jesse Keating 2f82dd
  out:
Jesse Keating 2f82dd
 	buffer->pages = NULL;
Jesse Keating 2f82dd
-	return retval;
Jesse Keating 2f82dd
+	return -ENOMEM;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 int fw_iso_buffer_map(struct fw_iso_buffer *buffer, struct vm_area_struct *vma)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	unsigned long uaddr;
Jesse Keating 2f82dd
-	int i, retval;
Jesse Keating 2f82dd
+	int i, ret;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	uaddr = vma->vm_start;
Jesse Keating 2f82dd
 	for (i = 0; i < buffer->page_count; i++) {
Jesse Keating 2f82dd
-		retval = vm_insert_page(vma, uaddr, buffer->pages[i]);
Jesse Keating 2f82dd
-		if (retval)
Jesse Keating 2f82dd
-			return retval;
Jesse Keating 2f82dd
+		ret = vm_insert_page(vma, uaddr, buffer->pages[i]);
Jesse Keating 2f82dd
+		if (ret)
Jesse Keating 2f82dd
+			return ret;
Jesse Keating 2f82dd
 		uaddr += PAGE_SIZE;
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
@@ -105,14 +111,14 @@ void fw_iso_buffer_destroy(struct fw_iso
Jesse Keating 2f82dd
 	buffer->pages = NULL;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-struct fw_iso_context *
Jesse Keating 2f82dd
-fw_iso_context_create(struct fw_card *card, int type,
Jesse Keating 2f82dd
-		      int channel, int speed, size_t header_size,
Jesse Keating 2f82dd
-		      fw_iso_callback_t callback, void *callback_data)
Jesse Keating 2f82dd
+struct fw_iso_context *fw_iso_context_create(struct fw_card *card,
Jesse Keating 2f82dd
+		int type, int channel, int speed, size_t header_size,
Jesse Keating 2f82dd
+		fw_iso_callback_t callback, void *callback_data)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_iso_context *ctx;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	ctx = card->driver->allocate_iso_context(card, type, header_size);
Jesse Keating 2f82dd
+	ctx = card->driver->allocate_iso_context(card,
Jesse Keating 2f82dd
+						 type, channel, header_size);
Jesse Keating 2f82dd
 	if (IS_ERR(ctx))
Jesse Keating 2f82dd
 		return ctx;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
@@ -134,25 +140,186 @@ void fw_iso_context_destroy(struct fw_is
Jesse Keating 2f82dd
 	card->driver->free_iso_context(ctx);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-int
Jesse Keating 2f82dd
-fw_iso_context_start(struct fw_iso_context *ctx, int cycle, int sync, int tags)
Jesse Keating 2f82dd
+int fw_iso_context_start(struct fw_iso_context *ctx,
Jesse Keating 2f82dd
+			 int cycle, int sync, int tags)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	return ctx->card->driver->start_iso(ctx, cycle, sync, tags);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-int
Jesse Keating 2f82dd
-fw_iso_context_queue(struct fw_iso_context *ctx,
Jesse Keating 2f82dd
-		     struct fw_iso_packet *packet,
Jesse Keating 2f82dd
-		     struct fw_iso_buffer *buffer,
Jesse Keating 2f82dd
-		     unsigned long payload)
Jesse Keating 2f82dd
+int fw_iso_context_queue(struct fw_iso_context *ctx,
Jesse Keating 2f82dd
+			 struct fw_iso_packet *packet,
Jesse Keating 2f82dd
+			 struct fw_iso_buffer *buffer,
Jesse Keating 2f82dd
+			 unsigned long payload)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_card *card = ctx->card;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	return card->driver->queue_iso(ctx, packet, buffer, payload);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-int
Jesse Keating 2f82dd
-fw_iso_context_stop(struct fw_iso_context *ctx)
Jesse Keating 2f82dd
+int fw_iso_context_stop(struct fw_iso_context *ctx)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	return ctx->card->driver->stop_iso(ctx);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+/*
Jesse Keating 2f82dd
+ * Isochronous bus resource management (channels, bandwidth), client side
Jesse Keating 2f82dd
+ */
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+static int manage_bandwidth(struct fw_card *card, int irm_id, int generation,
Jesse Keating 2f82dd
+			    int bandwidth, bool allocate)
Jesse Keating 2f82dd
+{
Jesse Keating 2f82dd
+	__be32 data[2];
Jesse Keating 2f82dd
+	int try, new, old = allocate ? BANDWIDTH_AVAILABLE_INITIAL : 0;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	/*
Jesse Keating 2f82dd
+	 * On a 1394a IRM with low contention, try < 1 is enough.
Jesse Keating 2f82dd
+	 * On a 1394-1995 IRM, we need at least try < 2.
Jesse Keating 2f82dd
+	 * Let's just do try < 5.
Jesse Keating 2f82dd
+	 */
Jesse Keating 2f82dd
+	for (try = 0; try < 5; try++) {
Jesse Keating 2f82dd
+		new = allocate ? old - bandwidth : old + bandwidth;
Jesse Keating 2f82dd
+		if (new < 0 || new > BANDWIDTH_AVAILABLE_INITIAL)
Jesse Keating 2f82dd
+			break;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+		data[0] = cpu_to_be32(old);
Jesse Keating 2f82dd
+		data[1] = cpu_to_be32(new);
Jesse Keating 2f82dd
+		switch (fw_run_transaction(card, TCODE_LOCK_COMPARE_SWAP,
Jesse Keating 2f82dd
+				irm_id, generation, SCODE_100,
Jesse Keating 2f82dd
+				CSR_REGISTER_BASE + CSR_BANDWIDTH_AVAILABLE,
Jesse Keating 2f82dd
+				data, sizeof(data))) {
Jesse Keating 2f82dd
+		case RCODE_GENERATION:
Jesse Keating 2f82dd
+			/* A generation change frees all bandwidth. */
Jesse Keating 2f82dd
+			return allocate ? -EAGAIN : bandwidth;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+		case RCODE_COMPLETE:
Jesse Keating 2f82dd
+			if (be32_to_cpup(data) == old)
Jesse Keating 2f82dd
+				return bandwidth;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+			old = be32_to_cpup(data);
Jesse Keating 2f82dd
+			/* Fall through. */
Jesse Keating 2f82dd
+		}
Jesse Keating 2f82dd
+	}
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	return -EIO;
Jesse Keating 2f82dd
+}
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+static int manage_channel(struct fw_card *card, int irm_id, int generation,
Jesse Keating 2f82dd
+			  u32 channels_mask, u64 offset, bool allocate)
Jesse Keating 2f82dd
+{
Jesse Keating 2f82dd
+	__be32 data[2], c, all, old;
Jesse Keating 2f82dd
+	int i, retry = 5;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	old = all = allocate ? cpu_to_be32(~0) : 0;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	for (i = 0; i < 32; i++) {
Jesse Keating 2f82dd
+		if (!(channels_mask & 1 << i))
Jesse Keating 2f82dd
+			continue;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+		c = cpu_to_be32(1 << (31 - i));
Jesse Keating 2f82dd
+		if ((old & c) != (all & c))
Jesse Keating 2f82dd
+			continue;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+		data[0] = old;
Jesse Keating 2f82dd
+		data[1] = old ^ c;
Jesse Keating 2f82dd
+		switch (fw_run_transaction(card, TCODE_LOCK_COMPARE_SWAP,
Jesse Keating 2f82dd
+					   irm_id, generation, SCODE_100,
Jesse Keating 2f82dd
+					   offset, data, sizeof(data))) {
Jesse Keating 2f82dd
+		case RCODE_GENERATION:
Jesse Keating 2f82dd
+			/* A generation change frees all channels. */
Jesse Keating 2f82dd
+			return allocate ? -EAGAIN : i;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+		case RCODE_COMPLETE:
Jesse Keating 2f82dd
+			if (data[0] == old)
Jesse Keating 2f82dd
+				return i;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+			old = data[0];
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+			/* Is the IRM 1394a-2000 compliant? */
Jesse Keating 2f82dd
+			if ((data[0] & c) == (data[1] & c))
Jesse Keating 2f82dd
+				continue;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+			/* 1394-1995 IRM, fall through to retry. */
Jesse Keating 2f82dd
+		default:
Jesse Keating 2f82dd
+			if (retry--)
Jesse Keating 2f82dd
+				i--;
Jesse Keating 2f82dd
+		}
Jesse Keating 2f82dd
+	}
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	return -EIO;
Jesse Keating 2f82dd
+}
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+static void deallocate_channel(struct fw_card *card, int irm_id,
Jesse Keating 2f82dd
+			       int generation, int channel)
Jesse Keating 2f82dd
+{
Jesse Keating 2f82dd
+	u32 mask;
Jesse Keating 2f82dd
+	u64 offset;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	mask = channel < 32 ? 1 << channel : 1 << (channel - 32);
Jesse Keating 2f82dd
+	offset = channel < 32 ? CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_HI :
Jesse Keating 2f82dd
+				CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_LO;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	manage_channel(card, irm_id, generation, mask, offset, false);
Jesse Keating 2f82dd
+}
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+/**
Jesse Keating 2f82dd
+ * fw_iso_resource_manage - Allocate or deallocate a channel and/or bandwidth
Jesse Keating 2f82dd
+ *
Jesse Keating 2f82dd
+ * In parameters: card, generation, channels_mask, bandwidth, allocate
Jesse Keating 2f82dd
+ * Out parameters: channel, bandwidth
Jesse Keating 2f82dd
+ * This function blocks (sleeps) during communication with the IRM.
Jesse Keating 2f82dd
+ *
Jesse Keating 2f82dd
+ * Allocates or deallocates at most one channel out of channels_mask.
Jesse Keating 2f82dd
+ * channels_mask is a bitfield with MSB for channel 63 and LSB for channel 0.
Jesse Keating 2f82dd
+ * (Note, the IRM's CHANNELS_AVAILABLE is a big-endian bitfield with MSB for
Jesse Keating 2f82dd
+ * channel 0 and LSB for channel 63.)
Jesse Keating 2f82dd
+ * Allocates or deallocates as many bandwidth allocation units as specified.
Jesse Keating 2f82dd
+ *
Jesse Keating 2f82dd
+ * Returns channel < 0 if no channel was allocated or deallocated.
Jesse Keating 2f82dd
+ * Returns bandwidth = 0 if no bandwidth was allocated or deallocated.
Jesse Keating 2f82dd
+ *
Jesse Keating 2f82dd
+ * If generation is stale, deallocations succeed but allocations fail with
Jesse Keating 2f82dd
+ * channel = -EAGAIN.
Jesse Keating 2f82dd
+ *
Jesse Keating 2f82dd
+ * If channel allocation fails, no bandwidth will be allocated either.
Jesse Keating 2f82dd
+ * If bandwidth allocation fails, no channel will be allocated either.
Jesse Keating 2f82dd
+ * But deallocations of channel and bandwidth are tried independently
Jesse Keating 2f82dd
+ * of each other's success.
Jesse Keating 2f82dd
+ */
Jesse Keating 2f82dd
+void fw_iso_resource_manage(struct fw_card *card, int generation,
Jesse Keating 2f82dd
+			    u64 channels_mask, int *channel, int *bandwidth,
Jesse Keating 2f82dd
+			    bool allocate)
Jesse Keating 2f82dd
+{
Jesse Keating 2f82dd
+	u32 channels_hi = channels_mask;	/* channels 31...0 */
Jesse Keating 2f82dd
+	u32 channels_lo = channels_mask >> 32;	/* channels 63...32 */
Jesse Keating 2f82dd
+	int irm_id, ret, c = -EINVAL;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	spin_lock_irq(&card->lock);
Jesse Keating 2f82dd
+	irm_id = card->irm_node->node_id;
Jesse Keating 2f82dd
+	spin_unlock_irq(&card->lock);
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	if (channels_hi)
Jesse Keating 2f82dd
+		c = manage_channel(card, irm_id, generation, channels_hi,
Jesse Keating 2f82dd
+		    CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_HI, allocate);
Jesse Keating 2f82dd
+	if (channels_lo && c < 0) {
Jesse Keating 2f82dd
+		c = manage_channel(card, irm_id, generation, channels_lo,
Jesse Keating 2f82dd
+		    CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_LO, allocate);
Jesse Keating 2f82dd
+		if (c >= 0)
Jesse Keating 2f82dd
+			c += 32;
Jesse Keating 2f82dd
+	}
Jesse Keating 2f82dd
+	*channel = c;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	if (allocate && channels_mask != 0 && c < 0)
Jesse Keating 2f82dd
+		*bandwidth = 0;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	if (*bandwidth == 0)
Jesse Keating 2f82dd
+		return;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	ret = manage_bandwidth(card, irm_id, generation, *bandwidth, allocate);
Jesse Keating 2f82dd
+	if (ret < 0)
Jesse Keating 2f82dd
+		*bandwidth = 0;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	if (allocate && ret < 0 && c >= 0) {
Jesse Keating 2f82dd
+		deallocate_channel(card, irm_id, generation, c);
Jesse Keating 2f82dd
+		*channel = ret;
Jesse Keating 2f82dd
+	}
Jesse Keating 2f82dd
+}
Jesse Keating 2f82dd
diff -Naurp linux-2.6-git/drivers/firewire/fw-ohci.c firewire-git/drivers/firewire/fw-ohci.c
Jesse Keating 2f82dd
--- linux-2.6-git/drivers/firewire/fw-ohci.c	2009-01-30 13:39:02.990772025 -0500
Jesse Keating 2f82dd
+++ firewire-git/drivers/firewire/fw-ohci.c	2009-01-30 13:35:51.861646907 -0500
Jesse Keating 2f82dd
@@ -205,6 +205,7 @@ struct fw_ohci {
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	u32 it_context_mask;
Jesse Keating 2f82dd
 	struct iso_context *it_context_list;
Jesse Keating 2f82dd
+	u64 ir_context_channels;
Jesse Keating 2f82dd
 	u32 ir_context_mask;
Jesse Keating 2f82dd
 	struct iso_context *ir_context_list;
Jesse Keating 2f82dd
 };
Jesse Keating 2f82dd
@@ -441,9 +442,8 @@ static inline void flush_writes(const st
Jesse Keating 2f82dd
 	reg_read(ohci, OHCI1394_Version);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static int
Jesse Keating 2f82dd
-ohci_update_phy_reg(struct fw_card *card, int addr,
Jesse Keating 2f82dd
-		    int clear_bits, int set_bits)
Jesse Keating 2f82dd
+static int ohci_update_phy_reg(struct fw_card *card, int addr,
Jesse Keating 2f82dd
+			       int clear_bits, int set_bits)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_ohci *ohci = fw_ohci(card);
Jesse Keating 2f82dd
 	u32 val, old;
Jesse Keating 2f82dd
@@ -658,8 +658,8 @@ static void ar_context_tasklet(unsigned 
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static int
Jesse Keating 2f82dd
-ar_context_init(struct ar_context *ctx, struct fw_ohci *ohci, u32 regs)
Jesse Keating 2f82dd
+static int ar_context_init(struct ar_context *ctx,
Jesse Keating 2f82dd
+			   struct fw_ohci *ohci, u32 regs)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct ar_buffer ab;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
@@ -690,8 +690,7 @@ static void ar_context_run(struct ar_con
Jesse Keating 2f82dd
 	flush_writes(ctx->ohci);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static struct descriptor *
Jesse Keating 2f82dd
-find_branch_descriptor(struct descriptor *d, int z)
Jesse Keating 2f82dd
+static struct descriptor *find_branch_descriptor(struct descriptor *d, int z)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	int b, key;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
@@ -751,8 +750,7 @@ static void context_tasklet(unsigned lon
Jesse Keating 2f82dd
  * Allocate a new buffer and add it to the list of free buffers for this
Jesse Keating 2f82dd
  * context.  Must be called with ohci->lock held.
Jesse Keating 2f82dd
  */
Jesse Keating 2f82dd
-static int
Jesse Keating 2f82dd
-context_add_buffer(struct context *ctx)
Jesse Keating 2f82dd
+static int context_add_buffer(struct context *ctx)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct descriptor_buffer *desc;
Jesse Keating 2f82dd
 	dma_addr_t uninitialized_var(bus_addr);
Jesse Keating 2f82dd
@@ -781,9 +779,8 @@ context_add_buffer(struct context *ctx)
Jesse Keating 2f82dd
 	return 0;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static int
Jesse Keating 2f82dd
-context_init(struct context *ctx, struct fw_ohci *ohci,
Jesse Keating 2f82dd
-	     u32 regs, descriptor_callback_t callback)
Jesse Keating 2f82dd
+static int context_init(struct context *ctx, struct fw_ohci *ohci,
Jesse Keating 2f82dd
+			u32 regs, descriptor_callback_t callback)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	ctx->ohci = ohci;
Jesse Keating 2f82dd
 	ctx->regs = regs;
Jesse Keating 2f82dd
@@ -814,8 +811,7 @@ context_init(struct context *ctx, struct
Jesse Keating 2f82dd
 	return 0;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-context_release(struct context *ctx)
Jesse Keating 2f82dd
+static void context_release(struct context *ctx)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_card *card = &ctx->ohci->card;
Jesse Keating 2f82dd
 	struct descriptor_buffer *desc, *tmp;
Jesse Keating 2f82dd
@@ -827,8 +823,8 @@ context_release(struct context *ctx)
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 /* Must be called with ohci->lock held */
Jesse Keating 2f82dd
-static struct descriptor *
Jesse Keating 2f82dd
-context_get_descriptors(struct context *ctx, int z, dma_addr_t *d_bus)
Jesse Keating 2f82dd
+static struct descriptor *context_get_descriptors(struct context *ctx,
Jesse Keating 2f82dd
+						  int z, dma_addr_t *d_bus)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct descriptor *d = NULL;
Jesse Keating 2f82dd
 	struct descriptor_buffer *desc = ctx->buffer_tail;
Jesse Keating 2f82dd
@@ -912,8 +908,8 @@ struct driver_data {
Jesse Keating 2f82dd
  * Must always be called with the ochi->lock held to ensure proper
Jesse Keating 2f82dd
  * generation handling and locking around packet queue manipulation.
Jesse Keating 2f82dd
  */
Jesse Keating 2f82dd
-static int
Jesse Keating 2f82dd
-at_context_queue_packet(struct context *ctx, struct fw_packet *packet)
Jesse Keating 2f82dd
+static int at_context_queue_packet(struct context *ctx,
Jesse Keating 2f82dd
+				   struct fw_packet *packet)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_ohci *ohci = ctx->ohci;
Jesse Keating 2f82dd
 	dma_addr_t d_bus, uninitialized_var(payload_bus);
Jesse Keating 2f82dd
@@ -1095,8 +1091,8 @@ static int handle_at_packet(struct conte
Jesse Keating 2f82dd
 #define HEADER_GET_DATA_LENGTH(q)	(((q) >> 16) & 0xffff)
Jesse Keating 2f82dd
 #define HEADER_GET_EXTENDED_TCODE(q)	(((q) >> 0) & 0xffff)
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-handle_local_rom(struct fw_ohci *ohci, struct fw_packet *packet, u32 csr)
Jesse Keating 2f82dd
+static void handle_local_rom(struct fw_ohci *ohci,
Jesse Keating 2f82dd
+			     struct fw_packet *packet, u32 csr)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_packet response;
Jesse Keating 2f82dd
 	int tcode, length, i;
Jesse Keating 2f82dd
@@ -1122,8 +1118,8 @@ handle_local_rom(struct fw_ohci *ohci, s
Jesse Keating 2f82dd
 	fw_core_handle_response(&ohci->card, &response);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-handle_local_lock(struct fw_ohci *ohci, struct fw_packet *packet, u32 csr)
Jesse Keating 2f82dd
+static void handle_local_lock(struct fw_ohci *ohci,
Jesse Keating 2f82dd
+			      struct fw_packet *packet, u32 csr)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_packet response;
Jesse Keating 2f82dd
 	int tcode, length, ext_tcode, sel;
Jesse Keating 2f82dd
@@ -1164,8 +1160,7 @@ handle_local_lock(struct fw_ohci *ohci, 
Jesse Keating 2f82dd
 	fw_core_handle_response(&ohci->card, &response);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-handle_local_request(struct context *ctx, struct fw_packet *packet)
Jesse Keating 2f82dd
+static void handle_local_request(struct context *ctx, struct fw_packet *packet)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	u64 offset;
Jesse Keating 2f82dd
 	u32 csr;
Jesse Keating 2f82dd
@@ -1205,11 +1200,10 @@ handle_local_request(struct context *ctx
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-at_context_transmit(struct context *ctx, struct fw_packet *packet)
Jesse Keating 2f82dd
+static void at_context_transmit(struct context *ctx, struct fw_packet *packet)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	unsigned long flags;
Jesse Keating 2f82dd
-	int retval;
Jesse Keating 2f82dd
+	int ret;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	spin_lock_irqsave(&ctx->ohci->lock, flags);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
@@ -1220,10 +1214,10 @@ at_context_transmit(struct context *ctx,
Jesse Keating 2f82dd
 		return;
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	retval = at_context_queue_packet(ctx, packet);
Jesse Keating 2f82dd
+	ret = at_context_queue_packet(ctx, packet);
Jesse Keating 2f82dd
 	spin_unlock_irqrestore(&ctx->ohci->lock, flags);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	if (retval < 0)
Jesse Keating 2f82dd
+	if (ret < 0)
Jesse Keating 2f82dd
 		packet->callback(packet, &ctx->ohci->card, packet->ack);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
@@ -1590,12 +1584,12 @@ static int ohci_enable(struct fw_card *c
Jesse Keating 2f82dd
 	return 0;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static int
Jesse Keating 2f82dd
-ohci_set_config_rom(struct fw_card *card, u32 *config_rom, size_t length)
Jesse Keating 2f82dd
+static int ohci_set_config_rom(struct fw_card *card,
Jesse Keating 2f82dd
+			       u32 *config_rom, size_t length)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_ohci *ohci;
Jesse Keating 2f82dd
 	unsigned long flags;
Jesse Keating 2f82dd
-	int retval = -EBUSY;
Jesse Keating 2f82dd
+	int ret = -EBUSY;
Jesse Keating 2f82dd
 	__be32 *next_config_rom;
Jesse Keating 2f82dd
 	dma_addr_t uninitialized_var(next_config_rom_bus);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
@@ -1649,7 +1643,7 @@ ohci_set_config_rom(struct fw_card *card
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 		reg_write(ohci, OHCI1394_ConfigROMmap,
Jesse Keating 2f82dd
 			  ohci->next_config_rom_bus);
Jesse Keating 2f82dd
-		retval = 0;
Jesse Keating 2f82dd
+		ret = 0;
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	spin_unlock_irqrestore(&ohci->lock, flags);
Jesse Keating 2f82dd
@@ -1661,13 +1655,13 @@ ohci_set_config_rom(struct fw_card *card
Jesse Keating 2f82dd
 	 * controller could need to access it before the bus reset
Jesse Keating 2f82dd
 	 * takes effect.
Jesse Keating 2f82dd
 	 */
Jesse Keating 2f82dd
-	if (retval == 0)
Jesse Keating 2f82dd
+	if (ret == 0)
Jesse Keating 2f82dd
 		fw_core_initiate_bus_reset(&ohci->card, 1);
Jesse Keating 2f82dd
 	else
Jesse Keating 2f82dd
 		dma_free_coherent(ohci->card.device, CONFIG_ROM_SIZE,
Jesse Keating 2f82dd
 				  next_config_rom, next_config_rom_bus);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	return retval;
Jesse Keating 2f82dd
+	return ret;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 static void ohci_send_request(struct fw_card *card, struct fw_packet *packet)
Jesse Keating 2f82dd
@@ -1689,7 +1683,7 @@ static int ohci_cancel_packet(struct fw_
Jesse Keating 2f82dd
 	struct fw_ohci *ohci = fw_ohci(card);
Jesse Keating 2f82dd
 	struct context *ctx = &ohci->at_request_ctx;
Jesse Keating 2f82dd
 	struct driver_data *driver_data = packet->driver_data;
Jesse Keating 2f82dd
-	int retval = -ENOENT;
Jesse Keating 2f82dd
+	int ret = -ENOENT;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	tasklet_disable(&ctx->tasklet);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
@@ -1704,23 +1698,22 @@ static int ohci_cancel_packet(struct fw_
Jesse Keating 2f82dd
 	driver_data->packet = NULL;
Jesse Keating 2f82dd
 	packet->ack = RCODE_CANCELLED;
Jesse Keating 2f82dd
 	packet->callback(packet, &ohci->card, packet->ack);
Jesse Keating 2f82dd
-	retval = 0;
Jesse Keating 2f82dd
-
Jesse Keating 2f82dd
+	ret = 0;
Jesse Keating 2f82dd
  out:
Jesse Keating 2f82dd
 	tasklet_enable(&ctx->tasklet);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	return retval;
Jesse Keating 2f82dd
+	return ret;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static int
Jesse Keating 2f82dd
-ohci_enable_phys_dma(struct fw_card *card, int node_id, int generation)
Jesse Keating 2f82dd
+static int ohci_enable_phys_dma(struct fw_card *card,
Jesse Keating 2f82dd
+				int node_id, int generation)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 #ifdef CONFIG_FIREWIRE_OHCI_REMOTE_DMA
Jesse Keating 2f82dd
 	return 0;
Jesse Keating 2f82dd
 #else
Jesse Keating 2f82dd
 	struct fw_ohci *ohci = fw_ohci(card);
Jesse Keating 2f82dd
 	unsigned long flags;
Jesse Keating 2f82dd
-	int n, retval = 0;
Jesse Keating 2f82dd
+	int n, ret = 0;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	/*
Jesse Keating 2f82dd
 	 * FIXME:  Make sure this bitmask is cleared when we clear the busReset
Jesse Keating 2f82dd
@@ -1730,7 +1723,7 @@ ohci_enable_phys_dma(struct fw_card *car
Jesse Keating 2f82dd
 	spin_lock_irqsave(&ohci->lock, flags);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	if (ohci->generation != generation) {
Jesse Keating 2f82dd
-		retval = -ESTALE;
Jesse Keating 2f82dd
+		ret = -ESTALE;
Jesse Keating 2f82dd
 		goto out;
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
@@ -1748,12 +1741,12 @@ ohci_enable_phys_dma(struct fw_card *car
Jesse Keating 2f82dd
 	flush_writes(ohci);
Jesse Keating 2f82dd
  out:
Jesse Keating 2f82dd
 	spin_unlock_irqrestore(&ohci->lock, flags);
Jesse Keating 2f82dd
-	return retval;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	return ret;
Jesse Keating 2f82dd
 #endif /* CONFIG_FIREWIRE_OHCI_REMOTE_DMA */
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static u64
Jesse Keating 2f82dd
-ohci_get_bus_time(struct fw_card *card)
Jesse Keating 2f82dd
+static u64 ohci_get_bus_time(struct fw_card *card)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_ohci *ohci = fw_ohci(card);
Jesse Keating 2f82dd
 	u32 cycle_time;
Jesse Keating 2f82dd
@@ -1765,6 +1758,28 @@ ohci_get_bus_time(struct fw_card *card)
Jesse Keating 2f82dd
 	return bus_time;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
+static void copy_iso_headers(struct iso_context *ctx, void *p)
Jesse Keating 2f82dd
+{
Jesse Keating 2f82dd
+	int i = ctx->header_length;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	if (i + ctx->base.header_size > PAGE_SIZE)
Jesse Keating 2f82dd
+		return;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	/*
Jesse Keating 2f82dd
+	 * The iso header is byteswapped to little endian by
Jesse Keating 2f82dd
+	 * the controller, but the remaining header quadlets
Jesse Keating 2f82dd
+	 * are big endian.  We want to present all the headers
Jesse Keating 2f82dd
+	 * as big endian, so we have to swap the first quadlet.
Jesse Keating 2f82dd
+	 */
Jesse Keating 2f82dd
+	if (ctx->base.header_size > 0)
Jesse Keating 2f82dd
+		*(u32 *) (ctx->header + i) = __swab32(*(u32 *) (p + 4));
Jesse Keating 2f82dd
+	if (ctx->base.header_size > 4)
Jesse Keating 2f82dd
+		*(u32 *) (ctx->header + i + 4) = __swab32(*(u32 *) p);
Jesse Keating 2f82dd
+	if (ctx->base.header_size > 8)
Jesse Keating 2f82dd
+		memcpy(ctx->header + i + 8, p + 8, ctx->base.header_size - 8);
Jesse Keating 2f82dd
+	ctx->header_length += ctx->base.header_size;
Jesse Keating 2f82dd
+}
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
 static int handle_ir_dualbuffer_packet(struct context *context,
Jesse Keating 2f82dd
 				       struct descriptor *d,
Jesse Keating 2f82dd
 				       struct descriptor *last)
Jesse Keating 2f82dd
@@ -1775,7 +1790,6 @@ static int handle_ir_dualbuffer_packet(s
Jesse Keating 2f82dd
 	__le32 *ir_header;
Jesse Keating 2f82dd
 	size_t header_length;
Jesse Keating 2f82dd
 	void *p, *end;
Jesse Keating 2f82dd
-	int i;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	if (db->first_res_count != 0 && db->second_res_count != 0) {
Jesse Keating 2f82dd
 		if (ctx->excess_bytes <= le16_to_cpu(db->second_req_count)) {
Jesse Keating 2f82dd
@@ -1788,25 +1802,14 @@ static int handle_ir_dualbuffer_packet(s
Jesse Keating 2f82dd
 	header_length = le16_to_cpu(db->first_req_count) -
Jesse Keating 2f82dd
 		le16_to_cpu(db->first_res_count);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	i = ctx->header_length;
Jesse Keating 2f82dd
 	p = db + 1;
Jesse Keating 2f82dd
 	end = p + header_length;
Jesse Keating 2f82dd
-	while (p < end && i + ctx->base.header_size <= PAGE_SIZE) {
Jesse Keating 2f82dd
-		/*
Jesse Keating 2f82dd
-		 * The iso header is byteswapped to little endian by
Jesse Keating 2f82dd
-		 * the controller, but the remaining header quadlets
Jesse Keating 2f82dd
-		 * are big endian.  We want to present all the headers
Jesse Keating 2f82dd
-		 * as big endian, so we have to swap the first
Jesse Keating 2f82dd
-		 * quadlet.
Jesse Keating 2f82dd
-		 */
Jesse Keating 2f82dd
-		*(u32 *) (ctx->header + i) = __swab32(*(u32 *) (p + 4));
Jesse Keating 2f82dd
-		memcpy(ctx->header + i + 4, p + 8, ctx->base.header_size - 4);
Jesse Keating 2f82dd
-		i += ctx->base.header_size;
Jesse Keating 2f82dd
+	while (p < end) {
Jesse Keating 2f82dd
+		copy_iso_headers(ctx, p);
Jesse Keating 2f82dd
 		ctx->excess_bytes +=
Jesse Keating 2f82dd
 			(le32_to_cpu(*(__le32 *)(p + 4)) >> 16) & 0xffff;
Jesse Keating 2f82dd
-		p += ctx->base.header_size + 4;
Jesse Keating 2f82dd
+		p += max(ctx->base.header_size, (size_t)8);
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
-	ctx->header_length = i;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	ctx->excess_bytes -= le16_to_cpu(db->second_req_count) -
Jesse Keating 2f82dd
 		le16_to_cpu(db->second_res_count);
Jesse Keating 2f82dd
@@ -1832,7 +1835,6 @@ static int handle_ir_packet_per_buffer(s
Jesse Keating 2f82dd
 	struct descriptor *pd;
Jesse Keating 2f82dd
 	__le32 *ir_header;
Jesse Keating 2f82dd
 	void *p;
Jesse Keating 2f82dd
-	int i;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	for (pd = d; pd <= last; pd++) {
Jesse Keating 2f82dd
 		if (pd->transfer_status)
Jesse Keating 2f82dd
@@ -1842,21 +1844,8 @@ static int handle_ir_packet_per_buffer(s
Jesse Keating 2f82dd
 		/* Descriptor(s) not done yet, stop iteration */
Jesse Keating 2f82dd
 		return 0;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	i   = ctx->header_length;
Jesse Keating 2f82dd
-	p   = last + 1;
Jesse Keating 2f82dd
-
Jesse Keating 2f82dd
-	if (ctx->base.header_size > 0 &&
Jesse Keating 2f82dd
-			i + ctx->base.header_size <= PAGE_SIZE) {
Jesse Keating 2f82dd
-		/*
Jesse Keating 2f82dd
-		 * The iso header is byteswapped to little endian by
Jesse Keating 2f82dd
-		 * the controller, but the remaining header quadlets
Jesse Keating 2f82dd
-		 * are big endian.  We want to present all the headers
Jesse Keating 2f82dd
-		 * as big endian, so we have to swap the first quadlet.
Jesse Keating 2f82dd
-		 */
Jesse Keating 2f82dd
-		*(u32 *) (ctx->header + i) = __swab32(*(u32 *) (p + 4));
Jesse Keating 2f82dd
-		memcpy(ctx->header + i + 4, p + 8, ctx->base.header_size - 4);
Jesse Keating 2f82dd
-		ctx->header_length += ctx->base.header_size;
Jesse Keating 2f82dd
-	}
Jesse Keating 2f82dd
+	p = last + 1;
Jesse Keating 2f82dd
+	copy_iso_headers(ctx, p);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	if (le16_to_cpu(last->control) & DESCRIPTOR_IRQ_ALWAYS) {
Jesse Keating 2f82dd
 		ir_header = (__le32 *) p;
Jesse Keating 2f82dd
@@ -1888,21 +1877,24 @@ static int handle_it_packet(struct conte
Jesse Keating 2f82dd
 	return 1;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static struct fw_iso_context *
Jesse Keating 2f82dd
-ohci_allocate_iso_context(struct fw_card *card, int type, size_t header_size)
Jesse Keating 2f82dd
+static struct fw_iso_context *ohci_allocate_iso_context(struct fw_card *card,
Jesse Keating 2f82dd
+				int type, int channel, size_t header_size)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_ohci *ohci = fw_ohci(card);
Jesse Keating 2f82dd
 	struct iso_context *ctx, *list;
Jesse Keating 2f82dd
 	descriptor_callback_t callback;
Jesse Keating 2f82dd
+	u64 *channels, dont_care = ~0ULL;
Jesse Keating 2f82dd
 	u32 *mask, regs;
Jesse Keating 2f82dd
 	unsigned long flags;
Jesse Keating 2f82dd
-	int index, retval = -ENOMEM;
Jesse Keating 2f82dd
+	int index, ret = -ENOMEM;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	if (type == FW_ISO_CONTEXT_TRANSMIT) {
Jesse Keating 2f82dd
+		channels = &dont_care;
Jesse Keating 2f82dd
 		mask = &ohci->it_context_mask;
Jesse Keating 2f82dd
 		list = ohci->it_context_list;
Jesse Keating 2f82dd
 		callback = handle_it_packet;
Jesse Keating 2f82dd
 	} else {
Jesse Keating 2f82dd
+		channels = &ohci->ir_context_channels;
Jesse Keating 2f82dd
 		mask = &ohci->ir_context_mask;
Jesse Keating 2f82dd
 		list = ohci->ir_context_list;
Jesse Keating 2f82dd
 		if (ohci->use_dualbuffer)
Jesse Keating 2f82dd
@@ -1912,9 +1904,11 @@ ohci_allocate_iso_context(struct fw_card
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	spin_lock_irqsave(&ohci->lock, flags);
Jesse Keating 2f82dd
-	index = ffs(*mask) - 1;
Jesse Keating 2f82dd
-	if (index >= 0)
Jesse Keating 2f82dd
+	index = *channels & 1ULL << channel ? ffs(*mask) - 1 : -1;
Jesse Keating 2f82dd
+	if (index >= 0) {
Jesse Keating 2f82dd
+		*channels &= ~(1ULL << channel);
Jesse Keating 2f82dd
 		*mask &= ~(1 << index);
Jesse Keating 2f82dd
+	}
Jesse Keating 2f82dd
 	spin_unlock_irqrestore(&ohci->lock, flags);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	if (index < 0)
Jesse Keating 2f82dd
@@ -1932,8 +1926,8 @@ ohci_allocate_iso_context(struct fw_card
Jesse Keating 2f82dd
 	if (ctx->header == NULL)
Jesse Keating 2f82dd
 		goto out;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	retval = context_init(&ctx->context, ohci, regs, callback);
Jesse Keating 2f82dd
-	if (retval < 0)
Jesse Keating 2f82dd
+	ret = context_init(&ctx->context, ohci, regs, callback);
Jesse Keating 2f82dd
+	if (ret < 0)
Jesse Keating 2f82dd
 		goto out_with_header;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	return &ctx->base;
Jesse Keating 2f82dd
@@ -1945,7 +1939,7 @@ ohci_allocate_iso_context(struct fw_card
Jesse Keating 2f82dd
 	*mask |= 1 << index;
Jesse Keating 2f82dd
 	spin_unlock_irqrestore(&ohci->lock, flags);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	return ERR_PTR(retval);
Jesse Keating 2f82dd
+	return ERR_PTR(ret);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 static int ohci_start_iso(struct fw_iso_context *base,
Jesse Keating 2f82dd
@@ -2024,16 +2018,16 @@ static void ohci_free_iso_context(struct
Jesse Keating 2f82dd
 	} else {
Jesse Keating 2f82dd
 		index = ctx - ohci->ir_context_list;
Jesse Keating 2f82dd
 		ohci->ir_context_mask |= 1 << index;
Jesse Keating 2f82dd
+		ohci->ir_context_channels |= 1ULL << base->channel;
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	spin_unlock_irqrestore(&ohci->lock, flags);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static int
Jesse Keating 2f82dd
-ohci_queue_iso_transmit(struct fw_iso_context *base,
Jesse Keating 2f82dd
-			struct fw_iso_packet *packet,
Jesse Keating 2f82dd
-			struct fw_iso_buffer *buffer,
Jesse Keating 2f82dd
-			unsigned long payload)
Jesse Keating 2f82dd
+static int ohci_queue_iso_transmit(struct fw_iso_context *base,
Jesse Keating 2f82dd
+				   struct fw_iso_packet *packet,
Jesse Keating 2f82dd
+				   struct fw_iso_buffer *buffer,
Jesse Keating 2f82dd
+				   unsigned long payload)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct iso_context *ctx = container_of(base, struct iso_context, base);
Jesse Keating 2f82dd
 	struct descriptor *d, *last, *pd;
Jesse Keating 2f82dd
@@ -2128,11 +2122,10 @@ ohci_queue_iso_transmit(struct fw_iso_co
Jesse Keating 2f82dd
 	return 0;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static int
Jesse Keating 2f82dd
-ohci_queue_iso_receive_dualbuffer(struct fw_iso_context *base,
Jesse Keating 2f82dd
-				  struct fw_iso_packet *packet,
Jesse Keating 2f82dd
-				  struct fw_iso_buffer *buffer,
Jesse Keating 2f82dd
-				  unsigned long payload)
Jesse Keating 2f82dd
+static int ohci_queue_iso_receive_dualbuffer(struct fw_iso_context *base,
Jesse Keating 2f82dd
+					     struct fw_iso_packet *packet,
Jesse Keating 2f82dd
+					     struct fw_iso_buffer *buffer,
Jesse Keating 2f82dd
+					     unsigned long payload)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct iso_context *ctx = container_of(base, struct iso_context, base);
Jesse Keating 2f82dd
 	struct db_descriptor *db = NULL;
Jesse Keating 2f82dd
@@ -2151,11 +2144,11 @@ ohci_queue_iso_receive_dualbuffer(struct
Jesse Keating 2f82dd
 	z = 2;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	/*
Jesse Keating 2f82dd
-	 * The OHCI controller puts the status word in the header
Jesse Keating 2f82dd
-	 * buffer too, so we need 4 extra bytes per packet.
Jesse Keating 2f82dd
+	 * The OHCI controller puts the isochronous header and trailer in the
Jesse Keating 2f82dd
+	 * buffer, so we need at least 8 bytes.
Jesse Keating 2f82dd
 	 */
Jesse Keating 2f82dd
 	packet_count = p->header_length / ctx->base.header_size;
Jesse Keating 2f82dd
-	header_size = packet_count * (ctx->base.header_size + 4);
Jesse Keating 2f82dd
+	header_size = packet_count * max(ctx->base.header_size, (size_t)8);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	/* Get header size in number of descriptors. */
Jesse Keating 2f82dd
 	header_z = DIV_ROUND_UP(header_size, sizeof(*d));
Jesse Keating 2f82dd
@@ -2173,7 +2166,8 @@ ohci_queue_iso_receive_dualbuffer(struct
Jesse Keating 2f82dd
 		db = (struct db_descriptor *) d;
Jesse Keating 2f82dd
 		db->control = cpu_to_le16(DESCRIPTOR_STATUS |
Jesse Keating 2f82dd
 					  DESCRIPTOR_BRANCH_ALWAYS);
Jesse Keating 2f82dd
-		db->first_size = cpu_to_le16(ctx->base.header_size + 4);
Jesse Keating 2f82dd
+		db->first_size =
Jesse Keating 2f82dd
+		    cpu_to_le16(max(ctx->base.header_size, (size_t)8));
Jesse Keating 2f82dd
 		if (p->skip && rest == p->payload_length) {
Jesse Keating 2f82dd
 			db->control |= cpu_to_le16(DESCRIPTOR_WAIT);
Jesse Keating 2f82dd
 			db->first_req_count = db->first_size;
Jesse Keating 2f82dd
@@ -2208,11 +2202,10 @@ ohci_queue_iso_receive_dualbuffer(struct
Jesse Keating 2f82dd
 	return 0;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static int
Jesse Keating 2f82dd
-ohci_queue_iso_receive_packet_per_buffer(struct fw_iso_context *base,
Jesse Keating 2f82dd
-					 struct fw_iso_packet *packet,
Jesse Keating 2f82dd
-					 struct fw_iso_buffer *buffer,
Jesse Keating 2f82dd
-					 unsigned long payload)
Jesse Keating 2f82dd
+static int ohci_queue_iso_receive_packet_per_buffer(struct fw_iso_context *base,
Jesse Keating 2f82dd
+					struct fw_iso_packet *packet,
Jesse Keating 2f82dd
+					struct fw_iso_buffer *buffer,
Jesse Keating 2f82dd
+					unsigned long payload)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct iso_context *ctx = container_of(base, struct iso_context, base);
Jesse Keating 2f82dd
 	struct descriptor *d = NULL, *pd = NULL;
Jesse Keating 2f82dd
@@ -2223,11 +2216,11 @@ ohci_queue_iso_receive_packet_per_buffer
Jesse Keating 2f82dd
 	int page, offset, packet_count, header_size, payload_per_buffer;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	/*
Jesse Keating 2f82dd
-	 * The OHCI controller puts the status word in the
Jesse Keating 2f82dd
-	 * buffer too, so we need 4 extra bytes per packet.
Jesse Keating 2f82dd
+	 * The OHCI controller puts the isochronous header and trailer in the
Jesse Keating 2f82dd
+	 * buffer, so we need at least 8 bytes.
Jesse Keating 2f82dd
 	 */
Jesse Keating 2f82dd
 	packet_count = p->header_length / ctx->base.header_size;
Jesse Keating 2f82dd
-	header_size  = ctx->base.header_size + 4;
Jesse Keating 2f82dd
+	header_size  = max(ctx->base.header_size, (size_t)8);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	/* Get header size in number of descriptors. */
Jesse Keating 2f82dd
 	header_z = DIV_ROUND_UP(header_size, sizeof(*d));
Jesse Keating 2f82dd
@@ -2286,29 +2279,27 @@ ohci_queue_iso_receive_packet_per_buffer
Jesse Keating 2f82dd
 	return 0;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static int
Jesse Keating 2f82dd
-ohci_queue_iso(struct fw_iso_context *base,
Jesse Keating 2f82dd
-	       struct fw_iso_packet *packet,
Jesse Keating 2f82dd
-	       struct fw_iso_buffer *buffer,
Jesse Keating 2f82dd
-	       unsigned long payload)
Jesse Keating 2f82dd
+static int ohci_queue_iso(struct fw_iso_context *base,
Jesse Keating 2f82dd
+			  struct fw_iso_packet *packet,
Jesse Keating 2f82dd
+			  struct fw_iso_buffer *buffer,
Jesse Keating 2f82dd
+			  unsigned long payload)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct iso_context *ctx = container_of(base, struct iso_context, base);
Jesse Keating 2f82dd
 	unsigned long flags;
Jesse Keating 2f82dd
-	int retval;
Jesse Keating 2f82dd
+	int ret;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	spin_lock_irqsave(&ctx->context.ohci->lock, flags);
Jesse Keating 2f82dd
 	if (base->type == FW_ISO_CONTEXT_TRANSMIT)
Jesse Keating 2f82dd
-		retval = ohci_queue_iso_transmit(base, packet, buffer, payload);
Jesse Keating 2f82dd
+		ret = ohci_queue_iso_transmit(base, packet, buffer, payload);
Jesse Keating 2f82dd
 	else if (ctx->context.ohci->use_dualbuffer)
Jesse Keating 2f82dd
-		retval = ohci_queue_iso_receive_dualbuffer(base, packet,
Jesse Keating 2f82dd
-							 buffer, payload);
Jesse Keating 2f82dd
+		ret = ohci_queue_iso_receive_dualbuffer(base, packet,
Jesse Keating 2f82dd
+							buffer, payload);
Jesse Keating 2f82dd
 	else
Jesse Keating 2f82dd
-		retval = ohci_queue_iso_receive_packet_per_buffer(base, packet,
Jesse Keating 2f82dd
-								buffer,
Jesse Keating 2f82dd
-								payload);
Jesse Keating 2f82dd
+		ret = ohci_queue_iso_receive_packet_per_buffer(base, packet,
Jesse Keating 2f82dd
+							buffer, payload);
Jesse Keating 2f82dd
 	spin_unlock_irqrestore(&ctx->context.ohci->lock, flags);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	return retval;
Jesse Keating 2f82dd
+	return ret;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 static const struct fw_card_driver ohci_driver = {
Jesse Keating 2f82dd
@@ -2357,8 +2348,8 @@ static void ohci_pmac_off(struct pci_dev
Jesse Keating 2f82dd
 #define ohci_pmac_off(dev)
Jesse Keating 2f82dd
 #endif /* CONFIG_PPC_PMAC */
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static int __devinit
Jesse Keating 2f82dd
-pci_probe(struct pci_dev *dev, const struct pci_device_id *ent)
Jesse Keating 2f82dd
+static int __devinit pci_probe(struct pci_dev *dev,
Jesse Keating 2f82dd
+			       const struct pci_device_id *ent)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_ohci *ohci;
Jesse Keating 2f82dd
 	u32 bus_options, max_receive, link_speed, version;
Jesse Keating 2f82dd
@@ -2440,6 +2431,7 @@ pci_probe(struct pci_dev *dev, const str
Jesse Keating 2f82dd
 	ohci->it_context_list = kzalloc(size, GFP_KERNEL);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	reg_write(ohci, OHCI1394_IsoXmitIntMaskSet, ~0);
Jesse Keating 2f82dd
+	ohci->ir_context_channels = ~0ULL;
Jesse Keating 2f82dd
 	ohci->ir_context_mask = reg_read(ohci, OHCI1394_IsoXmitIntMaskSet);
Jesse Keating 2f82dd
 	reg_write(ohci, OHCI1394_IsoXmitIntMaskClear, ~0);
Jesse Keating 2f82dd
 	size = sizeof(struct iso_context) * hweight32(ohci->ir_context_mask);
Jesse Keating 2f82dd
diff -Naurp linux-2.6-git/drivers/firewire/fw-sbp2.c firewire-git/drivers/firewire/fw-sbp2.c
Jesse Keating 2f82dd
--- linux-2.6-git/drivers/firewire/fw-sbp2.c	2009-01-30 13:39:02.991771976 -0500
Jesse Keating 2f82dd
+++ firewire-git/drivers/firewire/fw-sbp2.c	2009-01-30 13:35:51.861646907 -0500
Jesse Keating 2f82dd
@@ -392,20 +392,18 @@ static const struct {
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
 };
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-free_orb(struct kref *kref)
Jesse Keating 2f82dd
+static void free_orb(struct kref *kref)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct sbp2_orb *orb = container_of(kref, struct sbp2_orb, kref);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	kfree(orb);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-sbp2_status_write(struct fw_card *card, struct fw_request *request,
Jesse Keating 2f82dd
-		  int tcode, int destination, int source,
Jesse Keating 2f82dd
-		  int generation, int speed,
Jesse Keating 2f82dd
-		  unsigned long long offset,
Jesse Keating 2f82dd
-		  void *payload, size_t length, void *callback_data)
Jesse Keating 2f82dd
+static void sbp2_status_write(struct fw_card *card, struct fw_request *request,
Jesse Keating 2f82dd
+			      int tcode, int destination, int source,
Jesse Keating 2f82dd
+			      int generation, int speed,
Jesse Keating 2f82dd
+			      unsigned long long offset,
Jesse Keating 2f82dd
+			      void *payload, size_t length, void *callback_data)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct sbp2_logical_unit *lu = callback_data;
Jesse Keating 2f82dd
 	struct sbp2_orb *orb;
Jesse Keating 2f82dd
@@ -451,9 +449,8 @@ sbp2_status_write(struct fw_card *card, 
Jesse Keating 2f82dd
 	fw_send_response(card, request, RCODE_COMPLETE);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-complete_transaction(struct fw_card *card, int rcode,
Jesse Keating 2f82dd
-		     void *payload, size_t length, void *data)
Jesse Keating 2f82dd
+static void complete_transaction(struct fw_card *card, int rcode,
Jesse Keating 2f82dd
+				 void *payload, size_t length, void *data)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct sbp2_orb *orb = data;
Jesse Keating 2f82dd
 	unsigned long flags;
Jesse Keating 2f82dd
@@ -482,9 +479,8 @@ complete_transaction(struct fw_card *car
Jesse Keating 2f82dd
 	kref_put(&orb->kref, free_orb);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-sbp2_send_orb(struct sbp2_orb *orb, struct sbp2_logical_unit *lu,
Jesse Keating 2f82dd
-	      int node_id, int generation, u64 offset)
Jesse Keating 2f82dd
+static void sbp2_send_orb(struct sbp2_orb *orb, struct sbp2_logical_unit *lu,
Jesse Keating 2f82dd
+			  int node_id, int generation, u64 offset)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_device *device = fw_device(lu->tgt->unit->device.parent);
Jesse Keating 2f82dd
 	unsigned long flags;
Jesse Keating 2f82dd
@@ -531,8 +527,8 @@ static int sbp2_cancel_orbs(struct sbp2_
Jesse Keating 2f82dd
 	return retval;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-complete_management_orb(struct sbp2_orb *base_orb, struct sbp2_status *status)
Jesse Keating 2f82dd
+static void complete_management_orb(struct sbp2_orb *base_orb,
Jesse Keating 2f82dd
+				    struct sbp2_status *status)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct sbp2_management_orb *orb =
Jesse Keating 2f82dd
 		container_of(base_orb, struct sbp2_management_orb, base);
Jesse Keating 2f82dd
@@ -542,10 +538,9 @@ complete_management_orb(struct sbp2_orb 
Jesse Keating 2f82dd
 	complete(&orb->done);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static int
Jesse Keating 2f82dd
-sbp2_send_management_orb(struct sbp2_logical_unit *lu, int node_id,
Jesse Keating 2f82dd
-			 int generation, int function, int lun_or_login_id,
Jesse Keating 2f82dd
-			 void *response)
Jesse Keating 2f82dd
+static int sbp2_send_management_orb(struct sbp2_logical_unit *lu, int node_id,
Jesse Keating 2f82dd
+				    int generation, int function,
Jesse Keating 2f82dd
+				    int lun_or_login_id, void *response)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_device *device = fw_device(lu->tgt->unit->device.parent);
Jesse Keating 2f82dd
 	struct sbp2_management_orb *orb;
Jesse Keating 2f82dd
@@ -652,9 +647,8 @@ static void sbp2_agent_reset(struct sbp2
Jesse Keating 2f82dd
 			   &d, sizeof(d));
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-complete_agent_reset_write_no_wait(struct fw_card *card, int rcode,
Jesse Keating 2f82dd
-				   void *payload, size_t length, void *data)
Jesse Keating 2f82dd
+static void complete_agent_reset_write_no_wait(struct fw_card *card,
Jesse Keating 2f82dd
+		int rcode, void *payload, size_t length, void *data)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	kfree(data);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
@@ -1299,8 +1293,7 @@ static void sbp2_unmap_scatterlist(struc
Jesse Keating 2f82dd
 				 sizeof(orb->page_table), DMA_TO_DEVICE);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static unsigned int
Jesse Keating 2f82dd
-sbp2_status_to_sense_data(u8 *sbp2_status, u8 *sense_data)
Jesse Keating 2f82dd
+static unsigned int sbp2_status_to_sense_data(u8 *sbp2_status, u8 *sense_data)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	int sam_status;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
@@ -1337,8 +1330,8 @@ sbp2_status_to_sense_data(u8 *sbp2_statu
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-complete_command_orb(struct sbp2_orb *base_orb, struct sbp2_status *status)
Jesse Keating 2f82dd
+static void complete_command_orb(struct sbp2_orb *base_orb,
Jesse Keating 2f82dd
+				 struct sbp2_status *status)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct sbp2_command_orb *orb =
Jesse Keating 2f82dd
 		container_of(base_orb, struct sbp2_command_orb, base);
Jesse Keating 2f82dd
@@ -1384,9 +1377,8 @@ complete_command_orb(struct sbp2_orb *ba
Jesse Keating 2f82dd
 	orb->done(orb->cmd);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static int
Jesse Keating 2f82dd
-sbp2_map_scatterlist(struct sbp2_command_orb *orb, struct fw_device *device,
Jesse Keating 2f82dd
-		     struct sbp2_logical_unit *lu)
Jesse Keating 2f82dd
+static int sbp2_map_scatterlist(struct sbp2_command_orb *orb,
Jesse Keating 2f82dd
+		struct fw_device *device, struct sbp2_logical_unit *lu)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct scatterlist *sg = scsi_sglist(orb->cmd);
Jesse Keating 2f82dd
 	int i, n;
Jesse Keating 2f82dd
@@ -1584,9 +1576,8 @@ static int sbp2_scsi_abort(struct scsi_c
Jesse Keating 2f82dd
  * This is the concatenation of target port identifier and logical unit
Jesse Keating 2f82dd
  * identifier as per SAM-2...SAM-4 annex A.
Jesse Keating 2f82dd
  */
Jesse Keating 2f82dd
-static ssize_t
Jesse Keating 2f82dd
-sbp2_sysfs_ieee1394_id_show(struct device *dev, struct device_attribute *attr,
Jesse Keating 2f82dd
-			    char *buf)
Jesse Keating 2f82dd
+static ssize_t sbp2_sysfs_ieee1394_id_show(struct device *dev,
Jesse Keating 2f82dd
+			struct device_attribute *attr, char *buf)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct scsi_device *sdev = to_scsi_device(dev);
Jesse Keating 2f82dd
 	struct sbp2_logical_unit *lu;
Jesse Keating 2f82dd
diff -Naurp linux-2.6-git/drivers/firewire/fw-topology.c firewire-git/drivers/firewire/fw-topology.c
Jesse Keating 2f82dd
--- linux-2.6-git/drivers/firewire/fw-topology.c	2009-01-30 13:39:02.991771976 -0500
Jesse Keating 2f82dd
+++ firewire-git/drivers/firewire/fw-topology.c	2009-01-30 13:35:51.862647087 -0500
Jesse Keating 2f82dd
@@ -314,9 +314,8 @@ typedef void (*fw_node_callback_t)(struc
Jesse Keating 2f82dd
 				   struct fw_node * node,
Jesse Keating 2f82dd
 				   struct fw_node * parent);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-for_each_fw_node(struct fw_card *card, struct fw_node *root,
Jesse Keating 2f82dd
-		 fw_node_callback_t callback)
Jesse Keating 2f82dd
+static void for_each_fw_node(struct fw_card *card, struct fw_node *root,
Jesse Keating 2f82dd
+			     fw_node_callback_t callback)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct list_head list;
Jesse Keating 2f82dd
 	struct fw_node *node, *next, *child, *parent;
Jesse Keating 2f82dd
@@ -349,9 +348,8 @@ for_each_fw_node(struct fw_card *card, s
Jesse Keating 2f82dd
 		fw_node_put(node);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-report_lost_node(struct fw_card *card,
Jesse Keating 2f82dd
-		 struct fw_node *node, struct fw_node *parent)
Jesse Keating 2f82dd
+static void report_lost_node(struct fw_card *card,
Jesse Keating 2f82dd
+			     struct fw_node *node, struct fw_node *parent)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	fw_node_event(card, node, FW_NODE_DESTROYED);
Jesse Keating 2f82dd
 	fw_node_put(node);
Jesse Keating 2f82dd
@@ -360,9 +358,8 @@ report_lost_node(struct fw_card *card,
Jesse Keating 2f82dd
 	card->bm_retries = 0;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-report_found_node(struct fw_card *card,
Jesse Keating 2f82dd
-		  struct fw_node *node, struct fw_node *parent)
Jesse Keating 2f82dd
+static void report_found_node(struct fw_card *card,
Jesse Keating 2f82dd
+			      struct fw_node *node, struct fw_node *parent)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	int b_path = (node->phy_speed == SCODE_BETA);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
@@ -415,8 +412,7 @@ static void move_tree(struct fw_node *no
Jesse Keating 2f82dd
  * found, lost or updated.  Update the nodes in the card topology tree
Jesse Keating 2f82dd
  * as we go.
Jesse Keating 2f82dd
  */
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-update_tree(struct fw_card *card, struct fw_node *root)
Jesse Keating 2f82dd
+static void update_tree(struct fw_card *card, struct fw_node *root)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct list_head list0, list1;
Jesse Keating 2f82dd
 	struct fw_node *node0, *node1, *next1;
Jesse Keating 2f82dd
@@ -497,8 +493,8 @@ update_tree(struct fw_card *card, struct
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-update_topology_map(struct fw_card *card, u32 *self_ids, int self_id_count)
Jesse Keating 2f82dd
+static void update_topology_map(struct fw_card *card,
Jesse Keating 2f82dd
+				u32 *self_ids, int self_id_count)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	int node_count;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
@@ -510,10 +506,8 @@ update_topology_map(struct fw_card *card
Jesse Keating 2f82dd
 	fw_compute_block_crc(card->topology_map);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-void
Jesse Keating 2f82dd
-fw_core_handle_bus_reset(struct fw_card *card,
Jesse Keating 2f82dd
-			 int node_id, int generation,
Jesse Keating 2f82dd
-			 int self_id_count, u32 * self_ids)
Jesse Keating 2f82dd
+void fw_core_handle_bus_reset(struct fw_card *card, int node_id, int generation,
Jesse Keating 2f82dd
+			      int self_id_count, u32 *self_ids)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_node *local_node;
Jesse Keating 2f82dd
 	unsigned long flags;
Jesse Keating 2f82dd
diff -Naurp linux-2.6-git/drivers/firewire/fw-topology.h firewire-git/drivers/firewire/fw-topology.h
Jesse Keating 2f82dd
--- linux-2.6-git/drivers/firewire/fw-topology.h	2008-11-04 11:18:33.000000000 -0500
Jesse Keating 2f82dd
+++ firewire-git/drivers/firewire/fw-topology.h	2009-01-30 13:35:51.862647087 -0500
Jesse Keating 2f82dd
@@ -19,6 +19,11 @@
Jesse Keating 2f82dd
 #ifndef __fw_topology_h
Jesse Keating 2f82dd
 #define __fw_topology_h
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
+#include <linux list.h="">
Jesse Keating 2f82dd
+#include <linux slab.h="">
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+#include <asm atomic.h="">
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
 enum {
Jesse Keating 2f82dd
 	FW_NODE_CREATED,
Jesse Keating 2f82dd
 	FW_NODE_UPDATED,
Jesse Keating 2f82dd
@@ -51,26 +56,22 @@ struct fw_node {
Jesse Keating 2f82dd
 	struct fw_node *ports[0];
Jesse Keating 2f82dd
 };
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static inline struct fw_node *
Jesse Keating 2f82dd
-fw_node_get(struct fw_node *node)
Jesse Keating 2f82dd
+static inline struct fw_node *fw_node_get(struct fw_node *node)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	atomic_inc(&node->ref_count);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	return node;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static inline void
Jesse Keating 2f82dd
-fw_node_put(struct fw_node *node)
Jesse Keating 2f82dd
+static inline void fw_node_put(struct fw_node *node)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	if (atomic_dec_and_test(&node->ref_count))
Jesse Keating 2f82dd
 		kfree(node);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-void
Jesse Keating 2f82dd
-fw_destroy_nodes(struct fw_card *card);
Jesse Keating 2f82dd
-
Jesse Keating 2f82dd
-int
Jesse Keating 2f82dd
-fw_compute_block_crc(u32 *block);
Jesse Keating 2f82dd
+struct fw_card;
Jesse Keating 2f82dd
+void fw_destroy_nodes(struct fw_card *card);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
+int fw_compute_block_crc(u32 *block);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 #endif /* __fw_topology_h */
Jesse Keating 2f82dd
diff -Naurp linux-2.6-git/drivers/firewire/fw-transaction.c firewire-git/drivers/firewire/fw-transaction.c
Jesse Keating 2f82dd
--- linux-2.6-git/drivers/firewire/fw-transaction.c	2009-01-30 13:39:02.991771976 -0500
Jesse Keating 2f82dd
+++ firewire-git/drivers/firewire/fw-transaction.c	2009-01-30 13:35:51.862647087 -0500
Jesse Keating 2f82dd
@@ -64,10 +64,9 @@
Jesse Keating 2f82dd
 #define PHY_CONFIG_ROOT_ID(node_id)	((((node_id) & 0x3f) << 24) | (1 << 23))
Jesse Keating 2f82dd
 #define PHY_IDENTIFIER(id)		((id) << 30)
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static int
Jesse Keating 2f82dd
-close_transaction(struct fw_transaction *transaction,
Jesse Keating 2f82dd
-		  struct fw_card *card, int rcode,
Jesse Keating 2f82dd
-		  u32 *payload, size_t length)
Jesse Keating 2f82dd
+static int close_transaction(struct fw_transaction *transaction,
Jesse Keating 2f82dd
+			     struct fw_card *card, int rcode,
Jesse Keating 2f82dd
+			     u32 *payload, size_t length)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_transaction *t;
Jesse Keating 2f82dd
 	unsigned long flags;
Jesse Keating 2f82dd
@@ -94,9 +93,8 @@ close_transaction(struct fw_transaction 
Jesse Keating 2f82dd
  * Only valid for transactions that are potentially pending (ie have
Jesse Keating 2f82dd
  * been sent).
Jesse Keating 2f82dd
  */
Jesse Keating 2f82dd
-int
Jesse Keating 2f82dd
-fw_cancel_transaction(struct fw_card *card,
Jesse Keating 2f82dd
-		      struct fw_transaction *transaction)
Jesse Keating 2f82dd
+int fw_cancel_transaction(struct fw_card *card,
Jesse Keating 2f82dd
+			  struct fw_transaction *transaction)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	/*
Jesse Keating 2f82dd
 	 * Cancel the packet transmission if it's still queued.  That
Jesse Keating 2f82dd
@@ -116,9 +114,8 @@ fw_cancel_transaction(struct fw_card *ca
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 EXPORT_SYMBOL(fw_cancel_transaction);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-transmit_complete_callback(struct fw_packet *packet,
Jesse Keating 2f82dd
-			   struct fw_card *card, int status)
Jesse Keating 2f82dd
+static void transmit_complete_callback(struct fw_packet *packet,
Jesse Keating 2f82dd
+				       struct fw_card *card, int status)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_transaction *t =
Jesse Keating 2f82dd
 	    container_of(packet, struct fw_transaction, packet);
Jesse Keating 2f82dd
@@ -151,8 +148,7 @@ transmit_complete_callback(struct fw_pac
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-fw_fill_request(struct fw_packet *packet, int tcode, int tlabel,
Jesse Keating 2f82dd
+static void fw_fill_request(struct fw_packet *packet, int tcode, int tlabel,
Jesse Keating 2f82dd
 		int destination_id, int source_id, int generation, int speed,
Jesse Keating 2f82dd
 		unsigned long long offset, void *payload, size_t length)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
@@ -247,12 +243,10 @@ fw_fill_request(struct fw_packet *packet
Jesse Keating 2f82dd
  * @param callback_data pointer to arbitrary data, which will be
Jesse Keating 2f82dd
  *   passed to the callback
Jesse Keating 2f82dd
  */
Jesse Keating 2f82dd
-void
Jesse Keating 2f82dd
-fw_send_request(struct fw_card *card, struct fw_transaction *t,
Jesse Keating 2f82dd
-		int tcode, int destination_id, int generation, int speed,
Jesse Keating 2f82dd
-		unsigned long long offset,
Jesse Keating 2f82dd
-		void *payload, size_t length,
Jesse Keating 2f82dd
-		fw_transaction_callback_t callback, void *callback_data)
Jesse Keating 2f82dd
+void fw_send_request(struct fw_card *card, struct fw_transaction *t, int tcode,
Jesse Keating 2f82dd
+		     int destination_id, int generation, int speed,
Jesse Keating 2f82dd
+		     unsigned long long offset, void *payload, size_t length,
Jesse Keating 2f82dd
+		     fw_transaction_callback_t callback, void *callback_data)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	unsigned long flags;
Jesse Keating 2f82dd
 	int tlabel;
Jesse Keating 2f82dd
@@ -322,8 +316,8 @@ static void transaction_callback(struct 
Jesse Keating 2f82dd
  * Returns the RCODE.
Jesse Keating 2f82dd
  */
Jesse Keating 2f82dd
 int fw_run_transaction(struct fw_card *card, int tcode, int destination_id,
Jesse Keating 2f82dd
-		int generation, int speed, unsigned long long offset,
Jesse Keating 2f82dd
-		void *data, size_t length)
Jesse Keating 2f82dd
+		       int generation, int speed, unsigned long long offset,
Jesse Keating 2f82dd
+		       void *data, size_t length)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct transaction_callback_data d;
Jesse Keating 2f82dd
 	struct fw_transaction t;
Jesse Keating 2f82dd
@@ -399,9 +393,8 @@ void fw_flush_transactions(struct fw_car
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static struct fw_address_handler *
Jesse Keating 2f82dd
-lookup_overlapping_address_handler(struct list_head *list,
Jesse Keating 2f82dd
-				   unsigned long long offset, size_t length)
Jesse Keating 2f82dd
+static struct fw_address_handler *lookup_overlapping_address_handler(
Jesse Keating 2f82dd
+	struct list_head *list, unsigned long long offset, size_t length)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_address_handler *handler;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
@@ -414,9 +407,8 @@ lookup_overlapping_address_handler(struc
Jesse Keating 2f82dd
 	return NULL;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static struct fw_address_handler *
Jesse Keating 2f82dd
-lookup_enclosing_address_handler(struct list_head *list,
Jesse Keating 2f82dd
-				 unsigned long long offset, size_t length)
Jesse Keating 2f82dd
+static struct fw_address_handler *lookup_enclosing_address_handler(
Jesse Keating 2f82dd
+	struct list_head *list, unsigned long long offset, size_t length)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_address_handler *handler;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
@@ -449,36 +441,44 @@ const struct fw_address_region fw_unit_s
Jesse Keating 2f82dd
 #endif  /*  0  */
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 /**
Jesse Keating 2f82dd
- * Allocate a range of addresses in the node space of the OHCI
Jesse Keating 2f82dd
- * controller.  When a request is received that falls within the
Jesse Keating 2f82dd
- * specified address range, the specified callback is invoked.  The
Jesse Keating 2f82dd
- * parameters passed to the callback give the details of the
Jesse Keating 2f82dd
- * particular request.
Jesse Keating 2f82dd
+ * fw_core_add_address_handler - register for incoming requests
Jesse Keating 2f82dd
+ * @handler: callback
Jesse Keating 2f82dd
+ * @region: region in the IEEE 1212 node space address range
Jesse Keating 2f82dd
+ *
Jesse Keating 2f82dd
+ * region->start, ->end, and handler->length have to be quadlet-aligned.
Jesse Keating 2f82dd
+ *
Jesse Keating 2f82dd
+ * When a request is received that falls within the specified address range,
Jesse Keating 2f82dd
+ * the specified callback is invoked.  The parameters passed to the callback
Jesse Keating 2f82dd
+ * give the details of the particular request.
Jesse Keating 2f82dd
  *
Jesse Keating 2f82dd
  * Return value:  0 on success, non-zero otherwise.
Jesse Keating 2f82dd
  * The start offset of the handler's address region is determined by
Jesse Keating 2f82dd
  * fw_core_add_address_handler() and is returned in handler->offset.
Jesse Keating 2f82dd
- * The offset is quadlet-aligned.
Jesse Keating 2f82dd
  */
Jesse Keating 2f82dd
-int
Jesse Keating 2f82dd
-fw_core_add_address_handler(struct fw_address_handler *handler,
Jesse Keating 2f82dd
-			    const struct fw_address_region *region)
Jesse Keating 2f82dd
+int fw_core_add_address_handler(struct fw_address_handler *handler,
Jesse Keating 2f82dd
+				const struct fw_address_region *region)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_address_handler *other;
Jesse Keating 2f82dd
 	unsigned long flags;
Jesse Keating 2f82dd
 	int ret = -EBUSY;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
+	if (region->start & 0xffff000000000003ULL ||
Jesse Keating 2f82dd
+	    region->end   & 0xffff000000000003ULL ||
Jesse Keating 2f82dd
+	    region->start >= region->end ||
Jesse Keating 2f82dd
+	    handler->length & 3 ||
Jesse Keating 2f82dd
+	    handler->length == 0)
Jesse Keating 2f82dd
+		return -EINVAL;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
 	spin_lock_irqsave(&address_handler_lock, flags);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	handler->offset = roundup(region->start, 4);
Jesse Keating 2f82dd
+	handler->offset = region->start;
Jesse Keating 2f82dd
 	while (handler->offset + handler->length <= region->end) {
Jesse Keating 2f82dd
 		other =
Jesse Keating 2f82dd
 		    lookup_overlapping_address_handler(&address_handler_list,
Jesse Keating 2f82dd
 						       handler->offset,
Jesse Keating 2f82dd
 						       handler->length);
Jesse Keating 2f82dd
 		if (other != NULL) {
Jesse Keating 2f82dd
-			handler->offset =
Jesse Keating 2f82dd
-			    roundup(other->offset + other->length, 4);
Jesse Keating 2f82dd
+			handler->offset += other->length;
Jesse Keating 2f82dd
 		} else {
Jesse Keating 2f82dd
 			list_add_tail(&handler->link, &address_handler_list);
Jesse Keating 2f82dd
 			ret = 0;
Jesse Keating 2f82dd
@@ -493,12 +493,7 @@ fw_core_add_address_handler(struct fw_ad
Jesse Keating 2f82dd
 EXPORT_SYMBOL(fw_core_add_address_handler);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 /**
Jesse Keating 2f82dd
- * Deallocate a range of addresses allocated with fw_allocate.  This
Jesse Keating 2f82dd
- * will call the associated callback one last time with a the special
Jesse Keating 2f82dd
- * tcode TCODE_DEALLOCATE, to let the client destroy the registered
Jesse Keating 2f82dd
- * callback data.  For convenience, the callback parameters offset and
Jesse Keating 2f82dd
- * length are set to the start and the length respectively for the
Jesse Keating 2f82dd
- * deallocated region, payload is set to NULL.
Jesse Keating 2f82dd
+ * fw_core_remove_address_handler - unregister an address handler
Jesse Keating 2f82dd
  */
Jesse Keating 2f82dd
 void fw_core_remove_address_handler(struct fw_address_handler *handler)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
@@ -518,9 +513,8 @@ struct fw_request {
Jesse Keating 2f82dd
 	u32 data[0];
Jesse Keating 2f82dd
 };
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-free_response_callback(struct fw_packet *packet,
Jesse Keating 2f82dd
-		       struct fw_card *card, int status)
Jesse Keating 2f82dd
+static void free_response_callback(struct fw_packet *packet,
Jesse Keating 2f82dd
+				   struct fw_card *card, int status)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_request *request;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
@@ -528,9 +522,8 @@ free_response_callback(struct fw_packet 
Jesse Keating 2f82dd
 	kfree(request);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-void
Jesse Keating 2f82dd
-fw_fill_response(struct fw_packet *response, u32 *request_header,
Jesse Keating 2f82dd
-		 int rcode, void *payload, size_t length)
Jesse Keating 2f82dd
+void fw_fill_response(struct fw_packet *response, u32 *request_header,
Jesse Keating 2f82dd
+		      int rcode, void *payload, size_t length)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	int tcode, tlabel, extended_tcode, source, destination;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
@@ -588,8 +581,7 @@ fw_fill_response(struct fw_packet *respo
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 EXPORT_SYMBOL(fw_fill_response);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static struct fw_request *
Jesse Keating 2f82dd
-allocate_request(struct fw_packet *p)
Jesse Keating 2f82dd
+static struct fw_request *allocate_request(struct fw_packet *p)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_request *request;
Jesse Keating 2f82dd
 	u32 *data, length;
Jesse Keating 2f82dd
@@ -649,8 +641,8 @@ allocate_request(struct fw_packet *p)
Jesse Keating 2f82dd
 	return request;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-void
Jesse Keating 2f82dd
-fw_send_response(struct fw_card *card, struct fw_request *request, int rcode)
Jesse Keating 2f82dd
+void fw_send_response(struct fw_card *card,
Jesse Keating 2f82dd
+		      struct fw_request *request, int rcode)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	/* unified transaction or broadcast transaction: don't respond */
Jesse Keating 2f82dd
 	if (request->ack != ACK_PENDING ||
Jesse Keating 2f82dd
@@ -670,8 +662,7 @@ fw_send_response(struct fw_card *card, s
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 EXPORT_SYMBOL(fw_send_response);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-void
Jesse Keating 2f82dd
-fw_core_handle_request(struct fw_card *card, struct fw_packet *p)
Jesse Keating 2f82dd
+void fw_core_handle_request(struct fw_card *card, struct fw_packet *p)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_address_handler *handler;
Jesse Keating 2f82dd
 	struct fw_request *request;
Jesse Keating 2f82dd
@@ -719,8 +710,7 @@ fw_core_handle_request(struct fw_card *c
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 EXPORT_SYMBOL(fw_core_handle_request);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-void
Jesse Keating 2f82dd
-fw_core_handle_response(struct fw_card *card, struct fw_packet *p)
Jesse Keating 2f82dd
+void fw_core_handle_response(struct fw_card *card, struct fw_packet *p)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	struct fw_transaction *t;
Jesse Keating 2f82dd
 	unsigned long flags;
Jesse Keating 2f82dd
@@ -793,12 +783,10 @@ static const struct fw_address_region to
Jesse Keating 2f82dd
 	{ .start = CSR_REGISTER_BASE | CSR_TOPOLOGY_MAP,
Jesse Keating 2f82dd
 	  .end   = CSR_REGISTER_BASE | CSR_TOPOLOGY_MAP_END, };
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-handle_topology_map(struct fw_card *card, struct fw_request *request,
Jesse Keating 2f82dd
-		    int tcode, int destination, int source,
Jesse Keating 2f82dd
-		    int generation, int speed,
Jesse Keating 2f82dd
-		    unsigned long long offset,
Jesse Keating 2f82dd
-		    void *payload, size_t length, void *callback_data)
Jesse Keating 2f82dd
+static void handle_topology_map(struct fw_card *card, struct fw_request *request,
Jesse Keating 2f82dd
+		int tcode, int destination, int source, int generation,
Jesse Keating 2f82dd
+		int speed, unsigned long long offset,
Jesse Keating 2f82dd
+		void *payload, size_t length, void *callback_data)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	int i, start, end;
Jesse Keating 2f82dd
 	__be32 *map;
Jesse Keating 2f82dd
@@ -832,12 +820,10 @@ static const struct fw_address_region re
Jesse Keating 2f82dd
 	{ .start = CSR_REGISTER_BASE,
Jesse Keating 2f82dd
 	  .end   = CSR_REGISTER_BASE | CSR_CONFIG_ROM, };
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static void
Jesse Keating 2f82dd
-handle_registers(struct fw_card *card, struct fw_request *request,
Jesse Keating 2f82dd
-		 int tcode, int destination, int source,
Jesse Keating 2f82dd
-		 int generation, int speed,
Jesse Keating 2f82dd
-		 unsigned long long offset,
Jesse Keating 2f82dd
-		 void *payload, size_t length, void *callback_data)
Jesse Keating 2f82dd
+static void handle_registers(struct fw_card *card, struct fw_request *request,
Jesse Keating 2f82dd
+		int tcode, int destination, int source, int generation,
Jesse Keating 2f82dd
+		int speed, unsigned long long offset,
Jesse Keating 2f82dd
+		void *payload, size_t length, void *callback_data)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	int reg = offset & ~CSR_REGISTER_BASE;
Jesse Keating 2f82dd
 	unsigned long long bus_time;
Jesse Keating 2f82dd
@@ -939,11 +925,11 @@ static struct fw_descriptor model_id_des
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 static int __init fw_core_init(void)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
-	int retval;
Jesse Keating 2f82dd
+	int ret;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	retval = bus_register(&fw_bus_type);
Jesse Keating 2f82dd
-	if (retval < 0)
Jesse Keating 2f82dd
-		return retval;
Jesse Keating 2f82dd
+	ret = bus_register(&fw_bus_type);
Jesse Keating 2f82dd
+	if (ret < 0)
Jesse Keating 2f82dd
+		return ret;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	fw_cdev_major = register_chrdev(0, "firewire", &fw_device_ops);
Jesse Keating 2f82dd
 	if (fw_cdev_major < 0) {
Jesse Keating 2f82dd
@@ -951,19 +937,10 @@ static int __init fw_core_init(void)
Jesse Keating 2f82dd
 		return fw_cdev_major;
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	retval = fw_core_add_address_handler(&topology_map,
Jesse Keating 2f82dd
-					     &topology_map_region);
Jesse Keating 2f82dd
-	BUG_ON(retval < 0);
Jesse Keating 2f82dd
-
Jesse Keating 2f82dd
-	retval = fw_core_add_address_handler(®isters,
Jesse Keating 2f82dd
-					     ®isters_region);
Jesse Keating 2f82dd
-	BUG_ON(retval < 0);
Jesse Keating 2f82dd
-
Jesse Keating 2f82dd
-	/* Add the vendor textual descriptor. */
Jesse Keating 2f82dd
-	retval = fw_core_add_descriptor(&vendor_id_descriptor);
Jesse Keating 2f82dd
-	BUG_ON(retval < 0);
Jesse Keating 2f82dd
-	retval = fw_core_add_descriptor(&model_id_descriptor);
Jesse Keating 2f82dd
-	BUG_ON(retval < 0);
Jesse Keating 2f82dd
+	fw_core_add_address_handler(&topology_map, &topology_map_region);
Jesse Keating 2f82dd
+	fw_core_add_address_handler(®isters, ®isters_region);
Jesse Keating 2f82dd
+	fw_core_add_descriptor(&vendor_id_descriptor);
Jesse Keating 2f82dd
+	fw_core_add_descriptor(&model_id_descriptor);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	return 0;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
diff -Naurp linux-2.6-git/drivers/firewire/fw-transaction.h firewire-git/drivers/firewire/fw-transaction.h
Jesse Keating 2f82dd
--- linux-2.6-git/drivers/firewire/fw-transaction.h	2009-01-30 13:39:02.992772636 -0500
Jesse Keating 2f82dd
+++ firewire-git/drivers/firewire/fw-transaction.h	2009-01-30 13:35:51.862647087 -0500
Jesse Keating 2f82dd
@@ -82,14 +82,14 @@
Jesse Keating 2f82dd
 #define CSR_SPEED_MAP			0x2000
Jesse Keating 2f82dd
 #define CSR_SPEED_MAP_END		0x3000
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
+#define BANDWIDTH_AVAILABLE_INITIAL	4915
Jesse Keating 2f82dd
 #define BROADCAST_CHANNEL_INITIAL	(1 << 31 | 31)
Jesse Keating 2f82dd
 #define BROADCAST_CHANNEL_VALID		(1 << 30)
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 #define fw_notify(s, args...) printk(KERN_NOTICE KBUILD_MODNAME ": " s, ## args)
Jesse Keating 2f82dd
 #define fw_error(s, args...) printk(KERN_ERR KBUILD_MODNAME ": " s, ## args)
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static inline void
Jesse Keating 2f82dd
-fw_memcpy_from_be32(void *_dst, void *_src, size_t size)
Jesse Keating 2f82dd
+static inline void fw_memcpy_from_be32(void *_dst, void *_src, size_t size)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	u32    *dst = _dst;
Jesse Keating 2f82dd
 	__be32 *src = _src;
Jesse Keating 2f82dd
@@ -99,8 +99,7 @@ fw_memcpy_from_be32(void *_dst, void *_s
Jesse Keating 2f82dd
 		dst[i] = be32_to_cpu(src[i]);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static inline void
Jesse Keating 2f82dd
-fw_memcpy_to_be32(void *_dst, void *_src, size_t size)
Jesse Keating 2f82dd
+static inline void fw_memcpy_to_be32(void *_dst, void *_src, size_t size)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	fw_memcpy_from_be32(_dst, _src, size);
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
@@ -125,8 +124,7 @@ typedef void (*fw_packet_callback_t)(str
Jesse Keating 2f82dd
 				     struct fw_card *card, int status);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 typedef void (*fw_transaction_callback_t)(struct fw_card *card, int rcode,
Jesse Keating 2f82dd
-					  void *data,
Jesse Keating 2f82dd
-					  size_t length,
Jesse Keating 2f82dd
+					  void *data, size_t length,
Jesse Keating 2f82dd
 					  void *callback_data);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 /*
Jesse Keating 2f82dd
@@ -141,12 +139,6 @@ typedef void (*fw_address_callback_t)(st
Jesse Keating 2f82dd
 				      void *data, size_t length,
Jesse Keating 2f82dd
 				      void *callback_data);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-typedef void (*fw_bus_reset_callback_t)(struct fw_card *handle,
Jesse Keating 2f82dd
-					int node_id, int generation,
Jesse Keating 2f82dd
-					u32 *self_ids,
Jesse Keating 2f82dd
-					int self_id_count,
Jesse Keating 2f82dd
-					void *callback_data);
Jesse Keating 2f82dd
-
Jesse Keating 2f82dd
 struct fw_packet {
Jesse Keating 2f82dd
 	int speed;
Jesse Keating 2f82dd
 	int generation;
Jesse Keating 2f82dd
@@ -187,12 +179,6 @@ struct fw_transaction {
Jesse Keating 2f82dd
 	void *callback_data;
Jesse Keating 2f82dd
 };
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-static inline struct fw_packet *
Jesse Keating 2f82dd
-fw_packet(struct list_head *l)
Jesse Keating 2f82dd
-{
Jesse Keating 2f82dd
-	return list_entry(l, struct fw_packet, link);
Jesse Keating 2f82dd
-}
Jesse Keating 2f82dd
-
Jesse Keating 2f82dd
 struct fw_address_handler {
Jesse Keating 2f82dd
 	u64 offset;
Jesse Keating 2f82dd
 	size_t length;
Jesse Keating 2f82dd
@@ -201,7 +187,6 @@ struct fw_address_handler {
Jesse Keating 2f82dd
 	struct list_head link;
Jesse Keating 2f82dd
 };
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-
Jesse Keating 2f82dd
 struct fw_address_region {
Jesse Keating 2f82dd
 	u64 start;
Jesse Keating 2f82dd
 	u64 end;
Jesse Keating 2f82dd
@@ -315,10 +300,8 @@ struct fw_iso_packet {
Jesse Keating 2f82dd
 struct fw_iso_context;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 typedef void (*fw_iso_callback_t)(struct fw_iso_context *context,
Jesse Keating 2f82dd
-				  u32 cycle,
Jesse Keating 2f82dd
-				  size_t header_length,
Jesse Keating 2f82dd
-				  void *header,
Jesse Keating 2f82dd
-				  void *data);
Jesse Keating 2f82dd
+				  u32 cycle, size_t header_length,
Jesse Keating 2f82dd
+				  void *header, void *data);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 /*
Jesse Keating 2f82dd
  * An iso buffer is just a set of pages mapped for DMA in the
Jesse Keating 2f82dd
@@ -344,36 +327,25 @@ struct fw_iso_context {
Jesse Keating 2f82dd
 	void *callback_data;
Jesse Keating 2f82dd
 };
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-int
Jesse Keating 2f82dd
-fw_iso_buffer_init(struct fw_iso_buffer *buffer,
Jesse Keating 2f82dd
-		   struct fw_card *card,
Jesse Keating 2f82dd
-		   int page_count,
Jesse Keating 2f82dd
-		   enum dma_data_direction direction);
Jesse Keating 2f82dd
-int
Jesse Keating 2f82dd
-fw_iso_buffer_map(struct fw_iso_buffer *buffer, struct vm_area_struct *vma);
Jesse Keating 2f82dd
-void
Jesse Keating 2f82dd
-fw_iso_buffer_destroy(struct fw_iso_buffer *buffer, struct fw_card *card);
Jesse Keating 2f82dd
-
Jesse Keating 2f82dd
-struct fw_iso_context *
Jesse Keating 2f82dd
-fw_iso_context_create(struct fw_card *card, int type,