From patchwork Sat Nov 6 11:26:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Puranjay Mohan X-Patchwork-Id: 12606285 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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB64EC433EF for ; Sat, 6 Nov 2021 11:26:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8DDAD611C4 for ; Sat, 6 Nov 2021 11:26:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234047AbhKFL3I (ORCPT ); Sat, 6 Nov 2021 07:29:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229500AbhKFL3H (ORCPT ); Sat, 6 Nov 2021 07:29:07 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82340C061570 for ; Sat, 6 Nov 2021 04:26:26 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id n85so6787719pfd.10 for ; Sat, 06 Nov 2021 04:26:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=i0npdG7kpsBIuyXnUFtec9A+3MP5lApVY+4YnlPHv18=; b=PimngPCAQa+O15HZN5AoGDnn0PKAWOjT9/d3VlwGahiHynZu5Pv7cP5aLawu8XQfPv yXDipATBNWb9agjyjSDAfmKdPUXhxB0pVMMf4KtrQSumd/xlqfcGJDKS4mKJnsBL2Cst 0azQdbkkaQTuUNGc0Pb61lkeQjfUqJAjEshdxOUCEbPWgvDqe8cv4C48S1/qwJKLjC77 VC305ki8sjQMYa7nKEB6vUhxbVT8F3H6eafTsNzRa4D4Njpi3iAvgfslZTfjFiWqbg9d wv1e4Z8AY3bbE7Z0iOL9R3kfpRpKhigU1+7PPfDCFbWBfse9H5zR8vG0QcWfzL17QdJz hEow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=i0npdG7kpsBIuyXnUFtec9A+3MP5lApVY+4YnlPHv18=; b=khBjaw91hmKlxNpD/XxnJWeoHUjCZvSEf6WpAi/Vx28OUa0fhyU3wExycDr+1qrYHO Yw4URr/LQHlJ5n6THQTCUxskIYLaefqukKVkRbhBckxYP6NVIpLKrNHpqEAIuyOC9XzX Q6rbSTvXKv9/Mm/k4WwgNsEyDowB1bdyFOEJsMe2qijpFuo9qLUHdYw/DKZ6jqfr0KLT VhpZxFVGn5A57Z3mD21QTcDlo3svnEJNzseahZapT/NC65HO690P9XVVMDt5NCKmVKP8 sPuhquvQuI/YOsqBkecac+zd2NHOnXE9bm1CvwOCvCJflMfN8Q0ybVOpvnEeQ5sa32Pa 0vGA== X-Gm-Message-State: AOAM532m5bORX+PNtMqNoFV5tI5mOjP2Crm9EvOuERzT/IMFlK755o3T SgJrU7tkDnon16cuA00c9TBA2CPkz8LFHQ== X-Google-Smtp-Source: ABdhPJxJVSMBImKeY7lkbAV5x/LKWbKi7glK4AK+YvEHy9MbTHrDQ8bkDQhAJHVcxTVAF4XkEdYWhg== X-Received: by 2002:a63:88c8:: with SMTP id l191mr37754521pgd.369.1636197985972; Sat, 06 Nov 2021 04:26:25 -0700 (PDT) Received: from localhost.localdomain ([124.253.6.45]) by smtp.googlemail.com with ESMTPSA id c21sm10971037pfl.15.2021.11.06.04.26.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 04:26:25 -0700 (PDT) From: Puranjay Mohan To: bhelgaas@google.com, linux-pci@vger.kernel.org Cc: Puranjay Mohan Subject: [PATCH 1/2] PCI: Update BAR # and window messages Date: Sat, 6 Nov 2021 16:56:05 +0530 Message-Id: <20211106112606.192563-2-puranjay12@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20211106112606.192563-1-puranjay12@gmail.com> References: <20211106112606.192563-1-puranjay12@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The PCI logs messages print the register offsets at some places and BAR numbers at other places. There is no uniformity in this logging mechanism. It would be better to print names than register offsets. Add a helper function that aids in printing more meaningful information about the BAR numbers like "VF BAR", "ROM", "Bridge Window", etc. This function can be called while printing PCI log messages. Signed-off-by: Puranjay Mohan --- drivers/pci/pci.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/pci/pci.h | 2 ++ 2 files changed, 49 insertions(+) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index ce2ab62b64cf..1c2dfb2b9754 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -800,6 +800,53 @@ struct resource *pci_find_resource(struct pci_dev *dev, struct resource *res) } EXPORT_SYMBOL(pci_find_resource); +/** + * pci_resource_name - Return the name of the PCI resource. + * @dev: PCI device to query + * @i: index of the resource + * + * Returns the standard PCI resource(BAR) names according to their index. + */ +const char *pci_resource_name(struct pci_dev *dev, int i) +{ + if (dev->hdr_type == PCI_HEADER_TYPE_NORMAL) { + switch (i) { + case 0: return "BAR 0"; + case 1: return "BAR 1"; + case 2: return "BAR 2"; + case 3: return "BAR 3"; + case 4: return "BAR 4"; + case 5: return "BAR 5"; + case PCI_ROM_RESOURCE: return "ROM"; + #ifdef CONFIG_PCI_IOV + case PCI_IOV_RESOURCES + 0: return "VF BAR 0"; + case PCI_IOV_RESOURCES + 1: return "VF BAR 1"; + case PCI_IOV_RESOURCES + 2: return "VF BAR 2"; + case PCI_IOV_RESOURCES + 3: return "VF BAR 3"; + case PCI_IOV_RESOURCES + 4: return "VF BAR 4"; + case PCI_IOV_RESOURCES + 5: return "VF BAR 5"; + #endif + } + } else if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) { + switch (i) { + case 0: return "BAR 0"; + case 1: return "BAR 1"; + case PCI_BRIDGE_IO_WINDOW: return "bridge I/O window"; + case PCI_BRIDGE_MEM_WINDOW: return "bridge mem window"; + case PCI_BRIDGE_PREF_MEM_WINDOW: return "bridge mem pref window"; + } + } else if (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) { + switch (i) { + case 0: return "BAR 0"; + case PCI_CB_BRIDGE_IO_0_WINDOW: return "CardBus bridge I/O 0 window"; + case PCI_CB_BRIDGE_IO_1_WINDOW: return "CardBus bridge I/O 1 window"; + case PCI_CB_BRIDGE_MEM_0_WINDOW: return "CardBus bridge mem 0 window"; + case PCI_CB_BRIDGE_MEM_1_WINDOW: return "CardBus bridge mem 1 window"; + } + } + return "unknown"; +} + /** * pci_wait_for_pending - wait for @mask bit(s) to clear in status word @pos * @dev: the PCI device to operate on diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 1cce56c2aea0..ee0738c7731a 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -281,6 +281,8 @@ void __pci_bus_assign_resources(const struct pci_bus *bus, struct list_head *fail_head); bool pci_bus_clip_resource(struct pci_dev *dev, int idx); +const char *pci_resource_name(struct pci_dev *dev, int i); + void pci_reassigndev_resource_alignment(struct pci_dev *dev); void pci_disable_bridge_window(struct pci_dev *dev); struct pci_bus *pci_bus_get(struct pci_bus *bus); From patchwork Sat Nov 6 11:26:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Puranjay Mohan X-Patchwork-Id: 12606287 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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1EADC433FE for ; Sat, 6 Nov 2021 11:26:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 849BB60F21 for ; Sat, 6 Nov 2021 11:26:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234045AbhKFL3K (ORCPT ); Sat, 6 Nov 2021 07:29:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229500AbhKFL3J (ORCPT ); Sat, 6 Nov 2021 07:29:09 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0E16C061570 for ; Sat, 6 Nov 2021 04:26:28 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id o10-20020a17090a3d4a00b001a6555878a8so5178072pjf.1 for ; Sat, 06 Nov 2021 04:26:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qUBg4F2w42ifFGcRoyXQkPsTj7mdb/CGi2CkiubKUc0=; b=BuLz3TVar020xUmzLvjuJodwhOHBQu5eQz+KTHGG7pMfble6xd96GnAD6fj/Ugo7Qr p5jI5cIVRqHhWFtmwy2tx5VqX4K78LJOMmvt3onEmi4PTszGqsGMgGNAMlT8yZ7FFJER Hiz2zeqjDHcCR7P5S80+WVDc36RP+KUUw/YQUlzXYSaUFRwGkyySCIaBRBzJDWyA0EMi 7G5g/jBnIN9JJ+Zk+X0gswWQxowdtuMwh7yPQk/Zn/JW3ZTyUCmK/FMYw6BhWSy8faeZ jc4MM2aqsiRrlboniRUX+yLhdap3NgxAxgmV1Lv5NWKdmjz/c0+KOX+FLWD0e0CVzhqu c4GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qUBg4F2w42ifFGcRoyXQkPsTj7mdb/CGi2CkiubKUc0=; b=2aXLSvAoP31Lscl3lmXgB0o2QjC/KHfCQ+BSrQztGn6sExG/joVkwqNNQgO7nj5D15 CRrGu2J1/HBe+xJoiVEXtBkonqCAR4limi1H6uVGPXYoa+ahxPm/5LUolgSQsoq6jo5I FqYXz3TZ6ynZM5wFf1fVI1Niy0TXUMPDnftd/1tM1kuwMD8R8rtY3wUEUGn6TBZVCNx6 nG8KReAItnBC6/9sGn99xL/XMk85smdwggoalOlH/KcNBqLC+wSDArg47k5bDwKVbFW8 8nJ/yqCZchszlqgaF0OXIKxU3t2LoFZIT0ZFPY0Ol7tr/YspbjSN+DbpGN6+XPqv3Hil Ux/g== X-Gm-Message-State: AOAM530wm98Xfz/8++4JZdogpy6rhMmvgP34vJatObeclPRob+iontBo sRgwOsAjgNMlZUXQpx6aJcY= X-Google-Smtp-Source: ABdhPJwBvzTRy5YJpHsYXww2XdOyY+8K1i1KwZIavfAODrYHcI03/OEIbmS4ar1eJii0h6f23jefCg== X-Received: by 2002:a17:90b:4a01:: with SMTP id kk1mr9744254pjb.7.1636197988488; Sat, 06 Nov 2021 04:26:28 -0700 (PDT) Received: from localhost.localdomain ([124.253.6.45]) by smtp.googlemail.com with ESMTPSA id c21sm10971037pfl.15.2021.11.06.04.26.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 04:26:27 -0700 (PDT) From: Puranjay Mohan To: bhelgaas@google.com, linux-pci@vger.kernel.org Cc: Puranjay Mohan Subject: [PATCH 2/2] PCI: Use resource names in PCI log messages Date: Sat, 6 Nov 2021 16:56:06 +0530 Message-Id: <20211106112606.192563-3-puranjay12@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20211106112606.192563-1-puranjay12@gmail.com> References: <20211106112606.192563-1-puranjay12@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Use the pci_resource_name() to get the name of the resource and use it while printing log messages. Signed-off-by: Puranjay Mohan --- drivers/pci/probe.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index d9fc02a71baa..407854d17efa 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -181,6 +181,8 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, u64 l64, sz64, mask64; u16 orig_cmd; struct pci_bus_region region, inverted_region; + int idx = res - dev->resource; + const char *resource_name = pci_resource_name(dev, idx); mask = type ? PCI_ROM_ADDRESS_MASK : ~0; @@ -255,8 +257,8 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, sz64 = pci_size(l64, sz64, mask64); if (!sz64) { - pci_info(dev, FW_BUG "reg 0x%x: invalid BAR (can't size)\n", - pos); + pci_info(dev, FW_BUG "%s: invalid BAR (can't size)\n", + resource_name); goto fail; } @@ -266,8 +268,8 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, res->flags |= IORESOURCE_UNSET | IORESOURCE_DISABLED; res->start = 0; res->end = 0; - pci_err(dev, "reg 0x%x: can't handle BAR larger than 4GB (size %#010llx)\n", - pos, (unsigned long long)sz64); + pci_err(dev, "%s: can't handle BAR larger than 4GB (size %#010llx)\n", + resource_name, (unsigned long long)sz64); goto out; } @@ -276,8 +278,8 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, res->flags |= IORESOURCE_UNSET; res->start = 0; res->end = sz64 - 1; - pci_info(dev, "reg 0x%x: can't handle BAR above 4GB (bus address %#010llx)\n", - pos, (unsigned long long)l64); + pci_info(dev, "%s: can't handle BAR above 4GB (bus address %#010llx)\n", + resource_name, (unsigned long long)l64); goto out; } } @@ -303,8 +305,8 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, res->flags |= IORESOURCE_UNSET; res->start = 0; res->end = region.end - region.start; - pci_info(dev, "reg 0x%x: initial BAR value %#010llx invalid\n", - pos, (unsigned long long)region.start); + pci_info(dev, "%s: initial BAR value %#010llx invalid\n", + resource_name, (unsigned long long)region.start); } goto out; @@ -314,7 +316,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, res->flags = 0; out: if (res->flags) - pci_info(dev, "reg 0x%x: %pR\n", pos, res); + pci_info(dev, "%s: %pR\n", resource_name, res); return (res->flags & IORESOURCE_MEM_64) ? 1 : 0; }