Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp409397pxb; Wed, 13 Jan 2021 06:46:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJzQlGtwBYfu1JHon0JK+uOvhdRpliqsb3remow8oqDpPZftgTRH3ARDxZQciu3K8zl7eC2x X-Received: by 2002:a17:906:f0c9:: with SMTP id dk9mr1819775ejb.51.1610549177008; Wed, 13 Jan 2021 06:46:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610549177; cv=none; d=google.com; s=arc-20160816; b=Y1mFCvtIi/eY040F+7n6IyaIOt934gVyWECYzQUTGo1SF4E40AtWWMyrrsGVaKq3iO gkPpzr1QwIgYhGuOOIqSbxVXMyWdY+lRRB1ODh2z2NSQHOfRsapRgeCykteodUK95kNu f1Bl2z00miEYNv8gOO1zE6uQHQRpQOhuBdP/wYAK4l3hnNfEKMB8bn8Yu0fU1GVRtvgb gHorZv6vmvt6HNcqoCYGMJpldFNF4zvahhIkvv6lSHQkBkxbPWBeY+U19ikC5vewQGDH h86RKePA4I5YnVBCYwcu9WWfTAOAPAGKbEFBPVVcqy+CDGwb6UQRJ74pXmgWF1MJ84R1 nIBA== 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=nSaLjd0adwc4A9pw9dVhGLGEtgMueESLihkqzNC4nZI=; b=I+K2KlKX+drNYX1zY1l8sDLmEQU+9LnxS+UiFCTzIEoVQ0feyMeXzkDKtvd9D5693V 2tBGssxPOO0XTgIadzSz8MxFSU8o9vueZOgwviV++qHMlvuyuR7vFHf2wOu77PwwMt0C 8AJYU8ma9YGSeqbwt5ZBdI2EkehtdLIdGeOxQr/7Yn+Gj9ge8PSLDlQbHFAdLKuK3m9O FBcKGMEtY7HmzHhQoeUenmx/FsPoxV/AB5zvM1kzx2ZR2HZ9v3efJ3Kn7F1rRUqiMcfE CiXAWmjVzGCCL69eH1ZPOhdP3aa74RcCCzcbaVucChLoQfWm3Ya8gdGHewXAE9Vn4Rj+ /T3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=fg3Lqtnh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m13si1248184edi.155.2021.01.13.06.45.52; Wed, 13 Jan 2021 06:46:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=fg3Lqtnh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727068AbhAMOpN (ORCPT + 99 others); Wed, 13 Jan 2021 09:45:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726584AbhAMOpM (ORCPT ); Wed, 13 Jan 2021 09:45:12 -0500 Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F025EC061795 for ; Wed, 13 Jan 2021 06:44:31 -0800 (PST) Received: by mail-qk1-x732.google.com with SMTP id h4so1776858qkk.4 for ; Wed, 13 Jan 2021 06:44:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=nSaLjd0adwc4A9pw9dVhGLGEtgMueESLihkqzNC4nZI=; b=fg3LqtnhsOsxsTc67Ngrhxx4sU0hh8IMnJxPVNFfI0CuQ2kTlgx3FRnu4v/sqXbMuV 2qrkFcwJemXKZqUr3RBtPnGiHc6L5EpeaPGK3wmNCudEoOG5cFGM6Pte5QqKN20woxti wYjpadsWUWSf6jxMJIiP54HXSEGegQAv2hsiggh3iXsOam5PWhxOm8tb+AMkA7BC11Sf HV5hyMBJrWMEiKWodoVLJcCH7o/gT+uA+vfxn9bHx1aGpyXuW+9wix0najwRG1gdpWPf g6j5Qdg6BR2UKDn9r3U/1y+wLc4NBpUEwL7ttsp394eHRYPor0Dabpsy9RGmLIbZ79sk Kngw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nSaLjd0adwc4A9pw9dVhGLGEtgMueESLihkqzNC4nZI=; b=nJzM/CeFMDH+O7Z8gbLZAfOJTcrupRZHVtAACfDXwSi9XJ2gA1KDXlhxpd4dft7FD7 Eo7vPSKko+SRsoM+04Bi0Q5IM3PYrnzb7831TpGn/0KTEcLbF4R2QyvV7hXG30gbuvPG Vy9IWsUY2EmIESDgP/wXdm2kaRmDHCQ1vTFR11CTYpdMwVaoAZO3WlXbbVsVgDZY3mP8 ak+npH6h2f98nNJm+tH8PpqcF1p70qWyn9D/zGTNQSAUK7QMHmrttuoS2KaEOPkZcshv R0eZ6yVu8Q9kRW6yLBREs91zTBu8vZpzRwTpMfVLsJyC3eUvaNsM2jI1GVXOwBHUBR9X lBCw== X-Gm-Message-State: AOAM530T98IzJO1zJcJbiT9MEt/wF9tXemqExY66JesYupn9d5klAuR0 bvNSkEcwi2qW5R+tBOS2zoM/cB/VWtlLBE03xJ+b9A== X-Received: by 2002:a37:2f82:: with SMTP id v124mr2257967qkh.212.1610549070729; Wed, 13 Jan 2021 06:44:30 -0800 (PST) MIME-Version: 1.0 References: <20210105163927.1376770-1-kyletso@google.com> <20210105163927.1376770-2-kyletso@google.com> <20210112132925.GC2020859@kuha.fi.intel.com> In-Reply-To: <20210112132925.GC2020859@kuha.fi.intel.com> From: Kyle Tso Date: Wed, 13 Jan 2021 22:44:14 +0800 Message-ID: Subject: Re: [PATCH v5 1/3] usb: typec: tcpm: AMS and Collision Avoidance To: Heikki Krogerus Cc: Guenter Roeck , Greg KH , Hans de Goede , Badhri Jagan Sridharan , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Will McVicker Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 12, 2021 at 9:29 PM Heikki Krogerus wrote: > > On Wed, Jan 06, 2021 at 12:39:25AM +0800, Kyle Tso wrote: > > This patch provides the implementation of Collision Avoidance introduced > > in PD3.0. The start of each Atomic Message Sequence (AMS) initiated by > > the port will be denied if the current AMS is not interruptible. The > > Source port will set the CC to SinkTxNG if it is going to initiate an > > AMS, and SinkTxOk otherwise. Meanwhile, any AMS initiated by a Sink port > > will be denied in TCPM if the port partner (Source) sets SinkTxNG except > > for HARD_RESET and SOFT_RESET. > > > > Signed-off-by: Kyle Tso > > Signed-off-by: Will McVicker > > So did you and Will develop this patch together? > Not really. Will cherry-picked the patch from our old branch to a later one which is more close to Upstream. And I cherry-picked his version so the signed-off is here. I will remove the signed-off if that is the right move. > Few nitpicks below. > > > +static void tcpm_set_cc(struct tcpm_port *port, enum typec_cc_status cc) > > +{ > > + tcpm_log(port, "cc:=%d", cc); > > + port->cc_req = cc; > > + port->tcpc->set_cc(port->tcpc, cc); > > +} > > + > > +static enum typec_cc_status tcpm_rp_cc(struct tcpm_port *port); > > I think you should move the function here instead of adding the > prototype for it. > will fix this in the next patch version. > > + case CMD_DISCOVER_MODES: > > + res = tcpm_ams_start(port, DISCOVER_MODES); > > + break; > > + case CMD_ENTER_MODE: > > + res = tcpm_ams_start(port, > > + DFP_TO_UFP_ENTER_MODE); > > One line is enough: > > res = tcpm_ams_start(port, DFP_TO_UFP_ENTER_MODE); > will fix this in the next patch version. > > + break; > > + case CMD_EXIT_MODE: > > + res = tcpm_ams_start(port, > > + DFP_TO_UFP_EXIT_MODE); > > Ditto. > will fix this in the next patch version. > > + break; > > + case CMD_ATTENTION: > > + res = tcpm_ams_start(port, ATTENTION); > > + break; > > + case VDO_CMD_VENDOR(0) ... VDO_CMD_VENDOR(15): > > + res = tcpm_ams_start(port, STRUCTURED_VDMS); > > + break; > > + default: > > + res = -EOPNOTSUPP; > > + break; > > + } > > > > - port->vdm_retries = 0; > > - port->vdm_state = VDM_STATE_BUSY; > > - timeout = vdm_ready_timeout(port->vdo_data[0]); > > - mod_vdm_delayed_work(port, timeout); > > + if (res < 0) > > + return; > > } > > + > > + port->vdm_state = VDM_STATE_SEND_MESSAGE; > > + mod_vdm_delayed_work(port, (port->negotiated_rev >= PD_REV30) && > > + (port->pwr_role == TYPEC_SOURCE) && > > + (PD_VDO_SVDM(vdo_hdr)) && > > + (PD_VDO_CMDT(vdo_hdr) == CMDT_INIT) ? > > + PD_T_SINK_TX : 0); > > I don't think you need all those brackets. This would look better, and > I bet it would make also scripts/checkpatch.pl happy: > > mod_vdm_delayed_work(port, (port->negotiated_rev >= PD_REV30 && > port->pwr_role == TYPEC_SOURCE && > PD_VDO_SVDM(vdo_hdr) && > PD_VDO_CMDT(vdo_hdr) == CMDT_INIT) ? > PD_T_SINK_TX : 0); > will fix this in the next patch version. > > + /* > > + * If previous AMS is interrupted, switch to the upcoming > > + * state. > > + */ > > + upcoming_state = port->upcoming_state; > > + if (port->upcoming_state != INVALID_STATE) { > > + port->upcoming_state = INVALID_STATE; > > + tcpm_set_state(port, upcoming_state, 0); > > + break; > > + } > > I don't see the local upcoming_state variable is being used anywhere > outside of these conditions, so please set it inside the condition > block: > > if (port->upcoming_state != INVALID_STATE) { > upcoming_state = port->upcoming_state; > port->upcoming_state = INVALID_STATE; > tcpm_set_state(port, upcoming_state, 0); > break; > } > will do > > + upcoming_state = port->upcoming_state; > > + if (port->upcoming_state != INVALID_STATE) { > > + port->upcoming_state = INVALID_STATE; > > + tcpm_set_state(port, upcoming_state, 0); > > + break; > > + } > > Same here. > will do thanks, Kyle