From patchwork Tue Mar 14 04:46:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 69287 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1568297wrd; Mon, 13 Mar 2023 22:03:12 -0700 (PDT) X-Google-Smtp-Source: AK7set9RqUEbYDIJ4S6AeUp8YV/Wwh24nUvfZgk6LBoVJ1WipymCVKoOBx0t8JmryOOEz5hR9kIn X-Received: by 2002:a05:6122:1687:b0:405:a08a:fa4f with SMTP id 7-20020a056122168700b00405a08afa4fmr24673396vkl.8.1678770192274; Mon, 13 Mar 2023 22:03:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678770192; cv=none; d=google.com; s=arc-20160816; b=ync+MqCLw2GAQRK4eDA6LpOlnuzfEQSMa/y61Zra1opmNtVYONo7okw34puopvsp75 /MctiHdF3XBJSoVu3uSCfyoFsa+IwijqciAWZY+TYzOqVaXUSbVWYpWV19pKsac4midU FgbIse6OlNs0AQqX0kKz8qWyOR2QKSelWzyZLIZ0jCooTdXkTI6lxXZIi3DUn1diuph5 AAnz9l9D5V6CPHJvNFBdPsCThZTDWqh8vFTbKShHsw2/0LssfSUfilsvMHOCAG7TbICT /IA/hK7fsuy2Va9+CrMsVtwmT2QiuHd18Urs0TJh2a9JMuiNUVSjOeGsR4AvCD/wXP4Q EFaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YmBMpLwO4qRSgpNN2zu2wmSlV0dO5yPKMRqsInWvopM=; b=wT/xXnIvrrH8JGoLqh/zul0MyvuRaqqj0/E9aIPN4o0DEXHPsnoG88NnnxcKRS8GEw mBjDyqLNenskLM4poMIpzSH6pQLk9XyKbpi58MNn/7bR2E+mUQgZKHqjX4zIeKUmD5gg l0MmZzLBiFwBP1dK9zTH3zZqqvmAzCNEEB28NDXLDnkvophlXn4FtFY8S4p/SXlwB0E7 S4/EPZqpRTZox2ZLvav3mWNZGjHNOX8ugeA61hjsHp3dyBIeu/yoDpF4oBBSADr7tniJ cGxaMJUhmyTbAuNibQk0Zkig2QjhbOE44mMMvWYFsiCd5chHVd6XrFNtUrqrzqGKDewl BkrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cpsSqBec; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 189-20020a1f00c6000000b0042d4d95d5absi900788vka.111.2023.03.13.22.02.57; Mon, 13 Mar 2023 22:03:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cpsSqBec; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229441AbjCNEqn (ORCPT + 99 others); Tue, 14 Mar 2023 00:46:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229505AbjCNEqj (ORCPT ); Tue, 14 Mar 2023 00:46:39 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CC93A5CD for ; Mon, 13 Mar 2023 21:46:37 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id h11-20020a17090a2ecb00b00237c740335cso13911075pjs.3 for ; Mon, 13 Mar 2023 21:46:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678769197; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YmBMpLwO4qRSgpNN2zu2wmSlV0dO5yPKMRqsInWvopM=; b=cpsSqBecUtfR1YL08VzHXQKb+5jn+ts3gGNqf9sEp9Rf5VGxRyOXC4Ol/rGAWvxEp7 /zoNai5d3a+ptbhU5WJaTefpNmC+dOd1hF4WinSIoYbHUcU8AuSlflHuZbgkP4IbdM7m hV1Lo0CYP5maFSPBjqpIJmhUuTuz7Lj77/beCz1Ayn5sIuKhIV706ouoDUgmRUL1UXJD APLp0ZYjmD0vj3BxneLS7t1xISFq2dikx3/VSZLJaTyGtNSp2M23YBDIfMpokj4lc3RS Qoi9yvC782Y/rTo0k0RSJzml+kMvcnum3NoJmYZfr3FQ6W/fSFc0lGeF1OjOafkN4GkP lrKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678769197; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YmBMpLwO4qRSgpNN2zu2wmSlV0dO5yPKMRqsInWvopM=; b=bajOaub2lShyEfsa/5uzoaO30lu2lrNtY/qiIOgt3TN5nVZHI2W10GmMm2p8aXis2B kMawZfj2K02LhYVj+RAQfBeT+4rCwUuKmqfX++dVUso8nysWMKslJ7nbutT0PIuVX5Jl rg1oTt+a5Oz00jtwEMh9KSwyniAfgIjhdj2pppKTMHj6wcMHToArOae247XSz3AcnIQ4 vOgo4O7M0SwEKOv1t11caTC+osVuLYYFmpIDSc/Zg/p7n576wHXZJwY07gzAqsvDW3dh WYMPZFYjuOWRhEajORnhu+yOahmGLbin6LE6thCIzbwZ2QZ1zfFimuGBhtyN5RPKIdZq aMMg== X-Gm-Message-State: AO0yUKVkjhnGVJ/4fDSaT4rONgF2hUf7Q4wbYIRqpd5oE/Q2S05njP02 90f1xszOyH0zuOL6IqOsMRDR X-Received: by 2002:a17:902:c404:b0:19f:e9e7:4cb with SMTP id k4-20020a170902c40400b0019fe9e704cbmr8615091plk.45.1678769196675; Mon, 13 Mar 2023 21:46:36 -0700 (PDT) Received: from localhost.localdomain ([117.217.177.49]) by smtp.gmail.com with ESMTPSA id lh13-20020a170903290d00b0019c2b1c4ad4sm690125plb.6.2023.03.13.21.46.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 21:46:36 -0700 (PDT) From: Manivannan Sadhasivam To: lpieralisi@kernel.org, kw@linux.com Cc: kishon@kernel.org, bhelgaas@google.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Manivannan Sadhasivam Subject: [PATCH v3 1/7] PCI: endpoint: Pass EPF device ID to the probe function Date: Tue, 14 Mar 2023 10:16:17 +0530 Message-Id: <20230314044623.10254-2-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230314044623.10254-1-manivannan.sadhasivam@linaro.org> References: <20230314044623.10254-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760318133248965606?= X-GMAIL-MSGID: =?utf-8?q?1760318133248965606?= Currently, the EPF probe function doesn't get the device ID argument needed to correctly identify the device table ID of the EPF device. When multiple entries are added to the "struct pci_epf_device_id" table, the probe function needs to identify the correct one. And the only way to do so is by storing the correct device ID in "struct pci_epf" during "pci_epf_match_id()" and passing that to probe(). Signed-off-by: Manivannan Sadhasivam --- drivers/pci/endpoint/functions/pci-epf-ntb.c | 3 ++- drivers/pci/endpoint/functions/pci-epf-test.c | 2 +- drivers/pci/endpoint/functions/pci-epf-vntb.c | 2 +- drivers/pci/endpoint/pci-epf-core.c | 8 +++++--- include/linux/pci-epf.h | 4 +++- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-ntb.c b/drivers/pci/endpoint/functions/pci-epf-ntb.c index 9a00448c7e61..980b4ecf19a2 100644 --- a/drivers/pci/endpoint/functions/pci-epf-ntb.c +++ b/drivers/pci/endpoint/functions/pci-epf-ntb.c @@ -2075,11 +2075,12 @@ static struct config_group *epf_ntb_add_cfs(struct pci_epf *epf, /** * epf_ntb_probe() - Probe NTB function driver * @epf: NTB endpoint function device + * @id: NTB endpoint function device ID * * Probe NTB function driver when endpoint function bus detects a NTB * endpoint function. */ -static int epf_ntb_probe(struct pci_epf *epf) +static int epf_ntb_probe(struct pci_epf *epf, const struct pci_epf_device_id *id) { struct epf_ntb *ntb; struct device *dev; diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 0f9d2ec822ac..d5fcc78a5b73 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -980,7 +980,7 @@ static const struct pci_epf_device_id pci_epf_test_ids[] = { {}, }; -static int pci_epf_test_probe(struct pci_epf *epf) +static int pci_epf_test_probe(struct pci_epf *epf, const struct pci_epf_device_id *id) { struct pci_epf_test *epf_test; struct device *dev = &epf->dev; diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/endpoint/functions/pci-epf-vntb.c index b7c7a8af99f4..122eb7a12028 100644 --- a/drivers/pci/endpoint/functions/pci-epf-vntb.c +++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c @@ -1401,7 +1401,7 @@ static struct pci_epf_ops epf_ntb_ops = { * * Returns: Zero for success, or an error code in case of failure */ -static int epf_ntb_probe(struct pci_epf *epf) +static int epf_ntb_probe(struct pci_epf *epf, const struct pci_epf_device_id *id) { struct epf_ntb *ntb; struct device *dev; diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c index 2036e38be093..924564288c9a 100644 --- a/drivers/pci/endpoint/pci-epf-core.c +++ b/drivers/pci/endpoint/pci-epf-core.c @@ -494,11 +494,13 @@ static const struct device_type pci_epf_type = { }; static int -pci_epf_match_id(const struct pci_epf_device_id *id, const struct pci_epf *epf) +pci_epf_match_id(const struct pci_epf_device_id *id, struct pci_epf *epf) { while (id->name[0]) { - if (strcmp(epf->name, id->name) == 0) + if (strcmp(epf->name, id->name) == 0) { + epf->id = id; return true; + } id++; } @@ -526,7 +528,7 @@ static int pci_epf_device_probe(struct device *dev) epf->driver = driver; - return driver->probe(epf); + return driver->probe(epf, epf->id); } static void pci_epf_device_remove(struct device *dev) diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h index a215dc8ce693..bc613f0df7e3 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -89,7 +89,7 @@ struct pci_epc_event_ops { * @id_table: identifies EPF devices for probing */ struct pci_epf_driver { - int (*probe)(struct pci_epf *epf); + int (*probe)(struct pci_epf *epf, const struct pci_epf_device_id *id); void (*remove)(struct pci_epf *epf); struct device_driver driver; @@ -131,6 +131,7 @@ struct pci_epf_bar { * @epc: the EPC device to which this EPF device is bound * @epf_pf: the physical EPF device to which this virtual EPF device is bound * @driver: the EPF driver to which this EPF device is bound + * @id: Pointer to the EPF device ID * @list: to add pci_epf as a list of PCI endpoint functions to pci_epc * @lock: mutex to protect pci_epf_ops * @sec_epc: the secondary EPC device to which this EPF device is bound @@ -158,6 +159,7 @@ struct pci_epf { struct pci_epc *epc; struct pci_epf *epf_pf; struct pci_epf_driver *driver; + const struct pci_epf_device_id *id; struct list_head list; /* mutex to protect against concurrent access of pci_epf_ops */ struct mutex lock; From patchwork Tue Mar 14 04:46:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 69288 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1568355wrd; Mon, 13 Mar 2023 22:03:21 -0700 (PDT) X-Google-Smtp-Source: AK7set+r01VBH+QbuSycgWgk94sYokT7FloTRvSOJnGwAzC4TR1zdR2C4ztYqLrHJDKFQxXIgXc9 X-Received: by 2002:a05:6870:631b:b0:17a:b060:7b0d with SMTP id s27-20020a056870631b00b0017ab0607b0dmr84292oao.7.1678770201133; Mon, 13 Mar 2023 22:03:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678770201; cv=none; d=google.com; s=arc-20160816; b=MRXgYS6anrzUNV3R2X0f9mIUHo6ZdLTZSg8Ct/G8DCO+gCcnYTNaTdGIqA5JQo/Y5Z qypaLOnxjLMQqJeFbYxcw0jQnNXTDiUBeoZQpELAcsjk3CfvI53IDKw8VmdfGT8lC2dk ytl0AUkRv1Q2qsdnJRedHw/RlcEa9g2nXd2rjYDnEtxSnx0YBMNqE+0Kr6XXtBapURHQ 2d5ntd8OGC9fOtz/PonFYny6ObFOxSc46ThLfknSSjqArdJkMNnJtIeoXPr6Y1q7QOMu 2aZK7I14g0O2bcTgCu/Q+HFXUgrmWB2Rg/2+OYcGtnWLNM9wnVsWQ15suz4A2sGNFhoh POsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wvfvphEax9rDC9DBLoGwM3hS+dg6woN4JsLGnKLFC0E=; b=Rvt2/G9eL5gnW81OUz8Hq8xFqOstiZjhQ2gLwo/fPNhA8vtV1UNZ4Ui8f1kgXjPbOl aKrEp3ZtYlGsPZX6561iSu284/eVTYydZDZSoyewKIpJHmESqEocPavRCGeDaYeq8ywr jetW1WkVUdgExLfElli72sB3I5SOfDcbeEP7+43A7d8VLURpsbbJiU8fbtQMLo7313jV v+vC7G0tYwKtj5ylWOQniQsYkIohvw3M2zu/wnYn22lK6/8irul7uQnruSvNki/7c2fb WUh/5UeAwbpBLuoyOf8rcG/MtNVl0LvoLa7Q4WcnM9pj9ajBjjzJWUuGaoUZl5kvAt65 AMGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=x9dbAT+U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s22-20020a0568080b1600b00384570b7fb1si1258646oij.212.2023.03.13.22.03.07; Mon, 13 Mar 2023 22:03:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=x9dbAT+U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229869AbjCNEqr (ORCPT + 99 others); Tue, 14 Mar 2023 00:46:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229864AbjCNEqn (ORCPT ); Tue, 14 Mar 2023 00:46:43 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 017A39225D for ; Mon, 13 Mar 2023 21:46:40 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id p6so15385300plf.0 for ; Mon, 13 Mar 2023 21:46:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678769200; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wvfvphEax9rDC9DBLoGwM3hS+dg6woN4JsLGnKLFC0E=; b=x9dbAT+U55WpGhZBn9XjA1sU8XP2hJCiwXGEZLHNnpcNKsQQPTcTifF4u8u1X6bFqx 4H+rRYxH67YPKQvBdwJSwzg/g+5NDOkJPtcKZILIlOJ11CvgNpLM1x2QU5JuXopxYw1C pgFV4zkm8zwHAPpHNXgiN2Y/9kTxHj4tnsFw0KQR6Rbjx+NwrIO8tLg12MgtvXfMDE6o vxvcemOyZFeSWVXFnlLYIhQnP0myhuJRATOAxu+AbLZ8ykEwtkMKX6y5o4WTE8ZgSHqL LOwIz50CMcQlhpmJm+GsbsmPpemHO10ExwxYNaFwkIGyslc/caR/Ryt+1pM0lAGrauYN M8pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678769200; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wvfvphEax9rDC9DBLoGwM3hS+dg6woN4JsLGnKLFC0E=; b=XvkzphZ0+/OG2bQxXJ5w3VBOoPQRAQV9s34uQj9CvqIxriDLhnslgXcPgQ1yImmG/I FW+RgPoO6LTybr88VJycBiImEeAj7Nu3OzxBDC96MMAGn1HWJISicfphD0oJULVl35Ia Jss/DIuk1yAZu9ERvCe1M/MuexmAeJt41m9oQA03QXAhre5uC0zXdfdfwL3Sg28Rj+Mu n9/yJ7WT69ydFvMcxWcEzCQqR9wXRUZDifxs6BHhAExrgasO0eMkFDe11kLFgeVTJLLC HlCDQdQ0+ggPalYhiAbS/3u4EdCnIzx2Mordfeo5atzr8RsCXTG+400pNcqeYpD0blVq c8dw== X-Gm-Message-State: AO0yUKVcrK8b8wRiQasJ5l7D9avXXa0EP9rJSUtKay/K5+6ng2semmn9 GA1gZN9CuGf886JhKXneZsVL X-Received: by 2002:a17:902:d512:b0:196:704e:2c9a with SMTP id b18-20020a170902d51200b00196704e2c9amr43011634plg.22.1678769199864; Mon, 13 Mar 2023 21:46:39 -0700 (PDT) Received: from localhost.localdomain ([117.217.177.49]) by smtp.gmail.com with ESMTPSA id lh13-20020a170903290d00b0019c2b1c4ad4sm690125plb.6.2023.03.13.21.46.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 21:46:39 -0700 (PDT) From: Manivannan Sadhasivam To: lpieralisi@kernel.org, kw@linux.com Cc: kishon@kernel.org, bhelgaas@google.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Manivannan Sadhasivam Subject: [PATCH v3 2/7] PCI: endpoint: Warn and return if EPC is started/stopped multiple times Date: Tue, 14 Mar 2023 10:16:18 +0530 Message-Id: <20230314044623.10254-3-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230314044623.10254-1-manivannan.sadhasivam@linaro.org> References: <20230314044623.10254-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760318142727458427?= X-GMAIL-MSGID: =?utf-8?q?1760318142727458427?= When the EPC is started or stopped multiple times from configfs, just emit a once time warning and return. There is no need to call the EPC start/stop functions in those cases. Signed-off-by: Manivannan Sadhasivam --- drivers/pci/endpoint/pci-ep-cfs.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/pci/endpoint/pci-ep-cfs.c b/drivers/pci/endpoint/pci-ep-cfs.c index 4b8ac0ac84d5..62c8e09c59f4 100644 --- a/drivers/pci/endpoint/pci-ep-cfs.c +++ b/drivers/pci/endpoint/pci-ep-cfs.c @@ -178,6 +178,9 @@ static ssize_t pci_epc_start_store(struct config_item *item, const char *page, if (kstrtobool(page, &start) < 0) return -EINVAL; + if (WARN_ON_ONCE(start == epc_group->start)) + return 0; + if (!start) { pci_epc_stop(epc); epc_group->start = 0; From patchwork Tue Mar 14 04:46:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 69282 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1565925wrd; Mon, 13 Mar 2023 21:55:46 -0700 (PDT) X-Google-Smtp-Source: AK7set9tuDTAhR9WzsBGvqRF1WbY4t4AK7AQiDDSy/Q491ZVuAI4oDK7PHudUL3ArY6PWkQC7ViE X-Received: by 2002:a17:90a:55cd:b0:23b:5190:6a4f with SMTP id o13-20020a17090a55cd00b0023b51906a4fmr7662561pjm.47.1678769746524; Mon, 13 Mar 2023 21:55:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678769746; cv=none; d=google.com; s=arc-20160816; b=Tz7PzNQE5kp1RUpM3ZSiwUff75pi81NSWcWiDrThvGlCNeNJL0n29OKN0x8rZpOr40 pxnxNAiXItAQAXadU5pqSYFvCNHCo7o8iLjE11Z86bEa39KpuG7Xmj6Fpc5/37+OHdr5 cXTN1OuU2aug2c5iVtwpP/8n2YlN0GP26NL35JQlTlbjjcul936rgYPOtvXKTJeZplbd EarnNl4RLwHseBhZjjOXEQLpTeLBjK8dz2wrx+hlXqNneCpQqcCn6pRxrJlOimjP8EVd TpIXqcd7mC8mkWykRpe3GFEYVp4RA3/arlfccVggtP3Fmo5lblxlluAhf0PTOLyVQb6r 7p4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5CebAT6G7pMdHj4gkjeeBHR/+GUK4hl9hBpqAKTE774=; b=CjOY1fSBJxxpFWeDr5PmOU1sS00L5c3UjklR2SFJAwYMddh+G3XrklsoMnc6UD4UlD Q1c9aRI5eGhOpVpK9ab597iGBkXs29w9F8xw758OOYLg71Oun2lEA8qCut4dURFiAlax 28CX3Wosa7ztmot2tP+c+4yjXoGeNkIoTy9qxMAiNJ7/gT924bIyJgvmts40G2yXJLfh PwFbGbyQTA9XfnDz4LycxYOH/FgUEhPzfZbVJn3puCw/b+O6xbLuWgMboMs0Wwo3epmg 2BZ4stT630l6oVbTIDTAKKihWAvgCld5xVbUM2gjMvW8t6TjqkELLm3g3nXKwFMsLdyW kwMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FgMOxdg4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a71-20020a63904a000000b0050768ccbf4csi1287109pge.699.2023.03.13.21.55.28; Mon, 13 Mar 2023 21:55:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FgMOxdg4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229903AbjCNEq4 (ORCPT + 99 others); Tue, 14 Mar 2023 00:46:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229838AbjCNEqx (ORCPT ); Tue, 14 Mar 2023 00:46:53 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AFBA5FA58 for ; Mon, 13 Mar 2023 21:46:44 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id cn6so1607897pjb.2 for ; Mon, 13 Mar 2023 21:46:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678769203; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5CebAT6G7pMdHj4gkjeeBHR/+GUK4hl9hBpqAKTE774=; b=FgMOxdg4dDWnSfrnTfGPhTA5M1vKWe4fy2jD+/oVY5VI27AEDiZhPu06FUJRVCCCKw RG26JdNLbhv8CAREUDAZ6SZy8VvdBbOrdFqVHgo77k7wvNtq77toKuWJ/+tR/TURzm/u q5l6qj9sRzoRBb9MjumS3m7CeVYVogI1kvoACxtvxmetYhd09LMI6CSj1Q3b9bxbH1fT jgwZ32AvdfJvXn21wJ7j1b8fKA+PJWsm+gRUF2tH05jMMm3r62K3sfRb5p4C4IJPmjp/ 32adKedKxjObDwBAZff1MfJSkNVFREBCAi9Y89Kgia0DVn/amb6FfBSwsDprTR1FNrfP 7twA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678769203; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5CebAT6G7pMdHj4gkjeeBHR/+GUK4hl9hBpqAKTE774=; b=OQkV1G8Xdh+6MMUZ+RvawkBVicI2BzI9xFYMhXyl7FZmBMb6CW/eb4uFBB2lZqabaT rpT83k+yU1xkfrvDhlTn/9Ds4fk4+F3RZII7fo4yoUVNoMvHOZ2peIwQTzGn0MT24bXj 1aISaKHg3EX/WZC8ZQuZF5+9mjUBqhvtD0es10bHLGyp+YXwI/pk24yj1wOpEK/3kMrq O/xdAwkdBUtDZvjt7tcDPFWkyLaC0R42vNHnPTJkcTqyxtgKl8m/aFZwAx4InLiGqVPZ 4UFb51M62GEigWmvKtKffotOMMcr0321/FcRyYR6/HtxBUD9nDSZVeVcPUrS6gnNwdS1 1Q5w== X-Gm-Message-State: AO0yUKUM1DlZd0btnwXUEx8Ex+j56HtiIjBXic/e+q73vB8tm+EqcoFz 3PakTekvyEy13qyuy+YUGzKK X-Received: by 2002:a17:903:32cf:b0:19a:8e52:ce0 with SMTP id i15-20020a17090332cf00b0019a8e520ce0mr42868896plr.58.1678769203156; Mon, 13 Mar 2023 21:46:43 -0700 (PDT) Received: from localhost.localdomain ([117.217.177.49]) by smtp.gmail.com with ESMTPSA id lh13-20020a170903290d00b0019c2b1c4ad4sm690125plb.6.2023.03.13.21.46.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 21:46:42 -0700 (PDT) From: Manivannan Sadhasivam To: lpieralisi@kernel.org, kw@linux.com Cc: kishon@kernel.org, bhelgaas@google.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Manivannan Sadhasivam Subject: [PATCH v3 3/7] PCI: endpoint: Add linkdown notifier support Date: Tue, 14 Mar 2023 10:16:19 +0530 Message-Id: <20230314044623.10254-4-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230314044623.10254-1-manivannan.sadhasivam@linaro.org> References: <20230314044623.10254-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760317665971241565?= X-GMAIL-MSGID: =?utf-8?q?1760317665971241565?= Add support to notify the EPF device about the linkdown event from the EPC device. Signed-off-by: Manivannan Sadhasivam --- drivers/pci/endpoint/pci-epc-core.c | 26 ++++++++++++++++++++++++++ include/linux/pci-epc.h | 1 + include/linux/pci-epf.h | 2 ++ 3 files changed, 29 insertions(+) diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c index 9440d9811eea..e3a6b5554c1c 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -706,6 +706,32 @@ void pci_epc_linkup(struct pci_epc *epc) } EXPORT_SYMBOL_GPL(pci_epc_linkup); +/** + * pci_epc_linkdown() - Notify the EPF device that EPC device has dropped the + * connection with the Root Complex. + * @epc: the EPC device which has dropped the link with the host + * + * Invoke to Notify the EPF device that the EPC device has dropped the + * connection with the Root Complex. + */ +void pci_epc_linkdown(struct pci_epc *epc) +{ + struct pci_epf *epf; + + if (!epc || IS_ERR(epc)) + return; + + mutex_lock(&epc->list_lock); + list_for_each_entry(epf, &epc->pci_epf, list) { + mutex_lock(&epf->lock); + if (epf->event_ops && epf->event_ops->link_down) + epf->event_ops->link_down(epf); + mutex_unlock(&epf->lock); + } + mutex_unlock(&epc->list_lock); +} +EXPORT_SYMBOL_GPL(pci_epc_linkdown); + /** * pci_epc_init_notify() - Notify the EPF device that EPC device's core * initialization is completed. diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h index 301bb0e53707..63a6cc5e5282 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -203,6 +203,7 @@ void pci_epc_destroy(struct pci_epc *epc); int pci_epc_add_epf(struct pci_epc *epc, struct pci_epf *epf, enum pci_epc_interface_type type); void pci_epc_linkup(struct pci_epc *epc); +void pci_epc_linkdown(struct pci_epc *epc); void pci_epc_init_notify(struct pci_epc *epc); void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf, enum pci_epc_interface_type type); diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h index bc613f0df7e3..f8e5a63d0c83 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -71,10 +71,12 @@ struct pci_epf_ops { * struct pci_epf_event_ops - Callbacks for capturing the EPC events * @core_init: Callback for the EPC initialization complete event * @link_up: Callback for the EPC link up event + * @link_down: Callback for the EPC link down event */ struct pci_epc_event_ops { int (*core_init)(struct pci_epf *epf); int (*link_up)(struct pci_epf *epf); + int (*link_down)(struct pci_epf *epf); }; /** From patchwork Tue Mar 14 04:46:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 69283 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1566707wrd; Mon, 13 Mar 2023 21:58:46 -0700 (PDT) X-Google-Smtp-Source: AK7set9OuNlmBMsdv6oV3clLc98or832uE615io8HnDeqICK6HoUAtx8ZaTD8oBNnr4HGA8un9lY X-Received: by 2002:a05:6a20:4da8:b0:d4:4ec9:ac42 with SMTP id gj40-20020a056a204da800b000d44ec9ac42mr5474981pzb.40.1678769926436; Mon, 13 Mar 2023 21:58:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678769926; cv=none; d=google.com; s=arc-20160816; b=RwtE78J9lFlwXABYWXCv/bpAGqwO2UB7ewC/ga1MokLMQdZgyUDq1bvHMMgT65Mvrf TZZxbf3c5eKZjlamjiAGdexgsY2kLQyX+xqBrBtsEJAblHyuSNFLEjSrW3qno0LFNK3y vQvWtm40b8fisjXiF6XA5jVcHX4T9taespst98EIGlaGNZVVbYLgjmLJdwWYfZpMC7a6 LlCrpDmnMEOHSv+qusvzxogmaVH8BRcirVv4Rq3WU6GjwcIQ/0eNXeEp3NXQqivxyK5f NvTLfWLjEx5cDJnOP82dMdzKckgzeN4WxOUhS0TnYRDohx0p4levPxBe91zf5NeyXzDT ASEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MJgDTGPG3O7w69/b8j6+Tmk/A5SbbomMgk7rRHGZCSE=; b=j+DAyk/8KgtV7MIPewX0I1+Runz5ACP6nYDZzJ3kCqG3dSwRYNNmTfwxD3JZLSUXFz np2eZdb5gryV2jkKfXaaOhYR6U8F4G12s0dSBwmxpU5IpqNzxkSQCjt2x3veZR9Y3xeo ZvuUjUqk4SsqwP2NjpnMKceGUFg2G0JH6YmsWaErjgBu/MVE3SbMTjdwVeZmZA6cw7Vf 91hfP1K5DQ/VK7/DfTJ+KQD4RQetUvoBPgvSFZ2q3b2V3XcmIHgoxjr4UXhX1BSId0ZW RDWAL1cWkMMU1cFvFYyaVBNIYRq9K/uZ8qt7scq5nsVn944xSuJGrn35THSZWrfvyKN8 wOHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JZRz39Xh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v22-20020a63f216000000b00502d794102asi1348521pgh.588.2023.03.13.21.58.33; Mon, 13 Mar 2023 21:58:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JZRz39Xh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229836AbjCNErA (ORCPT + 99 others); Tue, 14 Mar 2023 00:47:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229854AbjCNEqx (ORCPT ); Tue, 14 Mar 2023 00:46:53 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73B8592713 for ; Mon, 13 Mar 2023 21:46:46 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id y15-20020a17090aa40f00b00237ad8ee3a0so13929192pjp.2 for ; Mon, 13 Mar 2023 21:46:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678769206; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MJgDTGPG3O7w69/b8j6+Tmk/A5SbbomMgk7rRHGZCSE=; b=JZRz39XhSL3phM1H74eCCcgQqHj7mBExgBLkqlGYoV8sX2n8D+AiX98ge8+6xWWEgN QLfDDheoo4YFcM06PX8lEfL+BitAhYUAqh3Ps7Wk8uX1SkBB0J2xoKcHzfMd3jPExDij O6hJFKO27C/zbT5FCbzmVWxVmPXGZQLuU0IiT19pPzTQPaGBiXTUTq88QZOFgp7e1kQw kBx8QdJPpemRFKUb6Hylzx8du4Hfhq26dJOAo9hgh5JRHFQkShS4UwhYjP42Nhq0JMEA r2Xhwy7hVrWklOraLN72k7wVIoAryqWoV6m8Z5uEXpB6+cAzwTpyauQwh++MwoDxUe6X 2l3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678769206; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MJgDTGPG3O7w69/b8j6+Tmk/A5SbbomMgk7rRHGZCSE=; b=7MQ04GiVJYW/2E4ldKPcqS2EPDm/4nvNyTCvB/UnTOmP2Qy2PZ0DsYOEk7+Dk055Xb 9qCMOwcoHbwagBF+MwhiGs/kucnCPuI33WMwxRtbYv1494IyiEewSBzsTUyY4zJICCmy 0k+h7zdd82QEVvlN4ReRnRovC6WEa1eX6J1JQwpHoniFwJLt0eMeVFFHuqh8RdZ/UtVG JaR3dIDhxSQWD4IlvhgmKN3JGIZAqjaXLJB+/Bb09+JDCB6lXLSYbr12FWxSCfeoXFw8 8SFSYt5hIKl1h6wOBLx3vBOdKxvI8m6O8XoznI3uQy+0su5O34r06gzx89ESlDxBuLUC DvVA== X-Gm-Message-State: AO0yUKVdrFUZvoPwd29EjNnC7jcBnVz1lLqTDCm0iznba+JlYz6EqLlI Yg44N5MFVN6xBpv5cL2zIUQx X-Received: by 2002:a17:902:db04:b0:19f:3e9b:7527 with SMTP id m4-20020a170902db0400b0019f3e9b7527mr8716245plx.61.1678769206058; Mon, 13 Mar 2023 21:46:46 -0700 (PDT) Received: from localhost.localdomain ([117.217.177.49]) by smtp.gmail.com with ESMTPSA id lh13-20020a170903290d00b0019c2b1c4ad4sm690125plb.6.2023.03.13.21.46.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 21:46:45 -0700 (PDT) From: Manivannan Sadhasivam To: lpieralisi@kernel.org, kw@linux.com Cc: kishon@kernel.org, bhelgaas@google.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Manivannan Sadhasivam Subject: [PATCH v3 4/7] PCI: endpoint: Add BME notifier support Date: Tue, 14 Mar 2023 10:16:20 +0530 Message-Id: <20230314044623.10254-5-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230314044623.10254-1-manivannan.sadhasivam@linaro.org> References: <20230314044623.10254-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760317854546185371?= X-GMAIL-MSGID: =?utf-8?q?1760317854546185371?= Add support to notify the EPF device about the Bus Master Enable (BME) event received by the EPC device from the Root complex. Signed-off-by: Manivannan Sadhasivam --- drivers/pci/endpoint/pci-epc-core.c | 26 ++++++++++++++++++++++++++ include/linux/pci-epc.h | 1 + include/linux/pci-epf.h | 2 ++ 3 files changed, 29 insertions(+) diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c index e3a6b5554c1c..11bd873a7997 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -758,6 +758,32 @@ void pci_epc_init_notify(struct pci_epc *epc) } EXPORT_SYMBOL_GPL(pci_epc_init_notify); +/** + * pci_epc_bme_notify() - Notify the EPF device that the EPC device has received + * the BME event from the Root complex + * @epc: the EPC device that received the BME event + * + * Invoke to Notify the EPF device that the EPC device has received the Bus + * Master Enable (BME) event from the Root complex + */ +void pci_epc_bme_notify(struct pci_epc *epc) +{ + struct pci_epf *epf; + + if (!epc || IS_ERR(epc)) + return; + + mutex_lock(&epc->list_lock); + list_for_each_entry(epf, &epc->pci_epf, list) { + mutex_lock(&epf->lock); + if (epf->event_ops && epf->event_ops->bme) + epf->event_ops->bme(epf); + mutex_unlock(&epf->lock); + } + mutex_unlock(&epc->list_lock); +} +EXPORT_SYMBOL_GPL(pci_epc_bme_notify); + /** * pci_epc_destroy() - destroy the EPC device * @epc: the EPC device that has to be destroyed diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h index 63a6cc5e5282..5cb694031072 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -205,6 +205,7 @@ int pci_epc_add_epf(struct pci_epc *epc, struct pci_epf *epf, void pci_epc_linkup(struct pci_epc *epc); void pci_epc_linkdown(struct pci_epc *epc); void pci_epc_init_notify(struct pci_epc *epc); +void pci_epc_bme_notify(struct pci_epc *epc); void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf, enum pci_epc_interface_type type); int pci_epc_write_header(struct pci_epc *epc, u8 func_no, u8 vfunc_no, diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h index f8e5a63d0c83..f34b3b32a0e7 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -72,11 +72,13 @@ struct pci_epf_ops { * @core_init: Callback for the EPC initialization complete event * @link_up: Callback for the EPC link up event * @link_down: Callback for the EPC link down event + * @bme: Callback for the EPC BME (Bus Master Enable) event */ struct pci_epc_event_ops { int (*core_init)(struct pci_epf *epf); int (*link_up)(struct pci_epf *epf); int (*link_down)(struct pci_epf *epf); + int (*bme)(struct pci_epf *epf); }; /** From patchwork Tue Mar 14 04:46:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 69285 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1567966wrd; Mon, 13 Mar 2023 22:02:19 -0700 (PDT) X-Google-Smtp-Source: AK7set/rSbgGjXKFujtIcpoOp8BawiExGOEDiqybVfmGuh90f4ByaVnnreRlaj4ydtqh2HyTR1fq X-Received: by 2002:a1f:16d7:0:b0:431:efde:a372 with SMTP id 206-20020a1f16d7000000b00431efdea372mr3905945vkw.6.1678770138982; Mon, 13 Mar 2023 22:02:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678770138; cv=none; d=google.com; s=arc-20160816; b=bXvZrRDYGJunrK9XYwAf0eexPdLoZPdSiXnQ4Uy6iKCHGEgCfxaU7Ib+iOY9b3Fz4s S9uZ5UX/kvCtq1W4HYDtRLu8wRpgkzpOdXLrNIN1NbmQ8wwJIBf2VjJefECpG2OZzhuA dMxrbjbahR104m3TryYwW9ub7dmOTqQspEHUaqxTqZkK2KgJN/IWOANJRm5urMgx57Sg j/v5OFgSQvqGwI/lVRFTa4sZrkjOz4iH+LPASBkOVJMxt325pztLoVPr/gK6qwlmXgan scU46MRPjGRLt5tHtnf/rgrYxKEoaX0yNXenTcDcYmxWyyDzXWZAKnnS6y4Biyr3PdqA D6gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VAvWJkbCnkvCCrjEbntOUm0v01njPW2wZQKEuX5KGW0=; b=Od0Sc04PTdM89jS89wakkzNVQO1cEPW2w6MEMt2k1OZtTmHC7lDB8Rcz+T5TFs0SEa iQEJFXM1BEyFHOHkmzRygs9zEXWli5NN476fHqwtQ/QtHkcUbiJ7txpA4GycFMmgaaAU 013A14wgJmR1M58wj9Dsq47K6LFqom20GoFUPrBoey87nW9Z04HNwhCFt+EwrPiJERdg eNK5oTuR38tqZOp33aPMa/pFh+wTolji3bRahzr8ev19D1wfBIMPosHzpDqttGGMokO5 kubYzadWkNHMTU78MhsixrD/9mJS3QLmCzM/0vgK/hwSv+KA/pxgenT44eybsuStPzfi iQUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HENhfj0P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q64-20020a1fd943000000b004318a60fc2csi995426vkg.40.2023.03.13.22.02.04; Mon, 13 Mar 2023 22:02:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HENhfj0P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229956AbjCNErU (ORCPT + 99 others); Tue, 14 Mar 2023 00:47:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230018AbjCNErE (ORCPT ); Tue, 14 Mar 2023 00:47:04 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77F9392F08 for ; Mon, 13 Mar 2023 21:46:50 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id y15-20020a17090aa40f00b00237ad8ee3a0so13929297pjp.2 for ; Mon, 13 Mar 2023 21:46:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678769209; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VAvWJkbCnkvCCrjEbntOUm0v01njPW2wZQKEuX5KGW0=; b=HENhfj0P03xr4pXsqionBzTdpzKD7bzfpTmWxv1zG9XLdzfuqmAzYXa0p8UyaQe7P9 JjNHpcepgZ65Cmcb76UJ7O3A3f+Ba80/6TCRKpaygXfseEcQ0EdYcfW6zS2einNVa64d N4z1jYsZgT/ee6CsmcKWqqT39VTB+OU0mVGDT8xk1CiVxiMPr7Pq3U3WR5EWqzFh5JDM 2FyMUwUQYwjIkDTL0zB5BEE7uycfk5izuGY4Q8kwNBZIQ7TyGslhBaUDApxeSoBwD0Qh wgNW5wNLKDkmBcaeMRuZFBDAnA8bioxImOWJmodGh0lkQ42zNuubC845Bwh3JwSmczTD sx3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678769209; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VAvWJkbCnkvCCrjEbntOUm0v01njPW2wZQKEuX5KGW0=; b=26f1aKwTaSM5N+OzmpSegYJjYHYallBVI2MRVgeIJixy9IXHqx2/gqqgWAdJKa77wI 77zhX0Ll/szcSqNSldAFUUfIqvle0vfv7UHKhaLgbX6KpK8R6rmF3Mzgz/q3iQTr99Lx mlYFuQbcw8BXSFFO6uvFtz4nOpOF4itGGIA8jKhJXwl792xBIH8RKKE68clHVwC6X8UW ba24A4KuupN4U13Hfx57b3M0QNGoyXA4G/7ppasgih6mcIU5ufLnA+/l5+mknuG06731 eBwWa7S38ZyvsHML4AaQf6hP4Q3UpRuuW3hblRsdc4+lNtpa1I6Q2db/qUrc0I0TN+fN Rgxg== X-Gm-Message-State: AO0yUKUWhTdzM+xAX+7zEU0Mwe+hwNPtT/nSIEHTVOjvj1wLTpN1+NZl McjNnHXbyRjCHy9KxHtms/k1qQ0D/wdoctlzxg== X-Received: by 2002:a17:902:d4cc:b0:19d:af20:3fe8 with SMTP id o12-20020a170902d4cc00b0019daf203fe8mr44973116plg.21.1678769209331; Mon, 13 Mar 2023 21:46:49 -0700 (PDT) Received: from localhost.localdomain ([117.217.177.49]) by smtp.gmail.com with ESMTPSA id lh13-20020a170903290d00b0019c2b1c4ad4sm690125plb.6.2023.03.13.21.46.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 21:46:48 -0700 (PDT) From: Manivannan Sadhasivam To: lpieralisi@kernel.org, kw@linux.com Cc: kishon@kernel.org, bhelgaas@google.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Manivannan Sadhasivam Subject: [PATCH v3 5/7] PCI: qcom-ep: Add support for Link down notification Date: Tue, 14 Mar 2023 10:16:21 +0530 Message-Id: <20230314044623.10254-6-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230314044623.10254-1-manivannan.sadhasivam@linaro.org> References: <20230314044623.10254-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760318077023366879?= X-GMAIL-MSGID: =?utf-8?q?1760318077023366879?= Add support to pass Link down notification to Endpoint function driver so that the LINK_DOWN event can be processed by the function. Signed-off-by: Manivannan Sadhasivam --- drivers/pci/controller/dwc/pcie-qcom-ep.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/pci/controller/dwc/pcie-qcom-ep.c b/drivers/pci/controller/dwc/pcie-qcom-ep.c index 19b32839ea26..4ce01ff7527c 100644 --- a/drivers/pci/controller/dwc/pcie-qcom-ep.c +++ b/drivers/pci/controller/dwc/pcie-qcom-ep.c @@ -569,6 +569,7 @@ static irqreturn_t qcom_pcie_ep_global_irq_thread(int irq, void *data) if (FIELD_GET(PARF_INT_ALL_LINK_DOWN, status)) { dev_dbg(dev, "Received Linkdown event\n"); pcie_ep->link_status = QCOM_PCIE_EP_LINK_DOWN; + pci_epc_linkdown(pci->ep.epc); } else if (FIELD_GET(PARF_INT_ALL_BME, status)) { dev_dbg(dev, "Received BME event. Link is enabled!\n"); pcie_ep->link_status = QCOM_PCIE_EP_LINK_ENABLED; From patchwork Tue Mar 14 04:46:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 69284 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1567578wrd; Mon, 13 Mar 2023 22:01:21 -0700 (PDT) X-Google-Smtp-Source: AK7set+he8FqJmP3Zz6lBp6PVmhhp8wXdRRZQUnpi4GaD5ZccuGrk61zCN9KbPZYeMHKEYLjFhcE X-Received: by 2002:a1f:32ce:0:b0:432:2c29:a3e0 with SMTP id y197-20020a1f32ce000000b004322c29a3e0mr1013504vky.13.1678770081164; Mon, 13 Mar 2023 22:01:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678770081; cv=none; d=google.com; s=arc-20160816; b=PrBakLkBbV6WouM/PB8XTqd7IL/W5lw4MpS2U5QU5bDe8PW7asvk+LDjfDTXBjK+Au rRATDIv7HvE31oaEtJIWx6exoaItRR1el88h38exzNgBF7Z85z6JjVousP9Ew/vOLRX8 Ylp7V+GVtP2r3Y1uOrbSxKKumIxFBXs3X2Fzw8MX28i6ayF8Rb4snw2O3y1WrCDvykMs M7AA1Hfw0nRreRjm25tkmHcVuRAF+gxWXLx2S8O0saEvgLvJQLPFWTV5x8vsY9VGDj4+ 7FUpoCdONfQ4cYAvhjveClUgL7wW+Fd9S1mljsSeD3ncXsHc8UCqWbKW9wNuX0CRPTYY +Z1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UG6X0V5nxXAs/7mwFsePGG2/rhZWHmM/NsTiFkA/mm8=; b=0mrxRFrmubEDsQ5ZdRbYnPlOuB5k4XWb+2dwuyZdKYTY8rWSjgkHZBEttbaUt92LZh XzEmEtuiuVU+irle5JEFTcZSM90rTmxwzEbvEI7QvFaiHTpv+htm3VKP/RbEMfE8yjSy LuMkL9tUDveJA/oTkLJUIaEDxVQMeaicNkKYhqSzowRYG+3ItAx2Yb8BmK1aZlvG/5ck Kq/HJyiqE/tFaQ6/+KMjaUMRsPn5KaFWLTg4z2WoXYyk/JivGGbGQfb4K3PBiQSGug8n iKA+BnlEgkKmWbzN9HhDSpPa47Ppmcdk8AWUKVsRkZk4pCTVX++qjrAgorTuPUmubmgK WEGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="A/G8tI3v"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q64-20020a1fd943000000b004318a60fc2csi995426vkg.40.2023.03.13.22.01.05; Mon, 13 Mar 2023 22:01:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="A/G8tI3v"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230035AbjCNErY (ORCPT + 99 others); Tue, 14 Mar 2023 00:47:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229864AbjCNErM (ORCPT ); Tue, 14 Mar 2023 00:47:12 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB3D3911D8 for ; Mon, 13 Mar 2023 21:46:52 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id h8so15314252plf.10 for ; Mon, 13 Mar 2023 21:46:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678769212; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UG6X0V5nxXAs/7mwFsePGG2/rhZWHmM/NsTiFkA/mm8=; b=A/G8tI3v0j1rlyEl0eaG32lsjFEdk1zArRvol3guPW7i0h9EOjCk00P7X/LsJ2YK8l uTqzNwCuAWKeabTDbjlaudLGKlwvVPt0uBFsh6ijip4jsSfQu99w+EKxcAcZ5wlprSoN JqK+zY3i/cCv93euqmx4wiDeiGEQQg89YGE+qQMHMZQAr/rK4gAPhicIxXy2MesqYllj XVJbJMnDakXv0ZShVsTTAtJqwjHbGFu63JypBaBPJV97ZjgcMqEJhOt9/iN66YDYoyIH LluzbtIpnsLOEvSK7Mgvcn8Gt9aEPK/Kh6GiQOpEtn+cEaNe00GOu3alKuiOtY0Rinxp MdsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678769212; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UG6X0V5nxXAs/7mwFsePGG2/rhZWHmM/NsTiFkA/mm8=; b=caQdfsm5fLJkFwdnLcMaABjSl0gR5H8OMduronTQNud/TdJCJUV9h2/vOMxr9KGyBQ lbbliJqffGOHR3wqLAsEY02uh+NSJ7pdO2VJLSqM02RvQmEhhwj8YJ6w8JLj4fAsq+ts uxhku1law8YGAZIzXDz/YmpWYOTPx67pa8dQdgYb1muWLQ2ZtfM3NQ4v+jEIm4J3eWqr GugOfMig3xLzSTWrCz2HKFaQjxIok8nXd3MJI2OWGJErTcFO/UQH6Pp/hP1K43Mu5dJ+ ZXTeFxYo4B/9O8jF7ULKCZKThd4+Px6y/NxG8Kif2K42km0OBqYRHNS9V9fKSAibu1TL J5tg== X-Gm-Message-State: AO0yUKVMi0SYdzaxcwg/8BpVzczEpNfQ/yGQl3OXF8dfL2p/sGfpzy1v bgGsuywavYxHgOsfNEFeGNIdx0LNOL8Qhjj5SQ== X-Received: by 2002:a17:903:1205:b0:19e:dc0e:1269 with SMTP id l5-20020a170903120500b0019edc0e1269mr27282300plh.7.1678769212290; Mon, 13 Mar 2023 21:46:52 -0700 (PDT) Received: from localhost.localdomain ([117.217.177.49]) by smtp.gmail.com with ESMTPSA id lh13-20020a170903290d00b0019c2b1c4ad4sm690125plb.6.2023.03.13.21.46.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 21:46:52 -0700 (PDT) From: Manivannan Sadhasivam To: lpieralisi@kernel.org, kw@linux.com Cc: kishon@kernel.org, bhelgaas@google.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Manivannan Sadhasivam Subject: [PATCH v3 6/7] PCI: qcom-ep: Add support for BME notification Date: Tue, 14 Mar 2023 10:16:22 +0530 Message-Id: <20230314044623.10254-7-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230314044623.10254-1-manivannan.sadhasivam@linaro.org> References: <20230314044623.10254-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760318016304535242?= X-GMAIL-MSGID: =?utf-8?q?1760318016304535242?= Add support to pass BME (Bus Master Enable) notification to Endpoint function driver so that the BME event can be processed by the function. Signed-off-by: Manivannan Sadhasivam --- drivers/pci/controller/dwc/pcie-qcom-ep.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/pci/controller/dwc/pcie-qcom-ep.c b/drivers/pci/controller/dwc/pcie-qcom-ep.c index 4ce01ff7527c..1435f516d3f7 100644 --- a/drivers/pci/controller/dwc/pcie-qcom-ep.c +++ b/drivers/pci/controller/dwc/pcie-qcom-ep.c @@ -573,6 +573,7 @@ static irqreturn_t qcom_pcie_ep_global_irq_thread(int irq, void *data) } else if (FIELD_GET(PARF_INT_ALL_BME, status)) { dev_dbg(dev, "Received BME event. Link is enabled!\n"); pcie_ep->link_status = QCOM_PCIE_EP_LINK_ENABLED; + pci_epc_bme_notify(pci->ep.epc); } else if (FIELD_GET(PARF_INT_ALL_PM_TURNOFF, status)) { dev_dbg(dev, "Received PM Turn-off event! Entering L23\n"); val = readl_relaxed(pcie_ep->parf + PARF_PM_CTRL); From patchwork Tue Mar 14 04:46:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 69291 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1570800wrd; Mon, 13 Mar 2023 22:10:33 -0700 (PDT) X-Google-Smtp-Source: AK7set/TA/WPzWcemNncSxP7QMEO084pktJ2mZqh6L+5TuU91AkPHSo2NOH9Nn8STtYP9ze8s3Tv X-Received: by 2002:a17:902:b715:b0:19f:3234:fec5 with SMTP id d21-20020a170902b71500b0019f3234fec5mr7188875pls.51.1678770632718; Mon, 13 Mar 2023 22:10:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678770632; cv=none; d=google.com; s=arc-20160816; b=QOjd5qSPpuI1PxHcQf4zyIMoqh/hga9lZG2E+LzYvbxRD4hVgliAD41AOfHGwhJgAC 1ywb/m5k7hcO6Ut7qwOExVa29WevLTiSEpVjamdVuFS5uqbwcZaZ/MqdlxfzO0aKPpRS 7IH63grN+L4c/WDArzca4zcAXUi1RULJfVrECqS5R2GyXgeoMNV1EkWt7GToBLDOiBhH PCzlBHSPwnscTbJlbynKQgUhvdrEqQnydolmVclgffspB2Zv0AI7Z4m/AeZyFBkSP8Ux ljfxLA7KcrJpk6Ht7wsYJk7YDlb2/AD99hw+SNYdZIyc1HApT7AqCSld4bVzic9aoB4W O8SQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=e/Olxjw+HQJK1P59lC+ASOiltstxhFqe09ROmonjaJY=; b=efINhtyrkH6lluUhXXuE/5x69IINw/1GN90WlW71uXKb4LvtMu+1YbtRn6Br8oljv+ 3gZnzNSpwgYlc6g7cT9xHu2yk+9SIQPLz6rm8SvKQR5DiOz/WgIT6zDw/LV2OXy81Yah yNipeZkl+vebk9LOIwEl/1oE2V1FaSg06gx5v5e17+LKCinrSCAt1R3zu03+4xJGMXwU 3QBo6W26gRsiZabu8T2MjGKwus9IWc+7qJRjCro9PK37cWAgxHIcHrj3vWAZM6iRIvNh 6lnday9efML5NWp+AP0cunOXuA8OMlLjZKT+hua/6SK6fOelOeAL228Xg8C5d4jaY8A7 C+pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZWvBVzen; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b19-20020a170902ed1300b0019c3ce49a13si1547440pld.372.2023.03.13.22.10.20; Mon, 13 Mar 2023 22:10:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZWvBVzen; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229838AbjCNErj (ORCPT + 99 others); Tue, 14 Mar 2023 00:47:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229987AbjCNEr1 (ORCPT ); Tue, 14 Mar 2023 00:47:27 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50ABF94754 for ; Mon, 13 Mar 2023 21:46:59 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id e15-20020a17090ac20f00b0023d1b009f52so3830851pjt.2 for ; Mon, 13 Mar 2023 21:46:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678769215; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=e/Olxjw+HQJK1P59lC+ASOiltstxhFqe09ROmonjaJY=; b=ZWvBVzen0T8f7BULVUv0cMr03PIhwu+ZX2I2CjmaSo0R2tzHH14XzNdq8SuxgOg9K/ wxPfVzinhu/2GQk9SP1s50lbChl8zK6osQ+xorNnBX0jcuu/a/VD8D+PfiYZu6Zh/08R TQelz691O145+wquLo/StQSYpKbN0f4G+SMgKOQRdkOxZ8NYZLqYxpQ3kaM76A/Mp8aC dqnylGPeMiQwqT8YLr5OzeoRXB/YOD1iODnm0RdjW+9O0v400cJ/i6uQV9+L9c4EyoEv ++AS3E1NUEJKWpa6xZ2Y6c2HADJtWn5HIdP/XPxiQ+PfWJCjsCSq4PJ/x3swi8rWh73C V+tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678769215; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=e/Olxjw+HQJK1P59lC+ASOiltstxhFqe09ROmonjaJY=; b=5hUuXLb/8lWoB9OiosebjEmsyD7C/aAMNM/MggQV2xKapEDtQP5DCViGFoM4+Cjue7 tnuyoUhUEy48lKf32WmwkZARfVKJnuoLg9euNq6Tu+4ECbCV7qETCI4CPYCfl5xbOlUt FNbwW0Ajr8ri5lgANQnorTe/s/fDEShbxyHbDUyLCeBYK4Hk2a8vc3mXr5fpwzPmp9gR mjbm56qI3eataURaqhJwGNVtE/ctFEntvRgYr5Oy6vkvhS5/DdMtGZjpuBmI/PX5UEyn MgIXLMY714SBf2vD249s/4ovYXZIBvInamiDG9NobmG71HkNsrGlw5bfk5dxt4b3UJUt X+6A== X-Gm-Message-State: AO0yUKWBpbbsOFMUgi7hKF8GlFP2piY/Gn5iBOzE/z5mv1pDjyBkoDZ0 9wyxuvbifIm+zj75uzUEQ9aD X-Received: by 2002:a17:902:ce90:b0:198:9e29:cc4f with SMTP id f16-20020a170902ce9000b001989e29cc4fmr43287436plg.43.1678769215273; Mon, 13 Mar 2023 21:46:55 -0700 (PDT) Received: from localhost.localdomain ([117.217.177.49]) by smtp.gmail.com with ESMTPSA id lh13-20020a170903290d00b0019c2b1c4ad4sm690125plb.6.2023.03.13.21.46.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 21:46:54 -0700 (PDT) From: Manivannan Sadhasivam To: lpieralisi@kernel.org, kw@linux.com Cc: kishon@kernel.org, bhelgaas@google.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Manivannan Sadhasivam Subject: [PATCH v3 7/7] PCI: endpoint: Add PCI Endpoint function driver for MHI bus Date: Tue, 14 Mar 2023 10:16:23 +0530 Message-Id: <20230314044623.10254-8-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230314044623.10254-1-manivannan.sadhasivam@linaro.org> References: <20230314044623.10254-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760318594735953538?= X-GMAIL-MSGID: =?utf-8?q?1760318594735953538?= Add PCI Endpoint driver for the Qualcomm MHI (Modem Host Interface) bus. The driver implements the MHI function over PCI in the endpoint device such as SDX55 modem. The MHI endpoint function driver acts as a controller driver for the MHI Endpoint stack and carries out all PCI related activities like mapping the host memory using iATU, triggering MSIs etc... Signed-off-by: Manivannan Sadhasivam Reviewed-by: Kishon Vijay Abraham I --- drivers/pci/endpoint/functions/Kconfig | 10 + drivers/pci/endpoint/functions/Makefile | 1 + drivers/pci/endpoint/functions/pci-epf-mhi.c | 454 +++++++++++++++++++ 3 files changed, 465 insertions(+) create mode 100644 drivers/pci/endpoint/functions/pci-epf-mhi.c diff --git a/drivers/pci/endpoint/functions/Kconfig b/drivers/pci/endpoint/functions/Kconfig index 9fd560886871..f5171b4fabbe 100644 --- a/drivers/pci/endpoint/functions/Kconfig +++ b/drivers/pci/endpoint/functions/Kconfig @@ -37,3 +37,13 @@ config PCI_EPF_VNTB between PCI Root Port and PCIe Endpoint. If in doubt, say "N" to disable Endpoint NTB driver. + +config PCI_EPF_MHI + tristate "PCI Endpoint driver for MHI bus" + depends on PCI_ENDPOINT && MHI_BUS_EP + help + Enable this configuration option to enable the PCI Endpoint + driver for Modem Host Interface (MHI) bus in Qualcomm Endpoint + devices such as SDX55. + + If in doubt, say "N" to disable Endpoint driver for MHI bus. diff --git a/drivers/pci/endpoint/functions/Makefile b/drivers/pci/endpoint/functions/Makefile index 5c13001deaba..696473fce50e 100644 --- a/drivers/pci/endpoint/functions/Makefile +++ b/drivers/pci/endpoint/functions/Makefile @@ -6,3 +6,4 @@ obj-$(CONFIG_PCI_EPF_TEST) += pci-epf-test.o obj-$(CONFIG_PCI_EPF_NTB) += pci-epf-ntb.o obj-$(CONFIG_PCI_EPF_VNTB) += pci-epf-vntb.o +obj-$(CONFIG_PCI_EPF_MHI) += pci-epf-mhi.o diff --git a/drivers/pci/endpoint/functions/pci-epf-mhi.c b/drivers/pci/endpoint/functions/pci-epf-mhi.c new file mode 100644 index 000000000000..03e7f42663b3 --- /dev/null +++ b/drivers/pci/endpoint/functions/pci-epf-mhi.c @@ -0,0 +1,454 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * PCI EPF driver for MHI Endpoint devices + * + * Copyright (C) 2022 Linaro Ltd. + * Author: Manivannan Sadhasivam + */ + +#include +#include +#include +#include +#include + +#define MHI_VERSION_1_0 0x01000000 + +struct pci_epf_mhi_ep_info { + const struct mhi_ep_cntrl_config *config; + struct pci_epf_header *epf_header; + enum pci_barno bar_num; + u32 epf_flags; + u32 msi_count; + u32 mru; +}; + +#define MHI_EP_CHANNEL_CONFIG_UL(ch_num, ch_name) \ + { \ + .num = ch_num, \ + .name = ch_name, \ + .dir = DMA_TO_DEVICE, \ + } + +#define MHI_EP_CHANNEL_CONFIG_DL(ch_num, ch_name) \ + { \ + .num = ch_num, \ + .name = ch_name, \ + .dir = DMA_FROM_DEVICE, \ + } + +static const struct mhi_ep_channel_config mhi_v1_channels[] = { + MHI_EP_CHANNEL_CONFIG_UL(0, "LOOPBACK"), + MHI_EP_CHANNEL_CONFIG_DL(1, "LOOPBACK"), + MHI_EP_CHANNEL_CONFIG_UL(2, "SAHARA"), + MHI_EP_CHANNEL_CONFIG_DL(3, "SAHARA"), + MHI_EP_CHANNEL_CONFIG_UL(4, "DIAG"), + MHI_EP_CHANNEL_CONFIG_DL(5, "DIAG"), + MHI_EP_CHANNEL_CONFIG_UL(6, "SSR"), + MHI_EP_CHANNEL_CONFIG_DL(7, "SSR"), + MHI_EP_CHANNEL_CONFIG_UL(8, "QDSS"), + MHI_EP_CHANNEL_CONFIG_DL(9, "QDSS"), + MHI_EP_CHANNEL_CONFIG_UL(10, "EFS"), + MHI_EP_CHANNEL_CONFIG_DL(11, "EFS"), + MHI_EP_CHANNEL_CONFIG_UL(12, "MBIM"), + MHI_EP_CHANNEL_CONFIG_DL(13, "MBIM"), + MHI_EP_CHANNEL_CONFIG_UL(14, "QMI"), + MHI_EP_CHANNEL_CONFIG_DL(15, "QMI"), + MHI_EP_CHANNEL_CONFIG_UL(16, "QMI"), + MHI_EP_CHANNEL_CONFIG_DL(17, "QMI"), + MHI_EP_CHANNEL_CONFIG_UL(18, "IP-CTRL-1"), + MHI_EP_CHANNEL_CONFIG_DL(19, "IP-CTRL-1"), + MHI_EP_CHANNEL_CONFIG_UL(20, "IPCR"), + MHI_EP_CHANNEL_CONFIG_DL(21, "IPCR"), + MHI_EP_CHANNEL_CONFIG_UL(32, "DUN"), + MHI_EP_CHANNEL_CONFIG_DL(33, "DUN"), + MHI_EP_CHANNEL_CONFIG_UL(36, "IP_SW0"), + MHI_EP_CHANNEL_CONFIG_DL(37, "IP_SW0"), +}; + +static const struct mhi_ep_cntrl_config mhi_v1_config = { + .max_channels = 128, + .num_channels = ARRAY_SIZE(mhi_v1_channels), + .ch_cfg = mhi_v1_channels, + .mhi_version = MHI_VERSION_1_0, +}; + +static struct pci_epf_header sdx55_header = { + .vendorid = PCI_VENDOR_ID_QCOM, + .deviceid = 0x0306, + .baseclass_code = PCI_BASE_CLASS_COMMUNICATION, + .subclass_code = PCI_CLASS_COMMUNICATION_MODEM & 0xff, + .interrupt_pin = PCI_INTERRUPT_INTA, +}; + +static const struct pci_epf_mhi_ep_info sdx55_info = { + .config = &mhi_v1_config, + .epf_header = &sdx55_header, + .bar_num = BAR_0, + .epf_flags = PCI_BASE_ADDRESS_MEM_TYPE_32, + .msi_count = 32, + .mru = 0x8000, +}; + +struct pci_epf_mhi { + const struct pci_epf_mhi_ep_info *info; + struct mhi_ep_cntrl mhi_cntrl; + struct pci_epf *epf; + struct mutex lock; + void __iomem *mmio; + resource_size_t mmio_phys; + u32 mmio_size; + int irq; + bool mhi_registered; +}; + +static int pci_epf_mhi_alloc_map(struct mhi_ep_cntrl *mhi_cntrl, u64 pci_addr, + phys_addr_t *phys_ptr, void __iomem **virt, size_t size) +{ + struct pci_epf_mhi *epf_mhi = container_of(mhi_cntrl, struct pci_epf_mhi, mhi_cntrl); + struct pci_epf *epf = epf_mhi->epf; + struct pci_epc *epc = epf_mhi->epf->epc; + size_t offset = pci_addr & (epc->mem->window.page_size - 1); + void __iomem *virt_addr; + phys_addr_t phys_addr; + int ret; + + virt_addr = pci_epc_mem_alloc_addr(epc, &phys_addr, size + offset); + if (!virt_addr) + return -ENOMEM; + + ret = pci_epc_map_addr(epc, epf->func_no, epf->vfunc_no, phys_addr, pci_addr - offset, + size + offset); + if (ret) { + pci_epc_mem_free_addr(epc, phys_addr, virt_addr, size + offset); + + return ret; + } + + *phys_ptr = phys_addr + offset; + *virt = virt_addr + offset; + + return 0; +} + +static void pci_epf_mhi_unmap_free(struct mhi_ep_cntrl *mhi_cntrl, u64 pci_addr, + phys_addr_t phys_addr, void __iomem *virt_addr, size_t size) +{ + struct pci_epf_mhi *epf_mhi = container_of(mhi_cntrl, struct pci_epf_mhi, mhi_cntrl); + struct pci_epf *epf = epf_mhi->epf; + struct pci_epc *epc = epf->epc; + size_t offset = pci_addr & (epc->mem->window.page_size - 1); + + pci_epc_unmap_addr(epc, epf->func_no, epf->vfunc_no, phys_addr - offset); + pci_epc_mem_free_addr(epc, phys_addr - offset, virt_addr - offset, size + offset); +} + +static void pci_epf_mhi_raise_irq(struct mhi_ep_cntrl *mhi_cntrl, u32 vector) +{ + struct pci_epf_mhi *epf_mhi = container_of(mhi_cntrl, struct pci_epf_mhi, mhi_cntrl); + struct pci_epf *epf = epf_mhi->epf; + struct pci_epc *epc = epf->epc; + + /* + * Vector is incremented by 1 here as the DWC core will decrement it before + * writing to iATU. + */ + pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, PCI_EPC_IRQ_MSI, vector + 1); +} + +static int pci_epf_mhi_read_from_host(struct mhi_ep_cntrl *mhi_cntrl, u64 from, void __iomem *to, + size_t size) +{ + struct pci_epf_mhi *epf_mhi = container_of(mhi_cntrl, struct pci_epf_mhi, mhi_cntrl); + struct pci_epf *epf = epf_mhi->epf; + struct pci_epc *epc = epf_mhi->epf->epc; + void __iomem *tre_buf; + phys_addr_t tre_phys; + size_t offset = from % 0x1000; + int ret; + + mutex_lock(&epf_mhi->lock); + + tre_buf = pci_epc_mem_alloc_addr(epc, &tre_phys, size + offset); + if (!tre_buf) { + mutex_unlock(&epf_mhi->lock); + return -ENOMEM; + } + + ret = pci_epc_map_addr(epc, epf->func_no, epf->vfunc_no, tre_phys, from - offset, + size + offset); + if (ret) { + pci_epc_mem_free_addr(epc, tre_phys, tre_buf, size + offset); + mutex_unlock(&epf_mhi->lock); + return ret; + } + + memcpy_fromio(to, tre_buf + offset, size); + + pci_epc_unmap_addr(epc, epf->func_no, epf->vfunc_no, tre_phys); + pci_epc_mem_free_addr(epc, tre_phys, tre_buf, size + offset); + + mutex_unlock(&epf_mhi->lock); + + return 0; +} + +static int pci_epf_mhi_write_to_host(struct mhi_ep_cntrl *mhi_cntrl, void __iomem *from, u64 to, + size_t size) +{ + struct pci_epf_mhi *epf_mhi = container_of(mhi_cntrl, struct pci_epf_mhi, mhi_cntrl); + struct pci_epf *epf = epf_mhi->epf; + struct pci_epc *epc = epf_mhi->epf->epc; + void __iomem *tre_buf; + phys_addr_t tre_phys; + size_t offset = to % 0x1000; + int ret; + + mutex_lock(&epf_mhi->lock); + + tre_buf = pci_epc_mem_alloc_addr(epc, &tre_phys, size + offset); + if (!tre_buf) { + mutex_unlock(&epf_mhi->lock); + return -ENOMEM; + } + + ret = pci_epc_map_addr(epc, epf->func_no, epf->vfunc_no, tre_phys, to - offset, + size + offset); + if (ret) { + pci_epc_mem_free_addr(epc, tre_phys, tre_buf, size + offset); + mutex_unlock(&epf_mhi->lock); + return ret; + } + + memcpy_toio(tre_buf + offset, from, size); + + pci_epc_unmap_addr(epc, epf->func_no, epf->vfunc_no, tre_phys); + pci_epc_mem_free_addr(epc, tre_phys, tre_buf, size + offset); + + mutex_unlock(&epf_mhi->lock); + + return 0; +} + +static int pci_epf_mhi_core_init(struct pci_epf *epf) +{ + struct pci_epf_mhi *epf_mhi = epf_get_drvdata(epf); + const struct pci_epf_mhi_ep_info *info = epf_mhi->info; + struct pci_epf_bar *epf_bar = &epf->bar[info->bar_num]; + struct pci_epc *epc = epf->epc; + struct device *dev = &epf->dev; + int ret; + + epf_bar->phys_addr = epf_mhi->mmio_phys; + epf_bar->size = epf_mhi->mmio_size; + epf_bar->barno = info->bar_num; + epf_bar->flags = info->epf_flags; + ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, epf_bar); + if (ret) { + dev_err(dev, "Failed to set BAR: %d\n", ret); + return ret; + } + + ret = pci_epc_set_msi(epc, epf->func_no, epf->vfunc_no, + order_base_2(info->msi_count)); + if (ret) { + dev_err(dev, "Failed to set MSI configuration: %d\n", ret); + return ret; + } + + ret = pci_epc_write_header(epc, epf->func_no, epf->vfunc_no, epf->header); + if (ret) { + dev_err(dev, "Failed to set Configuration header: %d\n", ret); + return ret; + } + + return 0; +} + +static int pci_epf_mhi_link_up(struct pci_epf *epf) +{ + struct pci_epf_mhi *epf_mhi = epf_get_drvdata(epf); + const struct pci_epf_mhi_ep_info *info = epf_mhi->info; + struct mhi_ep_cntrl *mhi_cntrl = &epf_mhi->mhi_cntrl; + struct pci_epc *epc = epf->epc; + struct device *dev = &epf->dev; + int ret; + + mhi_cntrl->mmio = epf_mhi->mmio; + mhi_cntrl->irq = epf_mhi->irq; + mhi_cntrl->mru = info->mru; + + /* Assign the struct dev of PCI EP as MHI controller device */ + mhi_cntrl->cntrl_dev = epc->dev.parent; + mhi_cntrl->raise_irq = pci_epf_mhi_raise_irq; + mhi_cntrl->alloc_map = pci_epf_mhi_alloc_map; + mhi_cntrl->unmap_free = pci_epf_mhi_unmap_free; + mhi_cntrl->read_from_host = pci_epf_mhi_read_from_host; + mhi_cntrl->write_to_host = pci_epf_mhi_write_to_host; + + /* Register the MHI EP controller */ + ret = mhi_ep_register_controller(mhi_cntrl, info->config); + if (ret) { + dev_err(dev, "Failed to register MHI EP controller: %d\n", ret); + return ret; + } + + epf_mhi->mhi_registered = true; + + return 0; +} + +static int pci_epf_mhi_link_down(struct pci_epf *epf) +{ + struct pci_epf_mhi *epf_mhi = epf_get_drvdata(epf); + struct mhi_ep_cntrl *mhi_cntrl = &epf_mhi->mhi_cntrl; + + if (epf_mhi->mhi_registered) { + mhi_ep_power_down(mhi_cntrl); + mhi_ep_unregister_controller(mhi_cntrl); + epf_mhi->mhi_registered = false; + } + + return 0; +} + +static int pci_epf_mhi_bme(struct pci_epf *epf) +{ + struct pci_epf_mhi *epf_mhi = epf_get_drvdata(epf); + struct mhi_ep_cntrl *mhi_cntrl = &epf_mhi->mhi_cntrl; + struct device *dev = &epf->dev; + int ret; + + /* Power up the MHI EP stack if link is up and stack is in power down state */ + if (!mhi_cntrl->enabled && epf_mhi->mhi_registered) { + ret = mhi_ep_power_up(mhi_cntrl); + if (ret) { + dev_err(dev, "Failed to power up MHI EP: %d\n", ret); + mhi_ep_unregister_controller(mhi_cntrl); + epf_mhi->mhi_registered = false; + } + } + + return 0; +} + +static int pci_epf_mhi_bind(struct pci_epf *epf) +{ + struct pci_epf_mhi *epf_mhi = epf_get_drvdata(epf); + struct pci_epc *epc = epf->epc; + struct platform_device *pdev = to_platform_device(epc->dev.parent); + struct device *dev = &epf->dev; + struct resource *res; + int ret; + + if (WARN_ON_ONCE(!epc)) + return -EINVAL; + + /* Get MMIO base address from Endpoint controller */ + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mmio"); + epf_mhi->mmio_phys = res->start; + epf_mhi->mmio_size = resource_size(res); + + epf_mhi->mmio = ioremap_wc(epf_mhi->mmio_phys, epf_mhi->mmio_size); + if (IS_ERR(epf_mhi->mmio)) + return PTR_ERR(epf_mhi->mmio); + + ret = platform_get_irq_byname(pdev, "doorbell"); + if (ret < 0) { + dev_err(dev, "Failed to get Doorbell IRQ\n"); + iounmap(epf_mhi->mmio); + return ret; + } + + epf_mhi->irq = ret; + + return 0; +} + +static void pci_epf_mhi_unbind(struct pci_epf *epf) +{ + struct pci_epf_mhi *epf_mhi = epf_get_drvdata(epf); + const struct pci_epf_mhi_ep_info *info = epf_mhi->info; + struct pci_epf_bar *epf_bar = &epf->bar[info->bar_num]; + struct mhi_ep_cntrl *mhi_cntrl = &epf_mhi->mhi_cntrl; + struct pci_epc *epc = epf->epc; + + /* + * Forcefully power down the MHI EP stack. Only way to bring the MHI EP stack + * back to working state after successive bind is by getting BME from host. + */ + if (epf_mhi->mhi_registered) { + mhi_ep_power_down(mhi_cntrl); + mhi_ep_unregister_controller(mhi_cntrl); + epf_mhi->mhi_registered = false; + } + + iounmap(epf_mhi->mmio); + pci_epc_clear_bar(epc, epf->func_no, epf->vfunc_no, epf_bar); +} + +static struct pci_epc_event_ops pci_epf_mhi_event_ops = { + .core_init = pci_epf_mhi_core_init, + .link_up = pci_epf_mhi_link_up, + .link_down = pci_epf_mhi_link_down, + .bme = pci_epf_mhi_bme, +}; + +static int pci_epf_mhi_probe(struct pci_epf *epf, const struct pci_epf_device_id *id) +{ + struct pci_epf_mhi_ep_info *info = (struct pci_epf_mhi_ep_info *) id->driver_data; + struct pci_epf_mhi *epf_mhi; + struct device *dev = &epf->dev; + + epf_mhi = devm_kzalloc(dev, sizeof(*epf_mhi), GFP_KERNEL); + if (!epf_mhi) + return -ENOMEM; + + epf->header = info->epf_header; + epf_mhi->info = info; + epf_mhi->epf = epf; + + epf->event_ops = &pci_epf_mhi_event_ops; + + mutex_init(&epf_mhi->lock); + + epf_set_drvdata(epf, epf_mhi); + + return 0; +} + +static const struct pci_epf_device_id pci_epf_mhi_ids[] = { + { + .name = "sdx55", .driver_data = (kernel_ulong_t) &sdx55_info, + }, + {}, +}; + +static struct pci_epf_ops pci_epf_mhi_ops = { + .unbind = pci_epf_mhi_unbind, + .bind = pci_epf_mhi_bind, +}; + +static struct pci_epf_driver pci_epf_mhi_driver = { + .driver.name = "pci_epf_mhi", + .probe = pci_epf_mhi_probe, + .id_table = pci_epf_mhi_ids, + .ops = &pci_epf_mhi_ops, + .owner = THIS_MODULE, +}; + +static int __init pci_epf_mhi_init(void) +{ + return pci_epf_register_driver(&pci_epf_mhi_driver); +} +module_init(pci_epf_mhi_init); + +static void __exit pci_epf_mhi_exit(void) +{ + pci_epf_unregister_driver(&pci_epf_mhi_driver); +} +module_exit(pci_epf_mhi_exit); + +MODULE_DESCRIPTION("PCI EPF driver for MHI Endpoint devices"); +MODULE_AUTHOR("Manivannan Sadhasivam "); +MODULE_LICENSE("GPL");