From: Pavel Shpakovskiy <shpakovskiip@gmail.com>
To: marcel@holtmann.org, johan.hedberg@gmail.com,
luiz.dentz@gmail.com, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, horms@kernel.org
Cc: linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, kernel@salutedevices.com,
Pavel Shpakovskiy <shpakovskiip@gmail.com>
Subject: [PATCH v1] Bluetooth: L2CAP: Introduce minimum limit of rx_credits value
Date: Mon, 30 Jun 2025 10:56:56 +0300 [thread overview]
Message-ID: <20250630075656.8970-1-shpakovskiip@gmail.com> (raw)
The commit 96cd8eaa131f
("Bluetooth: L2CAP: Derive rx credits from MTU and MPS")
removed the static rx_credits setup to improve BLE packet
communication for high MTU values. However, due to vendor-specific
issues in the Bluetooth module firmware, using low MTU values
(especially less than 256 bytes) results in dynamically calculated
rx_credits being too low, causing slow speeds and occasional BLE
connection failures.
This change aims to improve BLE connection stability and speed
for low MTU values. It is possible to tune minimum value
of rx credits with debugfs handle.
Signed-off-by: Pavel Shpakovskiy <shpakovskiip@gmail.com>
---
include/net/bluetooth/l2cap.h | 2 ++
net/bluetooth/l2cap_core.c | 17 +++++++++++++++--
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index 4bb0eaedda180..8648d9324a654 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -437,6 +437,8 @@ struct l2cap_conn_param_update_rsp {
#define L2CAP_CONN_PARAM_ACCEPTED 0x0000
#define L2CAP_CONN_PARAM_REJECTED 0x0001
+#define L2CAP_LE_MIN_CREDITS 10
+
struct l2cap_le_conn_req {
__le16 psm;
__le16 scid;
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index c88f69dde995e..392d7ba0f0737 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -50,6 +50,8 @@ static u32 l2cap_feat_mask = L2CAP_FEAT_FIXED_CHAN | L2CAP_FEAT_UCD;
static LIST_HEAD(chan_list);
static DEFINE_RWLOCK(chan_list_lock);
+static u16 le_min_credits = L2CAP_LE_MIN_CREDITS;
+
static struct sk_buff *l2cap_build_cmd(struct l2cap_conn *conn,
u8 code, u8 ident, u16 dlen, void *data);
static void l2cap_send_cmd(struct l2cap_conn *conn, u8 ident, u8 code, u16 len,
@@ -547,8 +549,17 @@ static __u16 l2cap_le_rx_credits(struct l2cap_chan *chan)
/* If we don't know the available space in the receiver buffer, give
* enough credits for a full packet.
*/
- if (chan->rx_avail == -1)
- return (chan->imtu / chan->mps) + 1;
+ if (chan->rx_avail == -1) {
+ u16 rx_credits = (chan->imtu / chan->mps) + 1;
+
+ if (rx_credits < le_min_credits) {
+ rx_credits = le_min_credits;
+ BT_DBG("chan %p: set rx_credits to minimum value: %u",
+ chan, chan->rx_credits);
+ }
+
+ return rx_credits;
+ }
/* If we know how much space is available in the receive buffer, give
* out as many credits as would fill the buffer.
@@ -7661,6 +7672,8 @@ int __init l2cap_init(void)
l2cap_debugfs = debugfs_create_file("l2cap", 0444, bt_debugfs,
NULL, &l2cap_debugfs_fops);
+ debugfs_create_u16("l2cap_le_min_credits", 0644, bt_debugfs,
+ &le_min_credits);
return 0;
}
--
2.34.1
next reply other threads:[~2025-06-30 7:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-30 7:56 Pavel Shpakovskiy [this message]
2025-06-30 8:41 ` [v1] Bluetooth: L2CAP: Introduce minimum limit of rx_credits value bluez.test.bot
2025-06-30 13:49 ` [PATCH v1] " Luiz Augusto von Dentz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250630075656.8970-1-shpakovskiip@gmail.com \
--to=shpakovskiip@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=johan.hedberg@gmail.com \
--cc=kernel@salutedevices.com \
--cc=kuba@kernel.org \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
--cc=marcel@holtmann.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox