Skip to contentSkip to conversation

Bluetooth: Broadcom controllers of the Apple T2 Macs

PATCH In review Andre Eikmeyer 2 participants 4 messages Nov 27

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover Bluetooth: Broadcom controllers of the Apple T2 Macs

This series is for the Broadcom Bluetooth controllers of the Apple T2 Macs, the BCM4364 over UART (hci_bcm) and the BCM4377 over PCIe (hci_bcm4377).

Patch 1 builds on a vendor command the Android Broadcom vendor library uses, 0xfc57, to keep A2DP from dropping out while WLAN runs on 2.4 GHz. Patch 2 sets the strict duplicate filter quirk in both drivers, so a discovery reports changed advertisement data before its next cycle.

The T2 Linux community runs these patches. Users reported them working on the MacBookPro15,1, 15,2, 15,3, 15,4, 16,1, 16,4, MacBookAir9,1 and iMac20,1.

Changes in v3:
- Rebase on bluetooth-next. Patch 2 sets the quirk after the new platform address check in bcm_setup()
- Patch 2: shorter subject
- Patch 1 is unchanged. The comparison with Sasha Finkelstein's channel priority patch is in the v2 thread

Changes in v2:
- Dropped "Bluetooth: btbcm: clear vendor bits in LE advertising report types" and the revert of 88397423671f. The mask in hci_event.c stays as it is.

v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

Andre Eikmeyer (2):
Bluetooth: btbcm: raise ACL priority on Apple Broadcom controllers
Bluetooth: set the strict duplicate filter quirk on Apple Broadcom

 drivers/bluetooth/Kconfig       |  1 +
 drivers/bluetooth/btbcm.c       | 71 +++++++++++++++++++++++++++++++++
 drivers/bluetooth/btbcm.h       |  7 ++++
 drivers/bluetooth/hci_bcm.c     | 23 +++++++++--
 drivers/bluetooth/hci_bcm4377.c |  8 ++++
 5 files changed, 107 insertions(+), 3 deletions(-)

base-commit: f57f78086ab54f3b3122fbaeba2c842ba7bb6d00

#1 lore raw

PATCH v3 1/2 Bluetooth: btbcm: raise ACL priority on Apple Broadcom controllers

On the MacBookPro15,1 (BCM4364B0 over UART) A2DP audio drops out as soon as WLAN runs on 2.4 GHz with traffic. The host keeps the eight ACL buffers of the controller filled, but the controller holds single ACL packets for 160-200 ms, so the sink runs dry.

Sending the Broadcom vendor command 0xfc57 (HCI_BRCM_SET_ACL_PRIORITY, handle and priority, as used by the Android Broadcom vendor library) with priority high for the audio link stops the dropouts. Setting it back to normal brings them back right away. The BCM4377 of the MacBookAir9,1 accepts the command as well.

Raise the priority for every BR/EDR ACL link once its Connection Complete event arrives. This covers audio as well as HID links. hci_bcm does this on Apple machines only, hci_bcm4377 always, since it only runs on Apple machines. The PCIe driver receives events in hard interrupt context, so the command is queued from a work item.

---
 drivers/bluetooth/Kconfig       |  1 +
 drivers/bluetooth/btbcm.c       | 71 +++++++++++++++++++++++++++++++++
 drivers/bluetooth/btbcm.h       |  7 ++++
 drivers/bluetooth/hci_bcm.c     | 18 ++++++++-
 drivers/bluetooth/hci_bcm4377.c |  3 ++
 5 files changed, 98 insertions(+), 2 deletions(-)
drivers/bluetooth/Kconfig +1 -0
index b18482b5677..3e2426abdff 100644
@@ -318,6 +318,7 @@ config BT_HCIBCM4377
 	tristate "HCI BCM4377/4378/4387/4388 PCIe driver"
 	depends on PCI
 	select FW_LOADER
+	select BT_BCM
 	help
 	  Support for Broadcom BCM4377/4378/4387/4388 Bluetooth chipsets
 	  attached via PCIe. These are usually found in Apple machines.
drivers/bluetooth/btbcm.c +71 -0

77 lines not on this page · raw message

