Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp194291rdh; Mon, 18 Dec 2023 16:30:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IFitB/arzWnb8DvHvXXXNicvhZhCJ2/brKZnYEl0noVAeKs5LcrEgC4Q0fL7oC72spkT64b X-Received: by 2002:ac2:5e2d:0:b0:50e:3868:5383 with SMTP id o13-20020ac25e2d000000b0050e38685383mr1213442lfg.2.1702945813370; Mon, 18 Dec 2023 16:30:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702945813; cv=none; d=google.com; s=arc-20160816; b=IreghvDmW7+PwLjvmaR6vHSSBHMWPKNZFKY3+Nxr3bWVCsztfHLTTmxBqQ/WzOBrmp ck9208GVXuRf/IqeatPXaN4ezB+EUTBY1FhCwuGcByrg9ACxEqVPnruBBST26YXkwfQ0 nJLv2iTah1saT+juUa3/MjutypLesfeaJmd/gBExTtnxq7Qm8mbrhhnI8x8GbEaA3ihu wC7QDDF4XH/KYbSFGeIq2IiQJvOI+QHE62N2k+QBNWj+dMZAvfz1NbmPxXubvpoD0m7S jDBXim/NsVtJUJ66VKCxJIiXwYkrz5t2gtzDWhCUXupi5w0cLNT6aDG1ZE3fPVsWseDL jQuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=O9qg9WcYvdr4wru6IqqwEj11ePgpxG1ae082lArFfG0=; fh=aWJFS5SYt7/M2hamxUaS2VqqDfgTqsTBkBsDCDuqycs=; b=TBy0MW5Dud5avXYGjNQj+Zoctsg+qcGshnykrBgCtAZ04uOgVJ89b/KUxBINw489lG ZmjU4JEDLpqw7GL/qu6BolBXS/9AHCx4j91x3vev3Eyfb2RScNUT67NWhbW8siF+K1Li O07POG3dHaYBCmzbWqcJVtjv7JJcA3L4NevyxSuVClrQuAnKdEggtQd4K6q/erSRkRMN OEfal4YZ604N1VKJxCTC8ZeYk1S+NRYcQMxFOYapxyVfoXcW4mKM3VF1WyIOHYb2/jqO TwF3noTFicFiMjYNw7G7I5+qlTz8afN6q+/JwGUI0/Ha4QCA0hdb0IWqENIYlkeHV+Hi Y8Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UqQed9Mu; spf=pass (google.com: domain of linux-bluetooth+bounces-651-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-651-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id rv23-20020a17090710d700b00a234955e110si1684512ejb.334.2023.12.18.16.30.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 16:30:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-651-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UqQed9Mu; spf=pass (google.com: domain of linux-bluetooth+bounces-651-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-651-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E907F1F24622 for ; Tue, 19 Dec 2023 00:30:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7EF1010E4; Tue, 19 Dec 2023 00:30:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UqQed9Mu" X-Original-To: linux-bluetooth@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E52D91381; Tue, 19 Dec 2023 00:30:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FF2CC433CA; Tue, 19 Dec 2023 00:30:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702945804; bh=dw3k5aL/+6q2ocOCHy31//nhjrvy16fo24znW4qvxy0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=UqQed9MujdbM2y2QI6n6x1UOSn5io0ur9S0LEQaA5dV9T1nl4BL08O2LwaFX/mSb1 DV8vAEBU5zmeelUVdkYrF459xs4/ctuN165RYzo8Df44Wur8wldRRYDbgd13InHw2y YlzBCbu1IEcI8S9ZvyyHiiZrRLMdWLpYsY39fLefa5a4ZfY+wDW1ODGWW1J8x+LZOu nG/NjW52sJA/K52ZWIfMwbcm3aopP6CLVpT/ctgwspvukJbHBg/U0rut1iW4ZIriTU 8r7KQGFx0kQECZcT2yPJqmPM7sV8UR/M2iOsPTw+XpikDECz3+B0+G3mJsw5+Vv9TS seECCCXdIfrcQ== Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-50e40b43798so239561e87.0; Mon, 18 Dec 2023 16:30:04 -0800 (PST) X-Gm-Message-State: AOJu0YzEF84r4wjUuAmcPW4O74Pe5zxNwsC17esBD47/10OR0bzRvWz0 fW7qpC2VCvcNmyJ8FJ413jOeAWK09JyZyvG7Htg= X-Received: by 2002:a19:9141:0:b0:50e:48c4:ba7d with SMTP id y1-20020a199141000000b0050e48c4ba7dmr43425lfj.2.1702945802370; Mon, 18 Dec 2023 16:30:02 -0800 (PST) Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231215063714.7684-1-hao.qin@mediatek.com> In-Reply-To: <20231215063714.7684-1-hao.qin@mediatek.com> From: Sean Wang Date: Mon, 18 Dec 2023 18:29:52 -0600 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/1] Bluetooth: btusb: mediatek: add a recovery method for MT7922 To: Hao Qin Cc: Marcel Holtmann , Johan Hedberg , Luiz Von Dentz , Sean Wang , Deren Wu , Aaron Hou , Chris Lu , Steve Lee , linux-bluetooth , linux-kernel , linux-mediatek Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Hao, On Fri, Dec 15, 2023 at 12:40=E2=80=AFAM Hao Qin wro= te: > > From: "hao.qin" > > For MT7922, perform a reset before patch download to avoid > unexpected problems caused by inconsistency between upper layer > status and dongle status. Add USB reset retry to recover from > unexpected patch download failure. After looking through the patch, I guess the patch providing the reset mechanism for 1) the core layer to call when cmd is timeout 2) resetting the device before the patch download 3) handling situations where something goes wrong during the patch download phase right ? if so, the description should be revised to make the patch close to what it does > > Signed-off-by: hao.qin > --- > drivers/bluetooth/btusb.c | 66 +++++++++++++++++++++++++++------------ > 1 file changed, 46 insertions(+), 20 deletions(-) > > diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c > index 0926e4451802..778e1a0d9cae 100644 > --- a/drivers/bluetooth/btusb.c > +++ b/drivers/bluetooth/btusb.c > @@ -2812,7 +2812,7 @@ static int btusb_mtk_hci_wmt_sync(struct hci_dev *h= dev, > * WMT command. > */ > err =3D wait_on_bit_timeout(&data->flags, BTUSB_TX_WAIT_VND_EVT, > - TASK_INTERRUPTIBLE, HCI_INIT_TIMEOUT); > + TASK_INTERRUPTIBLE, HCI_CMD_TIMEOUT); The changes are not specific to MT7922 and do not align with the commit description. Kindly consider moving them to another patch and provide clear reasons why they are necessary for MT7922 or any other chipsets. > if (err =3D=3D -EINTR) { > bt_dev_err(hdev, "Execution of wmt command interrupted"); > clear_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags); > @@ -2994,28 +2994,22 @@ static u32 btusb_mtk_reset_done(struct hci_dev *h= dev) > return val & MTK_BT_RST_DONE; > } > > -static int btusb_mtk_reset(struct hci_dev *hdev, void *rst_data) > +static int btusb_mtk_subsys_reset(struct hci_dev *hdev, u32 dev_id) > { > struct btusb_data *data =3D hci_get_drvdata(hdev); > - struct btmediatek_data *mediatek; > u32 val; > int err; > > - /* It's MediaTek specific bluetooth reset mechanism via USB */ > - if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) { > - bt_dev_err(hdev, "last reset failed? Not resetting again"= ); > - return -EBUSY; > - } > - > - err =3D usb_autopm_get_interface(data->intf); > - if (err < 0) > - return err; > - > - btusb_stop_traffic(data); > - usb_kill_anchored_urbs(&data->tx_anchor); > - mediatek =3D hci_get_priv(hdev); > - It seems that you refactored the existing btusb_mtk_reset in the patch. Could you please create another patch specifically for the refactoring without introducing any functional changes of MT7922 prior to adding the patch? This way would be good for ease of review and tracking in the future. Additionally, it ensures that those working on MT7921 are aware of the patch and its modifications. > - if (mediatek->dev_id =3D=3D 0x7925) { > + if (dev_id =3D=3D 0x7922) { > + btusb_mtk_uhw_reg_read(data, MTK_BT_SUBSYS_RST, &val); > + val |=3D 0x00002020; > + btusb_mtk_uhw_reg_write(data, MTK_BT_SUBSYS_RST, val); > + btusb_mtk_uhw_reg_write(data, MTK_EP_RST_OPT, 0x00010001)= ; > + btusb_mtk_uhw_reg_read(data, MTK_BT_SUBSYS_RST, &val); > + val |=3D (1 << 0); We can utilize BIT(0) instead of 1 << 0 > + btusb_mtk_uhw_reg_write(data, MTK_BT_SUBSYS_RST, val); > + msleep(100); > + } else if (dev_id =3D=3D 0x7925) { > btusb_mtk_uhw_reg_read(data, MTK_BT_RESET_REG_CONNV3, &va= l); > val |=3D (1 << 5); We can utilize BIT(5) instead of 1 << 5 > btusb_mtk_uhw_reg_write(data, MTK_BT_RESET_REG_CONNV3, va= l); > @@ -3053,14 +3047,41 @@ static int btusb_mtk_reset(struct hci_dev *hdev, = void *rst_data) > err =3D readx_poll_timeout(btusb_mtk_reset_done, hdev, val, > val & MTK_BT_RST_DONE, 20000, 1000000); > if (err < 0) > - bt_dev_err(hdev, "Reset timeout"); > + bt_dev_err(hdev, "Subsys reset timeout"); I guess it would be better to avoid the unnecessary change unrelated to the patch. > + > + if (dev_id =3D=3D 0x7922) > + btusb_mtk_uhw_reg_write(data, MTK_UDMA_INT_STA_BT, 0x0000= 00FF); > > btusb_mtk_id_get(data, 0x70010200, &val); > if (!val) > bt_dev_err(hdev, "Can't get device id, subsys reset fail.= "); > > - usb_queue_reset_device(data->intf); > + return err; > +} > + > +static int btusb_mtk_reset(struct hci_dev *hdev, void *rst_data) > +{ > + struct btusb_data *data =3D hci_get_drvdata(hdev); > + struct btmediatek_data *mediatek; > + int err; > + > + /* It's MediaTek specific bluetooth reset mechanism via USB */ > + if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) { > + bt_dev_err(hdev, "last reset failed? Not resetting again"= ); > + return -EBUSY; > + } > + > + err =3D usb_autopm_get_interface(data->intf); > + if (err < 0) > + return err; > + > + btusb_stop_traffic(data); > + usb_kill_anchored_urbs(&data->tx_anchor); > + mediatek =3D hci_get_priv(hdev); > > + err =3D btusb_mtk_subsys_reset(hdev, mediatek->dev_id); > + > + usb_queue_reset_device(data->intf); > clear_bit(BTUSB_HW_RESET_ACTIVE, &data->flags); > > return err; > @@ -3119,6 +3140,8 @@ static int btusb_mtk_setup(struct hci_dev *hdev) > fwname =3D FIRMWARE_MT7668; > break; > case 0x7922: > + btusb_mtk_subsys_reset(hdev, dev_id); > + fallthrough; > case 0x7961: > case 0x7925: > if (dev_id =3D=3D 0x7925) > @@ -3134,6 +3157,9 @@ static int btusb_mtk_setup(struct hci_dev *hdev) > btusb_mtk_hci_wmt_sync); > if (err < 0) { > bt_dev_err(hdev, "Failed to set up firmware (%d)"= , err); > + btusb_stop_traffic(data); > + usb_kill_anchored_urbs(&data->tx_anchor); > + usb_queue_reset_device(data->intf); The change doesn't appear to be specific to MT7922, as the commit description suggests. Please consider splitting it into another patch to address any existing chipset issues, if necessary. > return err; > } > > -- > 2.18.0 > >