From patchwork Thu Mar 17 23:40:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 12784656 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AB87C433EF for ; Thu, 17 Mar 2022 23:41:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229688AbiCQXmZ (ORCPT ); Thu, 17 Mar 2022 19:42:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229916AbiCQXmX (ORCPT ); Thu, 17 Mar 2022 19:42:23 -0400 Received: from beige.elm.relay.mailchannels.net (beige.elm.relay.mailchannels.net [23.83.212.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39935174BA6 for ; Thu, 17 Mar 2022 16:41:01 -0700 (PDT) X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id E2A6F6213E9; Thu, 17 Mar 2022 23:40:59 +0000 (UTC) Received: from pdx1-sub0-mail-a311.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 130176217FA; Thu, 17 Mar 2022 23:40:58 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1647560458; a=rsa-sha256; cv=none; b=SOdQ7EaNRqiFK6k5tkBekpyNMu0hsYx4Q47xk95QpAmLdexwDyNO+x9a5tDm8u1OT+9Jo5 o+V76NpnT0cA4WQfWCgqSPE/XbHzjjWuk3BawV+mFZt1BmgHkU/1dIAMREtQZyyO8mCVyK JcWe/cVxaIrTp1+Q3j8eRfkcUpDa4WKRlRqIRSIb7ailUgvIlRpOtBE1W0L81n6o6u7i/h r7LZBR6/WVSLTgtBLT8mdxU8eF1hfisL/tIbZ4I7RXJpwt/dsf1FOc6Rl7VKHLJbF3QicE /srmsDR+GU+tR78eDrSJpksQcGNPkVUBHvUKx6X+T49KoL7C0MZRZBTla+kjsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1647560458; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7u6SLBHOxzczR8velHOksChPK96jmeJqkciQmedcR7Q=; b=5DqKGsANM/dJcriT79hGrHP5dQT3aNYZ5aV8eZCO3PcjWqj5+p+LpA2Kvg3ypcBCnmUSCq WpFhDC4Lw2feqqWxCnF8Qp7cxlsQ3QSCera8NKV8grG3xkHoWpamZMCY5uHgA5vJsaFsio Zhk/jcgGqn1Z5v/yNL1rIS8N8iKeog6hu23ymm8hgtRkpa7J2utjWqTI9KIUBjqZnuQJJs /e9NsVwdBpD54gEk6RwLKsdrylxBqHlwuP6VKki/dmGf1+MKOKIDTDsC3hUDqT83hQP6Im 4AXYdj8JY+9APGLC+7FSCTFXGfAE7s94QsppBygZpgALRUSvP6kpa4yKdzBi2g== ARC-Authentication-Results: i=1; rspamd-c9cb649d9-kn94c; auth=pass smtp.auth=dreamhost smtp.mailfrom=dave@stgolabs.net X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net Received: from pdx1-sub0-mail-a311.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.112.144.24 (trex/6.5.3); Thu, 17 Mar 2022 23:40:59 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|dave@stgolabs.net X-MailChannels-Auth-Id: dreamhost X-Harbor-Shade: 6da52c301b533045_1647560459773_680018259 X-MC-Loop-Signature: 1647560459773:2814622097 X-MC-Ingress-Time: 1647560459773 Received: from localhost.localdomain (unknown [104.36.25.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dave@stgolabs.net) by pdx1-sub0-mail-a311.dreamhost.com (Postfix) with ESMTPSA id 4KKNtx20tkz3h; Thu, 17 Mar 2022 16:40:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stgolabs.net; s=dreamhost; t=1647560457; bh=R/o3Wa7CV1nyJi9TSaAyrkeotviZBwd03tMKWbujE6o=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=CDsIN/CpcgwhXwgRADycM1sgYfcwgNGrpF1FNbd2jU0f18VIObsHuaxWnalB6hoSF Jw0HCva9BoXyL2Z0s9YYrsrlm/ZlnEpw32W2UwZ3fwUa4pbdhWSSUjUvdBOqxyRyO1 6RMXXpQD0cBzezg8ymA976Zr8yVBA74ZxgfVGtFAv9z65G092Cb86N2/aQa2cpn5gM B/EKDVkDPfbTdac5c3X67luHulRs7ipWfofcALWAWmqk7VdwL7rJR/UBlBbOGibXMN jcS+vd44PmL2XIVrXOMuENCQ3TVsZXCi6AMrBkZey4I7KPN/1RzBF3TDcD2eqldJfR Oeeu+vjzC3BSg== From: Davidlohr Bueso To: linux-cxl@vger.kernel.org Cc: dan.j.williams@intel.com, ben.widawsky@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, dave@stgolabs.net Subject: [PATCH 1/5] cxl/mbox: Move mbox_mutex usage comment Date: Thu, 17 Mar 2022 16:40:45 -0700 Message-Id: <20220317234049.69323-2-dave@stgolabs.net> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220317234049.69323-1-dave@stgolabs.net> References: <20220317234049.69323-1-dave@stgolabs.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org ... this is better served in the callback that actually grabs the lock. Signed-off-by: Davidlohr Bueso --- drivers/cxl/core/mbox.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index be61a0d8016b..778b04a0fb0a 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -136,7 +136,7 @@ static struct cxl_mem_command *cxl_mem_find_command(u16 opcode) * @out: Caller allocated buffer for the output. * @out_size: Expected size of output. * - * Context: Any context. Will acquire and release mbox_mutex. + * Context: Any context. * Return: * * %>=0 - Number of bytes returned in @out. * * %-E2BIG - Payload is too large for hardware. @@ -165,6 +165,7 @@ int cxl_mbox_send_cmd(struct cxl_dev_state *cxlds, u16 opcode, void *in, if (out_size > cxlds->payload_size) return -E2BIG; + /* acquire and releases the mbox_mutex */ rc = cxlds->mbox_send(cxlds, &mbox_cmd); if (rc) return rc; From patchwork Thu Mar 17 23:40:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 12784658 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF6ACC433EF for ; Thu, 17 Mar 2022 23:41:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230151AbiCQXmc (ORCPT ); Thu, 17 Mar 2022 19:42:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230154AbiCQXmc (ORCPT ); Thu, 17 Mar 2022 19:42:32 -0400 Received: from bee.birch.relay.mailchannels.net (bee.birch.relay.mailchannels.net [23.83.209.14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E793B17F3E3 for ; Thu, 17 Mar 2022 16:41:14 -0700 (PDT) X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 3E752281004; Thu, 17 Mar 2022 23:41:14 +0000 (UTC) Received: from pdx1-sub0-mail-a311.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id BEFCB281957; Thu, 17 Mar 2022 23:40:58 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net Received: from pdx1-sub0-mail-a311.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.102.18.13 (trex/6.5.3); Thu, 17 Mar 2022 23:41:14 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|dave@stgolabs.net X-MailChannels-Auth-Id: dreamhost X-Cure-Vacuous: 288d36603fbaff1a_1647560474076_1027156811 X-MC-Loop-Signature: 1647560474076:2726396899 X-MC-Ingress-Time: 1647560474075 Received: from localhost.localdomain (unknown [104.36.25.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dave@stgolabs.net) by pdx1-sub0-mail-a311.dreamhost.com (Postfix) with ESMTPSA id 4KKNtx6pmxz3d; Thu, 17 Mar 2022 16:40:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stgolabs.net; s=dreamhost; t=1647560458; bh=xQh2PnCkjkzhaN3O5oXSokkJzc2IfmtlVvixyuG7EUg=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=k9mbvRh+PJXCgiEio+iYkTxc5rCgQ4RBf2sAzS1zGT3LOrmb8hSsqetieOn4oweFx rMaGL8ZMuz/k0pqpq6aFZ9sLwsSziiqQUk3LIxtb73Gehsxs012WmuT1exgV9UIrCD Eo+DOZG+y6jObV3/ECQ8ZzWaq7PbxSE3RzxB6Dl7XNWzojz0nm/IFeS+heFPrK/Ngy oS7ci1JzTnW1Mo7ZbQZtLpURyyXjOm9wO32vCkASmzYvqvD/mNq6mVFebRAoxztTe8 d1cgGHtuLLJMOOKMUpxouoH7pF/H+Wq7kmgB6LfK+UZKUd32kCeo2p0yzlKq9hDuI0 hTjj+OQ1h5ZkQ== From: Davidlohr Bueso To: linux-cxl@vger.kernel.org Cc: dan.j.williams@intel.com, ben.widawsky@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, dave@stgolabs.net Subject: [PATCH 2/5] cxl/pci: Use CXL_MBOX_SUCCESS to check against mbox_cmd return code Date: Thu, 17 Mar 2022 16:40:46 -0700 Message-Id: <20220317234049.69323-3-dave@stgolabs.net> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220317234049.69323-1-dave@stgolabs.net> References: <20220317234049.69323-1-dave@stgolabs.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Also mention the need for the caller to check against any errors from the hardware in return_code. Signed-off-by: Davidlohr Bueso --- drivers/cxl/pci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c index 8a7267d116b7..c77e06aff8dc 100644 --- a/drivers/cxl/pci.c +++ b/drivers/cxl/pci.c @@ -177,9 +177,9 @@ static int __cxl_pci_mbox_send_cmd(struct cxl_dev_state *cxlds, mbox_cmd->return_code = FIELD_GET(CXLDEV_MBOX_STATUS_RET_CODE_MASK, status_reg); - if (mbox_cmd->return_code != 0) { + if (mbox_cmd->return_code != CXL_MBOX_SUCCESS) { dev_dbg(dev, "Mailbox operation had an error\n"); - return 0; + return 0; /* completed but caller must check return_code */ } /* #7 */ From patchwork Thu Mar 17 23:40:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 12784655 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DD04C433F5 for ; Thu, 17 Mar 2022 23:41:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230146AbiCQXmY (ORCPT ); Thu, 17 Mar 2022 19:42:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229688AbiCQXmX (ORCPT ); Thu, 17 Mar 2022 19:42:23 -0400 Received: from beige.elm.relay.mailchannels.net (beige.elm.relay.mailchannels.net [23.83.212.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C355174BB0 for ; Thu, 17 Mar 2022 16:41:01 -0700 (PDT) X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 52337881B14; Thu, 17 Mar 2022 23:41:00 +0000 (UTC) Received: from pdx1-sub0-mail-a311.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 9D9D9881AF6; Thu, 17 Mar 2022 23:40:59 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1647560459; a=rsa-sha256; cv=none; b=y6KyjucrUfFqoV9JGPBDDFIVf1u4WEPorB8f/b+m4ZMYKlvYdZouFPkjkEoQRwaq1+A+Xa xBuwO5UFucfQQLM4ROXUIvmLvDyVc+TAUfmCityghdei8svKvO1QmEXpEyAhs+9bCk8hHe k+7Oxfm61zs9M+XUF8JrPfMReCWSqRZVpPcWc5fR+9Bafom70ByRaePqLVxoNdWl/0Ddzx DaeBvpPWrrj8AAuuYOHZ0KKfVlUX7/cxxWxOfob2TnxVw5xCvmf7q76Oro+N9ves5T91Ed TSQqbQ+2nFDXJ/LySk5oqRDpSroU8Yspls/uhYsPTwd/ApweMhE6xiyH6B/H8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1647560459; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=v6w9eM5yxxYzkqILV6KU6C0yQ19ho4zxdRRyRz7Hnf4=; b=MFtpBPAMJIgD6SAR82mqFe8scX8BPDxJn35rHZOQ4XizlaYs9EbIRS7IpKF1+vk/ovrZ0T fg9eQDD6km3CyK5+jgS9kQ7QcLxJLYvtJE51N5CDw8U8cPjqwimGDGZ2lwMR/Z38WaJiav ThVvEI0VAyptiQ56ymE0g31n+6JIv4f4Qvd6XFbLABFvmEjnqAvtpMKY8PwTomWHoKIRnh n4ucc/PADUAb1r6CeeddmlD7PIxrUEEYJ1fNYUw+LAdtR4zIuxO47YWY1zKPVrmBuyo7t6 vqiWjeNqzl2If1ONSNRcgTiCidfzckxobGIedWfDJyEfPOjVtuZKGRLFhTzrzg== ARC-Authentication-Results: i=1; rspamd-c9cb649d9-xgcgv; auth=pass smtp.auth=dreamhost smtp.mailfrom=dave@stgolabs.net X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net Received: from pdx1-sub0-mail-a311.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.109.126.219 (trex/6.5.3); Thu, 17 Mar 2022 23:41:00 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|dave@stgolabs.net X-MailChannels-Auth-Id: dreamhost X-Harbor-Supply: 5267f1c85b2c46c2_1647560460111_3057755779 X-MC-Loop-Signature: 1647560460111:1595744512 X-MC-Ingress-Time: 1647560460111 Received: from localhost.localdomain (unknown [104.36.25.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dave@stgolabs.net) by pdx1-sub0-mail-a311.dreamhost.com (Postfix) with ESMTPSA id 4KKNty65pPz1fQ; Thu, 17 Mar 2022 16:40:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stgolabs.net; s=dreamhost; t=1647560459; bh=v6w9eM5yxxYzkqILV6KU6C0yQ19ho4zxdRRyRz7Hnf4=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=XF6d6UbZjfHAa2i57aFiclfj5YnR1oj8ymLaAqmN8okyJhQ8NGs2JNZ0/M2bhrP/G lJURrAB5lY8dbHYHVfxVcUlhLl0rUUbTvy940fsaqtYXurbjBqi+N2KDbdD4fs+J1o PCr2zaJzUdCHYIaYRJEQF9nQginC74NOHda9HfK8JO9XBz8hda8ZByooBIBWM2K4Re TttEpCR7GG/l29GHLO8t63A4zp0AIMsz+KaLdPwZXdJoQMa7vuwdgw6xr6YyEfmRYj tUonCEur1HYYgoKjV8HOSmb27q6/SAeulQYkRdaSalE91Bf/XHRXczkyhGQNqwA56H ZHfHyn0JdDDdA== From: Davidlohr Bueso To: linux-cxl@vger.kernel.org Cc: dan.j.williams@intel.com, ben.widawsky@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, dave@stgolabs.net Subject: [PATCH 3/5] cxl/mbox: Improve handling of mbox_cmd return codes Date: Thu, 17 Mar 2022 16:40:47 -0700 Message-Id: <20220317234049.69323-4-dave@stgolabs.net> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220317234049.69323-1-dave@stgolabs.net> References: <20220317234049.69323-1-dave@stgolabs.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Upon a completed command the caller is still expected to check the actual return_code register for to ensure it succeed. This adds, per the spec, the potential command return codes. It maps the hardware return code with the kernel's errno style, and by default continues to use -ENXIO (Command completed, but device reported an error). Signed-off-by: Davidlohr Bueso --- drivers/cxl/core/mbox.c | 2 +- drivers/cxl/cxlmem.h | 90 ++++++++++++++++++++++++++++++++++++++++- drivers/cxl/pci.c | 2 +- 3 files changed, 91 insertions(+), 3 deletions(-) diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index 778b04a0fb0a..d4d4a16820b7 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -171,7 +171,7 @@ int cxl_mbox_send_cmd(struct cxl_dev_state *cxlds, u16 opcode, void *in, return rc; /* TODO: Map return code to proper kernel style errno */ - if (mbox_cmd.return_code != CXL_MBOX_SUCCESS) + if (mbox_cmd.return_code != CXL_MBOX_CMD_RC_SUCCESS) return -ENXIO; /* diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index 5d33ce24fe09..268597d1ff33 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -85,9 +85,97 @@ struct cxl_mbox_cmd { size_t size_in; size_t size_out; u16 return_code; -#define CXL_MBOX_SUCCESS 0 }; +/* + * Per CXL 2.0 Section 8.2.8.4.5.1 + */ +enum { + CXL_MBOX_CMD_RC_SUCCESS = 0, + CXL_MBOX_CMD_RC_BACKGROUND, + CXL_MBOX_CMD_RC_INVINPUT, + CXL_MBOX_CMD_RC_UNSUPPORTED, + CXL_MBOX_CMD_RC_INTERNAL, + CXL_MBOX_CMD_RC_RETRY, + CXL_MBOX_CMD_RC_BUSY, + CXL_MBOX_CMD_RC_MEDIADISABLED, + CXL_MBOX_CMD_RC_FWINPROGRESS, + CXL_MBOX_CMD_RC_FWOOO, + CXL_MBOX_CMD_RC_FWAUTH, + CXL_MBOX_CMD_RC_INVSLOT, + CXL_MBOX_CMD_RC_FWROLLBACK, + CXL_MBOX_CMD_RC_FWRESET, + CXL_MBOX_CMD_RC_INVHANDLE, + CXL_MBOX_CMD_RC_INVPA, + CXL_MBOX_CMD_RC_INJPOISON, + CXL_MBOX_CMD_RC_MEDIAFAILURE, + CXL_MBOX_CMD_RC_ABORT, + CXL_MBOX_CMD_RC_INVSECURITY, + CXL_MBOX_CMD_RC_PASSPHRASE, + CXL_MBOX_CMD_RC_MBOXUNSUPPORTED, + CXL_MBOX_CMD_RC_INVPAYLOAD, +}; + +#define CXL_CMD_RC(_value, errno, str) \ + [CXL_MBOX_CMD_RC_##_value] = { \ + .err = errno, \ + .desc = str, \ + } + +/* + * mbox cmd hardware return_code handling + */ +struct cxl_mbox_cmd_rc { + int err; /* proper kernel style errno */ + const char *desc; +}; + +static const struct cxl_mbox_cmd_rc cxl_mbox_cmd_rctable[] = { + CXL_CMD_RC(SUCCESS, 0, NULL), + CXL_CMD_RC(BACKGROUND, ENXIO, "background cmd started successfully"), + /* errors here on out */ + CXL_CMD_RC(INVINPUT, ENXIO, "cmd input was invalid"), + CXL_CMD_RC(UNSUPPORTED, ENXIO, "cmd is not supported"), + CXL_CMD_RC(INTERNAL, ENXIO, "internal device error"), + CXL_CMD_RC(RETRY, ENXIO, "temporary error, retry once"), + CXL_CMD_RC(BUSY, ENXIO, "ongoing background operation"), + CXL_CMD_RC(MEDIADISABLED, ENXIO, "media access is disabled"), + CXL_CMD_RC(FWINPROGRESS, ENXIO, + "only one FW package can be transferred at a time"), + CXL_CMD_RC(FWOOO, ENXIO, + "FW package content was transferred out of order"), + CXL_CMD_RC(FWAUTH, ENXIO, "FW package authentication failed"), + CXL_CMD_RC(INVSLOT, ENXIO, + "FW slot specified is not supported for requested op"), + CXL_CMD_RC(FWROLLBACK, ENXIO, + "rolled back to the previous active FW"), + CXL_CMD_RC(FWRESET, ENXIO, "FW failed to activate, needs cold reset"), + CXL_CMD_RC(INVHANDLE, ENXIO, + "one or more Event Record Handles were invalid"), + CXL_CMD_RC(INVPA, ENXIO, "physical address specified is invalid"), + CXL_CMD_RC(INJPOISON, ENXIO, + "allowed poison injection has been reached"), + CXL_CMD_RC(MEDIAFAILURE, ENXIO, "permanent issue with the media"), + CXL_CMD_RC(ABORT, ENXIO, "background cmd was aborted by device"), + CXL_CMD_RC(INVSECURITY, ENXIO, + "not valid in the current security state"), + CXL_CMD_RC(PASSPHRASE, ENXIO, + "passphrase doesn't match current passphrase"), + CXL_CMD_RC(MBOXUNSUPPORTED, ENXIO, + "not supported on the mailbox it was issued on"), + CXL_CMD_RC(INVPAYLOAD, ENXIO, "invalid payload length"), +}; + +static inline const char *cxl_mbox_cmd_rc2str(struct cxl_mbox_cmd *mbox_cmd) +{ + return cxl_mbox_cmd_rctable[mbox_cmd->return_code].desc; +} + +static inline int cxl_mbox_cmd_rc2errno(struct cxl_mbox_cmd *mbox_cmd) +{ + return cxl_mbox_cmd_rctable[mbox_cmd->return_code].err; +} + /* * CXL 2.0 - Memory capacity multiplier * See Section 8.2.9.5 diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c index c77e06aff8dc..0c36d111232b 100644 --- a/drivers/cxl/pci.c +++ b/drivers/cxl/pci.c @@ -177,7 +177,7 @@ static int __cxl_pci_mbox_send_cmd(struct cxl_dev_state *cxlds, mbox_cmd->return_code = FIELD_GET(CXLDEV_MBOX_STATUS_RET_CODE_MASK, status_reg); - if (mbox_cmd->return_code != CXL_MBOX_SUCCESS) { + if (mbox_cmd->return_code != CXL_MBOX_CMD_RC_SUCCESS) { dev_dbg(dev, "Mailbox operation had an error\n"); return 0; /* completed but caller must check return_code */ } From patchwork Thu Mar 17 23:40:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 12784659 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94B05C433EF for ; Thu, 17 Mar 2022 23:41:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230155AbiCQXme (ORCPT ); Thu, 17 Mar 2022 19:42:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230154AbiCQXmd (ORCPT ); Thu, 17 Mar 2022 19:42:33 -0400 Received: from bee.birch.relay.mailchannels.net (bee.birch.relay.mailchannels.net [23.83.209.14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B401C180051 for ; Thu, 17 Mar 2022 16:41:16 -0700 (PDT) X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 186B092227B; Thu, 17 Mar 2022 23:41:16 +0000 (UTC) Received: from pdx1-sub0-mail-a311.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 76A979218B6; Thu, 17 Mar 2022 23:41:00 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net Received: from pdx1-sub0-mail-a311.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.102.18.13 (trex/6.5.3); Thu, 17 Mar 2022 23:41:16 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|dave@stgolabs.net X-MailChannels-Auth-Id: dreamhost X-Eight-Thread: 621a4b4c0180b2ee_1647560475822_3605548828 X-MC-Loop-Signature: 1647560475822:1271953928 X-MC-Ingress-Time: 1647560475822 Received: from localhost.localdomain (unknown [104.36.25.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dave@stgolabs.net) by pdx1-sub0-mail-a311.dreamhost.com (Postfix) with ESMTPSA id 4KKNtz4G6xz1fK; Thu, 17 Mar 2022 16:40:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stgolabs.net; s=dreamhost; t=1647560460; bh=9Z4uOC7dwkUjTIQHUcRpTqAo7KQFNI1z+w+uTn0tSeU=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=klyEl4IHS87HgV4FPGuTK7EUmP6tTjrHGemPPcjaVoY1i4vaqedyLcG74jVOZ97QB oJT58BLOR13SrewAxaocpp56Nw95LOpYhpLbfHxew6FOHT6G46qjdyebs4/rOA2yqR FdJ2oRjiRwPQPPa195K93FnrNew9w7iBDe6fot8lwKuXTNHkiwz4c9PalPhZoXBbve 1slCf2azmBWaAEyXDKVInjxIZfPNqMM0wtheaRJIitZ632MlLDL0LeQ8GMY1kuUoZv bhAs4pUUalyalI1IEzueQBNz5CBtu5yEjlpc9lB4JtosfDUfbyYBVadIdaFUyKFFj/ KjhWoPbrauvQw== From: Davidlohr Bueso To: linux-cxl@vger.kernel.org Cc: dan.j.williams@intel.com, ben.widawsky@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, dave@stgolabs.net Subject: [PATCH 4/5] cxl/mbox: Use new return_code handling Date: Thu, 17 Mar 2022 16:40:48 -0700 Message-Id: <20220317234049.69323-5-dave@stgolabs.net> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220317234049.69323-1-dave@stgolabs.net> References: <20220317234049.69323-1-dave@stgolabs.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Use the global cxl_mbox_cmd_rc table to improve debug messaging in __cxl_pci_mbox_send_cmd() and allow cxl_mbox_send_cmd() to map to proper kernel style errno codes - this patch continues to use -ENXIO only so no change in semantics. Signed-off-by: Davidlohr Bueso --- drivers/cxl/core/mbox.c | 7 ++++--- drivers/cxl/pci.c | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index d4d4a16820b7..fa9e7043f158 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -170,9 +170,10 @@ int cxl_mbox_send_cmd(struct cxl_dev_state *cxlds, u16 opcode, void *in, if (rc) return rc; - /* TODO: Map return code to proper kernel style errno */ - if (mbox_cmd.return_code != CXL_MBOX_CMD_RC_SUCCESS) - return -ENXIO; + if (mbox_cmd.return_code != CXL_MBOX_CMD_RC_SUCCESS) { + int err = cxl_mbox_cmd_rc2errno(&mbox_cmd); + return -err; + } /* * Variable sized commands can't be validated and so it's up to the diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c index 0c36d111232b..67ec0220826f 100644 --- a/drivers/cxl/pci.c +++ b/drivers/cxl/pci.c @@ -178,7 +178,8 @@ static int __cxl_pci_mbox_send_cmd(struct cxl_dev_state *cxlds, FIELD_GET(CXLDEV_MBOX_STATUS_RET_CODE_MASK, status_reg); if (mbox_cmd->return_code != CXL_MBOX_CMD_RC_SUCCESS) { - dev_dbg(dev, "Mailbox operation had an error\n"); + dev_dbg(dev, "Mailbox operation had an error: %s\n", + cxl_mbox_cmd_rc2str(mbox_cmd)); return 0; /* completed but caller must check return_code */ } From patchwork Thu Mar 17 23:40:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 12784660 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3042C433F5 for ; Thu, 17 Mar 2022 23:41:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230154AbiCQXme (ORCPT ); Thu, 17 Mar 2022 19:42:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229776AbiCQXme (ORCPT ); Thu, 17 Mar 2022 19:42:34 -0400 Received: from bee.birch.relay.mailchannels.net (bee.birch.relay.mailchannels.net [23.83.209.14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43FAF18005E for ; Thu, 17 Mar 2022 16:41:17 -0700 (PDT) X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id ABA5D461A9D; Thu, 17 Mar 2022 23:41:16 +0000 (UTC) Received: from pdx1-sub0-mail-a311.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 6959E461704; Thu, 17 Mar 2022 23:41:01 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net Received: from pdx1-sub0-mail-a311.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.102.3.17 (trex/6.5.3); Thu, 17 Mar 2022 23:41:16 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|dave@stgolabs.net X-MailChannels-Auth-Id: dreamhost X-Decisive-Lyrical: 559af1812f0965ff_1647560476565_1436234604 X-MC-Loop-Signature: 1647560476565:2611649312 X-MC-Ingress-Time: 1647560476565 Received: from localhost.localdomain (unknown [104.36.25.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dave@stgolabs.net) by pdx1-sub0-mail-a311.dreamhost.com (Postfix) with ESMTPSA id 4KKNv034kqz1fQ; Thu, 17 Mar 2022 16:41:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stgolabs.net; s=dreamhost; t=1647560461; bh=i60qDhbVCCREqjnZZ3dUJy0KfFl+7Z1pcY2boobd42Y=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=ekfgegTX4ZiF0+UsTobZNigPja4IBxmGdQitFzPjpMasyr9xf2uUH6QTrcKqOAwNY e+sy2vM7Tjz0ohZLWh/HJyK0l0RGulNlmhpDMbDNAwAgLnkKcTqjnGY7eJ/rkyXvlu C5Mo1BCQbSBgrkrrZcwuJ6UCdj7Sj7LG+y/kUy6uj0In9LROjk6mm2k+GMErQ6k0/L Xdq24c9oLbUKEfSo5Y6YgHLDp+vOiZhDNoKX6v993ZHycPIlfaCedLxEmx0dZWu4qS 3c40JAcyW9cAs5pa855Oy0Uo6CvpvmzGIk3PFpmlK3CIIMLiIJ06AL0NnBw0CVhYEW 9W1k31+P76IGw== From: Davidlohr Bueso To: linux-cxl@vger.kernel.org Cc: dan.j.williams@intel.com, ben.widawsky@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, dave@stgolabs.net Subject: [PATCH 5/5] cxl/mbox: Retry sending mbox command upon RETRY return_code Date: Thu, 17 Mar 2022 16:40:49 -0700 Message-Id: <20220317234049.69323-6-dave@stgolabs.net> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220317234049.69323-1-dave@stgolabs.net> References: <20220317234049.69323-1-dave@stgolabs.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org As mentioned in CXL 2.0 specs: the hardware can set a Retry Required if the the command was not completed due to a temporary error. An optional single retry may resolve the issue. This is the only retry case as in general they are not recommended for commands that return an error. Signed-off-by: Davidlohr Bueso --- drivers/cxl/core/mbox.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index fa9e7043f158..567987052b68 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -160,20 +160,25 @@ int cxl_mbox_send_cmd(struct cxl_dev_state *cxlds, u16 opcode, void *in, .size_out = out_size, .payload_out = out, }; - int rc; + int rc, retry = 1; if (out_size > cxlds->payload_size) return -E2BIG; - /* acquire and releases the mbox_mutex */ - rc = cxlds->mbox_send(cxlds, &mbox_cmd); - if (rc) - return rc; + do { + /* acquire and releases the mbox_mutex */ + rc = cxlds->mbox_send(cxlds, &mbox_cmd); + if (rc) + return rc; - if (mbox_cmd.return_code != CXL_MBOX_CMD_RC_SUCCESS) { - int err = cxl_mbox_cmd_rc2errno(&mbox_cmd); - return -err; - } + if (mbox_cmd.return_code == CXL_MBOX_CMD_RC_SUCCESS) + break; + + if (mbox_cmd.return_code != CXL_MBOX_CMD_RC_RETRY || !retry) { + int err = cxl_mbox_cmd_rc2errno(&mbox_cmd); + return -err; + } + } while (retry--); /* * Variable sized commands can't be validated and so it's up to the