netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dimitris Michailidis <dm@chelsio.com>
To: netdev@vger.kernel.org
Subject: [PATCH 11/12] cxgb4: extend VPD parsing
Date: Tue, 14 Dec 2010 23:36:54 -0800	[thread overview]
Message-ID: <1292398615-26527-12-git-send-email-dm@chelsio.com> (raw)
In-Reply-To: <1292398615-26527-11-git-send-email-dm@chelsio.com>

Current code parses the VPD RO section for keywords but makes static
assumptions about the location of the section.  Remove them and parse
the VPD to find it.

Signed-off-by: Dimitris Michailidis <dm@chelsio.com>
---
 drivers/net/cxgb4/t4_hw.c |   41 +++++++++++++++++++++--------------------
 1 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/drivers/net/cxgb4/t4_hw.c b/drivers/net/cxgb4/t4_hw.c
index c7fb549..b9fd8a6 100644
--- a/drivers/net/cxgb4/t4_hw.c
+++ b/drivers/net/cxgb4/t4_hw.c
@@ -330,18 +330,6 @@ int t4_edc_read(struct adapter *adap, int idx, u32 addr, __be32 *data, u64 *ecc)
 	return 0;
 }
 
-/*
- * Partial EEPROM Vital Product Data structure.  Includes only the ID and
- * VPD-R header.
- */
-struct t4_vpd_hdr {
-	u8  id_tag;
-	u8  id_len[2];
-	u8  id_data[ID_LEN];
-	u8  vpdr_tag;
-	u8  vpdr_len[2];
-};
-
 #define EEPROM_STAT_ADDR   0x7bfc
 #define VPD_BASE           0
 #define VPD_LEN            512
@@ -372,23 +360,36 @@ static int get_vpd_params(struct adapter *adapter, struct vpd_params *p)
 	int i, ret;
 	int ec, sn;
 	u8 vpd[VPD_LEN], csum;
-	unsigned int vpdr_len;
-	const struct t4_vpd_hdr *v;
+	unsigned int vpdr_len, kw_offset, id_len;
 
 	ret = pci_read_vpd(adapter->pdev, VPD_BASE, sizeof(vpd), vpd);
 	if (ret < 0)
 		return ret;
 
