rt2x00: Move firmware checksumming to driver
authorIvo van Doorn <ivdoorn@gmail.com>
Sun, 9 Mar 2008 21:44:54 +0000 (22:44 +0100)
committerJohn W. Linville <linville@tuxdriver.com>
Thu, 13 Mar 2008 20:02:36 +0000 (16:02 -0400)
rt2x00lib depended on 2 crc algorithms because rt61/rt73
use a different algorithm then rt2800. This means that
even when only 1 algorithm was needed, the dependency was
still present for both.
By moving the checksum generation to the driver we can clean
up 2 annoying flags (which indicated which checksum was required)
and move the dependency to where it belongs: the driver.

Signed-off-by: Ivo van Doorn <IvDoorn@gmail.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
drivers/net/wireless/rt2x00/Kconfig
drivers/net/wireless/rt2x00/rt2x00.h
drivers/net/wireless/rt2x00/rt2x00firmware.c
drivers/net/wireless/rt2x00/rt61pci.c
drivers/net/wireless/rt2x00/rt73usb.c

index d5240aa06233c631625a48d7fa3954fa9fb2359f..4709c11da4194d76eee2d0470d03f02106590e41 100644 (file)
@@ -27,8 +27,6 @@ config RT2X00_LIB_USB
 config RT2X00_LIB_FIRMWARE
        boolean
        depends on RT2X00_LIB
-       select CRC_CCITT
-       select CRC_ITU_T
        select FW_LOADER
 
 config RT2X00_LIB_RFKILL
@@ -102,6 +100,7 @@ config RT61PCI
        depends on PCI
        select RT2X00_LIB_PCI
        select RT2X00_LIB_FIRMWARE
+       select CRC_ITU_T
        select EEPROM_93CX6
        ---help---
          This is an experimental driver for the Ralink rt61 wireless chip.
@@ -145,6 +144,7 @@ config RT73USB
        depends on USB
        select RT2X00_LIB_USB
        select RT2X00_LIB_FIRMWARE
+       select CRC_ITU_T
        ---help---
          This is an experimental driver for the Ralink rt73 wireless chip.
 
index fd65fccbdae7813a04dbe247f7181efa0724a888..8718ad3dcc00f67847323632c59f01cb1f2ecf19 100644 (file)
@@ -495,6 +495,7 @@ struct rt2x00lib_ops {
         */
        int (*probe_hw) (struct rt2x00_dev *rt2x00dev);
        char *(*get_firmware_name) (struct rt2x00_dev *rt2x00dev);
+       u16 (*get_firmware_crc) (void *data, const size_t len);
        int (*load_firmware) (struct rt2x00_dev *rt2x00dev, void *data,
                              const size_t len);
 
@@ -613,8 +614,6 @@ enum rt2x00_flags {
         */
        DRIVER_SUPPORT_MIXED_INTERFACES,
        DRIVER_REQUIRE_FIRMWARE,
-       DRIVER_REQUIRE_FIRMWARE_CRC_ITU_T,
-       DRIVER_REQUIRE_FIRMWARE_CCITT,
        DRIVER_REQUIRE_BEACON_GUARD,
        DRIVER_REQUIRE_ATIM_QUEUE,
 
index 4f9fe56f4f2e42689ea1ddf07d686fcd680a4fde..b971bc6e7ee260d9f3ca282e806004aeecae2faf 100644 (file)
@@ -23,8 +23,6 @@
        Abstract: rt2x00 firmware loading routines.
  */
 
-#include <linux/crc-ccitt.h>
-#include <linux/crc-itu-t.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 
@@ -63,36 +61,7 @@ static int rt2x00lib_request_firmware(struct rt2x00_dev *rt2x00dev)
                return -ENOENT;
        }
 
-       /*
-        * Perform crc validation on the firmware.
-        * The last 2 bytes in the firmware array are the crc checksum itself,
-        * this means that we should never pass those 2 bytes to the crc
-        * algorithm.
-        */
-       if (test_bit(DRIVER_REQUIRE_FIRMWARE_CRC_ITU_T, &rt2x00dev->flags)) {
-               /*
-                * Use the crc itu-t algorithm.
-                * Use 0 for the last 2 bytes to complete the checksum.
-                */
-               crc = crc_itu_t(0, fw->data, fw->size - 2);
-               crc = crc_itu_t_byte(crc, 0);
-               crc = crc_itu_t_byte(crc, 0);
-       } else if (test_bit(DRIVER_REQUIRE_FIRMWARE_CCITT, &rt2x00dev->flags)) {
-               /*
-                * Use the crc ccitt algorithm.
-                * This will return the same value as the legacy driver which
-                * used bit ordering reversion on the both the firmware bytes
-                * before input input as well as on the final output.
-                * Obviously using crc ccitt directly is much more efficient.
-                */
-               crc = crc_ccitt(~0, fw->data, fw->size - 2);
-       } else {
-               ERROR(rt2x00dev, "No checksum algorithm selected "
-                     "for firmware validation.\n");
-               retval = -ENOENT;
-               goto exit;
-       }
-
+       crc = rt2x00dev->ops->lib->get_firmware_crc(fw->data, fw->size);
        if (crc != (fw->data[fw->size - 2] << 8 | fw->data[fw->size - 1])) {
                ERROR(rt2x00dev, "Firmware checksum error.\n");
                retval = -ENOENT;
@@ -139,4 +108,3 @@ void rt2x00lib_free_firmware(struct rt2x00_dev *rt2x00dev)
        release_firmware(rt2x00dev->fw);
        rt2x00dev->fw = NULL;
 }
-
index 13b918db1850b9b92fbc1a2fbda338db5f7ff544..23b3e163b9ba8e605009a9dc95ce0bd0dac22efd 100644 (file)
@@ -24,6 +24,7 @@
        Supported chipsets: RT2561, RT2561s, RT2661.
  */
 
+#include <linux/crc-itu-t.h>
 #include <linux/delay.h>
 #include <linux/etherdevice.h>
 #include <linux/init.h>
@@ -856,7 +857,7 @@ dynamic_cca_tune:
 }
 
 /*
- * Firmware name function.
+ * Firmware functions
  */
 static char *rt61pci_get_firmware_name(struct rt2x00_dev *rt2x00dev)
 {
@@ -880,9 +881,23 @@ static char *rt61pci_get_firmware_name(struct rt2x00_dev *rt2x00dev)
        return fw_name;
 }
 
