Received: by 10.213.65.68 with SMTP id h4csp505780imn; Fri, 16 Mar 2018 09:48:44 -0700 (PDT) X-Google-Smtp-Source: AG47ELuEgZFuHAY7R+AC37Lqpg3arJpXlniOjq6Aeq7Kh4QwCalrOyB9C96TFNRPe2lfzYObuUV1 X-Received: by 10.99.124.25 with SMTP id x25mr2035872pgc.46.1521218924330; Fri, 16 Mar 2018 09:48:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521218924; cv=none; d=google.com; s=arc-20160816; b=Pq3Cjb6Gh4I2MgBsVEEfb5YnFL7g5Zu360/OsU0wHg4atXQ/0hZYIL4zwOt/wYaY95 hD+z5SIa7+3hx/NrauBEq4nv2TcfElrYHcfcOVg4CkHeV5WzWprtMPhh753bUh0jMdsN xjHYqm/sOwQP7prT2oqercOnEjxsC0TYyE6vQxsF+f6GBhstMoXUwQcPGqLg2fr7G1zm /PTlc0wKU9Z9diI/ZjvZojl9Cte0ecBwza+EIQLgumJ0INJ2Dljt+UoN84Sx+MCzyeUq ISsBm1Xx41osJxaN1fOVbQAu0a3o6mfcWVRp1P75Eqbm5MSiZTjpsSo7c+A4k06VKNVM uDgQ== 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=nT5RF8ORj46xEAAb6+hmlmVAygFnKLKhHMh7sX05YPw=; b=T9oJjeHPh3qhiEsAbhSM3NnsP6EA6fJV2iKkr4T+Go4g5UvDT1JM+Z/GzqXcSvKgg/ URKJWXNrVvSKxb7U6mfnArbTBHJoC1I4RzRWXx7Yu5LoUpYFSGzQM5JPIQ/F/rkfHJsQ 5mAvpPMFNswcRBbIWIyxVBPa+LXNDdA5LRxjkeW0s90Ks/k6K7FcyfKHOJ5G2R9olWqm 0OUuWEGPXt87aKe2/tVY3IpdiTNPYsmp6sq6djqKowKw24PdpQJTN3H2ttx+MHcTOfc2 BXlhtaCLXtfLaY0WKhQgU4zGp1E4T+du6NtnBbns7+rZeiuISuRze7aMVUY0yXVdYqQW xMxA== 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 m5si5120792pgv.487.2018.03.16.09.48.29; Fri, 16 Mar 2018 09:48:44 -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 S1753270AbeCPQrB (ORCPT + 99 others); Fri, 16 Mar 2018 12:47:01 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:39836 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933465AbeCPPfZ (ORCPT ); Fri, 16 Mar 2018 11:35:25 -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 D02561080; Fri, 16 Mar 2018 15:35:24 +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.14 038/109] typec: tcpm: fusb302: Resolve out of order messaging events Date: Fri, 16 Mar 2018 16:23:07 +0100 Message-Id: <20180316152332.015163661@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180316152329.844663293@linuxfoundation.org> References: <20180316152329.844663293@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.14-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/staging/typec/fusb302/fusb302.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) --- a/drivers/staging/typec/fusb302/fusb302.c +++ b/drivers/staging/typec/fusb302/fusb302.c @@ -1552,6 +1552,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; } @@ -1659,13 +1674,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) { @@ -1686,7 +1700,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);