]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/firewire/fw-card.c
[NETFILTER] xt_policy.c: kill some bloat
[linux-2.6-omap-h63xx.git] / drivers / firewire / fw-card.c
index b2aa85555a7a6a2cc7bcae1a96b42f2682d7a4f9..3e9719948a8e7817658496929115fe52bda45473 100644 (file)
@@ -19,7 +19,7 @@
 #include <linux/module.h>
 #include <linux/errno.h>
 #include <linux/device.h>
-#include <linux/rwsem.h>
+#include <linux/mutex.h>
 #include <linux/crc-itu-t.h>
 #include "fw-transaction.h"
 #include "fw-topology.h"
@@ -38,29 +38,29 @@ int fw_compute_block_crc(u32 *block)
        return length;
 }
 
-static DECLARE_RWSEM(card_rwsem);
+static DEFINE_MUTEX(card_mutex);
 static LIST_HEAD(card_list);
 
 static LIST_HEAD(descriptor_list);
 static int descriptor_count;
 
-#define bib_crc(v)             ((v) <<  0)
-#define bib_crc_length(v)      ((v) << 16)
-#define bib_info_length(v)     ((v) << 24)
-
-#define bib_link_speed(v)      ((v) <<  0)
-#define bib_generation(v)      ((v) <<  4)
-#define bib_max_rom(v)         ((v) <<  8)
-#define bib_max_receive(v)     ((v) << 12)
-#define bib_cyc_clk_acc(v)     ((v) << 16)
-#define bib_pmc                        ((1) << 27)
-#define bib_bmc                        ((1) << 28)
-#define bib_isc                        ((1) << 29)
-#define bib_cmc                        ((1) << 30)
-#define bib_imc                        ((1) << 31)
+#define BIB_CRC(v)             ((v) <<  0)
+#define BIB_CRC_LENGTH(v)      ((v) << 16)
+#define BIB_INFO_LENGTH(v)     ((v) << 24)
+
+#define BIB_LINK_SPEED(v)      ((v) <<  0)
+#define BIB_GENERATION(v)      ((v) <<  4)
+#define BIB_MAX_ROM(v)         ((v) <<  8)
+#define BIB_MAX_RECEIVE(v)     ((v) << 12)
+#define BIB_CYC_CLK_ACC(v)     ((v) << 16)
+#define BIB_PMC                        ((1) << 27)
+#define BIB_BMC                        ((1) << 28)
+#define BIB_ISC                        ((1) << 29)
+#define BIB_CMC                        ((1) << 30)
+#define BIB_IMC                        ((1) << 31)
 
 static u32 *
-generate_config_rom (struct fw_card *card, size_t *config_rom_length)
+generate_config_rom(struct fw_card *card, size_t *config_rom_length)
 {
        struct fw_descriptor *desc;
        static u32 config_rom[256];
@@ -75,16 +75,16 @@ generate_config_rom (struct fw_card *card, size_t *config_rom_length)
         * the version stored in the OHCI registers.
         */
 
-       memset(config_rom, 0, sizeof config_rom);
-       config_rom[0] = bib_crc_length(4) | bib_info_length(4) | bib_crc(0);
+       memset(config_rom, 0, sizeof(config_rom));
+       config_rom[0] = BIB_CRC_LENGTH(4) | BIB_INFO_LENGTH(4) | BIB_CRC(0);
        config_rom[1] = 0x31333934;
 
        config_rom[2] =
-               bib_link_speed(card->link_speed) |
-               bib_generation(card->config_rom_generation++ % 14 + 2) |
-               bib_max_rom(2) |
-               bib_max_receive(card->max_receive) |
-               bib_bmc | bib_isc | bib_cmc | bib_imc;
+               BIB_LINK_SPEED(card->link_speed) |
+               BIB_GENERATION(card->config_rom_generation++ % 14 + 2) |
+               BIB_MAX_ROM(2) |
+               BIB_MAX_RECEIVE(card->max_receive) |
+               BIB_BMC | BIB_ISC | BIB_CMC | BIB_IMC;
        config_rom[3] = card->guid >> 32;
        config_rom[4] = card->guid;
 
@@ -125,7 +125,7 @@ generate_config_rom (struct fw_card *card, size_t *config_rom_length)
 }
 
 static void
-update_config_roms (void)
+update_config_roms(void)
 {
        struct fw_card *card;
        u32 *config_rom;
@@ -138,7 +138,7 @@ update_config_roms (void)
 }
 
 int
