Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2310384rbb; Tue, 27 Feb 2024 19:05:36 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU0k4PXBIHGCVfJlQHkskg4t6FN6nIFLvPS+bDeAS62WHhQBmbP5NVl2/mLLy7NDQNmFEIs8te9a4DGESCKGLsQB0OVlNKLya/XfOKeKA== X-Google-Smtp-Source: AGHT+IFbbgwNGgqcOKL9lv2MckFbMWEzfo6FV7xwEYKE1OeQQTWhyhivwYxeGvCGnxgTPJ+Hw/SH X-Received: by 2002:a05:6214:4003:b0:68c:a83b:b1ba with SMTP id kd3-20020a056214400300b0068ca83bb1bamr4667038qvb.38.1709089535989; Tue, 27 Feb 2024 19:05:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709089535; cv=pass; d=google.com; s=arc-20160816; b=VMty9hjdufx1EXPOFv/rgxAzZ1JuQ5ZfnvJu94YOCESKIl0kVfEAzM4SWEJI8DDxyx ss8lZgnHYnmJrZMo1RNx64qxxZoWGkPNMpYo0rTqa/AKCJ81PUtuQyS9dlr32z1TJkMM HjFS8LMINrG4G/5v3r2VxBDld555hvr5HoSGUaap6C07kiJ7yqM22Z0gnt85YZY5D8xv UNf6+QU0yZFwhtoTJiJNvLeQgj4VfthkLIGDZVKdyMOWPKSlMlHAuIbmW7BfCOb2PLIf nHNrO7RPK4y0vOePoe9rENjV8+MdFkqZGMwDg9nTlXHVvMUAGYKPHdRW7xpI0eFuEkhB /CBQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=zRTLjsYwJzvI1s2Bp9S11TzSO+Nrwdmn+sIRJ1u8UyE=; fh=x4bFVqj5qD52f35ITnpIMR9XPjt+nAjpv5WW2CLFX0Q=; b=dJ+6xsBSoRTP8gXOZjyFdPz9HPUALCwAqWRwGWH8mS5pdquKni08oSTbmx8JzlSMnS BTrERSx0BkLQsOa+1ox0+vXX3AxxDdyD6w5uYOEYe+2AK8Tvsf4CUbbPDFoIkMeHN9TU BbjHFlhXSjGPwcSz284Xo262FwP7Z3yaBoIEQfcdKvA4tOPUa55uPuozP6WEkI2QH9Qq wDXoM9ozmA9YtXbXhsycffEIkA68VTGHyLL+lyiPjgQeZGXTDGwi1oSl/3/Dw0hLjPlr Q2bHI1z3FJRZRq6X3Yrk1MXPVkmIaKdpLH/dKz/GeWq3fIlU5PTzrF2Vbxetw1ZC714s ffLg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IgWxomVA; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84244-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84244-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id if11-20020a0562141c4b00b0068f90fe58a6si8897316qvb.245.2024.02.27.19.05.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 19:05:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84244-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IgWxomVA; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84244-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84244-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 066951C24D31 for ; Wed, 28 Feb 2024 00:00:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F122679E3; Wed, 28 Feb 2024 00:00:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="IgWxomVA" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E7EF3838A; Wed, 28 Feb 2024 00:00:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709078420; cv=none; b=XRMylcBt3OuCWdSyhXjH6PcKoAWiGMatGXdM/V9rHAST7BT3e5rULl4m+lQ1JZdfgz+iXCAMiWwWx/WI9KUoBLVIWIu8wUDCV/hU4fxgMzZ+r2uGoMAuYryReb9eGDv2u80oxuMIibm1XRjWvRIAcGO3cCW9hN6soTDhuAgv7Ek= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709078420; c=relaxed/simple; bh=tbwiqecWv333Dv92Qlp888aKfOTOHtcWbrck4ee1Idk=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kDrFx9ilh3ueYD2we/TWQsX76MbCR4YNLJIJb+v1RXfDJ7ykBCL8B2yPLFQqospuBcDig8gVrs+UdBE/kbv32Y9MFNDaUoRVJHBSV3u79A9uBc4JDma2AVa5ozl5+f6gKY4sws2xyCpl1stLqEYWdu4oWCsadLrPRm6NIXc/6fk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=IgWxomVA; arc=none smtp.client-ip=198.175.65.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709078418; x=1740614418; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=tbwiqecWv333Dv92Qlp888aKfOTOHtcWbrck4ee1Idk=; b=IgWxomVA9fj3D7qjH0m+t8Bx7s7mtjbs5BPvr0NU1cLzweckt0XCfznt uIKiwPqxuDrb/c8RCadjIiFDUpNt+YnY+vid2R8vtX9s941KjxU2o2LNX XdttJJt5VADq8q8QECDcrPn2wMV0eIOidHnm+7bYZSN82ByANYDrbtOp0 HCSo+h1bdr7jumr1RvmLApHsz4w2czrljefzPLCY43BoM4CHwO33URepg WeEccyMNdhkTP5Mgtaie8Rm3f1daSWScm8LvnWkqq5LJFiB488tsXEZ0F H+V1N/NZ41xOMyk5b5BHvz+VBwRhLRsoH5HuhEJ9/YkXXD0/QrrSuu7u7 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="14604935" X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="14604935" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 16:00:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="7176939" Received: from linux.intel.com ([10.54.29.200]) by orviesa010.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 16:00:17 -0800 Received: from debox1-desk4.lan (unknown [10.251.6.149]) by linux.intel.com (Postfix) with ESMTP id A789B580D7F; Tue, 27 Feb 2024 16:00:16 -0800 (PST) From: "David E. Box" To: david.e.box@linux.intel.com, rajvi.jingar@linux.intel.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com Subject: [PATCH V2 2/9] platform/x86/intel/sdsi: Combine read and write mailbox flows Date: Tue, 27 Feb 2024 16:00:09 -0800 Message-Id: <20240228000016.1685518-3-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228000016.1685518-1-david.e.box@linux.intel.com> References: <20240228000016.1685518-1-david.e.box@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The current mailbox commands are either read-only or write-only and the flow is different for each. New commands will need to send and receive data. In preparation for these commands, create a common polling function to handle sending data and receiving in the same transaction. Signed-off-by: David E. Box --- V2 - In sdsi_cmd_read() remove unnecessary check for non-zero packet_size in do loop since the loop is exited earlier when packet_size is zero. drivers/platform/x86/intel/sdsi.c | 79 +++++++++++++++++-------------- 1 file changed, 44 insertions(+), 35 deletions(-) diff --git a/drivers/platform/x86/intel/sdsi.c b/drivers/platform/x86/intel/sdsi.c index a70c071de6e2..d80c2dc0ce71 100644 --- a/drivers/platform/x86/intel/sdsi.c +++ b/drivers/platform/x86/intel/sdsi.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -156,8 +157,8 @@ static int sdsi_status_to_errno(u32 status) } } -static int sdsi_mbox_cmd_read(struct sdsi_priv *priv, struct sdsi_mbox_info *info, - size_t *data_size) +static int sdsi_mbox_poll(struct sdsi_priv *priv, struct sdsi_mbox_info *info, + size_t *data_size) { struct device *dev = priv->dev; u32 total, loop, eom, status, message_size; @@ -166,18 +167,10 @@ static int sdsi_mbox_cmd_read(struct sdsi_priv *priv, struct sdsi_mbox_info *inf lockdep_assert_held(&priv->mb_lock); - /* Format and send the read command */ - control = FIELD_PREP(CTRL_EOM, 1) | - FIELD_PREP(CTRL_SOM, 1) | - FIELD_PREP(CTRL_RUN_BUSY, 1) | - FIELD_PREP(CTRL_PACKET_SIZE, info->size); - writeq(control, priv->control_addr); - /* For reads, data sizes that are larger than the mailbox size are read in packets. */ total = 0; loop = 0; do { - void *buf = info->buffer + (SDSI_SIZE_MAILBOX * loop); u32 packet_size; /* Poll on ready bit */ @@ -195,6 +188,11 @@ static int sdsi_mbox_cmd_read(struct sdsi_priv *priv, struct sdsi_mbox_info *inf if (ret) break; + if (!packet_size) { + sdsi_complete_transaction(priv); + break; + } + /* Only the last packet can be less than the mailbox size. */ if (!eom && packet_size != SDSI_SIZE_MAILBOX) { dev_err(dev, "Invalid packet size\n"); @@ -208,9 +206,13 @@ static int sdsi_mbox_cmd_read(struct sdsi_priv *priv, struct sdsi_mbox_info *inf break; } - sdsi_memcpy64_fromio(buf, priv->mbox_addr, round_up(packet_size, SDSI_SIZE_CMD)); + if (info->buffer) { + void *buf = info->buffer + array_size(SDSI_SIZE_MAILBOX, loop); - total += packet_size; + sdsi_memcpy64_fromio(buf, priv->mbox_addr, + round_up(packet_size, SDSI_SIZE_CMD)); + total += packet_size; + } sdsi_complete_transaction(priv); } while (!eom && ++loop < MBOX_MAX_PACKETS); @@ -230,16 +232,33 @@ static int sdsi_mbox_cmd_read(struct sdsi_priv *priv, struct sdsi_mbox_info *inf dev_warn(dev, "Read count %u differs from expected count %u\n", total, message_size); - *data_size = total; + if (data_size) + *data_size = total; return 0; } -static int sdsi_mbox_cmd_write(struct sdsi_priv *priv, struct sdsi_mbox_info *info) +static int sdsi_mbox_cmd_read(struct sdsi_priv *priv, struct sdsi_mbox_info *info, + size_t *data_size) +{ + u64 control; + + lockdep_assert_held(&priv->mb_lock); + + /* Format and send the read command */ + control = FIELD_PREP(CTRL_EOM, 1) | + FIELD_PREP(CTRL_SOM, 1) | + FIELD_PREP(CTRL_RUN_BUSY, 1) | + FIELD_PREP(CTRL_PACKET_SIZE, info->size); + writeq(control, priv->control_addr); + + return sdsi_mbox_poll(priv, info, data_size); +} + +static int sdsi_mbox_cmd_write(struct sdsi_priv *priv, struct sdsi_mbox_info *info, + size_t *data_size) { u64 control; - u32 status; - int ret; lockdep_assert_held(&priv->mb_lock); @@ -256,20 +275,7 @@ static int sdsi_mbox_cmd_write(struct sdsi_priv *priv, struct sdsi_mbox_info *in FIELD_PREP(CTRL_PACKET_SIZE, info->size); writeq(control, priv->control_addr); - /* Poll on ready bit */ - ret = readq_poll_timeout(priv->control_addr, control, control & CTRL_READY, - MBOX_POLLING_PERIOD_US, MBOX_TIMEOUT_US); - - if (ret) - goto release_mbox; - - status = FIELD_GET(CTRL_STATUS, control); - ret = sdsi_status_to_errno(status); - -release_mbox: - sdsi_complete_transaction(priv); - - return ret; + return sdsi_mbox_poll(priv, info, data_size); } static int sdsi_mbox_acquire(struct sdsi_priv *priv, struct sdsi_mbox_info *info) @@ -313,7 +319,8 @@ static int sdsi_mbox_acquire(struct sdsi_priv *priv, struct sdsi_mbox_info *info return ret; } -static int sdsi_mbox_write(struct sdsi_priv *priv, struct sdsi_mbox_info *info) +static int sdsi_mbox_write(struct sdsi_priv *priv, struct sdsi_mbox_info *info, + size_t *data_size) { int ret; @@ -323,7 +330,7 @@ static int sdsi_mbox_write(struct sdsi_priv *priv, struct sdsi_mbox_info *info) if (ret) return ret; - return sdsi_mbox_cmd_write(priv, info); + return sdsi_mbox_cmd_write(priv, info, data_size); } static int sdsi_mbox_read(struct sdsi_priv *priv, struct sdsi_mbox_info *info, size_t *data_size) @@ -342,7 +349,7 @@ static int sdsi_mbox_read(struct sdsi_priv *priv, struct sdsi_mbox_info *info, s static ssize_t sdsi_provision(struct sdsi_priv *priv, char *buf, size_t count, enum sdsi_command command) { - struct sdsi_mbox_info info; + struct sdsi_mbox_info info = {}; int ret; if (count > (SDSI_SIZE_WRITE_MSG - SDSI_SIZE_CMD)) @@ -364,7 +371,9 @@ static ssize_t sdsi_provision(struct sdsi_priv *priv, char *buf, size_t count, ret = mutex_lock_interruptible(&priv->mb_lock); if (ret) goto free_payload; - ret = sdsi_mbox_write(priv, &info); + + ret = sdsi_mbox_write(priv, &info, NULL); + mutex_unlock(&priv->mb_lock); free_payload: @@ -408,7 +417,7 @@ static ssize_t certificate_read(u64 command, struct sdsi_priv *priv, char *buf, loff_t off, size_t count) { - struct sdsi_mbox_info info; + struct sdsi_mbox_info info = {}; size_t size; int ret; -- 2.34.1