Commit 7e64300a authored by Joe Perches's avatar Joe Perches Committed by David S. Miller

[E1000]: Convert regtest macro's to functions

Minimal macro to function conversion in e1000_ethtool.c

Adds functions reg_pattern_test and reg_set_and_check
Changes REG_PATTERN_TEST and REG_SET_AND_CHECK macros
to call these functions.

Saves ~2.5KB

Compiled x86, untested (no hardware)

old:

$ size drivers/net/e1000/e1000_ethtool.o
   text    data     bss     dec     hex filename
  16778       0       0   16778    418a drivers/net/e1000/e1000_ethtool.o

new:

$ size drivers/net/e1000/e1000_ethtool.o
   text    data     bss     dec     hex filename
  14128       0       0   14128    3730 drivers/net/e1000/e1000_ethtool.o
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Signed-off-by: default avatarAuke Kok <auke-jan.h.kok@intel.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ef90e4ec
...@@ -728,39 +728,65 @@ e1000_set_ringparam(struct net_device *netdev, ...@@ -728,39 +728,65 @@ e1000_set_ringparam(struct net_device *netdev,
return err; return err;
} }
#define REG_PATTERN_TEST(R, M, W) \ static bool reg_pattern_test(struct e1000_adapter *adapter, uint64_t *data,
{ \ int reg, uint32_t mask, uint32_t write)
uint32_t pat, val; \ {
const uint32_t test[] = \ static const uint32_t test[] =
{0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF}; \ {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
for (pat = 0; pat < ARRAY_SIZE(test); pat++) { \ uint8_t __iomem *address = adapter->hw.hw_addr + reg;
E1000_WRITE_REG(&adapter->hw, R, (test[pat] & W)); \ uint32_t read;
val = E1000_READ_REG(&adapter->hw, R); \ int i;
if (val != (test[pat] & W & M)) { \
DPRINTK(DRV, ERR, "pattern test reg %04X failed: got " \ for (i = 0; i < ARRAY_SIZE(test); i++) {
"0x%08X expected 0x%08X\n", \ writel(write & test[i], address);
E1000_##R, val, (test[pat] & W & M)); \ read = readl(address);
*data = (adapter->hw.mac_type < e1000_82543) ? \ if (read != (write & test[i] & mask)) {
E1000_82542_##R : E1000_##R; \ DPRINTK(DRV, ERR, "pattern test reg %04X failed: "
return 1; \ "got 0x%08X expected 0x%08X\n",
} \ reg, read, (write & test[i] & mask));
} \ *data = reg;
return true;
}
}
return false;
} }
#define REG_SET_AND_CHECK(R, M, W) \ static bool reg_set_and_check(struct e1000_adapter *adapter, uint64_t *data,
{ \ int reg, uint32_t mask, uint32_t write)
uint32_t val; \ {
E1000_WRITE_REG(&adapter->hw, R, W & M); \ uint8_t __iomem *address = adapter->hw.hw_addr + reg;
val = E1000_READ_REG(&adapter->hw, R); \ uint32_t read;
if ((W & M) != (val & M)) { \
DPRINTK(DRV, ERR, "set/check reg %04X test failed: got 0x%08X "\ writel(write & mask, address);
"expected 0x%08X\n", E1000_##R, (val & M), (W & M)); \ read = readl(address);
*data = (adapter->hw.mac_type < e1000_82543) ? \ if ((read & mask) != (write & mask)) {
E1000_82542_##R : E1000_##R; \ DPRINTK(DRV, ERR, "set/check reg %04X test failed: "
return 1; \ "got 0x%08X expected 0x%08X\n",
} \ reg, (read & mask), (write & mask));
*data = reg;
return true;
}
return false;
} }
#define REG_PATTERN_TEST(reg, mask, write) \
do { \
if (reg_pattern_test(adapter, data, \
(adapter->hw.mac_type >= e1000_82543) \
? E1000_##reg : E1000_82542_##reg, \
mask, write)) \
return 1; \
} while (0)
#define REG_SET_AND_CHECK(reg, mask, write) \
do { \
if (reg_set_and_check(adapter, data, \
(adapter->hw.mac_type >= e1000_82543) \
? E1000_##reg : E1000_82542_##reg, \
mask, write)) \
return 1; \
} while (0)
static int static int
e1000_reg_test(struct e1000_adapter *adapter, uint64_t *data) e1000_reg_test(struct e1000_adapter *adapter, uint64_t *data)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment