From patchwork Tue Jan 2 18:59:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jonas_Dre=C3=9Fler?= X-Patchwork-Id: 184436 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4630645dyb; Tue, 2 Jan 2024 11:01:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IEwQp3lpYpdKM66E/NLA/W2U12ijQ995MQHe1DFt851TisSVsXoTz93LzzqsVLsYl616WJI X-Received: by 2002:a05:6870:9625:b0:205:21f3:790f with SMTP id d37-20020a056870962500b0020521f3790fmr9350973oaq.42.1704222118966; Tue, 02 Jan 2024 11:01:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704222118; cv=none; d=google.com; s=arc-20160816; b=OvYP/u64Izi2Dfj5yZCwjSw+6nzP+rgjdbSg8/dqBZqJNvXblydC6Hm7JMkOociTkn Nwapo1PIFdKmBoynd1GAStVKlrcBVjlGBE8uifzTe4ViVlXz/lNvS2RGqqyv9zHgEjgl RFHcL8MLXrE5IQjMDSlvfEZYISKOVqoo6wGTkggGSFuHjDfngJ78Gt9P9fMb3BdH1WyV eH+UW/+v0Xr3QBcUvqYQRVKbfZXxKkbjE8jG2/HKGBT9dMW76PWC/pQWz8HzDYsIb8jA 24fsn5Iqd6JW50VK8rdieA3LM9ezTJMFmfAfiXld6U3QYIy9NZ0YbxaG4MzxMHoBEjCO E24Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=mYz1A1U3kOrainhKz7h69+HR2I8R9IIu5H7UkQZUrZI=; fh=3AqDzvZy8BuFcn015+g5AB3sGQnZc/edyFwniXfpO+U=; b=tNhFx5KB1F7imnOfsUNVP4g+r07ctEcfV5ROVehmGH8Q/VrVgoH0gX42GZpXcf9lkd wgBxnyu9YZIJlgQolufYgJaR0ummNiFxAJJohZL617TvP+XmkOy0AaFRuHgXX08IjLwR 1ATDSTOI5dAIXfQC+s6IBgCzVCTDOPAjo0MMC9uqfhUhGQCTqvx6r4H1qnFfROAyGkSs RDOQ6r7pw2lGklRYWH3e7JMSXIqDFVimGKCigXWD01F6VY3+rPStOvYuqtPvUX+AXJ1B +TPZGfuP2bM5OEmzM0BbEiRJPl+GB/e/IWsdNiNxHsWzp6bTzNt5ciiGonK/gTl1xMZL 4j+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14755-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14755-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id cb15-20020a056a02070f00b005cdfd4aa8b3si17857165pgb.193.2024.01.02.11.01.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 11:01:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14755-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14755-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14755-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B673D28403C for ; Tue, 2 Jan 2024 19:01:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6425217729; Tue, 2 Jan 2024 18:59:50 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC09D168DF; Tue, 2 Jan 2024 18:59:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=v0yd.nl Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=v0yd.nl Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4T4Mbg1nPPz9sp4; Tue, 2 Jan 2024 19:59:43 +0100 (CET) From: =?utf-8?q?Jonas_Dre=C3=9Fler?= To: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz Cc: =?utf-8?q?Jonas_Dre=C3=9Fler?= , linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 5/5] Bluetooth: hci_event: Try reconnecting on more kinds of errors Date: Tue, 2 Jan 2024 19:59:32 +0100 Message-ID: <20240102185933.64179-6-verdre@v0yd.nl> In-Reply-To: <20240102185933.64179-1-verdre@v0yd.nl> References: <20240102185933.64179-1-verdre@v0yd.nl> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4T4Mbg1nPPz9sp4 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787006413003679876 X-GMAIL-MSGID: 1787006413003679876 While some hardware seems to return "HCI Command Disallowed" errors when trying to connect to too many devices at once, other hardware (eg. the BCM4378 found in M1 macbooks) returns "HCI Hardware Failure" in this case. And the Marvell 88W8897 in various Microsoft Surface devices behaves different again: Here the "HCI Create Connection" succeeds, but later a "HCI Connection Complete" event with status "Rejected Limited Resources" comes in. Handle all these cases as expected by userspace and reuse the existing BT_CONNECT2 logic to try "HCI Create Connection" again after the ongoing connection attempts have been completed. Signed-off-by: Jonas Dreßler --- include/net/bluetooth/hci.h | 1 + net/bluetooth/hci_event.c | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index fef723afd..23890f53e 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -637,6 +637,7 @@ enum { /* ---- HCI Error Codes ---- */ #define HCI_ERROR_UNKNOWN_CONN_ID 0x02 +#define HCI_ERROR_HARDWARE_FAILURE 0x03 #define HCI_ERROR_AUTH_FAILURE 0x05 #define HCI_ERROR_PIN_OR_KEY_MISSING 0x06 #define HCI_ERROR_MEMORY_EXCEEDED 0x07 diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 1376092c5..46b6d7e27 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -2323,13 +2323,14 @@ static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status) if (status) { if (conn && conn->state == BT_CONNECT) { - /* If the request failed with "Command Disallowed", the + /* If the request failed with a certain status, the * card is either using all its available "slots" for * attempting new connections, or it's currently * doing an HCI Inquiry. In these cases we'll try to * do the "Create Connection" request again later. */ - if (status == HCI_ERROR_COMMAND_DISALLOWED) { + if (status == HCI_ERROR_COMMAND_DISALLOWED || + status == HCI_ERROR_HARDWARE_FAILURE) { conn->state = BT_CONNECT2; if (!hci_conn_hash_lookup_state(hdev, ACL_LINK, BT_CONNECT) && @@ -3254,7 +3255,26 @@ static void hci_conn_complete_evt(struct hci_dev *hdev, void *data, done: if (status) { - hci_conn_failed(conn, status); + if (status == HCI_ERROR_REJ_LIMITED_RESOURCES) { + conn->state = BT_CONNECT2; + + if (!hci_conn_hash_lookup_state(hdev, ACL_LINK, BT_CONNECT) && + !test_bit(HCI_INQUIRY, &hdev->flags)) { + bt_dev_err(hdev, + "\"Connect Complete\" event with error " + "(0x%2.2x) indicating to try again, but " + "there's no concurrent \"Create " + "Connection\" nor an ongoing inquiry", + status); + + hci_conn_failed(conn, status); + } + + hci_dev_unlock(hdev); + return; + } else { + hci_conn_failed(conn, status); + } } else if (ev->link_type == SCO_LINK) { switch (conn->setting & SCO_AIRMODE_MASK) { case SCO_AIRMODE_CVSD: