Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2730689pxj; Mon, 31 May 2021 09:17:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkwTYnd8A6HjqSs5mklzllwOFeN2VaYpb4MNjYDUx+9vLNXc+L0AmVXLjm+rbMoocLBdFW X-Received: by 2002:a17:906:ac1:: with SMTP id z1mr23754213ejf.463.1622477857693; Mon, 31 May 2021 09:17:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622477857; cv=none; d=google.com; s=arc-20160816; b=d3hj4sN79mpunEKzAlPcd5tPCgvFL8tdYkc13d/Gmrtm//LevIIddRdvSehLwDhY8x zUPP1d67I9mIXvVmt6ZRaH++VbQvXklufbkD+kzyC8hJaDZdq3aq3wd/i6ePyVHK8t81 1e5+Vfuz6P0bo+Dwjgg3r8KSVbD3jEVDv3Z7z4BTgmtz5N9wRzzJxKAON7vWeodrIv9s yEv9i74OkFIKKoDoJpEB+T2q2obcrRXAo8IyKK0TFpkpiQStu6OWNfbXMPRTqX7383Xk 1rjt2fiJa6WdBV1Me1WzsbcG1xTC1cdrRvNxajj4oXrF34Z5Z+s/mWPwuaU4X8ZKYlp4 +8jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pbUg+sPmmIaEXa3+4thOuldtzz1hcvDPdKAvAmY2atE=; b=xd279vMg8hqugtu8XfYI8PzCKqvDrZBKHY5pgJEzURZ6HFzUysIcXKZDZ4NFb0ZLU0 +Uz0CcspfThC2/TWlXowBPeWBNi8Hlkd82ksSO+TGA292+oX63/rDZO1+lJe0jblGCQg oFmjmppZ56g+dXy0q7erv1MWUUb5siFjdx8x+m0Xdxopwd+x/7Sz9AUFMkKgGthEV6np Ekg7TxPxAm+GVJrjsL3mpW2EwUxspFHDbpUwms7qNehJzpihCaKJw3vcFYgvJ64Ab7UP uwDVN2zKdwas32y2buJriJZ0Vc8T+7IRo9s+IH0v77b858XPOrjLndinAxGvtEJFPy+b K8Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=G4mD3i7l; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d10si3130472ejc.427.2021.05.31.09.17.14; Mon, 31 May 2021 09:17:37 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=G4mD3i7l; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232409AbhEaQRz (ORCPT + 99 others); Mon, 31 May 2021 12:17:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:37854 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233355AbhEaOlY (ORCPT ); Mon, 31 May 2021 10:41:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 587E661864; Mon, 31 May 2021 13:53:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622469200; bh=CgZKhzcJdUJqwbsidmnYwY02oE34P/p+ZdHQ220d6vA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G4mD3i7l3L4NjmESbsWvT+9WT32yaxv4S2SCC9SwdrzZCB+AFvR/onM7JVJvYB74G XZBVrMRpTfT/e09OAlq9UGYjgUYarDTH75W/EqeNWOicfufOoJWDLEArzmGlS4TmWi 4hC60UIMcTAvjYymgQd6nvyYjmZkfK6UNCPFtGzI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guenter Roeck , Heikki Krogerus , Kyle Tso Subject: [PATCH 5.12 108/296] usb: typec: tcpm: Properly interrupt VDM AMS Date: Mon, 31 May 2021 15:12:43 +0200 Message-Id: <20210531130707.572914947@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130703.762129381@linuxfoundation.org> References: <20210531130703.762129381@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kyle Tso commit 0bc3ee92880d910a1d100b73a781904f359e1f1c upstream. When a VDM AMS is interrupted by Messages other than VDM, the AMS needs to be finished properly. Also start a VDM AMS if receiving SVDM Commands from the port partner to complement the functionality of tcpm_vdm_ams(). Fixes: 0908c5aca31e ("usb: typec: tcpm: AMS and Collision Avoidance") Cc: stable Reviewed-by: Guenter Roeck Acked-by: Heikki Krogerus Signed-off-by: Kyle Tso Link: https://lore.kernel.org/r/20210523015855.1785484-2-kyletso@google.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/typec/tcpm/tcpm.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -1534,6 +1534,8 @@ static int tcpm_pd_svdm(struct tcpm_port if (PD_VDO_SVDM_VER(p[0]) < svdm_version) typec_partner_set_svdm_version(port->partner, PD_VDO_SVDM_VER(p[0])); + + tcpm_ams_start(port, DISCOVER_IDENTITY); /* 6.4.4.3.1: Only respond as UFP (device) */ if (port->data_role == TYPEC_DEVICE && port->nr_snk_vdo) { @@ -1552,14 +1554,19 @@ static int tcpm_pd_svdm(struct tcpm_port } break; case CMD_DISCOVER_SVID: + tcpm_ams_start(port, DISCOVER_SVIDS); break; case CMD_DISCOVER_MODES: + tcpm_ams_start(port, DISCOVER_MODES); break; case CMD_ENTER_MODE: + tcpm_ams_start(port, DFP_TO_UFP_ENTER_MODE); break; case CMD_EXIT_MODE: + tcpm_ams_start(port, DFP_TO_UFP_EXIT_MODE); break; case CMD_ATTENTION: + tcpm_ams_start(port, ATTENTION); /* Attention command does not have response */ *adev_action = ADEV_ATTENTION; return 0; @@ -2267,6 +2274,12 @@ static void tcpm_pd_data_request(struct bool frs_enable; int ret; + if (tcpm_vdm_ams(port) && type != PD_DATA_VENDOR_DEF) { + port->vdm_state = VDM_STATE_ERR_BUSY; + tcpm_ams_finish(port); + mod_vdm_delayed_work(port, 0); + } + switch (type) { case PD_DATA_SOURCE_CAP: for (i = 0; i < cnt; i++) @@ -2439,6 +2452,16 @@ static void tcpm_pd_ctrl_request(struct enum pd_ctrl_msg_type type = pd_header_type_le(msg->header); enum tcpm_state next_state; + /* + * Stop VDM state machine if interrupted by other Messages while NOT_SUPP is allowed in + * VDM AMS if waiting for VDM responses and will be handled later. + */ + if (tcpm_vdm_ams(port) && type != PD_CTRL_NOT_SUPP && type != PD_CTRL_GOOD_CRC) { + port->vdm_state = VDM_STATE_ERR_BUSY; + tcpm_ams_finish(port); + mod_vdm_delayed_work(port, 0); + } + switch (type) { case PD_CTRL_GOOD_CRC: case PD_CTRL_PING: @@ -2697,6 +2720,13 @@ static void tcpm_pd_ext_msg_request(stru enum pd_ext_msg_type type = pd_header_type_le(msg->header); unsigned int data_size = pd_ext_header_data_size_le(msg->ext_msg.header); + /* stopping VDM state machine if interrupted by other Messages */ + if (tcpm_vdm_ams(port)) { + port->vdm_state = VDM_STATE_ERR_BUSY; + tcpm_ams_finish(port); + mod_vdm_delayed_work(port, 0); + } + if (!(le16_to_cpu(msg->ext_msg.header) & PD_EXT_HDR_CHUNKED)) { tcpm_pd_handle_msg(port, PD_MSG_CTRL_NOT_SUPP, NONE_AMS); tcpm_log(port, "Unchunked extended messages unsupported");