Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp83382lqh; Wed, 27 Mar 2024 15:48:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVaOpyKaTeU8sJTTn6pLAKRWE0neSnrCN9qPM5v/r5RHx/Jj7r6189WWPwVDWgFcEccvinQRjfeB1vn7ndjNILqXk/i+BJE/3jOvHCX/Q== X-Google-Smtp-Source: AGHT+IEE+dRWEr/PtEOYDMRR9+5vi3zhskt6OOv8uB0w6cijEk/eF3h5rVLknxcF3ZE7p9enh/pF X-Received: by 2002:a17:903:8c5:b0:1de:e84b:74e1 with SMTP id lk5-20020a17090308c500b001dee84b74e1mr1341958plb.29.1711579707948; Wed, 27 Mar 2024 15:48:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711579707; cv=pass; d=google.com; s=arc-20160816; b=ojAvB4r/cZ8eGv3GHh183rq0uJObGQM8kLbnfzkjPmlm21QdmTtiTvLvl5lLC64/sM BuW0/8cc6aHd4MkwunJ96VrC4MnPG+MBiLDBPIfGPT+SENNpAZmKHbRYYcl9bTRQyqS5 CjkzgXl3L2UDqPbfstCxBu7I2MS3Th0kAz0zgCDnQIBoBZ6YGkQNGHxuvPJkleWQGBto I6gNfGJ54NZDp2/FBnDfGz5IYFl6JZ9bfLAhbK6b2apY5Xi8BbX0WCNOl9It1DyFIiTY tmP6Dj32v7GxXBnYND+oYW5o1vOxHHnEC7lQ9aJ5VD09m7iqKZinheYRKiP2rD0eKeYW zhVA== 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:cc:to:from; bh=VbkfsCRu91EZbPBCzIQaeEenXXgMY8Q9swqRWNb0CxI=; fh=V/ZqdMDaoW+4gUs64XaII0UfQ3sY4dKTrFRB3/bG0Zs=; b=wcW2Wltju96lfQH7V62XSQ12Hq79Q5C27JAJZF93viMmv68cO49uiOSh3moNLXW2Aw NC31DkSte3NgleoGlnVNqIHUynMoahwiOcgP4prxYM4s9vfe6TI0CCuV1mYRP5WadAyc +xnaHEuyja8PguShv+MgvTWY4QmE7aCb+mTNYhLPSNM/n9Qv24rlJhH13Xi+gPhtj8NF 4pPT0iMNH35t5M9fEXm7TOVzQNGCPhqqjqcMvtJlCZJ0O3AOnBO/Nek3NxiKbGrqzzvD 3Fr0c+4h1nSGkB7bknaBtVmC6VS8cpbkhgES5LIGL9Ju7x9ESzWJXV9dMbLZMm2B1QVS tDSQ==; 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-122114-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122114-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id lw6-20020a1709032ac600b001e0cd73e1a6si87858plb.308.2024.03.27.15.48.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 15:48:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-122114-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=c--e.de); spf=pass (google.com: domain of linux-kernel+bounces-122114-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122114-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 213AAB23C72 for ; Wed, 27 Mar 2024 22:46:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C6120154446; Wed, 27 Mar 2024 22:46:24 +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 015E9153822; Wed, 27 Mar 2024 22:46:20 +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=1711579584; cv=none; b=GCImtAUU0GmuEhiY7Y4tjIeulJhl+1yY2gVm0fMiXscvkZZZqYnaJ4ytfFZHzGol1ErO2WTbmTdUmNFh4AD4/jTk5ph/okEKX7nqtWqAHF/HodvhwiNVrG3P7sxQClRKJE41Fu51q9i3VR/xAdmesFG19p0WUgmzTuE+0FV5/Wo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711579584; c=relaxed/simple; bh=NDkRlF2/5vzs3/810luSDUIay1pqXOpyWDfGWEloJxs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=B1Ggk5jlHj8kTeCSQKJovrl2hIZ7zqZTmZGcx4i7jv59uW5awO7qDfOlm+7HkH5OTax7/gOEBgOEVVdP2QwKCaxd8Rl+hQXRIVJFd+BGkHmZ6ja6vTLvZMFdY+Gyd6j15Hb0GG5gXhZfB9Yi8srSJs802+8sGevRfy9AIG+YFmg= 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 1027914040D; Wed, 27 Mar 2024 23:46:20 +0100 (CET) From: "Christian A. Ehrhardt" To: linux-kernel@vger.kernel.org, Dmitry Baryshkov , Diogo Ivo Cc: "Christian A. Ehrhardt" , Heikki Krogerus , Greg Kroah-Hartman , Prashant Malani , Jameson Thies , Abhishek Pandit-Subedi , Neil Armstrong , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , =?UTF-8?q?Samuel=20=C4=8Cavoj?= , linux-usb@vger.kernel.org Subject: [PATCH 2/3] usb: typec: ucsi: Never send a lone connector change ack Date: Wed, 27 Mar 2024 23:45:53 +0100 Message-Id: <20240327224554.1772525-3-lk@c--e.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240327224554.1772525-1-lk@c--e.de> References: <20240327224554.1772525-1-lk@c--e.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Some PPM implementation do not like UCSI_ACK_CONNECTOR_CHANGE without UCSI_ACK_COMMAND_COMPLETE. Moreover, doing this is racy as it requires sending two UCSI_ACK_CC_CI commands in a row and the second one will be started with UCSI_CCI_ACK_COMPLETE already set in CCI. Bundle the UCSI_ACK_CONNECTOR_CHANGE with the UCSI_ACK_COMMAND_COMPLETE for the UCSI_GET_CONNECTOR_STATUS command that is sent while handling a connector change event. Signed-off-by: Christian A. Ehrhardt --- drivers/usb/typec/ucsi/ucsi.c | 48 +++++++++++++++-------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 31d8a46ae5e7..48f093a1dc09 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -49,22 +49,16 @@ static int ucsi_read_message_in(struct ucsi *ucsi, void *buf, return ucsi->ops->read(ucsi, UCSI_MESSAGE_IN, buf, buf_size); } -static int ucsi_acknowledge_command(struct ucsi *ucsi) +static int ucsi_acknowledge(struct ucsi *ucsi, bool conn_ack) { u64 ctrl; ctrl = UCSI_ACK_CC_CI; ctrl |= UCSI_ACK_COMMAND_COMPLETE; - - return ucsi->ops->sync_write(ucsi, UCSI_CONTROL, &ctrl, sizeof(ctrl)); -} - -static int ucsi_acknowledge_connector_change(struct ucsi *ucsi) -{ - u64 ctrl; - - ctrl = UCSI_ACK_CC_CI; - ctrl |= UCSI_ACK_CONNECTOR_CHANGE; + if (conn_ack) { + clear_bit(EVENT_PENDING, &ucsi->flags); + ctrl |= UCSI_ACK_CONNECTOR_CHANGE; + } return ucsi->ops->sync_write(ucsi, UCSI_CONTROL, &ctrl, sizeof(ctrl)); } @@ -77,7 +71,7 @@ static int ucsi_read_error(struct ucsi *ucsi) int ret; /* Acknowledge the command that failed */ - ret = ucsi_acknowledge_command(ucsi); + ret = ucsi_acknowledge(ucsi, false); if (ret) return ret; @@ -89,7 +83,7 @@ static int ucsi_read_error(struct ucsi *ucsi) if (ret) return ret; - ret = ucsi_acknowledge_command(ucsi); + ret = ucsi_acknowledge(ucsi, false); if (ret) return ret; @@ -152,7 +146,7 @@ static int ucsi_exec_command(struct ucsi *ucsi, u64 cmd) return -EIO; if (cci & UCSI_CCI_NOT_SUPPORTED) { - if (ucsi_acknowledge_command(ucsi) < 0) + if (ucsi_acknowledge(ucsi, false) < 0) dev_err(ucsi->dev, "ACK of unsupported command failed\n"); return -EOPNOTSUPP; @@ -165,15 +159,15 @@ static int ucsi_exec_command(struct ucsi *ucsi, u64 cmd) } if (cmd == UCSI_CANCEL && cci & UCSI_CCI_CANCEL_COMPLETE) { - ret = ucsi_acknowledge_command(ucsi); + ret = ucsi_acknowledge(ucsi, false); return ret ? ret : -EBUSY; } return UCSI_CCI_LENGTH(cci); } -int ucsi_send_command(struct ucsi *ucsi, u64 command, - void *data, size_t size) +static int ucsi_send_command_common(struct ucsi *ucsi, u64 command, + void *data, size_t size, bool conn_ack) { u8 length; int ret; @@ -192,7 +186,7 @@ int ucsi_send_command(struct ucsi *ucsi, u64 command, goto out; } - ret = ucsi_acknowledge_command(ucsi); + ret = ucsi_acknowledge(ucsi, conn_ack); if (ret) goto out; @@ -201,6 +195,12 @@ int ucsi_send_command(struct ucsi *ucsi, u64 command, mutex_unlock(&ucsi->ppm_lock); return ret; } + +int ucsi_send_command(struct ucsi *ucsi, u64 command, + void *data, size_t size) +{ + return ucsi_send_command_common(ucsi, command, data, size, false); +} EXPORT_SYMBOL_GPL(ucsi_send_command); /* -------------------------------------------------------------------------- */ @@ -1168,7 +1168,9 @@ static void ucsi_handle_connector_change(struct work_struct *work) mutex_lock(&con->lock); command = UCSI_GET_CONNECTOR_STATUS | UCSI_CONNECTOR_NUMBER(con->num); - ret = ucsi_send_command(ucsi, command, &con->status, sizeof(con->status)); + + ret = ucsi_send_command_common(ucsi, command, &con->status, + sizeof(con->status), true); if (ret < 0) { dev_err(ucsi->dev, "%s: GET_CONNECTOR_STATUS failed (%d)\n", __func__, ret); @@ -1225,14 +1227,6 @@ static void ucsi_handle_connector_change(struct work_struct *work) if (con->status.change & UCSI_CONSTAT_CAM_CHANGE) ucsi_partner_task(con, ucsi_check_altmodes, 1, 0); - mutex_lock(&ucsi->ppm_lock); - clear_bit(EVENT_PENDING, &con->ucsi->flags); - ret = ucsi_acknowledge_connector_change(ucsi); - mutex_unlock(&ucsi->ppm_lock); - - if (ret) - dev_err(ucsi->dev, "%s: ACK failed (%d)", __func__, ret); - out_unlock: mutex_unlock(&con->lock); } -- 2.40.1