From patchwork Fri Feb 26 20:40:32 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Carlson X-Patchwork-Id: 82453 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o1QKfcE5027821 for ; Fri, 26 Feb 2010 20:41:38 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753412Ab0BZUlh (ORCPT ); Fri, 26 Feb 2010 15:41:37 -0500 Received: from mms1.broadcom.com ([216.31.210.17]:3223 "EHLO mms1.broadcom.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751094Ab0BZUlg (ORCPT ); Fri, 26 Feb 2010 15:41:36 -0500 Received: from [10.9.200.133] by mms1.broadcom.com with ESMTP (Broadcom SMTP Relay (Email Firewall v6.3.2)); Fri, 26 Feb 2010 12:41:26 -0800 X-Server-Uuid: 02CED230-5797-4B57-9875-D5D2FEE4708A Received: from mail-irva-12.broadcom.com (10.11.16.101) by IRVEXCHHUB02.corp.ad.broadcom.com (10.9.200.133) with Microsoft SMTP Server id 8.2.213.0; Fri, 26 Feb 2010 12:42:50 -0800 Received: from xw6200 (mcarlson.broadcom.com [10.12.148.101]) by mail-irva-12.broadcom.com (Postfix) with ESMTP id E5F4969CA9; Fri, 26 Feb 2010 12:41:25 -0800 (PST) From: "Matt Carlson" To: jbarnes@virtuousgeek.org cc: linux-pci@vger.kernel.org, netdev@vger.kernel.org, andy@greyhouse.net, mcarlson@broadcom.com, "Michael Chan" Subject: [PATCH v2 1/7] pci: Add PCI LRDT tag size and section size Date: Fri, 26 Feb 2010 12:40:32 -0800 Message-ID: <1267216838-19459-2-git-send-email-mcarlson@broadcom.com> X-Mailer: git-send-email 1.6.4.4 MIME-Version: 1.0 X-WSS-ID: 6796EE7C20S42489774-01-01 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Fri, 26 Feb 2010 20:41:38 +0000 (UTC) diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c index 65df1de..d466208 100644 --- a/drivers/net/bnx2.c +++ b/drivers/net/bnx2.c @@ -7763,15 +7763,17 @@ bnx2_read_vpd_fw_ver(struct bnx2 *bp) unsigned int block_end; if (val == 0x82 || val == 0x91) { - i = (i + 3 + (data[i + 1] + (data[i + 2] << 8))); + i += PCI_VPD_LRDT_TAG_SIZE + + pci_vpd_lrdt_size(&data[i]); continue; } if (val != 0x90) goto vpd_done; - block_end = (i + 3 + (data[i + 1] + (data[i + 2] << 8))); - i += 3; + block_end = (i + PCI_VPD_LRDT_TAG_SIZE + + pci_vpd_lrdt_size(&data[i])); + i += PCI_VPD_LRDT_TAG_SIZE; if (block_end > BNX2_VPD_LEN) goto vpd_done; diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c index 7f82b02..d01e133 100644 --- a/drivers/net/tg3.c +++ b/drivers/net/tg3.c @@ -12483,19 +12483,18 @@ static void __devinit tg3_read_partno(struct tg3 *tp) unsigned int block_end; if (val == 0x82 || val == 0x91) { - i = (i + 3 + - (vpd_data[i + 1] + - (vpd_data[i + 2] << 8))); + i += PCI_VPD_LRDT_TAG_SIZE + + pci_vpd_lrdt_size(&vpd_data[i]); continue; } if (val != 0x90) goto out_not_found; - block_end = (i + 3 + - (vpd_data[i + 1] + - (vpd_data[i + 2] << 8))); - i += 3; + block_end = i + PCI_VPD_LRDT_TAG_SIZE + + pci_vpd_lrdt_size(&vpd_data[i]); + + i += PCI_VPD_LRDT_TAG_SIZE; if (block_end > TG3_NVM_VPD_LEN) goto out_not_found; diff --git a/include/linux/pci.h b/include/linux/pci.h index c1968f4..b46669b 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1338,5 +1338,19 @@ static inline bool pci_is_pcie(struct pci_dev *dev) void pci_request_acs(void); + +#define PCI_VPD_LRDT_TAG_SIZE 3 + +/** + * pci_vpd_lrdt_size - Extracts the Large Resource Data Type length + * @lrdt: Pointer to the beginning of the Large Resource Data Type tag + * + * Returns the extracted Large Resource Data Type length. + */ +static inline u16 pci_vpd_lrdt_size(u8 *lrdt) +{ + return (u16)lrdt[1] + ((u16)lrdt[2] << 8); +} + #endif /* __KERNEL__ */ #endif /* LINUX_PCI_H */