From patchwork Tue Oct 4 09:31:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Quan Nguyen X-Patchwork-Id: 12998056 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2C9F3C433F5 for ; Tue, 4 Oct 2022 09:33:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kCrNEqILDWD82I2MTSNDUh9PXM3r9s+Ylx+LHbkT80M=; b=3e3MGF1PS+qEhj boECXyxcQ1iOh4lyK91hJFU/OghJbnZGVbMwISUpipkJvgb9pVKoYkupmdSuclbeaAdPBOMBDZIf9 fS9xQQLUFUEHb8RiPXc0X0CKA0+JERV7PSCDsroFRdYAwyTzWesmfW3nHJsjI428BK26Gq+Z268zq Wpy1S4XK99CPZz8CJZnwgucK+JdNyjpMaEr8QkJQirmWVHUWs44uXg7Bgh2c1LlCjUZCBbfhgHQ32 zvxcl3cXGS+tdJm+WxMWND6twrrN6IWKgwrFoWWFl6DYqT4b7k4kGvrJ4cUz4pYSxc8Q7yWiIAxGC Q6jgL9N6mIArbtR/0xUA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ofeHN-0097u2-Jw; Tue, 04 Oct 2022 09:31:57 +0000 Received: from mail-dm6nam12on2139.outbound.protection.outlook.com ([40.107.243.139] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ofeH4-0097mH-2s for linux-arm-kernel@lists.infradead.org; Tue, 04 Oct 2022 09:31:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ihWO7ouOJOp6o3XTErXW76n89gZWOihUSB0UGdCGFpLTuVmnFiJ2G6jHHQt1AvxnXqydd5c+8pt/VIZ0x/2OshYgAv0/Z1s2VZa0nfjy/iU4uegcNN7K0of9HUyL65MoEFejed/LcXGAU5PpQhwxDHj/yy61x60SG9wioPnIx62UONn30rkZbtIXd8LTkSZgQ/sp5VV6Ck+t33/L5yCfsuDCmq2UCwRSaRlPq/JGNC1BXa6A9zIlnbqjGxF6od3DcsHlLQlZZLzvbcQuDx2skts8sQbXebledB3KDxGoHGH0SzcxQ7yZPaZZAiPmuRV+9ub0tgPxuLc0PvS2GCimfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=dGn/qlZZBJb2xTAyz0lLeorHHhSeyMVlbA89dilULvw=; b=e6WAnlNbl/YKiGdpgX2Ri543liwR9ljSnzE+W3qoJ+OKeFUZEnXUk2VpXQP98Z04Z5IhwwOlex7YsaAY2ZeJ5+H5vunqoqV9z+ADpwV42YeoxlfsDBJ/b7bN1JlCvTxVnWDJT/V5yw7yc/g4LcKZ/GQFKR403S9gW8BL2X796b9JNhsxyvhPuNf2YwV+LnhvJ0l6OBm61qaSaSVM6cWBTC0JldjIl1gmkLPD3D3ovvfqvRmhy0739qREEIOLIcfb4KBXEsj26wCwoqnuVQ7zRFex9sVw3CKUKvr7/Vsfv3OQD2ey2EjCvo8Vz1QLRKf4qzyTVtQo4DS0y7hEw0WlDg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dGn/qlZZBJb2xTAyz0lLeorHHhSeyMVlbA89dilULvw=; b=unbPIF6fs7QgPJDrNu/mPWrkYvpTFG7egvx8853pNa1KaUnkcGAifmUqIOrqRWb8eUHJ63obko863+23ol8oud3xw2LT7soNJbiIjgZ8OXO2to1Y/GWmaIEsRtC9tJsWhgQrk/OaVxi1xOZvlDfjFz0Xki6YKX+55mLeJKR5EWc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from SJ0PR01MB7282.prod.exchangelabs.com (2603:10b6:a03:3f2::24) by PH7PR01MB7703.prod.exchangelabs.com (2603:10b6:510:1d6::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.28; Tue, 4 Oct 2022 09:31:34 +0000 Received: from SJ0PR01MB7282.prod.exchangelabs.com ([fe80::7d50:e907:8e2e:1ff0]) by SJ0PR01MB7282.prod.exchangelabs.com ([fe80::7d50:e907:8e2e:1ff0%3]) with mapi id 15.20.5676.031; Tue, 4 Oct 2022 09:31:34 +0000 From: Quan Nguyen To: Randy Dunlap , Wolfram Sang , Corey Minyard , Rob Herring , Krzysztof Kozlowski , Brendan Higgins , Benjamin Herrenschmidt , Joel Stanley , Andrew Jeffery , openipmi-developer@lists.sourceforge.net, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, openbmc@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, Open Source Submission Cc: Phong Vo , thang@os.amperecomputing.com, Quan Nguyen Subject: [PATCH v10 1/3] ipmi: ssif_bmc: Add SSIF BMC driver Date: Tue, 4 Oct 2022 16:31:04 +0700 Message-Id: <20221004093106.1653317-2-quan@os.amperecomputing.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221004093106.1653317-1-quan@os.amperecomputing.com> References: <20221004093106.1653317-1-quan@os.amperecomputing.com> X-ClientProxiedBy: SG2P153CA0029.APCP153.PROD.OUTLOOK.COM (2603:1096:4:c7::16) To SJ0PR01MB7282.prod.exchangelabs.com (2603:10b6:a03:3f2::24) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR01MB7282:EE_|PH7PR01MB7703:EE_ X-MS-Office365-Filtering-Correlation-Id: 9711dd3d-c3c9-46ab-15d6-08daa5eb3a1a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Agh1uTkeD/1jUgbHTmrIW9AW3vopHjZhDRdbRAREyo4d+lkZXJcv5exPPGAcSscCU4ywLdhfVrOEGdvZU8Jnp7qBtQjv34zr5flcgnv5gWUWEyHGM6CDFnZHtoPVrghUJbsRp/JGRwH7NY4tE+ICq/n990sosw3e2DtKQgXXJdRrkTBZ/87ckTCD4d+OkIJEjNbV0HfCGdQiHXHHHmokc6nCU3OZ8af9GDy5qnxNPIic41/fpp4XlbyopemBM7JeGPq1Q3EEaLBFtx4vdoUVGjPG1ulk5p5NpKaeRbfmQRi2his+XHDL2uvxbfTjDP2UuikFtdPnkC0D4YNGP6Yv0spKRjJBF9NPoc0Gz3m0KMOVOqQUyFsqJUGS0Y+spgfAoINvcoP121WRJiZFuC6qvilK6NAN9ztYd2wvDETuKgsV2KjpwXl/PgT89y1SBRlsYogIPgQ2pyin8KFvPxOr5D5Qv/NjGKvBcSrXteSiVGRP5jN464yId9Hp/IStrZMnhcaiTepU+ap6FKDcLu9b0ZqDfu2nTetPc8s8tkNvxBGsWHeJBBVy/ZXPNhdzqtPbL+ZKnz1dMtYWq6SYd6gi3GGow4s4UqL+L0JDEADI2SuOaWRDvO1dTxu++bXZ1u/arjY4fM0BvIf5UrGj+HBbVbHCHhV7D7q5YFv6geFGFiVjhbPUpffOsTfnPd/V6e6FZVeqnxWC+INnv91LyWxRJht0IZQ4b1Ta1VqKtQ9oHKp+33Ei4wKmxHFZicVB3NKkjkS7YFxvUvguCW1rVgv+F1lgkNK1TNMLkDxpbNzc0bMXbTix8YeyHB+C/NFj+NeK X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR01MB7282.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(366004)(396003)(376002)(39850400004)(136003)(346002)(451199015)(1076003)(966005)(110136005)(186003)(478600001)(6486002)(6506007)(83380400001)(6666004)(107886003)(52116002)(6512007)(2906002)(5660300002)(54906003)(2616005)(38350700002)(38100700002)(4326008)(8676002)(66556008)(66476007)(26005)(66946007)(316002)(30864003)(921005)(41300700001)(7416002)(86362001)(8936002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?s5m1kkPq5Pxo+cmS8EM5BpfFQptX?= =?utf-8?q?NukWdB+OfRzTfAVpFJL0URyypImyyep2hKnZmJ/NdC4mL4zyZHcNofxmXlgmeilwY?= =?utf-8?q?k11b7Zl6vUkk0dGHz3zARPM7268Ic+f00Nza059+P4YPYzRBrp0usGeEHkAX3UjmC?= =?utf-8?q?hq5ntm4RbYz1k3PUVc8qDbpmJPBW7ScCb4E0xhzVhqPbCzWARLDu5ABjc4VN76zLJ?= =?utf-8?q?I+6jPYthzqaWcwelStzOVPL81B6hjihj1ZdYm2p8i29CgInTgqoqiIzLaTwWivf9e?= =?utf-8?q?blJlMFKyE+b/dwQgW2rkRqAnOWXxPGw96JPi8TFoK2JUoccyw5G/FZd9mCXBnonzJ?= =?utf-8?q?4XYlOiSq8FbLaoJmfZiHghdm3DB4NAuREK7f1kTfiVq9pG5jWoflu9Q/A29xoJiiV?= =?utf-8?q?8Bt+bDvIU1drZiicF03/CNes6t9v8zmwZyIBdQkCUZ7FJuSKq9t67+xL0MMfoKDQn?= =?utf-8?q?RWndpjc1Cdu7/k4U2Ku9rpvlGe2Snztnvb0lXjB6oL9U3AiZ/fvbCjC5Nke+fCw5b?= =?utf-8?q?JrJLII866bGHEP/Z9YApWsw4SCN0CEmHCCNwGtTVbAHqzMJwsLJtq20m90DMiju6/?= =?utf-8?q?DFQd54/pgKVjYrwBUdxwa/RJ/UbVgCY32xyMu742xvEezVPz2B8+fgGHRxU70OTuo?= =?utf-8?q?ydlVZZuagA+WAiT1ynp096eB1Jj4VdBc2MkzU6dOwjeA8OkdXiU0tohT+dPoe7h22?= =?utf-8?q?BJjh90S6hT8jP60s9GYJHxRu/exe6ApmnaH3mh4kws0nVscavvUzdn4oxHr5I8RRp?= =?utf-8?q?ImXzAkPhn5sFHKzTbuKLAjrBJ+rjZG2RSMkC3zYn0egLuu0F4wfAAmsUpWlWq+oj3?= =?utf-8?q?P/JU//GHgJCoSAkR6rOK5XrDafBEzXrCrPshxzRJz3qgh2CGp7t55O38t8rGblI0U?= =?utf-8?q?ZeZTjUVtYA7FM32dyY9SKzaaNidF9LgXwYlA6THe/AwthvGgJkNpevG6U+yQe/08S?= =?utf-8?q?8eiBFSeTbA7K5AvIoB3trHRtSPlONpkApKcvBLISyiwtQ+/hdz2KIy8kTVSudpa/X?= =?utf-8?q?x/ltaNLjJcf7oseaT22HIgE6ZcXJbF9Llwy3E3mJ1CFGobmSUheZOf1ByeYSNoZIu?= =?utf-8?q?GneTbGQZjfM6iLNkYP8dXlJs4g33GiKBxV1EVbwP9QhZWSuzjYCNh3fqX5k84zweG?= =?utf-8?q?3c5nsM7iQMXcTpaj/4DBJLYx9m6t9jSZXre1Wvs6gTf4mXr4IfOp9+3Z3QH5gCzGC?= =?utf-8?q?XkYgBOmEliBkB09PR1j3HDATsuAqKsZUkFp5G8Wyk48+kMRPJsFSvYdAOehkqAodD?= =?utf-8?q?8O0vIik+5NJe2i662DngUc0VX+xUN27dlRZLM5llBxxofkb+5xCLYreo/O+uCswoY?= =?utf-8?q?lUk4w/5k4mZEAAgiSkrdNOBtAJQyIKPYOgoz7VioUYITfWdJYk9xM2yhFmqTb/CWv?= =?utf-8?q?d+fnF7PK7MbYJ/RKhDRBjmr4n0AdIVxh04VMWHzFzT4PL0TYre1GZNh4i+tGcb/ww?= =?utf-8?q?aXAipmF4nik8PNNtq44y2val1NXoao3ClSXT7/T+YRxltt0BEWU9jlw1oRE3nNSnB?= =?utf-8?q?60rfi+WpZJh5JicQ038bJeY781n2RioLP50AzQF/NOoU3yk53JxMemU=3D?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9711dd3d-c3c9-46ab-15d6-08daa5eb3a1a X-MS-Exchange-CrossTenant-AuthSource: SJ0PR01MB7282.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Oct 2022 09:31:34.1563 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: fFJwrfhiWHoQ66u0m8bzl59P7tIEzL2ulmhiBBBvF0EJHE0lZoyGmEtDNB1+O/sx8iG6XGaQpYKthgR7Ck+lTdevU2Sv9vOQtCUJD5yayis= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR01MB7703 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221004_023138_233734_5A7E64A9 X-CRM114-Status: GOOD ( 18.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The SMBus system interface (SSIF) IPMI BMC driver can be used to perform in-band IPMI communication with their host in management (BMC) side. Thanks Dan for the copy_from_user() fix in the link below. Link: https://lore.kernel.org/linux-arm-kernel/20220310114119.13736-4-quan@os.amperecomputing.com/ Signed-off-by: Quan Nguyen --- v10: + None v9: + Fix dependence with I2C subsystem [Randy] + Remove useless error handling path [CJ] + Update comment for SSIF_ABORTING state [CJ] + Fix "unknown type name --u8" [kernel test robot] + Fix ssif_bmc_remove() to return void to align with recent kernel change [Quan] v8: + Dropped ssif_bmc.h file and move its content to ssif_bmc.c [Corey] + Add struct ipmi_ssif_msg to include/uapi/linux/ipmi_ssif_bmc.h header file [Corey] + Use unsigned int for len field in struct ipmi_ssif_msg [Corey] + Avoid using packed structure [Corey] + Add comment to clarify the logic flow [Corey] + Fix multipart read end with len=0 issue [Corey] + Refactor code handle the too big request message [Corey] + Fix code indentation issue [Corey] + Clean buffer before receiving request to avoid garbage [Quan] + Fix the license to SPDX-License-Identifier: GPL-2.0-only [Quan] v7: + Remove unneccessary del_timer() in response_timeout() [Corey] + Change compatible string from "ampere,ssif-bmc" to "ssif-bmc" [Jae] + Add MODULE_DEVICE_TABLE(of, ssif_bmc_match), fix blank line [Jae] + Dropped the use of ssif_msg_len() macro, use the len directly [Quan] + Solve possible issue if both response timer and ssif_bmc_write() occurred at the same time [Corey] + Fix wrong return type of ssif_bmc_poll() [kernel robot test] + Refactor and introduce ssif_part_buffer struct to replace the response_buf to manage each send/receive part of ssif [Quan] + Change SSIF_BAD_SMBUS state to SSIF_ABORTING state [Corey] + Support abort feature to skip the current bad request/response and wait until next new request [Corey] + Refactor the PEC calculation to avoid the re-calculate the PEC on each I2C_SLAVE_WRITE_RECEIVED event [Quan] + Fix the use of error-proned idx [Corey] + Defer the test for valid SMBus command until the read/write part is determined [Quan] + Change/split unsupported_smbus_cmd() to supported_[write|read]_cmd() [Corey] + Abort the request if somehow its size exceeded 255 bytes [Quan] v6: + Drop the use of slave_enable() [Wolfram] + Make i2c-aspeed to issue RxCmdLast command on all I2C_SLAVE_WRITE_REQUESTED event to assert NAK when slave busy [Quan] + Make i2c slave to return -EBUSY when it's busy [Quan] + Drop the aborting feature as return Completion Code 0xFF may stop host to retry and make ipmi_ssif.so fails to load [Quan] + Add timer to recover slave from busy state when no response [Quan] + Clean request/response buffer appropriately [Quan] + Add some minor change on error and warning messages [Quan] v5: + None v4: + Send response with Completion code 0xFF when aborting [Quan] + Added bounding check on SMBus writes and the whole request [Dan] + Moved buffer to end of struct ssif_bmc_ctx to avoid context corruption if somehow buffer is written past the end [Dan] + Return -EINVAL if userspace buffer too small, dont silence truncate [Corey, Joel] + Not necessary to check NONBLOCK in lock [Corey] + Enforce one user at a time [Joel] + Reject write with invalid response length from userspace [Corey] + Add state machines for better ssif bmc state handling [Quan] + Drop ssif_bmc_aspeed.c and make ssif_bmc.c is generic SSIF BMC driver [Quan] + Change compatible string "aspeed,ast2500-ssif-bmc" to "ampere,ssif-bmc" [Quan] + Abort current request with invalid SMBus write or invalid command [Quan] + Abort all request if there is pending response [Quan] + Changed validate_pec() to validate_request() [Quan] + Add unsupported_smbus_cmd() to handle unknown SMBus command [Quan] + Print internal state string for ease investigating issue [Quan] + Move to READY state on SLAVE_STOP event [Quan] + Change initilize_transfer() to process_smbus_cmd() [Quan] + Introduce functions for each slave event [Quan] v3: + Removed redundant license info [Joel] + Switched to use traditional if-else [Joel] + Removed unused ssif_bmc_ioctl() [Joel] + Made handle_request()/complete_response() to return void [Joel] + Refactored send_ssif_bmc_response() and receive_ssif_bmc_request() [Corey] + Removed mutex [Corey] + Use spin_lock/unlock_irqsave/restore in callback [Corey] + Removed the unnecessary memset [Corey] + Switch to use dev_err() [Corey] v2: + Fixed compiling error with COMPILE_TEST for arc --- drivers/char/ipmi/Kconfig | 10 + drivers/char/ipmi/Makefile | 1 + drivers/char/ipmi/ssif_bmc.c | 873 +++++++++++++++++++++++++++++ include/uapi/linux/ipmi_ssif_bmc.h | 18 + 4 files changed, 902 insertions(+) create mode 100644 drivers/char/ipmi/ssif_bmc.c create mode 100644 include/uapi/linux/ipmi_ssif_bmc.h diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig index 39565cf74b2c..b6c0d35fc1a5 100644 --- a/drivers/char/ipmi/Kconfig +++ b/drivers/char/ipmi/Kconfig @@ -169,6 +169,16 @@ config ASPEED_BT_IPMI_BMC found on Aspeed SOCs (AST2400 and AST2500). The driver implements the BMC side of the BT interface. +config SSIF_IPMI_BMC + tristate "SSIF IPMI BMC driver" + depends on I2C && I2C_SLAVE + help + This enables the IPMI SMBus system interface (SSIF) at the + management (BMC) side. + + The driver implements the BMC side of the SMBus system + interface (SSIF). + config IPMB_DEVICE_INTERFACE tristate 'IPMB Interface handler' depends on I2C diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile index 7ce790efad92..cb6138b8ded9 100644 --- a/drivers/char/ipmi/Makefile +++ b/drivers/char/ipmi/Makefile @@ -30,3 +30,4 @@ obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o obj-$(CONFIG_ASPEED_KCS_IPMI_BMC) += kcs_bmc_aspeed.o obj-$(CONFIG_NPCM7XX_KCS_IPMI_BMC) += kcs_bmc_npcm7xx.o obj-$(CONFIG_IPMB_DEVICE_INTERFACE) += ipmb_dev_int.o +obj-$(CONFIG_SSIF_IPMI_BMC) += ssif_bmc.o diff --git a/drivers/char/ipmi/ssif_bmc.c b/drivers/char/ipmi/ssif_bmc.c new file mode 100644 index 000000000000..a7bb4b99000e --- /dev/null +++ b/drivers/char/ipmi/ssif_bmc.c @@ -0,0 +1,873 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * The driver for BMC side of SSIF interface + * + * Copyright (c) 2022, Ampere Computing LLC + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DEVICE_NAME "ipmi-ssif-host" + +#define GET_8BIT_ADDR(addr_7bit) (((addr_7bit) << 1) & 0xff) + +/* A standard SMBus Transaction is limited to 32 data bytes */ +#define MAX_PAYLOAD_PER_TRANSACTION 32 +/* Transaction includes the address, the command, the length and the PEC byte */ +#define MAX_TRANSACTION (MAX_PAYLOAD_PER_TRANSACTION + 4) + +#define MAX_IPMI_DATA_PER_START_TRANSACTION 30 +#define MAX_IPMI_DATA_PER_MIDDLE_TRANSACTION 31 + +#define SSIF_IPMI_SINGLEPART_WRITE 0x2 +#define SSIF_IPMI_SINGLEPART_READ 0x3 +#define SSIF_IPMI_MULTIPART_WRITE_START 0x6 +#define SSIF_IPMI_MULTIPART_WRITE_MIDDLE 0x7 +#define SSIF_IPMI_MULTIPART_WRITE_END 0x8 +#define SSIF_IPMI_MULTIPART_READ_START 0x3 +#define SSIF_IPMI_MULTIPART_READ_MIDDLE 0x9 + +/* + * IPMI 2.0 Spec, section 12.7 SSIF Timing, + * Request-to-Response Time is T6max(250ms) - T1max(20ms) - 3ms = 227ms + * Recover ssif_bmc from busy state if it takes up to 500ms + */ +#define RESPONSE_TIMEOUT 500 /* ms */ + +struct ssif_part_buffer { + u8 address; + u8 smbus_cmd; + u8 length; + u8 payload[MAX_PAYLOAD_PER_TRANSACTION]; + u8 pec; + u8 index; +}; + +/* + * SSIF internal states: + * SSIF_READY 0x00 : Ready state + * SSIF_START 0x01 : Start smbus transaction + * SSIF_SMBUS_CMD 0x02 : Received SMBus command + * SSIF_REQ_RECVING 0x03 : Receiving request + * SSIF_RES_SENDING 0x04 : Sending response + * SSIF_ABORTING 0x05 : Aborting state + */ +enum ssif_state { + SSIF_READY, + SSIF_START, + SSIF_SMBUS_CMD, + SSIF_REQ_RECVING, + SSIF_RES_SENDING, + SSIF_ABORTING, + SSIF_STATE_MAX +}; + +struct ssif_bmc_ctx { + struct i2c_client *client; + struct miscdevice miscdev; + int msg_idx; + bool pec_support; + /* ssif bmc spinlock */ + spinlock_t lock; + wait_queue_head_t wait_queue; + u8 running; + enum ssif_state state; + /* Timeout waiting for response */ + struct timer_list response_timer; + bool response_timer_inited; + /* Flag to identify a Multi-part Read Transaction */ + bool is_singlepart_read; + u8 nbytes_processed; + u8 remain_len; + u8 recv_len; + /* Block Number of a Multi-part Read Transaction */ + u8 block_num; + bool request_available; + bool response_in_progress; + bool busy; + bool aborting; + /* Buffer for SSIF Transaction part*/ + struct ssif_part_buffer part_buf; + struct ipmi_ssif_msg response; + struct ipmi_ssif_msg request; +}; + +static inline struct ssif_bmc_ctx *to_ssif_bmc(struct file *file) +{ + return container_of(file->private_data, struct ssif_bmc_ctx, miscdev); +} + +static const char *state_to_string(enum ssif_state state) +{ + switch (state) { + case SSIF_READY: + return "SSIF_READY"; + case SSIF_START: + return "SSIF_START"; + case SSIF_SMBUS_CMD: + return "SSIF_SMBUS_CMD"; + case SSIF_REQ_RECVING: + return "SSIF_REQ_RECVING"; + case SSIF_RES_SENDING: + return "SSIF_RES_SENDING"; + case SSIF_ABORTING: + return "SSIF_ABORTING"; + default: + return "SSIF_STATE_UNKNOWN"; + } +} + +/* Handle SSIF message that will be sent to user */ +static ssize_t ssif_bmc_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) +{ + struct ssif_bmc_ctx *ssif_bmc = to_ssif_bmc(file); + struct ipmi_ssif_msg msg; + unsigned long flags; + ssize_t ret; + + spin_lock_irqsave(&ssif_bmc->lock, flags); + while (!ssif_bmc->request_available) { + spin_unlock_irqrestore(&ssif_bmc->lock, flags); + if (file->f_flags & O_NONBLOCK) + return -EAGAIN; + ret = wait_event_interruptible(ssif_bmc->wait_queue, + ssif_bmc->request_available); + if (ret) + return ret; + spin_lock_irqsave(&ssif_bmc->lock, flags); + } + + if (count < min_t(ssize_t, + sizeof_field(struct ipmi_ssif_msg, len) + ssif_bmc->request.len, + sizeof(struct ipmi_ssif_msg))) { + spin_unlock_irqrestore(&ssif_bmc->lock, flags); + ret = -EINVAL; + } else { + count = min_t(ssize_t, + sizeof_field(struct ipmi_ssif_msg, len) + ssif_bmc->request.len, + sizeof(struct ipmi_ssif_msg)); + memcpy(&msg, &ssif_bmc->request, count); + ssif_bmc->request_available = false; + spin_unlock_irqrestore(&ssif_bmc->lock, flags); + + ret = copy_to_user(buf, &msg, count); + } + + return (ret < 0) ? ret : count; +} + +/* Handle SSIF message that is written by user */ +static ssize_t ssif_bmc_write(struct file *file, const char __user *buf, size_t count, + loff_t *ppos) +{ + struct ssif_bmc_ctx *ssif_bmc = to_ssif_bmc(file); + struct ipmi_ssif_msg msg; + unsigned long flags; + ssize_t ret; + + if (count > sizeof(struct ipmi_ssif_msg)) + return -EINVAL; + + if (copy_from_user(&msg, buf, count)) + return -EFAULT; + + if (!msg.len || count < sizeof_field(struct ipmi_ssif_msg, len) + msg.len) + return -EINVAL; + + spin_lock_irqsave(&ssif_bmc->lock, flags); + while (ssif_bmc->response_in_progress) { + spin_unlock_irqrestore(&ssif_bmc->lock, flags); + if (file->f_flags & O_NONBLOCK) + return -EAGAIN; + ret = wait_event_interruptible(ssif_bmc->wait_queue, + !ssif_bmc->response_in_progress); + if (ret) + return ret; + spin_lock_irqsave(&ssif_bmc->lock, flags); + } + + /* + * The write must complete before the response timeout fired, otherwise + * the response is aborted and wait for next request + * Return -EINVAL if the response is aborted + */ + ret = (ssif_bmc->response_timer_inited) ? 0 : -EINVAL; + if (ret) + goto exit; + + del_timer(&ssif_bmc->response_timer); + ssif_bmc->response_timer_inited = false; + + memcpy(&ssif_bmc->response, &msg, count); + ssif_bmc->is_singlepart_read = (msg.len <= MAX_PAYLOAD_PER_TRANSACTION); + + ssif_bmc->response_in_progress = true; + + /* ssif_bmc not busy */ + ssif_bmc->busy = false; + + /* Clean old request buffer */ + memset(&ssif_bmc->request, 0, sizeof(struct ipmi_ssif_msg)); +exit: + spin_unlock_irqrestore(&ssif_bmc->lock, flags); + + return (ret < 0) ? ret : count; +} + +static int ssif_bmc_open(struct inode *inode, struct file *file) +{ + struct ssif_bmc_ctx *ssif_bmc = to_ssif_bmc(file); + int ret = 0; + + spin_lock_irq(&ssif_bmc->lock); + if (!ssif_bmc->running) + ssif_bmc->running = 1; + else + ret = -EBUSY; + spin_unlock_irq(&ssif_bmc->lock); + + return ret; +} + +static __poll_t ssif_bmc_poll(struct file *file, poll_table *wait) +{ + struct ssif_bmc_ctx *ssif_bmc = to_ssif_bmc(file); + __poll_t mask = 0; + + poll_wait(file, &ssif_bmc->wait_queue, wait); + + spin_lock_irq(&ssif_bmc->lock); + /* The request is available, userspace application can get the request */ + if (ssif_bmc->request_available) + mask |= POLLIN; + + spin_unlock_irq(&ssif_bmc->lock); + + return mask; +} + +static int ssif_bmc_release(struct inode *inode, struct file *file) +{ + struct ssif_bmc_ctx *ssif_bmc = to_ssif_bmc(file); + + spin_lock_irq(&ssif_bmc->lock); + ssif_bmc->running = 0; + spin_unlock_irq(&ssif_bmc->lock); + + return 0; +} + +/* + * System calls to device interface for user apps + */ +static const struct file_operations ssif_bmc_fops = { + .owner = THIS_MODULE, + .open = ssif_bmc_open, + .read = ssif_bmc_read, + .write = ssif_bmc_write, + .release = ssif_bmc_release, + .poll = ssif_bmc_poll, +}; + +/* Called with ssif_bmc->lock held. */ +static void complete_response(struct ssif_bmc_ctx *ssif_bmc) +{ + /* Invalidate response in buffer to denote it having been sent. */ + ssif_bmc->response.len = 0; + ssif_bmc->response_in_progress = false; + ssif_bmc->nbytes_processed = 0; + ssif_bmc->remain_len = 0; + ssif_bmc->busy = false; + memset(&ssif_bmc->part_buf, 0, sizeof(struct ssif_part_buffer)); + wake_up_all(&ssif_bmc->wait_queue); +} + +static void response_timeout(struct timer_list *t) +{ + struct ssif_bmc_ctx *ssif_bmc = from_timer(ssif_bmc, t, response_timer); + unsigned long flags; + + spin_lock_irqsave(&ssif_bmc->lock, flags); + + /* Do nothing if the response is in progress */ + if (!ssif_bmc->response_in_progress) { + /* Recover ssif_bmc from busy */ + ssif_bmc->busy = false; + ssif_bmc->response_timer_inited = false; + /* Set aborting flag */ + ssif_bmc->aborting = true; + } + + spin_unlock_irqrestore(&ssif_bmc->lock, flags); +} + +/* Called with ssif_bmc->lock held. */ +static void handle_request(struct ssif_bmc_ctx *ssif_bmc) +{ + /* set ssif_bmc to busy waiting for response */ + ssif_bmc->busy = true; + /* Request message is available to process */ + ssif_bmc->request_available = true; + /* Clean old response buffer */ + memset(&ssif_bmc->response, 0, sizeof(struct ipmi_ssif_msg)); + /* This is the new READ request.*/ + wake_up_all(&ssif_bmc->wait_queue); + + /* Armed timer to recover slave from busy state in case of no response */ + if (!ssif_bmc->response_timer_inited) { + timer_setup(&ssif_bmc->response_timer, response_timeout, 0); + ssif_bmc->response_timer_inited = true; + } + mod_timer(&ssif_bmc->response_timer, jiffies + msecs_to_jiffies(RESPONSE_TIMEOUT)); +} + +static void calculate_response_part_pec(struct ssif_part_buffer *part) +{ + u8 addr = part->address; + + /* PEC - Start Read Address */ + part->pec = i2c_smbus_pec(0, &addr, 1); + /* PEC - SSIF Command */ + part->pec = i2c_smbus_pec(part->pec, &part->smbus_cmd, 1); + /* PEC - Restart Write Address */ + addr = addr | 0x01; + part->pec = i2c_smbus_pec(part->pec, &addr, 1); + part->pec = i2c_smbus_pec(part->pec, &part->length, 1); + if (part->length) + part->pec = i2c_smbus_pec(part->pec, part->payload, part->length); +} + +static void set_singlepart_response_buffer(struct ssif_bmc_ctx *ssif_bmc) +{ + struct ssif_part_buffer *part = &ssif_bmc->part_buf; + + part->address = GET_8BIT_ADDR(ssif_bmc->client->addr); + part->length = (u8)ssif_bmc->response.len; + + /* Clear the rest to 0 */ + memset(part->payload + part->length, 0, MAX_PAYLOAD_PER_TRANSACTION - part->length); + memcpy(&part->payload[0], &ssif_bmc->response.payload[0], part->length); +} + +static void set_multipart_response_buffer(struct ssif_bmc_ctx *ssif_bmc) +{ + struct ssif_part_buffer *part = &ssif_bmc->part_buf; + u8 part_len = 0; + + part->address = GET_8BIT_ADDR(ssif_bmc->client->addr); + switch (part->smbus_cmd) { + case SSIF_IPMI_MULTIPART_READ_START: + /* + * Read Start length is 32 bytes. + * Read Start transfer first 30 bytes of IPMI response + * and 2 special code 0x00, 0x01. + */ + ssif_bmc->nbytes_processed = 0; + ssif_bmc->block_num = 0; + part->length = MAX_PAYLOAD_PER_TRANSACTION; + part_len = MAX_IPMI_DATA_PER_START_TRANSACTION; + ssif_bmc->remain_len = ssif_bmc->response.len - part_len; + + part->payload[0] = 0x00; /* Start Flag */ + part->payload[1] = 0x01; /* Start Flag */ + + memcpy(&part->payload[2], &ssif_bmc->response.payload[0], part_len); + break; + + case SSIF_IPMI_MULTIPART_READ_MIDDLE: + /* + * IPMI READ Middle or READ End messages can carry up to 31 bytes + * IPMI data plus block number byte. + */ + if (ssif_bmc->remain_len <= MAX_IPMI_DATA_PER_MIDDLE_TRANSACTION) { + /* + * This is READ End message + * Return length is the remaining response data length + * plus block number + * Block number 0xFF is to indicate this is last message + * + */ + /* Clean the buffer */ + memset(&part->payload[0], 0, MAX_PAYLOAD_PER_TRANSACTION); + part->length = ssif_bmc->remain_len + 1; + part_len = ssif_bmc->remain_len; + ssif_bmc->block_num = 0xFF; + part->payload[0] = ssif_bmc->block_num; + } else { + /* + * This is READ Middle message + * Response length is the maximum SMBUS transfer length + * Block number byte is incremented + * Return length is maximum SMBUS transfer length + */ + part->length = MAX_PAYLOAD_PER_TRANSACTION; + part_len = MAX_IPMI_DATA_PER_MIDDLE_TRANSACTION; + part->payload[0] = ssif_bmc->block_num; + ssif_bmc->block_num++; + } + + ssif_bmc->remain_len -= part_len; + memcpy(&part->payload[1], ssif_bmc->response.payload + ssif_bmc->nbytes_processed, + part_len); + break; + + default: + /* Do not expect to go to this case */ + dev_err(&ssif_bmc->client->dev, "%s: Unexpected SMBus command 0x%x\n", + __func__, part->smbus_cmd); + break; + } + + ssif_bmc->nbytes_processed += part_len; +} + +static bool supported_read_cmd(u8 cmd) +{ + if (cmd == SSIF_IPMI_SINGLEPART_READ || + cmd == SSIF_IPMI_MULTIPART_READ_START || + cmd == SSIF_IPMI_MULTIPART_READ_MIDDLE) + return true; + + return false; +} + +static bool supported_write_cmd(u8 cmd) +{ + if (cmd == SSIF_IPMI_SINGLEPART_WRITE || + cmd == SSIF_IPMI_MULTIPART_WRITE_START || + cmd == SSIF_IPMI_MULTIPART_WRITE_MIDDLE || + cmd == SSIF_IPMI_MULTIPART_WRITE_END) + return true; + + return false; +} + +/* Process the IPMI response that will be read by master */ +static void handle_read_processed(struct ssif_bmc_ctx *ssif_bmc, u8 *val) +{ + struct ssif_part_buffer *part = &ssif_bmc->part_buf; + + /* msg_idx start from 0 */ + if (part->index < part->length) + *val = part->payload[part->index]; + else if (part->index == part->length && ssif_bmc->pec_support) + *val = part->pec; + else + *val = 0; + + part->index++; +} + +static void handle_write_received(struct ssif_bmc_ctx *ssif_bmc, u8 *val) +{ + /* + * The msg_idx must be 1 when first enter SSIF_REQ_RECVING state + * And it would never exceeded 36 bytes included the 32 bytes max payload + + * the address + the command + the len and the PEC. + */ + if (ssif_bmc->msg_idx < 1 || ssif_bmc->msg_idx > MAX_TRANSACTION) + return; + + if (ssif_bmc->msg_idx == 1) { + ssif_bmc->part_buf.length = *val; + ssif_bmc->part_buf.index = 0; + } else { + ssif_bmc->part_buf.payload[ssif_bmc->part_buf.index++] = *val; + } + + ssif_bmc->msg_idx++; +} + +static bool validate_request_part(struct ssif_bmc_ctx *ssif_bmc) +{ + struct ssif_part_buffer *part = &ssif_bmc->part_buf; + bool ret = true; + u8 cpec; + u8 addr; + + if (part->index == part->length) { + /* PEC is not included */ + ssif_bmc->pec_support = false; + ret = true; + goto exit; + } + + if (part->index != part->length + 1) { + ret = false; + goto exit; + } + + /* PEC is included */ + ssif_bmc->pec_support = true; + part->pec = part->payload[part->length]; + addr = GET_8BIT_ADDR(ssif_bmc->client->addr); + cpec = i2c_smbus_pec(0, &addr, 1); + cpec = i2c_smbus_pec(cpec, &part->smbus_cmd, 1); + cpec = i2c_smbus_pec(cpec, &part->length, 1); + /* + * As SMBus specification does not allow the length + * (byte count) in the Write-Block protocol to be zero. + * Therefore, it is illegal to have the last Middle + * transaction in the sequence carry 32-byte and have + * a length of ‘0’ in the End transaction. + * But some users may try to use this way and we should + * prevent ssif_bmc driver broken in this case. + */ + if (part->length) + cpec = i2c_smbus_pec(cpec, part->payload, part->length); + + if (cpec != part->pec) + ret = false; + +exit: + return ret; +} + +static void process_request_part(struct ssif_bmc_ctx *ssif_bmc) +{ + struct ssif_part_buffer *part = &ssif_bmc->part_buf; + unsigned int len; + + switch (part->smbus_cmd) { + case SSIF_IPMI_SINGLEPART_WRITE: + /* save the whole part to request*/ + ssif_bmc->request.len = part->length; + memcpy(ssif_bmc->request.payload, part->payload, part->length); + + break; + case SSIF_IPMI_MULTIPART_WRITE_START: + ssif_bmc->request.len = 0; + + fallthrough; + case SSIF_IPMI_MULTIPART_WRITE_MIDDLE: + case SSIF_IPMI_MULTIPART_WRITE_END: + len = ssif_bmc->request.len + part->length; + /* Do the bound check here, not allow the request len exceed 254 bytes */ + if (len > IPMI_SSIF_PAYLOAD_MAX) { + dev_warn(&ssif_bmc->client->dev, + "Warn: Request exceeded 254 bytes, aborting"); + /* Request too long, aborting */ + ssif_bmc->aborting = true; + } else { + memcpy(ssif_bmc->request.payload + ssif_bmc->request.len, + part->payload, part->length); + ssif_bmc->request.len += part->length; + } + break; + default: + /* Do not expect to go to this case */ + dev_err(&ssif_bmc->client->dev, "%s: Unexpected SMBus command 0x%x\n", + __func__, part->smbus_cmd); + break; + } +} + +static void process_smbus_cmd(struct ssif_bmc_ctx *ssif_bmc, u8 *val) +{ + /* SMBUS command can vary (single or multi-part) */ + ssif_bmc->part_buf.smbus_cmd = *val; + ssif_bmc->msg_idx = 1; + memset(&ssif_bmc->part_buf.payload[0], 0, MAX_PAYLOAD_PER_TRANSACTION); + + if (*val == SSIF_IPMI_SINGLEPART_WRITE || *val == SSIF_IPMI_MULTIPART_WRITE_START) { + /* + * The response maybe not come in-time, causing host SSIF driver + * to timeout and resend a new request. In such case check for + * pending response and clear it + */ + if (ssif_bmc->response_in_progress) + complete_response(ssif_bmc); + + /* This is new request, flip aborting flag if set */ + if (ssif_bmc->aborting) + ssif_bmc->aborting = false; + } +} + +static void on_read_requested_event(struct ssif_bmc_ctx *ssif_bmc, u8 *val) +{ + if (ssif_bmc->state == SSIF_READY || + ssif_bmc->state == SSIF_START || + ssif_bmc->state == SSIF_REQ_RECVING || + ssif_bmc->state == SSIF_RES_SENDING) { + dev_warn(&ssif_bmc->client->dev, + "Warn: %s unexpected READ REQUESTED in state=%s\n", + __func__, state_to_string(ssif_bmc->state)); + ssif_bmc->state = SSIF_ABORTING; + *val = 0; + return; + + } else if (ssif_bmc->state == SSIF_SMBUS_CMD) { + if (!supported_read_cmd(ssif_bmc->part_buf.smbus_cmd)) { + dev_warn(&ssif_bmc->client->dev, "Warn: Unknown SMBus read command=0x%x", + ssif_bmc->part_buf.smbus_cmd); + ssif_bmc->aborting = true; + } + + if (ssif_bmc->aborting) + ssif_bmc->state = SSIF_ABORTING; + else + ssif_bmc->state = SSIF_RES_SENDING; + } + + ssif_bmc->msg_idx = 0; + + /* Send 0 if there is nothing to send */ + if (!ssif_bmc->response_in_progress || ssif_bmc->state == SSIF_ABORTING) { + *val = 0; + return; + } + + if (ssif_bmc->is_singlepart_read) + set_singlepart_response_buffer(ssif_bmc); + else + set_multipart_response_buffer(ssif_bmc); + + calculate_response_part_pec(&ssif_bmc->part_buf); + ssif_bmc->part_buf.index = 0; + *val = ssif_bmc->part_buf.length; +} + +static void on_read_processed_event(struct ssif_bmc_ctx *ssif_bmc, u8 *val) +{ + if (ssif_bmc->state == SSIF_READY || + ssif_bmc->state == SSIF_START || + ssif_bmc->state == SSIF_REQ_RECVING || + ssif_bmc->state == SSIF_SMBUS_CMD) { + dev_warn(&ssif_bmc->client->dev, + "Warn: %s unexpected READ PROCESSED in state=%s\n", + __func__, state_to_string(ssif_bmc->state)); + ssif_bmc->state = SSIF_ABORTING; + *val = 0; + return; + } + + /* Send 0 if there is nothing to send */ + if (!ssif_bmc->response_in_progress || ssif_bmc->state == SSIF_ABORTING) { + *val = 0; + return; + } + + handle_read_processed(ssif_bmc, val); +} + +static void on_write_requested_event(struct ssif_bmc_ctx *ssif_bmc, u8 *val) +{ + if (ssif_bmc->state == SSIF_READY || ssif_bmc->state == SSIF_SMBUS_CMD) { + ssif_bmc->state = SSIF_START; + + } else if (ssif_bmc->state == SSIF_START || + ssif_bmc->state == SSIF_REQ_RECVING || + ssif_bmc->state == SSIF_RES_SENDING) { + dev_warn(&ssif_bmc->client->dev, + "Warn: %s unexpected WRITE REQUEST in state=%s\n", + __func__, state_to_string(ssif_bmc->state)); + ssif_bmc->state = SSIF_ABORTING; + return; + } + + ssif_bmc->msg_idx = 0; + ssif_bmc->part_buf.address = *val; +} + +static void on_write_received_event(struct ssif_bmc_ctx *ssif_bmc, u8 *val) +{ + if (ssif_bmc->state == SSIF_READY || + ssif_bmc->state == SSIF_RES_SENDING) { + dev_warn(&ssif_bmc->client->dev, + "Warn: %s unexpected WRITE RECEIVED in state=%s\n", + __func__, state_to_string(ssif_bmc->state)); + ssif_bmc->state = SSIF_ABORTING; + + } else if (ssif_bmc->state == SSIF_START) { + ssif_bmc->state = SSIF_SMBUS_CMD; + + } else if (ssif_bmc->state == SSIF_SMBUS_CMD) { + if (!supported_write_cmd(ssif_bmc->part_buf.smbus_cmd)) { + dev_warn(&ssif_bmc->client->dev, "Warn: Unknown SMBus write command=0x%x", + ssif_bmc->part_buf.smbus_cmd); + ssif_bmc->aborting = true; + } + + if (ssif_bmc->aborting) + ssif_bmc->state = SSIF_ABORTING; + else + ssif_bmc->state = SSIF_REQ_RECVING; + } + + /* This is response sending state */ + if (ssif_bmc->state == SSIF_REQ_RECVING) + handle_write_received(ssif_bmc, val); + else if (ssif_bmc->state == SSIF_SMBUS_CMD) + process_smbus_cmd(ssif_bmc, val); +} + +static void on_stop_event(struct ssif_bmc_ctx *ssif_bmc, u8 *val) +{ + if (ssif_bmc->state == SSIF_READY || + ssif_bmc->state == SSIF_START || + ssif_bmc->state == SSIF_SMBUS_CMD || + ssif_bmc->state == SSIF_ABORTING) { + dev_warn(&ssif_bmc->client->dev, + "Warn: %s unexpected SLAVE STOP in state=%s\n", + __func__, state_to_string(ssif_bmc->state)); + ssif_bmc->state = SSIF_READY; + + } else if (ssif_bmc->state == SSIF_REQ_RECVING) { + if (validate_request_part(ssif_bmc)) { + process_request_part(ssif_bmc); + if (ssif_bmc->part_buf.smbus_cmd == SSIF_IPMI_SINGLEPART_WRITE || + ssif_bmc->part_buf.smbus_cmd == SSIF_IPMI_MULTIPART_WRITE_END) + handle_request(ssif_bmc); + ssif_bmc->state = SSIF_READY; + } else { + /* + * A BMC that receives an invalid request drop the data for the write + * transaction and any further transactions (read or write) until + * the next valid read or write Start transaction is received + */ + dev_err(&ssif_bmc->client->dev, "Error: invalid pec\n"); + ssif_bmc->aborting = true; + } + } else if (ssif_bmc->state == SSIF_RES_SENDING) { + if (ssif_bmc->is_singlepart_read || ssif_bmc->block_num == 0xFF) + /* Invalidate response buffer to denote it is sent */ + complete_response(ssif_bmc); + ssif_bmc->state = SSIF_READY; + } + + /* Reset message index */ + ssif_bmc->msg_idx = 0; +} + +/* + * Callback function to handle I2C slave events + */ +static int ssif_bmc_cb(struct i2c_client *client, enum i2c_slave_event event, u8 *val) +{ + unsigned long flags; + struct ssif_bmc_ctx *ssif_bmc = i2c_get_clientdata(client); + int ret = 0; + + spin_lock_irqsave(&ssif_bmc->lock, flags); + + switch (event) { + case I2C_SLAVE_READ_REQUESTED: + on_read_requested_event(ssif_bmc, val); + break; + + case I2C_SLAVE_WRITE_REQUESTED: + on_write_requested_event(ssif_bmc, val); + break; + + case I2C_SLAVE_READ_PROCESSED: + on_read_processed_event(ssif_bmc, val); + break; + + case I2C_SLAVE_WRITE_RECEIVED: + on_write_received_event(ssif_bmc, val); + break; + + case I2C_SLAVE_STOP: + on_stop_event(ssif_bmc, val); + break; + + default: + dev_warn(&ssif_bmc->client->dev, "Warn: Unknown i2c slave event\n"); + break; + } + + if (!ssif_bmc->aborting && ssif_bmc->busy) + ret = -EBUSY; + + spin_unlock_irqrestore(&ssif_bmc->lock, flags); + + return ret; +} + +static int ssif_bmc_probe(struct i2c_client *client, const struct i2c_device_id *id) +{ + struct ssif_bmc_ctx *ssif_bmc; + int ret; + + ssif_bmc = devm_kzalloc(&client->dev, sizeof(*ssif_bmc), GFP_KERNEL); + if (!ssif_bmc) + return -ENOMEM; + + spin_lock_init(&ssif_bmc->lock); + + init_waitqueue_head(&ssif_bmc->wait_queue); + ssif_bmc->request_available = false; + ssif_bmc->response_in_progress = false; + ssif_bmc->busy = false; + ssif_bmc->response_timer_inited = false; + + /* Register misc device interface */ + ssif_bmc->miscdev.minor = MISC_DYNAMIC_MINOR; + ssif_bmc->miscdev.name = DEVICE_NAME; + ssif_bmc->miscdev.fops = &ssif_bmc_fops; + ssif_bmc->miscdev.parent = &client->dev; + ret = misc_register(&ssif_bmc->miscdev); + if (ret) + return ret; + + ssif_bmc->client = client; + ssif_bmc->client->flags |= I2C_CLIENT_SLAVE; + + /* Register I2C slave */ + i2c_set_clientdata(client, ssif_bmc); + ret = i2c_slave_register(client, ssif_bmc_cb); + if (ret) + misc_deregister(&ssif_bmc->miscdev); + + return ret; +} + +static void ssif_bmc_remove(struct i2c_client *client) +{ + struct ssif_bmc_ctx *ssif_bmc = i2c_get_clientdata(client); + + i2c_slave_unregister(client); + misc_deregister(&ssif_bmc->miscdev); +} + +static const struct of_device_id ssif_bmc_match[] = { + { .compatible = "ssif-bmc" }, + { }, +}; +MODULE_DEVICE_TABLE(of, ssif_bmc_match); + +static const struct i2c_device_id ssif_bmc_id[] = { + { DEVICE_NAME, 0 }, + { }, +}; +MODULE_DEVICE_TABLE(i2c, ssif_bmc_id); + +static struct i2c_driver ssif_bmc_driver = { + .driver = { + .name = DEVICE_NAME, + .of_match_table = ssif_bmc_match, + }, + .probe = ssif_bmc_probe, + .remove = ssif_bmc_remove, + .id_table = ssif_bmc_id, +}; + +module_i2c_driver(ssif_bmc_driver); + +MODULE_AUTHOR("Quan Nguyen "); +MODULE_AUTHOR("Chuong Tran "); +MODULE_DESCRIPTION("Linux device driver of the BMC IPMI SSIF interface."); +MODULE_LICENSE("GPL"); diff --git a/include/uapi/linux/ipmi_ssif_bmc.h b/include/uapi/linux/ipmi_ssif_bmc.h new file mode 100644 index 000000000000..1c6a753dad08 --- /dev/null +++ b/include/uapi/linux/ipmi_ssif_bmc.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note*/ +/* + * Copyright (c) 2022, Ampere Computing LLC. + */ + +#ifndef _UAPI_LINUX_IPMI_SSIF_BMC_H +#define _UAPI_LINUX_IPMI_SSIF_BMC_H + +#include + +/* Max length of ipmi ssif message included netfn and cmd field */ +#define IPMI_SSIF_PAYLOAD_MAX 254 +struct ipmi_ssif_msg { + unsigned int len; + __u8 payload[IPMI_SSIF_PAYLOAD_MAX]; +}; + +#endif /* _UAPI_LINUX_IPMI_SSIF_BMC_H */ From patchwork Tue Oct 4 09:31:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quan Nguyen X-Patchwork-Id: 12998055 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F3748C433FE for ; Tue, 4 Oct 2022 09:33:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=GJTejw2ZLmwqBMWr8JP1Yu9wSIwMiNRK6LqEL3lhKxk=; b=bddzmFRoPFqdOz EzqEGPkBSjZSUrnPDZE5+RPoQ0KwXbgnbrqHnVLFdJJm/xCefJ5tJ5vYtY8uLVInMTgwdbVIXi6Iz iSZpUIp4AVyFJsDmLklktAYdbLf0FkNbA7gqz95IAaIh3YqCzxdpChLq9pdf3WqaGWTUx5zLMZIHz qG+CE8glLWdtw4J+0tDS/kGKFgYBg7AwnpuQRK+gnRvBupFbCzD0Hc/WxHD4VaAwl7vpOhnW45BEH /uQP9gLBzRWhxlL7X3wVx7F7YIoM5ShL0cTkMi0LG2Rwu2rzfGz2M8qfHPn92/QSqjwKUFYGovy3H JZmemF4CZKBQ8oSX91GA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ofeHX-0097w6-F6; Tue, 04 Oct 2022 09:32:07 +0000 Received: from mail-dm6nam12on2139.outbound.protection.outlook.com ([40.107.243.139] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ofeH9-0097mH-Mk for linux-arm-kernel@lists.infradead.org; Tue, 04 Oct 2022 09:31:46 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ggtOuspWmbsYq67riWFIiTTafctsw/gNhiX7hpbCMp6kp79gestLQ6uSmOElmJtpjpbRh4mrTJnb8wXWsz1RLhyV55+Kv292PEJvw0Tg4JPVejrN51L7YL79+n+lOyY1gWgR8I578nU4hiCeHtjKfmq0AaopNSccffyMenUZ5TA+UuG1+Mw28R2fdeeu583JLVv9ibQVPUOpCwzOQiwp6CftxnaPcOOT8pCk+rUhK3Pnu5jkHwFSnGOutdnYQ6XWTeJL8fI7c1qc2+TuUtJdv0jC2ZnPrXG9cK015seZ1Pg0CtMU/KdmCIwrYHDj4NSkY424hnH3ZQSuag96KnO+ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=3TUMvTNE7ZOA26Snq3JCd6YliAo5iu1MMM78QQ4h3Rk=; b=B/pigH2OA7VZTH1UJFf6Lkiqqx1sx0woruO1GAx5hMiqFq5B9vcTo3mHWsD9EnBaqzAvNClCOX9VPk1C+fHStMPggyu/y7rhKEUC1o16XA7MRU/ohzSAypVQ13ld9gG5Im9j5vmwFnjwztf/M1qEjeVlbA/e7Tc/oWCgSztvNCiFAGriI8ND+HLwbNrfMhA1x0aOrYyAbWHBBDBl2rKADGYvsIVEoK7dEArRNQr48EMRPkGd921uTd636RY2SCgCvTGOjyui0dSVZmmIRvpd45DPU9X4PSg498713OREYP7dQH5o3/p31qj2k8tjxF6AKGLBGaQsdEyngvm3Txpu5Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3TUMvTNE7ZOA26Snq3JCd6YliAo5iu1MMM78QQ4h3Rk=; b=eHQnlxK45cmyWYDa4kXzTsCpFwvOeFOp+L5v0nMV/1ff0AdGTh82NooKfy4on8SSYwf37WwZfPJ9OtmsxPO9t46VevOnBw9OkEBhSZD3TfSSoXbaVDDbkt69Xc1B18hTm9XRguWfNqauUCTuAYlGMwEiLD72sjGyZYBH+M42kpA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from SJ0PR01MB7282.prod.exchangelabs.com (2603:10b6:a03:3f2::24) by PH7PR01MB7703.prod.exchangelabs.com (2603:10b6:510:1d6::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.28; Tue, 4 Oct 2022 09:31:39 +0000 Received: from SJ0PR01MB7282.prod.exchangelabs.com ([fe80::7d50:e907:8e2e:1ff0]) by SJ0PR01MB7282.prod.exchangelabs.com ([fe80::7d50:e907:8e2e:1ff0%3]) with mapi id 15.20.5676.031; Tue, 4 Oct 2022 09:31:39 +0000 From: Quan Nguyen To: Randy Dunlap , Wolfram Sang , Corey Minyard , Rob Herring , Krzysztof Kozlowski , Brendan Higgins , Benjamin Herrenschmidt , Joel Stanley , Andrew Jeffery , openipmi-developer@lists.sourceforge.net, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, openbmc@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, Open Source Submission Cc: Phong Vo , thang@os.amperecomputing.com, Quan Nguyen , Rob Herring Subject: [PATCH v10 2/3] bindings: ipmi: Add binding for SSIF BMC driver Date: Tue, 4 Oct 2022 16:31:05 +0700 Message-Id: <20221004093106.1653317-3-quan@os.amperecomputing.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221004093106.1653317-1-quan@os.amperecomputing.com> References: <20221004093106.1653317-1-quan@os.amperecomputing.com> X-ClientProxiedBy: SG2P153CA0029.APCP153.PROD.OUTLOOK.COM (2603:1096:4:c7::16) To SJ0PR01MB7282.prod.exchangelabs.com (2603:10b6:a03:3f2::24) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR01MB7282:EE_|PH7PR01MB7703:EE_ X-MS-Office365-Filtering-Correlation-Id: c4a71c54-c827-4924-3162-08daa5eb3d7e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ci6AywFsOdJmeIZ5GqRM8e7p9TQ5ipySVcJVTqsroF8EsqIW5PfttmhzEh7GDS5hM4M7mCqQaKypj/vgZdTSGe/GvmOb2kFUVtao7bbQutUTCAQujsGp5mFXKFiVqiyLFW9kgaa1CCtHiXV//O1S6tpPkdwivD8adksfGvWVV/QOO8kNvVNHCxsDUSy3kLkh/KSV0LcKG9dXsc3OR9fRQ5m0HqSZj16ftrQNzv4DThxM5NlC05GLnA3PyDW6ARZjpkrHX3tZ7cY5/Ly36RekNKcLeFmwqjyF4N2I/dYC2ha+i0fPy4VCC0KQiXnN+5FS1/N/C5fasYJ3ikjgraR7G+n5NEb0j+i3Gvpi9o+oL148L6of0HF8d6Or2Pk+eEe6WBTMrYXOOZq0OsgKIKT91FPoJmndTfnRDNAcZ+rQV+PfiJtdQepy6Owvok7ZMUM85CC75n7kl8HOFg6ykiAjTU6j5+azoHR5/nLlmSC10fZyyX0iLpTaZdTsXM8gZbGF66sI71UoAcn8GPLGxSLFkD82aX1u83G3xUaY53EMUAeAItSbId12ImnAFaDLqeLkkG/ua0wSHhsMvfE6oEBnHS2ggQ7+bQ6ONjsUPl3KHHtbEUR5/0iux+iB1ezezeqFC+kukfGsPJK+F/Ihyf6rZHd3kdJg02bQl24C1MscJO0OLq/xh4LlGEyneABMy4KqeTIhTOpKQnY9Sef47AqZQ9NDPYAv+TN9BVbhruT8Z6THsuwisysH6wtcVTHgjIfDjQ9Rh274GV2wq5hRGlBanytfbtTI6sT2tFY+8/rwLw0GgPgme6L3Wgx/GYccg4X1w3rkbeIpRceOxIl8dlA79znylqNt7HzRGwKiWeM4nvc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR01MB7282.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(366004)(396003)(376002)(39850400004)(136003)(346002)(451199015)(1076003)(966005)(110136005)(186003)(478600001)(6486002)(6506007)(83380400001)(6666004)(52116002)(6512007)(2906002)(5660300002)(54906003)(2616005)(38350700002)(38100700002)(4326008)(8676002)(66556008)(66476007)(26005)(66946007)(316002)(921005)(41300700001)(7416002)(86362001)(8936002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TET2uh6ieznKx5il4v5AVd9XjQViP4AeriR5cX3jBMmc0S/4PkYx383uVQOTd4ttNlJSrQhJtbUuraBc350RApbCxpZ5cWZbjz+ie6540VxLygJHVF7+CdeEx7ivWFv4Hb5oXq0and4Qzgb5px2qeDATfOD/ckK/FHVhA+nEnenCr806aVStctL+/SnJuNy5lvJtMYklTSQiDYIgcEx+qDs631ScJvvytxOZFQSVMuJBw+f1grbvuMyp3BA9XIc7oRitwZrhakdh4/h28RlTMWjVxzk4UTQQ8/iyqnUiOfAMIM08bKzRL8n/1Sxxg9jzPb/JHsgVh0ooOt8NyYhBUMx6euMfgJnIZi9RpLghOvk8t+dPdXl9BPcNhJLlKkznR2q5iCAWh2dD/gzsE9NDH2MACNH9czeg6eyDsKm/LK82xwSH7w1O9V7zb4+zVq0IiwTHnty87UlvWjsaLZmpBORLb7mOIIlvZu4YGJOH7J7sZXQww0Vx9LVLhX6SZe8Vt9tevHRZ8/4weiNYDA001CKJ070Ts+qr2UD9OTTfphH9h6eX/6JrXb5zWSN3sie5NM0HEuALOiy/LSdkz+7v9/SlUpiu1/7KWGW3hm+Z/T2YDS2tzasOgfBWabWEaYygs147U1bUqOYEmgabsf6hbgJ4RET9lUDdD6P8drWw2iYMWZRPofPF88uvSz/gTHAeR+L0mkwwvmZIFS+ohatPfqlyphijzMnOEw2L6kAjnqAPC9/E+REUKdpDPGX5cN3Zkau49Bh0lvUQwQIcc1fuU6Z0I9TJbYuPaPNTxYB+m2N3RxHncZu5X3K0aiPExJsUdXqazUYdX5SIzsQp5LdhD3P4NQFOhQhlV4cl4IhZS70BB8N8DFQ6ci1X4FLRJS56jn6S3CXgvFETF5HFl9raKflvFHgmwCJ8muHrNxzsDb5aVDlo33ilt5crLmGvyJ5P+uD9LT3Fow0IJGjuO5pTxrhbT8DBYpAmZvFmpj7NIMN/Oaffth136uwzwLDuOnqB3Wii87Vvj6GtSA9gus2op9eGmsDFTCCje3SkyyvuvHL8p+pRFtEfzW42OYh+qna1UYET6ePS5crKgvKhrwwOr9J1OsbvFFMlJobS034UZOTUivql7PdARmAgRDAeNGA//5KeeM/Kk81lI7G7XxtFCdkS2D3GJkCqBiJDj2uO/vwBlG1eazKTaFmCY/Xkf36VwCdcnqpnjhE+rTM5W9Itoe4FNvQrJwHjYxDBNnnPQfSs3H0pT5Vb2jGM2db8d0hvDhymCNQJoLY6aA9KG+myrUc3jK6DbVPES2c1k++/qKUWWhw3lDGwvUuusNIp3R4QM7c9qNyhEQ0SqFMx5BPaC4pGUUGtgAYXXcwjz4E+S6754nlM1XIPp92AOhKyiJKzSgF1HoENNXAobZH6O8m96sUSrM9Rvcb8DEmLETJb6nV200ODDPMK4Jwc09JLUDzEXV/hzWa/A1OSZvBysAhDNdSAclpHDO6Z3eHKqU24GYiQ0FqErYhZNvdnf0yRLY5ikSAf+SMsP/GKAxhBUGSz6PCbX08Mb3GysgCRgNtMRqHoC+jnz5y60GPLU7DW+OQXwkyX5/+hD6oU0JZ3Rn1RYXRiep1bC1kgPP1rveyprpo= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: c4a71c54-c827-4924-3162-08daa5eb3d7e X-MS-Exchange-CrossTenant-AuthSource: SJ0PR01MB7282.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Oct 2022 09:31:39.6423 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: vO07yTEtfJXvpd0DvX8/J7UjNvpwfMDII/2NfzFj+3enu1sMgjjsvvj1o/+PPW2eCWqp2hAd8LwP9ZjPKpXkkGvAhUkIL9majm0N0WwhRkM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR01MB7703 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221004_023144_072289_F3F40CD5 X-CRM114-Status: GOOD ( 12.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add device tree binding document for the SSIF BMC driver. Signed-off-by: Quan Nguyen Reviewed-by: Rob Herring --- v10: + None v9: + Update missing Reviewed-by tag from v7 [Rob] v8: + None v7: + Change compatible string from "ampere,ssif-bmc" to "ssif-bmc" [Jae] v6: + None v5: + None v4: + Fix warning with dt_binding_check [Rob] + Change aspeed-ssif-bmc.yaml to ssif-bmc.yaml [Quan] v3: + Switched to use DT schema format [Rob] v2: + None --- .../devicetree/bindings/ipmi/ssif-bmc.yaml | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Documentation/devicetree/bindings/ipmi/ssif-bmc.yaml diff --git a/Documentation/devicetree/bindings/ipmi/ssif-bmc.yaml b/Documentation/devicetree/bindings/ipmi/ssif-bmc.yaml new file mode 100644 index 000000000000..02b662d780bb --- /dev/null +++ b/Documentation/devicetree/bindings/ipmi/ssif-bmc.yaml @@ -0,0 +1,38 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/ipmi/ssif-bmc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: SSIF IPMI BMC interface + +description: SSIF IPMI BMC device bindings + +maintainers: + - Quan Nguyen + +properties: + compatible: + enum: + - ssif-bmc + + reg: + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + ssif-bmc@10 { + compatible = "ssif-bmc"; + reg = <0x10>; + }; + }; From patchwork Tue Oct 4 09:31:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quan Nguyen X-Patchwork-Id: 12998057 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9B2AFC433FE for ; Tue, 4 Oct 2022 09:33:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Sc0fUBvMbQIRMupMNFlSoo2SWTHI0t7VCqKW+uqmsZY=; b=SX6SmM4SpGlwUf 2FQWY+A+8wmbQpU8hpsLtZbFt3L+k6RM6t0+JueuPxodjJjm8glNuwz6JhkBMyB/hRDf0m+OGNcJH Zdzdk8aDhIzWhoOuxRDaDpsSbn44SIPJ3evEu7YOm5OyyWP37WluTpEFb2xTLsjNsPrCxqV9d1xlc QLraz9+DsMapqiUwliOCSKbnwE/Eyn6VLEJtGno7YiTvnh4rTPV5uvVo17n8sJVVaj64SDxAa+8aF NcrLrk35nJ28JJfcgNTKIHCInyMGiAhpY0isqup1RBD9sT7JeIN965x2qqhemfTNguv8B48bq/rrX mjeBPROGE2ej0b+/o93Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ofeHm-0097zz-LG; Tue, 04 Oct 2022 09:32:23 +0000 Received: from mail-mw2nam04on2117.outbound.protection.outlook.com ([40.107.101.117] helo=NAM04-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ofeHG-0097ra-Kt for linux-arm-kernel@lists.infradead.org; Tue, 04 Oct 2022 09:31:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Cz/IFy/648WNwrRV8iSMgB8JvRc8xD7mI2oRrPIURRCkqtxWp4cO1yytVkeNDSttHnNfYEERQzfW6Ro86Mumb2jJ5uEKwv/aHuPb52WnHp4yF/cBOBkpKh2HoIBBhA4HQQnBeBSHxz0ivIuj2zTjyAxMUy0W11GfNYbiCVT8A4KwpFSkahd6PfRhl/bSrMhdvM7Ro4q5UM1R4VeLF7AGBxYaCwCHgShkn0uIfAd3Y6pfDK9Wca2CuS0HYgRv1B6IoWOD2b8rkDkOWKiSZZZyHVfkKbalUE2SmLJbw7SqtLXGaXGT54MSf+6+/JYCgoU2L0V+72u7XC/zxJa/hkQckg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=JarapY2F3PHBxMk0AMW5ZyebXunpeBj40CKtflfqha8=; b=jONLhwbSb9CQdWkUIZb38uTxH0SQFMWPg6akfWgiiapN6rlVLrHgUMN9aXpB4JBDDQk0TYj1kIAMM2evjgPYkVwH/p8olpqocqP+ki72iq9QiCwMuBftr3bnuq0VP6zTDy6UThqd2y3ozrH+Aa42PnjX/G5piX1BM43LLGEg5rfa/2ANLHeMY4HP5BuuO34YXRE6F4A+xheOF2LCjY3GW2a4AHtf+YnVbQc5wHusyRbp9aHWNU+v95lbgTlAVm9OXzRh43jYFtDx57jHdTIF+CMtT6LF6okAxf1tS9DKVp24ljOiCDk2vUa7jyza6Dkp1VA7O1pXp80urWAP+emSYA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JarapY2F3PHBxMk0AMW5ZyebXunpeBj40CKtflfqha8=; b=cX9GarOM7Cj5qaj33eILSLU2fk5WoTZ3bMKI2Pza4rdqDLe3JHHd6JpNQmNiXwqB6LtFdv5i2r4yTJzLAlmGF2bRZO8w0qKEBedE144O4UkDRcoHTZ+RCEKINx9BytmYluCbdbONRkF6dgOEgSm+uxII/VcVPIOTPxthAS2UUaQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from SJ0PR01MB7282.prod.exchangelabs.com (2603:10b6:a03:3f2::24) by BL0PR0102MB3428.prod.exchangelabs.com (2603:10b6:207:1a::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.15; Tue, 4 Oct 2022 09:31:45 +0000 Received: from SJ0PR01MB7282.prod.exchangelabs.com ([fe80::7d50:e907:8e2e:1ff0]) by SJ0PR01MB7282.prod.exchangelabs.com ([fe80::7d50:e907:8e2e:1ff0%3]) with mapi id 15.20.5676.031; Tue, 4 Oct 2022 09:31:45 +0000 From: Quan Nguyen To: Randy Dunlap , Wolfram Sang , Corey Minyard , Rob Herring , Krzysztof Kozlowski , Brendan Higgins , Benjamin Herrenschmidt , Joel Stanley , Andrew Jeffery , openipmi-developer@lists.sourceforge.net, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, openbmc@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, Open Source Submission Cc: Phong Vo , thang@os.amperecomputing.com, Quan Nguyen Subject: [PATCH v10 3/3] i2c: aspeed: Assert NAK when slave is busy Date: Tue, 4 Oct 2022 16:31:06 +0700 Message-Id: <20221004093106.1653317-4-quan@os.amperecomputing.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221004093106.1653317-1-quan@os.amperecomputing.com> References: <20221004093106.1653317-1-quan@os.amperecomputing.com> X-ClientProxiedBy: SG2P153CA0029.APCP153.PROD.OUTLOOK.COM (2603:1096:4:c7::16) To SJ0PR01MB7282.prod.exchangelabs.com (2603:10b6:a03:3f2::24) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR01MB7282:EE_|BL0PR0102MB3428:EE_ X-MS-Office365-Filtering-Correlation-Id: 73f470da-8426-461e-2569-08daa5eb40ae X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vrcgAjpsFyAzHV+SFNRsam6VEoWUSkMxcKNoEDSGivWR9dnRCgX2HW6JmLJbgq3wA8a4Cy19Cpfmo2x6uV5OWADTg0vSq9nAYA4200VvMwLfl5Yi1G2qkleKqwMd7cIZ/jStIkV/CB7edxJ0/ky93oFQORPBhNVPXqCtyVPXT/03TfnFPz7zK3syy9CacWhB8F0Gqcq0tJW6Emxx07vH10IsZNGZ0h/W5tod+tN+rxQMl5fEj/CgU1BCjTH948Kwg2fdT7In5AkuQBB4Uknom+SvC5TdGaxEGJ6uWfUe3UCcNYkDXYSem3PwADIyS+82oiTPUHkyLui9lZaqQ2gDjBARa7lZMuLeYsTD0BT1bmKmYOHsWRyTc92TKdNHTwDfMbHJUdesrVxwRSGp+YxmIbhvKTE7B88Muj4Ls78UDles26Zp3W9Hir4OiH4LtH/118badCfg0gnBAR0NcbIH0N7woyhwWQnt7iFVJXo28A0LkBlJK8nlBzUsxsIgKDLsDlzF/SsFnSUikkbZAYBDd66wZr+wX5NrWh8HVUaMgzjTJJJae7KrXubCrFK3eeMM94ZW7qjg9yZVX4QLMa27AFqoRR8+Bwmu6CEruIswu/5vgnOeR49Gdbz0RruILgsbPolJImNrbXh5iCcOc1MUNcMN/DRfL6I+T3vWvv5uohdGKt8bnuJ+bWJRt6ILktw87qTeGNOgkDTdr08SGQ7efGOpIvkeyzxBkoycS8KEpCwoxhr6V3EEM9MFwH/oLbSuoaeKY0OTwqarwD2Dw0FZ91DGLEbZmeehSNjEXZj951w= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR01MB7282.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(396003)(39850400004)(366004)(376002)(346002)(136003)(451199015)(54906003)(110136005)(6666004)(8936002)(5660300002)(6506007)(921005)(52116002)(7416002)(107886003)(478600001)(6486002)(38100700002)(186003)(2616005)(1076003)(38350700002)(86362001)(26005)(83380400001)(6512007)(2906002)(66946007)(316002)(8676002)(66476007)(66556008)(4326008)(41300700001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UkNe4ya916KBcBaZzOv0VgbZl7Jjg8peNjsln6zK7oMPwYFR8ZYyEthy7gp1e/ZYv/G/8nqYsfG6/6+oQ+oUFEyOJQc1L5F4r1nSBPIo+3zPKoRmh1kaCIP30yXby6FiCeC85soX7z3m+xfeFkarif9kJcYl0KNs8tF8wQcLiKKMH5yjX9CfAUAK+eVWqdwUfQ3HEW35ljv+k41hTiJv9WOKGM28G6r8vO02pPlVWKlQEleWJzjxgoZGpoouAmpcddci1wYbZTEJ79FUszCHf8ry7LrEAniFwWrB/14arNq0j3bEXx03xvisIEsfqBvHvct/L/CfpUVOS5qVzLw00WQ1rqqE21h/njClX2vXH8sLu3oAUdZ0wdk5AEXGVx/sa6BsSRpl2h3o8jjuSCLsvBvrkSGnxGejo3Na3gBypTHrw97EdGYvgKQT5sv8qSKFqU9LUlZ72vIBeOwCUav9NT+p9ku6qKtRmqAV4LvIQd/Nwi8LXtaO29PCLRlA3bNar4oehLlO7Wuq1QL+EGlONxe9fqEP/Dsddn7reZlAH5GsAhYnVvUV3BGw6ZOUp8cAApOyps2eySxojbM4KR8DIHtG8FhATrr7M8acrfe9mdGhTDMMwHNnPgS/G6NUkBtTlfcazPRl9lKjg50hAWmLwNdg1l9vgjQv2cYvqwl8czH9WQxw19ABpEhtVhMQ8Rv4VKXLDMoiwBWm8mV8aYtMocIlTtrlADVOiD3tMMt4rVu6iU2IT6mEe5MU0HSe4L43O7SCuRk/wT0hRBhEAYEqT2qxLmxja++ZI00Z7D1CCheK2ZVITvFcxaZAgLPYKxtqYYtVPG27gFNhCykDH6agqk7sDxZcEtEz4yVVciX5JgJ4E0I1Dba1jB5eGtDRLSkB9fE7KaYjbdcYRIbHH8bEU8w8BhsDlZCc7KrXCrs1rSEF++aiORz/7Q2NBvrCJHzPNx3kO0FG+Z1XQgA7PaOVLA9YsasErHapBLE/HXFhroOLzVxEEoUwqiprOveRjmmmgrgpRbTlgsK28SJCMyS3rqTmBS5XGKH5PMM769CeB21szf6JDVUKpftqJYiLYdKUVEXRfkTYnTFOd0Buxbz70BgXn0KogNQDgfR9+zC5uAxqXZ4flDMOFUfe3y8q88LGgeEsFqjUb8Jvc6qbEnaSs4CqmCrmWm4iFFa5R3rj4EZ7+aqqpIIvx9W9vxA3kCzWn4G28JCLH4TSgdDlVggOPMTI/ZyzQkB39PTRGdmxOzTfRoiqiGBll2PiaV49McudtMIrvIZilHynzenDztaEX67INj12cP62m+fUdLnpOxgGk+BdgmdtFw3Nv09x2wD8MRPo7tPxw9DTi5bLYg8VXwik//ikfIdaDKe77CFMn1a4SQ/FG35PYCdIRkrlLJCr2X3OSyZqRkmGtyV4L9EqAxYZrvFOK4+Q31gLJkNKo9uaEkvF2jQgD4BCIqhnCG8/LG7ZZm8uczpQWNXBpF+Am+gTrv52wuqUHamdOwzHTbeT0W5hg/1yy1MHlxs80FYfIBmrBYdV0d+UZZ1RS6rtnHBJCDzrgE7TTen8FbEgHasGcAVIs1G7huFDrHsuS+CQvD55pUmmahSYaZFb6q26umdcKr/QhmHfXsQLfRuv8Ec= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 73f470da-8426-461e-2569-08daa5eb40ae X-MS-Exchange-CrossTenant-AuthSource: SJ0PR01MB7282.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Oct 2022 09:31:45.0679 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: TzDuQI7feM3Mt0VRKP9bnAaRUi0ViXA5FXEyjW97UP2BEWM+5cENn8oLirsFEZJwG3NOM9Ta7kH7CES0PhgIsbJKgiUT6Pw/kMC1XwKzmpA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR0102MB3428 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221004_023150_707164_F0E36725 X-CRM114-Status: GOOD ( 12.81 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On I2C_SLAVE_WRITE_REQUESTED event, Slave already ACK'ed on the address phase. But as the backend driver is busy and unable to process any request from Master, issue RxCmdLast for Slave to auto send NACK on next incoming byte. Signed-off-by: Quan Nguyen --- v10: + Issuing RxCmdLast command for all errnos [Wolfram] v9: + Update commit message and add comment to explain the effect of issuing RxCmdLast when Slave busy [Quan] v7 -> v8: + None v6: + New introduced in v6 [Quan] --- drivers/i2c/busses/i2c-aspeed.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c index 185dedfebbac..c64c381b69b7 100644 --- a/drivers/i2c/busses/i2c-aspeed.c +++ b/drivers/i2c/busses/i2c-aspeed.c @@ -244,6 +244,7 @@ static u32 aspeed_i2c_slave_irq(struct aspeed_i2c_bus *bus, u32 irq_status) u32 command, irq_handled = 0; struct i2c_client *slave = bus->slave; u8 value; + int ret; if (!slave) return 0; @@ -311,7 +312,13 @@ static u32 aspeed_i2c_slave_irq(struct aspeed_i2c_bus *bus, u32 irq_status) break; case ASPEED_I2C_SLAVE_WRITE_REQUESTED: bus->slave_state = ASPEED_I2C_SLAVE_WRITE_RECEIVED; - i2c_slave_event(slave, I2C_SLAVE_WRITE_REQUESTED, &value); + ret = i2c_slave_event(slave, I2C_SLAVE_WRITE_REQUESTED, &value); + /* + * Slave ACK's on this address phase already but as the backend driver + * returns an errno, the bus driver should nack the next incoming byte. + */ + if (ret < 0) + writel(ASPEED_I2CD_M_S_RX_CMD_LAST, bus->base + ASPEED_I2C_CMD_REG); break; case ASPEED_I2C_SLAVE_WRITE_RECEIVED: i2c_slave_event(slave, I2C_SLAVE_WRITE_RECEIVED, &value);