From patchwork Thu Jan 16 03:22:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rocky Liao X-Patchwork-Id: 190644 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9199BC33CB2 for ; Thu, 16 Jan 2020 03:23:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 68A862084D for ; Thu, 16 Jan 2020 03:23:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=mg.codeaurora.org header.i=@mg.codeaurora.org header.b="NO7D9H6j" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726552AbgAPDXK (ORCPT ); Wed, 15 Jan 2020 22:23:10 -0500 Received: from mail26.static.mailgun.info ([104.130.122.26]:28863 "EHLO mail26.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729186AbgAPDXJ (ORCPT ); Wed, 15 Jan 2020 22:23:09 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1579144988; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=i6cUUbHdFxmyxXtrww4Y2pJJyGUa7lN7JxrT7wp+jjg=; b=NO7D9H6jiVZ6frifuNvXMT4WGm/C0L1CfbuyTI5eFraa3TpEDh8CCi3Y/mrHK8GjB65KBffa w9KgUrJxKqoLMw/5Pd7I/H7QxIsC639NrzSZZp+qee0o0+VqjdOfYSNMMpd3steNOxXfLZ9t R25HoCUxzFCoZ948JMAN19w6Twc= X-Mailgun-Sending-Ip: 104.130.122.26 X-Mailgun-Sid: WyI1MzIzYiIsICJsaW51eC1hcm0tbXNtQHZnZXIua2VybmVsLm9yZyIsICJiZTllNGEiXQ== Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by mxa.mailgun.org with ESMTP id 5e1fd71a.7f48c320cc00-smtp-out-n03; Thu, 16 Jan 2020 03:23:06 -0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1001) id DA8BFC43383; Thu, 16 Jan 2020 03:23:06 +0000 (UTC) Received: from rocky-Inspiron-7590.qca.qualcomm.com (unknown [180.166.53.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: rjliao) by smtp.codeaurora.org (Postfix) with ESMTPSA id DDB28C433A2; Thu, 16 Jan 2020 03:23:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org DDB28C433A2 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=rjliao@codeaurora.org From: Rocky Liao To: marcel@holtmann.org, johan.hedberg@gmail.com Cc: mka@chromium.org, linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org, linux-arm-msm@vger.kernel.org, bgodavar@codeaurora.org, hemantg@codeaurora.org, Rocky Liao Subject: [PATCH v5] Bluetooth: hci_qca: Enable power off/on support during hci down/up for QCA Rome Date: Thu, 16 Jan 2020 11:22:54 +0800 Message-Id: <20200116032254.20549-1-rjliao@codeaurora.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191225060317.5258-1-rjliao@codeaurora.org> References: <20191225060317.5258-1-rjliao@codeaurora.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org This patch registers hdev->shutdown() callback and also sets HCI_QUIRK_NON_PERSISTENT_SETUP for QCA Rome. It will power-off the BT chip during hci down and power-on/initialize the chip again during hci up. As wcn399x already enabled this, this patch also removed the callback register and QUIRK setting in qca_setup() for wcn399x and uniformly do this in the probe() routine. Signed-off-by: Rocky Liao --- Changes in v2: None Changes in v3: -moved the quirk and callback register to probe() Changes in v4: -rebased the patch with latest code -moved the quirk and callback register to probe() for wcn399x -updated commit message Changed in v5: -removed the "out" label and return err when fails drivers/bluetooth/hci_qca.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c index 1139142e8eed..d6e0c99ee5eb 100644 --- a/drivers/bluetooth/hci_qca.c +++ b/drivers/bluetooth/hci_qca.c @@ -1569,12 +1569,7 @@ static int qca_setup(struct hci_uart *hu) return ret; if (qca_is_wcn399x(soc_type)) { - /* Enable NON_PERSISTENT_SETUP QUIRK to ensure to execute - * setup for every hci up. - */ - set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks); set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks); - hu->hdev->shutdown = qca_power_off; ret = qca_read_soc_version(hdev, &soc_ver, soc_type); if (ret) @@ -1813,6 +1808,7 @@ static int qca_init_regulators(struct qca_power *qca, static int qca_serdev_probe(struct serdev_device *serdev) { struct qca_serdev *qcadev; + struct hci_dev *hdev; const struct qca_vreg_data *data; int err; @@ -1838,7 +1834,7 @@ static int qca_serdev_probe(struct serdev_device *serdev) data->num_vregs); if (err) { BT_ERR("Failed to init regulators:%d", err); - goto out; + return err; } qcadev->bt_power->vregs_on = false; @@ -1851,7 +1847,7 @@ static int qca_serdev_probe(struct serdev_device *serdev) err = hci_uart_register_device(&qcadev->serdev_hu, &qca_proto); if (err) { BT_ERR("wcn3990 serdev registration failed"); - goto out; + return err; } } else { qcadev->btsoc_type = QCA_ROME; @@ -1877,12 +1873,18 @@ static int qca_serdev_probe(struct serdev_device *serdev) return err; err = hci_uart_register_device(&qcadev->serdev_hu, &qca_proto); - if (err) + if (err) { + BT_ERR("Rome serdev registration failed"); clk_disable_unprepare(qcadev->susclk); + return err; + } } -out: return err; + hdev = qcadev->serdev_hu.hdev; + set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks); + hdev->shutdown = qca_power_off; + return 0; } static void qca_serdev_remove(struct serdev_device *serdev) From patchwork Thu Dec 26 06:45:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rocky Liao X-Patchwork-Id: 190853 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87FB7C2D0DB for ; Thu, 26 Dec 2019 06:46:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5D8BB2071E for ; Thu, 26 Dec 2019 06:46:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=mg.codeaurora.org header.i=@mg.codeaurora.org header.b="YhurIOYC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726134AbfLZGqI (ORCPT ); Thu, 26 Dec 2019 01:46:08 -0500 Received: from mail25.static.mailgun.info ([104.130.122.25]:64106 "EHLO mail25.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725939AbfLZGqI (ORCPT ); Thu, 26 Dec 2019 01:46:08 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1577342767; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=3KvIzKQ0OKqH/YujhVWDD4HZ/nw32REwxKJ0gvEgQOY=; b=YhurIOYCiePOa+1XqeApXPcMeMHU+76O4syDnrXpmLKmH8WJNs8B/wgC5jvs+FGPzTYW7WPt yOXppEavx+fUyRTdLD3wfOQKuxiogxqb8/SljXLUc+ubgKyPhPx7XBXihlA5El+vVVdv81gz VJCDU/Ki0x3fl7t0ISXb9/Mcufo= X-Mailgun-Sending-Ip: 104.130.122.25 X-Mailgun-Sid: WyI1MzIzYiIsICJsaW51eC1hcm0tbXNtQHZnZXIua2VybmVsLm9yZyIsICJiZTllNGEiXQ== Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by mxa.mailgun.org with ESMTP id 5e04572d.7f5a4ca58ae8-smtp-out-n01; Thu, 26 Dec 2019 06:46:05 -0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 9622AC4479D; Thu, 26 Dec 2019 06:46:04 +0000 (UTC) Received: from rocky-Inspiron-7590.qca.qualcomm.com (unknown [180.166.53.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: rjliao) by smtp.codeaurora.org (Postfix) with ESMTPSA id B8F68C433CB; Thu, 26 Dec 2019 06:46:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org B8F68C433CB Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=rjliao@codeaurora.org From: Rocky Liao To: marcel@holtmann.org, johan.hedberg@gmail.com Cc: linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org, linux-arm-msm@vger.kernel.org, Rocky Liao Subject: [PATCH v2 2/4] Bluetooth: hci_qca: Retry btsoc initialize when it fails Date: Thu, 26 Dec 2019 14:45:52 +0800 Message-Id: <20191226064554.16803-2-rjliao@codeaurora.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191226064554.16803-1-rjliao@codeaurora.org> References: <20191225060317.5258-1-rjliao@codeaurora.org> <20191226064554.16803-1-rjliao@codeaurora.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org This patch adds the retry of btsoc initialization when it fails. There are reports that the btsoc initialization may fail on some platforms but the repro ratio is very low. The failure may be caused by UART, platform HW or the btsoc itself but it's very difficlut to root cause, given the repro ratio is very low. Add a retry for the btsoc initialization will resolve most of the failures and make Bluetooth finally works. Signed-off-by: Rocky Liao --- Changes in v2: None drivers/bluetooth/hci_qca.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c index 43fd84028786..45042aa27fa4 100644 --- a/drivers/bluetooth/hci_qca.c +++ b/drivers/bluetooth/hci_qca.c @@ -53,6 +53,9 @@ /* Controller debug log header */ #define QCA_DEBUG_HANDLE 0x2EDC +/* max retry count when init fails */ +#define QCA_MAX_INIT_RETRY_COUNT 3 + enum qca_flags { QCA_IBS_ENABLED, QCA_DROP_VENDOR_EVENT, @@ -1257,7 +1260,9 @@ static int qca_setup(struct hci_uart *hu) { struct hci_dev *hdev = hu->hdev; struct qca_data *qca = hu->priv; + struct qca_serdev *qcadev; unsigned int speed, qca_baudrate = QCA_BAUDRATE_115200; + unsigned int init_retry_count = 0; enum qca_btsoc_type soc_type = qca_soc_type(hu); const char *firmware_name = qca_get_firmware_name(hu); int ret; @@ -1275,6 +1280,7 @@ static int qca_setup(struct hci_uart *hu) */ set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); +retry: if (qca_is_wcn399x(soc_type)) { bt_dev_info(hdev, "setting up wcn3990"); @@ -1293,6 +1299,12 @@ static int qca_setup(struct hci_uart *hu) return ret; } else { bt_dev_info(hdev, "ROME setup"); + if (hu->serdev) { + qcadev = serdev_device_get_drvdata(hu->serdev); + gpiod_set_value_cansleep(qcadev->bt_en, 1); + /* Controller needs time to bootup. */ + msleep(150); + } qca_set_speed(hu, QCA_INIT_SPEED); } @@ -1329,6 +1341,20 @@ static int qca_setup(struct hci_uart *hu) * patch/nvm-config is found, so run with original fw/config. */ ret = 0; + } else { + if (init_retry_count < QCA_MAX_INIT_RETRY_COUNT) { + qca_power_off(hdev); + if (hu->serdev) { + serdev_device_close(hu->serdev); + ret = serdev_device_open(hu->serdev); + if (ret) { + bt_dev_err(hu->hdev, "open port fail"); + return ret; + } + } + init_retry_count++; + goto retry; + } } /* Setup bdaddr */ From patchwork Wed Dec 25 06:03:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rocky Liao X-Patchwork-Id: 190855 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C27F0C2D0CF for ; Wed, 25 Dec 2019 06:03:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9828020643 for ; Wed, 25 Dec 2019 06:03:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=mg.codeaurora.org header.i=@mg.codeaurora.org header.b="vDN3OP0g" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726388AbfLYGDb (ORCPT ); Wed, 25 Dec 2019 01:03:31 -0500 Received: from mail25.static.mailgun.info ([104.130.122.25]:36923 "EHLO mail25.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726416AbfLYGDb (ORCPT ); Wed, 25 Dec 2019 01:03:31 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1577253811; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=J6AeN4DRpT+vdWvwbQxV34qHFa3WVW9yAt/YKjEVz9g=; b=vDN3OP0gPAonYpmDMPFZBMEcOiFwIg4o8k9xOHCFwichmafMztJ6kmQeSN3V9LyGZGQFUHAI gs8VJZ0/kyXpCqCIUeqTa5PGMit4MDWgqHMJ94scoQfsgGdOKgKgp6GxM/KI9OJnZlbkh/qc TWMdJ58jSjo81AdhTRv9iwEq9qE= X-Mailgun-Sending-Ip: 104.130.122.25 X-Mailgun-Sid: WyI1MzIzYiIsICJsaW51eC1hcm0tbXNtQHZnZXIua2VybmVsLm9yZyIsICJiZTllNGEiXQ== Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by mxa.mailgun.org with ESMTP id 5e02fbb1.7f9253a3c5a8-smtp-out-n02; Wed, 25 Dec 2019 06:03:29 -0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1001) id D633DC433A2; Wed, 25 Dec 2019 06:03:28 +0000 (UTC) Received: from rocky-Inspiron-7590.qca.qualcomm.com (unknown [180.166.53.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: rjliao) by smtp.codeaurora.org (Postfix) with ESMTPSA id 08DDCC43383; Wed, 25 Dec 2019 06:03:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 08DDCC43383 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=rjliao@codeaurora.org From: Rocky Liao To: marcel@holtmann.org, johan.hedberg@gmail.com Cc: linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org, linux-arm-msm@vger.kernel.org, Rocky Liao Subject: [PATCH v1 3/4] Bluetooth: hci_qca: Enable power off/on support during hci down/up for QCA Rome Date: Wed, 25 Dec 2019 14:03:16 +0800 Message-Id: <20191225060317.5258-3-rjliao@codeaurora.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191225060317.5258-1-rjliao@codeaurora.org> References: <20191225060317.5258-1-rjliao@codeaurora.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org This patch registers hdev->shutdown() callback and also sets HCI_QUIRK_NON_PERSISTENT_SETUP for QCA Rome. It will power-off the BT chip during hci down and power-on/initialize the chip again during hci up. Signed-off-by: Rocky Liao --- drivers/bluetooth/hci_qca.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c index 45042aa27fa4..7e202041ed77 100644 --- a/drivers/bluetooth/hci_qca.c +++ b/drivers/bluetooth/hci_qca.c @@ -1300,6 +1300,11 @@ static int qca_setup(struct hci_uart *hu) } else { bt_dev_info(hdev, "ROME setup"); if (hu->serdev) { + /* Enable NON_PERSISTENT_SETUP QUIRK to ensure to + * execute setup for every hci up. + */ + set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks); + hu->hdev->shutdown = qca_power_off; qcadev = serdev_device_get_drvdata(hu->serdev); gpiod_set_value_cansleep(qcadev->bt_en, 1); /* Controller needs time to bootup. */ From patchwork Fri Dec 27 07:21:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rocky Liao X-Patchwork-Id: 190840 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D222C2D0CE for ; Fri, 27 Dec 2019 07:21:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 22655208C4 for ; Fri, 27 Dec 2019 07:21:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=mg.codeaurora.org header.i=@mg.codeaurora.org header.b="Ct1BOPnF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727126AbfL0HVs (ORCPT ); Fri, 27 Dec 2019 02:21:48 -0500 Received: from mail26.static.mailgun.info ([104.130.122.26]:18616 "EHLO mail26.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727074AbfL0HVq (ORCPT ); Fri, 27 Dec 2019 02:21:46 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1577431305; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=3XiPykcnQMfX9C3BwmKaqmlebl0iDBuuAvhWUm2I778=; b=Ct1BOPnF38Re6qUg/LLKncEz1SN9kxgTL24JuJA9cvezNaPbUMkZeJKR12MRoZLSFvuXRNEd woyjOo+E8l8f/uj0pvUXbD0QnGY+wasjFYrcI4h94hEWmvN63ka959RnZv031teMevCCo53H PNe1dZDQZ2GrxWKluuEW6zXNahs= X-Mailgun-Sending-Ip: 104.130.122.26 X-Mailgun-Sid: WyI1MzIzYiIsICJsaW51eC1hcm0tbXNtQHZnZXIua2VybmVsLm9yZyIsICJiZTllNGEiXQ== Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by mxa.mailgun.org with ESMTP id 5e05b108.7f4db995c7d8-smtp-out-n02; Fri, 27 Dec 2019 07:21:44 -0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 70EF9C433CB; Fri, 27 Dec 2019 07:21:44 +0000 (UTC) Received: from rocky-Inspiron-7590.qca.qualcomm.com (unknown [180.166.53.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: rjliao) by smtp.codeaurora.org (Postfix) with ESMTPSA id 6425AC43383; Fri, 27 Dec 2019 07:21:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 6425AC43383 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=rjliao@codeaurora.org From: Rocky Liao To: marcel@holtmann.org, johan.hedberg@gmail.com Cc: linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org, linux-arm-msm@vger.kernel.org, Rocky Liao Subject: [PATCH v3 4/4] Bluetooth: hci_qca: Add HCI command timeout handling Date: Fri, 27 Dec 2019 15:21:30 +0800 Message-Id: <20191227072130.29431-4-rjliao@codeaurora.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191227072130.29431-1-rjliao@codeaurora.org> References: <20191225060317.5258-1-rjliao@codeaurora.org> <20191227072130.29431-1-rjliao@codeaurora.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org This patch adds the HCI command timeout handling, it will trigger btsoc to report its memory dump via vendor specific events when hit the defined max HCI command timeout count. After all the memory dump VSE are sent, the btsoc will also send a HCI_HW_ERROR event to host and this will cause a new hci down/up process and the btsoc will be re-initialized. Signed-off-by: Rocky Liao --- Changes in v2: - Fix build error Changes in v3: - Remove the function declaration - Move the cmd_timeout() callback register to probe() - Remove the redundant empty line drivers/bluetooth/hci_qca.c | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c index ca0b38f065e5..026e2e2cdd30 100644 --- a/drivers/bluetooth/hci_qca.c +++ b/drivers/bluetooth/hci_qca.c @@ -47,6 +47,8 @@ #define IBS_HOST_TX_IDLE_TIMEOUT_MS 2000 #define CMD_TRANS_TIMEOUT_MS 100 +#define QCA_BTSOC_DUMP_CMD 0xFB + /* susclk rate */ #define SUSCLK_RATE_32KHZ 32768 @@ -56,6 +58,9 @@ /* max retry count when init fails */ #define QCA_MAX_INIT_RETRY_COUNT 3 +/* when hit the max cmd time out count, trigger btsoc dump */ +#define QCA_MAX_CMD_TIMEOUT_COUNT 3 + enum qca_flags { QCA_IBS_ENABLED, QCA_DROP_VENDOR_EVENT, @@ -123,6 +128,8 @@ struct qca_data { u64 rx_votes_off; u64 votes_on; u64 votes_off; + + u32 cmd_timeout_cnt; }; enum qca_speed_type { @@ -1332,6 +1339,11 @@ static int qca_setup(struct hci_uart *hu) if (!ret) { set_bit(QCA_IBS_ENABLED, &qca->flags); qca_debugfs_init(hdev); + + /* clear the command time out count every time after + * initializaiton done + */ + qca->cmd_timeout_cnt = 0; } else if (ret == -ENOENT) { /* No patch/nvm-config found, run with original fw/config */ ret = 0; @@ -1462,6 +1474,38 @@ static int qca_power_off(struct hci_dev *hdev) return 0; } +static int qca_send_btsoc_dump_cmd(struct hci_uart *hu) +{ + int err = 0; + struct sk_buff *skb = NULL; + struct qca_data *qca = hu->priv; + + BT_DBG("hu %p sending btsoc dump command", hu); + + skb = bt_skb_alloc(1, GFP_ATOMIC); + if (!skb) { + BT_ERR("Failed to allocate memory for qca dump command"); + return -ENOMEM; + } + + skb_put_u8(skb, QCA_BTSOC_DUMP_CMD); + + skb_queue_tail(&qca->txq, skb); + + return err; +} + +static void qca_cmd_timeout(struct hci_dev *hdev) +{ + struct hci_uart *hu = hci_get_drvdata(hdev); + struct qca_data *qca = hu->priv; + + BT_ERR("hu %p hci cmd timeout count=0x%x", hu, ++qca->cmd_timeout_cnt); + + if (qca->cmd_timeout_cnt >= QCA_MAX_CMD_TIMEOUT_COUNT) + qca_send_btsoc_dump_cmd(hu); +} + static int qca_regulator_enable(struct qca_serdev *qcadev) { struct qca_power *power = qcadev->bt_power; @@ -1605,6 +1649,7 @@ static int qca_serdev_probe(struct serdev_device *serdev) hdev = qcadev->serdev_hu.hdev; set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks); hdev->shutdown = qca_power_off; + hdev->cmd_timeout = qca_cmd_timeout; } out: return err;