From badfcb24891ccd6d37750864b97586af8ab052c3 Mon Sep 17 00:00:00 2001 From: Clemens Ladisch Date: Mon, 13 Aug 2012 09:08:41 +0200 Subject: firewire: core: feed /dev/random with devices' GUIDs Send the GUIDs of newly registered controllers and devices to the /dev/random driver to help seed its pools. Signed-off-by: Clemens Ladisch Signed-off-by: Stefan Richter --- drivers/firewire/core-device.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'drivers') diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c index 7a05fd24d68b..3873d535b28d 100644 --- a/drivers/firewire/core-device.c +++ b/drivers/firewire/core-device.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -1066,6 +1067,8 @@ static void fw_device_init(struct work_struct *work) device->config_rom_retries = 0; set_broadcast_channel(device, device->generation); + + add_device_randomness(&device->config_rom[3], 8); } /* -- cgit v1.2.3-59-g8ed1b From 52439d605d6604c15954281a1d2831471dbd024c Mon Sep 17 00:00:00 2001 From: Stephan Gatzka Date: Mon, 3 Sep 2012 21:17:50 +0200 Subject: firewire: ohci: get IR bit from TSB41BA3D phy In case of a self constructed selfID packet this patch correctly determines the information if the TSB41BA3D phy initiated a bus reset. Signed-off-by: Stephan Gatzka Signed-off-by: Stefan Richter --- drivers/firewire/ohci.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c index c788dbdaf3bc..834e71d2324d 100644 --- a/drivers/firewire/ohci.c +++ b/drivers/firewire/ohci.c @@ -1777,11 +1777,35 @@ static int get_self_id_pos(struct fw_ohci *ohci, u32 self_id, return i; } +static int initiated_reset(struct fw_ohci *ohci) +{ + int reg; + int ret = 0; + + mutex_lock(&ohci->phy_reg_mutex); + reg = write_phy_reg(ohci, 7, 0xe0); /* Select page 7 */ + if (reg >= 0) { + reg = read_phy_reg(ohci, 8); + reg |= 0x40; + reg = write_phy_reg(ohci, 8, reg); /* set PMODE bit */ + if (reg >= 0) { + reg = read_phy_reg(ohci, 12); /* read register 12 */ + if (reg >= 0) { + if ((reg & 0x08) == 0x08) { + /* bit 3 indicates "initiated reset" */ + ret = 0x2; + } + } + } + } + mutex_unlock(&ohci->phy_reg_mutex); + return ret; +} + /* * TI TSB82AA2B and TSB12LV26 do not receive the selfID of a locally * attached TSB41BA3D phy; see http://www.ti.com/litv/pdf/sllz059. * Construct the selfID from phy register contents. - * FIXME: How to determine the selfID.i flag? */ static int find_and_insert_self_id(struct fw_ohci *ohci, int self_id_count) { @@ -1814,6 +1838,8 @@ static int find_and_insert_self_id(struct fw_ohci *ohci, int self_id_count) self_id |= ((status & 0x3) << (6 - (i * 2))); } + self_id |= initiated_reset(ohci); + pos = get_self_id_pos(ohci, self_id, self_id_count); if (pos >= 0) { memmove(&(ohci->self_id_buffer[pos+1]), -- cgit v1.2.3-59-g8ed1b From 35202f7d8420fff586b372422a2419affeaba8ef Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Sun, 19 Aug 2012 02:50:02 -0400 Subject: firewire: remove global lock around address handlers, convert to RCU Upper-layer handlers for inbound requests were called with a spinlock held by firewire-core. Calling into upper layers with a lower layer lock held is generally a bad idea. What's more, since commit ea102d0ec475 "firewire: core: convert AR-req handler lock from _irqsave to _bh", a caller of fw_send_request() i.e. initiator of outbound request could no longer do that while having interrupts disabled, if the local node was addressed by that request. In order to make all this more flexible, convert the management of address ranges and handlers from a global lock around readers and writers to RCU (and a remaining global lock for writers). As a minor side effect, handling of inbound requests at different cards and of local requests is now no longer serialized. (There is still per-card serialization of remote requests since firewire-ohci uses a single DMA tasklet for inbound request events.) In other words, address handlers are now called in an RCU read-side critical section instead of from within a spin_lock_bh serialized section. (Changelog rewritten by Stefan R.) Signed-off-by: Peter Hurley Signed-off-by: Stefan Richter --- drivers/firewire/core-transaction.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'drivers') diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c index 87d6f2d2f02d..d39cfa45817a 100644 --- a/drivers/firewire/core-transaction.c +++ b/drivers/firewire/core-transaction.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -489,7 +490,7 @@ static struct fw_address_handler *lookup_overlapping_address_handler( { struct fw_address_handler *handler; - list_for_each_entry(handler, list, link) { + list_for_each_entry_rcu(handler, list, link) { if (handler->offset < offset + length && offset < handler->offset + handler->length) return handler; @@ -510,7 +511,7 @@ static struct fw_address_handler *lookup_enclosing_address_handler( { struct fw_address_handler *handler; - list_for_each_entry(handler, list, link) { + list_for_each_entry_rcu(handler, list, link) { if (is_enclosing_handler(handler, offset, length)) return handler; } @@ -588,7 +589,7 @@ int fw_core_add_address_handler(struct fw_address_handler *handler, if (other != NULL) { handler->offset += other->length; } else { - list_add_tail(&handler->link, &address_handler_list); + list_add_tail_rcu(&handler->link, &address_handler_list); ret = 0; break; } @@ -609,8 +610,9 @@ EXPORT_SYMBOL(fw_core_add_address_handler); void fw_core_remove_address_handler(struct fw_address_handler *handler) { spin_lock_bh(&address_handler_lock); - list_del(&handler->link); + list_del_rcu(&handler->link); spin_unlock_bh(&address_handler_lock); + synchronize_rcu(); } EXPORT_SYMBOL(fw_core_remove_address_handler); @@ -844,7 +846,7 @@ static void handle_exclusive_region_request(struct fw_card *card, if (tcode == TCODE_LOCK_REQUEST) tcode = 0x10 + HEADER_GET_EXTENDED_TCODE(p->header[3]); - spin_lock_bh(&address_handler_lock); + rcu_read_lock(); handler = lookup_enclosing_address_handler(&address_handler_list, offset, request->length); if (handler) @@ -853,7 +855,7 @@ static void handle_exclusive_region_request(struct fw_card *card, p->generation, offset, request->data, request->length, handler->callback_data); - spin_unlock_bh(&address_handler_lock); + rcu_read_unlock(); if (!handler) fw_send_response(card, request, RCODE_ADDRESS_ERROR); @@ -886,8 +888,8 @@ static void handle_fcp_region_request(struct fw_card *card, return; } - spin_lock_bh(&address_handler_lock); - list_for_each_entry(handler, &address_handler_list, link) { + rcu_read_lock(); + list_for_each_entry_rcu(handler, &address_handler_list, link) { if (is_enclosing_handler(handler, offset, request->length)) handler->address_callback(card, NULL, tcode, destination, source, @@ -896,7 +898,7 @@ static void handle_fcp_region_request(struct fw_card *card, request->length, handler->callback_data); } - spin_unlock_bh(&address_handler_lock); + rcu_read_unlock(); fw_send_response(card, request, RCODE_COMPLETE); } -- cgit v1.2.3-59-g8ed1b From 4d50c44381c981c9caa74e82ab894d4938dac9ca Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Thu, 27 Sep 2012 21:46:09 +0200 Subject: firewire: addendum to address handler RCU conversion Follow up on commit c285f6ff6787 "firewire: remove global lock around address handlers, convert to RCU": - address_handler_lock no longer serializes the address handler, only its function to serialize updates to the list of handlers remains. Rename the lock to address_handler_list_lock. - Callers of fw_core_remove_address_handler() must be able to sleep. Comment on this in the API documentation. - The counterpart fw_core_add_address_handler() is by nature something which is used in process context. Replace spin_lock_bh() by spin_lock() in fw_core_add_address_handler() and in fw_core_remove_address_handler(), and document that process context is now required for fw_core_add_address_handler(). - Extend the documentation of fw_address_callback_t. Signed-off-by: Stefan Richter --- drivers/firewire/core-transaction.c | 13 ++++++++----- include/linux/firewire.h | 12 ++++++++++-- 2 files changed, 18 insertions(+), 7 deletions(-) (limited to 'drivers') diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c index d39cfa45817a..28a94c7ec6e5 100644 --- a/drivers/firewire/core-transaction.c +++ b/drivers/firewire/core-transaction.c @@ -519,7 +519,7 @@ static struct fw_address_handler *lookup_enclosing_address_handler( return NULL; } -static DEFINE_SPINLOCK(address_handler_lock); +static DEFINE_SPINLOCK(address_handler_list_lock); static LIST_HEAD(address_handler_list); const struct fw_address_region fw_high_memory_region = @@ -556,6 +556,7 @@ static bool is_in_fcp_region(u64 offset, size_t length) * the specified callback is invoked. The parameters passed to the callback * give the details of the particular request. * + * To be called in process context. * Return value: 0 on success, non-zero otherwise. * * The start offset of the handler's address region is determined by @@ -576,7 +577,7 @@ int fw_core_add_address_handler(struct fw_address_handler *handler, handler->length == 0) return -EINVAL; - spin_lock_bh(&address_handler_lock); + spin_lock(&address_handler_list_lock); handler->offset = region->start; while (handler->offset + handler->length <= region->end) { @@ -595,7 +596,7 @@ int fw_core_add_address_handler(struct fw_address_handler *handler, } } - spin_unlock_bh(&address_handler_lock); + spin_unlock(&address_handler_list_lock); return ret; } @@ -604,14 +605,16 @@ EXPORT_SYMBOL(fw_core_add_address_handler); /** * fw_core_remove_address_handler() - unregister an address handler * + * To be called in process context. + * * When fw_core_remove_address_handler() returns, @handler->callback() is * guaranteed to not run on any CPU anymore. */ void fw_core_remove_address_handler(struct fw_address_handler *handler) { - spin_lock_bh(&address_handler_lock); + spin_lock(&address_handler_list_lock); list_del_rcu(&handler->link); - spin_unlock_bh(&address_handler_lock); + spin_unlock(&address_handler_list_lock); synchronize_rcu(); } EXPORT_SYMBOL(fw_core_remove_address_handler); diff --git a/include/linux/firewire.h b/include/linux/firewire.h index db04ec5121cb..191501afd7fb 100644 --- a/include/linux/firewire.h +++ b/include/linux/firewire.h @@ -265,8 +265,16 @@ typedef void (*fw_transaction_callback_t)(struct fw_card *card, int rcode, void *data, size_t length, void *callback_data); /* - * Important note: Except for the FCP registers, the callback must guarantee - * that either fw_send_response() or kfree() is called on the @request. + * This callback handles an inbound request subaction. It is called in + * RCU read-side context, therefore must not sleep. + * + * The callback should not initiate outbound request subactions directly. + * Otherwise there is a danger of recursion of inbound and outbound + * transactions from and to the local node. + * + * The callback is responsible that either fw_send_response() or kfree() + * is called on the @request, except for FCP registers for which the core + * takes care of that. */ typedef void (*fw_address_callback_t)(struct fw_card *card, struct fw_request *request, -- cgit v1.2.3-59-g8ed1b