Skip to content

Commit 6ce7a92

Browse files
committed
bluetooth: hci: userchan: Improve RX allocation handling
This makes userchan transport behavior similar to other HCI transports (eg IPC). Improved logging gives clear overview of what RX events are discarded helping for configuration tuning. Signed-off-by: Szymon Janc <[email protected]>
1 parent 727c15a commit 6ce7a92

File tree

1 file changed

+57
-12
lines changed

1 file changed

+57
-12
lines changed

drivers/bluetooth/hci/userchan.c

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,24 +93,70 @@ static bool is_hci_event_discardable(const uint8_t *evt_data)
9393
}
9494
}
9595

96-
static struct net_buf *get_rx(const uint8_t *buf)
96+
static struct net_buf *get_rx_evt(const uint8_t *data)
9797
{
98-
bool discardable = false;
99-
k_timeout_t timeout = K_FOREVER;
98+
bool discardable = is_hci_event_discardable(data);
99+
struct net_buf *buf;
100+
101+
do {
102+
buf = bt_buf_get_evt(data[1], discardable, discardable ? K_NO_WAIT : K_SECONDS(1));
103+
if (buf == NULL) {
104+
if (discardable) {
105+
LOG_DBG("Discardable buffer pool full, ignoring event");
106+
return buf;
107+
}
108+
LOG_WRN("Couldn't allocate a buffer after waiting 1 second.");
109+
}
110+
} while (!buf);
100111

101-
switch (buf[0]) {
102-
case BT_HCI_H4_EVT:
103-
if (is_hci_event_discardable(buf)) {
104-
discardable = true;
105-
timeout = K_NO_WAIT;
112+
return buf;
113+
}
114+
115+
static struct net_buf *get_rx_acl(const uint8_t *data)
116+
{
117+
struct net_buf *buf;
118+
119+
buf = bt_buf_get_rx(BT_BUF_ACL_IN, K_NO_WAIT);
120+
if (buf == NULL) {
121+
LOG_ERR("No available ACL buffers!");
122+
}
123+
124+
return buf;
125+
}
126+
127+
static struct net_buf *get_rx_iso(const uint8_t *data)
128+
{
129+
static unsigned int fail_cnt;
130+
struct net_buf *buf;
131+
132+
buf = bt_buf_get_rx(BT_BUF_ISO_IN, K_NO_WAIT);
133+
if (buf == NULL) {
134+
if (fail_cnt == 0) {
135+
LOG_ERR("No available ISO buffers!");
106136
}
107137

108-
return bt_buf_get_evt(buf[1], discardable, timeout);
138+
fail_cnt++;
139+
} else {
140+
if (fail_cnt) {
141+
LOG_INF("ISO buffer available (%u dropped)!", fail_cnt);
142+
}
143+
144+
fail_cnt = 0;
145+
}
146+
147+
return buf;
148+
}
149+
150+
static struct net_buf *get_rx(const uint8_t *buf)
151+
{
152+
switch (buf[0]) {
153+
case BT_HCI_H4_EVT:
154+
return get_rx_evt(buf);
109155
case BT_HCI_H4_ACL:
110-
return bt_buf_get_rx(BT_BUF_ACL_IN, K_FOREVER);
156+
return get_rx_acl(buf);
111157
case BT_HCI_H4_ISO:
112158
if (IS_ENABLED(CONFIG_BT_ISO)) {
113-
return bt_buf_get_rx(BT_BUF_ISO_IN, K_FOREVER);
159+
return get_rx_iso(buf);
114160
}
115161
__fallthrough;
116162
default:
@@ -281,7 +327,6 @@ static void rx_thread(void *p1, void *p2, void *p3)
281327
frame_start += decoded_len;
282328

283329
if (!buf) {
284-
LOG_DBG("Discard adv report due to insufficient buf");
285330
continue;
286331
}
287332

0 commit comments

Comments
 (0)