-/*
- * Initialization functions.
- */
+static u16 rt61pci_get_firmware_crc(void *data, const size_t len)
+{
+       u16 crc;
+
+       /*
+        * Use the crc itu-t algorithm.
+        * The last 2 bytes in the firmware array are the crc checksum itself,
+        * this means that we should never pass those 2 bytes to the crc
+        * algorithm.
+        */
+       crc = crc_itu_t(0, data, len - 2);
+       crc = crc_itu_t_byte(crc, 0);
+       crc = crc_itu_t_byte(crc, 0);
+
+       return crc;
+}
+
 static int rt61pci_load_firmware(struct rt2x00_dev *rt2x00dev, void *data,
                                 const size_t len)
 {
@@ -963,6 +978,9 @@ static int rt61pci_load_firmware(struct rt2x00_dev *rt2x00dev, void *data,
        return 0;
 }
 
+/*
+ * Initialization functions.
+ */
 static void rt61pci_init_rxentry(struct rt2x00_dev *rt2x00dev,
                                 struct queue_entry *entry)
 {
@@ -2257,7 +2275,6 @@ static int rt61pci_probe_hw(struct rt2x00_dev *rt2x00dev)
         * This device requires firmware.
         */
        __set_bit(DRIVER_REQUIRE_FIRMWARE, &rt2x00dev->flags);
-       __set_bit(DRIVER_REQUIRE_FIRMWARE_CRC_ITU_T, &rt2x00dev->flags);
 
        /*
         * Set the rssi offset.
@@ -2457,6 +2474,7 @@ static const struct rt2x00lib_ops rt61pci_rt2x00_ops = {
        .irq_handler            = rt61pci_interrupt,
        .probe_hw               = rt61pci_probe_hw,
        .get_firmware_name      = rt61pci_get_firmware_name,
+       .get_firmware_crc       = rt61pci_get_firmware_crc,
        .load_firmware          = rt61pci_load_firmware,
        .initialize             = rt2x00pci_initialize,
        .uninitialize           = rt2x00pci_uninitialize,
index 82dd4ced4005ac1a3bf7d15666801036f6036980..72c2827ee57c33c6404bf6ac93961db739c61573 100644 (file)
@@ -24,6 +24,7 @@
        Supported chipsets: rt2571W & rt2671.
  */
 
+#include <linux/crc-itu-t.h>
 #include <linux/delay.h>
 #include <linux/etherdevice.h>
 #include <linux/init.h>
@@ -817,16 +818,30 @@ dynamic_cca_tune:
 }
 
 /*
- * Firmware name function.
+ * Firmware functions
  */
 static char *rt73usb_get_firmware_name(struct rt2x00_dev *rt2x00dev)
 {
        return FIRMWARE_RT2571;
 }
 
-/*
- * Initialization functions.
- */
+static u16 rt73usb_get_firmware_crc(void *data, const size_t len)
+{
+       u16 crc;
+
+       /*
+        * Use the crc itu-t algorithm.
+        * The last 2 bytes in the firmware array are the crc checksum itself,
+        * this means that we should never pass those 2 bytes to the crc
+        * algorithm.
+        */
+       crc = crc_itu_t(0, data, len - 2);
+       crc = crc_itu_t_byte(crc, 0);
+       crc = crc_itu_t_byte(crc, 0);
+
+       return crc;
+}
+
 static int rt73usb_load_firmware(struct rt2x00_dev *rt2x00dev, void *data,
                                 const size_t len)
 {
@@ -896,6 +911,9 @@ static int rt73usb_load_firmware(struct rt2x00_dev *rt2x00dev, void *data,
        return 0;
 }
 
+/*
+ * Initialization functions.
+ */
 static int rt73usb_init_registers(struct rt2x00_dev *rt2x00dev)
 {
        u32 reg;
@@ -1852,7 +1870,6 @@ static int rt73usb_probe_hw(struct rt2x00_dev *rt2x00dev)
         * This device requires firmware.
         */
        __set_bit(DRIVER_REQUIRE_FIRMWARE, &rt2x00dev->flags);
-       __set_bit(DRIVER_REQUIRE_FIRMWARE_CRC_ITU_T, &rt2x00dev->flags);
 
        /*
         * Set the rssi offset.
@@ -2061,6 +2078,7 @@ static const struct ieee80211_ops rt73usb_mac80211_ops = {
 static const struct rt2x00lib_ops rt73usb_rt2x00_ops = {
        .probe_hw               = rt73usb_probe_hw,
        .get_firmware_name      = rt73usb_get_firmware_name,
+       .get_firmware_crc       = rt73usb_get_firmware_crc,
        .load_firmware          = rt73usb_load_firmware,
        .initialize             = rt2x00usb_initialize,
        .uninitialize           = rt2x00usb_uninitialize,
This page took 0.029116 seconds and 5 git commands to generate.