Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp831599rdb; Sun, 18 Feb 2024 14:21:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVaUeHpDz1Lm4oiUlrArax/xYMbq0XNePREunIUkU+w15VyhjHrArpKpXzR18xC2kk54j3+FzkUPl2Wb7w7r/l+M5mqwlqSA/uJ8y+aPA== X-Google-Smtp-Source: AGHT+IFS2Ewh/atCPYym1U5Bk7sFwvkoVSrcqKthKWPczQZhvs0FtxUA2sdiw8oc6DkghgJKgjuw X-Received: by 2002:aa7:d917:0:b0:55f:e936:b495 with SMTP id a23-20020aa7d917000000b0055fe936b495mr7550644edr.0.1708294881721; Sun, 18 Feb 2024 14:21:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708294881; cv=pass; d=google.com; s=arc-20160816; b=eMqmILoc8RYHt4cZgyKOjFcXPM6JJ0WMi4P7mOHGNSLYTe1BIuF4OabK0NoNXsYLlU FVii8iCJ1yJgMWblNYfwKufVwhsSYw2mCmUWYuvO/Juxlab6TQowKbt4pVPyvhX3AgFf wir9FeUXiPnJNRqewRGDjcBGQbEwNN2F4wIdKIf6JXpZBVVun+Kf6sxM7NK/8gx587sW 8hZ/ymh8JCx0nCPIQNVVhMGQhn89o9a3SbpjHMVcPneQFkfvtvOzCItmkoioiihvawCH 0auluKw7S/D+MHoafvaTyVeQwpdpggNOVWhDvLnJhObRikcuQtN1xgIzUBw3cvXXSat+ 0xyg== 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:message-id:date:subject:cc:to :from; bh=uisxB3KZTpbJHIgWb4ozJcvFaJBCxtzvuKE83xRCESc=; fh=NZYqj9rN7CYKDURs9gmqF/Q4C0zz9wOO6FGPGe/FaIo=; b=DkR9GRX6nFEsyHPAI9ykQRYrbl2G8V6m0cXy3+6v0r8UU7VCNbd3QUZ5mKEp3A4DCY mQVSSIXMgz7sDv/Q2XEKQF7vKUb9jGG1oi5mxNrypM7kXeIT9PR76v1jGHYs/pyenrXp VpwIMNHJcptS0egaSmxvIFa8iPd6DKZ6DU5iZiKWEU2eieG8Nf3JAnuUI2cjjVyO+GtJ 5+oyoXj1g3i0eA+67T6sF3nA/2KLeDtTNRGeeAXVWB3PPsdz71U4JlB9J+qhykcPxpoG tQeODzjybdvA3Rtq+WizbwHanLZ9D2JndqsUdFHDxZ2GPB8PHcRFS/RGOo8ZD5jboI53 qadQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=c--e.de); spf=pass (google.com: domain of linux-kernel+bounces-70605-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70605-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id r9-20020a50d689000000b0056484c0df71si64284edi.542.2024.02.18.14.21.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 14:21:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70605-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=c--e.de); spf=pass (google.com: domain of linux-kernel+bounces-70605-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70605-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 7BD9B1F212B9 for ; Sun, 18 Feb 2024 22:21:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 24AF2745DE; Sun, 18 Feb 2024 22:21:12 +0000 (UTC) Received: from cae.in-ulm.de (cae.in-ulm.de [217.10.14.231]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BF23A71B41; Sun, 18 Feb 2024 22:21:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.10.14.231 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708294871; cv=none; b=LIv1Da+xY+nagFyKHZe6mOtlU/5pY7kSyWkvhrjqJRNUDKzBxHqZKrvEf9EW9uVFXirkGor/FuJjUtDgcavIR8+1kaaST1bL+CynycbAHaWws+uBC7ArpQAZXfiFWnC2njuvaGAp+iHkwca7dpqVtOZrMWv4MDY3iF2tmSQZvUA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708294871; c=relaxed/simple; bh=BRwcKCBkoqF12N4ufDpMcCEgTArkJnOd7MPeSkn/5No=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=qY3ErrK8Mm8AvLzJA5B8Ui6e28IgUIjf4HxyXlh41EiaUTEUlyg8moSacjmMFmAf/QQixBeydfqUSENf1yFlxYnkD1EDLXMMbPkdXDNnZMu7jP8c3LkuaGay8/5y/TpuuBD4fNwk5OJ+brsvgzgO5Vkyde0LIPpFt+eWYqTpmx8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=c--e.de; spf=pass smtp.mailfrom=c--e.de; arc=none smtp.client-ip=217.10.14.231 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=c--e.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=c--e.de Received: by cae.in-ulm.de (Postfix, from userid 1000) id E5249140229; Sun, 18 Feb 2024 23:21:00 +0100 (CET) From: "Christian A. Ehrhardt" To: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Christian A. Ehrhardt" , Heikki Krogerus , Greg Kroah-Hartman , Maxime Coquelin , Alexandre Torgue , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , =?UTF-8?q?Samuel=20=C4=8Cavoj?= , Hans de Goede , Neil Armstrong , Prashanth K , Dmitry Baryshkov , Saranya Gopal , Haotien Hsu , Andy Shevchenko , Utkarsh Patel , Bjorn Andersson , Luca Weiss , Min-Hua Chen , Rob Herring , Rajaram Regupathy , linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, Abhishek Pandit-Subedi Subject: [RFC PATCH 0/6] UCSI backend API refactoring Date: Sun, 18 Feb 2024 23:20:33 +0100 Message-Id: <20240218222039.822040-1-lk@c--e.de> X-Mailer: git-send-email 2.30.2 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 (new) API for UCSI backends has some problems: The UCSI spec assumes a mailbox style communication: 1. The OPM fills data (UCSI_MESSAGE_OUT and UCSI_CONTROL) into the mailbox memory region. In the ACPI case these are simple host memory accesses. 2. The OPM notifies the PPM that a command should be executed. In the ACPI case this is a call the _DSM ACPI function. Within that function the UCSI_CONTROL and the UCSI_MESSAGE_OUT data is transferred to something like the embedded controller and then the PPM is notified e.g. by an SMI. 3. The PPM executes the command. As a result UCSI_MESSAGE_IN and UCSI_CCI in the mailbox memory are updated and the OPM is notified. In the ACPI case the notification is an SCI and ACPI provides a handler that syncs UCSI_MESSAGE_IN and UCSI_CCI from the EC into host memory before notifying the OPM via the ACPI Notify() command. The major problem is that steps 1 (update mailbox memory) and step 2 (notify PPM and start command execution) are two different steps. The current API only knows about a write function that combines writing to mailbox memory and starting command execution. This only works as long as the commands do not have arguments that must be in UCSI_MESSAGE_OUT. Additionally, Step 3 (at least in the ACPI case) above suggests that UCSI_CCI and UCSI_MESSAGE_IN should generally be read from mailbox memory. Except for some special cases the sync operation via the _DSM-Read function in ACPI is not required and seems to do more harm then good. E.g. the zenbook quirks could be avoided if we didn't re-read the UCSI_CCI and UCSI_MESSAGE_IN data from the embedded controller on each read operation. The recent fix to the CCG backend seems to address the same issue. This change series proposes a new API with the following design goals: - Retain the nice features of the previous API redesign. In particular the synchronous execution of commands in the backend and the ability to handle quirks there. - The API must still be able to handle all backends (obviously). Thus each new API function is currently implemented in all backends in the same change. - Separate writing to mailbox data and starting command execution to allow for commands with UCSI_MESSAGE_OUT data. - Avoid hardware accesses (as opposed to mailbox memory accesses) outside of the command execution context as much as possible. - Avoid use of explicit mailbox offsets (that are subject to change with later UCSI revisions) in the UCSI core. The proposed new API features: - read_data() and write_data() for access to the message data fields. This is supposed to be a pure mailbox access that even in the case of a write does not start a command. - sync_cmd() and async_cmd() to write the command register and start command execution. - A cached version of the current contents of CCI in the core UCSI structure. This value is only updated if a notification is received from the hardware. - poll_cci() to force an update of the cached CCI value from hardware. This is required to poll for PPM reset completion. CAVEATs: - The series will certainly need more polishing etc. before it can be accepted. I will do this provided that the series is considered a good idea in general. - The series compiles, passes smatch, sparse and checkpatch but I only have ucsi_acpi hardware to test this. The other backends (ccg, glink, stm32g0) will need testers and likely some fixes as well. So, what do you think? Christian A. Ehrhardt (6): usb: ucsi_glink: Fix endianness issues ucsi_ccg: Cleanup endianness confusion usb: typec: ucsi: Make Version a parameter to ucsi_register usb: typec: ucsi: Cache current CCI value in struct ucsi usb: typec: ucsi: Introdcue ->read_data and ->write_data usb: typec: ucsi: Convert a?sync_write to a?sync_cmd drivers/usb/typec/ucsi/ucsi.c | 53 ++++-------- drivers/usb/typec/ucsi/ucsi.h | 28 +++--- drivers/usb/typec/ucsi/ucsi_acpi.c | 119 ++++++++++++-------------- drivers/usb/typec/ucsi/ucsi_ccg.c | 107 ++++++++++++----------- drivers/usb/typec/ucsi/ucsi_glink.c | 104 +++++++++++++++++----- drivers/usb/typec/ucsi/ucsi_stm32g0.c | 80 ++++++++++++++--- 6 files changed, 290 insertions(+), 201 deletions(-) -- 2.40.1