Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp207103rwb; Tue, 4 Oct 2022 02:55:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Pxmo+xFm8+d+5X/jOACFXKoPnSg2D9EPxRbIEo5xmVsmyc0DO4NsFWGOgy/5CpTmWgFpP X-Received: by 2002:a63:1d22:0:b0:439:3e7c:8af7 with SMTP id d34-20020a631d22000000b004393e7c8af7mr22831075pgd.78.1664877312402; Tue, 04 Oct 2022 02:55:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664877312; cv=none; d=google.com; s=arc-20160816; b=BlQikK1VMHtoqoYqWS7FoLFTl3BiqKIF1wHeIDcLlrYmb+oDRIa47eTShV8qkYdvEE bpJUGDkKE6vJDTfU78gwN5/FKz9UGINPE9ACIaFQUmnKYg/xf+M8PwJwJ1aoZWQm5iHd eSlk0S6psNrm7dDG/p8PUOdBGwLGh3e4AifT/JMAs6KSdSOgzGSmlKWMQXIcjpzuPDPh z6q0/GGdSk7TuXUXcIBPvsu5pO8cZLDTClReTqgTfbps/GBSBEFjN4652iJK7C7KaBUa kg0SLSDIg6Cd/f7Z9fuHE3zq6UaE88cYuICM4t1Jx+3wml+cSVyg8Xjq8F5QVeSAUVzG KSUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=ghNlSazUBlSssMryUfGeRu8nHv3dJlLHUt+J7yhS3Pc=; b=dQ0p5v3MJor8utACdvTupr8rWeda+OImLXvL56IEmEPRme+ql80xbziWIvnnpCS5J/ krdZqfMq3s51401J4V2DVFJnw52WZBH4qnR3EK+60dyn+tVDpqJ0P7je3gglFu1yGjR4 t61y04pvV0sMAKfXfOeZ/6l9dB7f1UBFXT+HmIg+c71fMAdYK88m2XZW8B4Ap7xRzlLe vPVQnEsIjrZDvRlLmWzrgFeMTV2Upi3/G6O4rlx33FqzqbYDq8mJGIQd7iuxRoQrRVfo w5AH6O4Jp1RQjg7cZXlZpuzq3xzDONUGeKt7aJcOhU9NHXnHU0gXTehpP5OljM3rk6SJ eEdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=V86fPWoZ; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nn10-20020a17090b38ca00b002034e5450f0si2681178pjb.131.2022.10.04.02.54.54; Tue, 04 Oct 2022 02:55:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-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; dkim=pass header.i=@google.com header.s=20210112 header.b=V86fPWoZ; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229882AbiJDJu3 (ORCPT + 99 others); Tue, 4 Oct 2022 05:50:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229810AbiJDJuM (ORCPT ); Tue, 4 Oct 2022 05:50:12 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FD075BC14 for ; Tue, 4 Oct 2022 02:47:23 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-3584be56efbso73166537b3.8 for ; Tue, 04 Oct 2022 02:47:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date; bh=ghNlSazUBlSssMryUfGeRu8nHv3dJlLHUt+J7yhS3Pc=; b=V86fPWoZule0ularpOpJHJxJRlCsOspfjHcOfXMUHhIBV9LFzfaQXKT0AMWIa4t3Ss HQH8Av0u7KpaLwl2UDxrIuMFlfnWfaB7R4fiH5hS0KtZ7Yr027WHbHaX7ILoGfPsXjgf AhogQ2eAZuEo0dqW5f3ckIvIwdcD5XWZ+zvFIx2v10e8yLnv15zvpLQGQ0KJqHhF1YDO ECPTbJjE41VOb5g5GVS1AcH+4gPc5ALxV42qba8FcoAaGRK28lYMCE9c4PHM4FbpXOwW BsiliWOKGZPMk47mdhMNFp90L8MeQRj1Ae3irmTS6TGOpEiEVtUQYN7dUEIb1scOSFWU oxew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date; bh=ghNlSazUBlSssMryUfGeRu8nHv3dJlLHUt+J7yhS3Pc=; b=PyrE8Xh5XN8RWlstJffkStMdljdfWhOj+/dwdMeMWAFzMH8niB/zCnRVMcND122Kt5 JvSS6UdURlLHFVXxy0PkcER6Xx8KqbPgrtdMclCZwyqre8zGNjIpTy7l1JJWrNVee11M rld1HA6A9IEaoUjslpYI73afflBzH1W/DPYksycfWn/6os0NxM8pE3zMj3W1L+USbbK0 9y8sGymFGFZH9a7yhUyaxo6dqSvcrGWChGCBwdKrhDFlFxFGzGcBmmHatbs9yGXhMDF9 7jYJIeqaiMwG1WfhwpZCrIwkEgHE8N1wtwKHeFkmeRY1IvMLkMtvvTVl9mxNBPs0d2kt 12XQ== X-Gm-Message-State: ACrzQf0jEOx9KXaoyIm5vfx7tY0q+B64QJzL4RCvVbUz0r2RJ9ZJMlnL VR0bDtiG2GMdHvVrLdbO8KGwDHF54U1WdqT/k6fniGYc5onk6Z0HVjHojNs1q+/mDjx2eOOJvoN fI6ZChUJrFgoS3R2ZpnPmuP6kbvZ6dwzlZNomdMYjY6KLo38q0/QELuSxibceFLOvHOd8qVoXpw IV X-Received: from apusaka-p920.tpe.corp.google.com ([2401:fa00:1:17:e06f:8778:ebde:592c]) (user=apusaka job=sendgmr) by 2002:a81:9b0f:0:b0:354:488:c995 with SMTP id s15-20020a819b0f000000b003540488c995mr23515334ywg.167.1664876842230; Tue, 04 Oct 2022 02:47:22 -0700 (PDT) Date: Tue, 4 Oct 2022 17:47:14 +0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221004174632.v2.1.I46e98b47be875d0b9abff2d19417c612077d1909@changeid> Subject: [PATCH v2] Bluetooth: btusb: Introduce generic USB reset From: Archie Pusaka To: linux-bluetooth , Luiz Augusto von Dentz , Marcel Holtmann Cc: CrosBT Upstreaming , Archie Pusaka , Abhishek Pandit-Subedi , Ying Hsu , Johan Hedberg , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Archie Pusaka On cmd_timeout with no reset_gpio, reset the USB port as a last resort. This patch changes the behavior of btusb_intel_cmd_timeout and btusb_rtl_cmd_timeout. Signed-off-by: Archie Pusaka Reviewed-by: Abhishek Pandit-Subedi Reviewed-by: Ying Hsu --- Tested by not cancelling cmd_timer when handing hci event. Before the patch: ERR kernel: [ 716.929206] Bluetooth: hci_cmd_timeout() hci0: command 0x0000 tx timeout ERR kernel: [ 716.929218] Bluetooth: btusb_rtl_cmd_timeout() hci0: No gpio to reset Realtek device, ignoring After the patch: ERR kernel: [ 225.270048] Bluetooth: hci_cmd_timeout() hci0: command 0x0000 tx timeout ERR kernel: [ 225.270060] Bluetooth: btusb_rtl_cmd_timeout() hci0: Resetting usb device. INFO kernel: [ 225.386613] usb 3-3: reset full-speed USB device number 3 using xhci_hcd Changes in v2: * Update commit message drivers/bluetooth/btusb.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 271963805a38..11040124ef79 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -696,6 +696,19 @@ struct btusb_data { unsigned cmd_timeout_cnt; }; +static void generic_usb_reset(struct hci_dev *hdev, struct btusb_data *data) +{ + int err; + + bt_dev_err(hdev, "Resetting usb device."); + /* This is not an unbalanced PM reference since the device will reset */ + err = usb_autopm_get_interface(data->intf); + if (!err) + usb_queue_reset_device(data->intf); + else + bt_dev_err(hdev, "Failed usb_autopm_get_interface: %d", err); +} + static void btusb_intel_cmd_timeout(struct hci_dev *hdev) { struct btusb_data *data = hci_get_drvdata(hdev); @@ -705,7 +718,7 @@ static void btusb_intel_cmd_timeout(struct hci_dev *hdev) return; if (!reset_gpio) { - bt_dev_err(hdev, "No way to reset. Ignoring and continuing"); + generic_usb_reset(hdev, data); return; } @@ -736,7 +749,7 @@ static void btusb_rtl_cmd_timeout(struct hci_dev *hdev) return; if (!reset_gpio) { - bt_dev_err(hdev, "No gpio to reset Realtek device, ignoring"); + generic_usb_reset(hdev, data); return; } @@ -761,7 +774,6 @@ static void btusb_qca_cmd_timeout(struct hci_dev *hdev) { struct btusb_data *data = hci_get_drvdata(hdev); struct gpio_desc *reset_gpio = data->reset_gpio; - int err; if (++data->cmd_timeout_cnt < 5) return; @@ -787,13 +799,7 @@ static void btusb_qca_cmd_timeout(struct hci_dev *hdev) return; } - bt_dev_err(hdev, "Multiple cmd timeouts seen. Resetting usb device."); - /* This is not an unbalanced PM reference since the device will reset */ - err = usb_autopm_get_interface(data->intf); - if (!err) - usb_queue_reset_device(data->intf); - else - bt_dev_err(hdev, "Failed usb_autopm_get_interface with %d", err); + generic_usb_reset(hdev, data); } static inline void btusb_free_frags(struct btusb_data *data) -- 2.38.0.rc1.362.ged0d419d3c-goog