Received: by 10.213.65.68 with SMTP id h4csp470173imn; Fri, 16 Mar 2018 08:44:02 -0700 (PDT) X-Google-Smtp-Source: AG47ELuFolvDerNZKr7rmD2mczxcLMYJXs6Cs/CQkSNAWYgMmRv1dUV5T+KncLbmY1NHpeMxVRuO X-Received: by 2002:a17:902:1665:: with SMTP id g92-v6mr2571286plg.195.1521215042889; Fri, 16 Mar 2018 08:44:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521215042; cv=none; d=google.com; s=arc-20160816; b=m+Y+Y+6RdlOccDMtJe9dxqiRL0Uvjz1mdqrg//RdsFK8KIJXBJtg83qu+h1dcZ4b9C sSjgcNszGT5O4K6uizkBijJ87ZaOjS6W7VnMvanNfmttX8bq8LEvddDlFaKlLllgbXXq IchLPpE5Ux3gnKgjJAwVGHG6IP47uzrEb6AuBe/D3+9xa3AqxJk1PHE7sKof0Mm97lr1 as2EaFOnLoFhlntWjssZO0nkUna6Z7CEwqZUz9Kpg0KQ59PD2+CgKml/Zdxcq1pUoHbn h0a9WvLICJCKgbo2d81B2jN/3/qk1zRw32TvbzqygKG1zddVJ03yuAcWumqqAnWVM8Ne jL+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=AS1lXyZnX4kF2YP+L1LjvMfhcbvwlXpuLwBY41oenOo=; b=JpcH/h4tYzDnlqAwiCh96N23viXwDDry6/qzIVxXp5RPcEL8TfWwR36VGsauaX980p cXSMAsv5Zv5rTjvYoCG8LctSm4P8/SYZf0m4DgQxn+4MJttHzTvPn3qgC1Mx9QfoWHCe PrpNAlgQfx8kY2MXWJz+XzjTJeAfg1eR+AdL5o+Ac7xm3tXlUQ1fUtqK+NEZCOa2H0iq RG4j+aZ7x4nNEir6uDljdyK/zecFvVdjtsskNSJsIJ+bH9xNe2avlVEWjb+1zIbJnOMX B3f37WQxY8j3HQvFz+NY2VsAWspvBB9qrL1zLBos0meYelsz5+eSHMGoOATVO2kbK2sT rZHQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t9-v6si6270886plq.321.2018.03.16.08.43.48; Fri, 16 Mar 2018 08:44:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934532AbeCPPmq (ORCPT + 99 others); Fri, 16 Mar 2018 11:42:46 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:44542 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934270AbeCPPmn (ORCPT ); Fri, 16 Mar 2018 11:42:43 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 33845FCA; Fri, 16 Mar 2018 15:42:42 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Adam Thomson , Guenter Roeck , Heikki Krogerus , Sasha Levin Subject: [PATCH 4.15 043/128] typec: tcpm: fusb302: Resolve out of order messaging events Date: Fri, 16 Mar 2018 16:23:04 +0100 Message-Id: <20180316152338.933623386@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180316152336.199007505@linuxfoundation.org> References: <20180316152336.199007505@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Adam Thomson [ Upstream commit ab69f61321140ff632d560775bc226259a78dfa2 ] The expectation in the FUSB302 driver is that a TX_SUCCESS event should occur after a message has been sent, but before a GCRCSENT event is raised to indicate successful receipt of a message from the partner. However in some circumstances it is possible to see the hardware raise a GCRCSENT event before a TX_SUCCESS event is raised. The upshot of this is that the GCRCSENT handling portion of code ends up reporting the GoodCRC message to TCPM because the TX_SUCCESS event hasn't yet arrived to trigger a consumption of it. When TX_SUCCESS is then raised by the chip it ends up consuming the actual message that was meant for TCPM, and this incorrect sequence results in a hard reset from TCPM. To avoid this problem, this commit updates the message reading code to check whether a GoodCRC message was received or not. Based on this check it will either report that the previous transmission has completed or it will pass the msg data to TCPM for futher processing. This way the incorrect ordering of the events no longer matters. Signed-off-by: Adam Thomson Reviewed-by: Guenter Roeck Acked-by: Heikki Krogerus Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/usb/typec/fusb302/fusb302.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) --- a/drivers/usb/typec/fusb302/fusb302.c +++ b/drivers/usb/typec/fusb302/fusb302.c @@ -1543,6 +1543,21 @@ static int fusb302_pd_read_message(struc fusb302_log(chip, "PD message header: %x", msg->header); fusb302_log(chip, "PD message len: %d", len); + /* + * Check if we've read off a GoodCRC message. If so then indicate to + * TCPM that the previous transmission has completed. Otherwise we pass + * the received message over to TCPM for processing. + * + * We make this check here instead of basing the reporting decision on + * the IRQ event type, as it's possible for the chip to report the + * TX_SUCCESS and GCRCSENT events out of order on occasion, so we need + * to check the message type to ensure correct reporting to TCPM. + */ + if ((!len) && (pd_header_type_le(msg->header) == PD_CTRL_GOOD_CRC)) + tcpm_pd_transmit_complete(chip->tcpm_port, TCPC_TX_SUCCESS); + else + tcpm_pd_receive(chip->tcpm_port, msg); + return ret; } @@ -1650,13 +1665,12 @@ static irqreturn_t fusb302_irq_intn(int if (interrupta & FUSB_REG_INTERRUPTA_TX_SUCCESS) { fusb302_log(chip, "IRQ: PD tx success"); - /* read out the received good CRC */ ret = fusb302_pd_read_message(chip, &pd_msg); if (ret < 0) { - fusb302_log(chip, "cannot read in GCRC, ret=%d", ret); + fusb302_log(chip, + "cannot read in PD message, ret=%d", ret); goto done; } - tcpm_pd_transmit_complete(chip->tcpm_port, TCPC_TX_SUCCESS); } if (interrupta & FUSB_REG_INTERRUPTA_HARDRESET) { @@ -1677,7 +1691,6 @@ static irqreturn_t fusb302_irq_intn(int "cannot read in PD message, ret=%d", ret); goto done; } - tcpm_pd_receive(chip->tcpm_port, &pd_msg); } done: mutex_unlock(&chip->lock);