Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH v3] Bluetooth: request LE data length for MT7922
@ 2026-11-23 23:35 Kyle Pepper
  0 siblings, 0 replies; only message in thread
From: Kyle Pepper @ 2026-11-23 23:35 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: luiz.dentz, marcel, sean.wang, matthias.bgg,
	angelogioacchino.delregno, linux-mediatek, linux-arm-kernel,
	linux-kernel

MT7922 USB firmware can accept maximum LE suggested default data lengths
without negotiating a larger transmit data length on a new connection.
On an ASUS G614PR with USB ID 0489:e0f6 and firmware 20260724143815,
ASHA playback remains choppy until an explicit LE Set Data Length request.
A request on the same Cochlear Nucleus 8 connection raises delivery from
21.5 to 50 audio SDUs/s and reduces peak outstanding packets from 32 to 3.

Set a quirk for MT7922 in USB setup and request the current suggested
defaults after successful remote feature exchange on central-role links.
Require local and remote DLE support and the LE Set Data Length command.
Keep suggested-default initialization and PHY negotiation unchanged.

Do not restrict the workaround to the tested firmware build or OEM USB
ID: the affected firmware range has not been confirmed. Other MediaTek
chips do not enable the quirk. The request also applies to 1M peers that
support DLE, and ordinary link-layer negotiation determines the result.

Hold a connection reference while queued and revalidate its membership,
state, role and capabilities before sending. Release the reference on
completion, cancellation or queue failure. A failed optional request
does not reject connection setup.

Assisted-by: OpenCode:gpt-6.1-sol
Assisted-by: Codex

Signed-off-by: Kyle Pepper <cochcoder@proton.me>
---
Changes in v3: move personal correspondence out of the commit message; no source changes.
Previous version: https://lore.kernel.org/linux-bluetooth/20261123221206.215119-1-cochcoder@proton.me/

Hi Luiz, 
Since there hasn't been a response from
the MediaTek folks in over 5 weeks I've gone
ahead and prepared this v2 quirk patch that 
will work for USB MT7922 controllers.
Thanks, 
Kyle Pepper

Contingency revision: MediaTek has been asked about a firmware fix and its
affected scope. No reply has been received as of November 23. This does
not establish that a firmware fix is unavailable or that every MT7922
firmware release is affected. A firmware fix remains preferable.

Changes in v2:
- Match MT7922 in USB setup, without a firmware-build or OEM USB-ID gate.
- Remove firmware-header matching and its setup-time clear/recheck logic.
- Rebase on current bluetooth-next; retain guarded referenced queue work.

Previous patch:
https://lore.kernel.org/linux-bluetooth/20261016170122.27119-1-cochcoder@proton.me/
Luiz requested checking firmware-fix plans and avoiding a single-build
gate unless MediaTek confirms an image-specific regression. This v2 is
prepared in case a validated firmware fix is not forthcoming; his reply
is conditional guidance, not an Acked-by or approval of this revision.

Historical evidence: manual same-link request on 0489:e0f6 with firmware
20260724143815 gave 21.5 -> 50 SDUs/s. Automatic requests worked in the
local patched 7.2.9 stack. No new hardware result is claimed for v2, for
other firmware/OEM boards, or for vanilla upstream. Suspend/resume,
other profiles, native concurrency and power regressions remain untested.

Local validation on base ffb95458a0f7: GCC and Clang baseline/candidate
builds each compile four Bluetooth objects with W=1 and zero warnings.
82 source-extracted ASan/UBSan controls pass; the baseline and five
mutation controls detect missing behavior and guards. LeakSanitizer is
disabled because the command runner uses ptrace; these are model tests.
Source-only strict checkpatch is clean. Stock full-mail checkpatch flags
the retained Assisted-by trailers as BAD_SIGN_OFF. No checker is changed
or attribution removed; remote CI and human-signed mail remain unchecked.

No introducing kernel commit has been established for this firmware bug,
so no Fixes or stable tag is inferred. No extra patch/MR dependency.
Human review and DCO sign-off are required before publication.

AI assistance: the retained request/queue implementation originated with
OpenCode:gpt-6.1-sol. Codex adapted matching, rebased it, and prepared this
message, review notes and offline validation in response to Luiz's review.

 drivers/bluetooth/btmtk.c        |  4 +++
 include/net/bluetooth/hci.h      |  5 +++
 include/net/bluetooth/hci_sync.h |  1 +
 net/bluetooth/hci_event.c        |  8 +++++
 net/bluetooth/hci_sync.c         | 58 ++++++++++++++++++++++++++++++++
 5 files changed, 76 insertions(+)

diff --git a/drivers/bluetooth/btmtk.c b/drivers/bluetooth/btmtk.c
index 1b3dab0d1..1869815cc 100644
--- a/drivers/bluetooth/btmtk.c
+++ b/drivers/bluetooth/btmtk.c
@@ -1858,6 +1858,10 @@ int btmtk_usb_setup(struct hci_dev *hdev)
 
 	btmtk_data->dev_id = dev_id;
 
