From: Bjorn Helgaas <helgaas@kernel.org>
To: Heiner Kallweit <hkallweit1@gmail.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
Raju Rangoju <rajur@chelsio.com>,
Jakub Kicinski <kuba@kernel.org>,
David Miller <davem@davemloft.net>,
"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [PATCH 11/12] cxgb4: Search VPD with pci_vpd_find_ro_info_keyword()
Date: Tue, 24 Aug 2021 12:11:42 -0500 [thread overview]
Message-ID: <20210824171142.GA3478603@bjorn-Precision-5520> (raw)
In-Reply-To: <db576a3e-e877-b37b-98ed-cfc03d225ab3@gmail.com>
On Sun, Aug 22, 2021 at 03:59:21PM +0200, Heiner Kallweit wrote:
> Use pci_vpd_find_ro_info_keyword() to search for keywords in VPD to
> simplify the code.
>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
> drivers/net/ethernet/chelsio/cxgb4/t4_hw.c | 67 +++++++++-------------
> 1 file changed, 27 insertions(+), 40 deletions(-)
>
> diff --git a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
> index 2aeb2f80f..5e8ac42ac 100644
> --- a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
> +++ b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
> @@ -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 i, ret = 0, addr;
> - int sn, pn, na;
> + unsigned int id_len, pn_len, sn_len, na_len;
> + int sn, pn, na, addr, ret = 0;
> u8 *vpd, base_val = 0;
> - unsigned int vpdr_len, kw_offset, id_len;
>
> vpd = vmalloc(VPD_LEN);
> if (!vpd)
> @@ -2772,60 +2771,48 @@ 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;
>
> - 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 = pci_vpd_check_csum(vpd, VPD_LEN);
> + if (ret) {
> + dev_err(adapter->pdev_dev, "VPD checksum incorrect or missing\n");
> ret = -EINVAL;
> goto out;
> }
>
> - 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;
> + ret = pci_vpd_find_ro_info_keyword(vpd, VPD_LEN,
> + PCI_VPD_RO_KEYWORD_SERIALNO, &sn_len);
> + if (ret < 0)
> goto out;
> - }
> + sn = 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"); \
Just for the record, I guess this patch gives up these error messages
that mention the specific keyword that's missing? Not really an issue
for *me*, since the people generating the VPD content should be able to
easily validate this and figure out any errors. Just pointing it out
in case the cxgb4 folks are attached to the messages.
> - 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;
> + ret = pci_vpd_find_ro_info_keyword(vpd, VPD_LEN,
> + PCI_VPD_RO_KEYWORD_PARTNO, &pn_len);
> + if (ret < 0)
> goto out;
> - }
> + pn = ret;
>
> - FIND_VPD_KW(sn, "SN");
> - FIND_VPD_KW(pn, "PN");
> - FIND_VPD_KW(na, "NA");
> -#undef FIND_VPD_KW
> + ret = pci_vpd_find_ro_info_keyword(vpd, VPD_LEN, "NA", &na_len);
> + if (ret < 0)
> + goto out;
> + 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);
> - i = pci_vpd_info_field_size(vpd + sn - PCI_VPD_INFO_FLD_HDR_SIZE);
> - memcpy(p->sn, vpd + sn, min(i, SERNUM_LEN));
> + memcpy(p->sn, vpd + sn, min_t(int, sn_len, SERNUM_LEN));
> strim(p->sn);
> - i = pci_vpd_info_field_size(vpd + pn - PCI_VPD_INFO_FLD_HDR_SIZE);
> - memcpy(p->pn, vpd + pn, min(i, PN_LEN));
> + memcpy(p->pn, vpd + pn, min_t(int, pn_len, PN_LEN));
> 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);
>
> out:
> vfree(vpd);
> - return ret < 0 ? ret : 0;
> + if (ret < 0) {
> + dev_err(adapter->pdev_dev, "error reading VPD\n");
> + return ret;
> + }
> +
> + return 0;
> }
>
> /**
> --
> 2.33.0
>
>
next prev parent reply other threads:[~2021-08-24 17:40 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-22 13:46 [PATCH 00/12] PCI/VPD: Convert more users to the new VPD API functions Heiner Kallweit
2021-08-22 13:48 ` [PATCH 01/12] sfc: falcon: Read VPD with pci_vpd_alloc() Heiner Kallweit
2021-08-22 16:25 ` kernel test robot
2021-08-22 13:49 ` [PATCH 02/12] sfc: falcon: Search VPD with pci_vpd_find_ro_info_keyword() Heiner Kallweit
2021-08-22 13:50 ` [PATCH 03/12] bnx2: " Heiner Kallweit
2021-08-22 13:52 ` [PATCH 04/12] bnx2: Replace open-coded version with swab32s() Heiner Kallweit
2021-08-22 13:53 ` [PATCH 05/12] bnx2x: Read VPD with pci_vpd_alloc() Heiner Kallweit
2021-08-22 17:42 ` kernel test robot
2021-08-22 13:54 ` [PATCH 06/12] bnx2x: Search VPD with pci_vpd_find_ro_info_keyword() Heiner Kallweit
2021-08-24 17:02 ` Bjorn Helgaas
2021-08-24 18:01 ` Heiner Kallweit
2021-08-24 18:47 ` Bjorn Helgaas
2021-08-22 13:55 ` [PATCH 07/12] bnxt: Read VPD with pci_vpd_alloc() Heiner Kallweit
2021-08-22 18:39 ` kernel test robot
2021-08-22 13:56 ` [PATCH 08/12] bnxt: Search VPD with pci_vpd_find_ro_info_keyword() Heiner Kallweit
2021-08-22 13:57 ` [PATCH 09/12] cxgb4: Validate VPD checksum with pci_vpd_check_csum() Heiner Kallweit
2021-08-22 13:58 ` [PATCH 10/12] cxgb4: Remove unused vpd_param member ec Heiner Kallweit
2021-08-22 13:59 ` [PATCH 11/12] cxgb4: Search VPD with pci_vpd_find_ro_info_keyword() Heiner Kallweit
2021-08-24 17:11 ` Bjorn Helgaas [this message]
2021-08-24 18:06 ` Heiner Kallweit
2021-08-22 14:01 ` [PATCH 12/12] scsi: cxlflash: " Heiner Kallweit
2021-08-24 18:48 ` [PATCH 00/12] PCI/VPD: Convert more users to the new VPD API functions Bjorn Helgaas
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=20210824171142.GA3478603@bjorn-Precision-5520 \
--to=helgaas@kernel.org \
--cc=bhelgaas@google.com \
--cc=davem@davemloft.net \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=rajur@chelsio.com \
/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).