-fw_core_add_descriptor (struct fw_descriptor *desc)
+fw_core_add_descriptor(struct fw_descriptor *desc)
 {
        size_t i;
 
@@ -154,24 +154,24 @@ fw_core_add_descriptor (struct fw_descriptor *desc)
        if (i != desc->length)
                return -EINVAL;
 
-       down_write(&card_rwsem);
+       mutex_lock(&card_mutex);
 
-       list_add_tail (&desc->link, &descriptor_list);
+       list_add_tail(&desc->link, &descriptor_list);
        descriptor_count++;
        if (desc->immediate > 0)
                descriptor_count++;
        update_config_roms();
 
-       up_write(&card_rwsem);
+       mutex_unlock(&card_mutex);
 
        return 0;
 }
 EXPORT_SYMBOL(fw_core_add_descriptor);
 
 void
-fw_core_remove_descriptor (struct fw_descriptor *desc)
+fw_core_remove_descriptor(struct fw_descriptor *desc)
 {
-       down_write(&card_rwsem);
+       mutex_lock(&card_mutex);
 
        list_del(&desc->link);
        descriptor_count--;
@@ -179,7 +179,7 @@ fw_core_remove_descriptor (struct fw_descriptor *desc)
                descriptor_count--;
        update_config_roms();
 
-       up_write(&card_rwsem);
+       mutex_unlock(&card_mutex);
 }
 EXPORT_SYMBOL(fw_core_remove_descriptor);
 
@@ -258,7 +258,7 @@ fw_card_bm_work(struct work_struct *work)
                fw_send_request(card, &bmd.t, TCODE_LOCK_COMPARE_SWAP,
                                irm_id, generation,
                                SCODE_100, CSR_REGISTER_BASE + CSR_BUS_MANAGER_ID,
-                               &bmd.lock, sizeof bmd.lock,
+                               &bmd.lock, sizeof(bmd.lock),
                                complete_bm_lock, &bmd);
                wait_for_completion(&bmd.done);
 
@@ -318,7 +318,7 @@ fw_card_bm_work(struct work_struct *work)
                 */
                spin_unlock_irqrestore(&card->lock, flags);
                return;
-       } else if (root->config_rom[2] & bib_cmc) {
+       } else if (root->config_rom[2] & BIB_CMC) {
                /*
                 * FIXME: I suppose we should set the cmstr bit in the
                 * STATE_CLEAR register of this node, as described in
@@ -336,8 +336,11 @@ fw_card_bm_work(struct work_struct *work)
        }
 
  pick_me:
-       /* Now figure out what gap count to set. */
-       if (card->topology_type == FW_TOPOLOGY_A &&
+       /*
+        * Pick a gap count from 1394a table E-1.  The table doesn't cover
+        * the typically much larger 1394b beta repeater delays though.
+        */
+       if (!card->beta_repeaters_present &&
            card->root_node->max_hops < ARRAY_SIZE(gap_count_table))
                gap_count = gap_count_table[card->root_node->max_hops];
        else
@@ -407,21 +410,16 @@ fw_card_add(struct fw_card *card,
        card->link_speed = link_speed;
        card->guid = guid;
 
-       /* Activate link_on bit and contender bit in our self ID packets.*/
-       if (card->driver->update_phy_reg(card, 4, 0,
-                                        PHY_LINK_ACTIVE | PHY_CONTENDER) < 0)
-               return -EIO;
-
        /*
         * The subsystem grabs a reference when the card is added and
         * drops it when the driver calls fw_core_remove_card.
         */
        fw_card_get(card);
 
-       down_write(&card_rwsem);
-       config_rom = generate_config_rom (card, &length);
+       mutex_lock(&card_mutex);
+       config_rom = generate_config_rom(card, &length);
        list_add_tail(&card->link, &card_list);
-       up_write(&card_rwsem);
+       mutex_unlock(&card_mutex);
 
        return card->driver->enable(card, config_rom, length);
 }
@@ -505,16 +503,18 @@ fw_core_remove_card(struct fw_card *card)
                                     PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
        fw_core_initiate_bus_reset(card, 1);
 
-       down_write(&card_rwsem);
+       mutex_lock(&card_mutex);
        list_del(&card->link);
-       up_write(&card_rwsem);
+       mutex_unlock(&card_mutex);
 
        /* Set up the dummy driver. */
        card->driver = &dummy_driver;
 
-       fw_flush_transactions(card);
-
        fw_destroy_nodes(card);
+       flush_scheduled_work();
+
+       fw_flush_transactions(card);
+       del_timer_sync(&card->flush_timer);
 
        fw_card_put(card);
 }