Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2301994rbb; Tue, 27 Feb 2024 18:38:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWqRYrSjOpjD8ryK5g/lg4NEQd4N+On7gOYbkVdDKO/nqtLWnuo7n9uVE69xqGsejx40RrNw7cUg2YKqOZ/QGcU4V+bNg6oIjEj2Au2OA== X-Google-Smtp-Source: AGHT+IG0SDWLcHiNsJcKuhOsLpZsn8QdCNqLYY3akapq8GOPpRu7ZPb65pH7v4uiwS8/9l0cJJmJ X-Received: by 2002:a17:902:da8e:b0:1dc:b739:353f with SMTP id j14-20020a170902da8e00b001dcb739353fmr4709269plx.29.1709087928034; Tue, 27 Feb 2024 18:38:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709087928; cv=pass; d=google.com; s=arc-20160816; b=qXTD/eH+oHjDj1srNcfP466d5Lnb2lEg3SBvDdovYh3jtnCr4uPPh2mVmhShFZQGz9 W8NE62KvK1A4sI+nEAeuKHnHHs2z62RyTn9hkmIbDSevyyP3M7sHrWKDuVhHWjGcN6ny GrEr9A4XvtGgWuF/NcUI0TEcVoDBUYfWJYcL9JqOBMUVuuyz58DaoFEgddDAGtUFWx9Y mxsbOAJOWwDdAdXxFl4w1ai2a5HxRN76rkE5bU9CdYnTNS/qUkj/17r6KJPtfqa14gJl 1BHHx6NTw3lkaYVAXgT6E9q1FIJqUgOyUe2nMYo0NsCCo6KAfBBQ20pkqm1B0oxqlQ+J CV2Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=cLqTFY5CV4LFXbXU1I4nLrhrhqYscn/Cbiw9v99+Xe0=; fh=uWu9MeyGkywR165s6yDWPgkXRNiae1Qrt207vzeAVio=; b=uu70+i1TPivQSrBPi/C2xp+SiPNyFHHC5xdUUkgD1RG7axZVn+zsEHUREzsYn4WCbg qr54ijOud0KlpyGPVBB/gvclzw5tA4I/xxAP7teJImzxsc2RiEB4FxSyFjdbkMF3Qv1K s0FRRkYWJ2tbqe5HJfUdeml35GB4p7jJXmvFYiEdtkPjq11KMrCg8ipkxZjuRJ1EK5yb QNEtbTxl4rJq2NkVaU/Rp5Yc7kRDzhsuBfbV4fnQNBSYDpvnWQZ1gKw80oobD4vH4WAv Z6eaFFxgTrirkqFRdzUYsxUH7ZOktY/zTt65T96PC/kSsIPgef8zOHHrfwbViVXaa3hX RZYw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=a9rfGTWA; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84422-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84422-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id b17-20020a170902d51100b001db78534cd4si2541401plg.256.2024.02.27.18.38.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 18:38:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84422-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=a9rfGTWA; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84422-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84422-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B3F462893B3 for ; Wed, 28 Feb 2024 02:38:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 425B51CD1C; Wed, 28 Feb 2024 02:38:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="a9rfGTWA" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (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 539D96AC2; Wed, 28 Feb 2024 02:38:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709087920; cv=none; b=jAUiMxy0N8gxgl3W6Ewvuu0oj96Af6BjKY4EsGAG8QQPAYCbEe7X7JD8Ive+rcaDLwDjwhLMtR1MiERxXRFidRbGReRU/peQ5THiMCQ748stNyBcyUx6ndJ4xZEBIUTdAVcrdm3DhQbCe8EFGCz3wczCKiwqZTvP4m3fs0nWgVI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709087920; c=relaxed/simple; bh=U8CSEd+TWH7dbfDiJ06PXYpZl5tcTmg25bXNDIew5KA=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=rjA9g8HB3r5NHZi8xYGCLBrrXh62UOgiSEHfVV2/iGL1bEZkHu6+JtaIPwf6D6SoE6zKimfb7Upn8TXRseuSi5StrvilvEoud5AXjLFKNvpV4TooQNCHtN1oZVmjKpqUvy04n0hAs3ec8tW3wfQp2Ao5sMpO7uV5aT3zsExUuIw= 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=a9rfGTWA; arc=none smtp.client-ip=198.175.65.20 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=1709087919; x=1740623919; h=message-id:date:mime-version:subject:to:references:from: in-reply-to:content-transfer-encoding; bh=U8CSEd+TWH7dbfDiJ06PXYpZl5tcTmg25bXNDIew5KA=; b=a9rfGTWALqL5RwoH57UV9aJmA18rB5GhPhpkSw3bucyZitKZzVp/G6e9 YXfGd0fmCC8vOEzHzUxTfwvp80lYMFPf9K+7d3jV6L26RrwoMbBKwegUn sNDb61rOQzVDyVI9uhgtFoJOpCxA7UV6kcLZgkHngDoiWro3v8GPrZk1Q quMt3ddz9aBTn/eVI3hANrAMddtQNORQxDjcoblzjl3ct88l2vXMgp3Yt NTWktFlUUorr4AnjJOka51KYyY7m7cQO3Fho/7dKjr88E0fqO1rXzVgvv yEs7UBXbkjneJRc8l7w0A09w2FPVn9+b7QFfvgX3W62xDCHAnm4zEYTVR Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3337488" X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="3337488" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 18:38:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="7831175" Received: from dschro4x-mobl.amr.corp.intel.com (HELO [10.212.137.190]) ([10.212.137.190]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 18:38:38 -0800 Message-ID: Date: Tue, 27 Feb 2024 18:38:37 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH V2 2/9] platform/x86/intel/sdsi: Combine read and write mailbox flows Content-Language: en-US To: "David E. Box" , rajvi.jingar@linux.intel.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com References: <20240228000016.1685518-1-david.e.box@linux.intel.com> <20240228000016.1685518-3-david.e.box@linux.intel.com> From: Kuppuswamy Sathyanarayanan In-Reply-To: <20240228000016.1685518-3-david.e.box@linux.intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 2/27/24 4:00 PM, David E. Box wrote: > 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; > Is there a chance for it to be NULL with current callers? > 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; > -- Sathyanarayanan Kuppuswamy Linux Kernel Developer