drivers/bluetooth/btbcm.h +7 -0
index b4cb24231a2..a4d47b242e9 100644
@@ -59,6 +59,8 @@ int btbcm_read_pcm_int_params(struct hci_dev *hdev,
 int btbcm_write_pcm_int_params(struct hci_dev *hdev,
 			       const struct bcm_set_pcm_int_params *params);
 
+void btbcm_set_acl_priority_on_connect(struct hci_dev *hdev, struct sk_buff *skb);
+
 int btbcm_setup_patchram(struct hci_dev *hdev);
 int btbcm_setup_apple(struct hci_dev *hdev);
 
@@ -94,6 +96,11 @@ static inline int btbcm_patchram(struct hci_dev *hdev, const struct firmware *fw
 	return -EOPNOTSUPP;
 }
 
+static inline void btbcm_set_acl_priority_on_connect(struct hci_dev *hdev,
+						     struct sk_buff *skb)
+{
+}
+
 static inline int btbcm_setup_patchram(struct hci_dev *hdev)
 {
 	return 0;
drivers/bluetooth/hci_bcm.c +16 -2
index 1f62a8c2fb3..d2fbaf7cfbc 100644
@@ -147,6 +147,7 @@ struct bcm_device {
 	bool			drive_rts_on_open;
 	bool			no_uart_clock_set;
 	bool			use_autobaud_mode;
+	bool			acl_priority;
 	u8			pcm_int_params[5];
 	u32			max_autobaud_speed;
 };
@@ -688,10 +689,21 @@ static int bcm_setup(struct hci_uart *hu)
 	.lsize = 0, \
 	.maxlen = BCM_TYPE52_SIZE
 
+static int bcm_recv_event(struct hci_dev *hdev, struct sk_buff *skb)
+{
+	struct hci_uart *hu = hci_get_drvdata(hdev);
+	struct bcm_data *bcm = hu->priv;
+
+	if (bcm->dev && bcm->dev->acl_priority)
+		btbcm_set_acl_priority_on_connect(hdev, skb);
+
+	return hci_recv_frame(hdev, skb);
+}
+
 static const struct h4_recv_pkt bcm_recv_pkts[] = {
 	{ H4_RECV_ACL,      .recv = hci_recv_frame },
 	{ H4_RECV_SCO,      .recv = hci_recv_frame },
-	{ H4_RECV_EVENT,    .recv = hci_recv_frame },
+	{ H4_RECV_EVENT,    .recv = bcm_recv_event },
 	{ H4_RECV_ISO,      .recv = hci_recv_frame },
 	{ BCM_RECV_LM_DIAG, .recv = hci_recv_diag  },
 	{ BCM_RECV_NULL,    .recv = hci_recv_diag  },
@@ -1094,8 +1106,10 @@ static int bcm_get_resources(struct bcm_device *dev)
 
 	dev->name = dev_name(dev->dev);
 
-	if (x86_apple_machine && !bcm_apple_get_resources(dev))
+	if (x86_apple_machine && !bcm_apple_get_resources(dev)) {
+		dev->acl_priority = true;
 		return 0;
+	}
 
 	dev->txco_clk = bcm_get_txco(dev->dev);
 	if (IS_ERR(dev->txco_clk))
drivers/bluetooth/hci_bcm4377.c +3 -0
index 72a9f269e8b..7900e8ca2fb 100644
@@ -22,6 +22,8 @@
 #include <net/bluetooth/bluetooth.h>
 #include <net/bluetooth/hci_core.h>
 
+#include "btbcm.h"
+
 enum bcm4377_chip {
 	BCM4377 = 0,
 	BCM4378,
@@ -689,6 +691,7 @@ static void bcm4377_handle_event(struct bcm4377_data *bcm4377,
 
 	memcpy(skb_put(skb, len), payload, len);
 	hci_skb_pkt_type(skb) = type;
+	btbcm_set_acl_priority_on_connect(bcm4377->hdev, skb);
 	hci_recv_frame(bcm4377->hdev, skb);
 
 out:
#3 lore raw

PATCH v3 2/2 Bluetooth: set the strict duplicate filter quirk on Apple Broadcom

In reply to Andre Eikmeyer

btbcm_finalize() sets HCI_QUIRK_STRICT_DUPLICATE_FILTER, but bcm_setup() returns before it when no patch file was loaded. The MacBookPro15,1 has none for its BCM4364B0 ("BCM: firmware Patch file not found"). hci_bcm4377 does not use btbcm_finalize() and never sets the quirk. A service discovery then scans with "Filter duplicates: Enabled", and the controller reports an address once per discovery cycle of about 10.7 s. A Mac that changed its advertisement data on the same address was reported 6 s after the change, at the next cycle.

Set the quirk in hci_bcm on that path and in hci_bcm4377.

---
 drivers/bluetooth/hci_bcm.c     | 5 ++++-
 drivers/bluetooth/hci_bcm4377.c | 5 +++++
 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/bluetooth/hci_bcm.c +4 -1
index d2fbaf7cfbc..d85554188b5 100644
@@ -604,8 +604,11 @@ static int bcm_setup(struct hci_uart *hu)
 	    bacmp(&bdaddr, BDADDR_ANY))
 		hci_set_quirk(hu->hdev, HCI_QUIRK_USE_BDADDR_PROPERTY);
 
-	if (!fw_load_done)
+	if (!fw_load_done) {
+		/* btbcm_finalize() sets this after loading a patch file */
+		hci_set_quirk(hu->hdev, HCI_QUIRK_STRICT_DUPLICATE_FILTER);
 		return 0;
+	}
 
 	/* Init speed if any */
 	if (bcm->dev && bcm->dev->init_speed)
drivers/bluetooth/hci_bcm4377.c +5 -0
index 7900e8ca2fb..3362e017bd1 100644
@@ -2391,6 +2391,11 @@ static int bcm4377_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	hdev->set_bdaddr = bcm4377_hci_set_bdaddr;
 	hdev->setup = bcm4377_hci_setup;
 
+	/* The controller reports an address once per scan with duplicate
+	 * filtering, also after its advertisement data changed.
+	 */
+	hci_set_quirk(hdev, HCI_QUIRK_STRICT_DUPLICATE_FILTER);
+
 	if (bcm4377->hw->broken_mws_transport_config)
 		hci_set_quirk(hdev, HCI_QUIRK_BROKEN_MWS_TRANSPORT_CONFIG);
 	if (bcm4377->hw->broken_ext_scan)
#2 lore raw
In reply to Andre Eikmeyer

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1224493/

---Test result---

Test Summary:

CheckPatch                    PASS      1.77 seconds
VerifyFixes                   PASS      0.09 seconds
VerifySignedoff               PASS      0.09 seconds
GitLint                       PASS      0.47 seconds
SubjectPrefix                 PASS      0.18 seconds
BuildKernel                   PASS      18.95 seconds
CheckAllWarning               PASS      22.13 seconds
CheckSparse                   PASS      23.76 seconds
BuildKernel32                 PASS      19.05 seconds
CheckKernelLLVM               PASS      19.24 seconds
TestRunnerSetup               PASS      432.23 seconds
IncrementalBuild              PASS      18.87 seconds

https://github.com/bluez/bluetooth-next/pull/1246

---
Regards,
Linux Bluetooth