aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/net/bnx2.c54
-rw-r--r--drivers/net/tg3.c32
-rw-r--r--drivers/pci/vpd.c18
-rw-r--r--include/linux/pci.h17
4 files changed, 78 insertions, 43 deletions
diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index b808707f83ff..bc23bfb687c3 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -7769,48 +7769,54 @@ bnx2_read_vpd_fw_ver(struct bnx2 *bp)
7769 } 7769 }
7770 7770
7771 for (i = 0; i <= BNX2_VPD_LEN - 3; ) { 7771 for (i = 0; i <= BNX2_VPD_LEN - 3; ) {
7772 unsigned int block_end; 7772 int j;
7773 unsigned int block_end, rosize;
7773 7774
7774 i = pci_vpd_find_tag(data, i, BNX2_VPD_LEN, 7775 i = pci_vpd_find_tag(data, i, BNX2_VPD_LEN,
7775 PCI_VPD_LRDT_RO_DATA); 7776 PCI_VPD_LRDT_RO_DATA);
7776 if (i < 0) 7777 if (i < 0)
7777 break; 7778 break;
7778 7779
7779 block_end = (i + PCI_VPD_LRDT_TAG_SIZE + 7780 rosize = pci_vpd_lrdt_size(&data[i]);
7780 pci_vpd_lrdt_size(&data[i])); 7781 block_end = i + PCI_VPD_LRDT_TAG_SIZE + rosize;
7781 i += PCI_VPD_LRDT_TAG_SIZE; 7782 i += PCI_VPD_LRDT_TAG_SIZE;
7782 7783
7783 if (block_end > BNX2_VPD_LEN) 7784 if (block_end > BNX2_VPD_LEN)
7784 goto vpd_done; 7785 goto vpd_done;
7785 7786
7786 while (i < (block_end - 2)) { 7787 j = pci_vpd_find_info_keyword(data, i, rosize,
7787 int len = pci_vpd_info_field_size(&data[i]); 7788 PCI_VPD_RO_KEYWORD_MFR_ID);
7789 if (j > 0) {
7790 int len = pci_vpd_info_field_size(&data[j]);
7788 7791
7789 if (i + PCI_VPD_INFO_FLD_HDR_SIZE + len > block_end) 7792 if (j + PCI_VPD_INFO_FLD_HDR_SIZE + len > block_end ||
7793 len != 4 ||
7794 memcmp(&data[j + PCI_VPD_INFO_FLD_HDR_SIZE],
7795 "1028", 4))
7790 goto vpd_done; 7796 goto vpd_done;
7791 7797
7792 if (data[i] == 'M' && data[i + 1] == 'N') { 7798 mn_match = true;
7793 if (len != 4 || 7799 }
7794 memcmp(&data[i + PCI_VPD_INFO_FLD_HDR_SIZE],
7795 "1028", 4))
7796 goto vpd_done;
7797 mn_match = true;
7798 7800
7799 } else if (data[i] == 'V' && data[i + 1] == '0') { 7801 j = pci_vpd_find_info_keyword(data, i, rosize,
7800 if (len > BNX2_MAX_VER_SLEN) 7802 PCI_VPD_RO_KEYWORD_VENDOR0);
7801 goto vpd_done; 7803 if (j > 0) {
7804 int len = pci_vpd_info_field_size(&data[j]);
7802 7805
7803 v0_len = len; 7806 j += PCI_VPD_INFO_FLD_HDR_SIZE;
7804 v0_str = &data[i + PCI_VPD_INFO_FLD_HDR_SIZE]; 7807 if (j + len > block_end || len > BNX2_MAX_VER_SLEN)
7805 }
7806 i += PCI_VPD_INFO_FLD_HDR_SIZE + len;
7807
7808 if (mn_match && v0_str) {
7809 memcpy(bp->fw_version, v0_str, v0_len);
7810 bp->fw_version[v0_len] = ' ';
7811 goto vpd_done; 7808 goto vpd_done;
7812 } 7809
7810 v0_len = len;
7811 v0_str = &data[j];
7813 } 7812 }
7813
7814 if (mn_match && v0_str) {
7815 memcpy(bp->fw_version, v0_str, v0_len);
7816 bp->fw_version[v0_len] = ' ';
7817 goto vpd_done;
7818 }
7819
7814 goto vpd_done; 7820 goto vpd_done;
7815 } 7821 }
7816 7822
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index f59f36910e98..204c565caa5a 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -12586,39 +12586,33 @@ static void __devinit tg3_read_partno(struct tg3 *tp)
12586 12586
12587 /* Now parse and find the part number. */ 12587 /* Now parse and find the part number. */
12588 for (i = 0; i < TG3_NVM_VPD_LEN - 2; ) { 12588 for (i = 0; i < TG3_NVM_VPD_LEN - 2; ) {
12589 unsigned int block_end; 12589 unsigned int block_end, rosize;
12590 12590
12591 i = pci_vpd_find_tag(vpd_data, i, TG3_NVM_VPD_LEN, 12591 i = pci_vpd_find_tag(vpd_data, i, TG3_NVM_VPD_LEN,
12592 PCI_VPD_LRDT_RO_DATA); 12592 PCI_VPD_LRDT_RO_DATA);
12593 if (i < 0) 12593 if (i < 0)
12594 break; 12594 break;
12595 12595
12596 block_end = i + PCI_VPD_LRDT_TAG_SIZE + 12596 rosize = pci_vpd_lrdt_size(&vpd_data[i]);
12597 pci_vpd_lrdt_size(&vpd_data[i]); 12597 block_end = i + PCI_VPD_LRDT_TAG_SIZE + rosize;
12598
12599 i += PCI_VPD_LRDT_TAG_SIZE; 12598 i += PCI_VPD_LRDT_TAG_SIZE;
12600 12599
12601 if (block_end > TG3_NVM_VPD_LEN) 12600 if (block_end > TG3_NVM_VPD_LEN)
12602 goto out_not_found; 12601 goto out_not_found;
12603 12602
12604 while (i < (block_end - 2)) { 12603 i = pci_vpd_find_info_keyword(vpd_data, i, rosize,
12605 if (vpd_data[i + 0] == 'P' && 12604 PCI_VPD_RO_KEYWORD_PARTNO);
12606 vpd_data[i + 1] == 'N') { 12605 if (i > 0) {
12607 int partno_len = pci_vpd_info_field_size(&vpd_data[i]); 12606 u8 len = pci_vpd_info_field_size(&vpd_data[i]);
12608 12607
12609 i += PCI_VPD_INFO_FLD_HDR_SIZE; 12608 i += PCI_VPD_INFO_FLD_HDR_SIZE;
12610 if (partno_len > TG3_BPN_SIZE || 12609 if (len > TG3_BPN_SIZE ||
12611 (partno_len + i) > TG3_NVM_VPD_LEN) 12610 (len + i) > TG3_NVM_VPD_LEN)
12612 goto out_not_found; 12611 break;
12613 12612
12614 memcpy(tp->board_part_number, 12613 memcpy(tp->board_part_number, &vpd_data[i], len);
12615 &vpd_data[i], partno_len);
12616 12614
12617 /* Success. */ 12615 return;
12618 return;
12619 }
12620 i += PCI_VPD_INFO_FLD_HDR_SIZE +
12621 pci_vpd_info_field_size(&vpd_data[i]);
12622 } 12616 }
12623 12617
12624 /* Part number not found. */ 12618 /* Part number not found. */
diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c
index 6bc554576f8d..a5a5ca17cfe6 100644
--- a/drivers/pci/vpd.c
+++ b/drivers/pci/vpd.c
@@ -41,3 +41,21 @@ int pci_vpd_find_tag(const u8 *buf, unsigned int off, unsigned int len, u8 rdt)
41 return -ENOENT; 41 return -ENOENT;
42} 42}
43EXPORT_SYMBOL_GPL(pci_vpd_find_tag); 43EXPORT_SYMBOL_GPL(pci_vpd_find_tag);
44
45int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off,
46 unsigned int len, const char *kw)
47{
48 int i;
49
50 for (i = off; i + PCI_VPD_INFO_FLD_HDR_SIZE <= off + len;) {
51 if (buf[i + 0] == kw[0] &&
52 buf[i + 1] == kw[1])
53 return i;
54
55 i += PCI_VPD_INFO_FLD_HDR_SIZE +
56 pci_vpd_info_field_size(&buf[i]);
57 }
58
59 return -ENOENT;
60}
61EXPORT_SYMBOL_GPL(pci_vpd_find_info_keyword);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index cfff32fc6e35..1f4a52131c99 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1375,6 +1375,10 @@ void pci_request_acs(void);
1375 1375
1376#define PCI_VPD_INFO_FLD_HDR_SIZE 3 1376#define PCI_VPD_INFO_FLD_HDR_SIZE 3
1377 1377
1378#define PCI_VPD_RO_KEYWORD_PARTNO "PN"
1379#define PCI_VPD_RO_KEYWORD_MFR_ID "MN"
1380#define PCI_VPD_RO_KEYWORD_VENDOR0 "V0"
1381
1378/** 1382/**
1379 * pci_vpd_lrdt_size - Extracts the Large Resource Data Type length 1383 * pci_vpd_lrdt_size - Extracts the Large Resource Data Type length
1380 * @lrdt: Pointer to the beginning of the Large Resource Data Type tag 1384 * @lrdt: Pointer to the beginning of the Large Resource Data Type tag
@@ -1420,5 +1424,18 @@ static inline u8 pci_vpd_info_field_size(const u8 *info_field)
1420 */ 1424 */
1421int pci_vpd_find_tag(const u8 *buf, unsigned int off, unsigned int len, u8 rdt); 1425int pci_vpd_find_tag(const u8 *buf, unsigned int off, unsigned int len, u8 rdt);
1422 1426
1427/**
1428 * pci_vpd_find_info_keyword - Locates an information field keyword in the VPD
1429 * @buf: Pointer to buffered vpd data
1430 * @off: The offset into the buffer at which to begin the search
1431 * @len: The length of the buffer area, relative to off, in which to search
1432 * @kw: The keyword to search for
1433 *
1434 * Returns the index where the information field keyword was found or
1435 * -ENOENT otherwise.
1436 */
1437int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off,
1438 unsigned int len, const char *kw);
1439
1423#endif /* __KERNEL__ */ 1440#endif /* __KERNEL__ */
1424#endif /* LINUX_PCI_H */ 1441#endif /* LINUX_PCI_H */