Skip to content

Commit 36c86c8

Browse files
Mat MartineauGustavo Padovan
authored andcommitted
Bluetooth: Configure appropriate timeouts for AMP controllers
The L2CAP spec recommends specific retransmit and monitor timeouts for ERTM channels that are on AMP controllers. These timeouts are calculated from the AMP controller's best effort flush timeout. BR/EDR controllers use the default retransmit and monitor timeouts. Signed-off-by: Mat Martineau <mathewm@codeaurora.org> Acked-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
1 parent b99e13a commit 36c86c8

1 file changed

Lines changed: 41 additions & 6 deletions

File tree

‎net/bluetooth/l2cap_core.c‎

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2967,6 +2967,44 @@ static inline bool __l2cap_efs_supported(struct l2cap_chan *chan)
29672967
return enable_hs && chan->conn->feat_mask & L2CAP_FEAT_EXT_FLOW;
29682968
}
29692969

2970+
static void __l2cap_set_ertm_timeouts(struct l2cap_chan *chan,
2971+
struct l2cap_conf_rfc *rfc)
2972+
{
2973+
if (chan->local_amp_id && chan->hs_hcon) {
2974+
u64 ertm_to = chan->hs_hcon->hdev->amp_be_flush_to;
2975+
2976+
/* Class 1 devices have must have ERTM timeouts
2977+
* exceeding the Link Supervision Timeout. The
2978+
* default Link Supervision Timeout for AMP
2979+
* controllers is 10 seconds.
2980+
*
2981+
* Class 1 devices use 0xffffffff for their
2982+
* best-effort flush timeout, so the clamping logic
2983+
* will result in a timeout that meets the above
2984+
* requirement. ERTM timeouts are 16-bit values, so
2985+
* the maximum timeout is 65.535 seconds.
2986+
*/
2987+
2988+
/* Convert timeout to milliseconds and round */
2989+
ertm_to = DIV_ROUND_UP_ULL(ertm_to, 1000);
2990+
2991+
/* This is the recommended formula for class 2 devices
2992+
* that start ERTM timers when packets are sent to the
2993+
* controller.
2994+
*/
2995+
ertm_to = 3 * ertm_to + 500;
2996+
2997+
if (ertm_to > 0xffff)
2998+
ertm_to = 0xffff;
2999+
3000+
rfc->retrans_timeout = cpu_to_le16((u16) ertm_to);
3001+
rfc->monitor_timeout = rfc->retrans_timeout;
3002+
} else {
3003+
rfc->retrans_timeout = __constant_cpu_to_le16(L2CAP_DEFAULT_RETRANS_TO);
3004+
rfc->monitor_timeout = __constant_cpu_to_le16(L2CAP_DEFAULT_MONITOR_TO);
3005+
}
3006+
}
3007+
29703008
static inline void l2cap_txwin_setup(struct l2cap_chan *chan)
29713009
{
29723010
if (chan->tx_win > L2CAP_DEFAULT_TX_WINDOW &&
@@ -3033,8 +3071,8 @@ static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data)
30333071
case L2CAP_MODE_ERTM:
30343072
rfc.mode = L2CAP_MODE_ERTM;
30353073
rfc.max_transmit = chan->max_tx;
3036-
rfc.retrans_timeout = 0;
3037-
rfc.monitor_timeout = 0;
3074+
3075+
__l2cap_set_ertm_timeouts(chan, &rfc);
30383076

30393077
size = min_t(u16, L2CAP_DEFAULT_MAX_PDU_SIZE, chan->conn->mtu -
30403078
L2CAP_EXT_HDR_SIZE - L2CAP_SDULEN_SIZE -
@@ -3262,10 +3300,7 @@ static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data)
32623300
rfc.max_pdu_size = cpu_to_le16(size);
32633301
chan->remote_mps = size;
32643302

3265-
rfc.retrans_timeout =
3266-
__constant_cpu_to_le16(L2CAP_DEFAULT_RETRANS_TO);
3267-
rfc.monitor_timeout =
3268-
__constant_cpu_to_le16(L2CAP_DEFAULT_MONITOR_TO);
3303+
__l2cap_set_ertm_timeouts(chan, &rfc);
32693304

32703305
set_bit(CONF_MODE_DONE, &chan->conf_state);
32713306

0 commit comments

Comments
 (0)