Commit 4067a854 authored by Matt Carlson's avatar Matt Carlson Committed by David S. Miller

pci: Add helper to search for VPD keywords

This patch adds the pci_vpd_find_info_keyword() helper function to
find information field keywords within read-only and read-write large
resource data type sections.
Signed-off-by: default avatarMatt Carlson <mcarlson@broadcom.com>
Signed-off-by: default avatarMichael Chan <mchan@broadcom.com>
Acked-by: default avatarJesse Barnes <jbarnes@virtuousgeek.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e1d5bdab
...@@ -7769,48 +7769,54 @@ bnx2_read_vpd_fw_ver(struct bnx2 *bp) ...@@ -7769,48 +7769,54 @@ bnx2_read_vpd_fw_ver(struct bnx2 *bp)
} }
for (i = 0; i <= BNX2_VPD_LEN - 3; ) { for (i = 0; i <= BNX2_VPD_LEN - 3; ) {
unsigned int block_end; int j;
unsigned int block_end, rosize;
i = pci_vpd_find_tag(data, i, BNX2_VPD_LEN, i = pci_vpd_find_tag(data, i, BNX2_VPD_LEN,
PCI_VPD_LRDT_RO_DATA); PCI_VPD_LRDT_RO_DATA);
if (i < 0) if (i < 0)
break; break;
block_end = (i + PCI_VPD_LRDT_TAG_SIZE + rosize = pci_vpd_lrdt_size(&data[i]);
pci_vpd_lrdt_size(&data[i])); block_end = i + PCI_VPD_LRDT_TAG_SIZE + rosize;
i += PCI_VPD_LRDT_TAG_SIZE; i += PCI_VPD_LRDT_TAG_SIZE;
if (block_end > BNX2_VPD_LEN) if (block_end > BNX2_VPD_LEN)
goto vpd_done; goto vpd_done;
while (i < (block_end - 2)) { j = pci_vpd_find_info_keyword(data, i, rosize,
int len = pci_vpd_info_field_size(&data[i]); PCI_VPD_RO_KEYWORD_MFR_ID);
if (j > 0) {
if (i + PCI_VPD_INFO_FLD_HDR_SIZE + len > block_end) int len = pci_vpd_info_field_size(&data[j]);
goto vpd_done;
if (data[i] == 'M' && data[i + 1] == 'N') { if (j + PCI_VPD_INFO_FLD_HDR_SIZE + len > block_end ||
if (len != 4 || len != 4 ||
memcmp(&data[i + PCI_VPD_INFO_FLD_HDR_SIZE], memcmp(&data[j + PCI_VPD_INFO_FLD_HDR_SIZE],
"1028", 4)) "1028", 4))
goto vpd_done; goto vpd_done;
mn_match = true; mn_match = true;
}
j = pci_vpd_find_info_keyword(data, i, rosize,
PCI_VPD_RO_KEYWORD_VENDOR0);
if (j > 0) {
int len = pci_vpd_info_field_size(&data[j]);
} else if (data[i] == 'V' && data[i + 1] == '0') { j += PCI_VPD_INFO_FLD_HDR_SIZE;
if (len > BNX2_MAX_VER_SLEN) if (j + len > block_end || len > BNX2_MAX_VER_SLEN)
goto vpd_done; goto vpd_done;
v0_len = len; v0_len = len;
v0_str = &data[i + PCI_VPD_INFO_FLD_HDR_SIZE]; v0_str = &data[j];
} }
i += PCI_VPD_INFO_FLD_HDR_SIZE + len;
if (mn_match && v0_str) { if (mn_match && v0_str) {
memcpy(bp->fw_version, v0_str, v0_len); memcpy(bp->fw_version, v0_str, v0_len);
bp->fw_version[v0_len] = ' '; bp->fw_version[v0_len] = ' ';
goto vpd_done; goto vpd_done;
} }
}
goto vpd_done; goto vpd_done;
} }
......
...@@ -12586,40 +12586,34 @@ static void __devinit tg3_read_partno(struct tg3 *tp) ...@@ -12586,40 +12586,34 @@ static void __devinit tg3_read_partno(struct tg3 *tp)
/* Now parse and find the part number. */ /* Now parse and find the part number. */
for (i = 0; i < TG3_NVM_VPD_LEN - 2; ) { for (i = 0; i < TG3_NVM_VPD_LEN - 2; ) {
unsigned int block_end; unsigned int block_end, rosize;
i = pci_vpd_find_tag(vpd_data, i, TG3_NVM_VPD_LEN, i = pci_vpd_find_tag(vpd_data, i, TG3_NVM_VPD_LEN,
PCI_VPD_LRDT_RO_DATA); PCI_VPD_LRDT_RO_DATA);
if (i < 0) if (i < 0)
break; break;
block_end = i + PCI_VPD_LRDT_TAG_SIZE + rosize = pci_vpd_lrdt_size(&vpd_data[i]);
pci_vpd_lrdt_size(&vpd_data[i]); block_end = i + PCI_VPD_LRDT_TAG_SIZE + rosize;
i += PCI_VPD_LRDT_TAG_SIZE; i += PCI_VPD_LRDT_TAG_SIZE;
if (block_end > TG3_NVM_VPD_LEN) if (block_end > TG3_NVM_VPD_LEN)
goto out_not_found; goto out_not_found;
while (i < (block_end - 2)) { i = pci_vpd_find_info_keyword(vpd_data, i, rosize,
if (vpd_data[i + 0] == 'P' && PCI_VPD_RO_KEYWORD_PARTNO);
vpd_data[i + 1] == 'N') { if (i > 0) {
int partno_len = pci_vpd_info_field_size(&vpd_data[i]); u8 len = pci_vpd_info_field_size(&vpd_data[i]);
i += PCI_VPD_INFO_FLD_HDR_SIZE; i += PCI_VPD_INFO_FLD_HDR_SIZE;
if (partno_len > TG3_BPN_SIZE || if (len > TG3_BPN_SIZE ||
(partno_len + i) > TG3_NVM_VPD_LEN) (len + i) > TG3_NVM_VPD_LEN)
goto out_not_found; break;
memcpy(tp->board_part_number, memcpy(tp->board_part_number, &vpd_data[i], len);
&vpd_data[i], partno_len);
/* Success. */
return; return;
} }
i += PCI_VPD_INFO_FLD_HDR_SIZE +
pci_vpd_info_field_size(&vpd_data[i]);
}
/* Part number not found. */ /* Part number not found. */
goto out_not_found; goto out_not_found;
......
...@@ -41,3 +41,21 @@ int pci_vpd_find_tag(const u8 *buf, unsigned int off, unsigned int len, u8 rdt) ...@@ -41,3 +41,21 @@ int pci_vpd_find_tag(const u8 *buf, unsigned int off, unsigned int len, u8 rdt)
return -ENOENT; return -ENOENT;
} }
EXPORT_SYMBOL_GPL(pci_vpd_find_tag); EXPORT_SYMBOL_GPL(pci_vpd_find_tag);
int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off,
unsigned int len, const char *kw)
{
int i;
for (i = off; i + PCI_VPD_INFO_FLD_HDR_SIZE <= off + len;) {
if (buf[i + 0] == kw[0] &&
buf[i + 1] == kw[1])
return i;
i += PCI_VPD_INFO_FLD_HDR_SIZE +
pci_vpd_info_field_size(&buf[i]);
}
return -ENOENT;
}
EXPORT_SYMBOL_GPL(pci_vpd_find_info_keyword);
...@@ -1375,6 +1375,10 @@ void pci_request_acs(void); ...@@ -1375,6 +1375,10 @@ void pci_request_acs(void);
#define PCI_VPD_INFO_FLD_HDR_SIZE 3 #define PCI_VPD_INFO_FLD_HDR_SIZE 3
#define PCI_VPD_RO_KEYWORD_PARTNO "PN"
#define PCI_VPD_RO_KEYWORD_MFR_ID "MN"
#define PCI_VPD_RO_KEYWORD_VENDOR0 "V0"
/** /**
* pci_vpd_lrdt_size - Extracts the Large Resource Data Type length * pci_vpd_lrdt_size - Extracts the Large Resource Data Type length
* @lrdt: Pointer to the beginning of the Large Resource Data Type tag * @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,5 +1424,18 @@ static inline u8 pci_vpd_info_field_size(const u8 *info_field)
*/ */
int pci_vpd_find_tag(const u8 *buf, unsigned int off, unsigned int len, u8 rdt); int pci_vpd_find_tag(const u8 *buf, unsigned int off, unsigned int len, u8 rdt);
/**
* pci_vpd_find_info_keyword - Locates an information field keyword in the VPD
* @buf: Pointer to buffered vpd data
* @off: The offset into the buffer at which to begin the search
* @len: The length of the buffer area, relative to off, in which to search
* @kw: The keyword to search for
*
* Returns the index where the information field keyword was found or
* -ENOENT otherwise.
*/
int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off,
unsigned int len, const char *kw);
#endif /* __KERNEL__ */ #endif /* __KERNEL__ */
#endif /* LINUX_PCI_H */ #endif /* LINUX_PCI_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment