Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1498292rwb; Tue, 4 Oct 2022 23:57:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Bx00KaEG3mWRdsdVr5WRXgRCyC6pzr0KWC4vYXhjfPmd6/I8O39kMwfBaJHr8GyrV0Rtm X-Received: by 2002:a05:6402:350b:b0:459:72ef:cf6b with SMTP id b11-20020a056402350b00b0045972efcf6bmr4808043edd.19.1664953062186; Tue, 04 Oct 2022 23:57:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664953062; cv=none; d=google.com; s=arc-20160816; b=JY+2UAd3mBrubxbrm5zxOWy3qb8X4noFX4ASVciinhGtPT496iBFH56N5b/d6/jaJc WBGiiovuS9+Q8OTjaLzqlKvyiezNcqSjR+Fstd3Uk7DjJ2GuhDRZNQpVEPNVXbFdA0iz 7QGB86Btea/nGaIYDq/Bz/alNLXREYWsUWUvfQbwEVn1ZmFKIRiwFB68ZCtQqQNCcU5M WF4O20abYcA7iN+SeOos1TMP4zpYdkRnLSijYStPl8hCprVLxRrmMfsCZT1dZlH39AWj +zlj0mseSYOPH4qi8fk/BI3Vu1OfcvPMzA+fy6tFDkY2wH8EhMbYL787T8fi074MLC9s 28Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=gY5AbX7M1j37Hq5yd7r3xMcaFoABrkHiHudnF2ZVA9g=; b=wuJ48DLm8bxENt3vCTVIGWRQyl61QMz5rWkxqrwdExnaKXM/9tH7cdHRkePrI/TdUy 5DQuXMbVGPPQNmWZidhWgV7A3LnVTjAwCQr9Koq5Nou81+RK2N5WWR6ao7inC0AQq9O9 KTmEjfaxVGbc16AXmgp0qwEJ7OecsvExbYUYwyQyyozdJtvdry43UcT8B1+s71vj8Qva DZQvK1cUqP8NkiLdPuscHFk267PFBs10B2dZT3x55EpJeOIfs0GZNwZKFAYN4b6HwzZf pT8uZRgr/ON/H8g9Ae212z0RdhIX588jKzZhH6V+sYMv5jq/zZ3DwsIb66/1tXBPu2j0 koXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Ot0HusIh; 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; 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 qf40-20020a1709077f2800b007123952b00dsi13159280ejc.100.2022.10.04.23.56.59; Tue, 04 Oct 2022 23:57:42 -0700 (PDT) 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; dkim=pass header.i=@google.com header.s=20210112 header.b=Ot0HusIh; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229727AbiJEGoH (ORCPT + 99 others); Wed, 5 Oct 2022 02:44:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229532AbiJEGoF (ORCPT ); Wed, 5 Oct 2022 02:44:05 -0400 Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43459647D5 for ; Tue, 4 Oct 2022 23:44:04 -0700 (PDT) Received: by mail-qt1-x831.google.com with SMTP id e20so9318687qts.1 for ; Tue, 04 Oct 2022 23:44:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=gY5AbX7M1j37Hq5yd7r3xMcaFoABrkHiHudnF2ZVA9g=; b=Ot0HusIhlbu/R0cyE0zYoUJOHdl4uPBd89Eeeha2fz8nbt0ivP+7WZWih5tGSLWpBi vP8XUJEqmuXC0wfB+ZUKzpDAAB4iDHpwRmVa1XJv2XdktllTDH+0RkLfRpl24Df8lo0L 2iRFWPfo26MXWs5k52UDJzRNOobaI91y8yeppJoQi4hHaOTT6Ja/rl0kERA9HSvqu65D RSKwffM18bxRFuhLhY2EewGHzf+v2MR6KLpFb3I9B5B1M2dYaCRr4hNfC68QwkPZ14Bu 13Ifm5ycCzUYQ5ey/ZEWyF5qZH4d/39Chv37EosODK4Ebgtvt40jtIWdHmHmewOzDi6L /2xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=gY5AbX7M1j37Hq5yd7r3xMcaFoABrkHiHudnF2ZVA9g=; b=QnxaqRLo2Nu8bEM3XKaYoXG06bswOn/xwsBgpubm41OmH3SOCOU4+Go7SFUy4+nnPa ZuuhUjsBfWifspBE9O7Dy/0AQIZUNNHQf5/J6WkdkZH+47L2YfAX02LD+ml26VGiM7XL gh9HcRecpgiYL3qhqlMEKj9hzbmOhrXdf2Hcf9tIZsS/whDF2FdCq8N1JNeeA52POs4m bl6MzQI/i4mTiVMNhxS0S27dGB/gdfEemcQxRv3v5AeXrw/onSoQ8P8G4AuIVCYWAJgA 4WuIBkyG9zIEwEYZePaIaVsqljQO5QwFv99zLUM74yKE7ypNwb0eDl3siDmzy/RWqFy3 vxRQ== X-Gm-Message-State: ACrzQf3+hSniZpiJtYWOk25SPv/SHYmzBWfwPpU+1Reu4+x4I+oU75mL RGwuTE20j6mZwu4J5/vF0PT+35/YKtjwSLOzWtqAXA== X-Received: by 2002:ac8:588c:0:b0:35b:b351:f470 with SMTP id t12-20020ac8588c000000b0035bb351f470mr22778816qta.42.1664952243143; Tue, 04 Oct 2022 23:44:03 -0700 (PDT) MIME-Version: 1.0 References: <20221004163224.1.I46e98b47be875d0b9abff2d19417c612077d1909@changeid> In-Reply-To: From: Archie Pusaka Date: Wed, 5 Oct 2022 14:43:51 +0800 Message-ID: Subject: Re: [PATCH] Bluetooth: btusb: Introduce generic USB reset To: Luiz Augusto von Dentz Cc: linux-bluetooth , Marcel Holtmann , 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=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_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-kernel@vger.kernel.org Hi Luiz, On Wed, 5 Oct 2022 at 04:53, Luiz Augusto von Dentz wrote: > > Hi Archie, > > On Tue, Oct 4, 2022 at 1:33 AM Archie Pusaka wrote: > > > > From: Archie Pusaka > > > > On cmd_timeout and there is no reset_gpio, reset the USB port as a > > last resort. > > > > Signed-off-by: Archie Pusaka > > Reviewed-by: Abhishek Pandit-Subedi > > Reviewed-by: Ying Hsu > > > > --- > > > > 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); > > Lets just have one line printed if it fails: > > 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); > OK, will update > > +} > > + > > 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); > > Lets call it btusb_reset since this is specific for the data->intf, > btw is this safe, or perhaps we want to refactor this to have it > callback based so each vendor can add it own specific hdev->reset > callback hardware reset with btusb_reset serving as default callback? OK. I think this is safe at least for now, since resetting btusb is probably better than just giving up doing nothing. But I can add hdev->reset if that is desirable. > Also the logic of btusb_intel_cmd_timeout should probably be put > inside btintel.c and I don't think we need the gpio_desc reference to > be inside the btusb_data since we can call gpiod_get_optional during > the reset phase and immediately do gpiod_put after done using it. > I am not familiar with this part. Perhaps it's better for this to be managed by another patch, since it is not the focus of this patch? > > 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 > > > > > -- > Luiz Augusto von Dentz Cheers, Archie