From patchwork Sun Aug 22 13:48: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: 501487 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 8C5C4C4320A for ; Sun, 22 Aug 2021 14:01:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5FC6D6126A for ; Sun, 22 Aug 2021 14:01:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232428AbhHVOCF (ORCPT ); Sun, 22 Aug 2021 10:02:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230495AbhHVOCE (ORCPT ); Sun, 22 Aug 2021 10:02:04 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FE21C061575; Sun, 22 Aug 2021 07:01:23 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id d26so1625241wrc.0; Sun, 22 Aug 2021 07:01: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=Euz0E6isscBYyFQ42pM4Z2EOYe57hCAo87czLinH3tQ=; b=Ku7NYMjn9nIwgb2ynMqcuTcWBtHsvWS2W57WhgpdY7Z4cL+aUN2DyL3RcNwP9ZKoLP ibLcGD0I/IRefzks/kJyucgsHGK9S2R7cFW3jiW2uU44uXOulsd76cmwk7CyF+rILsTN ONHjh3vcoQmrwMl9tJ4YoEZJt4qJr5/Hzv48lYjX8vhmIZojU1F0hkFTXV231HJmcaMj 1CcH28LUJdpqvOxvC/ZhkJVj+au958joOU4vUS0PFAhPiPaLGxaQYyrgoe+tbKmT0GUA 9eB1RnZEjXfBmnzh9cLfkGM+TyEf06yczr9N3SSq4R7GEazFqS5fCc/lEtlcoasH7Uyf vRKw== 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=Euz0E6isscBYyFQ42pM4Z2EOYe57hCAo87czLinH3tQ=; b=lf4nr76hQ6ufSzwBAPDdUJI/j9SZOtdBBcLGKcOJl0IpPC+cW2MK6ILctwprpZnaSy aRP1Aa2WQt1U20UvqIRxd3tRkifnt554FzkD+LczqmZJTmXVWcWyus3f2sOpte54fh23 j8a5eSYpHZ5OLald1S2w9NQc30jiR2HiheC5MMlTpt4ALKK2ACS65baNgJZ4wFXhnIf9 5kn+XeOkeNVQf0QSAmNxbFdfQSM03bRzb5Lou2pa2CxuM+YlV6tCkPUZhwFftck5pM0R dGqth4s+qsM/UNnzAzOQaIb73VQPCWcH0mMhctkcS7di+dp2jVlPrOT9pNAVM2Ppy1So v0pA== X-Gm-Message-State: AOAM533rwLq3wcuLiNVU9ejFnCvoR4Y4clInvTFN8NgGdbhd3txgme7C 92gWX8UzM9f9CrFsqFdFsbCvNBseJyBTEw== X-Google-Smtp-Source: ABdhPJxsxqZLYUrdIsPO90PZWWoJEriPEnNBkC+1jahdkQlcQTd45SQhdMkwHyALbQl9HWEmfTsHlA== X-Received: by 2002:a5d:6381:: with SMTP id p1mr9133141wru.310.1629640881263; Sun, 22 Aug 2021 07:01:21 -0700 (PDT) Received: from ?IPv6:2003:ea:8f08:4500:fc53:5e22:f926:c43b? (p200300ea8f084500fc535e22f926c43b.dip0.t-ipconnect.de. [2003:ea:8f08:4500:fc53:5e22:f926:c43b]) by smtp.googlemail.com with ESMTPSA id w14sm11818452wrt.23.2021.08.22.07.01.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 22 Aug 2021 07:01:20 -0700 (PDT) Subject: [PATCH 01/12] sfc: falcon: Read VPD with pci_vpd_alloc() From: Heiner Kallweit To: Bjorn Helgaas , Edward Cree , Martin Habets , Jakub Kicinski , David Miller Cc: "linux-pci@vger.kernel.org" , SCSI development list , "netdev@vger.kernel.org" References: <1ca29408-7bc7-4da5-59c7-87893c9e0442@gmail.com> Message-ID: <2a8d069e-9516-50d8-6520-2614222c8f5f@gmail.com> Date: Sun, 22 Aug 2021 15:48: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: <1ca29408-7bc7-4da5-59c7-87893c9e0442@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This is the same as 5119e20facfa "sfc: Read VPD with pci_vpd_alloc()", just for the falcon chip version. Signed-off-by: Heiner Kallweit --- drivers/net/ethernet/sfc/falcon/efx.c | 30 +++++++++++++-------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/sfc/falcon/efx.c b/drivers/net/ethernet/sfc/falcon/efx.c index c177ea0f3..5ab1e863d 100644 --- a/drivers/net/ethernet/sfc/falcon/efx.c +++ b/drivers/net/ethernet/sfc/falcon/efx.c @@ -2780,22 +2780,18 @@ static void ef4_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. + * Called during probe to display the part number of the installed NIC. */ -#define SFC_VPD_LEN 512 static void ef4_probe_vpd_strings(struct ef4_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; } @@ -2803,7 +2799,7 @@ static void ef4_probe_vpd_strings(struct ef4_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]); @@ -2816,14 +2812,14 @@ static void ef4_probe_vpd_strings(struct ef4_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, @@ -2834,21 +2830,23 @@ static void ef4_probe_vpd_strings(struct ef4_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 Sun Aug 22 13:49:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 501768 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 74CF6C4338F for ; Sun, 22 Aug 2021 14:01:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 55003610E6 for ; Sun, 22 Aug 2021 14:01:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232682AbhHVOCH (ORCPT ); Sun, 22 Aug 2021 10:02:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232398AbhHVOCF (ORCPT ); Sun, 22 Aug 2021 10:02:05 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2744EC061575; Sun, 22 Aug 2021 07:01:24 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id w21-20020a7bc1150000b02902e69ba66ce6so9005694wmi.1; Sun, 22 Aug 2021 07:01:24 -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=qsOp9qT56v4HmRyiUQT77z85goMAUjXgZo93KXhkEYA=; b=IyLT4e7/dWmqfV0jybUvZnJERhpUoDwkkNjo6/RnkQe5nFKxdbrwRVdXUOIazugdGp Ko+LdQy66agMlJkBzUeA99s96wAncLcTsE+MJv39+b0oP9eCXUiVb+L36XJPKEX98yFW LHKpD64cXHtWDPfsYSGQAos8eojqUTemhvqH+dpYXwfwk59ypDHzdv1ukfpatkDVgzUc OvF5A46J9/KmT4rA2B+ko8VpungezGGPX5/Tw/q6smTLH5e45wWsjM9EbvFa79kp1Zqw POz6qyrL2JyAOAtdxry28ePOv9/i/yp4DMrligMBUEudO/ROXoScEkyYzDYubTznPbdR EZDA== 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=qsOp9qT56v4HmRyiUQT77z85goMAUjXgZo93KXhkEYA=; b=TJ3H90PkffuK9dem8WLEN7TovftMg59UYujrGyxx702bZBJdEY7qOEJVGxq0ASRl+G GIVdo1jRhLT7WGqPpZ39h04ICKs5zVZQ96LhW1WvniN+iXBWNziTQrkB/aendpD0+4ff /BI2FXHP7nS5K33/OXAJmq8kjIulNB3T45nZLHhXT3azpAkhV6Bcky7a0bNc9c394DFs sAeSppcdcnW1MpXLvigw/EoTiwc0TqMz2nW+mqGKewilBXUiQAw0PsIrR1L8GgGu+qr7 v1wGD3pbdbUbR955Pe8Ht/JB7ifikbTwIAOX6qMPgIcYPp82N/alirhRazQoldYM/+dC Rwew== X-Gm-Message-State: AOAM530nyR7bbLd41jA9Y6fQwC8f9biJ7CX15erF/9jxkI/5osnyDnAH nO9d/O/nqJDptYnhRMXWfo58lDzZVpr/yA== X-Google-Smtp-Source: ABdhPJzhl8aVEl4lGyc7HUcO/xSXSeD//dwoam8H5WTnKFFNg44w73jOrjRLo4qQmDcKz5yTFW/BzQ== X-Received: by 2002:a05:600c:3792:: with SMTP id o18mr6174780wmr.27.1629640882523; Sun, 22 Aug 2021 07:01:22 -0700 (PDT) Received: from ?IPv6:2003:ea:8f08:4500:fc53:5e22:f926:c43b? (p200300ea8f084500fc535e22f926c43b.dip0.t-ipconnect.de. [2003:ea:8f08:4500:fc53:5e22:f926:c43b]) by smtp.googlemail.com with ESMTPSA id d7sm12362542wrs.39.2021.08.22.07.01.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 22 Aug 2021 07:01:22 -0700 (PDT) Subject: [PATCH 02/12] sfc: falcon: Search VPD with pci_vpd_find_ro_info_keyword() From: Heiner Kallweit To: Bjorn Helgaas , Edward Cree , Martin Habets , Jakub Kicinski , David Miller Cc: "linux-pci@vger.kernel.org" , SCSI development list , "netdev@vger.kernel.org" References: <1ca29408-7bc7-4da5-59c7-87893c9e0442@gmail.com> Message-ID: <898282a1-13bd-17bc-2e9a-d3dcd336b46c@gmail.com> Date: Sun, 22 Aug 2021 15:49:36 +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: <1ca29408-7bc7-4da5-59c7-87893c9e0442@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This is the same as 37838aa437c7 "sfc: Search VPD with pci_vpd_find_ro_info_keyword()", just for the falcon chip version. Signed-off-by: Heiner Kallweit --- drivers/net/ethernet/sfc/falcon/efx.c | 65 ++++++--------------------- 1 file changed, 14 insertions(+), 51 deletions(-) diff --git a/drivers/net/ethernet/sfc/falcon/efx.c b/drivers/net/ethernet/sfc/falcon/efx.c index 5ab1e863d..423bdf812 100644 --- a/drivers/net/ethernet/sfc/falcon/efx.c +++ b/drivers/net/ethernet/sfc/falcon/efx.c @@ -2785,9 +2785,9 @@ static void ef4_pci_remove(struct pci_dev *pci_dev) static void ef4_probe_vpd_strings(struct ef4_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)) { @@ -2795,57 +2795,20 @@ static void ef4_probe_vpd_strings(struct ef4_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_warn(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_warn(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 Sun Aug 22 13:50:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 501486 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=-11.4 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,UNWANTED_LANGUAGE_BODY, 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 9407CC432BE for ; Sun, 22 Aug 2021 14:01:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7B886610E6 for ; Sun, 22 Aug 2021 14:01:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233053AbhHVOCJ (ORCPT ); Sun, 22 Aug 2021 10:02:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232503AbhHVOCG (ORCPT ); Sun, 22 Aug 2021 10:02:06 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F7BFC061575; Sun, 22 Aug 2021 07:01:25 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id x12so21920138wrr.11; Sun, 22 Aug 2021 07:01: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=CpBIYdrsUs68KAyEiAlWKUwUStL3DPn+RhHbfb4DLQg=; b=fA2gLRGoLtDgyz1NUzccwk5dA4tCnsI12ztmJcxdy+Fm8mBQM3oN5kDbeyyfaNyLDx lR6k7NuSmFzaIjj1MLYA+7NxpAIx2XoCik5m7D9NnRagMtnssMnfhlpD0TGWwVagMFga IBbz0tuc+3yLW5jOxra7gheaG6bkWfbGberxwzSDcGyIkMFnk1XbTC7FPn1i4pgftjVF 1JlvH0BMVcHhocrfWEf3icfXY8J7mXCnLsWMTfdlceLn3udla/09Xw3rffQsIQxhKDin 1ut9JqGiw4DzJl/bxlxTNDh20dFGCM9lTzKYwlT1q9YPREM8y1yiW8/5umok9PT6EiGe sq2A== 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=CpBIYdrsUs68KAyEiAlWKUwUStL3DPn+RhHbfb4DLQg=; b=uGhgnbFr4n7ffWxmcomyNHKxCYUoWTsM8Lwu4LcDVwh6axXS+lAJhOUIKJxT+wJerT jczvxDfvt5wfLXhAuEMbMHord0udpGzCeP0cIcfNpdlSUI3j9Wx/94/7omkbgghU9rAE M0J9g6NEl2ZiX/FTq9EHS4cXxXhTFaQvayJQ/DDBM7fNGk8/Up2RPXYnIkrchv32QTv4 YyqySgN/GTGJ0kUlGuao0tuDZRldf2Jd2ZCdjyavYgc6sR46HXYO/5ngRiJdZsnSFss4 W1X9O0p7NfH4g64DL8RHYTMONQnyDOgcjtDeKFUnaVB9uEHfVlfLPm19mKR4/jH1DNEq i/aw== X-Gm-Message-State: AOAM533nWzeOMKlZ1VRzQmH66BTv2BG+3noDzIHAx7SgszFtLkTcB6ws kmxUajcBww6aLoZT+1HGG5EcIA5LrG/sHg== X-Google-Smtp-Source: ABdhPJyay3Lq6dztsuisnUsCmirevaSytLHSZh6xzltwhCab4KrKj6kBMHi4GfP0a/Fqrsqjuv65+g== X-Received: by 2002:a5d:51c6:: with SMTP id n6mr8852259wrv.370.1629640883695; Sun, 22 Aug 2021 07:01:23 -0700 (PDT) Received: from ?IPv6:2003:ea:8f08:4500:fc53:5e22:f926:c43b? (p200300ea8f084500fc535e22f926c43b.dip0.t-ipconnect.de. [2003:ea:8f08:4500:fc53:5e22:f926:c43b]) by smtp.googlemail.com with ESMTPSA id m16sm641870wmq.8.2021.08.22.07.01.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 22 Aug 2021 07:01:23 -0700 (PDT) Subject: [PATCH 03/12] bnx2: Search VPD with pci_vpd_find_ro_info_keyword() From: Heiner Kallweit To: Bjorn Helgaas , Rasesh Mody , GR-Linux-NIC-Dev@marvell.com, Jakub Kicinski , David Miller Cc: "linux-pci@vger.kernel.org" , SCSI development list , "netdev@vger.kernel.org" References: <1ca29408-7bc7-4da5-59c7-87893c9e0442@gmail.com> Message-ID: <7ca2b8b5-4c94-f644-1d80-b2ffb8df2d05@gmail.com> Date: Sun, 22 Aug 2021 15:50:50 +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: <1ca29408-7bc7-4da5-59c7-87893c9e0442@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use pci_vpd_find_ro_info_keyword() to search for keywords in VPD to simplify the code. Signed-off-by: Heiner Kallweit --- drivers/net/ethernet/broadcom/bnx2.c | 33 +++++++--------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnx2.c b/drivers/net/ethernet/broadcom/bnx2.c index 89ee1c0e9..de1a60a95 100644 --- a/drivers/net/ethernet/broadcom/bnx2.c +++ b/drivers/net/ethernet/broadcom/bnx2.c @@ -8033,9 +8033,9 @@ bnx2_get_pci_speed(struct bnx2 *bp) static void bnx2_read_vpd_fw_ver(struct bnx2 *bp) { + unsigned int len; int rc, i, j; u8 *data; - unsigned int block_end, rosize, len; #define BNX2_VPD_NVRAM_OFFSET 0x300 #define BNX2_VPD_LEN 128 @@ -8057,38 +8057,21 @@ bnx2_read_vpd_fw_ver(struct bnx2 *bp) data[i + 3] = data[i + BNX2_VPD_LEN]; } - i = pci_vpd_find_tag(data, BNX2_VPD_LEN, PCI_VPD_LRDT_RO_DATA); - if (i < 0) - goto vpd_done; - - rosize = pci_vpd_lrdt_size(&data[i]); - i += PCI_VPD_LRDT_TAG_SIZE; - block_end = i + rosize; - - if (block_end > BNX2_VPD_LEN) - goto vpd_done; - - j = pci_vpd_find_info_keyword(data, i, rosize, - PCI_VPD_RO_KEYWORD_MFR_ID); + j = pci_vpd_find_ro_info_keyword(data, BNX2_VPD_LEN, + PCI_VPD_RO_KEYWORD_MFR_ID, &len); if (j < 0) goto vpd_done; - len = pci_vpd_info_field_size(&data[j]); - - j += PCI_VPD_INFO_FLD_HDR_SIZE; - if (j + len > block_end || len != 4 || - memcmp(&data[j], "1028", 4)) + if (len != 4 || memcmp(&data[j], "1028", 4)) goto vpd_done; - j = pci_vpd_find_info_keyword(data, i, rosize, - PCI_VPD_RO_KEYWORD_VENDOR0); + j = pci_vpd_find_ro_info_keyword(data, BNX2_VPD_LEN, + PCI_VPD_RO_KEYWORD_VENDOR0, + &len); if (j < 0) goto vpd_done; - len = pci_vpd_info_field_size(&data[j]); - - j += PCI_VPD_INFO_FLD_HDR_SIZE; - if (j + len > block_end || len > BNX2_MAX_VER_SLEN) + if (len > BNX2_MAX_VER_SLEN) goto vpd_done; memcpy(bp->fw_version, &data[j], len); From patchwork Sun Aug 22 13:52:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 501767 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 81187C4320E for ; Sun, 22 Aug 2021 14:01:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 685326135E for ; Sun, 22 Aug 2021 14:01:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233299AbhHVOCM (ORCPT ); Sun, 22 Aug 2021 10:02:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232791AbhHVOCH (ORCPT ); Sun, 22 Aug 2021 10:02:07 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E288C061756; Sun, 22 Aug 2021 07:01:26 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id k8so21969406wrn.3; Sun, 22 Aug 2021 07:01:26 -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=69OYe9tROd3vXXnhUMU2DDb1J6uc6lcFtD6g0FYBe9o=; b=loDZL3yDasHCEoYfQOwAoMH6LusUl/iTl9I8gl+M2A2LUT4fnGNZ/YrngCVGP7uRdV Gattc73fzDLtCzW/jjwcEbo5HTK+guXwHIKyvlJpJb/D0hooJq0lSBk2/JGPPxlNMdH7 HwlmPZDRIp1spurh9ReQSAhc0CTiV8xQgdFalL1M1aFVrAH+LPnlgbuHLWXMDMep8v4o NjmXMrDmOhorccbXStmOpHUhv743yVZei+LfHQ2PH/3P7jPatdoMhkWnvF9d++WFchoB 2HmQTTuAOHJc5Mjajmyg5ybfSNCG4rRxwNqUlRYmTf/bYLT2YxpiX36hz9skqJ1qjv03 F7kA== 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=69OYe9tROd3vXXnhUMU2DDb1J6uc6lcFtD6g0FYBe9o=; b=cOLqrw4p5427ZglzydQAS6ocb9dCl5RSVBTaBWW6CTtJVxyVKQbQFbylnYOPwQ1Zoo c87HPpa0dB2h4TVa2aj0vCLVfLtgQYFWuA6IVe7wARrOb93Lh6NjA9CT18sz4FSILE5o R6ExdyqA/hgORj9k1kRHFj8O09JVW2pJYugkc8wYyurtML1uJoZK0eXN7YDwEvwtE+Xg GsePWXKNnbaRvFYao2o9j5sy5zaJ5aguZjBNa069A76YuQFUgtDxkUyGVYCoXjAGxLk9 dRjwf4oPLgyvj5tSv+nnxmTc0JqWJSQziwsbw3Pd6j2RQlQrVPAjHt+xrFYVuHKhhBN+ zUlg== X-Gm-Message-State: AOAM531bb4EIvwd5I1N8Mscj06VIromdvBo+1+aK8xVrVDg6fjk9anI1 BS6+0owKPy2DPe4N6FXkt2k41sWasu4sMw== X-Google-Smtp-Source: ABdhPJyIK5Ebc6yicAPcW76i5P1gkw0vuBCxEf/WqTLVvVInH6ty65SP9yFNraKXLnfRjkfgvxYSkw== X-Received: by 2002:a5d:6483:: with SMTP id o3mr8801278wri.197.1629640884832; Sun, 22 Aug 2021 07:01:24 -0700 (PDT) Received: from ?IPv6:2003:ea:8f08:4500:fc53:5e22:f926:c43b? (p200300ea8f084500fc535e22f926c43b.dip0.t-ipconnect.de. [2003:ea:8f08:4500:fc53:5e22:f926:c43b]) by smtp.googlemail.com with ESMTPSA id o14sm12033206wrw.17.2021.08.22.07.01.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 22 Aug 2021 07:01:24 -0700 (PDT) Subject: [PATCH 04/12] bnx2: Replace open-coded version with swab32s() From: Heiner Kallweit To: Bjorn Helgaas , Rasesh Mody , GR-Linux-NIC-Dev@marvell.com, Jakub Kicinski , David Miller Cc: "linux-pci@vger.kernel.org" , SCSI development list , "netdev@vger.kernel.org" References: <1ca29408-7bc7-4da5-59c7-87893c9e0442@gmail.com> Message-ID: Date: Sun, 22 Aug 2021 15:52:01 +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: <1ca29408-7bc7-4da5-59c7-87893c9e0442@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use swab32s() instead of open-coding it. Signed-off-by: Heiner Kallweit --- drivers/net/ethernet/broadcom/bnx2.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnx2.c b/drivers/net/ethernet/broadcom/bnx2.c index de1a60a95..599fc1436 100644 --- a/drivers/net/ethernet/broadcom/bnx2.c +++ b/drivers/net/ethernet/broadcom/bnx2.c @@ -8041,21 +8041,16 @@ bnx2_read_vpd_fw_ver(struct bnx2 *bp) #define BNX2_VPD_LEN 128 #define BNX2_MAX_VER_SLEN 30 - data = kmalloc(256, GFP_KERNEL); + data = kmalloc(BNX2_VPD_LEN, GFP_KERNEL); if (!data) return; - rc = bnx2_nvram_read(bp, BNX2_VPD_NVRAM_OFFSET, data + BNX2_VPD_LEN, - BNX2_VPD_LEN); + rc = bnx2_nvram_read(bp, BNX2_VPD_NVRAM_OFFSET, data, BNX2_VPD_LEN); if (rc) goto vpd_done; - for (i = 0; i < BNX2_VPD_LEN; i += 4) { - data[i] = data[i + BNX2_VPD_LEN + 3]; - data[i + 1] = data[i + BNX2_VPD_LEN + 2]; - data[i + 2] = data[i + BNX2_VPD_LEN + 1]; - data[i + 3] = data[i + BNX2_VPD_LEN]; - } + for (i = 0; i < BNX2_VPD_LEN; i += 4) + swab32s((u32 *)&data[i]); j = pci_vpd_find_ro_info_keyword(data, BNX2_VPD_LEN, PCI_VPD_RO_KEYWORD_MFR_ID, &len); From patchwork Sun Aug 22 13:53:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 501485 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 8DC41C43216 for ; Sun, 22 Aug 2021 14:01:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 776C26136F for ; Sun, 22 Aug 2021 14:01:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233413AbhHVOCO (ORCPT ); Sun, 22 Aug 2021 10:02:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233009AbhHVOCI (ORCPT ); Sun, 22 Aug 2021 10:02:08 -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 A05E9C061756; Sun, 22 Aug 2021 07:01:27 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id c129-20020a1c35870000b02902e6b6135279so9052485wma.0; Sun, 22 Aug 2021 07:01:27 -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=/Fh2fLkAINQvq4cNOqL6qOSjii9B6nvN6TPi70VGrkk=; b=dwwQ6WxhbehU1AY9N6lTZ1JkaVX1L6e1Shpgsl8HmnGTmOshzQLDujPzRLYfvBNegK JS53BxoYl7vuCNGW9ZQJXbknRzpZxcxh3WviUplnvLAAuMiumD+vwpn2JXIsrpbdzeNY zmoVQa3V8Y+riyOUNcvWrFIIEakISzVHXuCg94zsSFf3Ay89bcGhC5vUfHf8HksTJC+z JA/mm1afvxCSMcF2Fzn1dkUMWPvbOBn9lDwZZ3I7c/1cCG9L+sGVYC4Wm1P+Uo3dhha9 h/aKHcsqOLj7VnR1vwl/MvS4FhYlA2GzCcjmtLIbTvAj80jkS4Ch11NbCB6LupZEItyy +CxA== 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=/Fh2fLkAINQvq4cNOqL6qOSjii9B6nvN6TPi70VGrkk=; b=q83wmMjBqCg8yZ/Q8FLjk+IGtWcGJl8K4Ht0wHNNwzEMGzigxr2aqlRMG7EpnY2/3D +ZW+7KPOS+MT+Q/H79bHGuaJe3kHagACh6WZgiMtAyzvUsoQRHH6GD0F2HDMQzNdg/Ay edV3DBM3gp15HsWVJvQtT4pu2G12+687X79WqHqHXi0irzNs+pcu3gBIHqRTr7LrddQ9 zQoCIWDQkyW96jayX0Hrt8SpLAY6u4ct1DSbkH46rmY3iBJtM9HSyYC3izSxeqU9iuj9 jWwLwmO1JlGOCaRR6l9GO7prdlXTIKnNMnE+IL5V/Ui5R5CTqhxVoqNHfYvLBJbE6RW4 dszA== X-Gm-Message-State: AOAM530WZdMLPthuoxJ2XYzmLEsCBPn7f24jSC74l0KPvdAUAqXK2DcN uLls9OfJsuNBmxKMYxhG48+9loKfKR3y6Q== X-Google-Smtp-Source: ABdhPJz8yANcHjaGyqQGaY4JSONerEbzonpm3dqQlBV5QmGMTLV4Qmi+BW9OiLV6fzx34H0/2s8Ycw== X-Received: by 2002:a1c:9acc:: with SMTP id c195mr7114943wme.69.1629640885971; Sun, 22 Aug 2021 07:01:25 -0700 (PDT) Received: from ?IPv6:2003:ea:8f08:4500:fc53:5e22:f926:c43b? (p200300ea8f084500fc535e22f926c43b.dip0.t-ipconnect.de. [2003:ea:8f08:4500:fc53:5e22:f926:c43b]) by smtp.googlemail.com with ESMTPSA id b4sm1114901wrp.33.2021.08.22.07.01.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 22 Aug 2021 07:01:25 -0700 (PDT) Subject: [PATCH 05/12] bnx2x: Read VPD with pci_vpd_alloc() From: Heiner Kallweit To: Bjorn Helgaas , Ariel Elior , Sudarsana Kalluru , GR-everest-linux-l2@marvell.com, Jakub Kicinski , =?utf-8?q?David_H=C3=A4rdeman?= Cc: "linux-pci@vger.kernel.org" , "netdev@vger.kernel.org" References: <1ca29408-7bc7-4da5-59c7-87893c9e0442@gmail.com> Message-ID: <821a334d-ff9d-386e-5f42-9b620ab3dbfa@gmail.com> Date: Sun, 22 Aug 2021 15:53:23 +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: <1ca29408-7bc7-4da5-59c7-87893c9e0442@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use pci_vpd_alloc() to dynamically allocate a properly sized buffer and read the full VPD data into it. This simplifies the code, and we no longer have to make assumptions about VPD size. Signed-off-by: Heiner Kallweit Reported-by: kernel test robot --- drivers/net/ethernet/broadcom/bnx2x/bnx2x.h | 1 - .../net/ethernet/broadcom/bnx2x/bnx2x_main.c | 44 +++++-------------- 2 files changed, 10 insertions(+), 35 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h index d04994840..e789430f4 100644 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h @@ -2407,7 +2407,6 @@ void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, #define ETH_MAX_RX_CLIENTS_E2 ETH_MAX_RX_CLIENTS_E1H #endif -#define BNX2X_VPD_LEN 128 #define VENDOR_ID_LEN 4 #define VF_ACQUIRE_THRESH 3 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c index 6d9813491..0466adf8d 100644 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c @@ -12189,50 +12189,29 @@ static int bnx2x_get_hwinfo(struct bnx2x *bp) static void bnx2x_read_fwinfo(struct bnx2x *bp) { - int cnt, i, block_end, rodi; - char vpd_start[BNX2X_VPD_LEN+1]; + int i, block_end, rodi; char str_id_reg[VENDOR_ID_LEN+1]; char str_id_cap[VENDOR_ID_LEN+1]; - char *vpd_data; - char *vpd_extended_data = NULL; - u8 len; + unsigned int vpd_len; + u8 *vpd_data, len; - cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start); memset(bp->fw_ver, 0, sizeof(bp->fw_ver)); - if (cnt < BNX2X_VPD_LEN) - goto out_not_found; + vpd_data = pci_vpd_alloc(bp->pdev, &vpd_len); + if (IS_ERR(vpd_data)) + return; /* VPD RO tag should be first tag after identifier string, hence * we should be able to find it in first BNX2X_VPD_LEN chars */ - i = pci_vpd_find_tag(vpd_start, BNX2X_VPD_LEN, PCI_VPD_LRDT_RO_DATA); + i = pci_vpd_find_tag(vpd_data, vpd_len, PCI_VPD_LRDT_RO_DATA); if (i < 0) goto out_not_found; block_end = i + PCI_VPD_LRDT_TAG_SIZE + - pci_vpd_lrdt_size(&vpd_start[i]); - + pci_vpd_lrdt_size(&vpd_data[i]); i += PCI_VPD_LRDT_TAG_SIZE; - if (block_end > BNX2X_VPD_LEN) { - vpd_extended_data = kmalloc(block_end, GFP_KERNEL); - if (vpd_extended_data == NULL) - goto out_not_found; - - /* read rest of vpd image into vpd_extended_data */ - memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN); - cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN, - block_end - BNX2X_VPD_LEN, - vpd_extended_data + BNX2X_VPD_LEN); - if (cnt < (block_end - BNX2X_VPD_LEN)) - goto out_not_found; - vpd_data = vpd_extended_data; - } else - vpd_data = vpd_start; - - /* now vpd_data holds full vpd content in both cases */ - rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end, PCI_VPD_RO_KEYWORD_MFR_ID); if (rodi < 0) @@ -12258,17 +12237,14 @@ static void bnx2x_read_fwinfo(struct bnx2x *bp) rodi += PCI_VPD_INFO_FLD_HDR_SIZE; - if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) { + if (len < 32 && (len + rodi) <= vpd_len) { memcpy(bp->fw_ver, &vpd_data[rodi], len); bp->fw_ver[len] = ' '; } } - kfree(vpd_extended_data); - return; } out_not_found: - kfree(vpd_extended_data); - return; + kfree(vpd_data); } static void bnx2x_set_modes_bitmap(struct bnx2x *bp) From patchwork Sun Aug 22 13:54:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 501766 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 9AF06C43214 for ; Sun, 22 Aug 2021 14:01:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8EB886128A for ; Sun, 22 Aug 2021 14:01:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233520AbhHVOCQ (ORCPT ); Sun, 22 Aug 2021 10:02:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233122AbhHVOCJ (ORCPT ); Sun, 22 Aug 2021 10:02:09 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B545DC061756; Sun, 22 Aug 2021 07:01:28 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id f5so21903561wrm.13; Sun, 22 Aug 2021 07:01:28 -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=GhA3sTWdBctF9+XF0H4+34NcfxyTAeGY2X6mJWKS4kY=; b=jUSmWVAgEhYpz3iJ8axdw43hDeqRJNMl4rEKQZvKg5+Bboh6POi4+InERI2zRp6l3z n2G3sa9bMdqe80YpnG/kXZT5JWddHQ709TsNXRvQnUNdDjBO8AKYPhO2dMPLZvfgSpZ0 VQHEtiUf5GxNr8DeKTp5fwZT2CxOq/BW19ou92xP0PzfKO05bxxpRzPLV1iFR7mEr6vN UXf8wYVOSnwBtSxFwCAe9WESlSDL5bw96BpHNLrfJ27lWx8AqfaCJohiTFtBV3JlqK5t HCOfc3I6ZnV6fnDhJkuyuQ0NqGAYcklcGcwI61sQSdYPdpsuk5Oaga6k7L+yZ2myWdxa C7zg== 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=GhA3sTWdBctF9+XF0H4+34NcfxyTAeGY2X6mJWKS4kY=; b=JApJ9cAbEKVUwQeDyMXzq+oN8zOiXH2gloa6emz08BRf4GJrlI+/kQruNGQyYrI610 /9P2y4zFyivLg7QNSQBehDRbpB0FIqSSvNVUpUBXv9LSfsrDv2HS4o7g/84X8UaepKXs 9KmbPNW35Ufx7rifEl+raMiXMrdXMcxH590jwpQeWwK8tR32X3891oAhmKU4cq23WjtZ Jjv/nySGxByBd/OmbcX/jmQbPDYsIOs5RcaIoY4wSl1oDnFN+yIJjQYuFGVWPle5+Jhm SwQhW81d9jYgLA7JocvuGvh9gETQpabrk29py2cwVbkE3rqUQ9ydtdIYNwZJR2fD9O80 6xyw== X-Gm-Message-State: AOAM531GEe6OHrJLtHfgK8Q/pDeTQPQ/Ei8Kly+kOllbFPsvy32XzSXQ u1h32F/Q05k2s5R+chjbnQiTMZVXYcHxCw== X-Google-Smtp-Source: ABdhPJwzuftrtv/gnZaUzK2aqhteQyQFR1+wjAg5sHZjY1P7MCE0R4DE9WA3WGNlin0S0t47MhG5Zw== X-Received: by 2002:adf:fd51:: with SMTP id h17mr6569599wrs.178.1629640887149; Sun, 22 Aug 2021 07:01:27 -0700 (PDT) Received: from ?IPv6:2003:ea:8f08:4500:fc53:5e22:f926:c43b? (p200300ea8f084500fc535e22f926c43b.dip0.t-ipconnect.de. [2003:ea:8f08:4500:fc53:5e22:f926:c43b]) by smtp.googlemail.com with ESMTPSA id y15sm1680262wmi.18.2021.08.22.07.01.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 22 Aug 2021 07:01:26 -0700 (PDT) Subject: [PATCH 06/12] bnx2x: Search VPD with pci_vpd_find_ro_info_keyword() From: Heiner Kallweit To: Bjorn Helgaas , Ariel Elior , Sudarsana Kalluru , GR-everest-linux-l2@marvell.com, Jakub Kicinski , David Miller Cc: "linux-pci@vger.kernel.org" , "netdev@vger.kernel.org" References: <1ca29408-7bc7-4da5-59c7-87893c9e0442@gmail.com> Message-ID: Date: Sun, 22 Aug 2021 15:54:23 +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: <1ca29408-7bc7-4da5-59c7-87893c9e0442@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use pci_vpd_find_ro_info_keyword() to search for keywords in VPD to simplify the code. str_id_reg and str_id_cap hold the same string and are used in the same comparison. This doesn't make sense, use one string str_id instead. Signed-off-by: Heiner Kallweit --- .../net/ethernet/broadcom/bnx2x/bnx2x_main.c | 57 +++++-------------- 1 file changed, 15 insertions(+), 42 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c index 0466adf8d..2c7bfc416 100644 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c @@ -12189,11 +12189,10 @@ static int bnx2x_get_hwinfo(struct bnx2x *bp) static void bnx2x_read_fwinfo(struct bnx2x *bp) { - int i, block_end, rodi; - char str_id_reg[VENDOR_ID_LEN+1]; - char str_id_cap[VENDOR_ID_LEN+1]; - unsigned int vpd_len; - u8 *vpd_data, len; + char str_id[VENDOR_ID_LEN + 1]; + unsigned int vpd_len, kw_len; + u8 *vpd_data; + int rodi; memset(bp->fw_ver, 0, sizeof(bp->fw_ver)); @@ -12201,46 +12200,20 @@ static void bnx2x_read_fwinfo(struct bnx2x *bp) if (IS_ERR(vpd_data)) return; - /* VPD RO tag should be first tag after identifier string, hence - * we should be able to find it in first BNX2X_VPD_LEN chars - */ - i = pci_vpd_find_tag(vpd_data, vpd_len, PCI_VPD_LRDT_RO_DATA); - if (i < 0) - goto out_not_found; - - block_end = i + PCI_VPD_LRDT_TAG_SIZE + - pci_vpd_lrdt_size(&vpd_data[i]); - i += PCI_VPD_LRDT_TAG_SIZE; - - rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end, - PCI_VPD_RO_KEYWORD_MFR_ID); - if (rodi < 0) - goto out_not_found; - - len = pci_vpd_info_field_size(&vpd_data[rodi]); - - if (len != VENDOR_ID_LEN) + rodi = pci_vpd_find_ro_info_keyword(vpd_data, vpd_len, + PCI_VPD_RO_KEYWORD_MFR_ID, &kw_len); + if (rodi < 0 || kw_len != VENDOR_ID_LEN) goto out_not_found; - rodi += PCI_VPD_INFO_FLD_HDR_SIZE; - /* vendor specific info */ - snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL); - snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL); - if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) || - !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) { - - rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end, - PCI_VPD_RO_KEYWORD_VENDOR0); - if (rodi >= 0) { - len = pci_vpd_info_field_size(&vpd_data[rodi]); - - rodi += PCI_VPD_INFO_FLD_HDR_SIZE; - - if (len < 32 && (len + rodi) <= vpd_len) { - memcpy(bp->fw_ver, &vpd_data[rodi], len); - bp->fw_ver[len] = ' '; - } + snprintf(str_id, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL); + if (!strncmp(str_id, &vpd_data[rodi], VENDOR_ID_LEN)) { + rodi = pci_vpd_find_ro_info_keyword(vpd_data, vpd_len, + PCI_VPD_RO_KEYWORD_VENDOR0, + &kw_len); + if (rodi >= 0 && kw_len < sizeof(bp->fw_ver)) { + memcpy(bp->fw_ver, &vpd_data[rodi], kw_len); + bp->fw_ver[kw_len] = ' '; } } out_not_found: From patchwork Sun Aug 22 13:55:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 501484 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 59BD9C00144 for ; Sun, 22 Aug 2021 14:01:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 405A7610E6 for ; Sun, 22 Aug 2021 14:01:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233122AbhHVOCW (ORCPT ); Sun, 22 Aug 2021 10:02:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233244AbhHVOCM (ORCPT ); Sun, 22 Aug 2021 10:02:12 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F06C1C06175F; Sun, 22 Aug 2021 07:01:30 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id f5so21903692wrm.13; Sun, 22 Aug 2021 07:01:30 -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=EnYMLu3bLS8APgjASOjSEYt7FoYkDIJwe7q4cBAmVQk=; b=GZXbBbPYnuCE2fsTYmDNLccrUeRTMHMo7shzujcxhlB/DcAvRlguC4lRCpvN7WrCyB G8DRc9jGaddclUaYSeI2CBxIQUaagOLmkh3s+Mcqv/B80cJzXEOgIVnYrhvTtjJQVJds Juuh6KQbNout+9uBUyJ9HTN4nmTQvjJneu19065xHdjJ1jczSWZPcrDRbNQkOdtXol/l u3wxICK9d44apLzS0y2li4OXSPk/+bIDH3LYUzYAkKuXch/NA30+89vvX2H5YSJ8aOeY FArbGDDzZlbxGpOK9ujndJ6shhpYQ7YZW9MkFHR0dL9nbBkWBhvsVFDpJnk+HkVqaVd3 rgsQ== 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=EnYMLu3bLS8APgjASOjSEYt7FoYkDIJwe7q4cBAmVQk=; b=a0nAqluSVQNB4p2D7iWXCBlzZhGUtb+BWDYpo/P7jJGqTeKaUq4KOA5B9htZtIqMNR pMo4p9X1WSX9/uDEQJ4BHju+dzH0dlUUeg1D3w1NZkUYo6IDbMSTPpXkPSKK5cO1+W1X CNx2EEhmiPb0QDmLz2P0x4/Tqbah4js/sOWfF27aOFZqLWMAcsbKuMEsRGhg6/9j1m38 M0Tjl+yV/4vOmQFY2UMsLMxk9wcvvHQPENSG4TOYtg6+J4WQ9Sp50HMIX7QVLVk3Xe43 BrJEtL+Nkn51AWHRu5e6Uke2zjciGh7WSkKmdDoIMIFb0MpViToNx8iw7ethV4TVzK5k UZ9w== X-Gm-Message-State: AOAM533zmPb2bcKPtM9xdcjp4jRoCqe2/Y8fge5fDshve834G/AOQEYE r1bBA+QsMWXk3awtLqeErZ0qq8nIhVQShg== X-Google-Smtp-Source: ABdhPJyXJaWGFa8Bw5s6sjp12lxvolmrG8hLqT9uUaXw1nXDDt4X8qikLz9JOJarzGBm0c71HTDH6w== X-Received: by 2002:a05:6000:22d:: with SMTP id l13mr8873114wrz.410.1629640889403; Sun, 22 Aug 2021 07:01:29 -0700 (PDT) Received: from ?IPv6:2003:ea:8f08:4500:fc53:5e22:f926:c43b? (p200300ea8f084500fc535e22f926c43b.dip0.t-ipconnect.de. [2003:ea:8f08:4500:fc53:5e22:f926:c43b]) by smtp.googlemail.com with ESMTPSA id d4sm12264453wrz.35.2021.08.22.07.01.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 22 Aug 2021 07:01:27 -0700 (PDT) Subject: [PATCH 07/12] bnxt: Read VPD with pci_vpd_alloc() From: Heiner Kallweit To: Bjorn Helgaas , Michael Chan , Jakub Kicinski , David Miller Cc: "linux-pci@vger.kernel.org" , "netdev@vger.kernel.org" References: <1ca29408-7bc7-4da5-59c7-87893c9e0442@gmail.com> Message-ID: <62522a24-f39a-2b35-1577-1fbb41695bed@gmail.com> Date: Sun, 22 Aug 2021 15:55:23 +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: <1ca29408-7bc7-4da5-59c7-87893c9e0442@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use pci_vpd_alloc() to dynamically allocate a properly sized buffer and read the full VPD data into it. This simplifies the code, and we no longer have to make assumptions about VPD size. Signed-off-by: Heiner Kallweit --- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index 893bdaf03..00a9b7126 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -13171,22 +13171,17 @@ static int bnxt_init_mac_addr(struct bnxt *bp) return rc; } -#define BNXT_VPD_LEN 512 static void bnxt_vpd_read_info(struct bnxt *bp) { struct pci_dev *pdev = bp->pdev; int i, len, pos, ro_size, size; - ssize_t vpd_size; + unsigned int vpd_size; u8 *vpd_data; - vpd_data = kmalloc(BNXT_VPD_LEN, GFP_KERNEL); - if (!vpd_data) + vpd_data = pci_vpd_alloc(pdev, &vpd_size); + if (IS_ERR(vpd_data)) { + pci_warn(pdev, "Unable to read VPD\n"); return; - - vpd_size = pci_read_vpd(pdev, 0, BNXT_VPD_LEN, vpd_data); - if (vpd_size <= 0) { - netdev_err(bp->dev, "Unable to read VPD\n"); - goto exit; } i = pci_vpd_find_tag(vpd_data, vpd_size, PCI_VPD_LRDT_RO_DATA); From patchwork Sun Aug 22 13:56:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 501765 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 D7DFCC19F33 for ; Sun, 22 Aug 2021 14:01:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B844861284 for ; Sun, 22 Aug 2021 14:01:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233791AbhHVOCX (ORCPT ); Sun, 22 Aug 2021 10:02:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233569AbhHVOCT (ORCPT ); Sun, 22 Aug 2021 10:02:19 -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 1694FC061764; Sun, 22 Aug 2021 07:01:32 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id c8-20020a7bc008000000b002e6e462e95fso12230231wmb.2; Sun, 22 Aug 2021 07:01:32 -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=cQmhOSk8nRoBGUH/oIz/pxzaMjxJu0UzyDUdrY2chFM=; b=WK/MKhhMqT8T774X8c4BN0sDzTxROtezMCDV/xOyIo+wWhxSg3uDO65pGvJ+sK4TRY 51NII4XC6E0RYiccfjfQ/MmfPdBX0Q/7cY4Px7pb8XC2nANjc1u3fXldKxfgihkWgtZA SfbPWTtaEJfavHNt4C0Ejah8lUUAx+Yp1yek4DSeeApufd/KP0lZCBWtsYrPxKjFFTVh PFjoki0AVX05m41+SVB5XSJdl+Ol5MwT5Wwa1bVvh7PlpkpIuCcT/BdCsNIyLmDNEC5N BOpH4P4g4UeAcNaVdDUlyLT7H9JltfoQvU+qfKly2K1KvBVMkTLJU6a7hglOeC9COTeR QjoQ== 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=cQmhOSk8nRoBGUH/oIz/pxzaMjxJu0UzyDUdrY2chFM=; b=pdwXdNEF6LspdcS2LOqgXbKRg9LYOSkmYFLG5UYfleB8M7W7CY2ShE6TjfYR2qRVdr rKp2mU0MkQmsGl64t2QkNVuj8OdHOpX/0bX5i4RyvuTBSkyHRTX9qMe/nFgwjZymUj1R rwfEvsq3lFTx70vNZpM07eoz74oP6IcMr4h1K+LvFCFcFsOuCxixKP3YRiVoADHnDqyG Q88XQ4m0RWexpT6XvDKveqdiq4HvxFDlxEjnVSeP/pgXGEjA8wPWMfLw6DdpP79oJ31Y Y/6BLZ6Gj9nkgxBZYpsj90ga3r5N8Ow9HE/+GItW2jeDpeFvN5JZr3RjuA4HLp4IXgaH 7kFQ== X-Gm-Message-State: AOAM5312zBc8og0k3I5VUZj7URsSrR64ZTLbRJgq8Am65q3WzMH2NEJf Umd66by6bwpZ0D8CAL8FL96Q/UAC6Oj1OA== X-Google-Smtp-Source: ABdhPJxGy90XgokmWtzC10wWOFMJvPk1J8eDfHV+g7fP9j5JWik/hdWaQXta1iKU+GwH+NODzmcB2w== X-Received: by 2002:a05:600c:3b0e:: with SMTP id m14mr12410237wms.34.1629640890470; Sun, 22 Aug 2021 07:01:30 -0700 (PDT) Received: from ?IPv6:2003:ea:8f08:4500:fc53:5e22:f926:c43b? (p200300ea8f084500fc535e22f926c43b.dip0.t-ipconnect.de. [2003:ea:8f08:4500:fc53:5e22:f926:c43b]) by smtp.googlemail.com with ESMTPSA id p9sm6866472wmq.40.2021.08.22.07.01.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 22 Aug 2021 07:01:30 -0700 (PDT) Subject: [PATCH 08/12] bnxt: Search VPD with pci_vpd_find_ro_info_keyword() From: Heiner Kallweit To: Bjorn Helgaas , Michael Chan , Jakub Kicinski , David Miller Cc: "linux-pci@vger.kernel.org" , "netdev@vger.kernel.org" References: <1ca29408-7bc7-4da5-59c7-87893c9e0442@gmail.com> Message-ID: Date: Sun, 22 Aug 2021 15:56:24 +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: <1ca29408-7bc7-4da5-59c7-87893c9e0442@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use pci_vpd_find_ro_info_keyword() to search for keywords in VPD to simplify the code. Signed-off-by: Heiner Kallweit --- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 38 ++++++----------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index 00a9b7126..5df00a520 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -13174,8 +13174,8 @@ static int bnxt_init_mac_addr(struct bnxt *bp) static void bnxt_vpd_read_info(struct bnxt *bp) { struct pci_dev *pdev = bp->pdev; - int i, len, pos, ro_size, size; - unsigned int vpd_size; + unsigned int vpd_size, kw_len; + int pos, size; u8 *vpd_data; vpd_data = pci_vpd_alloc(pdev, &vpd_size); @@ -13184,42 +13184,22 @@ static void bnxt_vpd_read_info(struct bnxt *bp) return; } - i = pci_vpd_find_tag(vpd_data, vpd_size, PCI_VPD_LRDT_RO_DATA); - if (i < 0) { - netdev_err(bp->dev, "VPD READ-Only not found\n"); - goto exit; - } - - ro_size = pci_vpd_lrdt_size(&vpd_data[i]); - i += PCI_VPD_LRDT_TAG_SIZE; - if (i + ro_size > vpd_size) - goto exit; - - pos = pci_vpd_find_info_keyword(vpd_data, i, ro_size, - PCI_VPD_RO_KEYWORD_PARTNO); + pos = pci_vpd_find_ro_info_keyword(vpd_data, vpd_size, + PCI_VPD_RO_KEYWORD_PARTNO, &kw_len); if (pos < 0) goto read_sn; - len = pci_vpd_info_field_size(&vpd_data[pos]); - pos += PCI_VPD_INFO_FLD_HDR_SIZE; - if (len + pos > vpd_size) - goto read_sn; - - size = min(len, BNXT_VPD_FLD_LEN - 1); + size = min_t(int, kw_len, BNXT_VPD_FLD_LEN - 1); memcpy(bp->board_partno, &vpd_data[pos], size); read_sn: - pos = pci_vpd_find_info_keyword(vpd_data, i, ro_size, - PCI_VPD_RO_KEYWORD_SERIALNO); + pos = pci_vpd_find_ro_info_keyword(vpd_data, vpd_size, + PCI_VPD_RO_KEYWORD_SERIALNO, + &kw_len); if (pos < 0) goto exit; - len = pci_vpd_info_field_size(&vpd_data[pos]); - pos += PCI_VPD_INFO_FLD_HDR_SIZE; - if (len + pos > vpd_size) - goto exit; - - size = min(len, BNXT_VPD_FLD_LEN - 1); + size = min_t(int, kw_len, BNXT_VPD_FLD_LEN - 1); memcpy(bp->board_serialno, &vpd_data[pos], size); exit: kfree(vpd_data); From patchwork Sun Aug 22 13:57:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 501483 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 5ECDFC4320E for ; Sun, 22 Aug 2021 14:01:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 43BD5610E6 for ; Sun, 22 Aug 2021 14:01:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233885AbhHVOCZ (ORCPT ); Sun, 22 Aug 2021 10:02:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233608AbhHVOCU (ORCPT ); Sun, 22 Aug 2021 10:02:20 -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 2742BC06179A; Sun, 22 Aug 2021 07:01:33 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id k8so21969759wrn.3; Sun, 22 Aug 2021 07:01:33 -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=+0IRWd8qcrzfdJzo7TwSuHReOvCmzpH73e603jr2UKA=; b=o9JlqtELaYOjXCpljBT1K3bmAVNymZVHCWbDooNz6memSBOiIoQ6UWTABTZopD1N93 uyRiUfzuWS/IFL7WX5c96ofw4/CjGk+CJCAxv5SJwV0PIlfjEIto6yeZ7Ble9FI+z4sQ txmLG1CnA45RRDnA5oCdM0yc7gCGO/lrsmtbab2pkjCGM+7hQEr23qmQXnAKUGd2uYu0 iZBUp/SFXIKDkEdCsB71l+s7bhfo0Ox/y0OgNo1ZICcYa6LMu26VCgvHAERkGHc8H+8M f6ekeMUKWcglFy0Q/OvQYHPY7oseAs5oyxKA2xR+0EEq9VIangleJlTxSndQf82gwL79 LL1g== 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=+0IRWd8qcrzfdJzo7TwSuHReOvCmzpH73e603jr2UKA=; b=KK2o+RQua42WjtNb39tGi764K/JX0EAMpzNTfgQdhioD0EnRGeot+gxSkyqzfx2jbu 8gvQIz/oX/Cv7wlxUNn7etDC7Tpf8Opb6e1Zn0XdIfvePw/IsuyQRbw8tAl41R/zl1Yh JE4EKaeu15LKas54VYC3jGiAHPC5rV33EyA9Dgiug47giIlTU3MTdFW+xzSSiJy/UHiI +NLAgW2mwUl1g7PtOMTsFnAcRYXMlbQum0XOmVkQV5vqYF1ZdJEGvtoo9h1a8H7d1TCN GnaQWBQGrarwUiYO+8DsdkQbgduRdbuLbyfGf9mi4iuTkT0JiQMYgHtF1nnhSsaidLp8 U2gQ== X-Gm-Message-State: AOAM530KUe+dOv2Lx40bGSWUcX+VxsuEy1h8wcXWB1bz+ziV7BtONxXS DKMXCJdNsWCa/5HRydhrVe/p7Cq3M9aZEQ== X-Google-Smtp-Source: ABdhPJzV5ChAJYQXNRquCR77YhSexY9jbvNSKwV6FOGcUWNFikup6PwrClRu3OG7q2v0TL70LSlodA== X-Received: by 2002:a5d:4643:: with SMTP id j3mr1864491wrs.138.1629640891525; Sun, 22 Aug 2021 07:01:31 -0700 (PDT) Received: from ?IPv6:2003:ea:8f08:4500:fc53:5e22:f926:c43b? (p200300ea8f084500fc535e22f926c43b.dip0.t-ipconnect.de. [2003:ea:8f08:4500:fc53:5e22:f926:c43b]) by smtp.googlemail.com with ESMTPSA id y4sm6638981wmi.22.2021.08.22.07.01.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 22 Aug 2021 07:01:31 -0700 (PDT) Subject: [PATCH 09/12] cxgb4: Validate VPD checksum with pci_vpd_check_csum() From: Heiner Kallweit To: Bjorn Helgaas , Raju Rangoju , Jakub Kicinski , David Miller Cc: "linux-pci@vger.kernel.org" , "netdev@vger.kernel.org" References: <1ca29408-7bc7-4da5-59c7-87893c9e0442@gmail.com> Message-ID: <70404ece-0036-c0ce-f824-f5637e54115e@gmail.com> Date: Sun, 22 Aug 2021 15:57:27 +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: <1ca29408-7bc7-4da5-59c7-87893c9e0442@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Validate the VPD checksum with pci_vpd_check_csum() to simplify the code. Signed-off-by: Heiner Kallweit --- drivers/net/ethernet/chelsio/cxgb4/t4_hw.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c index 6606fb8b3..1ae3ee994 100644 --- a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c +++ b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c @@ -2745,7 +2745,7 @@ int t4_get_raw_vpd_params(struct adapter *adapter, struct vpd_params *p) { int i, ret = 0, addr; int ec, sn, pn, na; - u8 *vpd, csum, base_val = 0; + u8 *vpd, base_val = 0; unsigned int vpdr_len, kw_offset, id_len; vpd = vmalloc(VPD_LEN); @@ -2800,13 +2800,9 @@ int t4_get_raw_vpd_params(struct adapter *adapter, struct vpd_params *p) var += PCI_VPD_INFO_FLD_HDR_SIZE; \ } while (0) - FIND_VPD_KW(i, "RV"); - for (csum = 0; i >= 0; i--) - csum += vpd[i]; - - if (csum) { - dev_err(adapter->pdev_dev, - "corrupted VPD EEPROM, actual csum %u\n", csum); + 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; } From patchwork Sun Aug 22 13:58: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: 501764 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 ACAE6C4338F for ; Sun, 22 Aug 2021 14:01:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 90A6061207 for ; Sun, 22 Aug 2021 14:01:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234054AbhHVOCa (ORCPT ); Sun, 22 Aug 2021 10:02:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233631AbhHVOCU (ORCPT ); Sun, 22 Aug 2021 10:02:20 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93C20C0617AD; Sun, 22 Aug 2021 07:01:34 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id g138so8839677wmg.4; Sun, 22 Aug 2021 07:01:34 -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=quc2glksFzIpYe/71nWFAnXvhf2MCzTs4gt4GOznpHY=; b=C5WPzJHGaKKwSyH1L7XF1ewVO2Sg4gwHXdCSzOl6tOXRTUp96aRQ57g5ZMWT53IgK8 ReE1RHUOoYFDtwlLHLc5iVIpOj923Yu73Tkin2KeKtSPYQgGksW1z4k0XdjvCq2CtStw 8BjlKb2HATWtDxrMekqg6Re4ARPVfNBhw/3JZF/3wpIufPvjuIYtydWi2yTwY5BzSeaC QNDU/YMVOLKV3EycWy71bjEEKAZ3O89FJmJwZ4WgvjEWM3yyKi25YZi8xN9MRpoOgQdZ glyTRZM8Reby66hydsiWICSbR4/G911y1G07eVZx3B6l3hhzhuvOGiF28X+PbnHbrD/R JvVg== 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=quc2glksFzIpYe/71nWFAnXvhf2MCzTs4gt4GOznpHY=; b=RxhO50EcP02ITfWKWyo5DlNuKiNnqNaTwOkXF3zYjUkZ9Gmof10YOT7aHf2qwaW9ah 1Opn/l/cQqjYqAiC8ro7CBkQOZfDqm+RvjdlFNPqJrkNZ3pzMYS2eMSRsz8jk9WrFBnX Kb9gW2IVOdrVMUHI7UjdykXLalQ6m5wN/34oY3nhpKk3Ae46q70+PQKo5RzJqwIXwZ3s zr15frZlcI3LfVnje8i+9hXnbeLLCdSpJ5CkZtDfGbiHYZ1+AEoKkejHEnB2I1S6I7Rw xO3Jk9L9Q/r8en8epq+2oyZ9gGeuUEfCQwUW3vSS24R8nJS3NmPuvE/Mot8tyFSzokdk 3rHw== X-Gm-Message-State: AOAM533qohsxfeYdlzWW6I/bNogrkUVtjUWT4UxyuD68ekirLxh0ULJF tQvm/cIShiqe8/imFmxd2PECzqY3VyQFyA== X-Google-Smtp-Source: ABdhPJwOOmBcA3shwYluKb7pEMCw+OL9YzdLlqPut57f6XKbaR4MZCbdtqtheeQj4VXJBgrsGgDsmQ== X-Received: by 2002:a05:600c:3b98:: with SMTP id n24mr12102835wms.11.1629640892647; Sun, 22 Aug 2021 07:01:32 -0700 (PDT) Received: from ?IPv6:2003:ea:8f08:4500:fc53:5e22:f926:c43b? (p200300ea8f084500fc535e22f926c43b.dip0.t-ipconnect.de. [2003:ea:8f08:4500:fc53:5e22:f926:c43b]) by smtp.googlemail.com with ESMTPSA id d4sm12264651wrz.35.2021.08.22.07.01.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 22 Aug 2021 07:01:32 -0700 (PDT) Subject: [PATCH 10/12] cxgb4: Remove unused vpd_param member ec From: Heiner Kallweit To: Bjorn Helgaas , Raju Rangoju , Jakub Kicinski , David Miller Cc: "linux-pci@vger.kernel.org" , "netdev@vger.kernel.org" References: <1ca29408-7bc7-4da5-59c7-87893c9e0442@gmail.com> Message-ID: <30648e95-bfb9-9af3-0c8f-dd3e34df8b6b@gmail.com> Date: Sun, 22 Aug 2021 15:58: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: <1ca29408-7bc7-4da5-59c7-87893c9e0442@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Member ec isn't used, so remove it. Signed-off-by: Heiner Kallweit --- drivers/net/ethernet/chelsio/cxgb4/cxgb4.h | 2 -- drivers/net/ethernet/chelsio/cxgb4/t4_hw.c | 5 +---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4.h b/drivers/net/ethernet/chelsio/cxgb4/cxgb4.h index 9058f09f9..ecea3cdd3 100644 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4.h @@ -84,7 +84,6 @@ extern struct mutex uld_mutex; enum { MAX_NPORTS = 4, /* max # of ports */ SERNUM_LEN = 24, /* Serial # length */ - EC_LEN = 16, /* E/C length */ ID_LEN = 16, /* ID length */ PN_LEN = 16, /* Part Number length */ MACADDR_LEN = 12, /* MAC Address length */ @@ -391,7 +390,6 @@ struct tp_params { struct vpd_params { unsigned int cclk; - u8 ec[EC_LEN + 1]; u8 sn[SERNUM_LEN + 1]; u8 id[ID_LEN + 1]; u8 pn[PN_LEN + 1]; diff --git a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c index 1ae3ee994..2aeb2f80f 100644 --- a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c +++ b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c @@ -2744,7 +2744,7 @@ 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 ec, sn, pn, na; + int sn, pn, na; u8 *vpd, base_val = 0; unsigned int vpdr_len, kw_offset, id_len; @@ -2807,7 +2807,6 @@ int t4_get_raw_vpd_params(struct adapter *adapter, struct vpd_params *p) goto out; } - FIND_VPD_KW(ec, "EC"); FIND_VPD_KW(sn, "SN"); FIND_VPD_KW(pn, "PN"); FIND_VPD_KW(na, "NA"); @@ -2815,8 +2814,6 @@ int t4_get_raw_vpd_params(struct adapter *adapter, struct vpd_params *p) memcpy(p->id, vpd + PCI_VPD_LRDT_TAG_SIZE, id_len); strim(p->id); - memcpy(p->ec, vpd + ec, EC_LEN); - strim(p->ec); 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); From patchwork Sun Aug 22 13:59:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 501482 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 3FA54C432BE for ; Sun, 22 Aug 2021 14:01:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2030B61207 for ; Sun, 22 Aug 2021 14:01:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234187AbhHVOCg (ORCPT ); Sun, 22 Aug 2021 10:02:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233642AbhHVOCU (ORCPT ); Sun, 22 Aug 2021 10:02:20 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68A92C0617AE; Sun, 22 Aug 2021 07:01:35 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id f5so21904039wrm.13; Sun, 22 Aug 2021 07:01:35 -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=IPujwYC6E9l7jqY2RWqen9mgADujdWEnooR3WaHxdYM=; b=XFcTU7lkZFZ7hC4iTBXDTcHN55VjjNH6RXOTDZkKc0YnZc/6jT31WBHS6tmdfcrj5M kMM2+OOtNmzrzyN89i530GbMMw20IC3bZr992+nEvn+KZpnJRJc7g0XcLYPKutrOkx3Q 5Ovr0pwYzdGVAueDJqzIbFDskOII2+fegMIkd7usoBudkWR1D18UDmfI4WgtoYRveg1T EmxhAnJdQwkzhmAg0pDeGctKYwXEwbkNfL4R8Br+RWe/JlHsrRvzLhc4esdysyI399n4 Bw509HxI+TTLM20zIx9YqDKrEJBSW3JKEhtCEgtJYyv5QfFIrCVJke+KfM+itFkIM8V4 WiuA== 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=IPujwYC6E9l7jqY2RWqen9mgADujdWEnooR3WaHxdYM=; b=WoPHLqQOnLIIV8VTXd/aoKWl8Iw+2swvpYH1giMzT8olrXxQzeZfGkjYXBXQ7/eRau Qy3RnP64x8aKYVSbwnfPe3fQx2pZBt7SoEE4LO9HWVP9K9hxQ6CctOdzhMIzW70H8M17 K0lE75nMvRuDxiWkkSF3GVxBADzQx8qEgLA+V4CJqCKNl29sYMYjO0wHcDbRac5hAZmE XsETwjmos7CJkPe3xSKPueQiy2Oc5EQVbbe958s3gS8svizLHdGgwlanbey4NHLC+fL1 UwRxrb6pcesVeFlr7XSd2TX0JJgjhudbADIazJ+GWnREoUm9TtwI4lnYdwjdfr+mciOW FGEA== X-Gm-Message-State: AOAM532ONk112tuK2i+PXYZocnMi4vW+0qDCiTDchDYhDL+axQ4OnAmp BQGnXCVjYCC0gR6Fte2/5NnGT10Iv6g+Iw== X-Google-Smtp-Source: ABdhPJw1WUokU8P1rcYCEmDesECHWY5gmLrlPx40jjL8iTSNLxSN1cQkQhTsu5pBrfWwtH+7dgAYpw== X-Received: by 2002:a5d:690b:: with SMTP id t11mr6974024wru.182.1629640893822; Sun, 22 Aug 2021 07:01:33 -0700 (PDT) Received: from ?IPv6:2003:ea:8f08:4500:fc53:5e22:f926:c43b? (p200300ea8f084500fc535e22f926c43b.dip0.t-ipconnect.de. [2003:ea:8f08:4500:fc53:5e22:f926:c43b]) by smtp.googlemail.com with ESMTPSA id m21sm9894283wms.3.2021.08.22.07.01.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 22 Aug 2021 07:01:33 -0700 (PDT) Subject: [PATCH 11/12] cxgb4: Search VPD with pci_vpd_find_ro_info_keyword() From: Heiner Kallweit To: Bjorn Helgaas , Raju Rangoju , Jakub Kicinski , David Miller Cc: "linux-pci@vger.kernel.org" , "netdev@vger.kernel.org" References: <1ca29408-7bc7-4da5-59c7-87893c9e0442@gmail.com> Message-ID: Date: Sun, 22 Aug 2021 15:59:21 +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: <1ca29408-7bc7-4da5-59c7-87893c9e0442@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use pci_vpd_find_ro_info_keyword() to search for keywords in VPD to simplify the code. Signed-off-by: Heiner Kallweit --- 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"); \ - 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; } /**