Commit 8d63ee60 authored by Heiner Kallweit's avatar Heiner Kallweit Committed by David S. Miller

cxgb4: Search VPD with pci_vpd_find_ro_info_keyword()

Use pci_vpd_find_ro_info_keyword() to search for keywords in VPD to
simplify the code.
Signed-off-by: default avatarHeiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 3a93bede
...@@ -2743,10 +2743,9 @@ int t4_seeprom_wp(struct adapter *adapter, bool enable) ...@@ -2743,10 +2743,9 @@ int t4_seeprom_wp(struct adapter *adapter, bool enable)
*/ */
int t4_get_raw_vpd_params(struct adapter *adapter, struct vpd_params *p) int t4_get_raw_vpd_params(struct adapter *adapter, struct vpd_params *p)
{ {
int i, ret = 0, addr; unsigned int id_len, pn_len, sn_len, na_len;
int sn, pn, na; int sn, pn, na, addr, ret = 0;
u8 *vpd, base_val = 0; u8 *vpd, base_val = 0;
unsigned int vpdr_len, kw_offset, id_len;
vpd = vmalloc(VPD_LEN); vpd = vmalloc(VPD_LEN);
if (!vpd) if (!vpd)
...@@ -2772,60 +2771,48 @@ int t4_get_raw_vpd_params(struct adapter *adapter, struct vpd_params *p) ...@@ -2772,60 +2771,48 @@ int t4_get_raw_vpd_params(struct adapter *adapter, struct vpd_params *p)
} }
id_len = pci_vpd_lrdt_size(vpd); id_len = pci_vpd_lrdt_size(vpd);
if (id_len > ID_LEN)
id_len = ID_LEN;
i = pci_vpd_find_tag(vpd, VPD_LEN, PCI_VPD_LRDT_RO_DATA); ret = pci_vpd_check_csum(vpd, VPD_LEN);
if (i < 0) { if (ret) {
dev_err(adapter->pdev_dev, "missing VPD-R section\n"); dev_err(adapter->pdev_dev, "VPD checksum incorrect or missing\n");
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
vpdr_len = pci_vpd_lrdt_size(&vpd[i]); ret = pci_vpd_find_ro_info_keyword(vpd, VPD_LEN,
kw_offset = i + PCI_VPD_LRDT_TAG_SIZE; PCI_VPD_RO_KEYWORD_SERIALNO, &sn_len);
if (vpdr_len + kw_offset > VPD_LEN) { if (ret < 0)
dev_err(adapter->pdev_dev, "bad VPD-R length %u\n", vpdr_len);
ret = -EINVAL;
goto out; goto out;
} sn = ret;
#define FIND_VPD_KW(var, name) do { \ ret = pci_vpd_find_ro_info_keyword(vpd, VPD_LEN,
var = pci_vpd_find_info_keyword(vpd, kw_offset, vpdr_len, name); \ PCI_VPD_RO_KEYWORD_PARTNO, &pn_len);
if (var < 0) { \ if (ret < 0)
dev_err(adapter->pdev_dev, "missing VPD keyword " name "\n"); \
ret = -EINVAL; \
goto out; \
} \
var += PCI_VPD_INFO_FLD_HDR_SIZE; \
} while (0)
ret = pci_vpd_check_csum(vpd, VPD_LEN);
if (ret) {
dev_err(adapter->pdev_dev, "VPD checksum incorrect or missing\n");
ret = -EINVAL;
goto out; goto out;
} pn = ret;
FIND_VPD_KW(sn, "SN"); ret = pci_vpd_find_ro_info_keyword(vpd, VPD_LEN, "NA", &na_len);
FIND_VPD_KW(pn, "PN"); if (ret < 0)
FIND_VPD_KW(na, "NA"); goto out;
#undef FIND_VPD_KW na = ret;
memcpy(p->id, vpd + PCI_VPD_LRDT_TAG_SIZE, id_len); memcpy(p->id, vpd + PCI_VPD_LRDT_TAG_SIZE, min_t(int, id_len, ID_LEN));
strim(p->id); strim(p->id);
i = pci_vpd_info_field_size(vpd + sn - PCI_VPD_INFO_FLD_HDR_SIZE); memcpy(p->sn, vpd + sn, min_t(int, sn_len, SERNUM_LEN));
memcpy(p->sn, vpd + sn, min(i, SERNUM_LEN));
strim(p->sn); strim(p->sn);
i = pci_vpd_info_field_size(vpd + pn - PCI_VPD_INFO_FLD_HDR_SIZE); memcpy(p->pn, vpd + pn, min_t(int, pn_len, PN_LEN));
memcpy(p->pn, vpd + pn, min(i, PN_LEN));
strim(p->pn); strim(p->pn);
memcpy(p->na, vpd + na, min(i, MACADDR_LEN)); memcpy(p->na, vpd + na, min_t(int, na_len, MACADDR_LEN));
strim((char *)p->na); strim((char *)p->na);
out: out:
vfree(vpd); vfree(vpd);
return ret < 0 ? ret : 0; if (ret < 0) {
dev_err(adapter->pdev_dev, "error reading VPD\n");
return ret;
}
return 0;
} }
/** /**
......
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