From patchwork Wed Aug 18 18:59:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 499521 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4ADDDC432BE for ; Wed, 18 Aug 2021 19:07:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2FA5A60F35 for ; Wed, 18 Aug 2021 19:07:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232969AbhHRTHi (ORCPT ); Wed, 18 Aug 2021 15:07:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231743AbhHRTHg (ORCPT ); Wed, 18 Aug 2021 15:07:36 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69A71C061764; Wed, 18 Aug 2021 12:07:01 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id k29so5093401wrd.7; Wed, 18 Aug 2021 12:07:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=zMnqmq7S4zAgBQO1n4C6IYMsmqGmjhbOsQkz4Cr8kT4=; b=ty7fq1PcmLJvMFCmbnlYR7niEzSPgBUJODekYszK0OHOpcvH/N5lQ3EAokFQ1nT13c OSFr8YfWzw0GnlLbWPC9cqltbY5aRNbySqnZtmNDvW5OnVqIy9OLiBCdDxMXPEcF+ZpF /Okae7tBsYOfokwszzg+Zk315T8yXO89ptdKsaCeP25fhz08ykrs3yfTnxatzeRYybuw QILvjyRynOvVQVUqDnZd+KiHyTzNlXoHP52ntxDsnVwhlfNQzLZAQGN00+vAj4vAfGR0 nJa95ODd2mHDueyUsudjaOA5V313K3jwbI6OtnTKmwnFyrz19gbUaVyUzhmVLFtQHtUR czsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=zMnqmq7S4zAgBQO1n4C6IYMsmqGmjhbOsQkz4Cr8kT4=; b=DsXsdRRojGJrptWsE7u4h5qnG0Gd/xoDyVkFgW29GeMG3aP8eeDxD63qWb8h9Ci/Sh Gy6CAy4CPAcPgFmgXZ2P0fSIy+L70F8LXE1eIET9t+xLjjM9eD5lRrw8GyQY0VuFcS2V FLtmkEGc/f4di9fDLrMVmKfWaCFP3NRwDMsAsi9j/+7U+BoN5BmEDnDWdpUy4up1F4kr STe0Jh3tKd8RTqQqFJneO0BouaZGMsiv0FTQuhAMPdH+nX4seTOi2yluvwT5euy0nQ88 oUHQvpMYe9Kn8wkkDnB84I4MBH75o+NOqQlHq+pMEXtnhzeHvkWc8c/Mg9ssv7XribjX LHBg== X-Gm-Message-State: AOAM531qAtpq8OhTWjYOnIZMakr5JKfUNFRZY8F30gIjkvI5U6iHH/jC y9wgoWQ4NI6oBRj42oOnREPpFGevFHNI1Q== X-Google-Smtp-Source: ABdhPJwsjbscFfdd1R1vmBLczobtK9CJZZksM06H4ZzU1HHgvyNfXgkQ3EYkKhn8c+vA/tXkOvpODw== X-Received: by 2002:a05:6000:1a86:: with SMTP id f6mr12651155wry.345.1629313619650; Wed, 18 Aug 2021 12:06:59 -0700 (PDT) Received: from ?IPv6:2003:ea:8f08:4500:5c16:403a:870d:fceb? (p200300ea8f0845005c16403a870dfceb.dip0.t-ipconnect.de. [2003:ea:8f08:4500:5c16:403a:870d:fceb]) by smtp.googlemail.com with ESMTPSA id h9sm581023wmb.35.2021.08.18.12.06.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Aug 2021 12:06:59 -0700 (PDT) Subject: [PATCH 1/8] PCI/VPD: Add pci_vpd_alloc From: Heiner Kallweit To: Edward Cree , Martin Habets , Siva Reddy Kallam , Prashant Sreedharan , Michael Chan , David Miller , Jakub Kicinski Cc: "linux-pci@vger.kernel.org" , "netdev@vger.kernel.org" References: Message-ID: <955ff598-0021-8446-f856-0c2c077635d7@gmail.com> Date: Wed, 18 Aug 2021 20:59:31 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Several users of the VPD API use a fixed-size buffer and read the VPD into it for further usage. This requires special handling for the case that the buffer isn't big enough to hold the full VPD data. Also the buffer is often allocated on the stack what's not too nice. So let's extend the VPD API with a function that dynamically allocates a properly sized buffer. Signed-off-by: Heiner Kallweit --- drivers/pci/vpd.c | 26 ++++++++++++++++++++++++++ include/linux/pci.h | 9 +++++++++ 2 files changed, 35 insertions(+) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index 3b0425fb4..7c3a09737 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -270,6 +270,32 @@ const struct attribute_group pci_dev_vpd_attr_group = { .is_bin_visible = vpd_attr_is_visible, }; +void *pci_vpd_alloc(struct pci_dev *dev, unsigned int *size) +{ + unsigned int len = dev->vpd.len; + void *buf; + int cnt; + + if (!dev->vpd.cap) + return ERR_PTR(-ENODEV); + + buf = kmalloc(len, GFP_KERNEL); + if (!buf) + return ERR_PTR(-ENOMEM); + + cnt = pci_read_vpd(dev, 0, len, buf); + if (cnt != len) { + kfree(buf); + return ERR_PTR(-EIO); + } + + if (size) + *size = len; + + return buf; +} +EXPORT_SYMBOL_GPL(pci_vpd_alloc); + int pci_vpd_find_tag(const u8 *buf, unsigned int len, u8 rdt) { int i = 0; diff --git a/include/linux/pci.h b/include/linux/pci.h index e752cc39a..3061cc943 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -2330,6 +2330,15 @@ static inline u8 pci_vpd_info_field_size(const u8 *info_field) return info_field[2]; } +/** + * pci_vpd_alloc - Allocates buffer and reads VPD into it + * @dev: PCI device + * @size: pointer to field where VPD length is returned + * + * Returns pointer to allocated buffer or an ERR_PTR in case of failure + */ +void *pci_vpd_alloc(struct pci_dev *dev, unsigned int *size); + /** * pci_vpd_find_tag - Locates the Resource Data Type tag provided * @buf: Pointer to buffered vpd data From patchwork Wed Aug 18 19:00:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 500254 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE4AFC4338F for ; Wed, 18 Aug 2021 19:07:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8DF6960F35 for ; Wed, 18 Aug 2021 19:07:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233215AbhHRTHo (ORCPT ); Wed, 18 Aug 2021 15:07:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231743AbhHRTHk (ORCPT ); Wed, 18 Aug 2021 15:07:40 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6E6CC061764; Wed, 18 Aug 2021 12:07:04 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id j12-20020a05600c1c0c00b002e6d80c902dso2434438wms.4; Wed, 18 Aug 2021 12:07:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=BbhCVONKCGt83p5epp5UNjY/vD+Rp31aBgSbhnRKOjs=; b=Z+KZ96YeqtnTNkx2sTg1e0YxjG8IhBMyrmDm9AkyhzvVsbeXXFdOBPdz+G0iYLDOlN QtlUWa9VPPZzmAgZ1B+jVG5OfOtjyH1qIKUEb4AJ/9qdsQrau/yKZNHkmSjcClI08RUO lPNZLi51pTas3jFtJBZAKxVvu97YgzjhkSIYV0q5t9pm/v6/9TEql3zITS9Oe5ijDlig Eps5assQdyyj/pqUMs7nsuWq1ALmwpQCM7bgHlUr9oq6CYg31J1DzlM30mQogAGk+hyg ctVj/+hIRhDHx5Io6IQ5h8q8UnkwPmM1TcQlJsegR6j7V0Pf0JzPJq1hmzN9Ls5hpEiT A1yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=BbhCVONKCGt83p5epp5UNjY/vD+Rp31aBgSbhnRKOjs=; b=WJvkokRZWW2DsC1BOsYXmK2z45S/9DJrfdRvGT3JfMjgr4u2CW52fEo3Eq+pPLduB9 1PS8pZzGf4bEv1isgTNpJ+LRRJ5Qc4BjbnoBEi5XYiBNFhM1kLv90qbv489oMLUUsr7W krGh7hAjtsVBVX9XrsiOXYNezaThlJkqPpSImvoZnL7fJOGHL/G3N79icmd/k5XNrs2Y gcPaJVgwyKh20CUs9gzaQ8nXqEkE9JsAW0ReaczyTbqMb4Q3Y7Ej71Psj18B90QKAYZ3 OFqeGTg0s0iqI2ppgj40fqzqzeqon1xVQQOeKrJDN/j9d9dpzPSLowhtSce1dUk28ci1 QiDw== X-Gm-Message-State: AOAM531eX/ZUw1L6i7qLnYy24zHlYxG7JNECDnyse22w+WFKsbHbfIfc sGFgM1qRnUbnanaCsAhXbmB+Kit2kNBwkg== X-Google-Smtp-Source: ABdhPJzGnfHTuVuFIvk0GGTqkcaILlxTxEX/EOBviyfYbdNl6VOL9nErWQjL2Oxn/FGDAnYXaRsBPQ== X-Received: by 2002:a1c:7506:: with SMTP id o6mr10252795wmc.112.1629313623221; Wed, 18 Aug 2021 12:07:03 -0700 (PDT) Received: from ?IPv6:2003:ea:8f08:4500:5c16:403a:870d:fceb? (p200300ea8f0845005c16403a870dfceb.dip0.t-ipconnect.de. [2003:ea:8f08:4500:5c16:403a:870d:fceb]) by smtp.googlemail.com with ESMTPSA id l2sm662914wrx.2.2021.08.18.12.07.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Aug 2021 12:07:02 -0700 (PDT) Subject: [PATCH 2/8] PCI/VPD: Add pci_vpd_find_ro_info_keyword and pci_vpd_check_csum From: Heiner Kallweit To: Edward Cree , Martin Habets , Siva Reddy Kallam , Prashant Sreedharan , Michael Chan , David Miller , Jakub Kicinski Cc: "linux-pci@vger.kernel.org" , "netdev@vger.kernel.org" References: Message-ID: <1643bd7a-088e-1028-c9b0-9d112cf48d63@gmail.com> Date: Wed, 18 Aug 2021 21:00:57 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org All Users of pci_vpd_find_info_keyword() are interested in the VPD RO section only. In addition all calls are followed by the same activities to calculate start of tag data area and size of the data area. Therefore add an API function that combines these functionalities. pci_vpd_find_info_keyword() can be phased out once all users are converted. VPD checksum information and checksum calculation are part of the PCI standard. Therefore checksum handling can and should be moved into PCI VPD core. Add an API function pci_vpd_check_csum() for that. Signed-off-by: Heiner Kallweit --- drivers/pci/vpd.c | 56 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/pci.h | 21 +++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index 7c3a09737..01e575947 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -380,6 +380,62 @@ ssize_t pci_write_vpd(struct pci_dev *dev, loff_t pos, size_t count, const void } EXPORT_SYMBOL(pci_write_vpd); +int pci_vpd_find_ro_info_keyword(const void *buf, unsigned int len, + const char *kw, unsigned int *size) +{ + int ro_start, infokw_start; + unsigned int ro_len, infokw_size; + + ro_start = pci_vpd_find_tag(buf, len, PCI_VPD_LRDT_RO_DATA); + if (ro_start < 0) + return ro_start; + + ro_len = pci_vpd_lrdt_size(buf + ro_start); + ro_start += PCI_VPD_LRDT_TAG_SIZE; + + if (ro_start + ro_len > len) + ro_len = len - ro_start; + + infokw_start = pci_vpd_find_info_keyword(buf, ro_start, ro_len, kw); + if (infokw_start < 0) + return infokw_start; + + infokw_size = pci_vpd_info_field_size(buf + infokw_start); + infokw_start += PCI_VPD_INFO_FLD_HDR_SIZE; + + if (infokw_start + infokw_size > len) + return -EINVAL; + + if (size) + *size = infokw_size; + + return infokw_start; +} +EXPORT_SYMBOL_GPL(pci_vpd_find_ro_info_keyword); + +int pci_vpd_check_csum(const void *buf, unsigned int len) +{ + const u8 *vpd = buf; + unsigned int size; + u8 csum = 0; + int rv_start; + + rv_start = pci_vpd_find_ro_info_keyword(buf, len, PCI_VPD_RO_KEYWORD_CHKSUM, &size); + if (rv_start == -ENOENT) /* no checksum in VPD */ + return 1; + else if (rv_start < 0) + return rv_start; + + if (!size) + return -EINVAL; + + while (rv_start >= 0) + csum += vpd[rv_start--]; + + return csum ? -EILSEQ : 0; +} +EXPORT_SYMBOL_GPL(pci_vpd_check_csum); + #ifdef CONFIG_PCI_QUIRKS /* * Quirk non-zero PCI functions to route VPD access through function 0 for diff --git a/include/linux/pci.h b/include/linux/pci.h index 3061cc943..a82f5910f 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -2363,6 +2363,27 @@ int pci_vpd_find_tag(const u8 *buf, unsigned int len, u8 rdt); int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off, unsigned int len, const char *kw); +/** + * pci_vpd_check_csum - Check VPD checksum + * @buf: Pointer to buffered vpd data + * @len: VPD size + * + * Returns 1 if VPD has no checksum, otherwise 0 or an errno + */ +int pci_vpd_check_csum(const void *buf, unsigned int len); + +/** + * pci_vpd_find_ro_info_keyword - Locates an info field keyword in VPD RO section + * @buf: Pointer to buffered vpd data + * @len: The length of the buffer area in which to search + * @kw: The keyword to search for + * @size: pointer to field where length of found keyword data is returned + * + * Returns the index of the information field keyword data or -ENOENT if not found. + */ +int pci_vpd_find_ro_info_keyword(const void *buf, unsigned int len, + const char *kw, unsigned int *size); + /* PCI <-> OF binding helpers */ #ifdef CONFIG_OF struct device_node; From patchwork Wed Aug 18 19:01:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 499520 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40935C4320A for ; Wed, 18 Aug 2021 19:07:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2A59F60F35 for ; Wed, 18 Aug 2021 19:07:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233214AbhHRTHz (ORCPT ); Wed, 18 Aug 2021 15:07:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233226AbhHRTHo (ORCPT ); Wed, 18 Aug 2021 15:07:44 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E014C06179A; Wed, 18 Aug 2021 12:07:08 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id r7so5191294wrs.0; Wed, 18 Aug 2021 12:07:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=mBZb63SSLEPVDr6WHI9UQlUQ97X47DnKLHPVD6K6nag=; b=ASr2s5JJFnL15u3/P12jOQlhD5UagdZPSygAS9XhbGepJZ4MTnQo1WjgPaZTcxcSe1 imeRJHDsf+C/8HQWv96h3W0BL6GRBaxzUQDVQrgu9HoBtiGrXibUK4gwHff7kua0HKCc mViI3ouR/j3VkCFbASGQfswjgBj5slptoONvNbItOgFJvOBEZEEKGUgxuu+t8VKcKDnh FcdKU1qV0pOugBEFY6nH9Ai99+BxVT5JDz+iuEYLyVphxX4CiGyAoO7l5ebMSQI6bgb+ mB95nGrlZAdsZW6l19jXYNdYqCuVxkQLi9myqx9XyAOnF0/mTkhZC0yKy0ZPx0u/ULAM CezA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=mBZb63SSLEPVDr6WHI9UQlUQ97X47DnKLHPVD6K6nag=; b=DF5LrreqdXWzvTFVphGUQMHwvTL5OVUUgQaYytBNu3w3B3yEyswu74Z3XvH/i3ySJa 6CVAU224xL281qPDdAqnzGWHpAqLief/FaomB7uf6+J45sz4A70v65htGoyOTp5DQzcY 1ly6y0/QIeaet0+6ZJ4CbdIamrEjomGDXGBn/fEGdz9pnHtpwS0DbDQD+zsTLhvWDce4 SysU3PYAmKU4WWyxbh7+fJwVB2SBevZyYOo6TIASmxn12HX6pNScKk9Y+0UrZY8KXq+O +TVusXbzqpBVfVXydfIvnVRylzL0Sdw4FwWOZ3Y6hw2EvmP1+vvgJouwOHB4JyjCOmRy Fezg== X-Gm-Message-State: AOAM531xnebKnAWech16GXQfQP9Y2MgE/cckS1NdDOdWWxiQIn+eM+3y NdJ7jTlUVKWogPFplCvmhqrcI5CD2XuEyg== X-Google-Smtp-Source: ABdhPJyVfFkpxkHBgwdxdMCFQcX6ifkI1AmXZcsApQrNQnMnhU97MI5UBtB9HBt41tp9yenhNxtQIg== X-Received: by 2002:a05:6000:1864:: with SMTP id d4mr12998155wri.250.1629313626710; Wed, 18 Aug 2021 12:07:06 -0700 (PDT) Received: from ?IPv6:2003:ea:8f08:4500:5c16:403a:870d:fceb? (p200300ea8f0845005c16403a870dfceb.dip0.t-ipconnect.de. [2003:ea:8f08:4500:5c16:403a:870d:fceb]) by smtp.googlemail.com with ESMTPSA id s1sm5719988wmh.46.2021.08.18.12.07.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Aug 2021 12:07:06 -0700 (PDT) Subject: [PATCH 3/8] PCI/VPD: Add missing VPD RO field keywords From: Heiner Kallweit To: Edward Cree , Martin Habets , Siva Reddy Kallam , Prashant Sreedharan , Michael Chan , David Miller , Jakub Kicinski Cc: "linux-pci@vger.kernel.org" , "netdev@vger.kernel.org" References: Message-ID: <58b7b0d7-4320-fe1d-4c45-7b360f7ea3d7@gmail.com> Date: Wed, 18 Aug 2021 21:01:42 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch adds further keywords that are defined in the PCI spec. Signed-off-by: Heiner Kallweit --- include/linux/pci.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/pci.h b/include/linux/pci.h index a82f5910f..629c810ae 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -2274,6 +2274,8 @@ int pci_enable_atomic_ops_to_root(struct pci_dev *dev, u32 cap_mask); #define PCI_VPD_RO_KEYWORD_MFR_ID "MN" #define PCI_VPD_RO_KEYWORD_VENDOR0 "V0" #define PCI_VPD_RO_KEYWORD_CHKSUM "RV" +#define PCI_VPD_RO_KEYWORD_ECLEVEL "EC" +#define PCI_VPD_RO_KEYWORD_EXTCAP "CP" /** * pci_vpd_lrdt_size - Extracts the Large Resource Data Type length From patchwork Wed Aug 18 19:02:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 500253 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B5D5C4338F for ; Wed, 18 Aug 2021 19:07:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C179C610FD for ; Wed, 18 Aug 2021 19:07:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233283AbhHRTH6 (ORCPT ); Wed, 18 Aug 2021 15:07:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233285AbhHRTHr (ORCPT ); Wed, 18 Aug 2021 15:07:47 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED9F7C061764; Wed, 18 Aug 2021 12:07:11 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id g138so2254630wmg.4; Wed, 18 Aug 2021 12:07:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=2jGrYvV1Qk7AhZwzusm0nC2EVomIYB2AkGTE+vbDl6E=; b=EyhEQgWoJQtpEqWJeBziOG2Ezn36KdEJxfhsPZTIsHKZTf+erohmnEyILlvyf71oKp tz1RDN3VAsOwbbnutt7FDzbprEQ4qqYg2jps9ooyaq+VOH3dpExIkY7qs9GAFPdqQnLX FpbHr/I2Gka20cfL+6KenJzfil4QbCCFO7zlfvhlXaP+UCtbQXdxVHY0Hprv8QnLD3WG oL+Of1+hebDnV7Wr38ze3oqtOC4YoY0xEbJqYvIvPAQBtfuzQPxxIPswqn/O1wcIMgw1 pWAu0U1AFoXP5ZnQAJWNDTaorIzRTWAz8QZ+kzHy+jjhPi9BpcphoS+NfvSgr6XOsuot sdjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=2jGrYvV1Qk7AhZwzusm0nC2EVomIYB2AkGTE+vbDl6E=; b=LnUe88bWJXF5Q1QL2yzBQDGo0arbOzhZasMEM4ART+poxpbLx5NKC6t+8Jc9uP0tRG dm5PWiYgSjgB4xS4f8IZ6s9C0zoKU+eNStT0JMt6julhzkfp01R75ekWqPiqMrAxqU4/ 9u3cJL2f7Jm0tKR41wvRHL6+L1nmF3xsdfPaVgz+ccuz4Caq1AgLNHprytxjo84R0vxX sPy1iLWDzadKYk7tW0rzPze33Iexv2SCfIpXuvLddvXGcz3mfM43R5zizH0rzXD1dhD3 rOJSwivYFBxHYpECBKc+mp2J1UZMz5CsrxnYUSmvPWC6rUV1EDIH2nxgcERYLI9mlg4i 7Vdg== X-Gm-Message-State: AOAM532cjpkqQtsazYjL0yK5olHJ1i3IsZ9pf9PW58u2qMm9hgLsfsmy JvQwINswckZk/uy58tENMD7huZXeHDT7jg== X-Google-Smtp-Source: ABdhPJyZjJeTYHofPdlDM6rlgdwdavW2NCpIAKddrG2AND612nBzr0eHsYwwjnTmprAq9gqYX33Evw== X-Received: by 2002:a7b:c2fa:: with SMTP id e26mr9924341wmk.102.1629313630170; Wed, 18 Aug 2021 12:07:10 -0700 (PDT) Received: from ?IPv6:2003:ea:8f08:4500:5c16:403a:870d:fceb? (p200300ea8f0845005c16403a870dfceb.dip0.t-ipconnect.de. [2003:ea:8f08:4500:5c16:403a:870d:fceb]) by smtp.googlemail.com with ESMTPSA id 6sm570875wmk.20.2021.08.18.12.07.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Aug 2021 12:07:09 -0700 (PDT) Subject: [PATCH 4/8] sfc: Use new function pci_vpd_alloc From: Heiner Kallweit To: Edward Cree , Martin Habets , David Miller , Jakub Kicinski Cc: "linux-pci@vger.kernel.org" , "netdev@vger.kernel.org" References: Message-ID: Date: Wed, 18 Aug 2021 21:02:33 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use new VPD API function pci_vpd_alloc() for dynamically allocating a properly sized buffer and reading the full VPD data into it. This avoids having to allocate a buffer on the stack, and we don't have to make any assumptions on VPD size and location of information in VPD any longer. Signed-off-by: Heiner Kallweit --- drivers/net/ethernet/sfc/efx.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/drivers/net/ethernet/sfc/efx.c b/drivers/net/ethernet/sfc/efx.c index a295e2621..e04a63109 100644 --- a/drivers/net/ethernet/sfc/efx.c +++ b/drivers/net/ethernet/sfc/efx.c @@ -900,21 +900,18 @@ static void efx_pci_remove(struct pci_dev *pci_dev) /* NIC VPD information * Called during probe to display the part number of the - * installed NIC. VPD is potentially very large but this should - * always appear within the first 512 bytes. + * installed NIC. */ -#define SFC_VPD_LEN 512 static void efx_probe_vpd_strings(struct efx_nic *efx) { struct pci_dev *dev = efx->pci_dev; - char vpd_data[SFC_VPD_LEN]; - ssize_t vpd_size; int ro_start, ro_size, i, j; + unsigned int vpd_size; + u8 *vpd_data; - /* Get the vpd data from the device */ - vpd_size = pci_read_vpd(dev, 0, sizeof(vpd_data), vpd_data); - if (vpd_size <= 0) { - netif_err(efx, drv, efx->net_dev, "Unable to read VPD\n"); + vpd_data = pci_vpd_alloc(dev, &vpd_size); + if (IS_ERR(vpd_data)) { + pci_warn(dev, "Unable to read VPD\n"); return; } @@ -922,7 +919,7 @@ static void efx_probe_vpd_strings(struct efx_nic *efx) ro_start = pci_vpd_find_tag(vpd_data, vpd_size, PCI_VPD_LRDT_RO_DATA); if (ro_start < 0) { netif_err(efx, drv, efx->net_dev, "VPD Read-only not found\n"); - return; + goto out; } ro_size = pci_vpd_lrdt_size(&vpd_data[ro_start]); @@ -935,14 +932,14 @@ static void efx_probe_vpd_strings(struct efx_nic *efx) i = pci_vpd_find_info_keyword(vpd_data, i, j, "PN"); if (i < 0) { netif_err(efx, drv, efx->net_dev, "Part number not found\n"); - return; + goto out; } j = pci_vpd_info_field_size(&vpd_data[i]); i += PCI_VPD_INFO_FLD_HDR_SIZE; if (i + j > vpd_size) { netif_err(efx, drv, efx->net_dev, "Incomplete part number\n"); - return; + goto out; } netif_info(efx, drv, efx->net_dev, @@ -953,21 +950,23 @@ static void efx_probe_vpd_strings(struct efx_nic *efx) i = pci_vpd_find_info_keyword(vpd_data, i, j, "SN"); if (i < 0) { netif_err(efx, drv, efx->net_dev, "Serial number not found\n"); - return; + goto out; } j = pci_vpd_info_field_size(&vpd_data[i]); i += PCI_VPD_INFO_FLD_HDR_SIZE; if (i + j > vpd_size) { netif_err(efx, drv, efx->net_dev, "Incomplete serial number\n"); - return; + goto out; } efx->vpd_sn = kmalloc(j + 1, GFP_KERNEL); if (!efx->vpd_sn) - return; + goto out; snprintf(efx->vpd_sn, j + 1, "%s", &vpd_data[i]); +out: + kfree(vpd_data); } From patchwork Wed Aug 18 19:03:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 499519 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA6E0C4338F for ; Wed, 18 Aug 2021 19:07:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C5D67610FD for ; Wed, 18 Aug 2021 19:07:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233384AbhHRTIJ (ORCPT ); Wed, 18 Aug 2021 15:08:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231743AbhHRTHv (ORCPT ); Wed, 18 Aug 2021 15:07:51 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2ED13C061764; Wed, 18 Aug 2021 12:07:15 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id j12-20020a05600c1c0c00b002e6d80c902dso2434743wms.4; Wed, 18 Aug 2021 12:07:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=zGVsAIqhBW/AmYXXyLcUHMTNx7/cUwe/kNJ8uYF+hyA=; b=DA4wFZJS5eSLfAj1x7y+bgbSzYsUgF52jeBsnr8XxTkCOaADmb1rMM3Hi53OuOl7op /NvrK9Je00lo90ArycDzc7jEt9wVUwnbu3WbI6Cz8lfAG8gyFTpAeMPMYou+1zssavst NXAZjyOKgZ8pUKM05CLrtlLnISlyvWDc/IvfE7d1smEl6Qz/IQfUxMVXDpwgPUmwuMHm jywtjVWKgcuwVJfI93ROwC/8iem9OLP9gYNwVAFgoR5h2Fy28WZm+a0ZxFAHB2kb5T/I CA3u1m6PB9S3CXR1Wtyu+7H4Hg7IySsOylMNYoMn9etrpPU7wPXVEi8OM1u5Rrgv/ESR nh7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=zGVsAIqhBW/AmYXXyLcUHMTNx7/cUwe/kNJ8uYF+hyA=; b=kDo/5bM0mQUkx/1X9xIXOXefOF4eQKPQNipeOMf00CJ420GU+DUf+Mgk3FsSqoHJcA zlV02h8uaTaQGYsJ9ErHQoGtxwX1kcxJ6CoSuN1PhBsGS/3jf0XfX6XBrSJcuz5zqbuB WbQy/vfzhMxWviKrlT2uWAS4XpNLHpEgZVLsyS15h3LzWCJCS+Nej7cmG5DDKG0//aAL 5N7nfCB0P3EEiVDKLvbDvcn5uGfR4TSOKZJtsL877WUenykKyF0tSYpYSZlB9AJWvY1y r5de6tqiLKflU17osZZIPx94mr/9P8FCyVyFR/kzGZK9+t4n0+hjQgC6jGS0gPaDopM0 j36Q== X-Gm-Message-State: AOAM530wfvJvE4NIiTqYxIpdQMGaOn+LJn3fpY9v45Kkw04SeYF0g9BV m2rlMvdeRKlCv0MjZJgV+W0GmdfruprPIg== X-Google-Smtp-Source: ABdhPJwqj0Xpepf9nk1a7nfLAgF9q5Vzguo/sCttvAxUUrCkVPD1+3sPgQAEiWpOyagzGcnvfKRTrA== X-Received: by 2002:a05:600c:22c2:: with SMTP id 2mr9862895wmg.3.1629313633523; Wed, 18 Aug 2021 12:07:13 -0700 (PDT) Received: from ?IPv6:2003:ea:8f08:4500:5c16:403a:870d:fceb? (p200300ea8f0845005c16403a870dfceb.dip0.t-ipconnect.de. [2003:ea:8f08:4500:5c16:403a:870d:fceb]) by smtp.googlemail.com with ESMTPSA id p18sm679702wrt.13.2021.08.18.12.07.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Aug 2021 12:07:13 -0700 (PDT) Subject: [PATCH 5/8] sfc: Use new VPD API function pci_vpd_find_ro_info_keyword From: Heiner Kallweit To: Edward Cree , Martin Habets , David Miller , Jakub Kicinski Cc: "linux-pci@vger.kernel.org" , "netdev@vger.kernel.org" References: Message-ID: Date: Wed, 18 Aug 2021 21:03:44 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use new VPD API function pci_vpd_find_ro_info_keyword() to simplify the code. In addition replace netif_err() with pci_err() because the netdevice isn't registered yet what results in very ugly messages. Use kmemdup_nul() instead of open-coding it. Signed-off-by: Heiner Kallweit --- drivers/net/ethernet/sfc/efx.c | 65 ++++++++-------------------------- 1 file changed, 14 insertions(+), 51 deletions(-) diff --git a/drivers/net/ethernet/sfc/efx.c b/drivers/net/ethernet/sfc/efx.c index e04a63109..43ef4f529 100644 --- a/drivers/net/ethernet/sfc/efx.c +++ b/drivers/net/ethernet/sfc/efx.c @@ -905,9 +905,9 @@ static void efx_pci_remove(struct pci_dev *pci_dev) static void efx_probe_vpd_strings(struct efx_nic *efx) { struct pci_dev *dev = efx->pci_dev; - int ro_start, ro_size, i, j; - unsigned int vpd_size; + unsigned int vpd_size, kw_len; u8 *vpd_data; + int start; vpd_data = pci_vpd_alloc(dev, &vpd_size); if (IS_ERR(vpd_data)) { @@ -915,57 +915,20 @@ static void efx_probe_vpd_strings(struct efx_nic *efx) return; } - /* Get the Read only section */ - ro_start = pci_vpd_find_tag(vpd_data, vpd_size, PCI_VPD_LRDT_RO_DATA); - if (ro_start < 0) { - netif_err(efx, drv, efx->net_dev, "VPD Read-only not found\n"); - goto out; - } - - ro_size = pci_vpd_lrdt_size(&vpd_data[ro_start]); - j = ro_size; - i = ro_start + PCI_VPD_LRDT_TAG_SIZE; - if (i + j > vpd_size) - j = vpd_size - i; - - /* Get the Part number */ - i = pci_vpd_find_info_keyword(vpd_data, i, j, "PN"); - if (i < 0) { - netif_err(efx, drv, efx->net_dev, "Part number not found\n"); - goto out; - } - - j = pci_vpd_info_field_size(&vpd_data[i]); - i += PCI_VPD_INFO_FLD_HDR_SIZE; - if (i + j > vpd_size) { - netif_err(efx, drv, efx->net_dev, "Incomplete part number\n"); - goto out; - } - - netif_info(efx, drv, efx->net_dev, - "Part Number : %.*s\n", j, &vpd_data[i]); - - i = ro_start + PCI_VPD_LRDT_TAG_SIZE; - j = ro_size; - i = pci_vpd_find_info_keyword(vpd_data, i, j, "SN"); - if (i < 0) { - netif_err(efx, drv, efx->net_dev, "Serial number not found\n"); - goto out; - } - - j = pci_vpd_info_field_size(&vpd_data[i]); - i += PCI_VPD_INFO_FLD_HDR_SIZE; - if (i + j > vpd_size) { - netif_err(efx, drv, efx->net_dev, "Incomplete serial number\n"); - goto out; - } + start = pci_vpd_find_ro_info_keyword(vpd_data, vpd_size, + PCI_VPD_RO_KEYWORD_PARTNO, &kw_len); + if (start < 0) + pci_err(dev, "Part number not found or incomplete\n"); + else + pci_info(dev, "Part Number : %.*s\n", kw_len, vpd_data + start); - efx->vpd_sn = kmalloc(j + 1, GFP_KERNEL); - if (!efx->vpd_sn) - goto out; + start = pci_vpd_find_ro_info_keyword(vpd_data, vpd_size, + PCI_VPD_RO_KEYWORD_SERIALNO, &kw_len); + if (start < 0) + pci_err(dev, "Serial number not found or incomplete\n"); + else + efx->vpd_sn = kmemdup_nul(vpd_data + start, kw_len, GFP_KERNEL); - snprintf(efx->vpd_sn, j + 1, "%s", &vpd_data[i]); -out: kfree(vpd_data); } From patchwork Wed Aug 18 19:04:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 500252 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C907C4338F for ; Wed, 18 Aug 2021 19:07:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 72A1360F35 for ; Wed, 18 Aug 2021 19:07:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233425AbhHRTIN (ORCPT ); Wed, 18 Aug 2021 15:08:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233186AbhHRTHy (ORCPT ); Wed, 18 Aug 2021 15:07:54 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D730C0613CF; Wed, 18 Aug 2021 12:07:18 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id f13-20020a1c6a0d000000b002e6fd0b0b3fso3452270wmc.3; Wed, 18 Aug 2021 12:07:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=8K4MnAEhJS2dex7Zxf7KLhcekRxHS9icv9pu38R/sIc=; b=eEtIQT9vQ6NRyACElkzdyLpqPHhAKh+OrGmUOKnLIROcEoIH8TcM+QCPG03N7MzspT ExdnMNimM/vap0d1/Xi3MifhPkZRIhcqWDzaiig86beJzcAJWkwBBN/6ZWop/uW8qjL2 nRka2047yq1tnmmkjK4swNPbMu+lUlSidNU0OctTNPbrXqdF19MQZ6kVKdHM2uzJS3jk ykskkf1NSi5DNLDKRD+mSPViintj4Uyrm0jy9hjk3xTMMfzG8zS0gigorbe3jX5Rp2VG dCKfa2IzEC5i1i/Msqba2+ZrGSMTfdiGiPRLn1dFPXIhl9j9C8deFpNHi6FUTKitOlpV 3GXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=8K4MnAEhJS2dex7Zxf7KLhcekRxHS9icv9pu38R/sIc=; b=ixHRTYSfkjxXJQXQjKIxIVS6VQjQm7EiNVApfck+5BHvsuuuuO0CPy8P80QIBAPTkL FJ6ZRyhTZYZoRSOVXcKDQHv8TV02mWXlR1WKdJgdS/AxgrmOOZVPUKnGDOmAvAfqKdra lbFa3JPyy+Q8YIJui7RwE6lAd2uqVZqpiporDanm22b75LIgLbKvTGWtqwSAd/Yiqx/y hP8aMq6BYXCMDSTgGRhfYi7vLQPKQNXdF6zP9cjotd/kL0tyFVL2kgRBiPnW8pox6lSd Yf2LBTE2ZC1KVoksU0WxMHgRtIIzA53BsQJx/yFa086g502AK6JnKZIiaqoIwIOTLXE2 92JQ== X-Gm-Message-State: AOAM531U0+oON1dzXvl3secfsWxS7RsiroXyNh8x/7xEEKJzRv/AxXWj Jh4U4HW9eAWX978HjQ8LqJQiHS3g5PJOXQ== X-Google-Smtp-Source: ABdhPJw3KQiz1AyI9YM30UyLLLJy5qTjXb5f1U+Ji8d/ecMUaguG1bCFusFNlaB+B57aZ6agyG0FIA== X-Received: by 2002:a1c:2b04:: with SMTP id r4mr10005512wmr.168.1629313636983; Wed, 18 Aug 2021 12:07:16 -0700 (PDT) Received: from ?IPv6:2003:ea:8f08:4500:5c16:403a:870d:fceb? (p200300ea8f0845005c16403a870dfceb.dip0.t-ipconnect.de. [2003:ea:8f08:4500:5c16:403a:870d:fceb]) by smtp.googlemail.com with ESMTPSA id m10sm747723wro.63.2021.08.18.12.07.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Aug 2021 12:07:16 -0700 (PDT) Subject: [PATCH 6/8] tg3: Use new function pci_vpd_alloc From: Heiner Kallweit To: Siva Reddy Kallam , Prashant Sreedharan , Michael Chan , David Miller , Jakub Kicinski Cc: "linux-pci@vger.kernel.org" , "netdev@vger.kernel.org" References: Message-ID: Date: Wed, 18 Aug 2021 21:04:37 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use new VPD API function pci_vpd_alloc() for dynamically allocating a properly sized buffer and reading the full VPD data into it. This allows to simplify the code, and we don't have to make assumptions on VPD size any longer. Signed-off-by: Heiner Kallweit --- drivers/net/ethernet/broadcom/tg3.c | 27 ++++++++++----------------- drivers/net/ethernet/broadcom/tg3.h | 1 - 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c index 6f82eeaa4..fd4522c81 100644 --- a/drivers/net/ethernet/broadcom/tg3.c +++ b/drivers/net/ethernet/broadcom/tg3.c @@ -12791,7 +12791,7 @@ static void tg3_get_ethtool_stats(struct net_device *dev, memset(tmp_stats, 0, sizeof(struct tg3_ethtool_stats)); } -static __be32 *tg3_vpd_readblock(struct tg3 *tp, u32 *vpdlen) +static __be32 *tg3_vpd_readblock(struct tg3 *tp, unsigned int *vpdlen) { int i; __be32 *buf; @@ -12825,15 +12825,11 @@ static __be32 *tg3_vpd_readblock(struct tg3 *tp, u32 *vpdlen) offset = TG3_NVM_VPD_OFF; len = TG3_NVM_VPD_LEN; } - } else { - len = TG3_NVM_PCI_VPD_MAX_LEN; - } - buf = kmalloc(len, GFP_KERNEL); - if (buf == NULL) - return NULL; + buf = kmalloc(len, GFP_KERNEL); + if (!buf) + return NULL; - if (magic == TG3_EEPROM_MAGIC) { for (i = 0; i < len; i += 4) { /* The data is in little-endian format in NVRAM. * Use the big-endian read routines to preserve @@ -12844,12 +12840,9 @@ static __be32 *tg3_vpd_readblock(struct tg3 *tp, u32 *vpdlen) } *vpdlen = len; } else { - ssize_t cnt; - - cnt = pci_read_vpd(tp->pdev, 0, len, (u8 *)buf); - if (cnt < 0) - goto error; - *vpdlen = cnt; + buf = pci_vpd_alloc(tp->pdev, vpdlen); + if (IS_ERR(buf)) + return NULL; } return buf; @@ -12871,9 +12864,10 @@ static __be32 *tg3_vpd_readblock(struct tg3 *tp, u32 *vpdlen) static int tg3_test_nvram(struct tg3 *tp) { - u32 csum, magic, len; + u32 csum, magic; __be32 *buf; int i, j, k, err = 0, size; + unsigned int len; if (tg3_flag(tp, NO_NVRAM)) return 0; @@ -15621,8 +15615,7 @@ static int tg3_phy_probe(struct tg3 *tp) static void tg3_read_vpd(struct tg3 *tp) { u8 *vpd_data; - unsigned int block_end, rosize, len; - u32 vpdlen; + unsigned int block_end, rosize, len, vpdlen; int j, i = 0; vpd_data = (u8 *)tg3_vpd_readblock(tp, &vpdlen); diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h index 46ec4fdfd..1000c8940 100644 --- a/drivers/net/ethernet/broadcom/tg3.h +++ b/drivers/net/ethernet/broadcom/tg3.h @@ -2101,7 +2101,6 @@ /* Hardware Legacy NVRAM layout */ #define TG3_NVM_VPD_OFF 0x100 #define TG3_NVM_VPD_LEN 256 -#define TG3_NVM_PCI_VPD_MAX_LEN 512 /* Hardware Selfboot NVRAM layout */ #define TG3_NVM_HWSB_CFG1 0x00000004 From patchwork Wed Aug 18 19:05:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 499518 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FAF4C4338F for ; Wed, 18 Aug 2021 19:07:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4A70160F35 for ; Wed, 18 Aug 2021 19:07:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233575AbhHRTIW (ORCPT ); Wed, 18 Aug 2021 15:08:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233277AbhHRTH6 (ORCPT ); Wed, 18 Aug 2021 15:07:58 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1743EC0613CF; Wed, 18 Aug 2021 12:07:22 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id f5so5040137wrm.13; Wed, 18 Aug 2021 12:07:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=viCiWeLBgQYfYhWjpq4wMjdK20Zi2YY4mho1UtETxPw=; b=uk60/DRuP/r3It+7pa7c41w2H9nMbhocOBvWM2PzNNbRtyh82mKxX+ZwhX/rj9GSpH +3cuhdvkU39CeZujkSXqkz2LBGJFso0997z9PiU2KkILDTm01XPYaxjKy5JW5psJTN7L jiO5jkHxoTfPg5lBqc1umGWjuWX63VKaOoXUZ2p2pA8aR3OwrwKZTAVaw0CQLHDrgv4C Jj1L4aqXdX+lopaf8kNy4fmyg8WDD3sgmfrVqH3I0O7Qzel+a7dVyh1mM2vFA/vwUnNN ZwhJ6HMYftMzs9Wk2c7ZkTXz5tzqoNwGBH0H72Si8B9syMfkVwH8NM0sKUZIQN3Yahmz 1+Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=viCiWeLBgQYfYhWjpq4wMjdK20Zi2YY4mho1UtETxPw=; b=B/GuiMn2aovvGC8rgXgXWkPW+m/lu6WLxEQflMjWVoINBeRgMq7o1HvrItwtFSzW5Z vRZSxbfDqDpphptCE44a1R24cnJlNLLs/NZsgXZrOxjPLQuaE880kwEeM6QVFa+LS42A X+BW3FM3oF+/Is6AbehuBGywTVrVqQLpV1lX6/NMlp2Zoh/3kDnD279lPIXYIrxWpBRu r1kh0bZMVeIar+2EDZx9AGyAXx5QKlKpqISmX2rCDRKimPM5nUCl2CuxjfRIlG9hPQHs mStg8g7DcsBTCgERX27VhZtl5NUHgoEFSw/1TMNtXWMw8lpGIs6h/T0j5j+SlIPVwGOi SYOQ== X-Gm-Message-State: AOAM533c3uryRMbsyFqFHGxYXJz+bsiux2I5p9twP6G+YB579rtDsSqs OUi3kEEMse84FHONYB2sUIqD2n6Y54Ohcw== X-Google-Smtp-Source: ABdhPJwNK9wSwLji9YDtIe/ymlZz5bAhR385bB7wrMSefPHfNrn00T0PmbsT6wgPcdSSRqPlq1G0pQ== X-Received: by 2002:a5d:58d2:: with SMTP id o18mr12328384wrf.277.1629313640512; Wed, 18 Aug 2021 12:07:20 -0700 (PDT) Received: from ?IPv6:2003:ea:8f08:4500:5c16:403a:870d:fceb? (p200300ea8f0845005c16403a870dfceb.dip0.t-ipconnect.de. [2003:ea:8f08:4500:5c16:403a:870d:fceb]) by smtp.googlemail.com with ESMTPSA id i8sm5956419wma.7.2021.08.18.12.07.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Aug 2021 12:07:20 -0700 (PDT) Subject: [PATCH 7/8] tg3: Use new function pci_vpd_check_csum From: Heiner Kallweit To: Siva Reddy Kallam , Prashant Sreedharan , Michael Chan , David Miller , Jakub Kicinski Cc: "linux-pci@vger.kernel.org" , "netdev@vger.kernel.org" References: Message-ID: <7297fce9-47db-3b86-366e-10b9ef43beaf@gmail.com> Date: Wed, 18 Aug 2021 21:05:26 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use new VPD API function pci_vpd_check_csum() to simplify the code. Signed-off-by: Heiner Kallweit --- drivers/net/ethernet/broadcom/tg3.c | 31 ++++------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c index fd4522c81..309aec742 100644 --- a/drivers/net/ethernet/broadcom/tg3.c +++ b/drivers/net/ethernet/broadcom/tg3.c @@ -13010,33 +13010,10 @@ static int tg3_test_nvram(struct tg3 *tp) if (!buf) return -ENOMEM; - i = pci_vpd_find_tag((u8 *)buf, len, PCI_VPD_LRDT_RO_DATA); - if (i > 0) { - j = pci_vpd_lrdt_size(&((u8 *)buf)[i]); - if (j < 0) - goto out; - - if (i + PCI_VPD_LRDT_TAG_SIZE + j > len) - goto out; - - i += PCI_VPD_LRDT_TAG_SIZE; - j = pci_vpd_find_info_keyword((u8 *)buf, i, j, - PCI_VPD_RO_KEYWORD_CHKSUM); - if (j > 0) { - u8 csum8 = 0; - - j += PCI_VPD_INFO_FLD_HDR_SIZE; - - for (i = 0; i <= j; i++) - csum8 += ((u8 *)buf)[i]; - - if (csum8) - goto out; - } - } - - err = 0; - + err = pci_vpd_check_csum(buf, len); + /* go on if no checksum found */ + if (err == 1) + err = 0; out: kfree(buf); return err; From patchwork Wed Aug 18 19:06:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 500251 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2376AC4320A for ; Wed, 18 Aug 2021 19:08:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5ED7E61159 for ; Wed, 18 Aug 2021 19:08:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233651AbhHRTI0 (ORCPT ); Wed, 18 Aug 2021 15:08:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233496AbhHRTIF (ORCPT ); Wed, 18 Aug 2021 15:08:05 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E1EDC0613A3; Wed, 18 Aug 2021 12:07:25 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id c129-20020a1c35870000b02902e6b6135279so2476508wma.0; Wed, 18 Aug 2021 12:07:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=LDIfWEhWO8mVudTFuw38niuUgR6UGRnl4p6utnT37F4=; b=UvzolmWpYEyJzarXLllRnqJ9qRIjTu/H5jojxM9143e7AthN4ECQwqTBsQx/4ZyKHx IItSbEB5UNZbi9dL5W0+9wvVNF1j2i050BJ6aaIQm264QM3uv14iq9tIB28PGMjiaPgm JqaBkQL5/mwvAXaa2b2+ujSXNsaQ2y4o4/CaSfeIWeuP8DcTr/0eUT075PlvMfw4Frss iGFWUwmap1Ujlg2jvIPtC9RwmAnPI9TWjJfOyow+Olq30E4CsjsmXFYOvR9CdDtjqJ+Q TtlUyqIHBuqf79NxH5rdpfhnLor4Qp6JrDCBhIKNvsu8YA9/vbXqhVgoa2YuNC+Y553G DrXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=LDIfWEhWO8mVudTFuw38niuUgR6UGRnl4p6utnT37F4=; b=izoJyANs8WbBdgeqpzGS7RkleT3FrxURkudAQPAxLu4+H69vTiEY5B1HhWaUwEgxdB xAvupAuoZ8k3cXeFCGDECJB69x6uvSnUTI9x32LLxbchqDdysEMyEV43XL/kcctxAQuz apBSAQT1wb4t2Za6neb3SpJS4LnVJyS4/P+CFdh6yXk8R30GT4MZo98svwbYPYh4x9hB Sdz4al8wilk+R6kzU9ogC4BADnxGaEp2vIdarfvwBUgmzQf24Ka3mI8p7j+8g13LI4A/ oGK45VfLxYf8KL72b1UPKxE9Odjuxv9Dyt1O7cyVUFN/0Zt5y9hSxFR/YZ8C7qCwK1Nk aHtQ== X-Gm-Message-State: AOAM5337pN3uqByl6NG26jY1hjIM+DJc4J0dE5cb7sw1dIHVlxMFPbYU bbevxTj4DsO9Ocxr2QCqgmIrhSBmW4pafA== X-Google-Smtp-Source: ABdhPJzbczZWhLAF3ylgWjegsy80xxr46YwXW/f9gHPD38R3XLN1AUEBQQ+aJmwYzXcLaIG7PPv+ng== X-Received: by 2002:a7b:c5d2:: with SMTP id n18mr9990022wmk.97.1629313643865; Wed, 18 Aug 2021 12:07:23 -0700 (PDT) Received: from ?IPv6:2003:ea:8f08:4500:5c16:403a:870d:fceb? (p200300ea8f0845005c16403a870dfceb.dip0.t-ipconnect.de. [2003:ea:8f08:4500:5c16:403a:870d:fceb]) by smtp.googlemail.com with ESMTPSA id 7sm6043999wmk.39.2021.08.18.12.07.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Aug 2021 12:07:23 -0700 (PDT) Subject: [PATCH 8/8] tg3: Use new function pci_vpd_find_ro_info_keyword From: Heiner Kallweit To: Siva Reddy Kallam , Prashant Sreedharan , Michael Chan , David Miller , Jakub Kicinski Cc: "linux-pci@vger.kernel.org" , "netdev@vger.kernel.org" References: Message-ID: <0ae9d4c0-590d-682a-a0af-2272e5f71630@gmail.com> Date: Wed, 18 Aug 2021 21:06:40 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use new VPD API function pci_vpd_find_ro_info_keyword() to simplify the code. Signed-off-by: Heiner Kallweit --- drivers/net/ethernet/broadcom/tg3.c | 59 ++++++++--------------------- 1 file changed, 16 insertions(+), 43 deletions(-) diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c index 309aec742..6637a97d7 100644 --- a/drivers/net/ethernet/broadcom/tg3.c +++ b/drivers/net/ethernet/broadcom/tg3.c @@ -15592,63 +15592,36 @@ static int tg3_phy_probe(struct tg3 *tp) static void tg3_read_vpd(struct tg3 *tp) { u8 *vpd_data; - unsigned int block_end, rosize, len, vpdlen; - int j, i = 0; + unsigned int len, vpdlen; + int i; vpd_data = (u8 *)tg3_vpd_readblock(tp, &vpdlen); if (!vpd_data) goto out_no_vpd; - i = pci_vpd_find_tag(vpd_data, vpdlen, PCI_VPD_LRDT_RO_DATA); + i = pci_vpd_find_ro_info_keyword(vpd_data, vpdlen, + PCI_VPD_RO_KEYWORD_MFR_ID, &len); if (i < 0) - goto out_not_found; - - rosize = pci_vpd_lrdt_size(&vpd_data[i]); - block_end = i + PCI_VPD_LRDT_TAG_SIZE + rosize; - i += PCI_VPD_LRDT_TAG_SIZE; - - if (block_end > vpdlen) - goto out_not_found; - - j = pci_vpd_find_info_keyword(vpd_data, i, rosize, - PCI_VPD_RO_KEYWORD_MFR_ID); - if (j > 0) { - len = pci_vpd_info_field_size(&vpd_data[j]); + goto partno; - j += PCI_VPD_INFO_FLD_HDR_SIZE; - if (j + len > block_end || len != 4 || - memcmp(&vpd_data[j], "1028", 4)) - goto partno; + if (len != 4 || memcmp(vpd_data + i, "1028", 4)) + goto partno; - j = pci_vpd_find_info_keyword(vpd_data, i, rosize, - PCI_VPD_RO_KEYWORD_VENDOR0); - if (j < 0) - goto partno; - - len = pci_vpd_info_field_size(&vpd_data[j]); + i = pci_vpd_find_ro_info_keyword(vpd_data, vpdlen, + PCI_VPD_RO_KEYWORD_VENDOR0, &len); + if (i < 0) + goto partno; - j += PCI_VPD_INFO_FLD_HDR_SIZE; - if (j + len > block_end) - goto partno; - - if (len >= sizeof(tp->fw_ver)) - len = sizeof(tp->fw_ver) - 1; - memset(tp->fw_ver, 0, sizeof(tp->fw_ver)); - snprintf(tp->fw_ver, sizeof(tp->fw_ver), "%.*s bc ", len, - &vpd_data[j]); - } + memset(tp->fw_ver, 0, sizeof(tp->fw_ver)); + snprintf(tp->fw_ver, sizeof(tp->fw_ver), "%.*s bc ", len, vpd_data + i); partno: - i = pci_vpd_find_info_keyword(vpd_data, i, rosize, - PCI_VPD_RO_KEYWORD_PARTNO); + i = pci_vpd_find_ro_info_keyword(vpd_data, vpdlen, + PCI_VPD_RO_KEYWORD_PARTNO, &len); if (i < 0) goto out_not_found; - len = pci_vpd_info_field_size(&vpd_data[i]); - - i += PCI_VPD_INFO_FLD_HDR_SIZE; - if (len > TG3_BPN_SIZE || - (len + i) > vpdlen) + if (len > TG3_BPN_SIZE) goto out_not_found; memcpy(tp->board_part_number, &vpd_data[i], len);