From mboxrd@z Thu Jan 1 00:00:00 1970 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=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 EA981C433E9 for ; Sun, 24 Jan 2021 15:11:18 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AA9FB22B2B for ; Sun, 24 Jan 2021 15:11:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AA9FB22B2B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=socionext.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=GJS2UtEVY4/ifz3c+geSiEXYPQflcec5cATuldJIwo0=; b=WkTb8fc04UQgWOMZROiKmWiVmf N62kViBQO9lIwQ8HK4EeMNj4Wo7QMWrgAUsrKyOZSR2sY3on2uKayHzKCscde7Y+M/rbPL1B/cWcP kqPai5Ku1QR7m/2nMgsEOKaD5neFWuf2hb2q9DIw+UWw4KsOMm7R3tpYr87xf+7eW52saPQVawNW1 hTANTopAf4M6Bzpg9OUHEReZpxhl4cpFnn3YXWBJvQ9EZAm96UptRXy/t2lPuyaDApFb/1gGo2guz 1a96STM1iFvjJVYFRqL9774Ad1E4fiZ5CIJYAbbRZJRE/Z8A8LpBAyAe5frthaDKgGGqDjqzQiM1C 2luOE6cw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l3h1a-0003lI-2o; Sun, 24 Jan 2021 15:09:58 +0000 Received: from mx.socionext.com ([202.248.49.38]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l3h1O-0003iJ-ET for linux-arm-kernel@lists.infradead.org; Sun, 24 Jan 2021 15:09:48 +0000 Received: from unknown (HELO kinkan2-ex.css.socionext.com) ([172.31.9.52]) by mx.socionext.com with ESMTP; 25 Jan 2021 00:09:45 +0900 Received: from mail.mfilter.local (m-filter-2 [10.213.24.62]) by kinkan2-ex.css.socionext.com (Postfix) with ESMTP id 9876D2059027; Mon, 25 Jan 2021 00:09:45 +0900 (JST) Received: from 172.31.9.51 (172.31.9.51) by m-FILTER with ESMTP; Mon, 25 Jan 2021 00:09:45 +0900 Received: from plum.e01.socionext.com (unknown [10.213.132.32]) by kinkan2.css.socionext.com (Postfix) with ESMTP id DA7B3B1D40; Mon, 25 Jan 2021 00:09:44 +0900 (JST) From: Kunihiko Hayashi To: Lorenzo Pieralisi , Rob Herring , Bjorn Helgaas , Kishon Vijay Abraham I Subject: [PATCH v2 2/3] PCI: endpoint: Add endpoint restart management Date: Mon, 25 Jan 2021 00:09:36 +0900 Message-Id: <1611500977-24816-3-git-send-email-hayashi.kunihiko@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1611500977-24816-1-git-send-email-hayashi.kunihiko@socionext.com> References: <1611500977-24816-1-git-send-email-hayashi.kunihiko@socionext.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210124_100946_951560_5BF71289 X-CRM114-Status: GOOD ( 28.08 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kunihiko Hayashi , Masami Hiramatsu , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Jassi Brar , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add new functions to manage recovery of configuration parameters and restart the controller when asserting bus-reset from root-complex (RC). This feature is only available if bus-reset (PERST#) line is physically routed between RC and endpoint and the signal from RC affects endpoint. This feature works as follows. - This adds a polling thread, that polls and detects the bus-reset signal, and recovers configuration parameters for endpoint. The polling period is fixed at EPC_RESTART_POLL_PERIOD_MS. - After the endpoint controller starts and the user sets configuration parameters using sysfs or function drivers, once RC asserts bus-reset and endpoint can receive it, the endpoint controller will also reset and initialize configuration parameters. - If the thread detects bus-reset signal, the thread stops the controller, unbinds it, quickly binds it and restart it. The configuration paremters are restored to the user's values. Signed-off-by: Kunihiko Hayashi --- drivers/pci/endpoint/Kconfig | 9 +++ drivers/pci/endpoint/Makefile | 1 + drivers/pci/endpoint/pci-epc-restart.c | 114 +++++++++++++++++++++++++++++++++ include/linux/pci-epc.h | 15 +++++ 4 files changed, 139 insertions(+) create mode 100644 drivers/pci/endpoint/pci-epc-restart.c diff --git a/drivers/pci/endpoint/Kconfig b/drivers/pci/endpoint/Kconfig index 17bbdc9..016c82a 100644 --- a/drivers/pci/endpoint/Kconfig +++ b/drivers/pci/endpoint/Kconfig @@ -28,6 +28,15 @@ config PCI_ENDPOINT_CONFIGFS configure the endpoint function and used to bind the function with a endpoint controller. +config PCI_ENDPOINT_RESTART + bool "PCI Endpoint Restart Management Support" + depends on PCI_ENDPOINT + help + Enable restart management functions, which detects bus-reset + from root complex, and recover endpoint configuration. + This is only available if bus-reset line is physically routed + between root complex and endpoint. + source "drivers/pci/endpoint/functions/Kconfig" endmenu diff --git a/drivers/pci/endpoint/Makefile b/drivers/pci/endpoint/Makefile index 95b2fe4..7301aea 100644 --- a/drivers/pci/endpoint/Makefile +++ b/drivers/pci/endpoint/Makefile @@ -4,5 +4,6 @@ # obj-$(CONFIG_PCI_ENDPOINT_CONFIGFS) += pci-ep-cfs.o +obj-$(CONFIG_PCI_ENDPOINT_RESTART) += pci-epc-restart.o obj-$(CONFIG_PCI_ENDPOINT) += pci-epc-core.o pci-epf-core.o\ pci-epc-mem.o functions/ diff --git a/drivers/pci/endpoint/pci-epc-restart.c b/drivers/pci/endpoint/pci-epc-restart.c new file mode 100644 index 0000000..ab956be --- /dev/null +++ b/drivers/pci/endpoint/pci-epc-restart.c @@ -0,0 +1,114 @@ +// SPDX-License-Identifier: GPL-2.0 +/** + * PCI Endpoint Controller Restart Management + * + * Copyright (C) 2019-2020 Socionext Inc. + * Author: Kunihiko Hayashi + */ + +#include +#include +#include +#include +#include + +#define EPC_RESTART_POLL_PERIOD_MS 80 + +static int pci_epc_restart_thread(void *dev_id) +{ + struct pci_epc *epc = dev_id; + struct pci_epf *epf; + int ret = 0; + + dev_info(&epc->dev, "[epc-restart] thread start\n"); + + while (!kthread_should_stop()) { + if (epc->restart_poll) { + /* call polling function */ + ret = epc->restart_poll(epc->restart_poll_data); + if (!ret) { + msleep(EPC_RESTART_POLL_PERIOD_MS); + continue; + } else if (ret < 0) { + break; + } + } else { + /* wait for interrupt */ + ret = wait_for_completion_interruptible(&epc->restart_comp); + if (ret <= 0) + break; + } + + if (!pci_epc_is_started(epc)) + continue; + + /* + * After stop linkup, call unbind() once and call bind() again. + * to reload config parameters to the controller. + */ + pci_epc_stop(epc); + list_for_each_entry(epf, &epc->pci_epf, list) { + pci_epf_unbind(epf); + pci_epf_bind(epf); + } + pci_epc_start(epc); + + dev_info(&epc->dev, "[epc-restart] assert\n"); + } + + dev_info(&epc->dev, "[epc-restart] thread exit\n"); + + return ret; +} + +/** + * pci_epc_restart_init() - initialize epc-restart thread + * @epc: the EPC device + */ +int pci_epc_restart_init(struct pci_epc *epc) +{ + init_completion(&epc->restart_comp); + + epc->restart_task = kthread_run(pci_epc_restart_thread, epc, + "pci-epc-restart"); + if (IS_ERR(epc->restart_task)) + return PTR_ERR(epc->restart_task); + + return 0; +} +EXPORT_SYMBOL_GPL(pci_epc_restart_init); + +/** + * pci_epc_restart_cleanup() - clean up epc-restart thread + * @epc: the EPC device + */ +void pci_epc_restart_cleanup(struct pci_epc *epc) +{ + if (epc->restart_task) + kthread_stop(epc->restart_task); +} +EXPORT_SYMBOL_GPL(pci_epc_restart_cleanup); + +/** + * pci_epc_restart_notify() - notify to epc-restart thread + * @epc: the EPC device + */ +void pci_epc_restart_notify(struct pci_epc *epc) +{ + complete(&epc->restart_comp); +} +EXPORT_SYMBOL_GPL(pci_epc_restart_notify); + +/** + * pci_epc_restart_register_poll_func() - register polling method for restart thread + * @epc: the EPC device + * @func: polling function + * @data: data for polling function + */ +void pci_epc_restart_register_poll_func(struct pci_epc *epc, bool (*func)(void *), + void *data) +{ + epc->restart_poll = func; + epc->restart_poll_data = data; +} +EXPORT_SYMBOL_GPL(pci_epc_restart_register_poll_func); diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h index 5808952..45d2592 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -132,6 +132,10 @@ struct pci_epc_mem { * @function_num_map: bitmap to manage physical function number * @notifier: used to notify EPF of any EPC events (like linkup) * @started: true if this EPC is started + * @restart_task: pointer to task for restart thread + * @restart_comp: completion object for receiving reset interrupts from RC + * @restart_poll: function to poll reset detection from RC + * @restart_poll_data: an argument that restart_poll function gets */ struct pci_epc { struct device dev; @@ -147,6 +151,11 @@ struct pci_epc { unsigned long function_num_map; struct atomic_notifier_head notifier; bool started; + /* for epc-restart */ + struct task_struct *restart_task; + struct completion restart_comp; + bool (*restart_poll)(void *func); + void *restart_poll_data; }; /** @@ -254,4 +263,10 @@ void __iomem *pci_epc_mem_alloc_addr(struct pci_epc *epc, phys_addr_t *phys_addr, size_t size); void pci_epc_mem_free_addr(struct pci_epc *epc, phys_addr_t phys_addr, void __iomem *virt_addr, size_t size); +int pci_epc_restart_init(struct pci_epc *epc); +void pci_epc_restart_cleanup(struct pci_epc *epc); +void pci_epc_restart_notify(struct pci_epc *epc); +void pci_epc_restart_register_poll_func(struct pci_epc *epc, + bool (*func)(void *), void *data); + #endif /* __LINUX_PCI_EPC_H */ -- 2.7.4 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel