From patchwork Tue Aug 25 08:58:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?SsOpcsO0bWUgUG91aWxsZXI=?= X-Patchwork-Id: 259489 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=-11.4 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, RCVD_ILLEGAL_IP, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT 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 632F0C433E1 for ; Tue, 25 Aug 2020 09:00:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3B5A02067C for ; Tue, 25 Aug 2020 09:00:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=silabs.onmicrosoft.com header.i=@silabs.onmicrosoft.com header.b="i6F8LNj5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729259AbgHYJAH (ORCPT ); Tue, 25 Aug 2020 05:00:07 -0400 Received: from mail-bn8nam11on2079.outbound.protection.outlook.com ([40.107.236.79]:20448 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729698AbgHYI7w (ORCPT ); Tue, 25 Aug 2020 04:59:52 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eNmZyHti2awJ+PjzQxAtPTTIfO7sAVKwaBpcNzj2Ijiecmr9Xwsu+UwE88Jl4hVCCUK3rR8FjLP9Z1py9piA6xEuI9OKN0roTYKlbCBJNIZcyRFjVskZ5Sh08Xq7Kzrc9PXHDBgm1AVOVQLg/OWPzu9jL6bKA0jl86LQl5Di/M186XYJ5D9LsURT340m8uJH6Ml1fq/DDIdt2jc17Zvw/dG2kswbyO1GQtxXBUUu4U2z5XiW25cw95UQav0bQ1x3KcLCvFbfNxBtTAQsqCqpjydEF1Q7W9y6PnrQHbWbguX4uDU539PEQL1bgtMcuQbX+3CPT534z2JfTqB6tqK4hA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vnx1LDN0uuuMoQM1TsWcaSizN1CAv69/PathJt1c3xk=; b=RaWMdu4U3iswcJ73dFLC64Yi9LuoBJE9j2iilKI/4VEXZ89+FnVD8LIs3J0iwmoeRRdTewQNTk/koVDFF4yakfOAYrSTsD/UH06W9I/b79lcl6EV81r30SOQ/8DqW3R8wMKo6Sa/ouqKPvLCAgiaGgoy6gbaQwpDbjYyB+zAITBju6hPukxqNCHThSRUEJRmt4D3antA2e7K1IHa7LI2DrS8niXw7WcrVQd+KQJTk++jLyN4VfxtYsif+gRUaYIvayY7qNkiq1AU3JcUI0AU4PolS/Y1veKnGf2E90pTAdCAOB7yjd5WWLu0k0XRt61j4DYSmaZOVFiNxeI8FZQvqg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=silabs.com; dmarc=pass action=none header.from=silabs.com; dkim=pass header.d=silabs.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silabs.onmicrosoft.com; s=selector2-silabs-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vnx1LDN0uuuMoQM1TsWcaSizN1CAv69/PathJt1c3xk=; b=i6F8LNj57OsC6J/OakfmsQF1ibeUlh0I0c/sDXdMHHwdBlMiYWu2SNrZ9y7CAOf7LG9nFKhCP/XfrSJmPeO6sx2mDg+hsd3dlG/SJG7dLBfej8NIjHPHssSJYVq4Q181ncYuZUhkoYBP5ehx1++j8LXgta8ODz5yAehuTfBl7m0= Authentication-Results: driverdev.osuosl.org; dkim=none (message not signed) header.d=none; driverdev.osuosl.org; dmarc=none action=none header.from=silabs.com; Received: from SN6PR11MB2718.namprd11.prod.outlook.com (2603:10b6:805:63::18) by SN6PR11MB3501.namprd11.prod.outlook.com (2603:10b6:805:d4::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.26; Tue, 25 Aug 2020 08:59:14 +0000 Received: from SN6PR11MB2718.namprd11.prod.outlook.com ([fe80::85c9:1aa9:aeab:3fa6]) by SN6PR11MB2718.namprd11.prod.outlook.com ([fe80::85c9:1aa9:aeab:3fa6%4]) with mapi id 15.20.3305.026; Tue, 25 Aug 2020 08:59:13 +0000 From: Jerome Pouiller To: devel@driverdev.osuosl.org, linux-wireless@vger.kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Kalle Valo , "David S . Miller" , =?utf-8?b?SsOpcsO0bWUgUG91aWxsZXI=?= Subject: [PATCH v2 12/12] staging: wfx: add workaround for 'timeout while wake up chip' Date: Tue, 25 Aug 2020 10:58:28 +0200 Message-Id: <20200825085828.399505-12-Jerome.Pouiller@silabs.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200825085828.399505-1-Jerome.Pouiller@silabs.com> References: <20200825085828.399505-1-Jerome.Pouiller@silabs.com> X-ClientProxiedBy: PR3P192CA0002.EURP192.PROD.OUTLOOK.COM (2603:10a6:102:56::7) To SN6PR11MB2718.namprd11.prod.outlook.com (2603:10b6:805:63::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by PR3P192CA0002.EURP192.PROD.OUTLOOK.COM (2603:10a6:102:56::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Tue, 25 Aug 2020 08:59:12 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [37.71.187.125] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ba1e38ea-2b63-42b1-221e-08d848d523a5 X-MS-TrafficTypeDiagnostic: SN6PR11MB3501: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NDtufFFnrsC2nvuLCjdQZBRtM5Aft7Q5C61avkj29Wyj5j3xwrtoJiz+K+6UyGu07O3KKGKdimPdYF4iBxfREmHhplnb/MCuRQGfk9jpC2PNteSh87Kd0aiUBpHdiVWlfvwv6W5u6cOPaPxeYRo8MpdPVsd9z4NvPDtgFHSaNu2VlXtQkcmJFaA40hF6wReQpGISbLpeVqsyhCW2rJRtP41eX1VJtt1vhoBFnD+TjCnxUngBKEWNRnlKu6kjmr5g279tDp7lfM49CBpMMaugDIo+G0k04R1YfwyaOAcgu2FskejVMGlbDs4rhLCsO+No/cWHm/pKlS78enOS29ETCA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SN6PR11MB2718.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(136003)(39840400004)(396003)(346002)(376002)(366004)(316002)(5660300002)(478600001)(107886003)(1076003)(8936002)(83380400001)(16576012)(956004)(66556008)(66476007)(26005)(2616005)(186003)(8676002)(86362001)(66946007)(6486002)(54906003)(6666004)(36756003)(4326008)(66574015)(2906002)(52116002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: f13mqyYVwoQjkqKO41tGA5hckam2pEE7ev+Iv9Hfyen6aNsC1fLIm0DBQaL5LwiE+wCZtM50LaPaab95HL4D7eT6ukCf2djvvsRx6zRU/ONuHbJSErg4ixZVdTjvGdNgITNjD5/NeD7QwZG0DE/Bpn2ofoq3E6GbaKwMwFgHonwKNmrJoDmUNZVBh1VzNvmKgk5qkzO2W3zuR9JFjdrH41EqNyfetZTzPMoOPzulhPekNBCtf91KzX0FVRpTQPc3+gxPrwoW0V1CgP2i/+D/fs7B6RVlNMi3XvGhOTQxap+MmFNrqjHJGVvY6AiSoSY+AR2ezNvapRPuTUzuXR26LifqPvhUlRQTQt6jlJuK6zhNPpQTTibFtmjI/ATvsbNrGbQsR9AAUlpa6nC32XIYCNFBzY1TPqAN7ZnShpU4A5WEh5NcRJKgneJ45hE3g6mKAXdcd5pFPwYCrTh3z2qglm7E2DiPushyZMdkdRC8TnlUi63Yh1ocY3QKJ5n60/8q6LYabohk88ggl5+fnvhWyaJWeFk153CeVuNCL3jumkrxzO95+3QJdr1/0xjNtYr3vpDBOg69KJBgaOT0qLeXS078lChuste+Mz7XkD6Jz1okoU4a/kOVS/aYDVpWZf5CMa248VMlpTCokQ88+I3Plg== X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: ba1e38ea-2b63-42b1-221e-08d848d523a5 X-MS-Exchange-CrossTenant-AuthSource: SN6PR11MB2718.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2020 08:59:13.8102 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 54dbd822-5231-4b20-944d-6f4abcd541fb X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: NZBmieBIdOohjB5kZQvBpvFzvAzZMnlJLbv2+1Ml3felXp7EyZ+Qj3vrijhfb7eMys6QXDKWm51DS9ChJjgqwQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR11MB3501 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Jérôme Pouiller The host and the device can be connected with a called Wake-Up GPIO. When the host fall down this GPIO, it allows the device to enter in deep sleep and no communication with the device is no more possible (the device wakes up automatically on DTIM and fetch data if necessary). So, before to communicate with the device, the driver have to raise the Wake-up GPIO and then wait for an IRQ from the device. Unfortunately, old firmwares have a race in sleep/wake-up process and the device may never wake up. In this case, the IRQ is not sent and driver complains with "timeout while wake up chip". Then, the driver tries anyway to access the bus and an other error is raised by the bus. Fortunately, when the bug occurs, it is possible to fall down the IRQ and the device will eventually finish the sleep process. Then the driver can wake it up normally. The patch implements that workaround and add a retry limit in case something goes very wrong. Signed-off-by: Jérôme Pouiller --- drivers/staging/wfx/bh.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/staging/wfx/bh.c b/drivers/staging/wfx/bh.c index 07304a80c29b..f07bcee50e3f 100644 --- a/drivers/staging/wfx/bh.c +++ b/drivers/staging/wfx/bh.c @@ -18,25 +18,40 @@ static void device_wakeup(struct wfx_dev *wdev) { + int max_retry = 3; + if (!wdev->pdata.gpio_wakeup) return; if (gpiod_get_value_cansleep(wdev->pdata.gpio_wakeup)) return; - gpiod_set_value_cansleep(wdev->pdata.gpio_wakeup, 1); if (wfx_api_older_than(wdev, 1, 4)) { + gpiod_set_value_cansleep(wdev->pdata.gpio_wakeup, 1); if (!completion_done(&wdev->hif.ctrl_ready)) usleep_range(2000, 2500); - } else { + return; + } + for (;;) { + gpiod_set_value_cansleep(wdev->pdata.gpio_wakeup, 1); // completion.h does not provide any function to wait // completion without consume it (a kind of // wait_for_completion_done_timeout()). So we have to emulate // it. if (wait_for_completion_timeout(&wdev->hif.ctrl_ready, - msecs_to_jiffies(2))) + msecs_to_jiffies(2))) { complete(&wdev->hif.ctrl_ready); - else + return; + } else if (max_retry-- > 0) { + // Older firmwares have a race in sleep/wake-up process. + // Redo the process is sufficient to unfreeze the + // chip. dev_err(wdev->dev, "timeout while wake up chip\n"); + gpiod_set_value_cansleep(wdev->pdata.gpio_wakeup, 0); + usleep_range(2000, 2500); + } else { + dev_err(wdev->dev, "max wake-up retries reached\n"); + return; + } } }