-	v = (const struct t4_vpd_hdr *)vpd;
-	vpdr_len = pci_vpd_lrdt_size(&v->vpdr_tag);
-	if (vpdr_len + sizeof(struct t4_vpd_hdr) > VPD_LEN) {
+	if (vpd[0] != PCI_VPD_LRDT_ID_STRING) {
+		dev_err(adapter->pdev_dev, "missing VPD ID string\n");
+		return -EINVAL;
+	}
+
+	id_len = pci_vpd_lrdt_size(vpd);
+	if (id_len > ID_LEN)
+		id_len = ID_LEN;
+
+	i = pci_vpd_find_tag(vpd, 0, VPD_LEN, PCI_VPD_LRDT_RO_DATA);
+	if (i < 0) {
+		dev_err(adapter->pdev_dev, "missing VPD-R section\n");
+		return -EINVAL;
+	}
+
+	vpdr_len = pci_vpd_lrdt_size(&vpd[i]);
+	kw_offset = i + PCI_VPD_LRDT_TAG_SIZE;
+	if (vpdr_len + kw_offset > VPD_LEN) {
 		dev_err(adapter->pdev_dev, "bad VPD-R length %u\n", vpdr_len);
 		return -EINVAL;
 	}
 
 #define FIND_VPD_KW(var, name) do { \
-	var = pci_vpd_find_info_keyword(&v->id_tag, sizeof(struct t4_vpd_hdr), \
-					vpdr_len, name); \
+	var = pci_vpd_find_info_keyword(vpd, kw_offset, vpdr_len, name); \
 	if (var < 0) { \
 		dev_err(adapter->pdev_dev, "missing VPD keyword " name "\n"); \
 		return -EINVAL; \
@@ -410,7 +411,7 @@ static int get_vpd_params(struct adapter *adapter, struct vpd_params *p)
 	FIND_VPD_KW(sn, "SN");
 #undef FIND_VPD_KW
 
-	memcpy(p->id, v->id_data, ID_LEN);
+	memcpy(p->id, vpd + PCI_VPD_LRDT_TAG_SIZE, id_len);
 	strim(p->id);
 	memcpy(p->ec, vpd + ec, EC_LEN);
 	strim(p->ec);
-- 
1.5.4


  reply	other threads:[~2010-12-15  7:45 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-15  7:36 [PATCH 00/12 net-next] cxgb4 update v2 Dimitris Michailidis
2010-12-15  7:36 ` [PATCH 01/12] cxgb4: enable PCIe relaxed ordering Dimitris Michailidis
2010-12-15  7:36   ` [PATCH 02/12] cxgb4: do not read the clock frequency from VPD Dimitris Michailidis
2010-12-15  7:36     ` [PATCH 03/12] cxgb4: set the number of queues before device registration Dimitris Michailidis
2010-12-15  7:36       ` [PATCH 04/12] cxgb4: distinguish between 1-lane KR/KX and 4-lane KR/KX/KX4 ports Dimitris Michailidis
2010-12-15  7:36         ` [PATCH 05/12] cxgb4: print port information after registering each netdev Dimitris Michailidis
2010-12-15  7:36           ` [PATCH 06/12] cxgb4: allocate more space for MSI-X interrupt names Dimitris Michailidis
2010-12-15  7:36             ` [PATCH 07/12] cxgb4: correct formatting of " Dimitris Michailidis
2010-12-15  7:36               ` [PATCH 08/12] cxgb4: remove the name field from the adapter structure Dimitris Michailidis
2010-12-15  7:36                 ` [PATCH 09/12] cxgb4: remove a bitmap Dimitris Michailidis
2010-12-15  7:36                   ` [PATCH 10/12] cxgb4: add const to static arrays Dimitris Michailidis
2010-12-15  7:36                     ` Dimitris Michailidis [this message]
2010-12-15  7:36                       ` [PATCH 12/12] cxgb4: NUMA-aware Tx queue allocations Dimitris Michailidis
2010-12-16 20:10 ` [PATCH 00/12 net-next] cxgb4 update v2 David Miller
  -- strict thread matches above, loose matches on Subject: below --
2010-12-14 20:18 [PATCH 00/12 net-next] cxgb4 update Dimitris Michailidis
2010-12-14 20:18 ` [PATCH 01/12] cxgb4: enable PCIe relaxed ordering Dimitris Michailidis
2010-12-14 20:18   ` [PATCH 02/12] cxgb4: do not read the clock frequency from VPD Dimitris Michailidis
2010-12-14 20:18     ` [PATCH 03/12] cxgb4: set the number of queues before device registration Dimitris Michailidis
2010-12-14 20:18       ` [PATCH 04/12] cxgb4: distinguish between 1-lane KR/KX and 4-lane KR/KX/KX4 ports Dimitris Michailidis
2010-12-14 20:18         ` [PATCH 05/12] cxgb4: print port information after registering each netdev Dimitris Michailidis
2010-12-14 20:18           ` [PATCH 06/12] cxgb4: allocate more space for MSI-X interrupt names Dimitris Michailidis
2010-12-14 20:18             ` [PATCH 07/12] cxgb4: correct formatting of " Dimitris Michailidis
2010-12-14 20:18               ` [PATCH 08/12] cxgb4: remove the name field from the adapter structure Dimitris Michailidis
2010-12-14 20:18                 ` [PATCH 09/12] cxgb4: remove a bitmap Dimitris Michailidis
2010-12-14 20:18                   ` [PATCH 10/12] cxgb4: add const to static arrays Dimitris Michailidis
2010-12-14 20:18                     ` [PATCH 11/12] cxgb4: extend VPD parsing Dimitris Michailidis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1292398615-26527-12-git-send-email-dm@chelsio.com \
    --to=dm@chelsio.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).