diff options
author | David S. Miller <davem@davemloft.net> | 2021-08-23 12:59:19 +0300 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2021-08-23 12:59:19 +0300 |
commit | df6deaf6731519c6efd68ccd0638564e1afc4309 (patch) | |
tree | 50b061ac5c4538caf528d9ad964a35048b24016b /drivers/net/ethernet/chelsio | |
parent | 8d63ee602da381c437c0a4ef7ea882b71d829eb6 (diff) | |
download | linux-df6deaf6731519c6efd68ccd0638564e1afc4309.tar.xz |
Revert "cxgb4: Search VPD with pci_vpd_find_ro_info_keyword()"
This reverts commit 8d63ee602da381c437c0a4ef7ea882b71d829eb6.
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ethernet/chelsio')
-rw-r--r-- | drivers/net/ethernet/chelsio/cxgb4/t4_hw.c | 67 |
1 files changed, 40 insertions, 27 deletions
diff --git a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c index 5e8ac42ac6ab..2aeb2f80fa16 100644 --- a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c +++ b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c @@ -2743,9 +2743,10 @@ int t4_seeprom_wp(struct adapter *adapter, bool enable) */ int t4_get_raw_vpd_params(struct adapter *adapter, struct vpd_params *p) { - unsigned int id_len, pn_len, sn_len, na_len; - int sn, pn, na, addr, ret = 0; + int i, ret = 0, addr; + int sn, pn, na; u8 *vpd, base_val = 0; + unsigned int vpdr_len, kw_offset, id_len; vpd = vmalloc(VPD_LEN); if (!vpd) @@ -2771,48 +2772,60 @@ int t4_get_raw_vpd_params(struct adapter *adapter, struct vpd_params *p) } id_len = pci_vpd_lrdt_size(vpd); + if (id_len > ID_LEN) + id_len = ID_LEN; - ret = pci_vpd_check_csum(vpd, VPD_LEN); - if (ret) { - dev_err(adapter->pdev_dev, "VPD checksum incorrect or missing\n"); + i = pci_vpd_find_tag(vpd, VPD_LEN, PCI_VPD_LRDT_RO_DATA); + if (i < 0) { + dev_err(adapter->pdev_dev, "missing VPD-R section\n"); ret = -EINVAL; goto out; } - ret = pci_vpd_find_ro_info_keyword(vpd, VPD_LEN, - PCI_VPD_RO_KEYWORD_SERIALNO, &sn_len); - if (ret < 0) + 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); + ret = -EINVAL; goto out; - sn = ret; + } - ret = pci_vpd_find_ro_info_keyword(vpd, VPD_LEN, - PCI_VPD_RO_KEYWORD_PARTNO, &pn_len); - if (ret < 0) - goto out; - pn = ret; +#define FIND_VPD_KW(var, name) do { \ + 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"); \ + ret = -EINVAL; \ + goto out; \ + } \ + var += PCI_VPD_INFO_FLD_HDR_SIZE; \ +} while (0) - ret = pci_vpd_find_ro_info_keyword(vpd, VPD_LEN, "NA", &na_len); - if (ret < 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; - na = ret; + } + + FIND_VPD_KW(sn, "SN"); + FIND_VPD_KW(pn, "PN"); + FIND_VPD_KW(na, "NA"); +#undef FIND_VPD_KW - memcpy(p->id, vpd + PCI_VPD_LRDT_TAG_SIZE, min_t(int, id_len, ID_LEN)); + memcpy(p->id, vpd + PCI_VPD_LRDT_TAG_SIZE, id_len); strim(p->id); - memcpy(p->sn, vpd + sn, min_t(int, sn_len, SERNUM_LEN)); + i = pci_vpd_info_field_size(vpd + sn - PCI_VPD_INFO_FLD_HDR_SIZE); + memcpy(p->sn, vpd + sn, min(i, SERNUM_LEN)); strim(p->sn); - memcpy(p->pn, vpd + pn, min_t(int, pn_len, PN_LEN)); + i = pci_vpd_info_field_size(vpd + pn - PCI_VPD_INFO_FLD_HDR_SIZE); + memcpy(p->pn, vpd + pn, min(i, PN_LEN)); strim(p->pn); - memcpy(p->na, vpd + na, min_t(int, na_len, MACADDR_LEN)); + memcpy(p->na, vpd + na, min(i, MACADDR_LEN)); strim((char *)p->na); out: vfree(vpd); - if (ret < 0) { - dev_err(adapter->pdev_dev, "error reading VPD\n"); - return ret; - } - - return 0; + return ret < 0 ? ret : 0; } /** |