Message ID | 1673248790-15794-1-git-send-email-cy_huang@richtek.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2018543wrt; Sun, 8 Jan 2023 23:22:26 -0800 (PST) X-Google-Smtp-Source: AMrXdXtQQPxaHZngX/I1mstiUFz1+g1k/iF4y5ZQAMqL9WyWjM0M8ORWk+7l2sZrde7sd+ZJ/fFV X-Received: by 2002:a17:907:7e83:b0:7c0:f558:e518 with SMTP id qb3-20020a1709077e8300b007c0f558e518mr66288623ejc.51.1673248946319; Sun, 08 Jan 2023 23:22:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673248946; cv=none; d=google.com; s=arc-20160816; b=m+/3heMjdzpJ2aloDNWH3jMRtSpHDa0XDiBSDan7SiDHX7P/B44FUbWMQi4dYVKdlo lrEFyB38suiJ87idXYSYBE0Sb4jABM/kANd1sE6LrPjObMk7sGHk2PbEo6R1INHtEQG/ JB+Z45K+dg9RoHDpMnB8HtuMgOHWIxX3PhVlNQAO0O9+RbAK93Cu+SiqtH/v5PCrD2PD GyEbpWDcYX4kMf2BX0VFJLNmcDO9htHcSJMw0tfx4vAjcQJidLBAUdPXsuTIvCyq+kUv QgykMdSgpjHeVShLPp5guwmiQIiBRiP89FZk9qMfQIHJ55tc4Spdz4DjFKzSmE1bGL7X G3cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=uT0Mq48ZlRMvwajxL4lzX4MGf/UZE9fla3NQAZQBIS8=; b=ewLOivN7omO+vWoKWJDunB6SH1Qf6Ip7Gy1ontnarh5xeyBixhiIuIvY0mGgpP+Lug pCuopsUPa3vnPUd5ikaGcNPFktVWTwzozcIlXn5+jU6LIPbKI/2s7c+RoRmF7RpwGc+s MX28gOl0xmgoYFTrwAszY6Nu7pKK7xG4b2JGVwWfWrI2kvAcgvRgMmFlh4NxiFuU7nVs FbwWESb482jZ/VFJ8bde0nXyncX1JklTHhR1viG7YE02jwywijjpToTnx1Zm78FU9PCV EJHHVBltErID7IBuxkVjuz+BO+g/KFDRfbQgOylg531hau+2Xh1BRay1/asHDJUJBe8K foiQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sd42-20020a1709076e2a00b007be97d37b29si9782575ejc.104.2023.01.08.23.22.03; Sun, 08 Jan 2023 23:22:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234278AbjAIHUm (ORCPT <rfc822;zhanglyra.2023@gmail.com> + 99 others); Mon, 9 Jan 2023 02:20:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233151AbjAIHUY (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 9 Jan 2023 02:20:24 -0500 Received: from mg.richtek.com (mg.richtek.com [220.130.44.152]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9E806FE9; Sun, 8 Jan 2023 23:20:17 -0800 (PST) X-MailGates: (flag:4,DYNAMIC,BADHELO,RELAY,NOHOST:PASS)(compute_score:DE LIVER,40,3) Received: from 192.168.10.46 by mg.richtek.com with MailGates ESMTP Server V5.0(16471:0:AUTH_RELAY) (envelope-from <cy_huang@richtek.com>); Mon, 09 Jan 2023 15:19:51 +0800 (CST) Received: from ex3.rt.l (192.168.10.46) by ex3.rt.l (192.168.10.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.20; Mon, 9 Jan 2023 15:19:51 +0800 Received: from linuxcarl2.richtek.com (192.168.10.154) by ex3.rt.l (192.168.10.45) with Microsoft SMTP Server id 15.2.1118.20 via Frontend Transport; Mon, 9 Jan 2023 15:19:51 +0800 From: <cy_huang@richtek.com> To: <linux@roeck-us.net>, <heikki.krogerus@linux.intel.com>, <matthias.bgg@gmail.com> CC: <gregkh@linuxfoundation.org>, <gene_chen@richtek.com>, <linux-usb@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <linux-arm-kernel@lists.infradead.org>, <linux-mediatek@lists.infradead.org>, ChiYuan Huang <cy_huang@richtek.com>, <stable@vger.kernel.org> Subject: [PATCH RESEND v2] usb: typec: tcpm: Fix altmode re-registration causes sysfs create fail Date: Mon, 9 Jan 2023 15:19:50 +0800 Message-ID: <1673248790-15794-1-git-send-email-cy_huang@richtek.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754528687235883077?= X-GMAIL-MSGID: =?utf-8?q?1754528687235883077?= |
Series |
[RESEND,v2] usb: typec: tcpm: Fix altmode re-registration causes sysfs create fail
|
|
Commit Message
ChiYuan Huang
Jan. 9, 2023, 7:19 a.m. UTC
From: ChiYuan Huang <cy_huang@richtek.com> There's the altmode re-registeration issue after data role swap (DR_SWAP). Comparing to USBPD 2.0, in USBPD 3.0, it loose the limit that only DFP can initiate the VDM command to get partner identity information. For a USBPD 3.0 UFP device, it may already get the identity information from its port partner before DR_SWAP. If DR_SWAP send or receive at the mean time, 'send_discover' flag will be raised again. It causes discover identify action restart while entering ready state. And after all discover actions are done, the 'tcpm_register_altmodes' will be called. If old altmode is not unregistered, this sysfs create fail can be found. In 'DR_SWAP_CHANGE_DR' state case, only DFP will unregister altmodes. For UFP, the original altmodes keep registered. This patch fix the logic that after DR_SWAP, 'tcpm_unregister_altmodes' must be called whatever the current data role is. Reviewed-by: Macpaul Lin <macpaul.lin@mediatek.com> Fixes: ae8a2ca8a221 ("usb: typec: Group all TCPCI/TCPM code together) Reported-by: TommyYl Chen <tommyyl.chen@mediatek.com> Cc: stable@vger.kernel.org Signed-off-by: ChiYuan Huang <cy_huang@richtek.com> --- Since v2: - Correct the mail sent from Richtek. - Add 'Reviewed-by' tag. Hi, Greg: Please check this one. I have strongly requested our MIS to remove the confidential string. ChiYuan Huang. --- drivers/usb/typec/tcpm/tcpm.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
Comments
On Mon, Jan 09, 2023 at 03:19:50PM +0800, cy_huang@richtek.com wrote: > From: ChiYuan Huang <cy_huang@richtek.com> > > There's the altmode re-registeration issue after data role > swap (DR_SWAP). > > Comparing to USBPD 2.0, in USBPD 3.0, it loose the limit that only DFP > can initiate the VDM command to get partner identity information. > > For a USBPD 3.0 UFP device, it may already get the identity information > from its port partner before DR_SWAP. If DR_SWAP send or receive at the > mean time, 'send_discover' flag will be raised again. It causes discover > identify action restart while entering ready state. And after all > discover actions are done, the 'tcpm_register_altmodes' will be called. > If old altmode is not unregistered, this sysfs create fail can be found. > > In 'DR_SWAP_CHANGE_DR' state case, only DFP will unregister altmodes. > For UFP, the original altmodes keep registered. > > This patch fix the logic that after DR_SWAP, 'tcpm_unregister_altmodes' > must be called whatever the current data role is. > > Reviewed-by: Macpaul Lin <macpaul.lin@mediatek.com> > Fixes: ae8a2ca8a221 ("usb: typec: Group all TCPCI/TCPM code together) > Reported-by: TommyYl Chen <tommyyl.chen@mediatek.com> > Cc: stable@vger.kernel.org > Signed-off-by: ChiYuan Huang <cy_huang@richtek.com> Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> > --- > Since v2: > - Correct the mail sent from Richtek. > - Add 'Reviewed-by' tag. > > Hi, Greg: > > Please check this one. I have strongly requested our MIS to remove the confidential string. > > ChiYuan Huang. > --- > drivers/usb/typec/tcpm/tcpm.c | 7 +++---- > 1 file changed, 3 insertions(+), 4 deletions(-) > > diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c > index 904c7b4..59b366b 100644 > --- a/drivers/usb/typec/tcpm/tcpm.c > +++ b/drivers/usb/typec/tcpm/tcpm.c > @@ -4594,14 +4594,13 @@ static void run_state_machine(struct tcpm_port *port) > tcpm_set_state(port, ready_state(port), 0); > break; > case DR_SWAP_CHANGE_DR: > - if (port->data_role == TYPEC_HOST) { > - tcpm_unregister_altmodes(port); > + tcpm_unregister_altmodes(port); > + if (port->data_role == TYPEC_HOST) > tcpm_set_roles(port, true, port->pwr_role, > TYPEC_DEVICE); > - } else { > + else > tcpm_set_roles(port, true, port->pwr_role, > TYPEC_HOST); > - } > tcpm_ams_finish(port); > tcpm_set_state(port, ready_state(port), 0); > break; > -- > 2.7.4
On Mon, Jan 09, 2023 at 03:19:50PM +0800, cy_huang@richtek.com wrote: > From: ChiYuan Huang <cy_huang@richtek.com> > > There's the altmode re-registeration issue after data role > swap (DR_SWAP). > > Comparing to USBPD 2.0, in USBPD 3.0, it loose the limit that only DFP > can initiate the VDM command to get partner identity information. > > For a USBPD 3.0 UFP device, it may already get the identity information > from its port partner before DR_SWAP. If DR_SWAP send or receive at the > mean time, 'send_discover' flag will be raised again. It causes discover > identify action restart while entering ready state. And after all > discover actions are done, the 'tcpm_register_altmodes' will be called. > If old altmode is not unregistered, this sysfs create fail can be found. > > In 'DR_SWAP_CHANGE_DR' state case, only DFP will unregister altmodes. > For UFP, the original altmodes keep registered. > > This patch fix the logic that after DR_SWAP, 'tcpm_unregister_altmodes' > must be called whatever the current data role is. > > Reviewed-by: Macpaul Lin <macpaul.lin@mediatek.com> > Fixes: ae8a2ca8a221 ("usb: typec: Group all TCPCI/TCPM code together) > Reported-by: TommyYl Chen <tommyyl.chen@mediatek.com> > Cc: stable@vger.kernel.org > Signed-off-by: ChiYuan Huang <cy_huang@richtek.com> > --- > Since v2: > - Correct the mail sent from Richtek. > - Add 'Reviewed-by' tag. > Sorry, it seems I focus on the email testing and forget to attach the issue log in the v2 patch appendix. If anyone check this issue. Please refer to the v1 patch link. https://lore.kernel.org/lkml/1671096096-20307-1-git-send-email-u0084500@gmail.com/ Inside this, the issue log show how it happened. This can help better analyze this issue. ChiYuan Huang. > Hi, Greg: > > Please check this one. I have strongly requested our MIS to remove the confidential string. > > ChiYuan Huang. > --- > drivers/usb/typec/tcpm/tcpm.c | 7 +++---- > 1 file changed, 3 insertions(+), 4 deletions(-) > > diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c > index 904c7b4..59b366b 100644 > --- a/drivers/usb/typec/tcpm/tcpm.c > +++ b/drivers/usb/typec/tcpm/tcpm.c > @@ -4594,14 +4594,13 @@ static void run_state_machine(struct tcpm_port *port) > tcpm_set_state(port, ready_state(port), 0); > break; > case DR_SWAP_CHANGE_DR: > - if (port->data_role == TYPEC_HOST) { > - tcpm_unregister_altmodes(port); > + tcpm_unregister_altmodes(port); > + if (port->data_role == TYPEC_HOST) > tcpm_set_roles(port, true, port->pwr_role, > TYPEC_DEVICE); > - } else { > + else > tcpm_set_roles(port, true, port->pwr_role, > TYPEC_HOST); > - } > tcpm_ams_finish(port); > tcpm_set_state(port, ready_state(port), 0); > break; > -- > 2.7.4 >
diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index 904c7b4..59b366b 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -4594,14 +4594,13 @@ static void run_state_machine(struct tcpm_port *port) tcpm_set_state(port, ready_state(port), 0); break; case DR_SWAP_CHANGE_DR: - if (port->data_role == TYPEC_HOST) { - tcpm_unregister_altmodes(port); + tcpm_unregister_altmodes(port); + if (port->data_role == TYPEC_HOST) tcpm_set_roles(port, true, port->pwr_role, TYPEC_DEVICE); - } else { + else tcpm_set_roles(port, true, port->pwr_role, TYPEC_HOST); - } tcpm_ams_finish(port); tcpm_set_state(port, ready_state(port), 0); break;