]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
tg3: Add some VPD preprocessor constants
authorMatt Carlson <mcarlson@broadcom.com>
Thu, 3 Dec 2009 08:36:22 +0000 (08:36 +0000)
committerDavid S. Miller <davem@davemloft.net>
Thu, 3 Dec 2009 21:18:04 +0000 (13:18 -0800)
This patch cleans up the VPD code by creating preprocessor definitions
and using them in the place of hardcoded constants.

Signed-off-by: Matt Carlson <mcarlson@broadcom.com>
Reviewed-by: Michael Chan <mchan@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/tg3.c
drivers/net/tg3.h
include/linux/ethtool.h

index 36f2e1b8cbb197e319f96375b23b548b9eccec8d..2576effca845269e2a3b1e1bd52bce04ab487bec 100644 (file)
@@ -12433,7 +12433,7 @@ skip_phy_reset:
 
 static void __devinit tg3_read_partno(struct tg3 *tp)
 {
-       unsigned char vpd_data[256];   /* in little-endian format */
+       unsigned char vpd_data[TG3_NVM_VPD_LEN];   /* in little-endian format */
        unsigned int i;
        u32 magic;
 
@@ -12442,14 +12442,14 @@ static void __devinit tg3_read_partno(struct tg3 *tp)
                goto out_not_found;
 
        if (magic == TG3_EEPROM_MAGIC) {
-               for (i = 0; i < 256; i += 4) {
+               for (i = 0; i < TG3_NVM_VPD_LEN; i += 4) {
                        u32 tmp;
 
                        /* The data is in little-endian format in NVRAM.
                         * Use the big-endian read routines to preserve
                         * the byte order as it exists in NVRAM.
                         */
-                       if (tg3_nvram_read_be32(tp, 0x100 + i, &tmp))
+                       if (tg3_nvram_read_be32(tp, TG3_NVM_VPD_OFF + i, &tmp))
                                goto out_not_found;
 
                        memcpy(&vpd_data[i], &tmp, sizeof(tmp));
@@ -12458,7 +12458,7 @@ static void __devinit tg3_read_partno(struct tg3 *tp)
                int vpd_cap;
 
                vpd_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_VPD);
-               for (i = 0; i < 256; i += 4) {
+               for (i = 0; i < TG3_NVM_VPD_LEN; i += 4) {
                        u32 tmp, j = 0;
                        __le32 v;
                        u16 tmp16;
@@ -12483,7 +12483,7 @@ static void __devinit tg3_read_partno(struct tg3 *tp)
        }
 
        /* Now parse and find the part number. */
-       for (i = 0; i < 254; ) {
+       for (i = 0; i < TG3_NVM_VPD_LEN - 2; ) {
                unsigned char val = vpd_data[i];
                unsigned int block_end;
 
@@ -12502,7 +12502,7 @@ static void __devinit tg3_read_partno(struct tg3 *tp)
                              (vpd_data[i + 2] << 8)));
                i += 3;
 
-               if (block_end > 256)
+               if (block_end > TG3_NVM_VPD_LEN)
                        goto out_not_found;
 
                while (i < (block_end - 2)) {
@@ -12511,7 +12511,8 @@ static void __devinit tg3_read_partno(struct tg3 *tp)
                                int partno_len = vpd_data[i + 2];
 
                                i += 3;
-                               if (partno_len > 24 || (partno_len + i) > 256)
+                               if (partno_len > TG3_BPN_SIZE ||
+                                   (partno_len + i) > TG3_NVM_VPD_LEN)
                                        goto out_not_found;
 
                                memcpy(tp->board_part_number,
index 6a2c31071cafbfb33066ecbd4b14a09f291b8ae8..cd30889650f8774c2cab1273584888ee0b0e6ae4 100644 (file)
 
 #define TG3_OTP_DEFAULT                        0x286c1640
 
+
+/* Hardware Legacy NVRAM layout */
+#define TG3_NVM_VPD_OFF                        0x100
+#define TG3_NVM_VPD_LEN                        256
+
 /* Hardware Selfboot NVRAM layout */
 #define TG3_NVM_HWSB_CFG1              0x00000004
 #define  TG3_NVM_HWSB_CFG1_MAJMSK      0xf8000000
@@ -2893,8 +2898,9 @@ struct tg3 {
        u32                             led_ctrl;
        u32                             phy_otp;
 
-       char                            board_part_number[24];
-#define TG3_VER_SIZE 32
+#define TG3_BPN_SIZE                   24
+       char                            board_part_number[TG3_BPN_SIZE];
+#define TG3_VER_SIZE                   ETHTOOL_FWVERS_LEN
        char                            fw_ver[TG3_VER_SIZE];
        u32                             nic_sram_data_cfg;
        u32                             pci_clock_ctrl;
index bcaa0e0a54d393038bf295cbe7ca053de244f9ea..ef4a2d84d922166eec5f5a39a5250442d4eef4a4 100644 (file)
@@ -49,13 +49,14 @@ static inline __u32 ethtool_cmd_speed(struct ethtool_cmd *ep)
        return (ep->speed_hi << 16) | ep->speed;
 }
 
+#define ETHTOOL_FWVERS_LEN     32
 #define ETHTOOL_BUSINFO_LEN    32
 /* these strings are set to whatever the driver author decides... */
 struct ethtool_drvinfo {
        __u32   cmd;
        char    driver[32];     /* driver short name, "tulip", "eepro100" */
        char    version[32];    /* driver version string */
-       char    fw_version[32]; /* firmware version string, if applicable */
+       char    fw_version[ETHTOOL_FWVERS_LEN]; /* firmware version string */
        char    bus_info[ETHTOOL_BUSINFO_LEN];  /* Bus info for this IF. */
                                /* For PCI devices, use pci_name(pci_dev). */
        char    reserved1[32];