Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1315763pxb; Tue, 8 Feb 2022 14:29:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJymmPyGbr246MLJNytbKEqf3dhkhoaX/kzke7JpF6WiDRPCrYhLoq/QW7I/yP1gq+sD/mxd X-Received: by 2002:aa7:938c:: with SMTP id t12mr6330301pfe.51.1644359387478; Tue, 08 Feb 2022 14:29:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644359387; cv=none; d=google.com; s=arc-20160816; b=cEUmywp2VBeu8/9YQKA774QI2VFwtt5jVfkVSVo5Fcw9dxH+zmNtLeCXCNW96sE37G Kkaz09JOZnxCZWNoeQHqm0a+y4+rluSk5T+b/IqLsdZkEyLbKqrXqFQ7gOyHVF5ga0Pg HV/o+HZ97z+kjX02lvHrpvqDHd+ViVTJnNSMeGTjC0l8MZzuui2sO20kyBdY2ccacVbQ GbSl5PnAjuVdvLyXXXxoxW+aVAL/A2OM5Z5nvONhbuvLwhhE+74CZuniaGtL+rey8JJE 41nlosOeknTELQDWPnYLwUXLToycMYBgKbHhcXvTOsAjyzqtUdKhHKc26jBtScAlrb7D IfZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=OLS1qG2/31/qv95jBrunYz8W6LmWRIuON498ceRNCdU=; b=l6N9kjP0rd3/2YONGQra+nxa/TEp1U0n1kg/OX4vRXcIvLzkoSTobP9z8vUrhV2oXD gjl7eFKWLiwY8N636uxW2R0t3uT20kYvyQfF1VLlNAONpiBw20mE48IoPwepp3wSwFwO C2WihZM04tQYDnYpGRowevVVslRyEKVW15Qt8PNwbsoDqlPpc4404Q8Ev3Dsux5WocrN n9wmPw4T+4J1tR88JHo+8yr86unue2JfvSdWbjKDRGabeZpjOSrkIEuNlauWMsc+KmAP pky974yEue+PK8S5nJqNvIULa019Q7rxUUBZwul+3TRGW1LSy0q8wtob1/pPGqRHicTv 3ZGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="Q/LnvOvx"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ha2si3973673pjb.70.2022.02.08.14.29.34; Tue, 08 Feb 2022 14:29:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="Q/LnvOvx"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346585AbiBHGM0 (ORCPT + 99 others); Tue, 8 Feb 2022 01:12:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346513AbiBHGMX (ORCPT ); Tue, 8 Feb 2022 01:12:23 -0500 Received: from mail-yb1-xb34.google.com (mail-yb1-xb34.google.com [IPv6:2607:f8b0:4864:20::b34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F7D8C0401EF for ; Mon, 7 Feb 2022 22:12:23 -0800 (PST) Received: by mail-yb1-xb34.google.com with SMTP id bt13so22934187ybb.2 for ; Mon, 07 Feb 2022 22:12:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=OLS1qG2/31/qv95jBrunYz8W6LmWRIuON498ceRNCdU=; b=Q/LnvOvx7/obZ/wdiMqJNB/3sgZQ9TkVmhG8RJcQVbM/RAJKOyeUZsThaytxw5LwRG F0V7L/LF99sYMeIGsXtarFL53NlT+j40Yr4IR7/XK32DqxUEfzvupmSYQI5knbiAtdiE hbR1SIKE7mb3cRGGQMy4PnupF1nHo56/yPtzo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=OLS1qG2/31/qv95jBrunYz8W6LmWRIuON498ceRNCdU=; b=EhDtJyKM2cp8ZgtiXNbLwnyayTNLk7MFRitVie/wECYXi0O3NGs261P35fO+53rIXd u6tbYm//jT0kXZnsEToIlwntc3CP9zU2l0U/6sbpaqCf60uwp9nkDqczZeGL6RKCokNE e7km6CV2ZQkBrSdrBM8Z+QK9BpbkZt+QqX6RVlXxoIqXjMnjZ0mSBHu+k+DABNneh48P 6RrAdw9LsOyov9VeLYk98rudZkaN6W6ETdjdhzbBjBT5JJJDYe6aZWL7FNXhJAPAPw7r BSX3xsMVZiImH54bW5LMHc1nNwDkV7vIGzGZRD0O6OGwj4Bk0r7RFKFbpQ2+hqDq9jRm Rvlw== X-Gm-Message-State: AOAM530INPhzSz15TxQml/lUdKcrWBidXh0oYHhqLj3L9YN38UI5WSOD fPNUc58rWf0CyVrW5wz7GDRJKlxX8iNuwqiL+h98yA== X-Received: by 2002:a25:be43:: with SMTP id d3mr3156548ybm.454.1644300742373; Mon, 07 Feb 2022 22:12:22 -0800 (PST) MIME-Version: 1.0 References: <20220207214026.1526151-1-pmalani@chromium.org> <20220207214026.1526151-4-pmalani@chromium.org> In-Reply-To: From: Prashant Malani Date: Mon, 7 Feb 2022 22:12:10 -0800 Message-ID: Subject: Re: [PATCH 3/4] platform/chrome: cros_ec_typec: Configure muxes at start of port update To: Tzung-Bi Shih Cc: linux-kernel@vger.kernel.org, Benson Leung , Guenter Roeck , "open list:CHROMEOS EC USB TYPE-C DRIVER" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Tzung-Bi, On Mon, Feb 7, 2022 at 9:38 PM Tzung-Bi Shih wrote: > > On Mon, Feb 07, 2022 at 09:40:28PM +0000, Prashant Malani wrote: > > There are situations where the mux state reported by the Embedded > > Controller (EC), might lag the partner "connected" state. So, the mux > > state might still suggest that a partner is connected, while the PD > > "connected" state, being in Try.SNK (for example) suggests that the > > partner is disconnected. > > > > In such a scenario, we will end up sending a disconnect command to the > > mux driver, followed by a connect command, since the mux is configured > > later. Avoid this by configuring the mux before > > registering/disconnecting a partner. > > I failed to understand the description. It looks like some protocol details. > Could you provide some brief explanation in the commit message? I'm not sure how else I can better elaborate on this in the commit message than as currently stated. Since the EC is an independent controller, the mux state *can* lag the "connected" state. So, as described in the commit message, when a disconnect happens, we could have a disconnect (since PD_CTRL contains the "connected state") followed by a configure_mux with the mux state still suggesting a connected device (the drivers which implement the mux/switch controls can misconstrue the old mux state) which results in a connect. This patch eliminates that. > > On a related note, followed up the example scenario, which one of the > understanding is the most applicable: > 1) The disconnect followed by a connect is suboptimal. The patch cleans it. > 2) The disconnect followed by a connect is a bug. The patch fixes it. This one (number 2) > > > @@ -965,6 +965,11 @@ static int cros_typec_port_update(struct cros_typec_data *typec, int port_num) > > if (ret < 0) > > return ret; > > > > + /* Update the switches if they exist, according to requested state */ > > + ret = cros_typec_configure_mux(typec, port_num, &resp); > > + if (ret) > > + dev_warn(typec->dev, "Configure muxes failed, err = %d\n", ret); > > It used the fact that the function returns `ret` at the end. After the move, > the block is no longer the last thing before function returns. > > Does it make more sense to return earlier if cros_typec_configure_mux() fails? > Does the rest of code need to be executed even if cros_typec_configure_mux() > fails? Yes, it should still be executed (we still need to update the port state). That is why the return is eliminated. > > > @@ -980,11 +985,6 @@ static int cros_typec_port_update(struct cros_typec_data *typec, int port_num) > > if (typec->typec_cmd_supported) > > cros_typec_handle_status(typec, port_num); > > > > - /* Update the switches if they exist, according to requested state */ > > - ret = cros_typec_configure_mux(typec, port_num, &resp); > > - if (ret) > > - dev_warn(typec->dev, "Configure muxes failed, err = %d\n", ret); > > - > > return ret; > > If the function decides to return earlier, it can be `return 0;`. Sure, I can change this in the next version