From patchwork Sun Jan 7 18:02:47 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: 185752 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:37c1:b0:101:2151:f287 with SMTP id y1csp646077dyq; Sun, 7 Jan 2024 10:03:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IH1Ic+b9f4byTX2hxklTrlsFtWkl5sWAxiPstPx10/lvcT/xOoupL/Qv7o5m8HHNhWOu9l/ X-Received: by 2002:a05:6871:331e:b0:1fa:fc26:7f81 with SMTP id nf30-20020a056871331e00b001fafc267f81mr3622311oac.14.1704650630990; Sun, 07 Jan 2024 10:03:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704650630; cv=none; d=google.com; s=arc-20160816; b=jA/zADTf3BGXGL+0p+wdki8flV18nuILKkA/0WIlwiv7ikAytYTgjUzTEzYDh+taxB SYa+9JQ29PE2YTGq2p2yfS8LzNhFixQjNyexjrQauk1TU/4jG0HyJaFvnxfZDSspKAIp OldV2hoPOgpoFWaDjcfetiz1qvwPZRF3haiZsjQCREHwLgspuRSVZSQNTtiDE+QkC1+R QGUlRWRFRmmQp11eo/wfTnQZ8APbEI11EnS8+gJhfCVElEFXfC5GN206DtqfL+u1S1iq 4WRxPtD/QKEl/iwuUea9++QgkS7h/RmABmi4lMyndAt60A8MysAOxF3tIvApwMWtpfPp em0g== 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=BRBLKvI85gKxwt/MZ0dWAOM6hKHOZ1H0DLsqRVmVE7o=; fh=S5rf2bc7VLlSXYQ0EqFAIodb1qEiUfsxulvZhQKZRws=; b=iIz+KKso++lXYs8oHXGrkc2wGMRo+aNDIcmmJaLLPlQgXGBJseX4LzvaiLU52bU9vu LUcZ+Y1swb6Z129pjqNZcCeiaZ7nGklEWfU4RmwXCFJPaklG5ROr01uvVifS6rfM7krm enVp0BwxBW0haGCT9RMwJPvEnVAyA1wkYuNDJ1u737vRzwmR7jJUVLCUI4oIWa93Loy/ Lo+LIgqx+gIDTmjPi8UY/L9+gNhzV7Xz/h3pa+EAhToZipPMF9yCXBnClMTg3/skIDRo hpTVl9cEylPKGdBFRX3SgqeqMlvzINFqhMh2TzErfgbgAEemI0QgQxsZizdANtaq1REZ eXdg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-18941-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18941-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h191-20020a636cc8000000b005cd84895879si4940414pgc.789.2024.01.07.10.03.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jan 2024 10:03:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18941-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-18941-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18941-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 9B4BE28209D for ; Sun, 7 Jan 2024 18:03:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BF57714A84; Sun, 7 Jan 2024 18:03:14 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) (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 6405F13FEB; Sun, 7 Jan 2024 18:03:10 +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 [10.196.197.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-201.mailbox.org (Postfix) with ESMTPS id 4T7Q5x1MFpz9svQ; Sun, 7 Jan 2024 19:03:01 +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?= , asahi@lists.linux.dev, linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v3 1/4] Bluetooth: Remove HCI_POWER_OFF_TIMEOUT Date: Sun, 7 Jan 2024 19:02:47 +0100 Message-ID: <20240107180252.73436-2-verdre@v0yd.nl> In-Reply-To: <20240107180252.73436-1-verdre@v0yd.nl> References: <20240107180252.73436-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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787455739898071871 X-GMAIL-MSGID: 1787455739898071871 With commit cf75ad8b41d2 ("Bluetooth: hci_sync: Convert MGMT_SET_POWERED"), the power off sequence got refactored so that this timeout was no longer necessary, let's remove the leftover define from the header too. Signed-off-by: Jonas Dreßler --- include/net/bluetooth/hci.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index 111e8f8e5..cf5d6230c 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -426,7 +426,6 @@ enum { #define HCI_NCMD_TIMEOUT msecs_to_jiffies(4000) /* 4 seconds */ #define HCI_ACL_TX_TIMEOUT msecs_to_jiffies(45000) /* 45 seconds */ #define HCI_AUTO_OFF_TIMEOUT msecs_to_jiffies(2000) /* 2 seconds */ -#define HCI_POWER_OFF_TIMEOUT msecs_to_jiffies(5000) /* 5 seconds */ #define HCI_LE_CONN_TIMEOUT msecs_to_jiffies(20000) /* 20 seconds */ #define HCI_LE_AUTOCONN_TIMEOUT msecs_to_jiffies(4000) /* 4 seconds */ From patchwork Sun Jan 7 18:02:48 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: 185753 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:37c1:b0:101:2151:f287 with SMTP id y1csp646288dyq; Sun, 7 Jan 2024 10:04:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IEAeNH5LTDtLAQ8UIwAXnFx+xpwL6WrhztxvlLH6OXvkRcknRb65WJEF+fIHsNKnlSpGb93 X-Received: by 2002:a05:6a20:2586:b0:199:ad39:d415 with SMTP id k6-20020a056a20258600b00199ad39d415mr992386pzd.81.1704650652706; Sun, 07 Jan 2024 10:04:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704650652; cv=none; d=google.com; s=arc-20160816; b=PsXV79XDhqr2loBc5EffCvjfy6U+cBI/nS6lRBKxmggqrNJbwiSCreEKvTv9AoOqBw rWDo8+QV5HRQpbt8oOvtjTXnbO7pPw+ELdh+1NQcgxHPG8VxHBZCPov8WRnzKfcXOwmF FB/AaU8OMd4SSFnZ/230a1+xdHp+yg3KWqJku8JuJ8d1JFgVc0+kNz4D76wCK82Hn5b1 1gguSAazfeo+ejbokwLK045s6FJV4yoTTpwXN+B6t/7loCA9PZT8javHyBuMDjIZ9PwM 6plRckF6YB5tHRRROuKGCg31bBddshpDzIlmXunVNPP71Cs8AwiSa1fqfldIgsXqDlKm sGQA== 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=xFGvZRiDbQXjqxd2rppyOAzZOIsqJn9Ls1auXbQVx7s=; fh=S5rf2bc7VLlSXYQ0EqFAIodb1qEiUfsxulvZhQKZRws=; b=kb/CD5UkQe/ZbOxKWZ27tMUxDqIYf4VvqBM6R+8d9wSqdFtyxkxjDcCWWCNDsihWtY 2G9v5BopBLbVKemNRicVm8RcWJPwYxk+OJI2SyB1ow2Fgal2IMRLmvfwhiTXxq/sim7Z i+NaGT4UmoWcIyKyJKqjZBlvyhrtqfMpd3xmac7O8/dJSpVTgNuAntaxLbPQkwvmjzCO irasXZcmvx5JZ4Wu5RSsODlKJ5UzAus89CYJna9DAhpsAA/dAmDQW5bXG5uFWKtzwUcZ pImq5bUlP6eB1VhFxrQpYzlAKZbLGFP8SRdkyZXCwk3Zs92oX1+rV4LbHJV5/AafDi2W YCbA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-18942-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18942-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id s3-20020a637703000000b005bdbd1b52d4si4750352pgc.270.2024.01.07.10.04.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jan 2024 10:04:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18942-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-18942-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18942-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 7884F281F9E for ; Sun, 7 Jan 2024 18:04:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1EBDE21374; Sun, 7 Jan 2024 18:03:18 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) (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 80CB714273; Sun, 7 Jan 2024 18:03:13 +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-102.mailbox.org (Postfix) with ESMTPS id 4T7Q603S65z9t8h; Sun, 7 Jan 2024 19:03:04 +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?= , asahi@lists.linux.dev, linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v3 2/4] Bluetooth: mgmt: Remove leftover queuing of power_off work Date: Sun, 7 Jan 2024 19:02:48 +0100 Message-ID: <20240107180252.73436-3-verdre@v0yd.nl> In-Reply-To: <20240107180252.73436-1-verdre@v0yd.nl> References: <20240107180252.73436-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: 4T7Q603S65z9t8h X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787455763017134743 X-GMAIL-MSGID: 1787455763017134743 Queuing of power_off work was introduced in these functions with commits 8b064a3ad377 ("Bluetooth: Clean up HCI state when doing power off") and c9910d0fb4fc ("Bluetooth: Fix disconnecting connections in non-connected states") in an effort to clean up state and do things like disconnecting devices before actually powering off the device. After that, commit a3172b7eb4a2 ("Bluetooth: Add timer to force power off") introduced a timeout to ensure that the device actually got powered off, even if some of the cleanup work would never complete. This code later got refactored with commit cf75ad8b41d2 ("Bluetooth: hci_sync: Convert MGMT_SET_POWERED"), which made powering off the device synchronous and removed the need for initiating the power_off work from other places. The timeout mentioned above got removed too, because we now also made use of the command timeout during power on/off. These days the power_off work still exists, but it only seems to only be used for HCI_AUTO_OFF functionality, which is why we never noticed those two leftover places where we queue power_off work. So let's remove that code. Signed-off-by: Jonas Dreßler --- net/bluetooth/mgmt.c | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index d4498037f..c5291e139 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -9760,14 +9760,6 @@ void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, struct mgmt_ev_device_disconnected ev; struct sock *sk = NULL; - /* The connection is still in hci_conn_hash so test for 1 - * instead of 0 to know if this is the last one. - */ - if (mgmt_powering_down(hdev) && hci_conn_count(hdev) == 1) { - cancel_delayed_work(&hdev->power_off); - queue_work(hdev->req_workqueue, &hdev->power_off.work); - } - if (!mgmt_connected) return; @@ -9824,14 +9816,6 @@ void mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, { struct mgmt_ev_connect_failed ev; - /* The connection is still in hci_conn_hash so test for 1 - * instead of 0 to know if this is the last one. - */ - if (mgmt_powering_down(hdev) && hci_conn_count(hdev) == 1) { - cancel_delayed_work(&hdev->power_off); - queue_work(hdev->req_workqueue, &hdev->power_off.work); - } - bacpy(&ev.addr.bdaddr, bdaddr); ev.addr.type = link_to_bdaddr(link_type, addr_type); ev.status = mgmt_status(status); From patchwork Sun Jan 7 18:02:49 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: 185754 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:37c1:b0:101:2151:f287 with SMTP id y1csp646602dyq; Sun, 7 Jan 2024 10:04:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IHY9aglpDjOsHuMzfJTpMX4rdPgXdjtIltZF5LinNQqPvlGFnDak2Bh2GD8Jcdu4f9VT+bH X-Received: by 2002:a05:6e02:2162:b0:35f:b606:fe9a with SMTP id s2-20020a056e02216200b0035fb606fe9amr4424204ilv.3.1704650686971; Sun, 07 Jan 2024 10:04:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704650686; cv=none; d=google.com; s=arc-20160816; b=CvmTxnD0qQn8FEdpSyCiaCEeeqNNTXJwsb/lhQGVMcGQu+RfAqvoDNSl1IPwgyVU6e wrRWSqG+CgccENeEeWCh+UctUohCsJMY+n9xKkGewveXs3MKi2U+QfRPrO9b9cdvmZW6 yP+XC/js56+lmI/Q235hwSGd/2IYT25pEMqDeA07DO12fRxALk80H4oM5r+z1xm65gHt /nvrgteUbIN2sbRm49xvSSqaDc/KYPVkgAkTEZ3grLODcwW2MwmxUSqZ+uWhgFq4zaVL BJrj+GkF49p9vFcD8OVD7m0zDc2X6Rm2zzq6OgtRa6P0+u5V+xbzGsb+QZORb6Ggpm7E 8PlA== 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=den5Eoi9tjG885w25HxzuCi7niU+nGAVYurFh4dct9I=; fh=S5rf2bc7VLlSXYQ0EqFAIodb1qEiUfsxulvZhQKZRws=; b=FLKUJr4JfDvj70hO6K2Yc9eB4XQzdhOc+lLuGQczYqsvpwmp47K5lAxdqqBLm/4RW7 aBmG21RK5h2Qa3EVD38eumeLdRX1lwkyGWimaqIVJZLjJnftSImvlKRvpBfvXlU17xet ktmXHHmCVbERfHono0ZdIo5+grzzOqR9a9zxzOP8HFhQRpWjpWwPFwMFn/vYZn3dkrqs E+mdXFu4Q8i06zFFUqCnW64Wwg3G5oQ+FingzRamueD+8jIT/9bx9J+tc7a9vNqAnmUH gBrsaGSWouQLRUK+O2W7F900/JpBMzR6PF16u9m/wBKvad6FrtVAj9TdPni1iqBUygHb F4vg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-18943-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18943-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id m4-20020a170902768400b001d4dd43fc06si4640919pll.284.2024.01.07.10.04.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jan 2024 10:04:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18943-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-18943-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18943-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 B779928214A for ; Sun, 7 Jan 2024 18:04:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B75622BCF7; Sun, 7 Jan 2024 18:03:19 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) (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 851C513FEC; Sun, 7 Jan 2024 18:03:15 +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 [10.196.197.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-102.mailbox.org (Postfix) with ESMTPS id 4T7Q624zzNz9tCY; Sun, 7 Jan 2024 19:03:06 +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?= , asahi@lists.linux.dev, linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v3 3/4] Bluetooth: Add new state HCI_POWERING_DOWN Date: Sun, 7 Jan 2024 19:02:49 +0100 Message-ID: <20240107180252.73436-4-verdre@v0yd.nl> In-Reply-To: <20240107180252.73436-1-verdre@v0yd.nl> References: <20240107180252.73436-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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787455798286157621 X-GMAIL-MSGID: 1787455798286157621 Add a new state HCI_POWERING_DOWN that indicates that the device is currently powering down, this will be useful for the next commit. Signed-off-by: Jonas Dreßler --- include/net/bluetooth/hci.h | 1 + net/bluetooth/hci_sync.c | 16 +++++++++++----- net/bluetooth/mgmt.c | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index cf5d6230c..e08afd870 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -361,6 +361,7 @@ enum { HCI_SETUP, HCI_CONFIG, HCI_DEBUGFS_CREATED, + HCI_POWERING_DOWN, HCI_AUTO_OFF, HCI_RFKILLED, HCI_MGMT, diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index e6eee1808..c920de0a2 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -5389,27 +5389,33 @@ static int hci_power_off_sync(struct hci_dev *hdev) if (!test_bit(HCI_UP, &hdev->flags)) return 0; + hci_dev_set_flag(hdev, HCI_POWERING_DOWN); + if (test_bit(HCI_ISCAN, &hdev->flags) || test_bit(HCI_PSCAN, &hdev->flags)) { err = hci_write_scan_enable_sync(hdev, 0x00); if (err) - return err; + goto out; } err = hci_clear_adv_sync(hdev, NULL, false); if (err) - return err; + goto out; err = hci_stop_discovery_sync(hdev); if (err) - return err; + goto out; /* Terminated due to Power Off */ err = hci_disconnect_all_sync(hdev, HCI_ERROR_REMOTE_POWER_OFF); if (err) - return err; + goto out; + + err = hci_dev_close_sync(hdev); - return hci_dev_close_sync(hdev); +out: + hci_dev_clear_flag(hdev, HCI_POWERING_DOWN); + return err; } int hci_set_powered_sync(struct hci_dev *hdev, u8 val) diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index c5291e139..8f42ee059 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -1382,6 +1382,14 @@ static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data, hci_dev_lock(hdev); + if (!cp->val) { + if (hci_dev_test_flag(hdev, HCI_POWERING_DOWN)) { + err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED, + MGMT_STATUS_BUSY); + goto failed; + } + } + if (pending_find(MGMT_OP_SET_POWERED, hdev)) { err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED, MGMT_STATUS_BUSY); @@ -9742,6 +9750,9 @@ bool mgmt_powering_down(struct hci_dev *hdev) struct mgmt_pending_cmd *cmd; struct mgmt_mode *cp; + if (hci_dev_test_flag(hdev, HCI_POWERING_DOWN)) + return true; + cmd = pending_find(MGMT_OP_SET_POWERED, hdev); if (!cmd) return false; @@ -10049,6 +10060,9 @@ void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status) /* If this is a HCI command related to powering on the * HCI dev don't send any mgmt signals. */ + if (hci_dev_test_flag(hdev, HCI_POWERING_DOWN)) + return; + if (pending_find(MGMT_OP_SET_POWERED, hdev)) return; } From patchwork Sun Jan 7 18:02:50 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: 185755 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:37c1:b0:101:2151:f287 with SMTP id y1csp646677dyq; Sun, 7 Jan 2024 10:04:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IGSOeCq9ET3B0LvrGFSlKVq03pbyy71zeMwFsedFIiucvuAO6rSYHq02qaX1js3m2b0Eepd X-Received: by 2002:a05:622a:15c1:b0:427:a420:b1f with SMTP id d1-20020a05622a15c100b00427a4200b1fmr4159829qty.13.1704650696770; Sun, 07 Jan 2024 10:04:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704650696; cv=none; d=google.com; s=arc-20160816; b=G2BPkwPYO2ZU27SE7QkCNU67HLmfR25eM30aOTcTH6Rfqv2FSGPq0+eHwshQwklT+5 gOp73UpAbQn7ISVnr55oHEI+ozk8jUlOB3CRSpU7iJenRu1a+HY7FkREqyCjoKL2EYB5 1qYPDcm1yTqY8ytYiXdjARv0K5XmouFPB2JYjG1FezhMFQ8LLExBgbw7lbEnqOdHL/yZ PgdYXNjLTynpdphesW9TYbqNRBUq7PA+YHh9tDbY11hiEy7DvZoWN2UA+ovrbQFJ5h9M PdYo9hrdcxPcersNiUetoOFNdbgl8GyQcTLHZXg3/i3KqHDNvacmZ8tAvGMrx4oVBm6t m/Mw== 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=ogvFWz8faKUl8w9Qkr6MIMsXTJbDcRdSuadInZT/gp4=; fh=S5rf2bc7VLlSXYQ0EqFAIodb1qEiUfsxulvZhQKZRws=; b=l/wAhJJO/DRzERpENbrkQaJvpREJYfdRcRLCK1AwFNkQzPUDTIZSUvF+GnWH6HLXar zWyciTpH+sJHzBMyyWH9L1HN9A6PtiOOjl/QZt9BhKJeyRCFJgWTT4vD/Ts9v/irc5Hv QSzA827lOmQr2aLlUkIjPmr7TYu9g0JBiX+56i3H2y+vI/FbN9lGoEOCzrLom2Pl05Dg xVo+vAq+J+wHDeoLVozOsFAW4PvtrwEgwbGOZNP73yMzPLOEhF37q3EcFMi6W/qyTcUI gU3yiN0yCsAMCR8lI9HJBLEp2RX6KF7BRCkrzAEXceJDSV5QsXotx7W7h2161vL9HQQW z4JQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-18944-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18944-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id r9-20020a05622a034900b004297e8fe7b2si4171598qtw.530.2024.01.07.10.04.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jan 2024 10:04:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18944-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-18944-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18944-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id E76F21C216A9 for ; Sun, 7 Jan 2024 18:04:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8BC7220323; Sun, 7 Jan 2024 18:03:20 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) (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 6B4C414F64; Sun, 7 Jan 2024 18:03:17 +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 [10.196.197.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-202.mailbox.org (Postfix) with ESMTPS id 4T7Q644dvhz9srM; Sun, 7 Jan 2024 19:03:08 +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?= , asahi@lists.linux.dev, linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v3 4/4] Bluetooth: Disconnect connected devices before rfkilling adapter Date: Sun, 7 Jan 2024 19:02:50 +0100 Message-ID: <20240107180252.73436-5-verdre@v0yd.nl> In-Reply-To: <20240107180252.73436-1-verdre@v0yd.nl> References: <20240107180252.73436-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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787455809289923822 X-GMAIL-MSGID: 1787455809289923822 On a lot of platforms (at least the MS Surface devices, M1 macbooks, and a few ThinkPads) firmware doesn't do its job when rfkilling a device and the bluetooth adapter is not actually shut down properly on rfkill. This leads to connected devices remaining in connected state and the bluetooth connection eventually timing out after rfkilling an adapter. Use the rfkill hook in the HCI driver to go through the full power-off sequence (including stopping scans and disconnecting devices) before rfkilling it, just like MGMT_OP_SET_POWERED would do. In case anything during the larger power-off sequence fails, make sure the device is still closed and the rfkill ends up being effective in the end. Signed-off-by: Jonas Dreßler --- net/bluetooth/hci_core.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 1ec83985f..43e042338 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -940,20 +940,51 @@ int hci_get_dev_info(void __user *arg) /* ---- Interface to HCI drivers ---- */ +static int hci_dev_do_poweroff(struct hci_dev *hdev) +{ + int err; + + BT_DBG("%s %p", hdev->name, hdev); + + hci_req_sync_lock(hdev); + + err = hci_set_powered_sync(hdev, false); + + hci_req_sync_unlock(hdev); + + return err; +} + static int hci_rfkill_set_block(void *data, bool blocked) { struct hci_dev *hdev = data; + int err; BT_DBG("%p name %s blocked %d", hdev, hdev->name, blocked); if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) return -EBUSY; + if (blocked == hci_dev_test_flag(hdev, HCI_RFKILLED)) + return 0; + if (blocked) { hci_dev_set_flag(hdev, HCI_RFKILLED); + if (!hci_dev_test_flag(hdev, HCI_SETUP) && - !hci_dev_test_flag(hdev, HCI_CONFIG)) - hci_dev_do_close(hdev); + !hci_dev_test_flag(hdev, HCI_CONFIG)) { + err = hci_dev_do_poweroff(hdev); + if (err) { + bt_dev_err(hdev, "Error when powering off device on rfkill (%d)", + err); + + /* Make sure the device is still closed even if + * anything during power off sequence (eg. + * disconnecting devices) failed. + */ + hci_dev_do_close(hdev); + } + } } else { hci_dev_clear_flag(hdev, HCI_RFKILLED); }