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 / bnx2x / bnx2x_main.c
index 6d98134..ae87296 100644 (file)
@@ -12189,86 +12189,35 @@ static int bnx2x_get_hwinfo(struct bnx2x *bp)
 
 static void bnx2x_read_fwinfo(struct bnx2x *bp)
 {
-       int cnt, i, block_end, rodi;
-       char vpd_start[BNX2X_VPD_LEN+1];
-       char str_id_reg[VENDOR_ID_LEN+1];
-       char str_id_cap[VENDOR_ID_LEN+1];
-       char *vpd_data;
-       char *vpd_extended_data = NULL;
-       u8 len;
-
-       cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
-       memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
-
-       if (cnt < BNX2X_VPD_LEN)
-               goto out_not_found;
-
-       /* VPD RO tag should be first tag after identifier string, hence
-        * we should be able to find it in first BNX2X_VPD_LEN chars
-        */
-       i = pci_vpd_find_tag(vpd_start, BNX2X_VPD_LEN, PCI_VPD_LRDT_RO_DATA);
-       if (i < 0)
-               goto out_not_found;
-
-       block_end = i + PCI_VPD_LRDT_TAG_SIZE +
-                   pci_vpd_lrdt_size(&vpd_start[i]);
-
-       i += PCI_VPD_LRDT_TAG_SIZE;
-
-       if (block_end > BNX2X_VPD_LEN) {
-               vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
-               if (vpd_extended_data  == NULL)
-                       goto out_not_found;
-
-               /* read rest of vpd image into vpd_extended_data */
-               memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
-               cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
-                                  block_end - BNX2X_VPD_LEN,
-                                  vpd_extended_data + BNX2X_VPD_LEN);
-               if (cnt < (block_end - BNX2X_VPD_LEN))
-                       goto out_not_found;
-               vpd_data = vpd_extended_data;
-       } else
-               vpd_data = vpd_start;
+       char str_id[VENDOR_ID_LEN + 1];
+       unsigned int vpd_len, kw_len;
+       u8 *vpd_data;
+       int rodi;
 
-       /* now vpd_data holds full vpd content in both cases */
-
-       rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
-                                  PCI_VPD_RO_KEYWORD_MFR_ID);
-       if (rodi < 0)
-               goto out_not_found;
+       memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
 
-       len = pci_vpd_info_field_size(&vpd_data[rodi]);
+       vpd_data = pci_vpd_alloc(bp->pdev, &vpd_len);
+       if (IS_ERR(vpd_data))
+               return;
 
-       if (len != VENDOR_ID_LEN)
+       rodi = pci_vpd_find_ro_info_keyword(vpd_data, vpd_len,
+                                           PCI_VPD_RO_KEYWORD_MFR_ID, &kw_len);
+       if (rodi < 0 || kw_len != VENDOR_ID_LEN)
                goto out_not_found;
 
-       rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
-
        /* vendor specific info */
-       snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
-       snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
-       if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
-           !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
-
-               rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
-                                               PCI_VPD_RO_KEYWORD_VENDOR0);
-               if (rodi >= 0) {
-                       len = pci_vpd_info_field_size(&vpd_data[rodi]);
-
-                       rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
-
-                       if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
-                               memcpy(bp->fw_ver, &vpd_data[rodi], len);
-                               bp->fw_ver[len] = ' ';
-                       }
+       snprintf(str_id, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
+       if (!strncasecmp(str_id, &vpd_data[rodi], VENDOR_ID_LEN)) {
+               rodi = pci_vpd_find_ro_info_keyword(vpd_data, vpd_len,
+                                                   PCI_VPD_RO_KEYWORD_VENDOR0,
+                                                   &kw_len);
+               if (rodi >= 0 && kw_len < sizeof(bp->fw_ver)) {
+                       memcpy(bp->fw_ver, &vpd_data[rodi], kw_len);
+                       bp->fw_ver[kw_len] = ' ';
                }
-               kfree(vpd_extended_data);
-               return;
        }
 out_not_found:
-       kfree(vpd_extended_data);
-       return;
+       kfree(vpd_data);
 }
 
 static void bnx2x_set_modes_bitmap(struct bnx2x *bp)