diff options
author | Matt Carlson <mcarlson@broadcom.com> | 2009-02-25 09:25:52 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-02-27 02:16:37 -0500 |
commit | 6d348f2c1e0bb1cf7a494b51fc921095ead3f6ae (patch) | |
tree | 50cdec651df320aa42d1f2b896cc6aa50296e21f /drivers/net/tg3.c | |
parent | a9dc529dcd5c541c51cb2ba09bff99580361c576 (diff) |
tg3: Eliminate tg3_nvram_read_swab()
The remaining uses of tg3_nvram_read_swab() either intended to read the
data from NVRAM exactly as tg3_nvram_read_be32() did or hide deeper
interpretations of the data. For the former case, a direct replacement
of tg3_nvram_read_swab() with tg3_nvram_read_be32() is in order. For
the latter case, we remove tg3_nvram_read_swab() and document what the
code is really doing.
Signed-off-by: Matt Carlson <mcarlson@broadcom.com>
Signed-off-by: Benjamin Li <benli@broadcom.com>
Signed-off-by: Michael Chan <mchan@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/tg3.c')
-rw-r--r-- | drivers/net/tg3.c | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c index baa1f0e1a454..945391862ab1 100644 --- a/drivers/net/tg3.c +++ b/drivers/net/tg3.c | |||
@@ -2283,16 +2283,6 @@ static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val) | |||
2283 | return ret; | 2283 | return ret; |
2284 | } | 2284 | } |
2285 | 2285 | ||
2286 | static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val) | ||
2287 | { | ||
2288 | int err; | ||
2289 | u32 tmp; | ||
2290 | |||
2291 | err = tg3_nvram_read(tp, offset, &tmp); | ||
2292 | *val = swab32(tmp); | ||
2293 | return err; | ||
2294 | } | ||
2295 | |||
2296 | /* Ensures NVRAM data is in bytestream format. */ | 2286 | /* Ensures NVRAM data is in bytestream format. */ |
2297 | static int tg3_nvram_read_be32(struct tg3 *tp, u32 offset, __be32 *val) | 2287 | static int tg3_nvram_read_be32(struct tg3 *tp, u32 offset, __be32 *val) |
2298 | { | 2288 | { |
@@ -10195,9 +10185,20 @@ static void __devinit tg3_get_nvram_size(struct tg3 *tp) | |||
10195 | return; | 10185 | return; |
10196 | } | 10186 | } |
10197 | 10187 | ||
10198 | if (tg3_nvram_read_swab(tp, 0xf0, &val) == 0) { | 10188 | if (tg3_nvram_read(tp, 0xf0, &val) == 0) { |
10199 | if (val != 0) { | 10189 | if (val != 0) { |
10200 | tp->nvram_size = (val >> 16) * 1024; | 10190 | /* This is confusing. We want to operate on the |
10191 | * 16-bit value at offset 0xf2. The tg3_nvram_read() | ||
10192 | * call will read from NVRAM and byteswap the data | ||
10193 | * according to the byteswapping settings for all | ||
10194 | * other register accesses. This ensures the data we | ||
10195 | * want will always reside in the lower 16-bits. | ||
10196 | * However, the data in NVRAM is in LE format, which | ||
10197 | * means the data from the NVRAM read will always be | ||
10198 | * opposite the endianness of the CPU. The 16-bit | ||
10199 | * byteswap then brings the data to CPU endianness. | ||
10200 | */ | ||
10201 | tp->nvram_size = swab16((u16)(val & 0x0000ffff)) * 1024; | ||
10201 | return; | 10202 | return; |
10202 | } | 10203 | } |
10203 | } | 10204 | } |
@@ -11347,7 +11348,7 @@ skip_phy_reset: | |||
11347 | 11348 | ||
11348 | static void __devinit tg3_read_partno(struct tg3 *tp) | 11349 | static void __devinit tg3_read_partno(struct tg3 *tp) |
11349 | { | 11350 | { |
11350 | unsigned char vpd_data[256]; | 11351 | unsigned char vpd_data[256]; /* in little-endian format */ |
11351 | unsigned int i; | 11352 | unsigned int i; |
11352 | u32 magic; | 11353 | u32 magic; |
11353 | 11354 | ||
@@ -11358,13 +11359,14 @@ static void __devinit tg3_read_partno(struct tg3 *tp) | |||
11358 | for (i = 0; i < 256; i += 4) { | 11359 | for (i = 0; i < 256; i += 4) { |
11359 | u32 tmp; | 11360 | u32 tmp; |
11360 | 11361 | ||
11361 | if (tg3_nvram_read_swab(tp, 0x100 + i, &tmp)) | 11362 | /* The data is in little-endian format in NVRAM. |
11363 | * Use the big-endian read routines to preserve | ||
11364 | * the byte order as it exists in NVRAM. | ||
11365 | */ | ||
11366 | if (tg3_nvram_read_be32(tp, 0x100 + i, &tmp)) | ||
11362 | goto out_not_found; | 11367 | goto out_not_found; |
11363 | 11368 | ||
11364 | vpd_data[i + 0] = ((tmp >> 0) & 0xff); | 11369 | memcpy(&vpd_data[i], &tmp, sizeof(tmp)); |
11365 | vpd_data[i + 1] = ((tmp >> 8) & 0xff); | ||
11366 | vpd_data[i + 2] = ((tmp >> 16) & 0xff); | ||
11367 | vpd_data[i + 3] = ((tmp >> 24) & 0xff); | ||
11368 | } | 11370 | } |
11369 | } else { | 11371 | } else { |
11370 | int vpd_cap; | 11372 | int vpd_cap; |
@@ -11390,7 +11392,7 @@ static void __devinit tg3_read_partno(struct tg3 *tp) | |||
11390 | pci_read_config_dword(tp->pdev, vpd_cap + PCI_VPD_DATA, | 11392 | pci_read_config_dword(tp->pdev, vpd_cap + PCI_VPD_DATA, |
11391 | &tmp); | 11393 | &tmp); |
11392 | v = cpu_to_le32(tmp); | 11394 | v = cpu_to_le32(tmp); |
11393 | memcpy(&vpd_data[i], &v, 4); | 11395 | memcpy(&vpd_data[i], &v, sizeof(v)); |
11394 | } | 11396 | } |
11395 | } | 11397 | } |
11396 | 11398 | ||
@@ -12358,14 +12360,10 @@ static int __devinit tg3_get_device_address(struct tg3 *tp) | |||
12358 | } | 12360 | } |
12359 | if (!addr_ok) { | 12361 | if (!addr_ok) { |
12360 | /* Next, try NVRAM. */ | 12362 | /* Next, try NVRAM. */ |
12361 | if (!tg3_nvram_read_swab(tp, mac_offset + 0, &hi) && | 12363 | if (!tg3_nvram_read_be32(tp, mac_offset + 0, &hi) && |
12362 | !tg3_nvram_read_swab(tp, mac_offset + 4, &lo)) { | 12364 | !tg3_nvram_read_be32(tp, mac_offset + 4, &lo)) { |
12363 | dev->dev_addr[0] = ((hi >> 16) & 0xff); | 12365 | memcpy(&dev->dev_addr[0], ((char *)&hi) + 2, 2); |
12364 | dev->dev_addr[1] = ((hi >> 24) & 0xff); | 12366 | memcpy(&dev->dev_addr[2], (char *)&lo, sizeof(lo)); |
12365 | dev->dev_addr[2] = ((lo >> 0) & 0xff); | ||
12366 | dev->dev_addr[3] = ((lo >> 8) & 0xff); | ||
12367 | dev->dev_addr[4] = ((lo >> 16) & 0xff); | ||
12368 | dev->dev_addr[5] = ((lo >> 24) & 0xff); | ||
12369 | } | 12367 | } |
12370 | /* Finally just fetch it out of the MAC control regs. */ | 12368 | /* Finally just fetch it out of the MAC control regs. */ |
12371 | else { | 12369 | else { |