+	/* MT7922 needs per-link requests despite suggested defaults. */
+	if (dev_id == 0x7922)
+		hci_set_quirk(hdev, HCI_QUIRK_NEEDS_LE_SET_DATA_LEN);
+
 	err = btmtk_register_coredump(hdev, btmtk_data->drv_name, fw_version);
 	if (err < 0)
 		bt_dev_err(hdev, "Failed to register coredump (%d)", err);
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index efb85c781..85a4931e5 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -348,6 +348,11 @@ enum {
 	 */
 	HCI_QUIRK_BROKEN_READ_ENC_KEY_SIZE,
 
+	/* The controller needs an explicit LE Set Data Length request for
+	 * each central-role connection despite accepting suggested defaults.
+	 */
+	HCI_QUIRK_NEEDS_LE_SET_DATA_LEN,
+
 	/*
 	 * When this quirk is set, the reserved bits of Primary/Secondary_PHY
 	 * inside the LE Extended Advertising Report events are discarded.
diff --git a/include/net/bluetooth/hci_sync.h b/include/net/bluetooth/hci_sync.h
index 509ec4161..eab827dfa 100644
--- a/include/net/bluetooth/hci_sync.h
+++ b/include/net/bluetooth/hci_sync.h
@@ -195,6 +195,7 @@ int hci_le_read_remote_features(struct hci_conn *conn);
 
 int hci_acl_change_pkt_type(struct hci_conn *conn, u16 pkt_type);
 int hci_le_set_phy(struct hci_conn *conn, u8 tx_phys, u8 rx_phys, u16 phy_opts);
+int hci_le_set_data_len(struct hci_conn *conn);
 int hci_le_set_cig_params_sync(struct hci_dev *hdev, u8 cig_id);
 int hci_le_create_big_sync(struct hci_conn *conn, struct bt_iso_qos_ext *qos,
 			   u8 num_bis);
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index b6c7f9a9f..7ef2c4d19 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -7436,6 +7436,14 @@ static void hci_le_remote_feat_complete_evt(struct hci_dev *hdev, void *data,
 			 */
 			conn->le_tx_def_phys &= ~HCI_LE_SET_PHY_HDT;
 			conn->le_rx_def_phys &= ~HCI_LE_SET_PHY_HDT;
+
+			if (hci_test_quirk(hdev, HCI_QUIRK_NEEDS_LE_SET_DATA_LEN) &&
+			    conn->role == HCI_ROLE_MASTER &&
+			    (hdev->commands[33] & BIT(6)) &&
+			    (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT) &&
+			    (conn->le_features[0] & HCI_LE_DATA_LEN_EXT) &&
+			    hdev->le_def_tx_len > 27)
+				hci_le_set_data_len(conn);
 		}
 
 		if (conn->state == BT_CONFIG) {
diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index 2e88af51b..ac82aa085 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -9286,3 +9286,61 @@ int hci_le_eks_oppt_encrypt(struct hci_conn *conn)
 
 	return err;
 }
+
+static void le_set_data_len_complete(struct hci_dev *hdev, void *data, int err)
+{
+	struct hci_conn *conn = data;
+
+	bt_dev_dbg(hdev, "err %d", err);
+	if (err && err != -ECANCELED && err != -ENODEV)
+		bt_dev_warn(hdev, "Failed to set LE data length (%d)", err);
+	hci_conn_put(conn);
+}
+
+static int hci_le_set_data_len_sync(struct hci_dev *hdev, void *data)
+{
+	struct hci_conn *conn = data;
+	struct hci_cp_le_set_data_len cp;
+
+	hci_dev_lock(hdev);
+
+	if (!hci_conn_valid(hdev, conn) || conn->type != LE_LINK ||
+	    conn->role != HCI_ROLE_MASTER ||
+	    (conn->state != BT_CONNECTED && conn->state != BT_CONFIG)) {
+		hci_dev_unlock(hdev);
+		return -ECANCELED;
+	}
+
+	/* Use the current suggested defaults, including later host changes. */
+	if (!hci_test_quirk(hdev, HCI_QUIRK_NEEDS_LE_SET_DATA_LEN) ||
+	    !(hdev->commands[33] & BIT(6)) ||
+	    !(hdev->le_features[0] & HCI_LE_DATA_LEN_EXT) ||
+	    !(conn->le_features[0] & HCI_LE_DATA_LEN_EXT) ||
+	    hdev->le_def_tx_len <= 27) {
+		hci_dev_unlock(hdev);
+		return 0;
+	}
+
+	cp.handle = cpu_to_le16(conn->handle);
+	cp.tx_len = cpu_to_le16(hdev->le_def_tx_len);
+	cp.tx_time = cpu_to_le16(hdev->le_def_tx_time);
+
+	hci_dev_unlock(hdev);
+
+	return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_DATA_LEN,
+				     sizeof(cp), &cp, HCI_CMD_TIMEOUT);
+}
+
+int hci_le_set_data_len(struct hci_conn *conn)
+{
+	struct hci_dev *hdev = conn->hdev;
+	int err;
+
+	err = hci_cmd_sync_queue_once(hdev, hci_le_set_data_len_sync,
+				      hci_conn_get(conn),
+				      le_set_data_len_complete);
+	if (err)
+		hci_conn_put(conn);
+
+	return (err == -EEXIST) ? 0 : err;
+}

base-commit: ffb95458a0f70dcab620eee0ecf5ef7750971b2f


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-23 23:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 23:35 [PATCH v3] Bluetooth: request LE data length for MT7922 Kyle Pepper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox