[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8c734b83-aa2a-83a6-cb12-28e36ace2bbb@collabora.com>
Date: Tue, 13 Sep 2022 09:47:47 +0200
From: AngeloGioacchino Del Regno
<angelogioacchino.delregno@...labora.com>
To: sean.wang@...iatek.com, marcel@...tmann.org,
johan.hedberg@...il.com, luiz.dentz@...il.com
Cc: Soul.Huang@...iatek.com, YN.Chen@...iatek.com,
Leon.Yen@...iatek.com, Eric-SY.Chang@...iatek.com,
Deren.Wu@...iatek.com, km.lin@...iatek.com,
robin.chiu@...iatek.com, Eddie.Chen@...iatek.com,
ch.yeh@...iatek.com, posh.sun@...iatek.com, ted.huang@...iatek.com,
Stella.Chang@...iatek.com, Tom.Chou@...iatek.com,
steve.lee@...iatek.com, jsiuda@...gle.com, frankgor@...gle.com,
abhishekpandit@...gle.com, michaelfsun@...gle.com,
abhishekpandit@...omium.org, mcchou@...omium.org,
shawnku@...gle.com, linux-bluetooth@...r.kernel.org,
linux-mediatek@...ts.infradead.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/4] Bluetooth: btusb: mediatek: use readx_poll_timeout
instead of open coding
Il 13/09/22 00:18, sean.wang@...iatek.com ha scritto:
> From: Sean Wang <sean.wang@...iatek.com>
>
> Use readx_poll_timeout instead of open coding to poll the hardware reset
> status until it is done.
>
> Signed-off-by: Sean Wang <sean.wang@...iatek.com>
Hello Sean, thanks for the patch!
However, there's something to improve...
> ---
> drivers/bluetooth/btusb.c | 32 ++++++++++++++++++--------------
> 1 file changed, 18 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
> index c3daba17de7f..4dc9cae3e937 100644
> --- a/drivers/bluetooth/btusb.c
> +++ b/drivers/bluetooth/btusb.c
..snip..
> @@ -2910,18 +2918,14 @@ static void btusb_mtk_cmd_timeout(struct hci_dev *hdev)
> btusb_mtk_uhw_reg_write(data, MTK_BT_SUBSYS_RST, 0);
> btusb_mtk_uhw_reg_read(data, MTK_BT_SUBSYS_RST, &val);
>
> - /* Poll the register until reset is completed */
> - do {
> - btusb_mtk_uhw_reg_read(data, MTK_BT_MISC, &val);
> - if (val & MTK_BT_RST_DONE) {
> - bt_dev_dbg(hdev, "Bluetooth Reset Successfully");
> - break;
> - }
> + err = readx_poll_timeout(btusb_mtk_reset_done, hdev, val,
> + val & MTK_BT_RST_DONE,
> + 100000, 1000000);
I agree with using readx_poll_timeout() instead of open coding the same, but
there's a catch: this macro uses usleep_range(), which is meant to be used
for sleeping less than ~20ms.
Even the kerneldoc at include/linux/iopoll.h advertises that:
* @sleep_us: Maximum time to sleep between reads in us (0
* tight-loops). Should be less than ~20ms since usleep_range
* is used (see Documentation/timers/timers-howto.rst).
So, if there's any reason for which you can't sleep for less than 100ms
per iteration, I'm afraid that you can't use readx_poll_timeout()...
...otherwise, please change sleep_us to 20000 and keep the timeout at 1 sec.
Regards,
Angelo
> + if (err < 0)
> + bt_dev_err(hdev, "Reset timeout");
>
> - bt_dev_dbg(hdev, "Polling Bluetooth Reset CR");
> - retry++;
> - msleep(MTK_BT_RESET_WAIT_MS);
> - } while (retry < MTK_BT_RESET_NUM_TRIES);
> + if (val & MTK_BT_RST_DONE)
> + bt_dev_dbg(hdev, "Bluetooth Reset Successfully");
>
> btusb_mtk_id_get(data, 0x70010200, &val);
> if (!val)
Powered by blists - more mailing lists