From patchwork Fri Jul 17 21:32:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 6819411 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5B7F9C05AC for ; Fri, 17 Jul 2015 21:32:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4A0CA2081B for ; Fri, 17 Jul 2015 21:32:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2BACB20810 for ; Fri, 17 Jul 2015 21:32:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752840AbbGQVcF (ORCPT ); Fri, 17 Jul 2015 17:32:05 -0400 Received: from mail-oi0-f50.google.com ([209.85.218.50]:34079 "EHLO mail-oi0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752605AbbGQVcD (ORCPT ); Fri, 17 Jul 2015 17:32:03 -0400 Received: by oigd21 with SMTP id d21so36094289oig.1 for ; Fri, 17 Jul 2015 14:32:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=subject:to:from:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-type:content-transfer-encoding; bh=pm0tWjLKxytrqMXRkDgs8M+S7V5UEdHhQj8MtBgsXIU=; b=B8vPJ+Q06fR529DqsVRgVpWlGp5SOfLKYU9DWSmQeApb4KXqo2fmnvB0/OifJMTrlX Lbb+D8pM8s1mcVsh6cV6cCizqjrVWdlZke+mR18bL2ygBF4a6N01Vcn9LktpXLMVq3bT VxwsT3AHIzVrITikkKTiSxWbV5tkkv81GFpYzOtLnS+9vF2uYX5+58Rlgbneq7GLvTR1 OSZWOWtq+IHVMZrxktIg2XrMqxEvx05a5Nq0zRWzoYvDikDXiZczqmcvyZ6B/MXZBc0p 8wRhDjfHhio8rAso0nBhcqEPhYBQb5EN0Tx9iTYl6Xs2yKGSD0sx9cf3052BBwFfi9To HK8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:from:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-type :content-transfer-encoding; bh=pm0tWjLKxytrqMXRkDgs8M+S7V5UEdHhQj8MtBgsXIU=; b=QvdgbyRwJ/Q2CTTaBTamwSu60hZA+egeoHvUA8aGzX1fxRNG4w8v2aZXkQGGyMETmX ntUZoBjZpmgXXftAQogyFe0AVCFWitiqEcPU/mKJahp9nliUEKXw2G4IKfoBgFrM1sAX 63zMYp1CAZwimbJz5SSkCNq85rZtD/pWQPIWuYOiRKuMClLsgjnB6Sj0gPzWMYr8wkmz 4D0DaUwak8LyrV8+AleGqQp6Q0qcqE4RVf2wgVQP6QwHqNIbDtsiKgGyntJeK573x1be jos1HJVNWcbY5+Z3krzTZjb8cFcZM9ug6V2oJ9IwCyhDS04yGY6JzsxoXR4t2wYh/guO SrKw== X-Gm-Message-State: ALoCoQlKgvO2RPTABmnWpIhcYKbezsI0N9proMg9iymV6ID5KulyCbb/FlcDD/HOEQL0rynDIS4x X-Received: by 10.182.230.234 with SMTP id tb10mr16118317obc.23.1437168723052; Fri, 17 Jul 2015 14:32:03 -0700 (PDT) Received: from localhost ([146.7.4.71]) by smtp.gmail.com with ESMTPSA id j2sm6919178oed.9.2015.07.17.14.32.01 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 17 Jul 2015 14:32:01 -0700 (PDT) Subject: [PATCH 2/8] PCI: Embed ATS info directly into struct pci_dev To: linux-pci@vger.kernel.org, Joerg Roedel From: Bjorn Helgaas Cc: Gregor Dick Date: Fri, 17 Jul 2015 16:32:00 -0500 Message-ID: <20150717213200.18379.96435.stgit@bhelgaas-glaptop2.roam.corp.google.com> In-Reply-To: <20150717212759.18379.44858.stgit@bhelgaas-glaptop2.roam.corp.google.com> References: <20150717212759.18379.44858.stgit@bhelgaas-glaptop2.roam.corp.google.com> User-Agent: StGit/0.16 MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-8.0 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There are only 33 bits of information in the pci_ats struct, and we previously allocated it dynamically and maintained a pointer to it from the pci_dev struct. Move the ATS fields into struct pci_dev so we don't need the pointer and we don't have to allocate anything extra. Signed-off-by: Bjorn Helgaas --- drivers/pci/ats.c | 53 ++++++++++++++++------------------------------- include/linux/pci-ats.h | 9 +------- include/linux/pci.h | 7 ++++-- 3 files changed, 23 insertions(+), 46 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/pci/ats.c b/drivers/pci/ats.c index 923759f..2f1fb9c 100644 --- a/drivers/pci/ats.c +++ b/drivers/pci/ats.c @@ -21,27 +21,15 @@ static void ats_alloc_one(struct pci_dev *dev) { int pos; u16 cap; - struct pci_ats *ats; pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ATS); if (!pos) return; - ats = kzalloc(sizeof(*ats), GFP_KERNEL); - if (!ats) - return; - - ats->pos = pos; - pci_read_config_word(dev, pos + PCI_ATS_CAP, &cap); - ats->qdep = PCI_ATS_CAP_QDEP(cap) ? PCI_ATS_CAP_QDEP(cap) : + dev->ats_cap = pos; + pci_read_config_word(dev, dev->ats_cap + PCI_ATS_CAP, &cap); + dev->ats_qdep = PCI_ATS_CAP_QDEP(cap) ? PCI_ATS_CAP_QDEP(cap) : PCI_ATS_MAX_QDEP; - dev->ats = ats; -} - -static void ats_free_one(struct pci_dev *dev) -{ - kfree(dev->ats); - dev->ats = NULL; } void pci_ats_init(struct pci_dev *dev) @@ -49,11 +37,6 @@ void pci_ats_init(struct pci_dev *dev) ats_alloc_one(dev); } -void pci_ats_free(struct pci_dev *dev) -{ - ats_free_one(dev); -} - /** * pci_enable_ats - enable the ATS capability * @dev: the PCI device @@ -65,9 +48,9 @@ int pci_enable_ats(struct pci_dev *dev, int ps) { u16 ctrl; - BUG_ON(dev->ats && dev->ats->is_enabled); + BUG_ON(dev->ats_cap && dev->ats_enabled); - if (!dev->ats) + if (!dev->ats_cap) return -EINVAL; if (ps < PCI_ATS_MIN_STU) @@ -77,15 +60,15 @@ int pci_enable_ats(struct pci_dev *dev, int ps) if (dev->is_virtfn) { struct pci_dev *pdev = dev->physfn; - if (pdev->ats->stu != ps) + if (pdev->ats_stu != ps) return -EINVAL; } else { - dev->ats->stu = ps; - ctrl |= PCI_ATS_CTRL_STU(dev->ats->stu - PCI_ATS_MIN_STU); + dev->ats_stu = ps; + ctrl |= PCI_ATS_CTRL_STU(dev->ats_stu - PCI_ATS_MIN_STU); } - pci_write_config_word(dev, dev->ats->pos + PCI_ATS_CTRL, ctrl); + pci_write_config_word(dev, dev->ats_cap + PCI_ATS_CTRL, ctrl); - dev->ats->is_enabled = 1; + dev->ats_enabled = 1; return 0; } EXPORT_SYMBOL_GPL(pci_enable_ats); @@ -98,13 +81,13 @@ void pci_disable_ats(struct pci_dev *dev) { u16 ctrl; - BUG_ON(!dev->ats || !dev->ats->is_enabled); + BUG_ON(!dev->ats_cap || !dev->ats_enabled); - pci_read_config_word(dev, dev->ats->pos + PCI_ATS_CTRL, &ctrl); + pci_read_config_word(dev, dev->ats_cap + PCI_ATS_CTRL, &ctrl); ctrl &= ~PCI_ATS_CTRL_ENABLE; - pci_write_config_word(dev, dev->ats->pos + PCI_ATS_CTRL, ctrl); + pci_write_config_word(dev, dev->ats_cap + PCI_ATS_CTRL, ctrl); - dev->ats->is_enabled = 0; + dev->ats_enabled = 0; } EXPORT_SYMBOL_GPL(pci_disable_ats); @@ -119,8 +102,8 @@ void pci_restore_ats_state(struct pci_dev *dev) ctrl = PCI_ATS_CTRL_ENABLE; if (!dev->is_virtfn) - ctrl |= PCI_ATS_CTRL_STU(dev->ats->stu - PCI_ATS_MIN_STU); - pci_write_config_word(dev, dev->ats->pos + PCI_ATS_CTRL, ctrl); + ctrl |= PCI_ATS_CTRL_STU(dev->ats_stu - PCI_ATS_MIN_STU); + pci_write_config_word(dev, dev->ats_cap + PCI_ATS_CTRL, ctrl); } EXPORT_SYMBOL_GPL(pci_restore_ats_state); @@ -141,8 +124,8 @@ int pci_ats_queue_depth(struct pci_dev *dev) if (dev->is_virtfn) return 0; - if (dev->ats) - return dev->ats->qdep; + if (dev->ats_cap) + return dev->ats_qdep; return -ENODEV; } diff --git a/include/linux/pci-ats.h b/include/linux/pci-ats.h index d2e8170..5d81d47 100644 --- a/include/linux/pci-ats.h +++ b/include/linux/pci-ats.h @@ -4,13 +4,6 @@ #include /* Address Translation Service */ -struct pci_ats { - int pos; /* capability position */ - int stu; /* Smallest Translation Unit */ - int qdep; /* Invalidate Queue Depth */ - unsigned int is_enabled:1; /* Enable bit is set */ -}; - #ifdef CONFIG_PCI_ATS int pci_enable_ats(struct pci_dev *dev, int ps); @@ -25,7 +18,7 @@ int pci_ats_queue_depth(struct pci_dev *dev); */ static inline int pci_ats_enabled(struct pci_dev *dev) { - return dev->ats && dev->ats->is_enabled; + return dev->ats_cap && dev->ats_enabled; } #else /* CONFIG_PCI_ATS */ diff --git a/include/linux/pci.h b/include/linux/pci.h index 5c277f1..ba4a23b 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -343,6 +343,7 @@ struct pci_dev { unsigned int msi_enabled:1; unsigned int msix_enabled:1; unsigned int ari_enabled:1; /* ARI forwarding */ + unsigned int ats_enabled:1; /* Address Translation Service */ unsigned int is_managed:1; unsigned int needs_freset:1; /* Dev requires fundamental reset */ unsigned int state_saved:1; @@ -375,7 +376,9 @@ struct pci_dev { struct pci_sriov *sriov; /* SR-IOV capability related */ struct pci_dev *physfn; /* the PF this VF is associated with */ }; - struct pci_ats *ats; /* Address Translation Service */ + int ats_cap; /* ATS Capability offset */ + int ats_stu; /* ATS Smallest Translation Unit */ + int ats_qdep; /* ATS Invalidate Queue Depth */ #endif phys_addr_t rom; /* Physical address of ROM if it's not from the BAR */ size_t romlen; /* Length of ROM if it's not from the BAR */ @@ -1297,10 +1300,8 @@ void ht_destroy_irq(unsigned int irq); #ifdef CONFIG_PCI_ATS /* Address Translation Service */ void pci_ats_init(struct pci_dev *dev); -void pci_ats_free(struct pci_dev *dev); #else static inline void pci_ats_init(struct pci_dev *) { } -static inline void pci_ats_free(struct pci_dev *) { } #endif void pci_cfg_access_lock(struct pci_dev *dev);