Merge tag 'pci-v5.15-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaa...
[linux-2.6-microblaze.git] / drivers / net / ethernet / broadcom / tg3.c
index 8a238e3..5e0e0e7 100644 (file)
@@ -12788,7 +12788,7 @@ static void tg3_get_ethtool_stats(struct net_device *dev,
                memset(tmp_stats, 0, sizeof(struct tg3_ethtool_stats));
 }
 
-static __be32 *tg3_vpd_readblock(struct tg3 *tp, u32 *vpdlen)
+static __be32 *tg3_vpd_readblock(struct tg3 *tp, unsigned int *vpdlen)
 {
        int i;
        __be32 *buf;
@@ -12822,15 +12822,11 @@ static __be32 *tg3_vpd_readblock(struct tg3 *tp, u32 *vpdlen)
                        offset = TG3_NVM_VPD_OFF;
                        len = TG3_NVM_VPD_LEN;
                }
-       } else {
-               len = TG3_NVM_PCI_VPD_MAX_LEN;
-       }
 
-       buf = kmalloc(len, GFP_KERNEL);
-       if (buf == NULL)
-               return NULL;
+               buf = kmalloc(len, GFP_KERNEL);
+               if (!buf)
+                       return NULL;
 
-       if (magic == TG3_EEPROM_MAGIC) {
                for (i = 0; i < len; i += 4) {
                        /* The data is in little-endian format in NVRAM.
                         * Use the big-endian read routines to preserve
@@ -12841,12 +12837,9 @@ static __be32 *tg3_vpd_readblock(struct tg3 *tp, u32 *vpdlen)
                }
                *vpdlen = len;
        } else {
-               ssize_t cnt;
-
-               cnt = pci_read_vpd(tp->pdev, 0, len, (u8 *)buf);
-               if (cnt < 0)
-                       goto error;
-               *vpdlen = cnt;
+               buf = pci_vpd_alloc(tp->pdev, vpdlen);
+               if (IS_ERR(buf))
+                       return NULL;
        }
 
        return buf;
@@ -12868,9 +12861,10 @@ error:
 
 static int tg3_test_nvram(struct tg3 *tp)
 {
-       u32 csum, magic, len;
+       u32 csum, magic;
        __be32 *buf;
        int i, j, k, err = 0, size;
+       unsigned int len;
 
        if (tg3_flag(tp, NO_NVRAM))
                return 0;
@@ -13013,33 +13007,10 @@ static int tg3_test_nvram(struct tg3 *tp)
        if (!buf)
                return -ENOMEM;
 
-       i = pci_vpd_find_tag((u8 *)buf, len, PCI_VPD_LRDT_RO_DATA);
-       if (i > 0) {
-               j = pci_vpd_lrdt_size(&((u8 *)buf)[i]);
-               if (j < 0)
-                       goto out;
-
-               if (i + PCI_VPD_LRDT_TAG_SIZE + j > len)
-                       goto out;
-
-               i += PCI_VPD_LRDT_TAG_SIZE;
-               j = pci_vpd_find_info_keyword((u8 *)buf, i, j,
-                                             PCI_VPD_RO_KEYWORD_CHKSUM);
-               if (j > 0) {
-                       u8 csum8 = 0;
-
-                       j += PCI_VPD_INFO_FLD_HDR_SIZE;
-
-                       for (i = 0; i <= j; i++)
-                               csum8 += ((u8 *)buf)[i];
-
-                       if (csum8)
-                               goto out;
-               }
-       }
-
-       err = 0;
-
+       err = pci_vpd_check_csum(buf, len);
+       /* go on if no checksum found */
+       if (err == 1)
+               err = 0;
 out:
        kfree(buf);
        return err;
@@ -15624,64 +15595,36 @@ skip_phy_reset:
 static void tg3_read_vpd(struct tg3 *tp)
 {
        u8 *vpd_data;
-       unsigned int block_end, rosize, len;
-       u32 vpdlen;
-       int j, i = 0;
+       unsigned int len, vpdlen;
+       int i;
 
        vpd_data = (u8 *)tg3_vpd_readblock(tp, &vpdlen);
        if (!vpd_data)
                goto out_no_vpd;
 
-       i = pci_vpd_find_tag(vpd_data, vpdlen, PCI_VPD_LRDT_RO_DATA);
+       i = pci_vpd_find_ro_info_keyword(vpd_data, vpdlen,
+                                        PCI_VPD_RO_KEYWORD_MFR_ID, &len);
        if (i < 0)
-               goto out_not_found;
-
-       rosize = pci_vpd_lrdt_size(&vpd_data[i]);
-       block_end = i + PCI_VPD_LRDT_TAG_SIZE + rosize;
-       i += PCI_VPD_LRDT_TAG_SIZE;
+               goto partno;
 
-       if (block_end > vpdlen)
-               goto out_not_found;
-
-       j = pci_vpd_find_info_keyword(vpd_data, i, rosize,
-                                     PCI_VPD_RO_KEYWORD_MFR_ID);
-       if (j > 0) {
-               len = pci_vpd_info_field_size(&vpd_data[j]);
-
-               j += PCI_VPD_INFO_FLD_HDR_SIZE;
-               if (j + len > block_end || len != 4 ||
-                   memcmp(&vpd_data[j], "1028", 4))
-                       goto partno;
-
-               j = pci_vpd_find_info_keyword(vpd_data, i, rosize,
-                                             PCI_VPD_RO_KEYWORD_VENDOR0);
-               if (j < 0)
-                       goto partno;
+       if (len != 4 || memcmp(vpd_data + i, "1028", 4))
+               goto partno;
 
-               len = pci_vpd_info_field_size(&vpd_data[j]);
-
-               j += PCI_VPD_INFO_FLD_HDR_SIZE;
-               if (j + len > block_end)
-                       goto partno;
+       i = pci_vpd_find_ro_info_keyword(vpd_data, vpdlen,
+                                        PCI_VPD_RO_KEYWORD_VENDOR0, &len);
+       if (i < 0)
+               goto partno;
 
-               if (len >= sizeof(tp->fw_ver))
-                       len = sizeof(tp->fw_ver) - 1;
-               memset(tp->fw_ver, 0, sizeof(tp->fw_ver));
-               snprintf(tp->fw_ver, sizeof(tp->fw_ver), "%.*s bc ", len,
-                        &vpd_data[j]);
-       }
+       memset(tp->fw_ver, 0, sizeof(tp->fw_ver));
+       snprintf(tp->fw_ver, sizeof(tp->fw_ver), "%.*s bc ", len, vpd_data + i);
 
 partno:
-       i = pci_vpd_find_info_keyword(vpd_data, i, rosize,
-                                     PCI_VPD_RO_KEYWORD_PARTNO);
+       i = pci_vpd_find_ro_info_keyword(vpd_data, vpdlen,
+                                        PCI_VPD_RO_KEYWORD_PARTNO, &len);
        if (i < 0)
                goto out_not_found;
 
-       len = pci_vpd_info_field_size(&vpd_data[i]);
-
-       i += PCI_VPD_INFO_FLD_HDR_SIZE;
-       if (len > TG3_BPN_SIZE ||
-           (len + i) > vpdlen)
+       if (len > TG3_BPN_SIZE)
                goto out_not_found;
 
        memcpy(tp->board_part_number, &vpd_data[i], len);