]> err.no Git - linux-2.6/commitdiff
[E1000E]: convert register test macros to functions
authorJoe Perches <joe@perches.com>
Wed, 14 Nov 2007 04:53:51 +0000 (20:53 -0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 28 Jan 2008 23:03:51 +0000 (15:03 -0800)
Add functions for reg_pattern_test and reg_set_and check
Changed macros to use these functions

Compiled x86, untested

Size decreased ~2K

old:

$ size drivers/net/e1000e/ethtool.o
   text    data     bss     dec     hex filename
  14461       0       0   14461    387d drivers/net/e1000e/ethtool.o

new:

$ size drivers/net/e1000e/ethtool.o
   text    data     bss     dec     hex filename
  12498       0       0   12498    30d2 drivers/net/e1000e/ethtool.o

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Auke Kok <auke-jan.h.kok@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/e1000e/ethtool.c

index e6ff3af8ef0f8f10023610c443bcb84a8e7f2b05..6d9c27fd0b53b86953ecf3548d59c4825de1e626 100644 (file)
@@ -690,41 +690,63 @@ err_setup:
        return err;
 }
 
-#define REG_PATTERN_TEST(R, M, W) REG_PATTERN_TEST_ARRAY(R, 0, M, W)
-#define REG_PATTERN_TEST_ARRAY(reg, offset, mask, writeable)                 \
-{                                                                            \
-       u32 _pat;                                                             \
-       u32 _value;                                                           \
-       u32 _test[] = {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};       \
-       for (_pat = 0; _pat < ARRAY_SIZE(_test); _pat++) {                    \
-               E1000_WRITE_REG_ARRAY(hw, reg, offset,        \
-                                     (_test[_pat] & writeable));             \
-               _value = E1000_READ_REG_ARRAY(hw, reg, offset);     \
-               if (_value != (_test[_pat] & writeable & mask)) {             \
-                       ndev_err(netdev, "pattern test reg %04X "             \
-                                "failed: got 0x%08X expected 0x%08X\n",      \
-                                reg + offset,  \
-                                value, (_test[_pat] & writeable & mask));    \
-                       *data = reg;                                          \
-                       return 1;                                             \
-               }                                                             \
-       }                                                                     \
+bool reg_pattern_test_array(struct e1000_adapter *adapter, u64 *data,
+                           int reg, int offset, u32 mask, u32 write)
+{
+       int i;
+       u32 read;
+       static const u32 test[] =
+               {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
+       for (i = 0; i < ARRAY_SIZE(test); i++) {
+               E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
+                                     (test[i] & write));
+               read = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
+               if (read != (test[i] & write & mask)) {
+                       ndev_err(adapter->netdev, "pattern test reg %04X "
+                                "failed: got 0x%08X expected 0x%08X\n",
+                                reg + offset,
+                                read, (test[i] & write & mask));
+                       *data = reg;
+                       return true;
+               }
+       }
+       return false;
 }
 
-#define REG_SET_AND_CHECK(R, M, W)                                           \
-{                                                                            \
-       u32 _value;                                                           \
-       __ew32(hw, R, W & M);                                           \
-       _value = __er32(hw, R);                                         \
-       if ((W & M) != (_value & M)) {                                        \
-               ndev_err(netdev, "set/check reg %04X test failed: "           \
-                        "got 0x%08X expected 0x%08X\n", R, (_value & M),     \
-                        (W & M));                                            \
-               *data = R;                                                    \
-               return 1;                                                     \
-       }                                                                     \
+static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
+                             int reg, u32 mask, u32 write)
+{
+       u32 read;
+       __ew32(&adapter->hw, reg, write & mask);
+       read = __er32(&adapter->hw, reg);
+       if ((write & mask) != (read & mask)) {
+               ndev_err(adapter->netdev, "set/check reg %04X test failed: "
+                        "got 0x%08X expected 0x%08X\n", reg, (read & mask),
+                        (write & mask));
+               *data = reg;
+               return true;
+       }
+       return false;
 }
 
+#define REG_PATTERN_TEST(R, M, W) \
+       do { \
+               if (reg_pattern_test_array(adapter, data, R, 0, M, W)) \
+                       return 1; \
+       } while (0)
+
+#define REG_PATTERN_TEST_ARRAY(R, offset, M, W) \
+       do { \
+               if (reg_pattern_test_array(adapter, data, R, offset, M, W)) \
+                       return 1; \
+       } while (0)
+
+#define REG_SET_AND_CHECK(R, M, W) \
+       do { \
+               if (reg_set_and_check(adapter, data, R, M, W)) \
+                       return 1; \
+       } while (0)
+
 static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
 {
        struct e1000_hw *hw = &adapter->hw;