From patchwork Sat Feb 27 00:04:40 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Carlson X-Patchwork-Id: 82516 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 o1R05ZYf022193 for ; Sat, 27 Feb 2010 00:05:35 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966631Ab0B0AE5 (ORCPT ); Fri, 26 Feb 2010 19:04:57 -0500 Received: from mms3.broadcom.com ([216.31.210.19]:1952 "EHLO MMS3.broadcom.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966617Ab0B0AEz (ORCPT ); Fri, 26 Feb 2010 19:04:55 -0500 Received: from [10.9.200.131] by MMS3.broadcom.com with ESMTP (Broadcom SMTP Relay (Email Firewall v6.3.2)); Fri, 26 Feb 2010 16:04:48 -0800 X-Server-Uuid: B55A25B1-5D7D-41F8-BC53-C57E7AD3C201 Received: from mail-irva-12.broadcom.com (10.11.16.101) by IRVEXCHHUB01.corp.ad.broadcom.com (10.9.200.131) with Microsoft SMTP Server id 8.2.213.0; Fri, 26 Feb 2010 16:04:48 -0800 Received: from xw6200 (mcarlson.broadcom.com [10.12.148.101]) by mail-irva-12.broadcom.com (Postfix) with ESMTP id 7A65069CAB; Fri, 26 Feb 2010 16:04:47 -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 v3 2/7] pci: Add large and small resource data type code Date: Fri, 26 Feb 2010 16:04:40 -0800 Message-ID: <1267229085-21303-3-git-send-email-mcarlson@broadcom.com> X-Mailer: git-send-email 1.6.4.4 MIME-Version: 1.0 X-WSS-ID: 6796BE2A31G44179601-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]); Sat, 27 Feb 2010 00:05:36 +0000 (UTC) diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c index d466208..7caa98d 100644 --- a/drivers/net/bnx2.c +++ b/drivers/net/bnx2.c @@ -7762,15 +7762,26 @@ bnx2_read_vpd_fw_ver(struct bnx2 *bp) unsigned char val = data[i]; unsigned int block_end; - if (val == 0x82 || val == 0x91) { - i += PCI_VPD_LRDT_TAG_SIZE + - pci_vpd_lrdt_size(&data[i]); + if (val & PCI_VPD_LRDT) { + if (i + PCI_VPD_LRDT_TAG_SIZE > BNX2_VPD_LEN) + break; + + if (val != PCI_VPD_LRDT_RO_DATA) { + i += PCI_VPD_LRDT_TAG_SIZE + + pci_vpd_lrdt_size(&data[i]); + + continue; + } + } else { + if ((val & PCI_VPD_SRDT_TIN_MASK) == PCI_VPD_STIN_END) + break; + + i += PCI_VPD_SRDT_TAG_SIZE + + pci_vpd_srdt_size(&data[i]); + continue; } - if (val != 0x90) - goto vpd_done; - block_end = (i + PCI_VPD_LRDT_TAG_SIZE + pci_vpd_lrdt_size(&data[i])); i += PCI_VPD_LRDT_TAG_SIZE; diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c index d01e133..4c24998 100644 --- a/drivers/net/tg3.c +++ b/drivers/net/tg3.c @@ -12482,15 +12482,26 @@ static void __devinit tg3_read_partno(struct tg3 *tp) unsigned char val = vpd_data[i]; unsigned int block_end; - if (val == 0x82 || val == 0x91) { - i += PCI_VPD_LRDT_TAG_SIZE + - pci_vpd_lrdt_size(&vpd_data[i]); + if (val & PCI_VPD_LRDT) { + if (i + PCI_VPD_LRDT_TAG_SIZE > TG3_NVM_VPD_LEN) + break; + + if (val != PCI_VPD_LRDT_RO_DATA) { + i += PCI_VPD_LRDT_TAG_SIZE + + pci_vpd_lrdt_size(&vpd_data[i]); + + continue; + } + } else { + if ((val & PCI_VPD_SRDT_TIN_MASK) == PCI_VPD_STIN_END) + break; + + i += PCI_VPD_SRDT_TAG_SIZE + + pci_vpd_srdt_size(&vpd_data[i]); + continue; } - if (val != 0x90) - goto out_not_found; - block_end = i + PCI_VPD_LRDT_TAG_SIZE + pci_vpd_lrdt_size(&vpd_data[i]); diff --git a/include/linux/pci.h b/include/linux/pci.h index 038f3c0..d6f2b17 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1339,7 +1339,28 @@ static inline bool pci_is_pcie(struct pci_dev *dev) void pci_request_acs(void); -#define PCI_VPD_LRDT_TAG_SIZE 3 +#define PCI_VPD_LRDT 0x80 /* Large Resource Data Type */ +#define PCI_VPD_LRDT_ID(x) (x | PCI_VPD_LRDT) + +/* Large Resource Data Type Tag Item Names */ +#define PCI_VPD_LTIN_ID_STRING 0x02 /* Identifier String */ +#define PCI_VPD_LTIN_RO_DATA 0x10 /* Read-Only Data */ +#define PCI_VPD_LTIN_RW_DATA 0x11 /* Read-Write Data */ + +#define PCI_VPD_LRDT_ID_STRING PCI_VPD_LRDT_ID(PCI_VPD_LTIN_ID_STRING) +#define PCI_VPD_LRDT_RO_DATA PCI_VPD_LRDT_ID(PCI_VPD_LTIN_RO_DATA) +#define PCI_VPD_LRDT_RW_DATA PCI_VPD_LRDT_ID(PCI_VPD_LTIN_RW_DATA) + +/* Small Resource Data Type Tag Item Names */ +#define PCI_VPD_STIN_END 0x78 /* End */ + +#define PCI_VPD_SRDT_END PCI_VPD_STIN_END + +#define PCI_VPD_SRDT_TIN_MASK 0x78 +#define PCI_VPD_SRDT_LEN_MASK 0x07 + +#define PCI_VPD_LRDT_TAG_SIZE 3 +#define PCI_VPD_SRDT_TAG_SIZE 1 /** * pci_vpd_lrdt_size - Extracts the Large Resource Data Type length @@ -1352,5 +1373,16 @@ static inline u16 pci_vpd_lrdt_size(const u8 *lrdt) return (u16)lrdt[1] + ((u16)lrdt[2] << 8); } +/** + * pci_vpd_srdt_size - Extracts the Small Resource Data Type length + * @lrdt: Pointer to the beginning of the Small Resource Data Type tag + * + * Returns the extracted Small Resource Data Type length. + */ +static inline u8 pci_vpd_srdt_size(const u8 *srdt) +{ + return (*srdt) & PCI_VPD_SRDT_LEN_MASK; +} + #endif /* __KERNEL__ */ #endif /* LINUX_PCI_H */