From patchwork Thu Oct 31 16:27:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 2004740 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.a=rsa-sha256 header.s=selector1 header.b=Bz+Q8Wdi; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-pci+bounces-15731-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XfTtS2SVwz1xwF for ; Fri, 1 Nov 2024 03:27:44 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 9CBD3283779 for ; Thu, 31 Oct 2024 16:27:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D95AE1BD03F; Thu, 31 Oct 2024 16:27:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="Bz+Q8Wdi" X-Original-To: linux-pci@vger.kernel.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2045.outbound.protection.outlook.com [40.107.21.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F78D2E406; Thu, 31 Oct 2024 16:27:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.45 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730392043; cv=fail; b=fwYoDsyWbL6aVCV5eicad1PhR3mCErjECUfk9vZd2bfaFdCXS6A5LnrBXOYi7lH1I8vtDcozBqoNeonAchgzODo3Z3MWow8OJv5SiL71NfsUrZIHC3PT0vQq/CJQ3RcpijgvrG4HaaGj9UjADXjmlaovn4scWINelNHOHJfnTEg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730392043; c=relaxed/simple; bh=WztdJXCK+bOn8jeGvfQAh0AF4COBEh+c0a1xNE6MdUc=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=O222GVxHvhCZCLSP4gL1h5eYJgIABOnto1AMmZnGCua8CQ03p5FbPwUv+H3XmzaaYvDDvMtJrNM4UYomsLmk8i5TCfflKuA0z/UMTeKOkPSEMW/6aS5VrufrdKav8LBi7XFSmT7m8RppEsN0XrFZGflIdQ/g3gZuAes9ruOywS8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=Bz+Q8Wdi; arc=fail smtp.client-ip=40.107.21.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=OUZIFn7/A2V2TsW3x3N3GGhrbAD1xOCpEfiCUuKW77KckS0+SjK/YdH+du9TLwZiUKCKUI5ff5O5xUiesTE4FfLTOsMkCjni6oQbrlwE167rdhBlhLjKOa2y077LNl37aqstITiZkOsN3eWI+Dxk2WMA4ryFwUDgQ3ghBIIOc6PkEazsRE6tBNhp77Msp4gIeLCvUX9UmY5TGzX+uqCKteFHexGs+PqHiNwtWJIyH8IkaqI5uZziSvFTqeYNtd0mW7aAzX/+sIt39QtKCngzvRTWCaHs/c30qiT93yMS1WbqvgWPUrdPfL3tQstQPfiP9BmXQt9dmC6uM5fBxsTjhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Oan0nT460bnBSfdOKCXlsarwBLEOZ6HSByQIFZo5Sn4=; b=rN/wty1IPczsVy4Z+8AGBwTW+oUQs/hvWhoBL7XBY6JLSngz/GLrN1qEsghctkdU9I1BAeMHVouQjC9CaQBRyeg900pptNo9BB41thQWsYHaVRryVhkvhFGFRals8xWloAQE3gXvjJ1gnjDCIK52D+/Tk2C2/H1gzG9KlGKbKIGGzX0mn0nhNDbp+/eDVmWcIgyIsObPKnXCInCvnipD9kWy/Eb8Fwv4VxWdlth70hpacaHhpp0uGV0tkIfW14+WCoQ0zipnQrFJg47MfZcm/hKF1D07h0nv6rZcvX2T6y4qHHrt2KKGcUE7Bc1nqxwQB5ADxxlhNFEiYIdIHxCozQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Oan0nT460bnBSfdOKCXlsarwBLEOZ6HSByQIFZo5Sn4=; b=Bz+Q8Wdif90oVm6wCofNWsvzKqPytHIH7O7fij6LknfwV+XPrLCc6RImiqorCUal+bD2w2ySRwRJ5msUz2AlE/GLU50NY6OtsvRKrZvdVMGh7n9fAPIm2P2lD2mf+xGjf1zIB5CCaCnVERkiAMzW/Klx9msoRl225jqmPkEK4+lYIoFpPV2R5fvy4nNgYqRpz+ce1J+coam/cw6+zzQW/jmQKlZjjdKfSoNlfYMk62B9hg6WsKueoHnFu+gdpE3g8QjhvCh6e2JLXuW9xyBR93+BGaMM6Xa7Kxp46rxiypsWPBKpSYxCyu9XaziK1TRVix6Jv7xGC9jHYwcOQ5yzyQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by PA1PR04MB11081.eurprd04.prod.outlook.com (2603:10a6:102:485::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.25; Thu, 31 Oct 2024 16:27:17 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%4]) with mapi id 15.20.8093.027; Thu, 31 Oct 2024 16:27:16 +0000 From: Frank Li Date: Thu, 31 Oct 2024 12:27:00 -0400 Subject: [PATCH v4 1/5] PCI: endpoint: Add pci_epc_get_fn() API for customizable filtering Message-Id: <20241031-ep-msi-v4-1-717da2d99b28@nxp.com> References: <20241031-ep-msi-v4-0-717da2d99b28@nxp.com> In-Reply-To: <20241031-ep-msi-v4-0-717da2d99b28@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, tglx@linutronix.de, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1730392028; l=3101; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=WztdJXCK+bOn8jeGvfQAh0AF4COBEh+c0a1xNE6MdUc=; b=5R7ouNHd90vplufWGmVJaXnpYoRGO/hg16Xps5b38myeJ5Rvm7rUk9iQDjrnayCIReb1GHWsh I7Qu7uZx4FfBE8DwSjryyLQy5AqsqdkTvNlxPbHByxwA2nccdUyPCrd X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BYAPR08CA0056.namprd08.prod.outlook.com (2603:10b6:a03:117::33) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|PA1PR04MB11081:EE_ X-MS-Office365-Filtering-Correlation-Id: 1af4b9e5-ba50-4a91-2294-08dcf9c8e20f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|52116014|7416014|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?s5xAVL3CvBH00V/UeUJOCvASOMSwKML?= =?utf-8?q?Uv99iniiY1+SfZNGzOHLtrh5lY+A6H0ozJbWvWJgSRzrrwW6oAfyMPFPz63UvhdVt?= =?utf-8?q?JL90ilwJu7xu6w1q97zzQVLSYqPK0pP99a68TgtdPEfETHjAUOOGGwm8yUg3SeM9J?= =?utf-8?q?ftrtdkTS2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PUK3VbqVGGWiSC1T6c6FcuNo5tjiztbgy+gs4ZnP5?= =?utf-8?q?fOKDu3UnHcHOB5w+PRrh9/Y++3MgoPqFPoQTqEaAWNl8Q/ml9u1KxZRso7JOI6/Yt?= =?utf-8?q?PpK5VDzob+HBnYTAIyN3HIZ1x9jAI2r3vz8boQvETj9R6TOnwqF2nygf2VK2+nSco?= =?utf-8?q?e51uFskSvfc1mj1EZbz7cobgibSac360oQKCR184F8roFc7/hBRSyNNkYEiAvhFo0?= =?utf-8?q?v5Ew6AUNNnNRnkQEtLYZh5c+5rBeI+vVK6vsn262O7PWhYMVb7ECZVMc=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(52116014)(7416014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?rpgUtSHOCTCAa1qDAukBEtDJQhDJ?= =?utf-8?q?xW0Rndgxggi2Lm03Mv1Pnb6CuP+q9zVkXo0qGSuEGyCA7uNPPYaCOat/9rbBttDHJ?= =?utf-8?q?nbPKe36ucMNVwC4bWf7OGbnstook4N1A93+VpXfKnqG9wGptn32fMbtj9d4FRo+h1?= =?utf-8?q?zq3ThcacvcofStbJbiqstf/Q3pJ8kz7S6uRfTfGCJPHnVLxExF4IaTOvhlAZHZc4r?= =?utf-8?q?VhhpkTAnSDlfHlIm6NFRFxJbePDti5O7ufbeUUYic4nrrtp9wPFDTBs6r7DkBHtMY?= =?utf-8?q?6ADIP3pdYvCvPX0t1z+ocSAslnOkjnh3OdEX2wvCHZ1PA7TM3vFBEFT/fMXoOGXcn?= =?utf-8?q?2h+G1nYQWCu0ymcwH1YFzxerTBSFx+4kZwSAj05MGJ6hafawaPXIJKHqqjYsmG8Yz?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utf-8?q?H6BM+Oc6DuDQfauNygQdEy9gBx08duHMAIInnjf7T8UO+703rN9tJIBAMsadX/4YQ?= =?utf-8?q?o+zpl6RWvCDWyFbLBSCqRecA7IMxgAxBm7EpxT9eoZ7rV/kyWdQ85eSzAbZo+aZAL?= =?utf-8?q?Fkt8NcjlouuJ+ZbpAaRtf11OcZEHdT8y8EcmosnQeor2whEG7TXlos+odJ5EeFWMd?= =?utf-8?q?v8SfbhZRUqmDkLphNiPIawnxcn4hrNzjazs3Cpskn9i842s9t0psPbn8=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1af4b9e5-ba50-4a91-2294-08dcf9c8e20f X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2024 16:27:16.2338 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 8gtkQKvmiGvI98OyIatVYcmvRcEYlgXl3v6i6O2ByG0jjg49qgoajaEGNbPFX7JKg5nJvj9/3gAVT1wDlflBzg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA1PR04MB11081 Introduce the pci_epc_get_fn() API, allowing a custom filter callback function to be passed. Reimplement pci_epc_get() using pci_epc_get_fn() with a match name callback. Prepare the codebase for adding RC-to-EP doorbell support. Add DEFINE_FREE(pci_epc_put) to implement scope based auto cleanup. Signed-off-by: Frank Li --- change from v3 to v4 - none --- drivers/pci/endpoint/pci-epc-core.c | 23 +++++++++++++++++++++-- include/linux/pci-epc.h | 2 ++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c index 17f0071092550..14e6011df4b2c 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -48,6 +48,11 @@ void pci_epc_put(struct pci_epc *epc) } EXPORT_SYMBOL_GPL(pci_epc_put); +static bool pci_epc_match_name(struct device *dev, void *name) +{ + return strcmp(dev_name(dev), name) == 0; +} + /** * pci_epc_get() - get the PCI endpoint controller * @epc_name: device name of the endpoint controller @@ -56,6 +61,20 @@ EXPORT_SYMBOL_GPL(pci_epc_put); * endpoint controller */ struct pci_epc *pci_epc_get(const char *epc_name) +{ + return pci_epc_get_fn(pci_epc_match_name, (void *)epc_name); +} +EXPORT_SYMBOL_GPL(pci_epc_get); + +/** + * pci_epc_get_fn() - get the PCI endpoint controller + * @fn: callback match filter function, return true when matched + * @param: parameter for callback function fn + * + * Invoke to get struct pci_epc * corresponding to the device name of the + * endpoint controller + */ +struct pci_epc *pci_epc_get_fn(bool (*fn)(struct device *dev, void *param), void *param) { int ret = -EINVAL; struct pci_epc *epc; @@ -64,7 +83,7 @@ struct pci_epc *pci_epc_get(const char *epc_name) class_dev_iter_init(&iter, &pci_epc_class, NULL, NULL); while ((dev = class_dev_iter_next(&iter))) { - if (strcmp(epc_name, dev_name(dev))) + if (!fn(dev, param)) continue; epc = to_pci_epc(dev); @@ -82,7 +101,7 @@ struct pci_epc *pci_epc_get(const char *epc_name) class_dev_iter_exit(&iter); return ERR_PTR(ret); } -EXPORT_SYMBOL_GPL(pci_epc_get); +EXPORT_SYMBOL_GPL(pci_epc_get_fn); /** * pci_epc_get_first_free_bar() - helper to get first unreserved BAR diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h index 42ef06136bd1a..682808f4510be 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -266,7 +266,9 @@ pci_epc_get_first_free_bar(const struct pci_epc_features *epc_features); enum pci_barno pci_epc_get_next_free_bar(const struct pci_epc_features *epc_features, enum pci_barno bar); struct pci_epc *pci_epc_get(const char *epc_name); +struct pci_epc *pci_epc_get_fn(bool (*fn)(struct device *dev, void *param), void *param); void pci_epc_put(struct pci_epc *epc); +DEFINE_FREE(pci_epc_put, void *, if (!(_T)) pci_epc_put(_T)) int pci_epc_mem_init(struct pci_epc *epc, phys_addr_t base, size_t size, size_t page_size); From patchwork Thu Oct 31 16:27:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 2004742 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.a=rsa-sha256 header.s=selector1 header.b=ht7dQOvC; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.199.223; helo=ny.mirrors.kernel.org; envelope-from=linux-pci+bounces-15733-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [147.75.199.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XfTvf3rXqz1xwF for ; Fri, 1 Nov 2024 03:28:46 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 81BCD1C21BBF for ; Thu, 31 Oct 2024 16:28:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CB75A1C7B63; Thu, 31 Oct 2024 16:27:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="ht7dQOvC" X-Original-To: linux-pci@vger.kernel.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2045.outbound.protection.outlook.com [40.107.21.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9D061C57A0; Thu, 31 Oct 2024 16:27:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.45 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730392051; cv=fail; b=PJcXyIXLSeuPahNQrAKRtJpIi0oMCyRCgreYwfFwEwwjumpVrFAjx1RqdlgpEikKL8VnV3/um67X9UZLmHTRjD1nI0oFtEqjRBTrTbvrGhzdo6+AUJV5gpobIs2kH2FZwzFbW2YUs+7D5johtoSLIZ+xWoqGoGRvA1iR98iM9rI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730392051; c=relaxed/simple; bh=86w1a1XMlWfuSdwPQdmN0jUXDLe71oOcpkgioiRNwn8=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=iIR4jlVTToQtbJBpYe2iDu9vBj2eE7HrpvdxwqO4vetddsYMBf54otP/7g9Mub+7ilqIhDJf+5u4FjyBQ8goDftSftk5qKfJUB8IJ6Nw6hMuu4k/dZlVeoh9hTdD0XyeWakNVsLetWeHfeFpzy3WweHXU8XDBtFZd/RdAYQCONQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=ht7dQOvC; arc=fail smtp.client-ip=40.107.21.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cF6HEfjo4H0D9XuIfEDOesG5ZjDKkkxwUZflaUYzT5CzFxd9yrL2KPCQX/6CkDliwXMfkakOI9qN+70bkHRa05A8T+9C/oVRabJbn8xoYTJeevvROSqWS/dljvjFXk75D54gQxdIcstE8BSeTBdX699GKdsoQkVWfOoqVaAVTLeDaIX1D/G9i4k36xI5LQXSAt7GteQIO/EKihl15pkI/wWbHxKmFGtIgy+OFfRcEWfJOn+HOrCOwbIGbQoMKAdKZ3dKj+bQznvxCS0BsGGB+Os0s0l1NWk8L0icWvSWxgIdS02ldkpBEZOZCVmtTkZ2eeqpdhPpRHL5+uHUfnMuog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=3cvWynPFHPf07oWxi8rpPdNTX2d96vmSUu2BSeQ+qNo=; b=cpmAF6tv3VRU2PWPl0zcZ3tqp49idxdiV7zlmXUQ92td/4Tn0lvkgg1MO3Js+7UbmrXX5bS8JNBR6AerF1nPpq90hXg/k4McNY0sfNqdNMCHQf16RYuatNzmSHegl+lOKT8vjpeAjQCnQMLElbjLdlE39gtMvpfhqSMIBRFjlYk/t+slS+LOUfQBlpz68y4nIRMZWdll7q2pEhEDRgvGA6Cvu4gtSQFC5ms+P9uan/cF8B0TiLGjI0TJzmG4dmSSn1yffUQL1FzbHHjBz94gCTFZPCDzZdxtlahH2mu5HN0k+WB3QBQQ3QCKMNfJN39EsQmIOHmI6DVI62dF3zFRgQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3cvWynPFHPf07oWxi8rpPdNTX2d96vmSUu2BSeQ+qNo=; b=ht7dQOvCWErj22QXpnKF2/zKboJSQnuGF+KSrAZqRIdPqlMTYSEwztgy69Jax/xFe7TNkDy39VBZ79i7Y60nUL763I08Fsn6x9WoToNL+DNSMg4Oz1xmBHEsT0Bkr+b4egnJBG96a9z6dxwd0N+zav9K39BRrJCXGgvxAn9IggfuNUAHq6Bf8RWx/n39jHQXF3Jln9u35GRaaTHwRxinoQKcfoAViqeIRzivJzus7h+tvYJhb8nboZI3c5Qfa5Ecksd5tQwtFL+5kZwy4Ymv3yjneI4VfJZTTQSWVStguQkq9eMevcZz06t99MKLzjrSeiNX/a93AtEbqV6U4zuh4A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by PA1PR04MB11081.eurprd04.prod.outlook.com (2603:10a6:102:485::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.25; Thu, 31 Oct 2024 16:27:20 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%4]) with mapi id 15.20.8093.027; Thu, 31 Oct 2024 16:27:20 +0000 From: Frank Li Date: Thu, 31 Oct 2024 12:27:01 -0400 Subject: [PATCH v4 2/5] PCI: endpoint: Add RC-to-EP doorbell support using platform MSI controller Message-Id: <20241031-ep-msi-v4-2-717da2d99b28@nxp.com> References: <20241031-ep-msi-v4-0-717da2d99b28@nxp.com> In-Reply-To: <20241031-ep-msi-v4-0-717da2d99b28@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, tglx@linutronix.de, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1730392028; l=7322; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=86w1a1XMlWfuSdwPQdmN0jUXDLe71oOcpkgioiRNwn8=; b=Erbraa3lsZzknZGivE+84oK60M+flb/gF0e77hX/NWhTBmb/4Fv2V9SDcue/dnaM6Yr3otQWY Nj8ux8LJNtUCL+TTzRHEDBJSc/BTiSKVg3NyDMucbA62MPprlfnikLM X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BYAPR08CA0056.namprd08.prod.outlook.com (2603:10b6:a03:117::33) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|PA1PR04MB11081:EE_ X-MS-Office365-Filtering-Correlation-Id: fd943788-ace9-494a-cc8a-08dcf9c8e44c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|52116014|7416014|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?PDf12DKFXr54G5Pvz9q2+ebaNyCBKrj?= =?utf-8?q?XjQztlxI42kQHeYvvFDplnTBDaATVv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4KI4KglCGlzXKZwmCMnESJhEhjAsuTI6Bf?= =?utf-8?q?FWMY2mzn/FHuGAXRSuKBB13nfYhg/SXkdFKhcFOOZ05vZ+F826jBrdxhbX3Dim3V8?= =?utf-8?q?KXDDzce78SIH7RIZOobYEzf3PZQl6pveC+MiRvNLcVK0QRxuYLmpuukl0buZmTysn?= =?utf-8?q?+LfQBVXOXAMmBOkQPH4+fl4PR5bnhoOOkhbIE+WoJxA4qePFxrDuGk8Z7/68sPsL3?= =?utf-8?q?qVwaCuyeTOqgBcNUPv02Wekjm1yJQ0lz2GgbEjeJAi+Bbgq4rq1aQQe5wYNYsUj6j?= =?utf-8?q?WDDD/RCAGr1ZeyRnv6sLVrfHD2fi6FYqCXo8cWv6/y+F5YqwBeQqwr321EZw78c9y?= =?utf-8?q?xUlwesK25otlqzXpWP8FOVbjg0Z6cvvafG3NFMdRGhAVUvM5rHe7ClnM=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(52116014)(7416014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?SPrLaJTn8ByqsbAVoGKQjjlOtSaB?= =?utf-8?q?7pftYkJ31Kba1/VbUFzuwRc3eliJKuC11+fHqNC7HyM9kFjsADF2Ysy80fqk781sX?= =?utf-8?q?nDSBEabX/a9b5toclGcXKU7zpJK4DjqJ+lp/ZzecEZ8m62vK9zVrvYEfjqhSoGnl0?= =?utf-8?q?QzF8lqKtNRFg0xTEofYVZBBecyr6TqT0HElQpZqkwcIDoOstaYKqHcDuoDzuHsulZ?= =?utf-8?q?2898cdIlhp2cy+dhcRohk3LqtCRYeKsh/KcTom/5B/JBcyxofIkimvpk00y4W2uMY?= =?utf-8?q?B0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xBlLxmRIPbE3DrL0v92AuQJ46F3SkzdGMAZq6DxBstm8p5IiUDKG8WhpFXq2VCavs?= =?utf-8?q?BNz5IqzzbrGovu+uJniyEhlibfiqJTkAXE4MOTb9MsTE8F3twZF0gZJdhx48weAYj?= =?utf-8?q?FAlx6srCZ9ig6864DmyXcmrLY1D5liF3krftA9JWocIwZIKC8fBCeJWn/sRPhd5kH?= =?utf-8?q?xBcPcq1jlOJ7IRBa6/TLny0g2bZpDg/TKcBhflSlNC6tBPikAivFDERujPRywzlLK?= =?utf-8?q?i6xilvGEU5K0oQGGumJK968YD/NwoTpHHhZSxku+cBW+ixYMSnDl4vYkbStdvh7Io?= =?utf-8?q?4KTVSlT2WedmRiX2iwimXbTE2boZ2DIPErF5Kd1pDrJyJmavnk2KALtY=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: fd943788-ace9-494a-cc8a-08dcf9c8e44c X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2024 16:27:20.0550 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: YLxwMhjvEXGTZP4T6hLcaYhnFKI8fZqNPBGpEoMGDbBSZNFaXWNsPyBAm9/1K4eJ5A9IWOwM8mon/Lyi9UMfzQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA1PR04MB11081 Doorbell feature is implemented by mapping the EP's MSI interrupt controller message address to a dedicated BAR in the EPC core. It is the responsibility of the EPF driver to pass the actual message data to be written by the host to the doorbell BAR region through its own logic. Signed-off-by: Frank Li --- Change from v3 to v4 - msi change to use msi_get_virq() avoid use msi_for_each_desc(). - add new struct for pci_epf_doorbell_msg to msi msg,virq and irq name. - move mutex lock to epc function - initialize variable at declear place. - passdown epf to epc*() function to simplify code. --- drivers/pci/endpoint/Makefile | 2 +- drivers/pci/endpoint/pci-ep-msi.c | 128 ++++++++++++++++++++++++++++++++++++++ include/linux/pci-ep-msi.h | 15 +++++ include/linux/pci-epf.h | 19 ++++++ 4 files changed, 163 insertions(+), 1 deletion(-) diff --git a/drivers/pci/endpoint/Makefile b/drivers/pci/endpoint/Makefile index 95b2fe47e3b06..a1ccce440c2c5 100644 --- a/drivers/pci/endpoint/Makefile +++ b/drivers/pci/endpoint/Makefile @@ -5,4 +5,4 @@ obj-$(CONFIG_PCI_ENDPOINT_CONFIGFS) += pci-ep-cfs.o obj-$(CONFIG_PCI_ENDPOINT) += pci-epc-core.o pci-epf-core.o\ - pci-epc-mem.o functions/ + pci-epc-mem.o pci-ep-msi.o functions/ diff --git a/drivers/pci/endpoint/pci-ep-msi.c b/drivers/pci/endpoint/pci-ep-msi.c new file mode 100644 index 0000000000000..91207fb66db32 --- /dev/null +++ b/drivers/pci/endpoint/pci-ep-msi.c @@ -0,0 +1,128 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * PCI Endpoint *Controller* (EPC) MSI library + * + * Copyright (C) 2024 NXP + * Author: Frank Li + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static irqreturn_t pci_epf_doorbell_handler(int irq, void *data) +{ + struct pci_epf *epf = data; + struct msi_desc *desc = irq_get_msi_desc(irq); + + if (desc && epf->event_ops && epf->event_ops->doorbell) + epf->event_ops->doorbell(epf, desc->msi_index); + + return IRQ_HANDLED; +} + +static bool pci_epc_match_parent(struct device *dev, void *param) +{ + return dev->parent == param; +} + +static void pci_epc_write_msi_msg(struct msi_desc *desc, struct msi_msg *msg) +{ + struct pci_epc *epc __free(pci_epc_put) = NULL; + struct pci_epf *epf; + + epc = pci_epc_get_fn(pci_epc_match_parent, desc->dev); + if (!epc) + return; + + /* Only support one EPF for doorbell */ + epf = list_first_entry_or_null(&epc->pci_epf, struct pci_epf, list); + + if (epf && epf->db_msg && desc->msi_index < epf->num_db) + memcpy(&epf->db_msg[desc->msi_index].msg, msg, sizeof(*msg)); +} + +static void pci_epc_free_doorbell(struct pci_epc *epc, struct pci_epf *epf) +{ + int i; + + guard(mutex)(&epc->lock); + + for (i = 0; i < epf->num_db && epf->db_msg[i].virq; i++) { + free_irq(epf->db_msg[i].virq, epf); + epf->db_msg[i].virq = 0; + kfree(epf->db_msg[i].name); + epf->db_msg[i].name = NULL; + } + + platform_device_msi_free_irqs_all(epc->dev.parent); +} + +static int pci_epc_alloc_doorbell(struct pci_epc *epc, struct pci_epf *epf) +{ + struct device *dev = epc->dev.parent; + u16 num_db = epf->num_db; + int i = 0; + int ret; + + guard(mutex)(&epc->lock); + + ret = platform_device_msi_init_and_alloc_irqs(dev, num_db, pci_epc_write_msi_msg); + if (ret) { + dev_err(dev, "Failed to allocate MSI\n"); + return -ENOMEM; + } + + for (i = 0; i < num_db; i++) { + epf->db_msg[i].virq = msi_get_virq(dev, i); + epf->db_msg[i].name = kasprintf(GFP_KERNEL, "pci-epc-doorbell%d", i); + ret = request_irq(epf->db_msg[i].virq, pci_epf_doorbell_handler, 0, + epf->db_msg[i].name, epf); + if (ret) { + dev_err(dev, "Failed to request doorbell\n"); + pci_epc_free_doorbell(epc, epf); + return ret; + } + } + + return 0; +}; + +int pci_epf_alloc_doorbell(struct pci_epf *epf, u16 num_db) +{ + struct pci_epc *epc = epf->epc; + void *msg; + int ret; + + msg = kcalloc(num_db, sizeof(struct pci_epf_doorbell_msg), GFP_KERNEL); + if (!msg) + return -ENOMEM; + + epf->num_db = num_db; + epf->db_msg = msg; + + ret = pci_epc_alloc_doorbell(epc, epf); + if (ret) + kfree(msg); + + return ret; +} +EXPORT_SYMBOL_GPL(pci_epf_alloc_doorbell); + +void pci_epf_free_doorbell(struct pci_epf *epf) +{ + struct pci_epc *epc = epf->epc; + + pci_epc_free_doorbell(epc, epf); + + kfree(epf->db_msg); + epf->db_msg = NULL; + epf->num_db = 0; +} +EXPORT_SYMBOL_GPL(pci_epf_free_doorbell); diff --git a/include/linux/pci-ep-msi.h b/include/linux/pci-ep-msi.h new file mode 100644 index 0000000000000..f0cfecf491199 --- /dev/null +++ b/include/linux/pci-ep-msi.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * PCI Endpoint *Function* side MSI header file + * + * Copyright (C) 2024 NXP + * Author: Frank Li + */ + +#ifndef __PCI_EP_MSI__ +#define __PCI_EP_MSI__ + +int pci_epf_alloc_doorbell(struct pci_epf *epf, u16 nums); +void pci_epf_free_doorbell(struct pci_epf *epf); + +#endif /* __PCI_EP_MSI__ */ diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h index 18a3aeb62ae4e..50c0f877f2efb 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -12,6 +12,7 @@ #include #include #include +#include #include struct pci_epf; @@ -75,6 +76,7 @@ struct pci_epf_ops { * @link_up: Callback for the EPC link up event * @link_down: Callback for the EPC link down event * @bus_master_enable: Callback for the EPC Bus Master Enable event + * @doorbell: Callback for EPC receive MSI from RC side */ struct pci_epc_event_ops { int (*epc_init)(struct pci_epf *epf); @@ -82,6 +84,7 @@ struct pci_epc_event_ops { int (*link_up)(struct pci_epf *epf); int (*link_down)(struct pci_epf *epf); int (*bus_master_enable)(struct pci_epf *epf); + int (*doorbell)(struct pci_epf *epf, int index); }; /** @@ -125,6 +128,18 @@ struct pci_epf_bar { int flags; }; +/** + * struct pci_epf_doorbell_msg - represents doorbell message + * @msi_msg: MSI message + * @virq: irq number of this doorbell MSI message + * @name: irq name for doorbell interrupt + */ +struct pci_epf_doorbell_msg { + struct msi_msg msg; + int virq; + char *name; +}; + /** * struct pci_epf - represents the PCI EPF device * @dev: the PCI EPF device @@ -152,6 +167,8 @@ struct pci_epf_bar { * @vfunction_num_map: bitmap to manage virtual function number * @pci_vepf: list of virtual endpoint functions associated with this function * @event_ops: Callbacks for capturing the EPC events + * @db_msg: data for MSI from RC side + * @num_db: number of doorbells */ struct pci_epf { struct device dev; @@ -182,6 +199,8 @@ struct pci_epf { unsigned long vfunction_num_map; struct list_head pci_vepf; const struct pci_epc_event_ops *event_ops; + struct pci_epf_doorbell_msg *db_msg; + u16 num_db; }; /** From patchwork Thu Oct 31 16:27:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 2004743 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.a=rsa-sha256 header.s=selector1 header.b=eMGmy3BH; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-pci+bounces-15734-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XfTvv47Z9z1xwF for ; Fri, 1 Nov 2024 03:28:59 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 4EC111F22748 for ; Thu, 31 Oct 2024 16:28:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5D8531BD515; Thu, 31 Oct 2024 16:27:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="eMGmy3BH" X-Original-To: linux-pci@vger.kernel.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2045.outbound.protection.outlook.com [40.107.21.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 08ED91BC9FC; Thu, 31 Oct 2024 16:27:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.45 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730392055; cv=fail; b=IDBUdbkPaOOqOyD1jLTfcer5CIWH/GNy5fI172bdohGZwF15xO/QsNzUVckt0l0itOauFBPVI9GIm6JyrU1qFr0NU+nUG9KpYD6mNilQelx93peBpIqoc7gp/YEpujDa6ZCnB3RnPH08yMpE5hmvcW4v4kfMURu0pBjaECd2ZCo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730392055; c=relaxed/simple; bh=JYWf7Ivf0hxPXaDhUGKHvnfXMpLlf1E7XiPYVstdBQk=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=PMS5uysOhHUHj4YTv9647sMvwr6hCRYgP5uOD548C4WHzlJlDUE6Nrm33/4e5//q+leYXW2A0/B8v5yigBbR0pTdpdkhIhCHoUxw8blJroVYF42EiZJ7hURFH5w1EGzv9ygAGnNL5U6gnX4pLKuw2+K/f3J/2Zk5mJ8GpaB096w= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=eMGmy3BH; arc=fail smtp.client-ip=40.107.21.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Rst8UucvP2zB3S+01x9o/LesiTsMhT6gOiA75G/kBIkDqidqFKJfm0Ru8ZlxXsApWADvE5KugjJnswC8z7TCdSqqkBvm9MoHHx5Q16UIPNhcyPmrOlclr/YpMmheolXlKAF7HmJA/0ahIjUUKJ5BTcClckabo8n+9MJDH46wpNBRRiofI8N3zuKKPoAxQb6fQVn3aRdppymKGup6Sy4jqOned7G8MFeO9oEmKDHB+ZaeW0lLb4SAB9YB8fbfMSnMJ8yaQJdAAGfEBAanWzPTuN5C+7khKoLKjCjHj1Qfe/iDGn+W/hfGUwsdVVZba/Wu26Qgn/SZaKEihiMbl6C/wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=rSHhGQNj+pSFlSAACu8GErRxT1442ZWIsPF1u4YQz+A=; b=aao/Y9NalEB2TlHKMUhd0FFrSJEX2QDAEZT80PSXQfcWXJ9ZyBdEkNsAHLj9rNrU7g+Sd1HEy7lLg50PUv6C/ahtuwxVL+ZsjjwnJTus0tR93QdJ5rfrcOcUfsp7PULdMdM3AkIz5yMQgaAzqHHXt6Ifvp4CBOuUS/NFvZvqDYGG8NEjRuYRH6o0OlrYkcfiiTGKXE9AOJicB77l8DCxtdvSxCLeXCxR9bAXXdBxNyJUmc2uSEtpOE1Vt6MPZNnpylgWs73G5roYNSZ3xgGcq/WAMLLe8sDnUHNzmleScviYbHv/J86KQpDH/AhpvgFTk4o35GJtpnXsBZV0yWw2Jw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rSHhGQNj+pSFlSAACu8GErRxT1442ZWIsPF1u4YQz+A=; b=eMGmy3BH8LF/YEXD0foZZGCT62ZoKBwX/2KGTdEqilBl30s1qQvmjLxSo+nnHmNg0lakVtMRUmVzXrrr0P4jynRmBpnLPdjZ7snNOZEuazj2gRmNlLH080zLz4Z5PARN/mk3XNHitifschAApwN5X4QBRae8EVCI9yAgiMDTuLS7SpVbVxuaad/3tZXge+wbteoyLnAfmo7FYubu2zGDYMFVewFkICdtqmayANGt3QETQJoASR41ZCSHn+C24mioZcIiVgTNTRkp/yISdLu93vMybafORoxlYm+fcUjIZnRt/2p5mK7xRIJNoconspObjWuWvlsEmT7xsAqy9gu/Ug== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by PA1PR04MB11081.eurprd04.prod.outlook.com (2603:10a6:102:485::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.25; Thu, 31 Oct 2024 16:27:23 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%4]) with mapi id 15.20.8093.027; Thu, 31 Oct 2024 16:27:23 +0000 From: Frank Li Date: Thu, 31 Oct 2024 12:27:02 -0400 Subject: [PATCH v4 3/5] PCI: endpoint: pci-epf-test: Add doorbell test support Message-Id: <20241031-ep-msi-v4-3-717da2d99b28@nxp.com> References: <20241031-ep-msi-v4-0-717da2d99b28@nxp.com> In-Reply-To: <20241031-ep-msi-v4-0-717da2d99b28@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, tglx@linutronix.de, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1730392028; l=6630; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=JYWf7Ivf0hxPXaDhUGKHvnfXMpLlf1E7XiPYVstdBQk=; b=OeCLCcpHihO4JQsIb48Ao7gjrAZLLw/jpot03X9xaFEBbgSjRF6gQfbIE8OMXTIo99EeQR2S3 m548nd/NW42AxAH2xW8nHiU1wImcEA8E+jKaxz8S+4gLd4d+xxwf2it X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BYAPR08CA0056.namprd08.prod.outlook.com (2603:10b6:a03:117::33) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|PA1PR04MB11081:EE_ X-MS-Office365-Filtering-Correlation-Id: 519c698d-5aa3-4e35-579c-08dcf9c8e695 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|52116014|7416014|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?kS5RoQusBiHveAJK+RLkkSssLHzoX9O?= =?utf-8?q?Yv1RZiWNQzazgn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fHlNliWCIor0Zr/GF3m8vzCHCfnUPQRm2clqPahZ7a52Vmqck?= =?utf-8?q?xQHshkFOIEB3Q5DroJQrlaL6pXDdiJ0y/JkBVfcfPMOpZjua3mRw3nxGnagCD+3mW?= =?utf-8?q?btDaNEN2bd44jXgsxsG61sAH6jwZjJueLcnKg8pgmcwqnInvBccprtky89N6ykp6V?= =?utf-8?q?ySUUX3jb5nHnx4EiF2JFwQL75Z9JGOX+HoCasngxWSlP3xIhg6VB0U2W+C/gDbOLd?= =?utf-8?q?H1s7DMoDTZxRjOk8K/IqPHMJfMpXoRbTUtnxZ9mYahHMivW4Ld5blUpKcZBM+dHW/?= =?utf-8?q?U09qGbHWIRGbCax/UNvNvurmG26jmRElS0Njn80IZg3DWn/2bt2qqLDz4FUEFu1Tl?= =?utf-8?q?5yY2sOXEm9FJQvb5m0ylGHCHcqgeC0hWC03VeudusS00qkJGNEQ4btNA=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(52116014)(7416014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?81Yf7TpqdPQUHmxguxFP/QmeohfC?= =?utf-8?q?njkO5VMDkml4IZtlJZaBMGkLO3i+NJawFngkatrhFelBMw1r0fnj/hwkPedggodwk?= =?utf-8?q?YzSkl9dxJxw6LRHk8fvQZiOQo1ZUZ8xU6SmO6ewUthO/QXYwuVTSGTcQ+PLMqdYkZ?= =?utf-8?q?OVgXP1wafe0JULth9cpHgRDou0IyIOydi1BA1ARJc+iuz69sLKOw2uxSF8YaVybHs?= =?utf-8?q?zQzDt4+lecm2qMWM3pT8qKdHwmiOiJ9yoTEoXaDeMQFUnqAqxCGPt2HWieMNGi24Y?= =?utf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Q?= =?utf-8?q?Togu5jxENOwTBc1cw7Mmp+4GZTQTKZrQ3EkWJFbz7OUJJvaX/jo/ALrT1S1YaXfl3?= =?utf-8?q?lw0ACOMVbZjwVkPwsFfQ1+/pMU+KaQKtq2MNe5Zw9BMGkg7rlXjm8jmfxsgSSOFke?= =?utf-8?q?fPh1a+zYWWj4OvoeRpZazlIDoFBw/ryQxgX1Gvxun6Jt/sfpkSyEjqrafUtFIl3EQ?= =?utf-8?q?+k0QrVtixAsSDqqiSzzbmZUBk26RFK/3ZTkxJeXx0IKHDWRL9J+4hqRN86ZYABQYj?= =?utf-8?q?ZuPQcQav4UUyIGL8nrqhIoi/g70UU5bZ5t97Wna5868jVeSe5m3NbbeGu9mhyR9Z1?= =?utf-8?q?2sHznQsr8N71Kr+nxlWEjoPpv2VUTenKCP1Ut1GJ3Gg0b0AWad0Wji0k=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 519c698d-5aa3-4e35-579c-08dcf9c8e695 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2024 16:27:23.7961 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: pT1r3NF/laGZcn/LH6azim2vKAanO8vDhBu6aua1+1Y2g4JRsHNhc015jqKjJU5yjFuAELzRDKKERlnVcRJMwQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA1PR04MB11081 Add three registers: doorbell_bar, doorbell_addr, and doorbell_data, along with doorbell_done. Use pci_epf_alloc_doorbell() to allocate a doorbell address space. Enable the Root Complex (RC) side driver to trigger pci-epc-test's doorbell callback handler by writing doorbell_data to the mapped doorbell_bar's address space. Set doorbell_done in the doorbell callback to indicate completion. To avoid broken compatibility, add new command COMMAND_ENABLE_DOORBELL and COMMAND_DISABLE_DOORBELL. Host side need send COMMAND_ENABLE_DOORBELL to map one bar's inbound address to MSI space. the command COMMAND_DISABLE_DOORBELL to recovery original inbound address mapping. Host side new driver Host side old driver EP: new driver S F EP: old driver F F S: If EP side support MSI, 'pcitest -B' return success. If EP side doesn't support MSI, the same to 'F'. F: 'pcitest -B' return failure, other case as usual. Signed-off-by: Frank Li --- change from v3 to v4 - remove revid requirement - Add command COMMAND_ENABLE_DOORBELL and COMMAND_DISABLE_DOORBELL. - call pci_epc_set_bar() to map inbound address to MSI space only at COMMAND_ENABLE_DOORBELL. --- drivers/pci/endpoint/functions/pci-epf-test.c | 104 ++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 7c2ed6eae53ad..dcb69921497fd 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -11,12 +11,14 @@ #include #include #include +#include #include #include #include #include #include +#include #include #define IRQ_TYPE_INTX 0 @@ -29,6 +31,8 @@ #define COMMAND_READ BIT(3) #define COMMAND_WRITE BIT(4) #define COMMAND_COPY BIT(5) +#define COMMAND_ENABLE_DOORBELL BIT(6) +#define COMMAND_DISABLE_DOORBELL BIT(7) #define STATUS_READ_SUCCESS BIT(0) #define STATUS_READ_FAIL BIT(1) @@ -39,6 +43,11 @@ #define STATUS_IRQ_RAISED BIT(6) #define STATUS_SRC_ADDR_INVALID BIT(7) #define STATUS_DST_ADDR_INVALID BIT(8) +#define STATUS_DOORBELL_SUCCESS BIT(9) +#define STATUS_DOORBELL_ENABLE_SUCCESS BIT(10) +#define STATUS_DOORBELL_ENABLE_FAIL BIT(11) +#define STATUS_DOORBELL_DISABLE_SUCCESS BIT(12) +#define STATUS_DOORBELL_DISABLE_FAIL BIT(13) #define FLAG_USE_DMA BIT(0) @@ -74,6 +83,9 @@ struct pci_epf_test_reg { u32 irq_type; u32 irq_number; u32 flags; + u32 doorbell_bar; + u32 doorbell_addr; + u32 doorbell_data; } __packed; static struct pci_epf_header test_header = { @@ -630,6 +642,60 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, } } +static void pci_epf_enable_doorbell(struct pci_epf_test *epf_test, struct pci_epf_test_reg *reg) +{ + enum pci_barno bar = reg->doorbell_bar; + struct pci_epf *epf = epf_test->epf; + struct pci_epc *epc = epf->epc; + struct pci_epf_bar db_bar; + struct msi_msg *msg; + u64 doorbell_addr; + u32 align; + int ret; + + align = epf_test->epc_features->align; + align = align ? align : 128; + + if (bar < BAR_0 || bar == epf_test->test_reg_bar || !epf->db_msg) { + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + return; + } + + msg = &epf->db_msg[0].msg; + doorbell_addr = msg->address_hi; + doorbell_addr <<= 32; + doorbell_addr |= msg->address_lo; + + db_bar.phys_addr = round_down(doorbell_addr, align); + db_bar.barno = bar; + db_bar.size = epf->bar[bar].size; + db_bar.flags = epf->bar[bar].flags; + db_bar.addr = NULL; + + ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &db_bar); + if (!ret) + reg->status |= STATUS_DOORBELL_ENABLE_SUCCESS; +} + +static void pci_epf_disable_doorbell(struct pci_epf_test *epf_test, struct pci_epf_test_reg *reg) +{ + enum pci_barno bar = reg->doorbell_bar; + struct pci_epf *epf = epf_test->epf; + struct pci_epc *epc = epf->epc; + int ret; + + if (bar < BAR_0 || bar == epf_test->test_reg_bar || !epf->db_msg) { + reg->status |= STATUS_DOORBELL_DISABLE_FAIL; + return; + } + + ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &epf->bar[bar]); + if (ret) + reg->status |= STATUS_DOORBELL_DISABLE_FAIL; + else + reg->status |= STATUS_DOORBELL_DISABLE_SUCCESS; +} + static void pci_epf_test_cmd_handler(struct work_struct *work) { u32 command; @@ -676,6 +742,14 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) pci_epf_test_copy(epf_test, reg); pci_epf_test_raise_irq(epf_test, reg); break; + case COMMAND_ENABLE_DOORBELL: + pci_epf_enable_doorbell(epf_test, reg); + pci_epf_test_raise_irq(epf_test, reg); + break; + case COMMAND_DISABLE_DOORBELL: + pci_epf_disable_doorbell(epf_test, reg); + pci_epf_test_raise_irq(epf_test, reg); + break; default: dev_err(dev, "Invalid command 0x%x\n", command); break; @@ -810,11 +884,24 @@ static int pci_epf_test_link_down(struct pci_epf *epf) return 0; } +static int pci_epf_test_doorbell(struct pci_epf *epf, int index) +{ + struct pci_epf_test *epf_test = epf_get_drvdata(epf); + enum pci_barno test_reg_bar = epf_test->test_reg_bar; + struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; + + reg->status |= STATUS_DOORBELL_SUCCESS; + pci_epf_test_raise_irq(epf_test, reg); + + return 0; +} + static const struct pci_epc_event_ops pci_epf_test_event_ops = { .epc_init = pci_epf_test_epc_init, .epc_deinit = pci_epf_test_epc_deinit, .link_up = pci_epf_test_link_up, .link_down = pci_epf_test_link_down, + .doorbell = pci_epf_test_doorbell, }; static int pci_epf_test_alloc_space(struct pci_epf *epf) @@ -909,6 +996,23 @@ static int pci_epf_test_bind(struct pci_epf *epf) if (ret) return ret; + ret = pci_epf_alloc_doorbell(epf, 1); + if (!ret) { + struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; + struct msi_msg *msg = &epf->db_msg[0].msg; + u32 align = epc_features->align; + u64 doorbell_addr; + + align = align ? align : 128; + doorbell_addr = msg->address_hi; + doorbell_addr <<= 32; + doorbell_addr |= msg->address_lo; + + reg->doorbell_addr = doorbell_addr & (align - 1); + reg->doorbell_data = msg->data; + reg->doorbell_bar = pci_epc_get_next_free_bar(epc_features, test_reg_bar + 1); + } + return 0; } From patchwork Thu Oct 31 16:27:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 2004744 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.a=rsa-sha256 header.s=selector1 header.b=UJAm8Gea; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-pci+bounces-15735-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XfTwB5M4Zz1xwF for ; Fri, 1 Nov 2024 03:29:14 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 6E155284D62 for ; Thu, 31 Oct 2024 16:29:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 83FEC1BC061; Thu, 31 Oct 2024 16:27:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="UJAm8Gea" X-Original-To: linux-pci@vger.kernel.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2045.outbound.protection.outlook.com [40.107.21.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EBA4E1C9DCD; Thu, 31 Oct 2024 16:27:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.45 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730392059; cv=fail; b=td+nhlcu7XeYul0WdqgwjmnrJGRCbIFzcZ/lMTYu4MwY4UhGcN49MCqDumMPEdTJgPAKX72ziPdl8IBgFUIeehelMWGPwZypt+8I7ZiFrufSihd8037fiPC2kxtZMh+rTAWYbf74lKGDuWc2a3FgmjQFOj6NPya79GE3jEx2gCI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730392059; c=relaxed/simple; bh=i6aZ3BpLlZvTDNHNcifM1VjlyX/rs1wNUbpxzMJy3Ik=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=bqt6cyqC3XvGHLn98DRchu8zE1tmHKvkDZH0dd78GTfNNJulW5Tgsl/LJUbf9NbP2w/Mc0TXUHHHk8ZBHqMdt7omK3fP2agkD2wa7xAWLug6U9b8GjCl7tle2xJgAiRyf+V3YU2IpPOtayKOyOaEUmrnSO6EzA1OPL28IoleaMc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=UJAm8Gea; arc=fail smtp.client-ip=40.107.21.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=o98czCV4LFC+SDKgiCWv4HrYfo2UZU6FVqX+IO+cofqvXjJJJzLKdaJLwukDkxlwi/ehKv47MQEhvqHUwIK0pwUqKtskbY6UlGM+kQNttUltyKb/xPVRu64JCM+Y0/1drWq+zfXhjbDJtC+3wAt3DNxX5xWgZXBYAUHXFNwIEDzSRbepiViccBNxr07Y0SCYnlb1jQWKABmDT6R7gZK6ZAohDwvG72wHq3YPyJOjXTnnZwq4FUtCm4D6PvnMt3J/O5bnF5zapObjp+41pnLLuWDNQpEXR8fPiZLXNVcUAUheX9kfziKchXvko2M8PcHX10p/woW2NOhgLJyO4o7iOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=bdsDZcZopyzwIsuh8/N0Z3TaMLcl/E/eqRHf10fBk4A=; b=aRARyyujoXSSoHwTQch8M1SKXZrLQzi4+JoT7gXHFJqM8HlTLt9BKeDCH5NeBOy71NgUnIknzIdwUo0kpGdnC0H79IJXgD0eFnTFNSOb3IVQUI1FJl5bvPxcyFdjonF1whBgPCCr80+K28Hh57g6bUP40WTAs+q5WBS9ikWmuNF0tS5vexe9CFFlGfV7KmNKDqzHjAxStTyD20WgmTvq/pr+QAWqzcWPpjBvgd0fnkx0hqVmODCUyyeQBdFyCbYKLGX8OmRZs2aiPqqEhTH/1WG13NxhBzxVJBYWrelrdIato2TLVKZuxSZnqSirPLUWVNERnM+Mn9szJNTDPUXGlg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bdsDZcZopyzwIsuh8/N0Z3TaMLcl/E/eqRHf10fBk4A=; b=UJAm8GeaNVNtWEwcQZ+4XyKzNdNTW5sGzo+54SPaYYPyIM6eCnySMeWsWyJz7KaQ+ONg2OTwRAERUv1pyWlyxoK5bhZi/nb5Hn4T5+Hn45cVCU5ek22lBZ4Wpjj28Mzk0aJ+HgWX8tUgfAqgsHaQHNSghqsrP4F9QmG3ViIikOQA7NeDGmCzwO3Bo9IfdnmQOjXESrRhAtWbRdtth3pp/4fIoZz0kD+qIadcDwRrzcRU8hSBSYXM4S1VWSWzufBS6Hp+WuBL9+2N2t3nw4D/OYY18YDYUa0RKj1Zn4Au/2sBVwK9QcOXiUqePg83mLHPTVhIPy62en9DMDuKC2Af0Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by PA1PR04MB11081.eurprd04.prod.outlook.com (2603:10a6:102:485::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.25; Thu, 31 Oct 2024 16:27:28 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%4]) with mapi id 15.20.8093.027; Thu, 31 Oct 2024 16:27:27 +0000 From: Frank Li Date: Thu, 31 Oct 2024 12:27:03 -0400 Subject: [PATCH v4 4/5] misc: pci_endpoint_test: Add doorbell test case Message-Id: <20241031-ep-msi-v4-4-717da2d99b28@nxp.com> References: <20241031-ep-msi-v4-0-717da2d99b28@nxp.com> In-Reply-To: <20241031-ep-msi-v4-0-717da2d99b28@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, tglx@linutronix.de, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1730392028; l=5224; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=i6aZ3BpLlZvTDNHNcifM1VjlyX/rs1wNUbpxzMJy3Ik=; b=5jELuiH5oQz+YJD33m0qwKHJuSgQnlfEdt3F7+EOGKN3nfGuwoR0EzfLnaC1WJnhQTaKPi9Af HMOguLXZSh9BlWtf4mkSpwoi1/n+vsifws3EQ8W+bi5VDMNZbNbowDC X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BYAPR08CA0056.namprd08.prod.outlook.com (2603:10b6:a03:117::33) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|PA1PR04MB11081:EE_ X-MS-Office365-Filtering-Correlation-Id: ec108188-9697-44fe-ac73-08dcf9c8e8c6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|52116014|7416014|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?OlhPUSibAVbIVMakDqd2tpwj9hNeicZ?= =?utf-8?q?/I3Iel3jxglez/39aJbzkMyDR070m3GVmHWJzz0rcYEUJ0Wqo4TU7y8Q8nC4DWnxs?= =?utf-8?q?LGl8Q3pXFjxtXJBYgQN4STdHV4q6WXGBJd3912pbxa7WvSlUI3BXDaBOtSWPlkbv6?= =?utf-8?q?W2UcJNGWlCevsMvbuhMGkOP55dHNhNjZmO6MDM6MfRY+UIjouhMwD0yh+6tZ3Nd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/+869/SCpyG?= =?utf-8?q?DXQOo7Aa1ShNKgJkOKvgM3QIyGCbOLj1m60hhtOFUB/MH2D+xHr287Ex5ust5smx9?= =?utf-8?q?P0x96IrSNljCS+htekeZiJygPjUCbQLdHMooXEWOGs1GZM3i3yyWFlgCsd7wpmyna?= =?utf-8?q?WDpt3cCl9S0Z7YgzUbpIvfcX3Yu6bD3HVWepUYqmHv/6rDTDhjqbSufBEQof9X6ve?= =?utf-8?q?d2acQ8g33pHWeaICv82cg/jFuGGfckF2OUkzg97wyqq+VdaKD0gHbUso=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(52116014)(7416014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?QOpY41+m3tp5b5+xYkh50Wnq56sr?= =?utf-8?q?CrO56SFAHuH3c79gWiJmo9HiEzdEtsn6IyOszRpG08IEn0M6wXZOx/WvPoiNrWWGn?= =?utf-8?q?8+HLC7YlaQBZFjkPvV+XE4tMdSNN61YxNzp7mXIUf17T8+4uDuahFuK2cT+oZxQz+?= =?utf-8?q?DkRyr0qnySmGWyWmWlQEae6FQyXwkNWXhwUxQiy0qb5zKnGHpYDssupOiRzyhrULN?= =?utf-8?q?d6J5yWtrtmMdKxBdEUriucNL4TDvbsPltOh1UfFPL4ZRtmoFnB6nMPoRD7YNn5rq1?= =?utf-8?q?clFIjRza34k0MKmVI6aLSkA7MgR7LGSIckv0NamXnXXXq98kBrS8wE8f322ANt4AK?= =?utf-8?q?EvEblD4NzANINP0A64WmE5HxlON5VIfAU+0Ueaq2NvcuDFbYpyUioFkfY/l5HxfDL?= =?utf-8?q?UETWWh2NS3iLYKwcT8jw0+59he/Z/wdO5VRlKkkVd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QLGhGo?= =?utf-8?q?BZfdOPOgA4nESbVOvPC9lF63rSFQiHiMeipIYBuyt0yiVz4p6X1IbR7n93s5OyX64?= =?utf-8?q?u9rDzM9jq2ba/pdmimqa+UpN62G5SJUivMjyYPFerahGVbwvvhWayx2NBa/x86mwc?= =?utf-8?q?/NQPPWECpRowloD1PE+F5EY6/Ff8DgI3gB3GQ4cMDJ9rT6Ygr9HQD6pk=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ec108188-9697-44fe-ac73-08dcf9c8e8c6 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2024 16:27:27.5115 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: wEpcAi2OqKo1sim7hcv0WG/wURBMySfU4Fi+D+XPC2NRotx5hJeYfctbLmjmyjnepiJlnvVuhYXvBR5m2LuXAw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA1PR04MB11081 Add three registers: PCIE_ENDPOINT_TEST_DB_BAR, PCIE_ENDPOINT_TEST_DB_ADDR, and PCIE_ENDPOINT_TEST_DB_DATA. Trigger the doorbell by writing data from PCI_ENDPOINT_TEST_DB_DATA to the address provided by PCI_ENDPOINT_TEST_DB_ADDR and wait for endpoint feedback. Add two command to COMMAND_ENABLE_DOORBELL and COMMAND_DISABLE_DOORBELL to enable EP side's doorbell support and avoid compatible problem. Host side new driver Host side old driver EP: new driver S F EP: old driver F F S: If EP side support MSI, 'pcitest -B' return success. If EP side doesn't support MSI, the same to 'F'. F: 'pcitest -B' return failure, other case as usual. Signed-off-by: Frank Li --- change from v3 to v4 - Add COMMAND_ENABLE_DOORBELL and COMMAND_DISABLE_DOORBELL. - Remove new DID requirement. --- drivers/misc/pci_endpoint_test.c | 63 ++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/pcitest.h | 1 + 2 files changed, 64 insertions(+) diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index 3aaaf47fa4ee2..d8193626c8965 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -42,6 +42,8 @@ #define COMMAND_READ BIT(3) #define COMMAND_WRITE BIT(4) #define COMMAND_COPY BIT(5) +#define COMMAND_ENABLE_DOORBELL BIT(6) +#define COMMAND_DISABLE_DOORBELL BIT(7) #define PCI_ENDPOINT_TEST_STATUS 0x8 #define STATUS_READ_SUCCESS BIT(0) @@ -53,6 +55,11 @@ #define STATUS_IRQ_RAISED BIT(6) #define STATUS_SRC_ADDR_INVALID BIT(7) #define STATUS_DST_ADDR_INVALID BIT(8) +#define STATUS_DOORBELL_SUCCESS BIT(9) +#define STATUS_DOORBELL_ENABLE_SUCCESS BIT(10) +#define STATUS_DOORBELL_ENABLE_FAIL BIT(11) +#define STATUS_DOORBELL_DISABLE_SUCCESS BIT(12) +#define STATUS_DOORBELL_DISABLE_FAIL BIT(13) #define PCI_ENDPOINT_TEST_LOWER_SRC_ADDR 0x0c #define PCI_ENDPOINT_TEST_UPPER_SRC_ADDR 0x10 @@ -67,7 +74,12 @@ #define PCI_ENDPOINT_TEST_IRQ_NUMBER 0x28 #define PCI_ENDPOINT_TEST_FLAGS 0x2c +#define PCI_ENDPOINT_TEST_DB_BAR 0x30 +#define PCI_ENDPOINT_TEST_DB_ADDR 0x34 +#define PCI_ENDPOINT_TEST_DB_DATA 0x38 + #define FLAG_USE_DMA BIT(0) +#define FLAG_SUPPORT_DOORBELL BIT(1) #define PCI_DEVICE_ID_TI_AM654 0xb00c #define PCI_DEVICE_ID_TI_J7200 0xb00f @@ -75,6 +87,7 @@ #define PCI_DEVICE_ID_TI_J721S2 0xb013 #define PCI_DEVICE_ID_LS1088A 0x80c0 #define PCI_DEVICE_ID_IMX8 0x0808 +#define PCI_DEVICE_ID_IMX8_DB 0x080c #define is_am654_pci_dev(pdev) \ ((pdev)->device == PCI_DEVICE_ID_TI_AM654) @@ -108,6 +121,7 @@ enum pci_barno { BAR_3, BAR_4, BAR_5, + NO_BAR = -1, }; struct pci_endpoint_test { @@ -746,6 +760,52 @@ static bool pci_endpoint_test_set_irq(struct pci_endpoint_test *test, return false; } +static bool pci_endpoint_test_doorbell(struct pci_endpoint_test *test) +{ + enum pci_barno bar; + u32 data, status; + u32 addr; + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND, + COMMAND_ENABLE_DOORBELL); + + wait_for_completion_timeout(&test->irq_raised, msecs_to_jiffies(1000)); + + status = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS); + if (status & STATUS_DOORBELL_ENABLE_FAIL) + return false; + + data = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_DATA); + addr = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_ADDR); + bar = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_BAR); + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE, irq_type); + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, 1); + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_STATUS, 0); + + bar = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_BAR); + + writel(data, test->bar[bar] + addr); + + wait_for_completion_timeout(&test->irq_raised, msecs_to_jiffies(1000)); + + status = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS); + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND, + COMMAND_DISABLE_DOORBELL); + + wait_for_completion_timeout(&test->irq_raised, msecs_to_jiffies(1000)); + + status |= pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS); + + if ((status & STATUS_DOORBELL_SUCCESS) && + (status & STATUS_DOORBELL_DISABLE_SUCCESS)) + return true; + + return false; +} + static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { @@ -793,6 +853,9 @@ static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd, case PCITEST_CLEAR_IRQ: ret = pci_endpoint_test_clear_irq(test); break; + case PCITEST_DOORBELL: + ret = pci_endpoint_test_doorbell(test); + break; } ret: diff --git a/include/uapi/linux/pcitest.h b/include/uapi/linux/pcitest.h index 94b46b043b536..06d9f548b510e 100644 --- a/include/uapi/linux/pcitest.h +++ b/include/uapi/linux/pcitest.h @@ -21,6 +21,7 @@ #define PCITEST_SET_IRQTYPE _IOW('P', 0x8, int) #define PCITEST_GET_IRQTYPE _IO('P', 0x9) #define PCITEST_CLEAR_IRQ _IO('P', 0x10) +#define PCITEST_DOORBELL _IO('P', 0x11) #define PCITEST_FLAGS_USE_DMA 0x00000001 From patchwork Thu Oct 31 16:27:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 2004745 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.a=rsa-sha256 header.s=selector1 header.b=MPVfBtPv; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-pci+bounces-15736-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XfTwX2rZYz1xwF for ; Fri, 1 Nov 2024 03:29:32 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id C5DC4B211AD for ; Thu, 31 Oct 2024 16:29:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 339281C9EDD; Thu, 31 Oct 2024 16:27:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="MPVfBtPv" X-Original-To: linux-pci@vger.kernel.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2045.outbound.protection.outlook.com [40.107.21.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C92671C9EC6; Thu, 31 Oct 2024 16:27:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.45 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730392063; cv=fail; b=AIxQ6xcI3JlYLQJ8IxFwh88U0AAqf+/0OISBBfbfrbTLJG+CWZ4y7QBYJVNWRE314LpqFZNkZxAkbL5DL4UrvOQTYGzyOPoe44iJSj9GsjQHst30PtthvuS9iXU6PuPN0CUHBVQauVQQd5FPIlCn3PE3ICnnMNsP6mC1jXVG0E0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730392063; c=relaxed/simple; bh=QXAZUTo25wHxfm2hPmZ2UTgDrVKcvTZyNirR6BThLKo=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=K8w40xb2v3Yn96LLK/w44L5Cvl1WaGneav04vHlQJch+SCcjrqXSVyKsR0LqX6JpPnjIfbF97qoEpR4uvue8Gv6wYEkK1KFSZRj+xk07qWGJ19qEtn7N+bu09znMeBgYAUzBaU6T8InQLzAUdHjxK0CKAJkqNEBfwL6GoDhIrDs= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=MPVfBtPv; arc=fail smtp.client-ip=40.107.21.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=PUxCIuKqdmCDTModtyCkmeEz2bnXhTbBBsIcfio1iyA8hTZS7PPGJuXe7WMJiff6Fas17ecGSpOgypYlTHG3Srp2txVyV8MBwVI2iP47262I/ztsB3mQlzA7m8J3J6/oLmqDo/1t3K4eKtghwBK2RtMS3v0jMG44I1jof6YiTWzE6LvBwLt7VJZ+mViMilpsvrUsraDKTsVbtMakKVykFRHgFUvxQm6PvVU4xnQBRx65KQutqEV4ohQbMtRejof/37mF4tbqOWMTJpUkVm7gnDThI58VT4MtBUCcFSoSmGbapTAjW07fNLvjPBVZXCRsbcKE0xHg9XcT6FwL0J0v+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=3XsfDMu3OuLSSl5vBa2X1Qbhd1a7N+LYSe23dI9037Y=; b=PI1CHFsL3qF4WTopF3MlBfYI0/Fuz93szg/Ura9QW4JzcENEqyrjHrkbkj4XTK6Dj7JVMMqljvAmt1PzqHj9EPysH4Lkym2fPKO3BlN7FoxL7JGo6zuRzgvMD31rN1BpfUVHI7j8Iglzon4KY12CxGgW5A8V9c60WY0ZFupZ+5gdvashc+FahN3FASGAaI78dAhL6vWSKGYDR6CROOahyqyKpsfsTf6Vrw3ANdASXKXS0iwIRXV9ck4dqyvOMoOXnpstwLvWNacRMqRAmriJ/B8UfDaEflhY3VZCO7zhlgu5JD9f9Tk44480HiGqABs/oZuSh/rJ7ib6ARwr/4fFiw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3XsfDMu3OuLSSl5vBa2X1Qbhd1a7N+LYSe23dI9037Y=; b=MPVfBtPvQyXmC1OCKcgIjhxQ+3e3lZMkNCXPjTEF2gxDH1zOD/xRr7be/u0ZJAWo+GkD0ZmHJDLwrElXIsGafqYi0V+1nyWep0O8UIBPwZKW5+VKC4cEq/66S++8Qot62ivihejNAmCuUENHeZeYFU3PYvO/xh3szpkncqx4PksbdgpES4h8yiOg2YRx25YmW38GmlIoBNLALk/hn1veIULG2gMqpbJgCJn02j+Vca4mocBlyaNn9SZPJjT1NKWGgo1M9ZBPzbWtMUrxneeSaESP6edH00TN75eWW5p0UG7+JezSfeb9Wq486AxAgxuc8Pbe7ycOWESYyhHh3O5KGA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by PA1PR04MB11081.eurprd04.prod.outlook.com (2603:10a6:102:485::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.25; Thu, 31 Oct 2024 16:27:31 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%4]) with mapi id 15.20.8093.027; Thu, 31 Oct 2024 16:27:31 +0000 From: Frank Li Date: Thu, 31 Oct 2024 12:27:04 -0400 Subject: [PATCH v4 5/5] tools: PCI: Add 'B' option for test doorbell Message-Id: <20241031-ep-msi-v4-5-717da2d99b28@nxp.com> References: <20241031-ep-msi-v4-0-717da2d99b28@nxp.com> In-Reply-To: <20241031-ep-msi-v4-0-717da2d99b28@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, tglx@linutronix.de, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1730392028; l=1804; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=QXAZUTo25wHxfm2hPmZ2UTgDrVKcvTZyNirR6BThLKo=; b=BQijpRRjBWhkiRVjXCG9igHmC6uR8sz0/GFvhgRsJ8HN54IWhy9aDPakxpCM3SJFG892FIb6I iQgBv1l3WBqBuS4OdfyuX4I+xZ2jOX9dUmetDCRJ3QQKjqqe4LkrSfi X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BYAPR08CA0056.namprd08.prod.outlook.com (2603:10b6:a03:117::33) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|PA1PR04MB11081:EE_ X-MS-Office365-Filtering-Correlation-Id: 345de0ef-540f-42a2-754f-08dcf9c8eafb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|52116014|7416014|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?uRrQnHbfcka7Lvvr/gJlexPLtJrxS9p?= =?utf-8?q?gP9t+RO+hrjeGIv79T9xAbQ87jM/pEzNpyJFYbxGWo7P6uu0KVkq31JwhXdWVkF58?= =?utf-8?q?SPR5Yxg0DnAwCIprcqszn76lQiX9oltfDdiqX0g71+KQtF2gmcwLgK5efA8ySgcOb?= =?utf-8?q?zSp1jeyBzSodP9/MdBCCHEYIyc/hkgfvcXtUN7arxNsYXF2kLUILgOsmSEpj6W7Xr?= =?utf-8?q?qNXUS05PFjObZRXxr2PpTboNWitXwgHCoLMTYytKoLPtt3U1GIkO6Mg20/8hEgzg/?= =?utf-8?q?qZu2jzqPmw//qAWl34J/vWEpe9Q+MOQ29Fd38d292zucWpQy8ksPVu/cOL1mCDQYU?= =?utf-8?q?x5tM63DPjCLlkrZogeNXM4g3H1UAQzMSDK+vKmwOPoCRVikq42QbOEkzZWe8VM3bc?= =?utf-8?q?lBTgBtPS5x3F/Dz1QBUuXQlFxUiz4n0Hk6h6CPTTZYMiRkqWa/S4jT3caYZXI8dju?= =?utf-8?q?JdAXfiLnC/3rS1wulzFaX4ELJfmTbHNOJCsbwxhDRmi53NLJpWGCNBjMHiKXsMHQN?= =?utf-8?q?RJ43bTR+n0PnfDpWbp4y1twRjhKulga52mZvdfkpiSp9301vdcfX7DzHIOLKYzwsM?= =?utf-8?q?yx0tCJ4bQ3tLTavM+7ZbH5Fe3hqvasLaVlQXQmwGLHnNhive3r3/AInLlAvyoCqSR?= =?utf-8?q?2IzdlQMP5J4vc+JzPhrQ6UdFC+LN/8oxXOILYXbPspbmyDdmNh8rSJYZQ2L0Npgjb?= =?utf-8?q?u1rJApazFzDL1a7CZhFujgsUIlizfNGAcFOMsCSTyUg2A3jJMNh3/X0i1WUDr4+28?= =?utf-8?q?y72xXqUjm4jSX9XV07hYNTfrMA+3o4JjIU23P8dlSKHZb7uN7mXUIIUwxVAnBiEoU?= =?utf-8?q?CV+KtISR1vvm7xaNFZLBTNUryoWLI5r8zJ6imQ1L0TcwOHSxvanrVWMoR/gSOFNU6?= =?utf-8?q?bwrDw75/aa2xEvZBntOqKhibUYujHP3mO/AJPg6RJf3ksYDBX4ukCOYGu6mSKfTPs?= =?utf-8?q?hfvKG/7BnOzCCAyoYmc6ufdQEWH0vtrIJk9LTfNFredtjJO+z93gts8UXtzB3fF7w?= =?utf-8?q?TTq0lY1bGtUe1d8/NxO6QEmsVmWy59tZeIsk0rCRa0+4hylwfvAI//3abXQF6QEa6?= =?utf-8?q?b/XYpPm6baXeOLSx/bgXMtKXeMa9+Qm8npiRJ5d/2uEWMZ7G303Iefepg3slzSEKE?= =?utf-8?q?4JT2c0XeYxZTyd3mVO20RT6sQkeXcmmHz3PTTBRRPOxDfjg73HzIj3Uq2UDpiwstf?= =?utf-8?q?KKMrUW4pQrsUHJT+EpeqT25QJdAxXMWUJCUSWpsCDWy43ooX5VfqZaRsFvP/PXwc7?= =?utf-8?q?eiHHRlYFO8nooSA7Eld9N25jCC4rfen0jOa0lFzBZsCp+vfqJUsM1EBA=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(52116014)(7416014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 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mThimTlE41ATU5FpHbbBoeG3AxOi9hf9Ucitu8tQg5ZgeTtLlHU9g9aAATR?= =?utf-8?q?O75q/o5P37jns76ZB4upHdI+XzKfwncblB7+E7ye4MtdPK3dyk/VM/JYEhGojhY5m?= =?utf-8?q?Hiu6oweulB24bPjbez5OiWNpa9sMeWZATqKvjPIPF1hwrPOSxoAGmJjcgXr/iAIv2?= =?utf-8?q?Cl9b/JI68ZGQkrgR4jQWRV2x126It/mzyr1Zm0k/V0riDmUsTSa0ONJoUWRl1yf60?= =?utf-8?q?UsVef5DBYalb5EJMJUhcuozuvu1fZvIRtrObwjf3hm8+DIZe7cKewL6ZGs4+6ffnW?= =?utf-8?q?CCH4YWbot5ZfrFieRZMarphANxXBrYp1Wqmc3UnLmUWZTOOCJkCuRKLIgjUJbwC0q?= =?utf-8?q?ShLkTY6SFXCXY/jobjTNyWx9ScsEfmfuiqha1HitLhayBgR7tkLKhKH3o+Sc0QjCC?= =?utf-8?q?O5tH/8yat96d5pQ7zLu+fgnEiDTBKHcPEBgghl4+otJdJEzB5zLz+F3ORfCgM9qpO?= =?utf-8?q?Rx62CKwHvehYrqD26vAGxLmNZ87nYuPoMtBo60GhRQ9io9f1CRrcfFp6Gvsj7pbx/?= =?utf-8?q?Sct0iIww1r/tTkVgcWpSUWqIQJbKTtC+oSH5jawttwZnoEjjbqt6242GdctwTFvAe?= =?utf-8?q?3bLZJEdt5sXb8BNhqhN9hOD2zxvuGucUexUqz9Eyr6Q5AzTmP629csFI=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 345de0ef-540f-42a2-754f-08dcf9c8eafb X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2024 16:27:31.1832 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: oFGAb8Ivl5lUQGVialAs8G0BY+IwyQ2FWqlS3p48nGxmhyL/aYCtND+8lBvErXyt4LxDzWS0+zOdfUs2KMwlkg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA1PR04MB11081 Add doorbell test support. Signed-off-by: Frank Li --- Change from v3 to v4 - none --- tools/pci/pcitest.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/pci/pcitest.c b/tools/pci/pcitest.c index 470258009ddc2..bbe26ebbfd945 100644 --- a/tools/pci/pcitest.c +++ b/tools/pci/pcitest.c @@ -34,6 +34,7 @@ struct pci_test { bool copy; unsigned long size; bool use_dma; + bool doorbell; }; static int run_test(struct pci_test *test) @@ -147,6 +148,15 @@ static int run_test(struct pci_test *test) fprintf(stdout, "%s\n", result[ret]); } + if (test->doorbell) { + ret = ioctl(fd, PCITEST_DOORBELL, 0); + fprintf(stdout, "Ringing doorbell on the EP\t\t"); + if (ret < 0) + fprintf(stdout, "TEST FAILED\n"); + else + fprintf(stdout, "%s\n", result[ret]); + } + fflush(stdout); close(fd); return (ret < 0) ? ret : 1 - ret; /* return 0 if test succeeded */ @@ -172,7 +182,7 @@ int main(int argc, char **argv) /* set default endpoint device */ test->device = "/dev/pci-endpoint-test.0"; - while ((c = getopt(argc, argv, "D:b:m:x:i:deIlhrwcs:")) != EOF) + while ((c = getopt(argc, argv, "D:b:m:x:i:BdeIlhrwcs:")) != EOF) switch (c) { case 'D': test->device = optarg; @@ -222,6 +232,9 @@ int main(int argc, char **argv) case 'd': test->use_dma = true; continue; + case 'B': + test->doorbell = true; + continue; case 'h': default: usage: @@ -241,6 +254,7 @@ int main(int argc, char **argv) "\t-w Write buffer test\n" "\t-c Copy buffer test\n" "\t-s Size of buffer {default: 100KB}\n" + "\t-B Doorbell test\n" "\t-h Print this help message\n", argv[0]); return -EINVAL;