aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorMatt Carlson <mcarlson@broadcom.com>2009-02-25 09:25:30 -0500
committerDavid S. Miller <davem@davemloft.net>2009-02-27 02:16:36 -0500
commita9dc529dcd5c541c51cb2ba09bff99580361c576 (patch)
tree3933849baa62bb04d65a974ee01e68546fbfd33d /drivers/net
parente4f341103e4a2b35f56a0f89802f1b1448e8d04b (diff)
tg3: Correct NVRAM stream endian notations
Any software requesting NVRAM data as it exists on NVRAM is necessarily requesting that the results be returned as a bytestream. A bytestream data read in from the device can also be thought to be in big endian format. Therefore, all the LE notations in the driver are mislabeled. This patch converts all LE notations to BE notations, carefully evaluating the surrounding code in the process. 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')
-rw-r--r--drivers/net/tg3.c55
1 files changed, 29 insertions, 26 deletions
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index a2ca6ab2df00..baa1f0e1a454 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -2293,12 +2293,13 @@ static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val)
2293 return err; 2293 return err;
2294} 2294}
2295 2295
2296static int tg3_nvram_read_le(struct tg3 *tp, u32 offset, __le32 *val) 2296/* Ensures NVRAM data is in bytestream format. */
2297static int tg3_nvram_read_be32(struct tg3 *tp, u32 offset, __be32 *val)
2297{ 2298{
2298 u32 v; 2299 u32 v;
2299 int res = tg3_nvram_read_swab(tp, offset, &v); 2300 int res = tg3_nvram_read(tp, offset, &v);
2300 if (!res) 2301 if (!res)
2301 *val = cpu_to_le32(v); 2302 *val = cpu_to_be32(v);
2302 return res; 2303 return res;
2303} 2304}
2304 2305
@@ -8539,7 +8540,7 @@ static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
8539 int ret; 8540 int ret;
8540 u8 *pd; 8541 u8 *pd;
8541 u32 i, offset, len, b_offset, b_count; 8542 u32 i, offset, len, b_offset, b_count;
8542 __le32 val; 8543 __be32 val;
8543 8544
8544 if (tp->link_config.phy_is_low_power) 8545 if (tp->link_config.phy_is_low_power)
8545 return -EAGAIN; 8546 return -EAGAIN;
@@ -8558,7 +8559,7 @@ static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
8558 /* i.e. offset=1 len=2 */ 8559 /* i.e. offset=1 len=2 */
8559 b_count = len; 8560 b_count = len;
8560 } 8561 }
8561 ret = tg3_nvram_read_le(tp, offset-b_offset, &val); 8562 ret = tg3_nvram_read_be32(tp, offset-b_offset, &val);
8562 if (ret) 8563 if (ret)
8563 return ret; 8564 return ret;
8564 memcpy(data, ((char*)&val) + b_offset, b_count); 8565 memcpy(data, ((char*)&val) + b_offset, b_count);
@@ -8570,7 +8571,7 @@ static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
8570 /* read bytes upto the last 4 byte boundary */ 8571 /* read bytes upto the last 4 byte boundary */
8571 pd = &data[eeprom->len]; 8572 pd = &data[eeprom->len];
8572 for (i = 0; i < (len - (len & 3)); i += 4) { 8573 for (i = 0; i < (len - (len & 3)); i += 4) {
8573 ret = tg3_nvram_read_le(tp, offset + i, &val); 8574 ret = tg3_nvram_read_be32(tp, offset + i, &val);
8574 if (ret) { 8575 if (ret) {
8575 eeprom->len += i; 8576 eeprom->len += i;
8576 return ret; 8577 return ret;
@@ -8584,7 +8585,7 @@ static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
8584 pd = &data[eeprom->len]; 8585 pd = &data[eeprom->len];
8585 b_count = len & 3; 8586 b_count = len & 3;
8586 b_offset = offset + len - b_count; 8587 b_offset = offset + len - b_count;
8587 ret = tg3_nvram_read_le(tp, b_offset, &val); 8588 ret = tg3_nvram_read_be32(tp, b_offset, &val);
8588 if (ret) 8589 if (ret)
8589 return ret; 8590 return ret;
8590 memcpy(pd, &val, b_count); 8591 memcpy(pd, &val, b_count);
@@ -8601,7 +8602,7 @@ static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
8601 int ret; 8602 int ret;
8602 u32 offset, len, b_offset, odd_len; 8603 u32 offset, len, b_offset, odd_len;
8603 u8 *buf; 8604 u8 *buf;
8604 __le32 start, end; 8605 __be32 start, end;
8605 8606
8606 if (tp->link_config.phy_is_low_power) 8607 if (tp->link_config.phy_is_low_power)
8607 return -EAGAIN; 8608 return -EAGAIN;
@@ -8614,7 +8615,7 @@ static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
8614 8615
8615 if ((b_offset = (offset & 3))) { 8616 if ((b_offset = (offset & 3))) {
8616 /* adjustments to start on required 4 byte boundary */ 8617 /* adjustments to start on required 4 byte boundary */
8617 ret = tg3_nvram_read_le(tp, offset-b_offset, &start); 8618 ret = tg3_nvram_read_be32(tp, offset-b_offset, &start);
8618 if (ret) 8619 if (ret)
8619 return ret; 8620 return ret;
8620 len += b_offset; 8621 len += b_offset;
@@ -8628,7 +8629,7 @@ static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
8628 /* adjustments to end on required 4 byte boundary */ 8629 /* adjustments to end on required 4 byte boundary */
8629 odd_len = 1; 8630 odd_len = 1;
8630 len = (len + 3) & ~3; 8631 len = (len + 3) & ~3;
8631 ret = tg3_nvram_read_le(tp, offset+len-4, &end); 8632 ret = tg3_nvram_read_be32(tp, offset+len-4, &end);
8632 if (ret) 8633 if (ret)
8633 return ret; 8634 return ret;
8634 } 8635 }
@@ -9200,7 +9201,7 @@ static void tg3_get_ethtool_stats (struct net_device *dev,
9200static int tg3_test_nvram(struct tg3 *tp) 9201static int tg3_test_nvram(struct tg3 *tp)
9201{ 9202{
9202 u32 csum, magic; 9203 u32 csum, magic;
9203 __le32 *buf; 9204 __be32 *buf;
9204 int i, j, k, err = 0, size; 9205 int i, j, k, err = 0, size;
9205 9206
9206 if (tg3_nvram_read(tp, 0, &magic) != 0) 9207 if (tg3_nvram_read(tp, 0, &magic) != 0)
@@ -9237,14 +9238,15 @@ static int tg3_test_nvram(struct tg3 *tp)
9237 9238
9238 err = -EIO; 9239 err = -EIO;
9239 for (i = 0, j = 0; i < size; i += 4, j++) { 9240 for (i = 0, j = 0; i < size; i += 4, j++) {
9240 if ((err = tg3_nvram_read_le(tp, i, &buf[j])) != 0) 9241 err = tg3_nvram_read_be32(tp, i, &buf[j]);
9242 if (err)
9241 break; 9243 break;
9242 } 9244 }
9243 if (i < size) 9245 if (i < size)
9244 goto out; 9246 goto out;
9245 9247
9246 /* Selfboot format */ 9248 /* Selfboot format */
9247 magic = swab32(le32_to_cpu(buf[0])); 9249 magic = be32_to_cpu(buf[0]);
9248 if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == 9250 if ((magic & TG3_EEPROM_MAGIC_FW_MSK) ==
9249 TG3_EEPROM_MAGIC_FW) { 9251 TG3_EEPROM_MAGIC_FW) {
9250 u8 *buf8 = (u8 *) buf, csum8 = 0; 9252 u8 *buf8 = (u8 *) buf, csum8 = 0;
@@ -9273,7 +9275,7 @@ static int tg3_test_nvram(struct tg3 *tp)
9273 if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == 9275 if ((magic & TG3_EEPROM_MAGIC_HW_MSK) ==
9274 TG3_EEPROM_MAGIC_HW) { 9276 TG3_EEPROM_MAGIC_HW) {
9275 u8 data[NVRAM_SELFBOOT_DATA_SIZE]; 9277 u8 data[NVRAM_SELFBOOT_DATA_SIZE];
9276 u8 parity[NVRAM_SELFBOOT_DATA_SIZE]; 9278 u8 parity[NVRAM_SELFBOOT_DATA_SIZE];
9277 u8 *buf8 = (u8 *) buf; 9279 u8 *buf8 = (u8 *) buf;
9278 9280
9279 /* Separate the parity bits and the data bytes. */ 9281 /* Separate the parity bits and the data bytes. */
@@ -9316,13 +9318,13 @@ static int tg3_test_nvram(struct tg3 *tp)
9316 9318
9317 /* Bootstrap checksum at offset 0x10 */ 9319 /* Bootstrap checksum at offset 0x10 */
9318 csum = calc_crc((unsigned char *) buf, 0x10); 9320 csum = calc_crc((unsigned char *) buf, 0x10);
9319 if(csum != le32_to_cpu(buf[0x10/4])) 9321 if (csum != be32_to_cpu(buf[0x10/4]))
9320 goto out; 9322 goto out;
9321 9323
9322 /* Manufacturing block starts at offset 0x74, checksum at 0xfc */ 9324 /* Manufacturing block starts at offset 0x74, checksum at 0xfc */
9323 csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88); 9325 csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88);
9324 if (csum != le32_to_cpu(buf[0xfc/4])) 9326 if (csum != be32_to_cpu(buf[0xfc/4]))
9325 goto out; 9327 goto out;
9326 9328
9327 err = 0; 9329 err = 0;
9328 9330
@@ -10654,13 +10656,13 @@ static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp,
10654 10656
10655 for (i = 0; i < len; i += 4) { 10657 for (i = 0; i < len; i += 4) {
10656 u32 addr; 10658 u32 addr;
10657 __le32 data; 10659 __be32 data;
10658 10660
10659 addr = offset + i; 10661 addr = offset + i;
10660 10662
10661 memcpy(&data, buf + i, 4); 10663 memcpy(&data, buf + i, 4);
10662 10664
10663 tw32(GRC_EEPROM_DATA, le32_to_cpu(data)); 10665 tw32(GRC_EEPROM_DATA, be32_to_cpu(data));
10664 10666
10665 val = tr32(GRC_EEPROM_ADDR); 10667 val = tr32(GRC_EEPROM_ADDR);
10666 tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE); 10668 tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE);
@@ -10710,8 +10712,9 @@ static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len,
10710 phy_addr = offset & ~pagemask; 10712 phy_addr = offset & ~pagemask;
10711 10713
10712 for (j = 0; j < pagesize; j += 4) { 10714 for (j = 0; j < pagesize; j += 4) {
10713 if ((ret = tg3_nvram_read_le(tp, phy_addr + j, 10715 ret = tg3_nvram_read_be32(tp, phy_addr + j,
10714 (__le32 *) (tmp + j)))) 10716 (__be32 *) (tmp + j));
10717 if (ret)
10715 break; 10718 break;
10716 } 10719 }
10717 if (ret) 10720 if (ret)
@@ -10758,7 +10761,7 @@ static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len,
10758 __be32 data; 10761 __be32 data;
10759 10762
10760 data = *((__be32 *) (tmp + j)); 10763 data = *((__be32 *) (tmp + j));
10761 /* swab32(le32_to_cpu(data)), actually */ 10764
10762 tw32(NVRAM_WRDATA, be32_to_cpu(data)); 10765 tw32(NVRAM_WRDATA, be32_to_cpu(data));
10763 10766
10764 tw32(NVRAM_ADDR, phy_addr + j); 10767 tw32(NVRAM_ADDR, phy_addr + j);
@@ -11529,8 +11532,8 @@ static void __devinit tg3_read_fw_ver(struct tg3 *tp)
11529 11532
11530 offset = offset + ver_offset - start; 11533 offset = offset + ver_offset - start;
11531 for (i = 0; i < 16; i += 4) { 11534 for (i = 0; i < 16; i += 4) {
11532 __le32 v; 11535 __be32 v;
11533 if (tg3_nvram_read_le(tp, offset + i, &v)) 11536 if (tg3_nvram_read_be32(tp, offset + i, &v))
11534 return; 11537 return;
11535 11538
11536 memcpy(tp->fw_ver + i, &v, 4); 11539 memcpy(tp->fw_ver + i, &v, 4);
@@ -11571,8 +11574,8 @@ static void __devinit tg3_read_fw_ver(struct tg3 *tp)
11571 tp->fw_ver[bcnt++] = ' '; 11574 tp->fw_ver[bcnt++] = ' ';
11572 11575
11573 for (i = 0; i < 4; i++) { 11576 for (i = 0; i < 4; i++) {
11574 __le32 v; 11577 __be32 v;
11575 if (tg3_nvram_read_le(tp, offset, &v)) 11578 if (tg3_nvram_read_be32(tp, offset, &v))
11576 return; 11579 return;
11577 11580
11578 offset += sizeof(v); 11581 offset += sizeof(v);