From patchwork Fri May 21 13:01:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Tso X-Patchwork-Id: 12273133 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.2 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_NONE, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5BD31C43460 for ; Fri, 21 May 2021 13:01:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3E79E6138C for ; Fri, 21 May 2021 13:01:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232761AbhEUNDT (ORCPT ); Fri, 21 May 2021 09:03:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232891AbhEUNDQ (ORCPT ); Fri, 21 May 2021 09:03:16 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9B0AC0613CE for ; Fri, 21 May 2021 06:01:52 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id v17-20020a6346510000b029021a532f226dso12378457pgk.21 for ; Fri, 21 May 2021 06:01:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=w7NQZCFeih8HQ6CGBSGm0Dxti/IMLI0sR42V/tW/LBM=; b=ZOvM8pVs4SpzsuoADEA4dbmhM5M6KXyxppUN3Bcro+72TSSW+tsSr+cchzLPZARCIr GvLv9u0MnxheFNobxyjh96iN6EG2IMkLK6xr7bFZIfvWbD8xcacU6lXXbvv0XRpvgaNG H3wd9q9eqTLlNBA69QcnOqOvy4XfI/7uFeQ5B6xJdWvKoNrBecRux+4MSYc72GqRxs3C fgV3X1fx2aTtOX9gy/ziUbdYKRVeyHSqhh11cFIx6p0jeRlOOnEmME+HiOYPcewBzJYO i6X7MXQoi+kdWCwNlyuHojS89o36bI7IKbHIkC4oeTJ5UfKWtr/F9uaWyHYhuZ+hKgUk +/Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=w7NQZCFeih8HQ6CGBSGm0Dxti/IMLI0sR42V/tW/LBM=; b=HgSAU1TV/iYZ+nQeVnz+ahON2LZ8H1+rDqCuC0VmLYbaYRpUdGLpzQIlkQxG/yKK0Y bU4BHSGi2xUZr3O+KpTCxW+B0bquVyFuF6vBJNsyKNO435GbRAtFT7X0wSz/RGBWV0oN ATgI82yLJNxECufz/PWFGtTvzerg2Jf5nlogNhYFHhddGRtbDMnZYudH2tzJ74bZqRHc nty3Ss55/CAw0m+wr0ACh48nmALcDjO+EaaOS0yiRHr2Il4OaD84lJ6R0lUK471TgPzD 7GmdrHDWrzrI1hdzpKR5i4mpYOtyHQCeOop5YR7oj9P6qpTobnJG+AGup9A8cLZ5ZQ8H zTcw== X-Gm-Message-State: AOAM531v4taIXgQYqmveSk5xrbndQoWA4+O5iHxzmKe0qhjoZQ48ovAe rvjpfoWewWLVXKMLu7pRdx6GECPDAGGC X-Google-Smtp-Source: ABdhPJzaevP+Ugt8Z6fOld2zkI4r198IINlmzW6Ir1P9VkSqnRi5IDU9iedq5SVym5ovBAZBvLj4PpJ+YKf5 X-Received: from kyletso.ntc.corp.google.com ([2401:fa00:fc:202:905b:c174:8f59:4851]) (user=kyletso job=sendgmr) by 2002:a17:902:db09:b029:f4:8d37:8d12 with SMTP id m9-20020a170902db09b02900f48d378d12mr12474043plx.52.1621602112242; Fri, 21 May 2021 06:01:52 -0700 (PDT) Date: Fri, 21 May 2021 21:01:20 +0800 In-Reply-To: <20210521130121.1470334-1-kyletso@google.com> Message-Id: <20210521130121.1470334-2-kyletso@google.com> Mime-Version: 1.0 References: <20210521130121.1470334-1-kyletso@google.com> X-Mailer: git-send-email 2.31.1.818.g46aad6cb9e-goog Subject: [PATCH 1/2] usb: typec: tcpm: Properly interrupt VDM AMS From: Kyle Tso To: linux@roeck-us.net, heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org Cc: badhri@google.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Kyle Tso Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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") Signed-off-by: Kyle Tso Reviewed-by: Guenter Roeck Reported-by: kernel test robot --- drivers/usb/typec/tcpm/tcpm.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index 64133e586c64..deb8a9d01f73 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -1550,6 +1550,8 @@ static int tcpm_pd_svdm(struct tcpm_port *port, struct typec_altmode *adev, 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) { @@ -1568,14 +1570,19 @@ static int tcpm_pd_svdm(struct tcpm_port *port, struct typec_altmode *adev, } 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; @@ -2287,6 +2294,12 @@ static void tcpm_pd_data_request(struct tcpm_port *port, 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++) @@ -2459,6 +2472,16 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port, 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: @@ -2717,6 +2740,13 @@ static void tcpm_pd_ext_msg_request(struct tcpm_port *port, 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 (!(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"); From patchwork Fri May 21 13:01:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Tso X-Patchwork-Id: 12273135 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.2 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_NONE, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BD7AC433B4 for ; Fri, 21 May 2021 13:02:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1C69A6138C for ; Fri, 21 May 2021 13:02:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233317AbhEUND3 (ORCPT ); Fri, 21 May 2021 09:03:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232959AbhEUNDW (ORCPT ); Fri, 21 May 2021 09:03:22 -0400 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 312CAC0613CE for ; Fri, 21 May 2021 06:01:58 -0700 (PDT) Received: by mail-qv1-xf4a.google.com with SMTP id b24-20020a0cb3d80000b02901e78b82d74aso16736131qvf.20 for ; Fri, 21 May 2021 06:01:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=hjK4qHjpBKdfkmlPVsP8X40hmtzrrpX8nHB5WsA0A04=; b=XKQA7O5anoKZTBb5fhFPVJNHly1HSjklTYpjQrzLk2nElaNookpsYbWxC3wF+0fkEZ S6yOr8tNtpwVK4cwEkyw/nt3auSDfi35oF9whSuCeeyKvhSJRsmBK6bvug+MGmQRRfD3 j9Rk75MwFM6p0CuGcaHBxs7Lm3b8CFZDK1xS15P07bRB/2nGPznqWZBOqbdvoNBINr+R hJjHQi5BIxvutEwpr1NIJZeYX5wSEf7y4R5ACZTXHRYMXt+p0JakMdvM7JQDpRNaF4VM /h3DBtN8D23VaP0CrYyRVSUj/kV8yv0py5FrgTYeUk0ncWPuK9C6V6X/y6ypZH71U7RM 2rog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=hjK4qHjpBKdfkmlPVsP8X40hmtzrrpX8nHB5WsA0A04=; b=oe3slawhMmZrUgjupskH4ebOICWYtpztFfkuVrZq1VNDfyFOo3bymCuktnEwpJo+JF AOcmN/N25iuRb2L7oV/+lxmbxE6gX7eiD+BNuZBn1RPvB1rgYAFLLV82NKCsWdeQ+Eph wT0zf3K/g8t3IKMrRfV3KeDIRR3qwsQ0HLwFEeTeHGirsFA27E/DAr0LH9uq916WrnqL pyTG8tDmA2sfoHqXWfmwonsZcwkEQIBfYxIZmgawncBX6hwOCJBvsRigKBh7j14YGJhA vez/qvUd5F/x0oyBS1reIwfsfU1+KceOu582iK04TFfYTs4sAHP6LokOGx7UhKK+9JUC zWig== X-Gm-Message-State: AOAM532ImkfcJJlYKZ7wZGFgQl1VRcqAhZDDFM37VuCrRbYFtbGPlV2z XTdHqgvWy5sQaryP/r4drg0HuhWtJs1r X-Google-Smtp-Source: ABdhPJyTiKqGw1Th8nl1MJyY14wZpSQyYGtOGYphjIfhkiIKDQjCZGKKlqiAdOL67/52seMuerF2U2AJLNkZ X-Received: from kyletso.ntc.corp.google.com ([2401:fa00:fc:202:905b:c174:8f59:4851]) (user=kyletso job=sendgmr) by 2002:a05:6214:dc8:: with SMTP id 8mr8616260qvt.58.1621602117277; Fri, 21 May 2021 06:01:57 -0700 (PDT) Date: Fri, 21 May 2021 21:01:21 +0800 In-Reply-To: <20210521130121.1470334-1-kyletso@google.com> Message-Id: <20210521130121.1470334-3-kyletso@google.com> Mime-Version: 1.0 References: <20210521130121.1470334-1-kyletso@google.com> X-Mailer: git-send-email 2.31.1.818.g46aad6cb9e-goog Subject: [PATCH 2/2] usb: typec: tcpm: Respond Not_Supported if no snk_vdo From: Kyle Tso To: linux@roeck-us.net, heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org Cc: badhri@google.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Kyle Tso Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If snk_vdo is not populated from fwnode, it implies the port does not support responding to SVDM commands. Not_Supported Message shall be sent if the contract is in PD3. And for PD2, the port shall ignore the commands. Fixes: 193a68011fdc ("staging: typec: tcpm: Respond to Discover Identity commands") Signed-off-by: Kyle Tso Reviewed-by: Guenter Roeck --- drivers/usb/typec/tcpm/tcpm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index deb8a9d01f73..d32caa875d9a 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -2430,7 +2430,10 @@ static void tcpm_pd_data_request(struct tcpm_port *port, NONE_AMS); break; case PD_DATA_VENDOR_DEF: - tcpm_handle_vdm_request(port, msg->payload, cnt); + if (tcpm_vdm_ams(port) || port->nr_snk_vdo) + tcpm_handle_vdm_request(port, msg->payload, cnt); + else if (port->negotiated_rev > PD_REV20) + tcpm_pd_handle_msg(port, PD_MSG_CTRL_NOT_SUPP, NONE_AMS); break; case PD_DATA_BIST: port->bist_request = le32_to_cpu(msg->payload[0]);