Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp637207iog; Mon, 13 Jun 2022 09:37:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tkK/OSmv+kBPF2BB5r9MiZpJs6AqWmsoxpuGOH9nRH5hLZJSncIxfhKOlBo0Ah/MIaF18J X-Received: by 2002:a17:902:d505:b0:167:6662:c7fe with SMTP id b5-20020a170902d50500b001676662c7femr484900plg.31.1655138243291; Mon, 13 Jun 2022 09:37:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655138243; cv=none; d=google.com; s=arc-20160816; b=WRHa2iceuSt5xqqxnfczEC5mtLYjp2prkpstNAFbrUmHF0jt9eypP+mHBCm8zJbjfI RNmgtTKab67xtwz2IhYeCJNQAwY4bMWAfmIUBl+c3MO7VhXUBKUnxjlhr3SRAE+EX+BM t22i1c0aIg2WeKr+/4FyV3IWGD3I8PWWOrH5Uqp/YThjYzO4Q6ec1i1WG4CghkYYl3tC LqNjTMA+sJgJ4+dUlf3QCctfYM0Zd1sZQb7bPb48GzdvRWZlFR35Cq82aenhGp8iaRid e5/YRbUYLGnlkDABCZzE6L+B9xbRbny6iF0DuUJnzWPXBxV7Vo88I+CPuQAW22eO8zKi Rihw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=1O+xm8OX+p7BlrqyEqCZKZj5xafZ91tAT8H1qJFm4Pw=; b=0SVTKXxuW1WnShUkwJXaDSdX4hpqxosW256iPckYLuf3EK7i3Q/jP9SYFd0A1ehkrm u90Yb28gRy1LSXOFR1xo364WzTqrLCBTkAbKnP5safU9e/GeX0aBqGNQSwm2A5s8Kj4E ZmY5+ErHTJtYT+tAveBEQWe8eVjOAx7M9VyLMIlQ89hfqd3WnO4fW04hQjXkOQNMDDNN GFB55KkB3IFE8JIPhBTm/2ntt5K4LZ9QpW5KwwjU7pzdRzmyW9v1dCorkWqrbQsKh8fa aVgaE0la1p/QSDCVEQBcbL+FdzXIByG4JrsDWykVIpl9QANOmIlcqwGB83K7eGrkw0hF s4tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernkonzept.com header.s=mx1 header.b=GGxftj7v; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernkonzept.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t7-20020a634607000000b003fadcc14015si10106053pga.15.2022.06.13.09.36.50; Mon, 13 Jun 2022 09:37:22 -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=fail header.i=@kernkonzept.com header.s=mx1 header.b=GGxftj7v; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernkonzept.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1385882AbiFMOws (ORCPT + 99 others); Mon, 13 Jun 2022 10:52:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1385909AbiFMOvC (ORCPT ); Mon, 13 Jun 2022 10:51:02 -0400 X-Greylist: delayed 1799 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 13 Jun 2022 04:55:27 PDT Received: from mx.kernkonzept.com (serv1.kernkonzept.com [IPv6:2a01:4f8:1c1c:b490::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B69DE2ED65; Mon, 13 Jun 2022 04:55:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kernkonzept.com; s=mx1; h=Content-Transfer-Encoding:MIME-Version:Message-Id :Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=1O+xm8OX+p7BlrqyEqCZKZj5xafZ91tAT8H1qJFm4Pw=; b=GGxftj7vG/t264Yay8zk+3rEiD uRPM2vt+3LhK4f4EuK0mcfE3JrjpqQEwjeWdJKVPHopnMpUhULah65d1a1h7L8LxtnBFAZZe1Gwjj EWJL3qcFHJpyboZjReZ9b0uFJEM6VPpWkMAX0YCLRR7uNoXZMM0bsCUMrj9A/Aag8594togSe+25i ItJ+gBY0543KiVnQha10sCj+Y+Ll5GulAh870c7sRJTV7bfATUI9veFjFQJ6Q+u0FwNRK9MYdwgC/ dBSB8P+gakxUV8V/oZPwe90YSyZYZoCs2FgabB3H088kNHPfGZ0kLHiftNK2Sf66FkREnOqVMtqHH F4swSQ5w==; Received: from [10.22.3.24] (helo=kernkonzept.com) by mx.kernkonzept.com with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2) id 1o0hwS-0051cL-49; Mon, 13 Jun 2022 13:09:08 +0200 From: Stephan Gerhold To: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz Cc: Andy Gross , Bjorn Andersson , linux-arm-msm@vger.kernel.org, linux-bluetooth@vger.kernel.org, Stephan Gerhold , Stephan Gerhold Subject: [PATCH] Bluetooth: btqcomsmd: Fix command timeout after setting BD address Date: Mon, 13 Jun 2022 13:07:45 +0200 Message-Id: <20220613110745.3778356-1-stephan.gerhold@kernkonzept.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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-bluetooth@vger.kernel.org The Bluetooth firmware seems to become unresponsive for a while after setting the BD address. At least on recent kernel versions this often causes timeouts for subsequent commands, e.g. the HCI reset sent by the Bluetooth core during initialization: Bluetooth: hci0: Opcode 0x c03 failed: -110 Unfortunately this behavior does not seem to be documented anywhere. Experimentation suggests that the minimum necessary delay to avoid the problem is ~150us. However, to be sure add a sleep for > 1ms in case it is a bit longer on other firmware versions. Fixes: 1511cc750c3d ("Bluetooth: Introduce Qualcomm WCNSS SMD based HCI driver") Signed-off-by: Stephan Gerhold --- I tested this using a script that reboots repeatedly and checks for the error. With this patch, BT shows up successfully for 100+ consecutive boots. Without this patch it usually fails after 1-5 boots (or even always on some boards). --- drivers/bluetooth/btqcomsmd.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/bluetooth/btqcomsmd.c b/drivers/bluetooth/btqcomsmd.c index 2acb719e596f..11c7e04bf394 100644 --- a/drivers/bluetooth/btqcomsmd.c +++ b/drivers/bluetooth/btqcomsmd.c @@ -122,6 +122,21 @@ static int btqcomsmd_setup(struct hci_dev *hdev) return 0; } +static int btqcomsmd_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr) +{ + int ret; + + ret = qca_set_bdaddr_rome(hdev, bdaddr); + if (ret) + return ret; + + /* The firmware stops responding for a while after setting the bdaddr, + * causing timeouts for subsequent commands. Sleep a bit to avoid this. + */ + usleep_range(1000, 10000); + return 0; +} + static int btqcomsmd_probe(struct platform_device *pdev) { struct btqcomsmd *btq; @@ -162,7 +177,7 @@ static int btqcomsmd_probe(struct platform_device *pdev) hdev->close = btqcomsmd_close; hdev->send = btqcomsmd_send; hdev->setup = btqcomsmd_setup; - hdev->set_bdaddr = qca_set_bdaddr_rome; + hdev->set_bdaddr = btqcomsmd_set_bdaddr; ret = hci_register_dev(hdev); if (ret < 0) -- 2.30.2