Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp110306imj; Thu, 14 Feb 2019 16:29:34 -0800 (PST) X-Google-Smtp-Source: AHgI3IZO9XKI3dj6KYmB82eAYkyik4ulBwlUDmPkQtVZH6k1x7AnobpWul3YduJp8u6nCYeeYLDs X-Received: by 2002:a63:4b25:: with SMTP id y37mr2661936pga.181.1550190574376; Thu, 14 Feb 2019 16:29:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550190574; cv=none; d=google.com; s=arc-20160816; b=NgDUNdvNhz+ldCbmPuJeZIB8ZwdUOnMRbF6Wv5cuUKWE0deLmsQc6qd5EVgQ27nWLP L0MOJoMdMuxUp8Cr3P407hmbf0sd3eOOXnnj5wOz9zFBvqVyJxdlmbFZZ5t7CZH5drQB Zv+AIIZiwryKQzNOa0gucV44C9/eIUNhctcGoTiLsrNsmtCLveylnIGsKKVVv/GfDcy8 /yfMvAFx8pqTgjs1H1d1DYCXBgPpDQ82s/WTXFuW3N2+hCoAgfBiHiKe/adWeVtXS3mQ 3DT4pxbf6OEkwUF/cmFVJxPJGNtdWLXer5OnVJKMOmfx/+U7vgTL0pu8y2o7atPtjafS fg8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:cc:to:subject; bh=JaThRs8LXitrMcKvr3cAhBFcKDGym5qsfWfi8TvUxRY=; b=KdZ5TTCEDhxF09sgbYAk/nIsn8Je5aMBfHJs7qfWu0ida6Pb3N3ICQiYp/ODZvPqDv tdNVunRQZRX5LvgCHo/Cv9qp2dKt0xsUTZ9TDK+lQxr/N2O8n+RZHyAEM914ReBROFtC qz/ep8wF2l4UPPkV6Cf3nLTkTmJtPwJtBQ97CRomQ3VhyIxdoSag2/cumQ/A24Ux1u8m PiGkpVlxcD6EurOlY/3lXTEUKctujg1Ey6OnNniH7QJfZ3JW1FRiDkAQKcm4Wt9ZlwQM udwlx72inhfRQxbrMtY5ikmd2NEOtEMpS0AxBkS1ktgSwvyGJ3iCQGZdw0I0GIs8NixF pz7w== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h17si3501456pgv.438.2019.02.14.16.29.10; Thu, 14 Feb 2019 16:29:34 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2394845AbfBNPBd (ORCPT + 99 others); Thu, 14 Feb 2019 10:01:33 -0500 Received: from mga11.intel.com ([192.55.52.93]:61509 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393887AbfBNPBb (ORCPT ); Thu, 14 Feb 2019 10:01:31 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Feb 2019 07:01:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,369,1544515200"; d="scan'208,223";a="299739594" Received: from mattu-haswell.fi.intel.com (HELO [10.237.72.164]) ([10.237.72.164]) by orsmga005.jf.intel.com with ESMTP; 14 Feb 2019 07:01:25 -0800 Subject: Re: [RFC PATCH 0/2] Fix for the internal card reader and suspend on MacBooks To: Ivan Mironov , linux-usb@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Alan Stern , Martin Liu , YueHaibing , Nicolas Boichat , Jon Flatley , Kai-Heng Feng , Benson Leung , Harry Pan , Jack Stocker , Danilo Krummrich , Samuel Sadok References: <20190213211323.6072-1-mironov.ivan@gmail.com> From: Mathias Nyman Message-ID: Date: Thu, 14 Feb 2019 17:03:23 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20190213211323.6072-1-mironov.ivan@gmail.com> Content-Type: multipart/mixed; boundary="------------B4ED0A9FF53D6336E2ACE800" Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a multi-part message in MIME format. --------------B4ED0A9FF53D6336E2ACE800 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 13.2.2019 23.13, Ivan Mironov wrote: > Hi all, > > There is a known problem on some MacBooks: internal card reader > disappears after the first suspend/resume and all subsequent attempts > to suspend laptop are failing. > > This was reported[1][2] and even discussed in the mailing lists[3], > without any real solution. After trying various things[4], including > some existing quirks, I discovered that switching link state to DISABLED > before suspend both fixes the card reader device and allows any subsequent > suspend to succeed. > > First patch adds code for this new quirk, and second patch enables this > quirk for card reader device which is used in my macbook. > > I'm not really familiar with either USB standards or kernel code to > support them, so this patch series is RFC. I'm especially unsure with the > "resume" part, because I implemented it by trial and error mostly. > However, I'm using kernel with these patches and it works for me. > > Also, feel free to suggest other kernel patches or existing quirks or > quirk combinations to fix the same problem. > > Oh, and by the way: I've checked schematics of various macbooks available > on the internet. It seems that the actual chip is Genesys Logic GL3219, > probably just with the custom ID. What I found curious, is that USB 2.0 > pins of this chip (D+ and D-) are not really connected anywhere, but > instead shorted through the resistor. Could it be possible that this > somehow messes up some logic inside the device, host controller or > linux kernel? > This card reader prevents second system suspend on latest kernels, see thread: https://marc.info/?l=linux-usb&m=154816680816246&w=2 In that case the card reader fails to resume from usb3 U3 suspend state, and ends up stuck in USB3 polling state, which now prevents suspend Could you try a testpatch (attached) to see if it helps? Thanks -Mathias --------------B4ED0A9FF53D6336E2ACE800 Content-Type: text/x-patch; name="0001-usb-warm-reset-USB3-ports-stuck-in-polling.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-usb-warm-reset-USB3-ports-stuck-in-polling.patch" From 6b3b9f3d41b8ac9cf993bf4b88a20e30c99e3b7f Mon Sep 17 00:00:00 2001 From: Mathias Nyman Date: Thu, 14 Feb 2019 15:40:12 +0200 Subject: [PATCH] usb: warm reset USB3 ports stuck in polling warm reset USB3 ports stuck in polling after 360ms. In the polling state USB3 ports are link training, which should not take longer than 360ms according to USB3 specification tPollingLFPSTimeout value. The card reader connected to xhci in MacBookPro is found stuck in this state after resuming from suspend. Signed-off-by: Mathias Nyman --- drivers/usb/core/hub.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 8d4631c..448884d 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -1151,9 +1151,10 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) */ if (hub_is_superspeed(hdev) && ((portstatus & USB_PORT_STAT_LINK_STATE) == - USB_SS_PORT_LS_POLLING)) + USB_SS_PORT_LS_POLLING)) { need_debounce_delay = true; - + set_bit(port1, hub->event_bits); + } /* Clear status-change flags; we'll debounce later */ if (portchange & USB_PORT_STAT_C_CONNECTION) { need_debounce_delay = true; @@ -2697,6 +2698,9 @@ static unsigned hub_is_wusb(struct usb_hub *hub) #define HUB_LONG_RESET_TIME 200 #define HUB_RESET_TIMEOUT 800 +#define HUB_LFPS_TIME 24 +#define HUB_LFPS_TIMEOUT 360 + /* * "New scheme" enumeration causes an extra state transition to be * exposed to an xhci host and causes USB3 devices to receive control @@ -2737,6 +2741,31 @@ static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1, || link_state == USB_SS_PORT_LS_COMP_MOD; } +static bool hub_port_stuck_in_polling(struct usb_hub *hub, int port1, + u16 portstatus) +{ + u16 link_state; + u16 portchange; + int lfps_delay = 0; + + if (!hub_is_superspeed(hub->hdev)) + return false; + + link_state = portstatus & USB_PORT_STAT_LINK_STATE; + + while (link_state == USB_SS_PORT_LS_POLLING) { + msleep(HUB_LFPS_TIME); + + hub_port_status(hub, port1, &portstatus, &portchange); + link_state = portstatus & USB_PORT_STAT_LINK_STATE; + + lfps_delay += HUB_LFPS_TIME; + if (lfps_delay > HUB_LFPS_TIMEOUT) + return true; + } + return false; +} + static int hub_port_wait_reset(struct usb_hub *hub, int port1, struct usb_device *udev, unsigned int delay, bool warm) { @@ -5329,7 +5358,8 @@ static void port_event(struct usb_hub *hub, int port1) * Warm reset a USB3 protocol port if it's in * SS.Inactive state. */ - if (hub_port_warm_reset_required(hub, port1, portstatus)) { + if (hub_port_warm_reset_required(hub, port1, portstatus) || + hub_port_stuck_in_polling(hub, port1, portstatus)) { dev_dbg(&port_dev->dev, "do warm reset\n"); if (!udev || !(portstatus & USB_PORT_STAT_CONNECTION) || udev->state == USB_STATE_NOTATTACHED) { -- 2.7.4 --------------B4ED0A9FF53D6336E2ACE800--