Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp640005rwb; Thu, 6 Oct 2022 02:21:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7kX7YM4/6bZ5p3jYDvp86Yevu0z8xM8TiF9qK8cCrR4ohOQa1ipsaUYUpp5tJDAm9hweBP X-Received: by 2002:a05:6a00:1c99:b0:562:6292:9e4e with SMTP id y25-20020a056a001c9900b0056262929e4emr4257412pfw.22.1665048074801; Thu, 06 Oct 2022 02:21:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665048074; cv=none; d=google.com; s=arc-20160816; b=bveaFCP+qwre7geYc+4cokCGh0vjSgU9o7lA9fwUCqwAIPBJGJQsu6LQ5UPHq+RMju ZuvzBdwumwJ2tkuEcw+biGKHTg2dcFmpZEDvLK4ZlJT0eYnFjQdgWzcpDMx8ICsWBfxP ELiVOfA9S2itkhbceREwwngxZ0mWY+7lnon5vYLEsbJiOV+1t4mt0zdhO+e1ZShmB+v2 wTjwwa1PNUOpyNOc7A+LvFOlL3jEzkscEJ/lmY0mNDfrVtqPTZHwqEjVptHKJ/saJXHP YC8GSjoVMf1P9DEzDap8G/i4cRF5OX2T2EapjBrXiqxNt7DHyjJoP78/qa4hlVhhjPVG ECzQ== 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=W6dnd6MUybWhVHYUHQ8d7S6D4UzG0vGs7tI9w8WKSPw=; b=oM7+PzEePe8T+O7xAl1SJbPy1uuz5MpBm51MtPdUX1goRUOUo2lqB9czYICDlyroX7 bniig1kqdUBCL5HJeEQAkT3PnWsj0UoL+KcdrLicxGMZjGvTmmogZ9Iu/ufKOs5NI/Jn XOgWYCKUe2+Njtw5F+OTZDFm0DZ2FYtlT350uvoMAJA1KvIFxBF5J9zYbLbaI7wAj4NJ wbUE3aTvzSWmNwT/AE4SRrSLye+ZRBVYxewf8SR1yY0SjlSKYcebZwlKtLS/v7ypAKFc Tt0wrx1eA+ax94f0t/JK0GstnZ8+uJ//miY6pbA9Ng+qeP4ER8DDRzDilRigwgHWz5Ah 7nUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=SSpzU+3w; 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 n189-20020a6340c6000000b0042b6f63ce67si18632238pga.407.2022.10.06.02.20.49; Thu, 06 Oct 2022 02:21:14 -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=SSpzU+3w; 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 S231327AbiJFJJm (ORCPT + 99 others); Thu, 6 Oct 2022 05:09:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231328AbiJFJJk (ORCPT ); Thu, 6 Oct 2022 05:09:40 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 715CACFE for ; Thu, 6 Oct 2022 02:09:37 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-349423f04dbso13088237b3.13 for ; Thu, 06 Oct 2022 02:09:37 -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=W6dnd6MUybWhVHYUHQ8d7S6D4UzG0vGs7tI9w8WKSPw=; b=SSpzU+3wLTsbRTZVM5yu2Enu8uvoYL9bqFOuq1fID5Ck3vddYC9Fn2fSzvLKbenMUx fuF4R6M5SBRsLSABcNeCV9rpYF62Ev+3xv/A+pnTFcZsv2lxVRPguNBfm5QCC6EMr7E7 H2vr6MX5XTebP3D0H5ofNAwLXJkTUMjqS54djUwpy0stP3+jl9ypp6h1ipVNdaNPtss1 SpAiACIC768tO0rIonQB/nhoOdlTl9Bl9YlCeF4YPv6cVlA7MjUcyKgelLElupjTIX2q KiDfZ6dzGys/MZJ8FBdi91HZBLTjIe20tkGm6j4flwNHexG6NHjuhpLIIUgDGpxwmrpg 3Rag== 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=W6dnd6MUybWhVHYUHQ8d7S6D4UzG0vGs7tI9w8WKSPw=; b=VbZFpMx96+fLpBWq22V2ACHwJh83q92IgILsIvczGUB7evpsxxwFFaqn+d1RyRORCT 1Y+eQZecUTKOobO7iLnUjT8HFluilWNzKoZPvqcmobc4T3DlE64jFlRE5jLgpmV5CP9b 1rpachpix0wdU5AMOW02+4NwZDuc9TrVXbrMJsRu210fCY+O6KdIutQGZKfbNr/UU0S8 ijeZBy1FRQVSZDiMelywp3DiHxskZRwVlg3O29GjVN7TC/vD3jd0IsSC/w4HMDbkMNvd W85G9Gwj64zVD6tZ0pa7eeukzIahzfD8/XW+7JhfG8C769L/uBBpSZp7xw3jinpk3teQ CIQA== X-Gm-Message-State: ACrzQf1l2ayGB0+c4xvVFkgdWF+YUJBzn50P44F7tpzgiTHV6CsVwd9I PtTZab5rgAcZA9B5rFkQju7F4UlVlyBFUYQhGab+YHW3edb9sQUECUREak+AEVGcIKe57BjCLFv CMSEaOthQz9/tkOCWgznOW0Ys4xg18l8IBkjGvRrf9SlBrngldZyFAValBrSRc45Fg8FJ3XPn/g VM X-Received: from apusaka-p920.tpe.corp.google.com ([2401:fa00:1:17:1fb9:e3c:c40d:dd12]) (user=apusaka job=sendgmr) by 2002:a25:bc83:0:b0:6bc:a6d2:5216 with SMTP id e3-20020a25bc83000000b006bca6d25216mr3841415ybk.204.1665047376628; Thu, 06 Oct 2022 02:09:36 -0700 (PDT) Date: Thu, 6 Oct 2022 17:09:31 +0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221006170915.v3.1.I46e98b47be875d0b9abff2d19417c612077d1909@changeid> Subject: [PATCH v3] 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 , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Johan Hedberg , Paolo Abeni , linux-kernel@vger.kernel.org, netdev@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=unavailable 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 v3: * introduce hdev->reset to override the generic reset function Changes in v2: * Update commit message drivers/bluetooth/btusb.c | 35 +++++++++++++++++++++++--------- include/net/bluetooth/hci_core.h | 1 + 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 271963805a38..e6add3604214 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -696,6 +696,28 @@ struct btusb_data { unsigned cmd_timeout_cnt; }; +static void btusb_reset(struct hci_dev *hdev) +{ + struct btusb_data *data; + int err; + + if (hdev->reset) { + hdev->reset(hdev); + return; + } + + data = hci_get_drvdata(hdev); + /* This is not an unbalanced PM reference since the device will reset */ + err = usb_autopm_get_interface(data->intf); + if (err) { + bt_dev_err(hdev, "Failed usb_autopm_get_interface: %d", err); + return; + } + + bt_dev_err(hdev, "Resetting usb device."); + usb_queue_reset_device(data->intf); +} + static void btusb_intel_cmd_timeout(struct hci_dev *hdev) { struct btusb_data *data = hci_get_drvdata(hdev); @@ -705,7 +727,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"); + btusb_reset(hdev); return; } @@ -736,7 +758,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"); + btusb_reset(hdev); return; } @@ -761,7 +783,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 +808,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); + btusb_reset(hdev); } static inline void btusb_free_frags(struct btusb_data *data) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index c54bc71254af..55a40f5606c3 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -659,6 +659,7 @@ struct hci_dev { int (*set_diag)(struct hci_dev *hdev, bool enable); int (*set_bdaddr)(struct hci_dev *hdev, const bdaddr_t *bdaddr); void (*cmd_timeout)(struct hci_dev *hdev); + void (*reset)(struct hci_dev *hdev); bool (*wakeup)(struct hci_dev *hdev); int (*set_quality_report)(struct hci_dev *hdev, bool enable); int (*get_data_path_id)(struct hci_dev *hdev, __u8 *data_path); -- 2.38.0.rc1.362.ged0d419d3c-goog