From patchwork Sun Feb 18 22:20:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Christian A. Ehrhardt" X-Patchwork-Id: 20570 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp972187dyc; Sun, 18 Feb 2024 14:21:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWkPvsX8fkenvn5zBI7i3qhZKF8F0QP/pteWKUphwAdRXpmk5fUxycqBs7Mqg07sHKDntYvhp7YzEaknx6QRVMuISJgjw== X-Google-Smtp-Source: AGHT+IFXy3dMOtBTZLbehDPL+grVb9Hr86/bUt3CObQC/fZOLHhaz1pgsPhlek2XmGegzaltftGh X-Received: by 2002:a19:ae09:0:b0:512:b3d3:44fe with SMTP id f9-20020a19ae09000000b00512b3d344femr456807lfc.0.1708294899093; Sun, 18 Feb 2024 14:21:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708294899; cv=pass; d=google.com; s=arc-20160816; b=tHkC5Rr1aAW6hkgNyYc9r0tMMXbHMIrZHSKcgVoRWOWzhyOgDh0g6e4m4YC6jTiviK GnpCHzJ6PHsZmhCs3sXpW8gbiWri4cYzJ25iDQog0lINeUUjZuLsUQSKYwT7s4onD5NY YXMsl0m5sYsBiIo1cWcmHoO1xzhZx+MMm56TysAp2lYXoRPFe8QoERlr4fUhvODq9nSj iV/8mD5b6f7B2AOn9YDOkywevvbswgI1MHUyaAm2BcKjTPMeLCJ+GZovSs9T+i/kwVIy SH3Um++NQAoluU03sFxi9btUoSCHk/jHk6I9WoBY/2A3LjVxBm8NwgFPw4cuhwAayWMS ZkCw== 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70605-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id h20-20020a170906591400b00a3e256e95c9si1505762ejq.1022.2024.02.18.14.21.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 14:21:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70605-ouuuleilei=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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70605-ouuuleilei=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 597F51F21704 for ; Sun, 18 Feb 2024 22:21:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 95F8A74E21; Sun, 18 Feb 2024 22:21:13 +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_Kleine-K?= =?utf-8?q?=C3=B6nig?= , =?utf-8?q?Samuel_?= =?utf-8?q?=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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791277031777110519 X-GMAIL-MSGID: 1791277031777110519 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(-)