aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/firewire
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-07-15 15:39:13 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-15 15:39:13 -0400
commit849c529f57020cc47085400edd5e641d95cd4faf (patch)
tree5f2d1add9f98995bf8c22cdfc6ade3e02869e1ac /drivers/firewire
parentb9d2252c1e44fa83a4e65fdc9eb93db6297c55af (diff)
parenta7ea67823af4a7e442e92064b0fab46603a588f6 (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394-2.6
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394-2.6: firewire: don't respond to broadcast write requests firewire: clean up fw_card reference counting firewire: clean up some includes firewire: remove unused struct members firewire: implement broadcast_channel CSR for 1394a compliance ieee1394: dump mmapped iso buffers in core files ieee1394: raw1394: Push the BKL down into the driver ioctls ieee1394: video1394: reorder module init, prepare BKL removal ieee1394: reduce log noise about config ROM CRC errors
Diffstat (limited to 'drivers/firewire')
-rw-r--r--drivers/firewire/fw-card.c32
-rw-r--r--drivers/firewire/fw-device.c5
-rw-r--r--drivers/firewire/fw-device.h1
-rw-r--r--drivers/firewire/fw-ohci.c1
-rw-r--r--drivers/firewire/fw-transaction.c32
-rw-r--r--drivers/firewire/fw-transaction.h34
6 files changed, 72 insertions, 33 deletions
diff --git a/drivers/firewire/fw-card.c b/drivers/firewire/fw-card.c
index 5b4c0d9f5173..da873d795aad 100644
--- a/drivers/firewire/fw-card.c
+++ b/drivers/firewire/fw-card.c
@@ -16,12 +16,15 @@
16 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */ 17 */
18 18
19#include <linux/module.h> 19#include <linux/completion.h>
20#include <linux/errno.h> 20#include <linux/crc-itu-t.h>
21#include <linux/delay.h> 21#include <linux/delay.h>
22#include <linux/device.h> 22#include <linux/device.h>
23#include <linux/errno.h>
24#include <linux/kref.h>
25#include <linux/module.h>
23#include <linux/mutex.h> 26#include <linux/mutex.h>
24#include <linux/crc-itu-t.h> 27
25#include "fw-transaction.h" 28#include "fw-transaction.h"
26#include "fw-topology.h" 29#include "fw-topology.h"
27#include "fw-device.h" 30#include "fw-device.h"
@@ -396,14 +399,16 @@ fw_card_initialize(struct fw_card *card, const struct fw_card_driver *driver,
396{ 399{
397 static atomic_t index = ATOMIC_INIT(-1); 400 static atomic_t index = ATOMIC_INIT(-1);
398 401
399 atomic_set(&card->device_count, 0);
400 card->index = atomic_inc_return(&index); 402 card->index = atomic_inc_return(&index);
401 card->driver = driver; 403 card->driver = driver;
402 card->device = device; 404 card->device = device;
403 card->current_tlabel = 0; 405 card->current_tlabel = 0;
404 card->tlabel_mask = 0; 406 card->tlabel_mask = 0;
405 card->color = 0; 407 card->color = 0;
408 card->broadcast_channel = BROADCAST_CHANNEL_INITIAL;
406 409
410 kref_init(&card->kref);
411 init_completion(&card->done);
407 INIT_LIST_HEAD(&card->transaction_list); 412 INIT_LIST_HEAD(&card->transaction_list);
408 spin_lock_init(&card->lock); 413 spin_lock_init(&card->lock);
409 setup_timer(&card->flush_timer, 414 setup_timer(&card->flush_timer,
@@ -496,7 +501,6 @@ dummy_enable_phys_dma(struct fw_card *card,
496} 501}
497 502
498static struct fw_card_driver dummy_driver = { 503static struct fw_card_driver dummy_driver = {
499 .name = "dummy",
500 .enable = dummy_enable, 504 .enable = dummy_enable,
501 .update_phy_reg = dummy_update_phy_reg, 505 .update_phy_reg = dummy_update_phy_reg,
502 .set_config_rom = dummy_set_config_rom, 506 .set_config_rom = dummy_set_config_rom,
@@ -507,6 +511,14 @@ static struct fw_card_driver dummy_driver = {
507}; 511};
508 512
509void 513void
514fw_card_release(struct kref *kref)
515{
516 struct fw_card *card = container_of(kref, struct fw_card, kref);
517
518 complete(&card->done);
519}
520
521void
510fw_core_remove_card(struct fw_card *card) 522fw_core_remove_card(struct fw_card *card)
511{ 523{
512 card->driver->update_phy_reg(card, 4, 524 card->driver->update_phy_reg(card, 4,
@@ -521,12 +533,10 @@ fw_core_remove_card(struct fw_card *card)
521 card->driver = &dummy_driver; 533 card->driver = &dummy_driver;
522 534
523 fw_destroy_nodes(card); 535 fw_destroy_nodes(card);
524 /* 536
525 * Wait for all device workqueue jobs to finish. Otherwise the 537 /* Wait for all users, especially device workqueue jobs, to finish. */
526 * firewire-core module could be unloaded before the jobs ran. 538 fw_card_put(card);
527 */ 539 wait_for_completion(&card->done);
528 while (atomic_read(&card->device_count) > 0)
529 msleep(100);
530 540
531 cancel_delayed_work_sync(&card->work); 541 cancel_delayed_work_sync(&card->work);
532 fw_flush_transactions(card); 542 fw_flush_transactions(card);
diff --git a/drivers/firewire/fw-device.c b/drivers/firewire/fw-device.c
index d9c8daf7ae7d..0855fb5568e8 100644
--- a/drivers/firewire/fw-device.c
+++ b/drivers/firewire/fw-device.c
@@ -168,7 +168,7 @@ static void fw_device_release(struct device *dev)
168 fw_node_put(device->node); 168 fw_node_put(device->node);
169 kfree(device->config_rom); 169 kfree(device->config_rom);
170 kfree(device); 170 kfree(device);
171 atomic_dec(&card->device_count); 171 fw_card_put(card);
172} 172}
173 173
174int fw_device_enable_phys_dma(struct fw_device *device) 174int fw_device_enable_phys_dma(struct fw_device *device)
@@ -946,8 +946,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
946 */ 946 */
947 device_initialize(&device->device); 947 device_initialize(&device->device);
948 atomic_set(&device->state, FW_DEVICE_INITIALIZING); 948 atomic_set(&device->state, FW_DEVICE_INITIALIZING);
949 atomic_inc(&card->device_count); 949 device->card = fw_card_get(card);
950 device->card = card;
951 device->node = fw_node_get(node); 950 device->node = fw_node_get(node);
952 device->node_id = node->node_id; 951 device->node_id = node->node_id;
953 device->generation = card->generation; 952 device->generation = card->generation;
diff --git a/drivers/firewire/fw-device.h b/drivers/firewire/fw-device.h
index 5f131f5129da..42305bbac72f 100644
--- a/drivers/firewire/fw-device.h
+++ b/drivers/firewire/fw-device.h
@@ -62,7 +62,6 @@ struct fw_device {
62 bool cmc; 62 bool cmc;
63 struct fw_card *card; 63 struct fw_card *card;
64 struct device device; 64 struct device device;
65 struct list_head link;
66 struct list_head client_list; 65 struct list_head client_list;
67 u32 *config_rom; 66 u32 *config_rom;
68 size_t config_rom_length; 67 size_t config_rom_length;
diff --git a/drivers/firewire/fw-ohci.c b/drivers/firewire/fw-ohci.c
index 0b66306af479..333b12544dd1 100644
--- a/drivers/firewire/fw-ohci.c
+++ b/drivers/firewire/fw-ohci.c
@@ -2292,7 +2292,6 @@ ohci_queue_iso(struct fw_iso_context *base,
2292} 2292}
2293 2293
2294static const struct fw_card_driver ohci_driver = { 2294static const struct fw_card_driver ohci_driver = {
2295 .name = ohci_driver_name,
2296 .enable = ohci_enable, 2295 .enable = ohci_enable,
2297 .update_phy_reg = ohci_update_phy_reg, 2296 .update_phy_reg = ohci_update_phy_reg,
2298 .set_config_rom = ohci_set_config_rom, 2297 .set_config_rom = ohci_set_config_rom,
diff --git a/drivers/firewire/fw-transaction.c b/drivers/firewire/fw-transaction.c
index 03ae8a77c479..40db80752272 100644
--- a/drivers/firewire/fw-transaction.c
+++ b/drivers/firewire/fw-transaction.c
@@ -55,6 +55,9 @@
55#define HEADER_GET_DATA_LENGTH(q) (((q) >> 16) & 0xffff) 55#define HEADER_GET_DATA_LENGTH(q) (((q) >> 16) & 0xffff)
56#define HEADER_GET_EXTENDED_TCODE(q) (((q) >> 0) & 0xffff) 56#define HEADER_GET_EXTENDED_TCODE(q) (((q) >> 0) & 0xffff)
57 57
58#define HEADER_DESTINATION_IS_BROADCAST(q) \
59 (((q) & HEADER_DESTINATION(0x3f)) == HEADER_DESTINATION(0x3f))
60
58#define PHY_CONFIG_GAP_COUNT(gap_count) (((gap_count) << 16) | (1 << 22)) 61#define PHY_CONFIG_GAP_COUNT(gap_count) (((gap_count) << 16) | (1 << 22))
59#define PHY_CONFIG_ROOT_ID(node_id) ((((node_id) & 0x3f) << 24) | (1 << 23)) 62#define PHY_CONFIG_ROOT_ID(node_id) ((((node_id) & 0x3f) << 24) | (1 << 23))
60#define PHY_IDENTIFIER(id) ((id) << 30) 63#define PHY_IDENTIFIER(id) ((id) << 30)
@@ -624,12 +627,9 @@ allocate_request(struct fw_packet *p)
624void 627void
625fw_send_response(struct fw_card *card, struct fw_request *request, int rcode) 628fw_send_response(struct fw_card *card, struct fw_request *request, int rcode)
626{ 629{
627 /* 630 /* unified transaction or broadcast transaction: don't respond */
628 * Broadcast packets are reported as ACK_COMPLETE, so this 631 if (request->ack != ACK_PENDING ||
629 * check is sufficient to ensure we don't send response to 632 HEADER_DESTINATION_IS_BROADCAST(request->request_header[0])) {
630 * broadcast packets or posted writes.
631 */
632 if (request->ack != ACK_PENDING) {
633 kfree(request); 633 kfree(request);
634 return; 634 return;
635 } 635 }
@@ -817,12 +817,13 @@ handle_registers(struct fw_card *card, struct fw_request *request,
817 int reg = offset & ~CSR_REGISTER_BASE; 817 int reg = offset & ~CSR_REGISTER_BASE;
818 unsigned long long bus_time; 818 unsigned long long bus_time;
819 __be32 *data = payload; 819 __be32 *data = payload;
820 int rcode = RCODE_COMPLETE;
820 821
821 switch (reg) { 822 switch (reg) {
822 case CSR_CYCLE_TIME: 823 case CSR_CYCLE_TIME:
823 case CSR_BUS_TIME: 824 case CSR_BUS_TIME:
824 if (!TCODE_IS_READ_REQUEST(tcode) || length != 4) { 825 if (!TCODE_IS_READ_REQUEST(tcode) || length != 4) {
825 fw_send_response(card, request, RCODE_TYPE_ERROR); 826 rcode = RCODE_TYPE_ERROR;
826 break; 827 break;
827 } 828 }
828 829
@@ -831,7 +832,17 @@ handle_registers(struct fw_card *card, struct fw_request *request,
831 *data = cpu_to_be32(bus_time); 832 *data = cpu_to_be32(bus_time);
832 else 833 else
833 *data = cpu_to_be32(bus_time >> 25); 834 *data = cpu_to_be32(bus_time >> 25);
834 fw_send_response(card, request, RCODE_COMPLETE); 835 break;
836
837 case CSR_BROADCAST_CHANNEL:
838 if (tcode == TCODE_READ_QUADLET_REQUEST)
839 *data = cpu_to_be32(card->broadcast_channel);
840 else if (tcode == TCODE_WRITE_QUADLET_REQUEST)
841 card->broadcast_channel =
842 (be32_to_cpu(*data) & BROADCAST_CHANNEL_VALID) |
843 BROADCAST_CHANNEL_INITIAL;
844 else
845 rcode = RCODE_TYPE_ERROR;
835 break; 846 break;
836 847
837 case CSR_BUS_MANAGER_ID: 848 case CSR_BUS_MANAGER_ID:
@@ -850,10 +861,13 @@ handle_registers(struct fw_card *card, struct fw_request *request,
850 861
851 case CSR_BUSY_TIMEOUT: 862 case CSR_BUSY_TIMEOUT:
852 /* FIXME: Implement this. */ 863 /* FIXME: Implement this. */
864
853 default: 865 default:
854 fw_send_response(card, request, RCODE_ADDRESS_ERROR); 866 rcode = RCODE_ADDRESS_ERROR;
855 break; 867 break;
856 } 868 }
869
870 fw_send_response(card, request, rcode);
857} 871}
858 872
859static struct fw_address_handler registers = { 873static struct fw_address_handler registers = {
diff --git a/drivers/firewire/fw-transaction.h b/drivers/firewire/fw-transaction.h
index 04d3854f6560..2ae1b0d6cb7b 100644
--- a/drivers/firewire/fw-transaction.h
+++ b/drivers/firewire/fw-transaction.h
@@ -19,14 +19,15 @@
19#ifndef __fw_transaction_h 19#ifndef __fw_transaction_h
20#define __fw_transaction_h 20#define __fw_transaction_h
21 21
22#include <linux/completion.h>
22#include <linux/device.h> 23#include <linux/device.h>
23#include <linux/timer.h>
24#include <linux/interrupt.h>
25#include <linux/list.h>
26#include <linux/fs.h>
27#include <linux/dma-mapping.h> 24#include <linux/dma-mapping.h>
28#include <linux/firewire-constants.h> 25#include <linux/firewire-constants.h>
29#include <asm/atomic.h> 26#include <linux/kref.h>
27#include <linux/list.h>
28#include <linux/spinlock_types.h>
29#include <linux/timer.h>
30#include <linux/workqueue.h>
30 31
31#define TCODE_IS_READ_REQUEST(tcode) (((tcode) & ~1) == 4) 32#define TCODE_IS_READ_REQUEST(tcode) (((tcode) & ~1) == 4)
32#define TCODE_IS_BLOCK_PACKET(tcode) (((tcode) & 1) != 0) 33#define TCODE_IS_BLOCK_PACKET(tcode) (((tcode) & 1) != 0)
@@ -80,6 +81,9 @@
80#define CSR_SPEED_MAP 0x2000 81#define CSR_SPEED_MAP 0x2000
81#define CSR_SPEED_MAP_END 0x3000 82#define CSR_SPEED_MAP_END 0x3000
82 83
84#define BROADCAST_CHANNEL_INITIAL (1 << 31 | 31)
85#define BROADCAST_CHANNEL_VALID (1 << 30)
86
83#define fw_notify(s, args...) printk(KERN_NOTICE KBUILD_MODNAME ": " s, ## args) 87#define fw_notify(s, args...) printk(KERN_NOTICE KBUILD_MODNAME ": " s, ## args)
84#define fw_error(s, args...) printk(KERN_ERR KBUILD_MODNAME ": " s, ## args) 88#define fw_error(s, args...) printk(KERN_ERR KBUILD_MODNAME ": " s, ## args)
85 89
@@ -216,7 +220,8 @@ extern struct bus_type fw_bus_type;
216struct fw_card { 220struct fw_card {
217 const struct fw_card_driver *driver; 221 const struct fw_card_driver *driver;
218 struct device *device; 222 struct device *device;
219 atomic_t device_count; 223 struct kref kref;
224 struct completion done;
220 225
221 int node_id; 226 int node_id;
222 int generation; 227 int generation;
@@ -236,6 +241,7 @@ struct fw_card {
236 */ 241 */
237 int self_id_count; 242 int self_id_count;
238 u32 topology_map[252 + 3]; 243 u32 topology_map[252 + 3];
244 u32 broadcast_channel;
239 245
240 spinlock_t lock; /* Take this lock when handling the lists in 246 spinlock_t lock; /* Take this lock when handling the lists in
241 * this struct. */ 247 * this struct. */
@@ -256,6 +262,20 @@ struct fw_card {
256 int bm_generation; 262 int bm_generation;
257}; 263};
258 264
265static inline struct fw_card *fw_card_get(struct fw_card *card)
266{
267 kref_get(&card->kref);
268
269 return card;
270}
271
272void fw_card_release(struct kref *kref);
273
274static inline void fw_card_put(struct fw_card *card)
275{
276 kref_put(&card->kref, fw_card_release);
277}
278
259/* 279/*
260 * The iso packet format allows for an immediate header/payload part 280 * The iso packet format allows for an immediate header/payload part
261 * stored in 'header' immediately after the packet info plus an 281 * stored in 'header' immediately after the packet info plus an
@@ -348,8 +368,6 @@ int
348fw_iso_context_stop(struct fw_iso_context *ctx); 368fw_iso_context_stop(struct fw_iso_context *ctx);
349 369
350struct fw_card_driver { 370struct fw_card_driver {
351 const char *name;
352
353 /* 371 /*
354 * Enable the given card with the given initial config rom. 372 * Enable the given card with the given initial config rom.
355 * This function is expected to activate the card, and either 373 * This function is expected to activate the card, and either