Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4725017ybv; Mon, 17 Feb 2020 04:46:59 -0800 (PST) X-Google-Smtp-Source: APXvYqymv9h1ix+QdNT1flXxWlvA2N/UmuTrShGGAWB7L6AQBHTXTJyWTfDmLvuXV3V0oxDBNfuO X-Received: by 2002:aca:5844:: with SMTP id m65mr9889465oib.136.1581943619588; Mon, 17 Feb 2020 04:46:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581943619; cv=none; d=google.com; s=arc-20160816; b=V0OkCR06bfxTYpKB11wKOq+AD7+WTnzmGSWJoyctFcsXitpsw/e1O+aap6A1fC/Ffs O6EARkt0j4uXIKEgChqxXdLjllFcEHwgVZquxneLmsIxJY5tB/sjlVGKN6uPzFGub37I hHl4xipSEecSpClmN6XTs5CCdFiFH+sMZt1hIIDkk67Pyde1O+FsKVVXYAxOpb8hW1do 0nRznVftqTg283Nh2GqZ/ErU/TD6oMJLw2QTK3DaLa2isFfTtPWu+c9Slw+rdpxP06DY 5UDrkiLWgzXvte0nmVN0Sq2ivV89ngdccDBPgWHjul7LcpcIgLLRTpty1HU1m3GGTHPN +aXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from; bh=eGt2+Yh0O6x9T6oLgMVEW8AJcfszXV5Q3sRLEsQmQ/0=; b=SnpO6jvbBUFYZ40IDz5wL6ZszjELr/t69ljn2fC4dCz094Vxop1AhvNwjS1zm4niJp +C2qW4Ke8NMYYnD3Ea+r1gZlYbW2QNjuWDVF52A6rLEpoR1Sx/ykHBdFrmYCVyWz+hE5 g4eteY/X9Q7pZZi7DXVcPVNmhvPi+9ErTaaO2aqSFxL6bvjUME+5phj5DpGovQ0NytiO Jk4nN3GEL7Qh8YaoXAug9LgZVGOQ1MlZsLVpZHTKt7Kgw4cVX5n/5QGxgANipv1VFMJN Cxf4r4/2QqszFPcdebU0wKvTpHrsJjzNzGaWLdDty7gk1XoIYKpB35a6QhhNXueHd8gy t4gQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=SeFtdgpa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c4si180460ots.107.2020.02.17.04.46.47; Mon, 17 Feb 2020 04:46:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=SeFtdgpa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729688AbgBQMLX (ORCPT + 99 others); Mon, 17 Feb 2020 07:11:23 -0500 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:10305 "EHLO hqnvemgate24.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729672AbgBQMLW (ORCPT ); Mon, 17 Feb 2020 07:11:22 -0500 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Mon, 17 Feb 2020 04:10:12 -0800 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Mon, 17 Feb 2020 04:11:21 -0800 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Mon, 17 Feb 2020 04:11:21 -0800 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 17 Feb 2020 12:11:21 +0000 Received: from hqnvemgw03.nvidia.com (10.124.88.68) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Mon, 17 Feb 2020 12:11:21 +0000 Received: from vidyas-desktop.nvidia.com (Not Verified[10.24.37.38]) by hqnvemgw03.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Mon, 17 Feb 2020 04:11:20 -0800 From: Vidya Sagar To: , , , , , , CC: , , , , , , , Subject: [PATCH V3 5/5] PCI: pci-epf-test: Add support to defer core initialization Date: Mon, 17 Feb 2020 17:40:36 +0530 Message-ID: <20200217121036.3057-6-vidyas@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200217121036.3057-1-vidyas@nvidia.com> References: <20200217121036.3057-1-vidyas@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1581941412; bh=eGt2+Yh0O6x9T6oLgMVEW8AJcfszXV5Q3sRLEsQmQ/0=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=SeFtdgpahDWW2OuUC/5wwH/aUpbu27WMzNmBU03CZUEA9JXy+K7f1o3SeyqSehlH6 Ug/9satkjGGYJWFbK2dJ8O49uDPl4gma+oCxfucDw+0TWA3hPFWqUutvJ91Mvtp/R1 UuVdPvKVhnBEAOFqi22wnC1desbLLnHjlSMzo1IccC5E50UCHED7AvGSCclJjmwz3G /goV3gslJyIxuAf7zFkL2hNXOHeVHAJlRN0kOWFqONBzGM0E/scTMjve7OuQp5hECs +lcZio3QhwaS3s5vofaeBwxl0rU++zxNxfBe/rdfuMHc8MwxySPHSW5VmtCsS9rrWu dQvPnE7dylgQw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support to defer core initialization and to receive a notifier when core is ready to accommodate platforms where core is not for initialization untile reference clock from host is available. Signed-off-by: Vidya Sagar Acked-by: Kishon Vijay Abraham I --- V3: * Added Acked-by: Kishon Vijay Abraham I V2: * Addressed review comments from Kishon drivers/pci/endpoint/functions/pci-epf-test.c | 118 ++++++++++++------ 1 file changed, 77 insertions(+), 41 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index bddff15052cc..be04c6220265 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -360,18 +360,6 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) msecs_to_jiffies(1)); } -static int pci_epf_test_notifier(struct notifier_block *nb, unsigned long val, - void *data) -{ - struct pci_epf *epf = container_of(nb, struct pci_epf, nb); - struct pci_epf_test *epf_test = epf_get_drvdata(epf); - - queue_delayed_work(kpcitest_workqueue, &epf_test->cmd_handler, - msecs_to_jiffies(1)); - - return NOTIFY_OK; -} - static void pci_epf_test_unbind(struct pci_epf *epf) { struct pci_epf_test *epf_test = epf_get_drvdata(epf); @@ -428,6 +416,78 @@ static int pci_epf_test_set_bar(struct pci_epf *epf) return 0; } +static int pci_epf_test_core_init(struct pci_epf *epf) +{ + struct pci_epf_header *header = epf->header; + const struct pci_epc_features *epc_features; + struct pci_epc *epc = epf->epc; + struct device *dev = &epf->dev; + bool msix_capable = false; + bool msi_capable = true; + int ret; + + epc_features = pci_epc_get_features(epc, epf->func_no); + if (epc_features) { + msix_capable = epc_features->msix_capable; + msi_capable = epc_features->msi_capable; + } + + ret = pci_epc_write_header(epc, epf->func_no, header); + if (ret) { + dev_err(dev, "Configuration header write failed\n"); + return ret; + } + + ret = pci_epf_test_set_bar(epf); + if (ret) + return ret; + + if (msi_capable) { + ret = pci_epc_set_msi(epc, epf->func_no, epf->msi_interrupts); + if (ret) { + dev_err(dev, "MSI configuration failed\n"); + return ret; + } + } + + if (msix_capable) { + ret = pci_epc_set_msix(epc, epf->func_no, epf->msix_interrupts); + if (ret) { + dev_err(dev, "MSI-X configuration failed\n"); + return ret; + } + } + + return 0; +} + +static int pci_epf_test_notifier(struct notifier_block *nb, unsigned long val, + void *data) +{ + struct pci_epf *epf = container_of(nb, struct pci_epf, nb); + struct pci_epf_test *epf_test = epf_get_drvdata(epf); + int ret; + + switch (val) { + case CORE_INIT: + ret = pci_epf_test_core_init(epf); + if (ret) + return NOTIFY_BAD; + break; + + case LINK_UP: + queue_delayed_work(kpcitest_workqueue, &epf_test->cmd_handler, + msecs_to_jiffies(1)); + break; + + default: + dev_err(&epf->dev, "Invalid EPF test notifier event\n"); + return NOTIFY_BAD; + } + + return NOTIFY_OK; +} + static int pci_epf_test_alloc_space(struct pci_epf *epf) { struct pci_epf_test *epf_test = epf_get_drvdata(epf); @@ -496,14 +556,11 @@ static int pci_epf_test_bind(struct pci_epf *epf) { int ret; struct pci_epf_test *epf_test = epf_get_drvdata(epf); - struct pci_epf_header *header = epf->header; const struct pci_epc_features *epc_features; enum pci_barno test_reg_bar = BAR_0; struct pci_epc *epc = epf->epc; - struct device *dev = &epf->dev; bool linkup_notifier = false; - bool msix_capable = false; - bool msi_capable = true; + bool core_init_notifier = false; if (WARN_ON_ONCE(!epc)) return -EINVAL; @@ -511,8 +568,7 @@ static int pci_epf_test_bind(struct pci_epf *epf) epc_features = pci_epc_get_features(epc, epf->func_no); if (epc_features) { linkup_notifier = epc_features->linkup_notifier; - msix_capable = epc_features->msix_capable; - msi_capable = epc_features->msi_capable; + core_init_notifier = epc_features->core_init_notifier; test_reg_bar = pci_epc_get_first_free_bar(epc_features); pci_epf_configure_bar(epf, epc_features); } @@ -520,34 +576,14 @@ static int pci_epf_test_bind(struct pci_epf *epf) epf_test->test_reg_bar = test_reg_bar; epf_test->epc_features = epc_features; - ret = pci_epc_write_header(epc, epf->func_no, header); - if (ret) { - dev_err(dev, "Configuration header write failed\n"); - return ret; - } - ret = pci_epf_test_alloc_space(epf); if (ret) return ret; - ret = pci_epf_test_set_bar(epf); - if (ret) - return ret; - - if (msi_capable) { - ret = pci_epc_set_msi(epc, epf->func_no, epf->msi_interrupts); - if (ret) { - dev_err(dev, "MSI configuration failed\n"); - return ret; - } - } - - if (msix_capable) { - ret = pci_epc_set_msix(epc, epf->func_no, epf->msix_interrupts); - if (ret) { - dev_err(dev, "MSI-X configuration failed\n"); + if (!core_init_notifier) { + ret = pci_epf_test_core_init(epf); + if (ret) return ret; - } } if (linkup_notifier) { -- 2.17.1