From patchwork Fri Apr 1 23:38:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 12798856 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A142DC433F5 for ; Fri, 1 Apr 2022 23:38:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353439AbiDAXkW (ORCPT ); Fri, 1 Apr 2022 19:40:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353427AbiDAXkU (ORCPT ); Fri, 1 Apr 2022 19:40:20 -0400 Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72C602739 for ; Fri, 1 Apr 2022 16:38:29 -0700 (PDT) Received: by mail-il1-x12f.google.com with SMTP id d3so3019872ilr.10 for ; Fri, 01 Apr 2022 16:38:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=/Gp6F9qkkhPrndSWliPIV0M7p0aUKRwWzBTpGmpEAxc=; b=KbXd10LnWEwnrAW2bcQU+pB9XukOXlhNUPnuwHF1BjFr2kJvm6xD8Rs7l2m4hjcVDW 5M4qJJKu4rTf5oLnmiLBG9c28Zva7mMP0UyyceiTPSPze8X9N79MhazW3QbEhcFqujtx DZ47x4aMzIYo4mxMLrTwksDUgNsT8gvG2GZTC2659N74UmdupGK35s7xF/ey4JZZGI2G mxaIu7SeW5AaaZ7i3Zl93ypZP2pEG75ASyRcB4UcK4IOvlN+otAHu8kxegdM0HZAWBDH CfZZ/u/7+ZG/Zl9cyeSoyFOKFwnQ6i8uNGcK6EQOGpuTYMUq6s090YNJXTimXZumTw+a J6Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=/Gp6F9qkkhPrndSWliPIV0M7p0aUKRwWzBTpGmpEAxc=; b=uTbb6NS38xFWt9wz3sbGXMtpmtaKxGlnuBrhEK9ZZwqPjtZ+jGOsGv/I8lVRuK58gr PRINPKMqo/4mlN5ROqCltcW+woCzdU8KEWewUuhMWsOSeLyfITFxOKrkgoaKzPZAn0RD 9kkYZXF2RTnImNtCBV2Vex1iGZl1BvEb4wxXYchcZ8rbowgWox666V2zZys1iB6iwLaW nHa6GtaB6nn3HTJ3P/O0LcLEbuQ+M9vgJLsd83m24lZa4wKq1SDBr+t1Nc0oWf5Ws1oj Drrpd3UBWzkvf7mdFvhDDsHqSkaUUZ+AdtJ38H+1TrF+TnvyJaYsvjLOfJ6BO6vQJYXC nH0g== X-Gm-Message-State: AOAM530iYL2CI6kZYTA54sp+4gs0V8yLbD6Nl/E5Wa6cg+2fYU+0MoCP u0AjsLiH2tj/rl3qAewT7lBSmDngsYk= X-Google-Smtp-Source: ABdhPJwpYBGD0C6mwcU4Y34BJ4rO9CNhorBSLShjWQmP9JiRSmr2f+Xkasbm8My597a8Qji12Awg+A== X-Received: by 2002:a05:6e02:19c9:b0:2ca:57a:9f62 with SMTP id r9-20020a056e0219c900b002ca057a9f62mr934071ill.63.1648856308522; Fri, 01 Apr 2022 16:38:28 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id b19-20020a5d8553000000b00649f02b1b0csm2217062ios.39.2022.04.01.16.38.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Apr 2022 16:38:28 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v4 1/4] Bluetooth: HCI: Add HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN quirk Date: Fri, 1 Apr 2022 16:38:23 -0700 Message-Id: <20220401233826.122544-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This adds HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN quirk which can be used to mark HCI_Enhanced_Setup_Synchronous_Connection as broken even if its support command bit are set since some controller report it as supported but the command don't work properly with some configurations (e.g. BT_VOICE_TRANSPARENT/mSBC). Signed-off-by: Luiz Augusto von Dentz --- v4: Address latest comments, add patch 4/4 spliting hci_dev_open_sync so each stage can be handled by its own function. v3: Make HCI_QUIRK_BROKEN macro expand quirk name and address other comments from v2. v2: Change hci_broken/hci_quirk_broken and HCI_BROKEN/HCI_QUIRK_BROKEN and add patch 3/3 setting HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN for QCA controllers. include/net/bluetooth/hci.h | 9 +++++++++ include/net/bluetooth/hci_core.h | 8 ++++++-- net/bluetooth/hci_conn.c | 2 +- net/bluetooth/sco.c | 2 +- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index 5cb095b09a94..8bb81ea4d286 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -265,6 +265,15 @@ enum { * runtime suspend, because event filtering takes place there. */ HCI_QUIRK_BROKEN_FILTER_CLEAR_ALL, + + /* + * When this quirk is set, disables the use of + * HCI_OP_ENHANCED_SETUP_SYNC_CONN command to setup SCO connections. + * + * This quirk can be set before hci_register_dev is called or + * during the hdev->setup vendor callback. + */ + HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN, }; /* HCI device flags */ diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index d5377740e99c..59815df1272a 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -1492,8 +1492,12 @@ void hci_conn_del_sysfs(struct hci_conn *conn); #define privacy_mode_capable(dev) (use_ll_privacy(dev) && \ (hdev->commands[39] & 0x04)) -/* Use enhanced synchronous connection if command is supported */ -#define enhanced_sco_capable(dev) ((dev)->commands[29] & 0x08) +/* Use enhanced synchronous connection if command is supported and its quirk + * has not been set. + */ +#define enhanced_sync_conn_capable(dev) \ + (((dev)->commands[29] & 0x08) && \ + !test_bit(HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN, &(dev)->quirks)) /* Use ext scanning if set ext scan param and ext scan enable is supported */ #define use_ext_scan(dev) (((dev)->commands[37] & 0x20) && \ diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 84312c836549..cd51bf2a709b 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -481,7 +481,7 @@ static bool hci_setup_sync_conn(struct hci_conn *conn, __u16 handle) bool hci_setup_sync(struct hci_conn *conn, __u16 handle) { - if (enhanced_sco_capable(conn->hdev)) + if (enhanced_sync_conn_capable(conn->hdev)) return hci_enhanced_setup_sync_conn(conn, handle); return hci_setup_sync_conn(conn, handle); diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c index 8eabf41b2993..2a58c7d88433 100644 --- a/net/bluetooth/sco.c +++ b/net/bluetooth/sco.c @@ -885,7 +885,7 @@ static int sco_sock_setsockopt(struct socket *sock, int level, int optname, err = -EBADFD; break; } - if (enhanced_sco_capable(hdev) && + if (enhanced_sync_conn_capable(hdev) && voice.setting == BT_VOICE_TRANSPARENT) sco_pi(sk)->codec.id = BT_CODEC_TRANSPARENT; hci_dev_put(hdev); From patchwork Fri Apr 1 23:38:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 12798857 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7DCB9C433EF for ; Fri, 1 Apr 2022 23:38:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353425AbiDAXkZ (ORCPT ); Fri, 1 Apr 2022 19:40:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353431AbiDAXkV (ORCPT ); Fri, 1 Apr 2022 19:40:21 -0400 Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82E822AC4 for ; Fri, 1 Apr 2022 16:38:30 -0700 (PDT) Received: by mail-il1-x12f.google.com with SMTP id x9so3044905ilc.3 for ; Fri, 01 Apr 2022 16:38:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=5h+itaPpaVusfkPsF6oYH8QwyThNAc1BGn7bHzjyg/8=; b=CC5fZsAGmOciHdt+CEhL/wCHZzd28dNilLcDsanszFecm8RhUlgcY+cSh8mvF8b1tG ycZR1+9nct1wRRr6cKydQ9RmR7wC+g87mK7YLEIFPkVYBAEmL4DdBrrPY6UROHzjgWFp Zx4jdwb/2J7s5HIST6ymM5Tcv7F1TFNFWnwoBF/m4YQTaGrpAcwOVyJB22u1FDlBaz5W SmVfsOxhJ63pQeTE1lI8p9V0zEqInjnjt+Y7x0P7RldVLNBuviIIWR72Y0ivznAtAWmW 34AOF121glfXXFP/JM9HNvVuWidCf7RRETE2puqZ1R+Ws6qXlHBNymM4HWohbG78YEY1 bHoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5h+itaPpaVusfkPsF6oYH8QwyThNAc1BGn7bHzjyg/8=; b=MiTETrw0WrmUwDRnmj/uqmkH2Lr0ZvpVD1V3hSFfob/TteLCeLCjKgv0+P2efQui12 bIhnmOO7a9Yzv/YZUp0ZYJ/tQr3qA+hp8Epv4SyTwzC9QTGGBj9yMjs5q1dUI48/JnRb u4p5cg21mi9FgppGMWJBu0b1Eqn5HGM1msFGCtZ12C3zoh8saZUY4pXowx33w4j2/yyt xwtBGA5U7EYDHUtDsh4y8FQUEHcK1FhhTn9RAwCcMAT+uL7XwoS/vhu3qwIEQ6X4efKm 9S0Vb07A9oRVZ0NMZRW9bOXqpfyiRM8W8zY7XSeZdNwhnGKYJVKHZY1IDdirBCGvPi60 CoVg== X-Gm-Message-State: AOAM530VLfD3oSuUKvxgQ+rIHudFua9MtSKZDW8QjKTTq1Qh71M4Kshe Mv7AEpU7hbfnFIm+w54vK6ZmrQCCSMI= X-Google-Smtp-Source: ABdhPJwsXWTt5af9NMwZ77CBQNMxiFCd00VnQCOTbaWzEQWYdpk6v2Le6yqw3VaEJZ6sbajkcajTdw== X-Received: by 2002:a05:6e02:1c8e:b0:2ca:b36:19f8 with SMTP id w14-20020a056e021c8e00b002ca0b3619f8mr907808ill.203.1648856309217; Fri, 01 Apr 2022 16:38:29 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id b19-20020a5d8553000000b00649f02b1b0csm2217062ios.39.2022.04.01.16.38.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Apr 2022 16:38:28 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v4 2/4] Bluetooth: Print broken quirks Date: Fri, 1 Apr 2022 16:38:24 -0700 Message-Id: <20220401233826.122544-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220401233826.122544-1-luiz.dentz@gmail.com> References: <20220401233826.122544-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This prints warnings for controllers setting broken quirks to increase their visibility and warn about broken controllers firmware that probably needs updates to behave properly. Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_sync.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 8f4c5698913d..5610ec1242d6 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -3825,6 +3825,30 @@ static int hci_init_sync(struct hci_dev *hdev) return 0; } +#define HCI_QUIRK_BROKEN(_quirk, _desc) { HCI_QUIRK_BROKEN_##_quirk, _desc } + +static const struct { + unsigned long quirk; + const char *desc; +} hci_broken_table[] = { + HCI_QUIRK_BROKEN(LOCAL_COMMANDS, + "HCI Read Local Supported Commands not supported"), + HCI_QUIRK_BROKEN(STORED_LINK_KEY, + "HCI Delete Stored Link Key command is advertised, " + "but not supported."), + HCI_QUIRK_BROKEN(ERR_DATA_REPORTING, + "HCI Read Default Erroneous Data Reporting command is " + "advertised, but not supported."), + HCI_QUIRK_BROKEN(READ_TRANSMIT_POWER, + "HCI Read Transmit Power Level command is advertised, " + "but not supported."), + HCI_QUIRK_BROKEN(FILTER_CLEAR_ALL, + "HCI Set Event Filter command not supported."), + HCI_QUIRK_BROKEN(ENHANCED_SETUP_SYNC_CONN, + "HCI Enhanced Setup Synchronous Connection command is " + "advertised, but not supported.") +}; + int hci_dev_open_sync(struct hci_dev *hdev) { int ret = 0; @@ -3886,12 +3910,19 @@ int hci_dev_open_sync(struct hci_dev *hdev) if (hci_dev_test_flag(hdev, HCI_SETUP) || test_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks)) { bool invalid_bdaddr; + size_t i; hci_sock_dev_event(hdev, HCI_DEV_SETUP); if (hdev->setup) ret = hdev->setup(hdev); + for (i = 0; i < ARRAY_SIZE(hci_broken_table); i++) { + if (test_bit(hci_broken_table[i].quirk, &hdev->quirks)) + bt_dev_warn(hdev, "%s", + hci_broken_table[i].desc); + } + /* The transport driver can set the quirk to mark the * BD_ADDR invalid before creating the HCI device or in * its setup callback. From patchwork Fri Apr 1 23:38:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 12798859 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3ACE6C433FE for ; Fri, 1 Apr 2022 23:38:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353427AbiDAXk2 (ORCPT ); Fri, 1 Apr 2022 19:40:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353438AbiDAXkW (ORCPT ); Fri, 1 Apr 2022 19:40:22 -0400 Received: from mail-il1-x12d.google.com (mail-il1-x12d.google.com [IPv6:2607:f8b0:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D97185FF9 for ; Fri, 1 Apr 2022 16:38:30 -0700 (PDT) Received: by mail-il1-x12d.google.com with SMTP id j15so3002796ila.13 for ; Fri, 01 Apr 2022 16:38:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=tRi9mkD2hB3smWylSIZlbf8NOW3OIQwRaYtRTDbSDKo=; b=JX6OijcR8WIImGFVrJ4ROAoFpl0K80Bhx+Ilvd6AHfcC2GH9CDE59pp/5gSTif7ocd RgruJ4CJelx9p5SrebBiW+u86LPBsFOW5dnyJTELeXVu40FpEoF8PCxMVKkgefVOZPLB 5j9+maTEQKcX3uK31Lla1EYbshio1RRI5uoUnMBFVy52lTSDeTX0fyKmYZWBZ4twU3hq UcSf6/xeG/nTtII0UcXkaBS9nuRJk2T3scdmnthGriU1rJKF/N9vny/H4fjS/zmy3/yA iuI4edMJaLYeyw14CLhh4rZNkOCItxgHgc/4M1J9zSUq2TpTvjBvMVRYqqQd33yUdrtu zyOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tRi9mkD2hB3smWylSIZlbf8NOW3OIQwRaYtRTDbSDKo=; b=3eP1BjAmcoqBqFYrsAXZsy2QOYiLZ5vOZMrI0a0d4S/47q/Kjd0HSJZbVWbyMP+53M ks3hGdV5jyv9FvYgNz//kiTlrRzOKBMU+9zIjxyTPoRHacDA1OZSd/ctDdKfOoct4laE vAqhL31dM6XeRgi3fzOFB9i32LvJvdXFIguQKep8lg6T34Rpk5yg3fvQ/DLf4xE6qwT8 +3m2cV5qMsP+q3HWRG7x+jU6N++2o6z/A7bbNMW5byO8hhcnxQPLOEGWSFQ6ph/b8aq/ MSCE3S5xlJJxP6OAqnjjs3JsjtOiBRkz6HHRKCneeTMzmQ7X7tNtGVBsfXdKkHOvlo9K JiXg== X-Gm-Message-State: AOAM5333bdCe/Oc5SF8VD7od8++VPciUO3Ke+0Bkft5UTQOQQEO8P3u7 OXIJZvg5TJ4oXGnotaX/ZHH9h9tJxp4= X-Google-Smtp-Source: ABdhPJwvWvVpMosNtpDd0BAJNqg1aTe/WegJcfCVC75ddGPvpMKa5o7Jw/NR7UOscrFTYoExoCR7Bg== X-Received: by 2002:a05:6e02:178a:b0:2ca:123a:c6eb with SMTP id y10-20020a056e02178a00b002ca123ac6ebmr952473ilu.187.1648856309872; Fri, 01 Apr 2022 16:38:29 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id b19-20020a5d8553000000b00649f02b1b0csm2217062ios.39.2022.04.01.16.38.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Apr 2022 16:38:29 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v4 3/4] Bluetooth: btusb: Set HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN for QCA Date: Fri, 1 Apr 2022 16:38:25 -0700 Message-Id: <20220401233826.122544-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220401233826.122544-1-luiz.dentz@gmail.com> References: <20220401233826.122544-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This sets HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN for QCA controllers since SCO appear to not work when using HCI_OP_ENHANCED_SETUP_SYNC_CONN. Link: https://bugzilla.kernel.org/show_bug.cgi?id=215576 Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btusb.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 50df417207af..06a854a2507e 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -3335,6 +3335,11 @@ static int btusb_setup_qca(struct hci_dev *hdev) msleep(QCA_BT_RESET_WAIT_MS); } + /* Mark HCI_OP_ENHANCED_SETUP_SYNC_CONN as broken as it doesn't seem to + * work with the likes of HSP/HFP mSBC. + */ + set_bit(HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN, &hdev->quirks); + return 0; } From patchwork Fri Apr 1 23:38:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 12798858 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59287C433F5 for ; Fri, 1 Apr 2022 23:38:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353430AbiDAXk0 (ORCPT ); Fri, 1 Apr 2022 19:40:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353437AbiDAXkW (ORCPT ); Fri, 1 Apr 2022 19:40:22 -0400 Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A3FDE37 for ; Fri, 1 Apr 2022 16:38:31 -0700 (PDT) Received: by mail-il1-x132.google.com with SMTP id z10so3087656iln.0 for ; Fri, 01 Apr 2022 16:38:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=XeImaVfzLHou7+z6R/xeYIY1VSit5WMBxFwnBNaCYSc=; b=R3wyaIkjEWpeiMOQ/HhvfISFnjB0nO44o3ug6/sK2xcTifK/1L/YZ8P1uRbfAbnB1O HC83F+jCjpBWgV75sTlvs08ONGVFSxP4smvGAzrSkIeTxvLfwjYWo8Am1wwlkn5TwoM0 HLkvwtWt9COJW75ZqJ8dJBZaI+5K0ESKIj6qGA5eBvoYUphEY5M0r0tedVOnG64ljhSR srb9UnMHIoSON2Z2EWPqG99txFrtuIWzCYGkFNnpH5r4GzBNwBNTANjIiINaLwrCULk/ TGYLI/fk/q6XAcfJBE9zRA9I78uUIOhB9BszZ/sPpmGNbr1TYuqk4ZXRIpBA7qOFL4XR 79FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XeImaVfzLHou7+z6R/xeYIY1VSit5WMBxFwnBNaCYSc=; b=tuU6ggGcDVHKMWTMwUdMc95bshpMiyHBUoOuDeBuqBdyxJcojQvmslSGqyY+oFWR4S UxF/qodDNBSX/JNPhR3JyYzfl5A6/Tr+d2GTQepvathOHsXRVdHLAh9yMoH3VIPY+UxL N84UkLKE7k8Wlji6uJlplQ06b72ei4PbQz9/YpRsvfgXq/8uD9aDnTSPJ5P9q6yf72VD dk6UnvTnWEQZeWY9Wn5TYBMJGkFTHM/7P3y/oreCSeo91ZWBw2S8FW+D7hrn4joP2ZnT PRIFzwaryhYiJYyujF9Gr6dvw+qqXNmgqEmf45DhSB5c76kwLVW8tjvfY2MYMTR141Ot eVfw== X-Gm-Message-State: AOAM530nbPCWCSa8FMgBwvQiJ3Dp87EIKQxH8+g/Hnbbs9zGdiqcAEN1 HhoMDWGBR5w406o3M0UHIrL+kS0FtLg= X-Google-Smtp-Source: ABdhPJzhednDgspih/DM5aZnuash9hbjd9wPmzTD6/EaIJ9TQyCFvmvn0Wv2Ru2NCyaa6PkNjFGXNw== X-Received: by 2002:a05:6e02:216f:b0:2ca:203b:75d with SMTP id s15-20020a056e02216f00b002ca203b075dmr365224ilv.174.1648856310720; Fri, 01 Apr 2022 16:38:30 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id b19-20020a5d8553000000b00649f02b1b0csm2217062ios.39.2022.04.01.16.38.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Apr 2022 16:38:30 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v4 4/4] Bluetooth: hci_sync: Split hci_dev_open_sync Date: Fri, 1 Apr 2022 16:38:26 -0700 Message-Id: <20220401233826.122544-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220401233826.122544-1-luiz.dentz@gmail.com> References: <20220401233826.122544-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This splits hci_dev_open_sync so each stage is handle by its own function so it is easier to identify each stage. Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_sync.c | 225 ++++++++++++++++++++++----------------- 1 file changed, 126 insertions(+), 99 deletions(-) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 5610ec1242d6..2d3b9adbd215 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -3849,90 +3849,40 @@ static const struct { "advertised, but not supported.") }; -int hci_dev_open_sync(struct hci_dev *hdev) +/* This function handles hdev setup stage: + * + * Calls hdev->setup + * Setup address if HCI_QUIRK_USE_BDADDR_PROPERTY is set. + */ +static int hci_dev_setup_sync(struct hci_dev *hdev) { int ret = 0; - - bt_dev_dbg(hdev, ""); - - if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) { - ret = -ENODEV; - goto done; - } + bool invalid_bdaddr; + size_t i; if (!hci_dev_test_flag(hdev, HCI_SETUP) && - !hci_dev_test_flag(hdev, HCI_CONFIG)) { - /* Check for rfkill but allow the HCI setup stage to - * proceed (which in itself doesn't cause any RF activity). - */ - if (hci_dev_test_flag(hdev, HCI_RFKILLED)) { - ret = -ERFKILL; - goto done; - } - - /* Check for valid public address or a configured static - * random address, but let the HCI setup proceed to - * be able to determine if there is a public address - * or not. - * - * In case of user channel usage, it is not important - * if a public address or static random address is - * available. - * - * This check is only valid for BR/EDR controllers - * since AMP controllers do not have an address. - */ - if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && - hdev->dev_type == HCI_PRIMARY && - !bacmp(&hdev->bdaddr, BDADDR_ANY) && - !bacmp(&hdev->static_addr, BDADDR_ANY)) { - ret = -EADDRNOTAVAIL; - goto done; - } - } - - if (test_bit(HCI_UP, &hdev->flags)) { - ret = -EALREADY; - goto done; - } - - if (hdev->open(hdev)) { - ret = -EIO; - goto done; - } - - set_bit(HCI_RUNNING, &hdev->flags); - hci_sock_dev_event(hdev, HCI_DEV_OPEN); - - atomic_set(&hdev->cmd_cnt, 1); - set_bit(HCI_INIT, &hdev->flags); - - if (hci_dev_test_flag(hdev, HCI_SETUP) || - test_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks)) { - bool invalid_bdaddr; - size_t i; + !test_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks)) + return 0; - hci_sock_dev_event(hdev, HCI_DEV_SETUP); + bt_dev_dbg(hdev, ""); - if (hdev->setup) - ret = hdev->setup(hdev); + hci_sock_dev_event(hdev, HCI_DEV_SETUP); - for (i = 0; i < ARRAY_SIZE(hci_broken_table); i++) { - if (test_bit(hci_broken_table[i].quirk, &hdev->quirks)) - bt_dev_warn(hdev, "%s", - hci_broken_table[i].desc); - } + if (hdev->setup) + ret = hdev->setup(hdev); - /* The transport driver can set the quirk to mark the - * BD_ADDR invalid before creating the HCI device or in - * its setup callback. - */ - invalid_bdaddr = test_bit(HCI_QUIRK_INVALID_BDADDR, - &hdev->quirks); + for (i = 0; i < ARRAY_SIZE(hci_broken_table); i++) { + if (test_bit(hci_broken_table[i].quirk, &hdev->quirks)) + bt_dev_warn(hdev, "%s", hci_broken_table[i].desc); + } - if (ret) - goto setup_failed; + /* The transport driver can set the quirk to mark the + * BD_ADDR invalid before creating the HCI device or in + * its setup callback. + */ + invalid_bdaddr = test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); + if (!ret) { if (test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) { if (!bacmp(&hdev->public_addr, BDADDR_ANY)) hci_dev_get_bd_addr_from_property(hdev); @@ -3951,33 +3901,51 @@ int hci_dev_open_sync(struct hci_dev *hdev) invalid_bdaddr = false; } } + } -setup_failed: - /* The transport driver can set these quirks before - * creating the HCI device or in its setup callback. - * - * For the invalid BD_ADDR quirk it is possible that - * it becomes a valid address if the bootloader does - * provide it (see above). - * - * In case any of them is set, the controller has to - * start up as unconfigured. - */ - if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) || - invalid_bdaddr) - hci_dev_set_flag(hdev, HCI_UNCONFIGURED); + /* The transport driver can set these quirks before + * creating the HCI device or in its setup callback. + * + * For the invalid BD_ADDR quirk it is possible that + * it becomes a valid address if the bootloader does + * provide it (see above). + * + * In case any of them is set, the controller has to + * start up as unconfigured. + */ + if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) || + invalid_bdaddr) + hci_dev_set_flag(hdev, HCI_UNCONFIGURED); - /* For an unconfigured controller it is required to - * read at least the version information provided by - * the Read Local Version Information command. - * - * If the set_bdaddr driver callback is provided, then - * also the original Bluetooth public device address - * will be read using the Read BD Address command. - */ - if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) - ret = hci_unconf_init_sync(hdev); - } + /* For an unconfigured controller it is required to + * read at least the version information provided by + * the Read Local Version Information command. + * + * If the set_bdaddr driver callback is provided, then + * also the original Bluetooth public device address + * will be read using the Read BD Address command. + */ + if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) + return hci_unconf_init_sync(hdev); + + return ret; +} + +/* This function handles hdev init stage: + * + * Calls hci_dev_setup_sync to perform setup stage + * Calls hci_init_sync to perform HCI command init sequence + */ +static int hci_dev_init_sync(struct hci_dev *hdev) +{ + int ret; + + bt_dev_dbg(hdev, ""); + + atomic_set(&hdev->cmd_cnt, 1); + set_bit(HCI_INIT, &hdev->flags); + + ret = hci_dev_setup_sync(hdev); if (hci_dev_test_flag(hdev, HCI_CONFIG)) { /* If public address change is configured, ensure that @@ -4017,6 +3985,65 @@ int hci_dev_open_sync(struct hci_dev *hdev) clear_bit(HCI_INIT, &hdev->flags); + return ret; +} + +int hci_dev_open_sync(struct hci_dev *hdev) +{ + int ret; + + bt_dev_dbg(hdev, ""); + + if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) { + ret = -ENODEV; + goto done; + } + + if (!hci_dev_test_flag(hdev, HCI_SETUP) && + !hci_dev_test_flag(hdev, HCI_CONFIG)) { + /* Check for rfkill but allow the HCI setup stage to + * proceed (which in itself doesn't cause any RF activity). + */ + if (hci_dev_test_flag(hdev, HCI_RFKILLED)) { + ret = -ERFKILL; + goto done; + } + + /* Check for valid public address or a configured static + * random address, but let the HCI setup proceed to + * be able to determine if there is a public address + * or not. + * + * In case of user channel usage, it is not important + * if a public address or static random address is + * available. + * + * This check is only valid for BR/EDR controllers + * since AMP controllers do not have an address. + */ + if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && + hdev->dev_type == HCI_PRIMARY && + !bacmp(&hdev->bdaddr, BDADDR_ANY) && + !bacmp(&hdev->static_addr, BDADDR_ANY)) { + ret = -EADDRNOTAVAIL; + goto done; + } + } + + if (test_bit(HCI_UP, &hdev->flags)) { + ret = -EALREADY; + goto done; + } + + if (hdev->open(hdev)) { + ret = -EIO; + goto done; + } + + set_bit(HCI_RUNNING, &hdev->flags); + hci_sock_dev_event(hdev, HCI_DEV_OPEN); + + ret = hci_dev_init_sync(hdev); if (!ret) { hci_dev_hold(hdev); hci_dev_set_flag(hdev, HCI_RPA_EXPIRED);