sky2: Factor out code to calculate packet sizes
[safe/jmp/linux-2.6] / drivers / firewire / core-card.c
index f73e3bd..7083bcc 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "core.h"
 
-static int __compute_block_crc(__be32 *block)
+int fw_compute_block_crc(__be32 *block)
 {
        int length;
        u16 crc;
@@ -50,25 +50,14 @@ static int __compute_block_crc(__be32 *block)
        return length;
 }
 
-int fw_compute_block_crc(u32 *block)
-{
-       __be32 be32_block[256];
-       int i, length;
-
-       length = (*block >> 16) & 0xff;
-       for (i = 0; i < length; i++)
-               be32_block[i] = cpu_to_be32(block[i + 1]);
-       *block |= crc_itu_t(0, (u8 *) be32_block, length * 4);
-
-       return length;
-}
-
 static DEFINE_MUTEX(card_mutex);
 static LIST_HEAD(card_list);
 
 static LIST_HEAD(descriptor_list);
 static int descriptor_count;
 
+static __be32 tmp_config_rom[256];
+
 #define BIB_CRC(v)             ((v) <<  0)
 #define BIB_CRC_LENGTH(v)      ((v) << 16)
 #define BIB_INFO_LENGTH(v)     ((v) << 24)
@@ -84,10 +73,9 @@ static int descriptor_count;
 #define BIB_CMC                        ((1) << 30)
 #define BIB_IMC                        ((1) << 31)
 
-static __be32 *generate_config_rom(struct fw_card *card, size_t *rom_length)
+static size_t generate_config_rom(struct fw_card *card, __be32 *config_rom)
 {
        struct fw_descriptor *desc;
-       static __be32 config_rom[256];
        int i, j, k, length;
 
        /*
@@ -140,22 +128,19 @@ static __be32 *generate_config_rom(struct fw_card *card, size_t *rom_length)
         * the bus info block, which is always the case for this
         * implementation. */
        for (i = 0; i < j; i += length + 1)
-               length = __compute_block_crc(config_rom + i);
-
-       *rom_length = j;
+               length = fw_compute_block_crc(config_rom + i);
 
-       return config_rom;
+       return j;
 }
 
 static void update_config_roms(void)
 {
        struct fw_card *card;
-       __be32 *config_rom;
        size_t length;
 
        list_for_each_entry (card, &card_list, link) {
-               config_rom = generate_config_rom(card, &length);
-               card->driver->set_config_rom(card, config_rom, length);
+               length = generate_config_rom(card, tmp_config_rom);
+               card->driver->set_config_rom(card, tmp_config_rom, length);
        }
 }
 
@@ -443,7 +428,6 @@ EXPORT_SYMBOL(fw_card_initialize);
 int fw_card_add(struct fw_card *card,
                u32 max_receive, u32 link_speed, u64 guid)
 {
-       __be32 *config_rom;
        size_t length;
        int ret;
 
@@ -453,8 +437,8 @@ int fw_card_add(struct fw_card *card,
 
        mutex_lock(&card_mutex);
 
-       config_rom = generate_config_rom(card, &length);
-       ret = card->driver->enable(card, config_rom, length);
+       length = generate_config_rom(card, tmp_config_rom);
+       ret = card->driver->enable(card, tmp_config_rom, length);
        if (ret == 0)
                list_add_tail(&card->link, &card_list);