From patchwork Sun Aug 8 17:19:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 12425019 X-Patchwork-Delegate: bhelgaas@google.com 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.3 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=ham 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 4B03FC4320A for ; Sun, 8 Aug 2021 17:20:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2C8D860F0F for ; Sun, 8 Aug 2021 17:20:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231881AbhHHRUJ (ORCPT ); Sun, 8 Aug 2021 13:20:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232186AbhHHRTd (ORCPT ); Sun, 8 Aug 2021 13:19:33 -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 56282C061760 for ; Sun, 8 Aug 2021 10:19:14 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id b13so18208802wrs.3 for ; Sun, 08 Aug 2021 10:19:14 -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=L8rDTmouG5tACcWkL3LAGSDRDzrjpaFRhkMDBNhwt3I=; b=O2aAk1rI01AR9M5PjOrMm4sGSD6/HQ2DxfK/c+UBt/4zAPuvux9tyB/4TODmVm95Ki 0QGRJIu8MURakna/5CAiwUtgU27h9R2jYzeCzxisPD1jyFMDkDC3cuFVmkrFpfZdzfoZ vU1/KueHW57M3r6m2Sj4Zy5NRT8tDVcSow/u6AfR3+2gKnTsUuokLskXChOLh5HTESU6 0ofRIzZDt9f4uCr4m9c7wDVCrVi0kyRFom8nyE+dDUB0Dtc68IT0pJfSXsu8Iz4Edznw eKRLrm/6XuGADhK0j+PFQmgxYKihNCnREhOwQddsleRiXFoEQN8luF3W6y+F+Viy84CB F8iA== 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=L8rDTmouG5tACcWkL3LAGSDRDzrjpaFRhkMDBNhwt3I=; b=Ypyhv2My7mq9O9z8vd211VT77tGNNouP6eLis1vFEwgUCD94fc8zIoi2o2cBYVEvIG DkMqBTjOHV0iG6stf8M8wEk0EeZKfjw0CJG1Z2kGFRDzUYx+qomOjOZjy/p/rvW4s9z2 n1iVSF/mFZZQMvUdjUXvJWwZLopC7oK1J7ca6fV5cz3F1UBOOciDfqEjHTqCJeJQFXgj LyydiHvdlHQ3O2FLnIfuikH10i2uf/XprQUMBpxr7tB930aBRFWT+QCwmJkeNq9pP384 zs5uFZ6QwcVnwOBcExvAjnxR+pPp1OmSgw4yLn8hp2aVzVmi/xoyIQqRbcVsBqxw91sH ndUA== X-Gm-Message-State: AOAM533jPmqsoXNYt1f68d7w785y24ycb5N7NWXz5qvrdqhYphYUV7ec T6Str6B3iQo1elJdAcFkd1HqOQC9AyZL4g== X-Google-Smtp-Source: ABdhPJyPHHs6gT6W6W2LyUBuq3IGWdxbij4CaCZLj6m5v+dnEjYvtibfEE//rC+QBDkoN2UekUUnpA== X-Received: by 2002:a5d:658a:: with SMTP id q10mr20938663wru.343.1628443152261; Sun, 08 Aug 2021 10:19:12 -0700 (PDT) Received: from ?IPv6:2003:ea:8f10:c200:7101:8b48:5eab:cb5f? (p200300ea8f10c20071018b485eabcb5f.dip0.t-ipconnect.de. [2003:ea:8f10:c200:7101:8b48:5eab:cb5f]) by smtp.googlemail.com with ESMTPSA id g11sm17019619wrd.97.2021.08.08.10.19.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 08 Aug 2021 10:19:11 -0700 (PDT) Subject: [PATCH 1/6] PCI/VPD: Move pci_read/write_vpd in the code From: Heiner Kallweit To: Bjorn Helgaas Cc: "linux-pci@vger.kernel.org" References: <1e61d5dc-824c-e855-01eb-6c7f45c55285@gmail.com> Message-ID: <89f0f5a2-293b-a017-fc67-a36473a792bf@gmail.com> Date: Sun, 8 Aug 2021 19:19:10 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <1e61d5dc-824c-e855-01eb-6c7f45c55285@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org In preparation of subsequent patches move these two functions in the code. Signed-off-by: Heiner Kallweit --- drivers/pci/vpd.c | 60 +++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index 5e2e63809..e87f299ee 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -31,36 +31,6 @@ static struct pci_dev *pci_get_func0_dev(struct pci_dev *dev) return pci_get_slot(dev->bus, PCI_DEVFN(PCI_SLOT(dev->devfn), 0)); } -/** - * pci_read_vpd - Read one entry from Vital Product Data - * @dev: pci device struct - * @pos: offset in vpd space - * @count: number of bytes to read - * @buf: pointer to where to store result - */ -ssize_t pci_read_vpd(struct pci_dev *dev, loff_t pos, size_t count, void *buf) -{ - if (!dev->vpd || !dev->vpd->ops) - return -ENODEV; - return dev->vpd->ops->read(dev, pos, count, buf); -} -EXPORT_SYMBOL(pci_read_vpd); - -/** - * pci_write_vpd - Write entry to Vital Product Data - * @dev: pci device struct - * @pos: offset in vpd space - * @count: number of bytes to write - * @buf: buffer containing write data - */ -ssize_t pci_write_vpd(struct pci_dev *dev, loff_t pos, size_t count, const void *buf) -{ - if (!dev->vpd || !dev->vpd->ops) - return -ENODEV; - return dev->vpd->ops->write(dev, pos, count, buf); -} -EXPORT_SYMBOL(pci_write_vpd); - #define PCI_VPD_MAX_SIZE (PCI_VPD_ADDR_MASK + 1) /** @@ -409,6 +379,36 @@ int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off, } EXPORT_SYMBOL_GPL(pci_vpd_find_info_keyword); +/** + * pci_read_vpd - Read one entry from Vital Product Data + * @dev: pci device struct + * @pos: offset in vpd space + * @count: number of bytes to read + * @buf: pointer to where to store result + */ +ssize_t pci_read_vpd(struct pci_dev *dev, loff_t pos, size_t count, void *buf) +{ + if (!dev->vpd || !dev->vpd->ops) + return -ENODEV; + return dev->vpd->ops->read(dev, pos, count, buf); +} +EXPORT_SYMBOL(pci_read_vpd); + +/** + * pci_write_vpd - Write entry to Vital Product Data + * @dev: pci device struct + * @pos: offset in vpd space + * @count: number of bytes to write + * @buf: buffer containing write data + */ +ssize_t pci_write_vpd(struct pci_dev *dev, loff_t pos, size_t count, const void *buf) +{ + if (!dev->vpd || !dev->vpd->ops) + return -ENODEV; + return dev->vpd->ops->write(dev, pos, count, buf); +} +EXPORT_SYMBOL(pci_write_vpd); + #ifdef CONFIG_PCI_QUIRKS /* * Quirk non-zero PCI functions to route VPD access through function 0 for From patchwork Sun Aug 8 17:20:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 12425021 X-Patchwork-Delegate: bhelgaas@google.com 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.3 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=ham 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 CC6F1C4338F for ; Sun, 8 Aug 2021 17:20:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B2DFC60F11 for ; Sun, 8 Aug 2021 17:20:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230502AbhHHRUa (ORCPT ); Sun, 8 Aug 2021 13:20:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230049AbhHHRUa (ORCPT ); Sun, 8 Aug 2021 13:20:30 -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 191D5C061760 for ; Sun, 8 Aug 2021 10:20:10 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id f5so2404884wrm.13 for ; Sun, 08 Aug 2021 10:20:10 -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=65E1bA4oCNTLY3YGhSWBcoGT7k6EVcPa7tZb07l1a80=; b=G3aJVEkRRex0jYOsfYHT46CO1UrOiFtenAdWwUdYgQD4ZyPoekAmB+7QKo5tUVfZes 0GDq3KATYolCD/ieEG2gXx5iQvgqx8ZXTdFhrNu6AVTzCfRLxnOwBkP7cFruiQ18IvAn 3/PtbJHeVQgc45mzAGAM/2jp3iNwpqz5qc8FEX85sQ3EfobsiYpFtOUpUxLHHVOIbxRS /U6aD8M3ZA4ZFDVnA4S1Q9YxerG9EjPZRK1uRo9kLIH3C9lzXWNzjEeVW+dOu1DKW6/R 94ke4VXtTIJkr3WgarvNP/o2RiM6CKjzphz3nKMwnFCAR6m4cP5IfC5LzORZrh0LDgNu rJTw== 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=65E1bA4oCNTLY3YGhSWBcoGT7k6EVcPa7tZb07l1a80=; b=pLUr/lyVLkk2E4xhw8Ve1wf4rzV4yCmWiRgtkgfBnQV1IemP4rqbc/GleOGnZ2x4xh gWL+QaaQjaNmuCL/577LfzSCIaXyNcP90XqXvgAU9PbBGMGNJN7lygLF+Q2hgGZ9fshA Fz7gTC/nYajKeqzRDkLfUPhLadsJToNY4eUD7Wmwv84Z+EFfRyVr2XjaC4zuRqthqc3D LwvWrRQvpLYAliVGUZmNTbEws+E6ZejBdiVaUap69AOjPzw2imH4zf1mEBrkgoKbzy0C eVpDFjTk9zNeBYb6Zv9TjCiajhTyuIMQihm3X0q0hvPjrbSIF5Cmubg5y8gvWa81f35H Vjvg== X-Gm-Message-State: AOAM530yIQGahDreYFpinZOcQ7kFyUIq2i2myaX0u06IKBYEM3tRSpfZ e5Aqp9varPHhBsKsHGG/4yLUgQdOlQSd8A== X-Google-Smtp-Source: ABdhPJy6/tn9lPwY1GkBZvpSEJeCdmbMx3fdFY4125sBeCN6GWwq0Px/QA2tmjX1YiJ//327UXcrbQ== X-Received: by 2002:a5d:58da:: with SMTP id o26mr1747858wrf.140.1628443208507; Sun, 08 Aug 2021 10:20:08 -0700 (PDT) Received: from ?IPv6:2003:ea:8f10:c200:7101:8b48:5eab:cb5f? (p200300ea8f10c20071018b485eabcb5f.dip0.t-ipconnect.de. [2003:ea:8f10:c200:7101:8b48:5eab:cb5f]) by smtp.googlemail.com with ESMTPSA id z5sm18062757wmp.26.2021.08.08.10.20.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 08 Aug 2021 10:20:08 -0700 (PDT) Subject: [PATCH 2/6] PCI/VPD: Remove struct pci_vpd_ops From: Heiner Kallweit To: Bjorn Helgaas Cc: "linux-pci@vger.kernel.org" References: <1e61d5dc-824c-e855-01eb-6c7f45c55285@gmail.com> Message-ID: Date: Sun, 8 Aug 2021 19:20:05 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <1e61d5dc-824c-e855-01eb-6c7f45c55285@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Code can be significantly simplified by removing struct pci_vpd_ops and avoiding the indirect calls. Signed-off-by: Heiner Kallweit --- drivers/pci/vpd.c | 90 ++++++++++++++++++----------------------------- 1 file changed, 34 insertions(+), 56 deletions(-) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index e87f299ee..6a0d617b2 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -13,13 +13,7 @@ /* VPD access through PCI 2.2+ VPD capability */ -struct pci_vpd_ops { - ssize_t (*read)(struct pci_dev *dev, loff_t pos, size_t count, void *buf); - ssize_t (*write)(struct pci_dev *dev, loff_t pos, size_t count, const void *buf); -}; - struct pci_vpd { - const struct pci_vpd_ops *ops; struct mutex lock; unsigned int len; u8 cap; @@ -123,11 +117,16 @@ static int pci_vpd_wait(struct pci_dev *dev, bool set) static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count, void *arg) { - struct pci_vpd *vpd = dev->vpd; + struct pci_vpd *vpd; int ret = 0; loff_t end = pos + count; u8 *buf = arg; + if (!dev || !dev->vpd) + return -ENODEV; + + vpd = dev->vpd; + if (pos < 0) return -EINVAL; @@ -189,11 +188,16 @@ static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count, static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count, const void *arg) { - struct pci_vpd *vpd = dev->vpd; + struct pci_vpd *vpd; const u8 *buf = arg; loff_t end = pos + count; int ret = 0; + if (!dev || !dev->vpd) + return -ENODEV; + + vpd = dev->vpd; + if (pos < 0 || (pos & 3) || (count & 3)) return -EINVAL; @@ -238,44 +242,6 @@ static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count, return ret ? ret : count; } -static const struct pci_vpd_ops pci_vpd_ops = { - .read = pci_vpd_read, - .write = pci_vpd_write, -}; - -static ssize_t pci_vpd_f0_read(struct pci_dev *dev, loff_t pos, size_t count, - void *arg) -{ - struct pci_dev *tdev = pci_get_func0_dev(dev); - ssize_t ret; - - if (!tdev) - return -ENODEV; - - ret = pci_read_vpd(tdev, pos, count, arg); - pci_dev_put(tdev); - return ret; -} - -static ssize_t pci_vpd_f0_write(struct pci_dev *dev, loff_t pos, size_t count, - const void *arg) -{ - struct pci_dev *tdev = pci_get_func0_dev(dev); - ssize_t ret; - - if (!tdev) - return -ENODEV; - - ret = pci_write_vpd(tdev, pos, count, arg); - pci_dev_put(tdev); - return ret; -} - -static const struct pci_vpd_ops pci_vpd_f0_ops = { - .read = pci_vpd_f0_read, - .write = pci_vpd_f0_write, -}; - void pci_vpd_init(struct pci_dev *dev) { struct pci_vpd *vpd; @@ -290,10 +256,6 @@ void pci_vpd_init(struct pci_dev *dev) return; vpd->len = PCI_VPD_MAX_SIZE; - if (dev->dev_flags & PCI_DEV_FLAGS_VPD_REF_F0) - vpd->ops = &pci_vpd_f0_ops; - else - vpd->ops = &pci_vpd_ops; mutex_init(&vpd->lock); vpd->cap = cap; vpd->valid = 0; @@ -388,9 +350,17 @@ EXPORT_SYMBOL_GPL(pci_vpd_find_info_keyword); */ ssize_t pci_read_vpd(struct pci_dev *dev, loff_t pos, size_t count, void *buf) { - if (!dev->vpd || !dev->vpd->ops) - return -ENODEV; - return dev->vpd->ops->read(dev, pos, count, buf); + ssize_t ret; + + if (dev->dev_flags & PCI_DEV_FLAGS_VPD_REF_F0) { + dev = pci_get_func0_dev(dev); + ret = pci_vpd_read(dev, pos, count, buf); + pci_dev_put(dev); + } else { + ret = pci_vpd_read(dev, pos, count, buf); + } + + return ret; } EXPORT_SYMBOL(pci_read_vpd); @@ -403,9 +373,17 @@ EXPORT_SYMBOL(pci_read_vpd); */ ssize_t pci_write_vpd(struct pci_dev *dev, loff_t pos, size_t count, const void *buf) { - if (!dev->vpd || !dev->vpd->ops) - return -ENODEV; - return dev->vpd->ops->write(dev, pos, count, buf); + ssize_t ret; + + if (dev->dev_flags & PCI_DEV_FLAGS_VPD_REF_F0) { + dev = pci_get_func0_dev(dev); + ret = pci_vpd_write(dev, pos, count, buf); + pci_dev_put(dev); + } else { + ret = pci_vpd_write(dev, pos, count, buf); + } + + return ret; } EXPORT_SYMBOL(pci_write_vpd); From patchwork Sun Aug 8 17:21:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 12425023 X-Patchwork-Delegate: bhelgaas@google.com 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.5 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=ham 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 B0C6FC4338F for ; Sun, 8 Aug 2021 17:21:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8636060F25 for ; Sun, 8 Aug 2021 17:21:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231559AbhHHRV1 (ORCPT ); Sun, 8 Aug 2021 13:21:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230049AbhHHRV1 (ORCPT ); Sun, 8 Aug 2021 13:21:27 -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 00635C061760 for ; Sun, 8 Aug 2021 10:21:06 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id q11-20020a7bce8b0000b02902e6880d0accso950849wmj.0 for ; Sun, 08 Aug 2021 10:21:06 -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=LZ0CiqYvQd9POK26TIoWPQqNqHc6FZbED182og4oCLo=; b=u9kj9Mc45d4cFgKucX08N8JMBNkxG7E5oByUaW2CIipUn2tirDdECwBulYgGyqmHxj IG5v1SqiegjfQ/vszdJojbV8bJcF0EqfwXwraRAcRefEZYDINch75PNMCWXxoqHJHnWh kNfjE301ZGHzS9MeNbc5um92xApuYCPTFmkJuw0gtXdH2scce5RFmWAOSqFYW0meBWzy ekfukHOUmckZWLB0FVaHH056aNW7zr4Vr2ZjuB10vbszUQyxSjz9eR/FkeJNTVCc1Q6q CAxWJxEf8n4xLVX//FlWMUWT7cCY+o3xM1SOdVY2shi/NSTQt2h0e49beXrnPOnJq5Qo 50Rw== 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=LZ0CiqYvQd9POK26TIoWPQqNqHc6FZbED182og4oCLo=; b=HC8t4B/ZiltyEoL9aWdzSC4991lPvy47S4jshXrJnrwi/SZ/FCsIFnWcaINgMyXp32 VhRmbdgbci8rSKv3HDjrNySiLGe/Z2nsLahb5SMRsTwvEEhoQ5DbeP7s+9ZvlQ5wySbz mHSYBL9YNvImAhL7IohxtZCesqwBBE8C3pj/9ELOYHEib/x79nEDaU/nwMUJyouEoJek DPv87Omjhrx2fA290FoCitL1XGG8nhRbvVf2sH1bJCUpEOyMttLlyxYdEth4p5SpYgUU 2v4E+Yj5JPBlMHoX93TxkuXBAx0YnGkRlvI+F9Du8/aPThBDRWqVHzied5kLg8yXMdC6 Uw+g== X-Gm-Message-State: AOAM530MsQ9FTT8yvNOnj+6NoJ1YzHQMTwvySiskniZ6+HmLjBBOFXhR Sl9fTOp5no7Z0QGFvFOovo1wiOEcBs7BAA== X-Google-Smtp-Source: ABdhPJzcDDI9lypE8p18iusXE8qi1MZ3lHFnX5SlbtCokRKtEk8ZgViQ6con+n7zYqyBvaD1d2Qj+w== X-Received: by 2002:a7b:c014:: with SMTP id c20mr12637397wmb.81.1628443265463; Sun, 08 Aug 2021 10:21:05 -0700 (PDT) Received: from ?IPv6:2003:ea:8f10:c200:7101:8b48:5eab:cb5f? (p200300ea8f10c20071018b485eabcb5f.dip0.t-ipconnect.de. [2003:ea:8f10:c200:7101:8b48:5eab:cb5f]) by smtp.googlemail.com with ESMTPSA id s2sm14818985wmh.46.2021.08.08.10.21.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 08 Aug 2021 10:21:05 -0700 (PDT) Subject: [PATCH 3/6] PCI/VPD: Remove member valid from struct pci_vpd From: Heiner Kallweit To: Bjorn Helgaas Cc: "linux-pci@vger.kernel.org" References: <1e61d5dc-824c-e855-01eb-6c7f45c55285@gmail.com> Message-ID: <9f777bc7-5316-e1b8-e5d4-f9f609bdb5dd@gmail.com> Date: Sun, 8 Aug 2021 19:21:02 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <1e61d5dc-824c-e855-01eb-6c7f45c55285@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Instead of having a separate flag let's use vp->len != 0 as indicator that VPD validity has been checked. Now vpd->len == PCI_VPD_SZ_INVALID is used to indicate that VPD is invalid. Signed-off-by: Heiner Kallweit --- drivers/pci/vpd.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index 6a0d617b2..d6c216caf 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -17,7 +17,6 @@ struct pci_vpd { struct mutex lock; unsigned int len; u8 cap; - unsigned int valid:1; }; static struct pci_dev *pci_get_func0_dev(struct pci_dev *dev) @@ -25,7 +24,8 @@ static struct pci_dev *pci_get_func0_dev(struct pci_dev *dev) return pci_get_slot(dev->bus, PCI_DEVFN(PCI_SLOT(dev->devfn), 0)); } -#define PCI_VPD_MAX_SIZE (PCI_VPD_ADDR_MASK + 1) +#define PCI_VPD_MAX_SIZE (PCI_VPD_ADDR_MASK + 1) +#define PCI_VPD_SZ_INVALID UINT_MAX /** * pci_vpd_size - determine actual size of Vital Product Data @@ -36,6 +36,9 @@ static size_t pci_vpd_size(struct pci_dev *dev) size_t off = 0; unsigned char header[1+2]; /* 1 byte tag, 2 bytes length */ + /* Otherwise the following reads would fail. */ + dev->vpd->len = PCI_VPD_MAX_SIZE; + while (pci_read_vpd(dev, off, 1, header) == 1) { unsigned char tag; size_t size; @@ -48,7 +51,7 @@ static size_t pci_vpd_size(struct pci_dev *dev) if (pci_read_vpd(dev, off + 1, 2, &header[1]) != 2) { pci_warn(dev, "failed VPD read at offset %zu\n", off + 1); - return off; + return off ?: PCI_VPD_SZ_INVALID; } size = pci_vpd_lrdt_size(header); if (off + size > PCI_VPD_MAX_SIZE) @@ -73,7 +76,7 @@ static size_t pci_vpd_size(struct pci_dev *dev) pci_info(dev, "invalid VPD tag %#04x at offset %zu%s\n", header[0], off, off == 0 ? "; assume missing optional EEPROM" : ""); - return off; + return off ?: PCI_VPD_SZ_INVALID; } /* @@ -130,12 +133,10 @@ static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count, if (pos < 0) return -EINVAL; - if (!vpd->valid) { - vpd->valid = 1; + if (!vpd->len) vpd->len = pci_vpd_size(dev); - } - if (vpd->len == 0) + if (vpd->len == PCI_VPD_SZ_INVALID) return -EIO; if (pos > vpd->len) @@ -201,12 +202,10 @@ static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count, if (pos < 0 || (pos & 3) || (count & 3)) return -EINVAL; - if (!vpd->valid) { - vpd->valid = 1; + if (!vpd->len) vpd->len = pci_vpd_size(dev); - } - if (vpd->len == 0) + if (vpd->len == PCI_VPD_SZ_INVALID) return -EIO; if (end > vpd->len) @@ -255,10 +254,8 @@ void pci_vpd_init(struct pci_dev *dev) if (!vpd) return; - vpd->len = PCI_VPD_MAX_SIZE; mutex_init(&vpd->lock); vpd->cap = cap; - vpd->valid = 0; dev->vpd = vpd; } @@ -423,8 +420,7 @@ DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, PCI_ANY_ID, static void quirk_blacklist_vpd(struct pci_dev *dev) { if (dev->vpd) { - dev->vpd->len = 0; - dev->vpd->valid = 1; + dev->vpd->len = PCI_VPD_SZ_INVALID; pci_warn(dev, FW_BUG "disabling VPD access (can't determine size of non-standard VPD format)\n"); } } @@ -455,7 +451,6 @@ static void pci_vpd_set_size(struct pci_dev *dev, size_t len) if (!vpd || len == 0 || len > PCI_VPD_MAX_SIZE) return; - vpd->valid = 1; vpd->len = len; } From patchwork Sun Aug 8 17:21:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 12425025 X-Patchwork-Delegate: bhelgaas@google.com 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.3 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=ham 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 E22A9C4338F for ; Sun, 8 Aug 2021 17:22:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B74E960F11 for ; Sun, 8 Aug 2021 17:22:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231466AbhHHRWV (ORCPT ); Sun, 8 Aug 2021 13:22:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230049AbhHHRWV (ORCPT ); Sun, 8 Aug 2021 13:22:21 -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 10ED5C061760 for ; Sun, 8 Aug 2021 10:22:01 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id m12so18182463wru.12 for ; Sun, 08 Aug 2021 10:22:00 -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=xfC/a7r2v7rInT2z/B87NUzq6WuaHjmedALyon0+2G0=; b=ZDtdAM7yImJNDa38XuGeEj7um4/oabBGChij19mxMXgq4yHpWu10cVbhdnrG9bPOPM 8ESnjHrVoyoITuq3eYmLbtaFTYpdB8v1xLC+jJO56BgffSLkOIkiUhbmvm+ujhMGSdx5 1CwABWKyyM4UGhfUo6e9p0hRrg5QFPUh6HLbkpRwXrStCQEUd5Yd7fysdfJwhAtJfYdx WQbe0MB7Pv/i6WqxVukW9cl8/dW+Gq95+qngJUTAOzaHRf2G8HzS0EoklyPgFJrq7pw0 T85dyD/DdYr9qLkfsFwag25pFnMzIiIC38Jcbi4/CC6wdy5ZC1DzjHkNhdwV3noi+TLh qC4w== 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=xfC/a7r2v7rInT2z/B87NUzq6WuaHjmedALyon0+2G0=; b=oHikz3jGyC3nTxq+UFRUMWSwiuJh3MWgcmKRhKJGVo2QB/tPmpeEImaROaQZbWXhY7 cgIoltKhlXo1XL8gSx0YgwuElUjcxFH7s33YcITBDzHI7jwW8BCfH1MZotpzGbrmfLjq BVSSU/ZZrpe2obwWN7iMCr0gGBWqeiMT0igKrID4N0idDE9goEUH/1ezhIfVwfnfAisv FFsfQ4aSskcxAT9wAypt9CI4NC3nzH7zrJsQCXIk+LrFlWsrqRoBLQLV4TLl++h/P7AT SJQBQsJ+8bLI8Es0LxMFQniFNeBn0g4vusNUpXiCAW5NJOVOnsxCi22fhu7jLmVR1K7g p7+w== X-Gm-Message-State: AOAM5321z3apVFmBmbXyXRodU9Y63LC+YVoIigG101Aie8TUHHPcoGEO jfCHlv00LR/3VLQMSUCCWFAi5pZceSLDDw== X-Google-Smtp-Source: ABdhPJwgH4uF6V0Xxzr3npDDvp7PreuxjyXrQSqcvCqct0DhMCP2kk1hXyRIcBZEqPm8+fIla5zEog== X-Received: by 2002:adf:ecc9:: with SMTP id s9mr20709634wro.306.1628443319504; Sun, 08 Aug 2021 10:21:59 -0700 (PDT) Received: from ?IPv6:2003:ea:8f10:c200:7101:8b48:5eab:cb5f? (p200300ea8f10c20071018b485eabcb5f.dip0.t-ipconnect.de. [2003:ea:8f10:c200:7101:8b48:5eab:cb5f]) by smtp.googlemail.com with ESMTPSA id w14sm5737633wrt.23.2021.08.08.10.21.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 08 Aug 2021 10:21:59 -0700 (PDT) Subject: [PATCH 4/6] PCI/VPD: Embed struct pci_vpd member in struct pci_dev From: Heiner Kallweit To: Bjorn Helgaas Cc: "linux-pci@vger.kernel.org" References: <1e61d5dc-824c-e855-01eb-6c7f45c55285@gmail.com> Message-ID: Date: Sun, 8 Aug 2021 19:21:56 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <1e61d5dc-824c-e855-01eb-6c7f45c55285@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Now that struct pci_vpd became really small, we can simplify the code by embedding a struct pci_vpd member in struct pci_dev instead of dynamically allocating it. Signed-off-by: Heiner Kallweit --- drivers/pci/probe.c | 1 - drivers/pci/vpd.c | 67 ++++++++++----------------------------------- include/linux/pci.h | 9 ++++-- 3 files changed, 21 insertions(+), 56 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 79177ac37..0ec5c792c 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -2225,7 +2225,6 @@ static void pci_release_capabilities(struct pci_dev *dev) { pci_aer_exit(dev); pci_rcec_exit(dev); - pci_vpd_release(dev); pci_iov_release(dev); pci_free_cap_save_buffers(dev); } diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index d6c216caf..86f9440e0 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -13,12 +13,6 @@ /* VPD access through PCI 2.2+ VPD capability */ -struct pci_vpd { - struct mutex lock; - unsigned int len; - u8 cap; -}; - static struct pci_dev *pci_get_func0_dev(struct pci_dev *dev) { return pci_get_slot(dev->bus, PCI_DEVFN(PCI_SLOT(dev->devfn), 0)); @@ -37,7 +31,7 @@ static size_t pci_vpd_size(struct pci_dev *dev) unsigned char header[1+2]; /* 1 byte tag, 2 bytes length */ /* Otherwise the following reads would fail. */ - dev->vpd->len = PCI_VPD_MAX_SIZE; + dev->vpd.len = PCI_VPD_MAX_SIZE; while (pci_read_vpd(dev, off, 1, header) == 1) { unsigned char tag; @@ -90,7 +84,7 @@ static size_t pci_vpd_size(struct pci_dev *dev) */ static int pci_vpd_wait(struct pci_dev *dev, bool set) { - struct pci_vpd *vpd = dev->vpd; + struct pci_vpd *vpd = &dev->vpd; unsigned long timeout = jiffies + msecs_to_jiffies(125); unsigned long max_sleep = 16; u16 status; @@ -120,16 +114,14 @@ static int pci_vpd_wait(struct pci_dev *dev, bool set) static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count, void *arg) { - struct pci_vpd *vpd; + struct pci_vpd *vpd = &dev->vpd; int ret = 0; loff_t end = pos + count; u8 *buf = arg; - if (!dev || !dev->vpd) + if (!vpd->cap) return -ENODEV; - vpd = dev->vpd; - if (pos < 0) return -EINVAL; @@ -189,16 +181,14 @@ static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count, static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count, const void *arg) { - struct pci_vpd *vpd; + struct pci_vpd *vpd = &dev->vpd; const u8 *buf = arg; loff_t end = pos + count; int ret = 0; - if (!dev || !dev->vpd) + if (!vpd->cap) return -ENODEV; - vpd = dev->vpd; - if (pos < 0 || (pos & 3) || (count & 3)) return -EINVAL; @@ -243,25 +233,8 @@ static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count, void pci_vpd_init(struct pci_dev *dev) { - struct pci_vpd *vpd; - u8 cap; - - cap = pci_find_capability(dev, PCI_CAP_ID_VPD); - if (!cap) - return; - - vpd = kzalloc(sizeof(*vpd), GFP_ATOMIC); - if (!vpd) - return; - - mutex_init(&vpd->lock); - vpd->cap = cap; - dev->vpd = vpd; -} - -void pci_vpd_release(struct pci_dev *dev) -{ - kfree(dev->vpd); + dev->vpd.cap = pci_find_capability(dev, PCI_CAP_ID_VPD); + mutex_init(&dev->vpd.lock); } static ssize_t vpd_read(struct file *filp, struct kobject *kobj, @@ -293,7 +266,7 @@ static umode_t vpd_attr_is_visible(struct kobject *kobj, { struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj)); - if (!pdev->vpd) + if (!pdev->vpd.cap) return 0; return a->attr.mode; @@ -401,7 +374,7 @@ static void quirk_f0_vpd_link(struct pci_dev *dev) if (!f0) return; - if (f0->vpd && dev->class == f0->class && + if (f0->vpd.cap && dev->class == f0->class && dev->vendor == f0->vendor && dev->device == f0->device) dev->dev_flags |= PCI_DEV_FLAGS_VPD_REF_F0; @@ -419,10 +392,8 @@ DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, PCI_ANY_ID, */ static void quirk_blacklist_vpd(struct pci_dev *dev) { - if (dev->vpd) { - dev->vpd->len = PCI_VPD_SZ_INVALID; - pci_warn(dev, FW_BUG "disabling VPD access (can't determine size of non-standard VPD format)\n"); - } + dev->vpd.len = PCI_VPD_SZ_INVALID; + pci_warn(dev, FW_BUG "disabling VPD access (can't determine size of non-standard VPD format)\n"); } DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0060, quirk_blacklist_vpd); DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x007c, quirk_blacklist_vpd); @@ -444,16 +415,6 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, PCI_ANY_ID, DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_VENDOR_ID_AMAZON_ANNAPURNA_LABS, 0x0031, PCI_CLASS_BRIDGE_PCI, 8, quirk_blacklist_vpd); -static void pci_vpd_set_size(struct pci_dev *dev, size_t len) -{ - struct pci_vpd *vpd = dev->vpd; - - if (!vpd || len == 0 || len > PCI_VPD_MAX_SIZE) - return; - - vpd->len = len; -} - static void quirk_chelsio_extend_vpd(struct pci_dev *dev) { int chip = (dev->device & 0xf000) >> 12; @@ -472,9 +433,9 @@ static void quirk_chelsio_extend_vpd(struct pci_dev *dev) * limits. */ if (chip == 0x0 && prod >= 0x20) - pci_vpd_set_size(dev, 8192); + dev->vpd.len = 8192; else if (chip >= 0x4 && func < 0x8) - pci_vpd_set_size(dev, 2048); + dev->vpd.len = 2048; } DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, PCI_ANY_ID, diff --git a/include/linux/pci.h b/include/linux/pci.h index 540b377ca..e752cc39a 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -300,9 +300,14 @@ struct pci_cap_saved_state { struct pci_cap_saved_data cap; }; +struct pci_vpd { + struct mutex lock; + unsigned int len; + u8 cap; +}; + struct irq_affinity; struct pcie_link_state; -struct pci_vpd; struct pci_sriov; struct pci_p2pdma; struct rcec_ea; @@ -473,7 +478,7 @@ struct pci_dev { #ifdef CONFIG_PCI_MSI const struct attribute_group **msi_irq_groups; #endif - struct pci_vpd *vpd; + struct pci_vpd vpd; #ifdef CONFIG_PCIE_DPC u16 dpc_cap; unsigned int dpc_rp_extensions:1; From patchwork Sun Aug 8 17:22:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 12425027 X-Patchwork-Delegate: bhelgaas@google.com 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.3 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=ham 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 9F9F1C4338F for ; Sun, 8 Aug 2021 17:23:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 77B7A60F11 for ; Sun, 8 Aug 2021 17:23:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231649AbhHHRXU (ORCPT ); Sun, 8 Aug 2021 13:23:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231199AbhHHRXU (ORCPT ); Sun, 8 Aug 2021 13:23:20 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3365C061760 for ; Sun, 8 Aug 2021 10:23:00 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id i4so756418wru.0 for ; Sun, 08 Aug 2021 10:22:57 -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=cCNpFG5aHGh4jGVccDghzCAzsVqauDMJguybpsCmQN0=; b=kW919A70yMe+70axQ99EwS/Uy+lxbXUNHsiGT/27xPP/B2XEI8oFzoRJdNF6eiYYY3 tQId2vbcXD3HJjpK7TW/uO8BT/8gphOPynLIOjl3/Pza4yEeg3bieo/8d4AzUAUbLxsS tAGVX/VEEpccRv6NnAmb3KarYIqdeqpfgw6WnOmr165pjJjcbFTaYoZ/cVOywxwkoDVs 3J3ochFHjsisCgQT41cwKzF2IIL5tRdaMjyJZxZRRmdKFLN74CQ+a3JJHdWI/aSsyMf2 m2tXL7Ed7S8d/F9tB0pdcwKpcPs+ZjuSAkJxsRGwnGcMT3joHlYRR/R/gVTpYyMzOSNu RdiQ== 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=cCNpFG5aHGh4jGVccDghzCAzsVqauDMJguybpsCmQN0=; b=ld/6EnYoVr2MJTtIMC8LLP3kxoysXoPqG0RovYxVekw1UxZ4XXyRN++tFkFjRP1xJ1 SDeKZukXr9vF4daaI1LstvrhdT/Pqehormoggci1E8Alxm6VfwfYTLq+6WjGUlBSpr0i n2DXICGf+HmtRtGGE2rntaUn8jnnhFGVszE7p8XUjtnDL0dN2RkbSVkomjAAO+TqTV53 mcBZuhbM7bvNJ3uEEseRjGN3XQf9KI6UDlLvbvZol/Fso9bopxQCru5Eaztz+Ki0FpHg Bjy1ec/M1HE7ebSZc4ioKhZHSvEeaH+SpxgaewlLRPQzPIAbUZTswCqMg5OUIgPxuXBS 7lxg== X-Gm-Message-State: AOAM5324GuMsmLAfld/BmvXTyLrtVmtibNXyE68ewp991oVBTkLDLi2K NSwXJ3sw/UrPnWNGNq2xhDV425XFS8dkAQ== X-Google-Smtp-Source: ABdhPJxHy1lHcRNGHeJlulMuBh1r3+qZ6imAPaTKaQ6QLrkK0w/G4jxDZUNRUTEdE9MmbADP/JU3Jg== X-Received: by 2002:a5d:45c2:: with SMTP id b2mr1172788wrs.188.1628443376227; Sun, 08 Aug 2021 10:22:56 -0700 (PDT) Received: from ?IPv6:2003:ea:8f10:c200:7101:8b48:5eab:cb5f? (p200300ea8f10c20071018b485eabcb5f.dip0.t-ipconnect.de. [2003:ea:8f10:c200:7101:8b48:5eab:cb5f]) by smtp.googlemail.com with ESMTPSA id s10sm3549960wrv.54.2021.08.08.10.22.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 08 Aug 2021 10:22:55 -0700 (PDT) Subject: [PATCH 5/6] PCI/VPD: Determine VPD size in pci_vpd_init already From: Heiner Kallweit To: Bjorn Helgaas Cc: "linux-pci@vger.kernel.org" References: <1e61d5dc-824c-e855-01eb-6c7f45c55285@gmail.com> Message-ID: Date: Sun, 8 Aug 2021 19:22:52 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <1e61d5dc-824c-e855-01eb-6c7f45c55285@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org After preceding patches in this series we now can move determining VPD size to pci_vpd_init(). Any quirk sets dev->vpd.len to a non-zero value and therefore causes skipping the dynamic size calculation. Prerequisite is that we move the quirks from FINAL to HEADER stage. Signed-off-by: Heiner Kallweit --- drivers/pci/vpd.c | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index 86f9440e0..9187ba496 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -125,9 +125,6 @@ static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count, if (pos < 0) return -EINVAL; - if (!vpd->len) - vpd->len = pci_vpd_size(dev); - if (vpd->len == PCI_VPD_SZ_INVALID) return -EIO; @@ -192,9 +189,6 @@ static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count, if (pos < 0 || (pos & 3) || (count & 3)) return -EINVAL; - if (!vpd->len) - vpd->len = pci_vpd_size(dev); - if (vpd->len == PCI_VPD_SZ_INVALID) return -EIO; @@ -235,6 +229,9 @@ void pci_vpd_init(struct pci_dev *dev) { dev->vpd.cap = pci_find_capability(dev, PCI_CAP_ID_VPD); mutex_init(&dev->vpd.lock); + + if (!dev->vpd.len) + dev->vpd.len = pci_vpd_size(dev); } static ssize_t vpd_read(struct file *filp, struct kobject *kobj, @@ -395,25 +392,24 @@ static void quirk_blacklist_vpd(struct pci_dev *dev) dev->vpd.len = PCI_VPD_SZ_INVALID; pci_warn(dev, FW_BUG "disabling VPD access (can't determine size of non-standard VPD format)\n"); } -DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0060, quirk_blacklist_vpd); -DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x007c, quirk_blacklist_vpd); -DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0413, quirk_blacklist_vpd); -DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0078, quirk_blacklist_vpd); -DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0079, quirk_blacklist_vpd); -DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0073, quirk_blacklist_vpd); -DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0071, quirk_blacklist_vpd); -DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x005b, quirk_blacklist_vpd); -DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x002f, quirk_blacklist_vpd); -DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x005d, quirk_blacklist_vpd); -DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x005f, quirk_blacklist_vpd); -DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, PCI_ANY_ID, - quirk_blacklist_vpd); +DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_LSI_LOGIC, 0x0060, quirk_blacklist_vpd); +DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_LSI_LOGIC, 0x007c, quirk_blacklist_vpd); +DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_LSI_LOGIC, 0x0413, quirk_blacklist_vpd); +DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_LSI_LOGIC, 0x0078, quirk_blacklist_vpd); +DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_LSI_LOGIC, 0x0079, quirk_blacklist_vpd); +DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_LSI_LOGIC, 0x0073, quirk_blacklist_vpd); +DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_LSI_LOGIC, 0x0071, quirk_blacklist_vpd); +DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_LSI_LOGIC, 0x005b, quirk_blacklist_vpd); +DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_LSI_LOGIC, 0x002f, quirk_blacklist_vpd); +DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_LSI_LOGIC, 0x005d, quirk_blacklist_vpd); +DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_LSI_LOGIC, 0x005f, quirk_blacklist_vpd); +DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATTANSIC, PCI_ANY_ID, quirk_blacklist_vpd); /* * The Amazon Annapurna Labs 0x0031 device id is reused for other non Root Port * device types, so the quirk is registered for the PCI_CLASS_BRIDGE_PCI class. */ -DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_VENDOR_ID_AMAZON_ANNAPURNA_LABS, 0x0031, - PCI_CLASS_BRIDGE_PCI, 8, quirk_blacklist_vpd); +DECLARE_PCI_FIXUP_CLASS_HEADER(PCI_VENDOR_ID_AMAZON_ANNAPURNA_LABS, 0x0031, + PCI_CLASS_BRIDGE_PCI, 8, quirk_blacklist_vpd); static void quirk_chelsio_extend_vpd(struct pci_dev *dev) { @@ -438,7 +434,7 @@ static void quirk_chelsio_extend_vpd(struct pci_dev *dev) dev->vpd.len = 2048; } -DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, PCI_ANY_ID, - quirk_chelsio_extend_vpd); +DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_CHELSIO, PCI_ANY_ID, + quirk_chelsio_extend_vpd); #endif From patchwork Sun Aug 8 17:23: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: 12425029 X-Patchwork-Delegate: bhelgaas@google.com 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.3 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=ham 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 8EE9AC4338F for ; Sun, 8 Aug 2021 17:24:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 614C160F11 for ; Sun, 8 Aug 2021 17:24:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231199AbhHHRYW (ORCPT ); Sun, 8 Aug 2021 13:24:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231764AbhHHRYW (ORCPT ); Sun, 8 Aug 2021 13:24:22 -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 311B0C061760 for ; Sun, 8 Aug 2021 10:24:02 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id i10-20020a05600c354ab029025a0f317abfso12796041wmq.3 for ; Sun, 08 Aug 2021 10:24:02 -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=ZrGMfIn9duZHrgPrZQrczeNxCd3FMunAZEVzb7ncRw8=; b=X505X68eKtrt/V1b6m9riXb/Y8VXIMWJLl4HV21l2Bctqm0/2fEm/udq5XLfBt4idf pTyvvXFABpoW7INAlzpYYQAqijO1FL26LI1d1DnJDUtwDJ11MLu8bee01ZfuJiEFcm/m v+7DiR1jIcTk/IIsUS+n1o8JerJziD/TTWNe4ywUwPa2QJIbdZfH0FCeoSFCllVdkHBZ nLYKrAjhgyyCxDyNwXwQcmq/YTUAO/0NJYnfs5Z+WXU7mB/8s0zMV7yDmm4iOcjKKj98 b3S6nAAACp9DIy8MaMjiKCqQWBmaDnaONk8pv2onP3ipoKaW02gyAK6uBobBtzltg3D+ Vy7A== 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=ZrGMfIn9duZHrgPrZQrczeNxCd3FMunAZEVzb7ncRw8=; b=TICkE9l8ntAHvVqmMATtlMdFlGQ7+wBkfScP4JLQkMZNrwqYTejG8XYWupWabQJLvs tL8vKu8Bdk0bwUXHNNI6BL/mL2Mqiy6Kk1E7yITWvg38b4cYIlMi6rIuhEBSIcWmf89I jEp6TN0SYj7uJTJrSFl6F8nlUuePIsy5eVoZ+cl03NSmniiXS9mq14pDnldIBpbEuSXJ ilgG13kmXmNTeRSCabCzk8vceLXzy+6f3Fj0N2dVm12qDpbWoK3CQ5KZXbgY4D67/EOH rm5rnVqPf2hAsQfONwZwRh1Mg+VU2yosSkN2SVtZ7fjETk0ZI6TryH6X0gdJmkkWHmOW IZ9g== X-Gm-Message-State: AOAM530mo+WM9o6knGhOXKQPmXLXLyJqWH3HQJwqx9CemLLj/BPm+y7V 6mfaYZ5MWO4nqmI7uBbYuCBg2Itm4PY10w== X-Google-Smtp-Source: ABdhPJxroo1sm7PMDrM/DUUtIqoOi65iFlLLuzjbQrhJxMPWQbtrBSpbdD3dPqBhIL4JZkKU0te2qg== X-Received: by 2002:a05:600c:198f:: with SMTP id t15mr6978828wmq.76.1628443440634; Sun, 08 Aug 2021 10:24:00 -0700 (PDT) Received: from ?IPv6:2003:ea:8f10:c200:7101:8b48:5eab:cb5f? (p200300ea8f10c20071018b485eabcb5f.dip0.t-ipconnect.de. [2003:ea:8f10:c200:7101:8b48:5eab:cb5f]) by smtp.googlemail.com with ESMTPSA id c15sm16977316wrw.93.2021.08.08.10.23.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 08 Aug 2021 10:24:00 -0700 (PDT) Subject: [PATCH 6/6] PCI/VPD: Treat invalid VPD like no VPD capability From: Heiner Kallweit To: Bjorn Helgaas Cc: "linux-pci@vger.kernel.org" References: <1e61d5dc-824c-e855-01eb-6c7f45c55285@gmail.com> Message-ID: <6a02b204-4ed2-4553-c3b2-eacf9554fa8d@gmail.com> Date: Sun, 8 Aug 2021 19:23:57 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <1e61d5dc-824c-e855-01eb-6c7f45c55285@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Exporting sysfs files that can't be accessed doesn't make much sense. Therefore, if either a quirk or the dynamic size calculation result in VPD being marked as invalid, treat this like device has no VPD capability. One consequence is that vpd sysfs file is not visible. Signed-off-by: Heiner Kallweit --- drivers/pci/vpd.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index 9187ba496..58a3aa6a4 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -125,9 +125,6 @@ static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count, if (pos < 0) return -EINVAL; - if (vpd->len == PCI_VPD_SZ_INVALID) - return -EIO; - if (pos > vpd->len) return 0; @@ -189,9 +186,6 @@ static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count, if (pos < 0 || (pos & 3) || (count & 3)) return -EINVAL; - if (vpd->len == PCI_VPD_SZ_INVALID) - return -EIO; - if (end > vpd->len) return -EINVAL; @@ -232,6 +226,9 @@ void pci_vpd_init(struct pci_dev *dev) if (!dev->vpd.len) dev->vpd.len = pci_vpd_size(dev); + + if (dev->vpd.len == PCI_VPD_SZ_INVALID) + dev->vpd.cap = 0; } static ssize_t vpd_read(struct file *filp, struct kobject *kobj,