From patchwork Wed Nov 25 17:20:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 332380 Delivered-To: patch@linaro.org Received: by 2002:a92:5e16:0:0:0:0:0 with SMTP id s22csp622908ilb; Wed, 25 Nov 2020 09:25:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJx7x7Rb+XAW5mFumL7x3XHUI0H7VvswI5P2hNqxiUpjhiEQL9Ie+YW67fbcY6h4x6/DzxbF X-Received: by 2002:a17:906:4756:: with SMTP id j22mr4102159ejs.315.1606325107357; Wed, 25 Nov 2020 09:25:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606325107; cv=none; d=google.com; s=arc-20160816; b=WOH7+Dsc57sWuR4Vuaw+usYlHluFZ7Mepemf/R6gfoLIXKxWek2QEvHsfBtJ0Pzqjq HeBIN/sIP882Z+BgGcVxZT8hK8FH4/cWM38hRtecQ6rrfLk2CkkhXSK8lwdsEUKnunuK lJQXyrx8sDwfgDZ/5qTv91VU7WckD3hhaaRlR6qzlFUuwVBC769IkkE9wgOGKBEE8ynu pe1q27LCMqMOjf/mtIutDc+drVYy474SByxAwcu7AEt2oUfNeCR/YMZmnZqXRauX4LEs p7PtAlVyfD8DNvz1/syQT4abCksXM5zaWeaxXC72oPA4wu7zD7RutqrcfwpfEQaqmJo5 HSsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=+aC3ykKw9fCG7TeYHja+8D7HSCvquw7rdN7rxKCDF7I=; b=jYH5trpIYeDDDv5j/u5BqWpSDLKnVpcWjoWufeRlsRSVN27mR4F0u5vELOUaPLiSSr pZz8nxs9SruDhXsHLl01dMaZ7rbX2aHdcO3FKEYhcx6c3FD4uI64jjcXYZmA/2WBjlrH qMHlCAIsZ4LDZw7im6jtaq+/BdpdZUBPwL/3NKQ6pBSmy9VK3qjcZgFPh+AZLuu8TxbE RgLkUcb/fRku4OZUfEiukYEY7chM4rlp5lQ5VX2jfOPbG3ruJZkqiiL6dhTmMnH82FbU H42NrBmMPa3wWplPqjbVnf6B1bc8dXPT0OOHHXQbqvUCa+8rP/IfabgLL+1XICtt66gh 01cg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k22si2164875edj.571.2020.11.25.09.25.07 for ; Wed, 25 Nov 2020 09:25:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732700AbgKYRYz (ORCPT ); Wed, 25 Nov 2020 12:24:55 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:8035 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731278AbgKYRYx (ORCPT ); Wed, 25 Nov 2020 12:24:53 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Ch76f57gkzhcWr; Thu, 26 Nov 2020 01:24:26 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Thu, 26 Nov 2020 01:24:37 +0800 From: John Garry To: , , , , , CC: , , , , , "John Garry" Subject: [PATCH v3 1/5] genirq/affinity: Add irq_update_affinity_desc() Date: Thu, 26 Nov 2020 01:20:37 +0800 Message-ID: <1606324841-217570-2-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1606324841-217570-1-git-send-email-john.garry@huawei.com> References: <1606324841-217570-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add a function to allow the affinity of an interrupt be switched to managed, such that interrupts allocated for platform devices may be managed. Suggested-by: Thomas Gleixner Signed-off-by: John Garry --- include/linux/interrupt.h | 8 +++++ kernel/irq/manage.c | 63 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) -- 2.26.2 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h index ee8299eb1f52..870b3251e174 100644 --- a/include/linux/interrupt.h +++ b/include/linux/interrupt.h @@ -352,6 +352,8 @@ extern int irq_can_set_affinity(unsigned int irq); extern int irq_select_affinity(unsigned int irq); extern int irq_set_affinity_hint(unsigned int irq, const struct cpumask *m); +extern int irq_update_affinity_desc(unsigned int irq, + struct irq_affinity_desc *affinity); extern int irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify); @@ -387,6 +389,12 @@ static inline int irq_set_affinity_hint(unsigned int irq, return -EINVAL; } +static inline int irq_update_affinity_desc(unsigned int irq, + struct irq_affinity_desc *affinity) +{ + return -EINVAL; +} + static inline int irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify) { diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index c460e0496006..8201aff639f7 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -371,6 +371,69 @@ int irq_set_affinity_locked(struct irq_data *data, const struct cpumask *mask, return ret; } +/** + * irq_update_affinity_desc - Update affinity management for an interrupt + * @irq: The interrupt number to update + * @affinity: Pointer to the affinity descriptor + * + * This interface can be used to configure the affinity management of + * interrupts which have been allocated already. + */ +int irq_update_affinity_desc(unsigned int irq, + struct irq_affinity_desc *affinity) +{ + struct irq_desc *desc; + unsigned long flags; + bool activated; + int ret = 0; + + /* + * Supporting this with the reservation scheme used by x86 needs + * some more thought. Fail it for now. + */ + if (IS_ENABLED(CONFIG_GENERIC_IRQ_RESERVATION_MODE)) + return -EOPNOTSUPP; + + desc = irq_get_desc_buslock(irq, &flags, 0); + if (!desc) + return -EINVAL; + + /* Requires the interrupt to be shut down */ + if (irqd_is_started(&desc->irq_data)) { + ret = -EBUSY; + goto out_unlock; + } + + /* Interrupts which are already managed cannot be modified */ + if (irqd_affinity_is_managed(&desc->irq_data)) { + ret = -EBUSY; + goto out_unlock; + } + + /* + * Deactivate the interrupt. That's required to undo + * anything an earlier activation has established. + */ + activated = irqd_is_activated(&desc->irq_data); + if (activated) + irq_domain_deactivate_irq(&desc->irq_data); + + if (affinity->is_managed) { + irqd_set(&desc->irq_data, IRQD_AFFINITY_MANAGED); + irqd_set(&desc->irq_data, IRQD_MANAGED_SHUTDOWN); + } + + cpumask_copy(desc->irq_common_data.affinity, &affinity->mask); + + /* Restore the activation state */ + if (activated) + irq_domain_deactivate_irq(&desc->irq_data); + +out_unlock: + irq_put_desc_busunlock(desc, flags); + return ret; +} + int __irq_set_affinity(unsigned int irq, const struct cpumask *mask, bool force) { struct irq_desc *desc = irq_to_desc(irq); From patchwork Wed Nov 25 17:20:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 332378 Delivered-To: patch@linaro.org Received: by 2002:a92:5e16:0:0:0:0:0 with SMTP id s22csp622886ilb; Wed, 25 Nov 2020 09:25:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJxPSr/F/uC8vzvfnuQjtdhuo8MT3W6rmEzOXbtWzXB7bmPS5MZHA8lmyxaunE+/ivdAZ1NK X-Received: by 2002:a50:f147:: with SMTP id z7mr4471562edl.76.1606325105723; Wed, 25 Nov 2020 09:25:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606325105; cv=none; d=google.com; s=arc-20160816; b=fXk6ngSFUxTZmI8EIj0NEZlr6tdwTUv08bZV7agOday9F8vy8JbbAdMvWLeOpUjifH jDYG91AoboFMkm6Ul0HR/k07IwsyqcntX30JW3V3hkihd3F4WoFAqC1h9eY+I/C4VEk8 GE3Rw8YBolGGAB/cHR4LEAbUdDR72TSwpQYX+AY2hN5ylKIqpxM+0/pq8qI/XSuHnbts 444pHUpEY/MOyR4XVA1RByf8lHj7y8QFwyixgJ4rJ66Djdo1jn6oHDf1TZXcSQxzm90B wBAhwLQDFrPABOWue1wrZl+5VffhIemYrhsugz86tqC6pIjj1qWV83u5ByDNeWueSHeV qSzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=YXQIOB/6p4NQaBehOVwuK6HZht+ocPfwMk8UVYmbSss=; b=azLpTf+RfsYH8jTsOh8QqO0gKuxoHZ7vC3tl/GF+t6HIY6wXIODff4AvVfeTXDQ4Dv erhWjucDLICgZrRcmlkLaUYHdeqmhx8qblBsJcitwR/e9n5Fp7gXnUbSZDrCjJQx/8v4 SKXLQpUoII9P878CHgBxPBqE1uJi5LP9N/HVx/tTj0lmSCPHGQm2jy0n1gndT3eEO+Vm 052zNqwbgKzhG6cYxdyJYGJW6sqgtBvbfOyvD6pfavWtn/G52C2xhl/P084zrc4rmWj5 gyZ3E9EKTe6BuAgFR+jv+ctVs5cggOm/ejWZPl5cgj03Logg6BxLL1k2Elaw67Ly96GB 2SFg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k22si2164875edj.571.2020.11.25.09.25.05 for ; Wed, 25 Nov 2020 09:25:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732692AbgKYRYz (ORCPT ); Wed, 25 Nov 2020 12:24:55 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:8036 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731127AbgKYRYy (ORCPT ); Wed, 25 Nov 2020 12:24:54 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Ch76f4sSDzhc0Z; Thu, 26 Nov 2020 01:24:26 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Thu, 26 Nov 2020 01:24:38 +0800 From: John Garry To: , , , , , CC: , , , , , "John Garry" Subject: [PATCH v3 2/5] ACPI: Make acpi_dev_irqresource_disabled() public Date: Thu, 26 Nov 2020 01:20:38 +0800 Message-ID: <1606324841-217570-3-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1606324841-217570-1-git-send-email-john.garry@huawei.com> References: <1606324841-217570-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org To allow the platform device to "put" an irq, make the function to reset an ACPI companion device irq resource public. Signed-off-by: John Garry --- drivers/acpi/resource.c | 2 +- include/linux/acpi.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) -- 2.26.2 diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c index ad04824ca3ba..0999a98cab3c 100644 --- a/drivers/acpi/resource.c +++ b/drivers/acpi/resource.c @@ -380,7 +380,7 @@ unsigned int acpi_dev_get_irq_type(int triggering, int polarity) } EXPORT_SYMBOL_GPL(acpi_dev_get_irq_type); -static void acpi_dev_irqresource_disabled(struct resource *res, u32 gsi) +void acpi_dev_irqresource_disabled(struct resource *res, u32 gsi) { res->start = gsi; res->end = gsi; diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 39263c6b52e1..d5101e36a645 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -467,6 +467,7 @@ bool acpi_dev_resource_ext_address_space(struct acpi_resource *ares, struct resource_win *win); unsigned long acpi_dev_irq_flags(u8 triggering, u8 polarity, u8 shareable); unsigned int acpi_dev_get_irq_type(int triggering, int polarity); +void acpi_dev_irqresource_disabled(struct resource *res, u32 gsi); bool acpi_dev_resource_interrupt(struct acpi_resource *ares, int index, struct resource *res); @@ -939,6 +940,10 @@ static inline struct acpi_device *acpi_resource_consumer(struct resource *res) return NULL; } +static inline void acpi_dev_irqresource_disabled(struct resource *res, u32 gsi) +{ +} + #endif /* !CONFIG_ACPI */ #ifdef CONFIG_ACPI_HOTPLUG_IOAPIC From patchwork Wed Nov 25 17:20:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 332382 Delivered-To: patch@linaro.org Received: by 2002:a92:5e16:0:0:0:0:0 with SMTP id s22csp622937ilb; Wed, 25 Nov 2020 09:25:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJyOantGvnVZBdpIr2sGkJ8OSYBMwZlbgpks/BCeEACaOiPn5kP90GM/A74YGvx7sE59nJzZ X-Received: by 2002:a17:906:f744:: with SMTP id jp4mr4188011ejb.122.1606325109300; Wed, 25 Nov 2020 09:25:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606325109; cv=none; d=google.com; s=arc-20160816; b=WsV7BQPrfdBoW0+coPOJGIRuMraHDpefDCU/jfFbDuR4B2gqy4JWVNYlpbpy+sHrL+ ASQsbsqkcuGVjSLCqDYJf891clkQ2iVgbyjW8peKDwUqL2ai08163VRiRiWujsBYkzVo 2eBL3oyW/8OcN3qCtBpvZJOqvgquZECYNuA2tMOFf4lptk7GexN0cSAxOlswPypwGSCc lJH+TuvQbU68y1iTjqntRC3l4d501MlxhHkPP0u0XMYjMY3Hg2Ane4xBfIeQrSGxb+Fx gKuJIgq7QXqTee/ahoqcxMVBQ7uHH1E11pdkspTGcvJS5fkEPU9VB3haHXal+Z/Id/k1 ZsOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=FT8kpJdpX9o68giOqPnVPkI3/gJCcePn8D8B33EYOTg=; b=oXPnl9IPNbKj5bUF+yrnOa/1qklhsyOB4gezNuNQz8bEXv/7kmTB8m0UszXpAsWVlY OCHbhIh34HwE6bEPUDYINm56jfcvUcCeBjcN4MrqpIhl+n1rKMrOfQeX82QsqgPvf6ko SIuszxrgWY2Caq9jYeTwSwDFSrUrhEiMfvneH2cNtyZsifaWVicRkBwtFleBEBkH1YuU nAcbfm+5eTt4r5hsSCURPrhR/UxIK02Sjcngg/2GXBComsFsOkw0huJOm48KViTFwymC cdRxaknuhxaWeEXIur7bJnmovyvbU550cQThdlZmweJ2fP3bqGVXmRhB3AqAvL5XSuod YcnA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k22si2164875edj.571.2020.11.25.09.25.09 for ; Wed, 25 Nov 2020 09:25:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732721AbgKYRZB (ORCPT ); Wed, 25 Nov 2020 12:25:01 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:8037 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731631AbgKYRYx (ORCPT ); Wed, 25 Nov 2020 12:24:53 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Ch76f5frfzhf7m; Thu, 26 Nov 2020 01:24:26 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Thu, 26 Nov 2020 01:24:38 +0800 From: John Garry To: , , , , , CC: , , , , , "John Garry" Subject: [PATCH v3 3/5] driver core: platform: Add platform_put_irq() Date: Thu, 26 Nov 2020 01:20:39 +0800 Message-ID: <1606324841-217570-4-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1606324841-217570-1-git-send-email-john.garry@huawei.com> References: <1606324841-217570-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add a function to tear down the work which was done in platform_get_irq() for when the device driver is done with the irq. For ACPI companion devices the irq resource is set as disabled, as this resource is configured from platform_get_irq()->acpi_irq_get() and requires resetting. Signed-off-by: John Garry --- drivers/base/platform.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) -- 2.26.2 diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 88aef93eb4dd..3eeda3746701 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -289,6 +289,20 @@ int platform_irq_count(struct platform_device *dev) } EXPORT_SYMBOL_GPL(platform_irq_count); +void platform_put_irq(struct platform_device *dev, unsigned int num) +{ + unsigned int virq = platform_get_irq(dev, num); + + irq_dispose_mapping(virq); + if (has_acpi_companion(&dev->dev)) { + struct resource *r = platform_get_resource(dev, IORESOURCE_IRQ, + num); + + if (r) + acpi_dev_irqresource_disabled(r, 0); + } +} + /** * platform_get_resource_byname - get a resource for a device by name * @dev: platform device From patchwork Wed Nov 25 17:20:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 332721 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT 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 9A799C83013 for ; Wed, 25 Nov 2020 17:25:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5A40321973 for ; Wed, 25 Nov 2020 17:25:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732587AbgKYRYu (ORCPT ); Wed, 25 Nov 2020 12:24:50 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:8585 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731220AbgKYRYu (ORCPT ); Wed, 25 Nov 2020 12:24:50 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Ch76X2gxzzLtmw; Thu, 26 Nov 2020 01:24:20 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Thu, 26 Nov 2020 01:24:39 +0800 From: John Garry To: , , , , , CC: , , , , , "John Garry" Subject: [PATCH v3 4/5] Driver core: platform: Add devm_platform_get_irqs_affinity() Date: Thu, 26 Nov 2020 01:20:40 +0800 Message-ID: <1606324841-217570-5-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1606324841-217570-1-git-send-email-john.garry@huawei.com> References: <1606324841-217570-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Drivers for multi-queue platform devices may also want managed interrupts for handling HW queue completion interrupts, so add support. The function accepts an affinity descriptor pointer, which covers a set of irqs for the device. The reason a devm method is added - as opposed to non-devm - is because the only current in-tree user will also use devm method for requesting the interrupts; as such, the function is made as devm as it can ensure ordering of freeing the irq and disposing of the mapping. Signed-off-by: John Garry --- drivers/base/platform.c | 114 +++++++++++++++++++++++++++++++- include/linux/platform_device.h | 6 ++ 2 files changed, 119 insertions(+), 1 deletion(-) diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 3eeda3746701..08f4175c4ac8 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -289,7 +290,7 @@ int platform_irq_count(struct platform_device *dev) } EXPORT_SYMBOL_GPL(platform_irq_count); -void platform_put_irq(struct platform_device *dev, unsigned int num) +static void platform_put_irq(struct platform_device *dev, unsigned int num) { unsigned int virq = platform_get_irq(dev, num); @@ -303,6 +304,117 @@ void platform_put_irq(struct platform_device *dev, unsigned int num) } } +struct irq_affinity_devres { + unsigned int count; + void *dev_id; + unsigned int irq[]; +}; + +static void devm_platform_get_irqs_affinity_release(struct device *dev, + void *res) +{ + struct platform_device *pdev = to_platform_device(dev); + struct irq_affinity_devres *ptr = res; + int i; + + for (i = 0; i < ptr->count; i++) + platform_put_irq(pdev, i); +} + +/** + * devm_platform_get_irqs_affinity - devm method to get a set of IRQs for a + * device using an interrupt affinity descriptor + * @dev: platform device pointer + * @affd: affinity descriptor + * @minvec: minimum count of interrupt vectors + * @maxvec: maximum count of interrupt vectors + * @irqs: pointer holder for IRQ numbers + * + * Gets a set of IRQs for a platform device, and updates IRQ afffinty according + * to the passed affinity descriptor + * + * Return: Number of vectors on success, negative error number on failure. + */ +int devm_platform_get_irqs_affinity(struct platform_device *dev, + struct irq_affinity *affd, + unsigned int minvec, + unsigned int maxvec, + int **irqs) +{ + struct irq_affinity_devres *ptr; + struct irq_affinity_desc *desc; + size_t size; + int i, ret, nvec; + + if (!affd) + return -EPERM; + + if (maxvec < minvec) + return -ERANGE; + + nvec = platform_irq_count(dev); + + if (nvec < minvec) + return -ENOSPC; + + if (nvec <= affd->pre_vectors + affd->post_vectors) + return -EIO; + + nvec = irq_calc_affinity_vectors(minvec, nvec, affd); + if (nvec < minvec) + return -ENOSPC; + + if (nvec > maxvec) + nvec = maxvec; + + size = sizeof(*ptr) + sizeof(unsigned int) * nvec; + ptr = devres_alloc(devm_platform_get_irqs_affinity_release, size, + GFP_KERNEL); + if (!ptr) + return -ENOMEM; + + ptr->count = nvec; + + for (i = 0; i < nvec; i++) { + int irq = platform_get_irq(dev, i); + if (irq < 0) { + ret = irq; + goto err_free_devres; + } + ptr->irq[i] = irq; + } + + desc = irq_create_affinity_masks(nvec, affd); + if (!desc) { + ret = -ENOMEM; + goto err_free_devres; + } + + for (i = 0; i < nvec; i++) { + ret = irq_update_affinity_desc(ptr->irq[i], &desc[i]); + if (ret) { + dev_err(&dev->dev, "failed to update irq%d affinity descriptor (%d)\n", + ptr->irq[i], ret); + goto err_free_desc; + } + } + + devres_add(&dev->dev, ptr); + + kfree(desc); + + *irqs = ptr->irq; + + return nvec; + +err_free_desc: + kfree(desc); +err_free_devres: + devres_free(ptr); + return ret; +} +EXPORT_SYMBOL_GPL(devm_platform_get_irqs_affinity); + /** * platform_get_resource_byname - get a resource for a device by name * @dev: platform device diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h index 77a2aada106d..4d75633e6735 100644 --- a/include/linux/platform_device.h +++ b/include/linux/platform_device.h @@ -15,6 +15,7 @@ #define PLATFORM_DEVID_NONE (-1) #define PLATFORM_DEVID_AUTO (-2) +struct irq_affinity; struct mfd_cell; struct property_entry; struct platform_device_id; @@ -70,6 +71,11 @@ devm_platform_ioremap_resource_byname(struct platform_device *pdev, extern int platform_get_irq(struct platform_device *, unsigned int); extern int platform_get_irq_optional(struct platform_device *, unsigned int); extern int platform_irq_count(struct platform_device *); +extern int devm_platform_get_irqs_affinity(struct platform_device *dev, + struct irq_affinity *affd, + unsigned int minvec, + unsigned int maxvec, + int **irqs); extern struct resource *platform_get_resource_byname(struct platform_device *, unsigned int, const char *); From patchwork Wed Nov 25 17:20:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 332381 Delivered-To: patch@linaro.org Received: by 2002:a92:5e16:0:0:0:0:0 with SMTP id s22csp622929ilb; Wed, 25 Nov 2020 09:25:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJwv4KdxAqm+XVvwvw+spJGTSRcYdkCnhpqjmD3tP7jiy4k0VPYeC+Xz6JuuezBtL5HiG5WB X-Received: by 2002:a17:906:787:: with SMTP id l7mr4140954ejc.31.1606325108580; Wed, 25 Nov 2020 09:25:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606325108; cv=none; d=google.com; s=arc-20160816; b=FSVOtUGq6B6B5N48wp2axJkfP5SyDSyOaNJ1ErchwFYcHA6Ig0mmSubXd5uh3KaeCT 9AtP4J4fgxyLYdpL/U5ujzdHNLda+VOvCmGMz5gLDWmkoCOdbd+ksXR8pxIeUrVmolNY mhZvSn/g4Wy3OrV5ufMzWyPoWiTByHAM1wM+RHoDOiPAl93bkC19/OEYGOlSwMUgDBGB 6eT6TKS8ttZ6WSg4C4ElPACmDTCAlzkxXgYX1NrvDLgKEpOLGy7//i4qQAGy0hedgnIf Lx9pns6hrmr0kVH9frGrw2C72a28QS9jLBrkn58WHxp5cEJp7lCbjIYIMIRp34gNKXso wopg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=fe3TzQCjIESjos1ugBPsR3ZNIs+lW2r7cE8z4Ti7Jvc=; b=nzDRSZl9B4DgalUqUczUxAQzfaunxKJOB+SbtqlioAeQq8mG3h7UePH2nXuMx+lIqF 7DyKfOMBjoS2cxB1jerNDpBXgHEvKNn2YjFszrPe8t1k+QMXehFF/ziMKBYljehw9Oib eNSueak298CzMf18P+cI7w+hBkUuEfh8GFVkIqxpJzlq7yuWz9jNpiHqgi6vgfgnq/Ll NU3ibPtWN8R2dfMJD4qDgs/BKCGUqFhqqZhW9vQBBj3TKTYu69m4J/B7B2Bf52BarnZf v6AdmcJD8/77f3EeDwUV+l0VHWsTteRQVuKb87F03JJZalEREn6YmjL2A/NOEMoAcmLt 2//Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k22si2164875edj.571.2020.11.25.09.25.08 for ; Wed, 25 Nov 2020 09:25:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732680AbgKYRYx (ORCPT ); Wed, 25 Nov 2020 12:24:53 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:8586 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731170AbgKYRYx (ORCPT ); Wed, 25 Nov 2020 12:24:53 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Ch76X2M1fzLtm3; Thu, 26 Nov 2020 01:24:20 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Thu, 26 Nov 2020 01:24:39 +0800 From: John Garry To: , , , , , CC: , , , , , "John Garry" Subject: [PATCH v3 5/5] scsi: hisi_sas: Expose HW queues for v2 hw Date: Thu, 26 Nov 2020 01:20:41 +0800 Message-ID: <1606324841-217570-6-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1606324841-217570-1-git-send-email-john.garry@huawei.com> References: <1606324841-217570-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org As a performance enhancement, make the completion queue interrupts managed. In addition, in commit bf0beec0607d ("blk-mq: drain I/O when all CPUs in a hctx are offline"), CPU hotplug for MQ devices using managed interrupts is made safe. So expose HW queues to blk-mq to take advantage of this. Flag Scsi_host.host_tagset is also set to ensure that the HBA is not sent more commands than it can handle. However the driver still does not use request tag for IPTT as there are many HW bugs means that special rules apply for IPTT allocation. Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas.h | 4 ++ drivers/scsi/hisi_sas/hisi_sas_main.c | 11 +++++ drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 68 +++++++++++++++++++++----- 3 files changed, 70 insertions(+), 13 deletions(-) -- 2.26.2 diff --git a/drivers/scsi/hisi_sas/hisi_sas.h b/drivers/scsi/hisi_sas/hisi_sas.h index a25cfc11c96d..aa67807c5693 100644 --- a/drivers/scsi/hisi_sas/hisi_sas.h +++ b/drivers/scsi/hisi_sas/hisi_sas.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -312,6 +313,7 @@ enum { struct hisi_sas_hw { int (*hw_init)(struct hisi_hba *hisi_hba); + int (*interrupt_preinit)(struct hisi_hba *hisi_hba); void (*setup_itct)(struct hisi_hba *hisi_hba, struct hisi_sas_device *device); int (*slot_index_alloc)(struct hisi_hba *hisi_hba, @@ -418,6 +420,8 @@ struct hisi_hba { u32 refclk_frequency_mhz; u8 sas_addr[SAS_ADDR_SIZE]; + int *irq_map; /* v2 hw */ + int n_phy; spinlock_t lock; struct semaphore sem; diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c index c8dd8588f800..624c5ec723fb 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -2614,6 +2614,13 @@ static struct Scsi_Host *hisi_sas_shost_alloc(struct platform_device *pdev, return NULL; } +static int hisi_sas_interrupt_preinit(struct hisi_hba *hisi_hba) +{ + if (hisi_hba->hw->interrupt_preinit) + return hisi_hba->hw->interrupt_preinit(hisi_hba); + return 0; +} + int hisi_sas_probe(struct platform_device *pdev, const struct hisi_sas_hw *hw) { @@ -2671,6 +2678,10 @@ int hisi_sas_probe(struct platform_device *pdev, sha->sas_port[i] = &hisi_hba->port[i].sas_port; } + rc = hisi_sas_interrupt_preinit(hisi_hba); + if (rc) + goto err_out_ha; + rc = scsi_add_host(shost, &pdev->dev); if (rc) goto err_out_ha; diff --git a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c index b57177b52fac..6ad486e49468 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c @@ -3302,6 +3302,30 @@ static irq_handler_t fatal_interrupts[HISI_SAS_FATAL_INT_NR] = { fatal_axi_int_v2_hw }; +#define CQ0_IRQ_INDEX (96) + +static int hisi_sas_v2_interrupt_preinit(struct hisi_hba *hisi_hba) +{ + struct platform_device *pdev = hisi_hba->platform_dev; + struct Scsi_Host *shost = hisi_hba->shost; + int nvec, *irqs; + struct irq_affinity desc = { + .pre_vectors = CQ0_IRQ_INDEX, + }; + + nvec = devm_platform_get_irqs_affinity(pdev, &desc, CQ0_IRQ_INDEX + 1, + CQ0_IRQ_INDEX + hisi_hba->queue_count, + &hisi_hba->irq_map); + if (nvec < 0) + return nvec; + + shost->nr_hw_queues = hisi_hba->cq_nvecs = nvec - 96; + + kfree(irqs); + + return 0; +} + /* * There is a limitation in the hip06 chipset that we need * to map in all mbigen interrupts, even if they are not used. @@ -3310,14 +3334,11 @@ static int interrupt_init_v2_hw(struct hisi_hba *hisi_hba) { struct platform_device *pdev = hisi_hba->platform_dev; struct device *dev = &pdev->dev; - int irq, rc = 0, irq_map[128]; + int irq, rc = 0; int i, phy_no, fatal_no, queue_no; - for (i = 0; i < 128; i++) - irq_map[i] = platform_get_irq(pdev, i); - for (i = 0; i < HISI_SAS_PHY_INT_NR; i++) { - irq = irq_map[i + 1]; /* Phy up/down is irq1 */ + irq = hisi_hba->irq_map[i + 1]; /* Phy up/down is irq1 */ rc = devm_request_irq(dev, irq, phy_interrupts[i], 0, DRV_NAME " phy", hisi_hba); if (rc) { @@ -3331,7 +3352,7 @@ static int interrupt_init_v2_hw(struct hisi_hba *hisi_hba) for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++) { struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; - irq = irq_map[phy_no + 72]; + irq = hisi_hba->irq_map[phy_no + 72]; rc = devm_request_irq(dev, irq, sata_int_v2_hw, 0, DRV_NAME " sata", phy); if (rc) { @@ -3343,7 +3364,7 @@ static int interrupt_init_v2_hw(struct hisi_hba *hisi_hba) } for (fatal_no = 0; fatal_no < HISI_SAS_FATAL_INT_NR; fatal_no++) { - irq = irq_map[fatal_no + 81]; + irq = hisi_hba->irq_map[fatal_no + 81]; rc = devm_request_irq(dev, irq, fatal_interrupts[fatal_no], 0, DRV_NAME " fatal", hisi_hba); if (rc) { @@ -3354,24 +3375,22 @@ static int interrupt_init_v2_hw(struct hisi_hba *hisi_hba) } } - for (queue_no = 0; queue_no < hisi_hba->queue_count; queue_no++) { + for (queue_no = 0; queue_no < hisi_hba->cq_nvecs; queue_no++) { struct hisi_sas_cq *cq = &hisi_hba->cq[queue_no]; - cq->irq_no = irq_map[queue_no + 96]; + cq->irq_no = hisi_hba->irq_map[queue_no + 96]; rc = devm_request_threaded_irq(dev, cq->irq_no, cq_interrupt_v2_hw, cq_thread_v2_hw, IRQF_ONESHOT, DRV_NAME " cq", cq); if (rc) { dev_err(dev, "irq init: could not request cq interrupt %d, rc=%d\n", - irq, rc); + cq->irq_no, rc); rc = -ENOENT; goto err_out; } + cq->irq_mask = irq_get_affinity_mask(cq->irq_no); } - - hisi_hba->cq_nvecs = hisi_hba->queue_count; - err_out: return rc; } @@ -3529,6 +3548,26 @@ static struct device_attribute *host_attrs_v2_hw[] = { NULL }; +static int map_queues_v2_hw(struct Scsi_Host *shost) +{ + struct hisi_hba *hisi_hba = shost_priv(shost); + struct blk_mq_queue_map *qmap = &shost->tag_set.map[HCTX_TYPE_DEFAULT]; + const struct cpumask *mask; + unsigned int queue, cpu; + + for (queue = 0; queue < qmap->nr_queues; queue++) { + mask = irq_get_affinity_mask(hisi_hba->irq_map[96 + queue]); + if (!mask) + continue; + + for_each_cpu(cpu, mask) + qmap->mq_map[cpu] = qmap->queue_offset + queue; + } + + return 0; + +} + static struct scsi_host_template sht_v2_hw = { .name = DRV_NAME, .proc_name = DRV_NAME, @@ -3553,10 +3592,13 @@ static struct scsi_host_template sht_v2_hw = { #endif .shost_attrs = host_attrs_v2_hw, .host_reset = hisi_sas_host_reset, + .map_queues = map_queues_v2_hw, + .host_tagset = 1, }; static const struct hisi_sas_hw hisi_sas_v2_hw = { .hw_init = hisi_sas_v2_init, + .interrupt_preinit = hisi_sas_v2_interrupt_preinit, .setup_itct = setup_itct_v2_hw, .slot_index_alloc = slot_index_alloc_quirk_v2_hw, .alloc_dev = alloc_dev_quirk_v2_hw,