aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Carlson <mcarlson@broadcom.com>2010-02-26 09:04:42 -0500
committerDavid S. Miller <davem@davemloft.net>2010-02-28 03:43:32 -0500
commite1d5bdabb94da89bdb3c3f2ee105cf61fca88ec8 (patch)
treebc5b86b19bc49ace2df10ed9e7ba7d1ca2b74d33
parentb55ac1b22690d2e5b02a61cf6d69c2d66969c79d (diff)
pci: Add VPD information field helper functions
This patch adds a preprocessor constant to describe the PCI VPD information field header size and an inline function to extract the size of the information field itself. Signed-off-by: Matt Carlson <mcarlson@broadcom.com> Signed-off-by: Michael Chan <mchan@broadcom.com> Acked-by: Jesse Barnes <jbarnes@virtuousgeek.org> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/bnx2.c11
-rw-r--r--drivers/net/tg3.c7
-rw-r--r--include/linux/pci.h13
3 files changed, 23 insertions, 8 deletions
diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index fd43feb5a350..b808707f83ff 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -7784,14 +7784,15 @@ bnx2_read_vpd_fw_ver(struct bnx2 *bp)
7784 goto vpd_done; 7784 goto vpd_done;
7785 7785
7786 while (i < (block_end - 2)) { 7786 while (i < (block_end - 2)) {
7787 int len = data[i + 2]; 7787 int len = pci_vpd_info_field_size(&data[i]);
7788 7788
7789 if (i + 3 + len > block_end) 7789 if (i + PCI_VPD_INFO_FLD_HDR_SIZE + len > block_end)
7790 goto vpd_done; 7790 goto vpd_done;
7791 7791
7792 if (data[i] == 'M' && data[i + 1] == 'N') { 7792 if (data[i] == 'M' && data[i + 1] == 'N') {
7793 if (len != 4 || 7793 if (len != 4 ||
7794 memcmp(&data[i + 3], "1028", 4)) 7794 memcmp(&data[i + PCI_VPD_INFO_FLD_HDR_SIZE],
7795 "1028", 4))
7795 goto vpd_done; 7796 goto vpd_done;
7796 mn_match = true; 7797 mn_match = true;
7797 7798
@@ -7800,9 +7801,9 @@ bnx2_read_vpd_fw_ver(struct bnx2 *bp)
7800 goto vpd_done; 7801 goto vpd_done;
7801 7802
7802 v0_len = len; 7803 v0_len = len;
7803 v0_str = &data[i + 3]; 7804 v0_str = &data[i + PCI_VPD_INFO_FLD_HDR_SIZE];
7804 } 7805 }
7805 i += 3 + len; 7806 i += PCI_VPD_INFO_FLD_HDR_SIZE + len;
7806 7807
7807 if (mn_match && v0_str) { 7808 if (mn_match && v0_str) {
7808 memcpy(bp->fw_version, v0_str, v0_len); 7809 memcpy(bp->fw_version, v0_str, v0_len);
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index 76ad141ab448..f59f36910e98 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -12604,9 +12604,9 @@ static void __devinit tg3_read_partno(struct tg3 *tp)
12604 while (i < (block_end - 2)) { 12604 while (i < (block_end - 2)) {
12605 if (vpd_data[i + 0] == 'P' && 12605 if (vpd_data[i + 0] == 'P' &&
12606 vpd_data[i + 1] == 'N') { 12606 vpd_data[i + 1] == 'N') {
12607 int partno_len = vpd_data[i + 2]; 12607 int partno_len = pci_vpd_info_field_size(&vpd_data[i]);
12608 12608
12609 i += 3; 12609 i += PCI_VPD_INFO_FLD_HDR_SIZE;
12610 if (partno_len > TG3_BPN_SIZE || 12610 if (partno_len > TG3_BPN_SIZE ||
12611 (partno_len + i) > TG3_NVM_VPD_LEN) 12611 (partno_len + i) > TG3_NVM_VPD_LEN)
12612 goto out_not_found; 12612 goto out_not_found;
@@ -12617,7 +12617,8 @@ static void __devinit tg3_read_partno(struct tg3 *tp)
12617 /* Success. */ 12617 /* Success. */
12618 return; 12618 return;
12619 } 12619 }
12620 i += 3 + vpd_data[i + 2]; 12620 i += PCI_VPD_INFO_FLD_HDR_SIZE +
12621 pci_vpd_info_field_size(&vpd_data[i]);
12621 } 12622 }
12622 12623
12623 /* Part number not found. */ 12624 /* Part number not found. */
diff --git a/include/linux/pci.h b/include/linux/pci.h
index e30ceea7345b..cfff32fc6e35 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1373,6 +1373,8 @@ void pci_request_acs(void);
1373#define PCI_VPD_LRDT_TAG_SIZE 3 1373#define PCI_VPD_LRDT_TAG_SIZE 3
1374#define PCI_VPD_SRDT_TAG_SIZE 1 1374#define PCI_VPD_SRDT_TAG_SIZE 1
1375 1375
1376#define PCI_VPD_INFO_FLD_HDR_SIZE 3
1377
1376/** 1378/**
1377 * pci_vpd_lrdt_size - Extracts the Large Resource Data Type length 1379 * pci_vpd_lrdt_size - Extracts the Large Resource Data Type length
1378 * @lrdt: Pointer to the beginning of the Large Resource Data Type tag 1380 * @lrdt: Pointer to the beginning of the Large Resource Data Type tag
@@ -1396,6 +1398,17 @@ static inline u8 pci_vpd_srdt_size(const u8 *srdt)
1396} 1398}
1397 1399
1398/** 1400/**
1401 * pci_vpd_info_field_size - Extracts the information field length
1402 * @lrdt: Pointer to the beginning of an information field header
1403 *
1404 * Returns the extracted information field length.
1405 */
1406static inline u8 pci_vpd_info_field_size(const u8 *info_field)
1407{
1408 return info_field[2];
1409}
1410
1411/**
1399 * pci_vpd_find_tag - Locates the Resource Data Type tag provided 1412 * pci_vpd_find_tag - Locates the Resource Data Type tag provided
1400 * @buf: Pointer to buffered vpd data 1413 * @buf: Pointer to buffered vpd data
1401 * @off: The offset into the buffer at which to begin the search 1414 * @off: The offset into the buffer at which to begin the search