From patchwork Tue Jan 2 13:33:07 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: 184354 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4450868dyb; Tue, 2 Jan 2024 05:43:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IFwmFDkfwsB3tZHyVNPlG/yPi6Qwr745oeaMdkJTxkQUBEGfchdv5Dt3DKZMmRwISekhS8P X-Received: by 2002:a50:c282:0:b0:556:66d5:d68c with SMTP id o2-20020a50c282000000b0055666d5d68cmr1336424edf.56.1704203033137; Tue, 02 Jan 2024 05:43:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704203033; cv=none; d=google.com; s=arc-20160816; b=SovKB6qN8LNsIbkVTNNAZBVkB6UEVyfc2p5Gg5Wm14IZsUeQz8hGHh4waYkJJeOnlg Q4UQr4IBjZpYe3gGWyKpNHfPl9+wG3OfyBu2bDdqfG2qFiPt03pZngRHbqxwJdcLfBMr wjHkUVSENV6tWyCkVVrw31dqvw1rd1AKmoByJb+JCD4ZaRXO8NbFRfdXI0wf5ZIVGBzu 7Nb9PdF4lF1qEVlhjrmwCNb7zeKv0aMZpORFGQJBsrcoR7jZUMyPaVheKOAPrd5WJGBM mgj6O6lst5G2tCuTyhQZYfoEcQiv0rkH1n0JT0Ks47nFXiW7BdKV3VTEOVbow2fn7MGQ HFUA== 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=nODm6EQDjhZ3dpYRgjvcp1ORTUFigjUok9mHqFbxD8E=; fh=S5rf2bc7VLlSXYQ0EqFAIodb1qEiUfsxulvZhQKZRws=; b=rn6YXTvAH4mZRDk0LElDO/EPF1LosrMC88JZuHdO1Swn/pzUWPuGxSjfx3s/+DW4Ne Vi6ykipoYzIv/fCL0+rnVR3eWKekhH3bCUDQj5/NTPgtjzCH04KwV2a3GiWF5BwcLIe5 /FTB7EeSK3Lg6gJUtHSOX1T9GixbPsYbmS6pFTEO2da3S7CybGM12cUITSU9Ig1OxpTX lLBaZYRFUeRR6VYhynDPF2KJSj6brOUhlE/fWFu1ZyO6aA1qhr3oG2zG9q4LxXC3WS0e oWdd7uqpGZqmaCn0LR/NjPpaMM/XVuXWsDhTNLfJqDdtFjn3nUfhrChESYVLuWNevm0J FrEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14433-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14433-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id g9-20020a50d5c9000000b0055678085e1bsi1059668edj.187.2024.01.02.05.43.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 05:43:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14433-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14433-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14433-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 am.mirrors.kernel.org (Postfix) with ESMTPS id BEC141F21B66 for ; Tue, 2 Jan 2024 13:43:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DD87713FE2; Tue, 2 Jan 2024 13:42:52 +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 D7ED311CB8; Tue, 2 Jan 2024 13:42:48 +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 smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (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 4T4DM34RLKz9sWY; Tue, 2 Jan 2024 14:33:19 +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 1/4] Bluetooth: HCI: Remove HCI_POWER_OFF_TIMEOUT Date: Tue, 2 Jan 2024 14:33:07 +0100 Message-ID: <20240102133311.6712-2-verdre@v0yd.nl> In-Reply-To: <20240102133311.6712-1-verdre@v0yd.nl> References: <20240102133311.6712-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: 4T4DM34RLKz9sWY X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786986400058613987 X-GMAIL-MSGID: 1786986400058613987 With commit cf75ad8b41d2aa06f98f365d42a3ae8b059daddd, the power off sequence got refactored so that this 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 Tue Jan 2 13:33:08 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: 184337 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4446330dyb; Tue, 2 Jan 2024 05:34:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IFH8QqnbvCzgBN+EhB0x8ScIjJay2fhAUUnhMPfPd+ep3EwQt4oYjPsnQGR804iLe1k8ZA1 X-Received: by 2002:a05:600c:a388:b0:40c:6b55:29f1 with SMTP id hn8-20020a05600ca38800b0040c6b5529f1mr9577482wmb.135.1704202455301; Tue, 02 Jan 2024 05:34:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704202455; cv=none; d=google.com; s=arc-20160816; b=yStS6mJfQnwbgPtBQ73CaeoM7Emmn3dOi/7xql/gVDqurVPRgtx91lby+CqzcC7aJW fTPjiVyJzcBASLeA+AE74e7WbWb1DZ72BHZ65eZAZa6UMtO8cGwSnwWxSABavi0QGs5b JjobhXDrXDWgHMlemSv/rg/dsH0KUeFV7RuprX+/aQcZKdM36mgVizhZAUA9wIpLaUhc RvGVgcSGBKP4w6oTGu/SVVrxu2KrjCbT2gyl1efV5AC7ayPe/IYyDjzuN6/RD2qC+Wbu iSIdOrrUv6C5W8oE8kiY4XHKQdueB60VySxh6O4SNAtzruV0pttASFFQxkbr7vW5PZVG cmeg== 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=87+jM2180EUyQlCWJD7RFO6Vd7lJRZXroSxhcNUu254=; fh=S5rf2bc7VLlSXYQ0EqFAIodb1qEiUfsxulvZhQKZRws=; b=FJmuTFXwu4SEpK5DVdWjitZzybbMUz8XUrSIXoofCK05aMqGLaCDn2alkR0zangV5I i7EPqcANUYo+hLpV2eSOmLV0gPzXbvve1VAhavS4S0miEcfq8Eg7qMnOaHPTVenKCdtk CCzkFnJfWVz8OJh/f3q+i1bNq4A4M1w/pU9KDD1hoKs8FOexdBhcc+RryOPTK7LEHH75 jmheHqgQ6p9YXfEo8R0H5dDMcNWR0E5eKJHgN0EDWOUiOysBWyPiRWLMpeZgbZnIcJRu +UcyHu815bfPaUueUzZf533nYdXTWR7ZiqoBmsSPOgqYCtkfpFL2gJsuop9ZZIb8VqEL dWVA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14404-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14404-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id wi5-20020a170906fd4500b00a26ee6b99adsi6789554ejb.394.2024.01.02.05.34.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 05:34:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14404-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14404-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14404-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 am.mirrors.kernel.org (Postfix) with ESMTPS id BAEDD1F2137D for ; Tue, 2 Jan 2024 13:34:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A32E011719; Tue, 2 Jan 2024 13:33:29 +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 C01BAFBEC; Tue, 2 Jan 2024 13:33:25 +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 smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (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 4T4DM61GV8z9t16; Tue, 2 Jan 2024 14:33:22 +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 2/4] Bluetooth: mgmt: Remove leftover queuing of power_off work Date: Tue, 2 Jan 2024 14:33:08 +0100 Message-ID: <20240102133311.6712-3-verdre@v0yd.nl> In-Reply-To: <20240102133311.6712-1-verdre@v0yd.nl> References: <20240102133311.6712-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: 4T4DM61GV8z9t16 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786985793802105824 X-GMAIL-MSGID: 1786985793802105824 Queuing of power_off work was introduced in these functions with commits 8b064a3ad377c016a17e74f676e7a204c2b8c9f2 and c9910d0fb4fc2ede468b26d45a1d50c309897770 in an effort to clean up state and do things like disconnecting devices before actually powering off the device. After that, commit a3172b7eb4a2719711187cfca12097d2326e85a7 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 cf75ad8b41d2aa06f98f365d42a3ae8b059daddd, 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 Tue Jan 2 13:33:09 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: 184353 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4450747dyb; Tue, 2 Jan 2024 05:43:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IEYkoy3oIPa7X1UGBpYa8qhID6fufy9wPDGaYVIl23ggQVNfybcFM8DNJ40IqdIhIqxJC6E X-Received: by 2002:a05:622a:386:b0:425:a69f:9780 with SMTP id j6-20020a05622a038600b00425a69f9780mr25105992qtx.30.1704203020300; Tue, 02 Jan 2024 05:43:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704203020; cv=none; d=google.com; s=arc-20160816; b=EdWQYTI/q4bckjc6LkpCIhH0lgzMrhsok3pTNCTIBZ7nFoaBO0O/ngOljKev/5ND5j 38y9hS02Dtc5HSSkzSs8B8D+A8f3Rhjhan5IDI6uYmwBC+m05ufpIluhw6bNoLYU7IH5 2Nse4yZU5owd7UQymnV6HfA11GTeqm3I8oJDzLLdA0Psiv0KYC+KjRDw/kELkL7Nm2yF piqVoUb4g0wxMXqJ+DvqKk+AWVaooNvJ4ZMo8SGGFnp5ELhcPjSIbenMVNlsWGzDjV2H bu4QmIO++D7K6ATm9bV7kq8ZykZAjUYRm/gtkMmd/VFLuzKOgKTsSKXX9dk2GU/LAUdv OKrg== 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=fIi4+XoEGdi8dsVlv5x0/PizIyew5QJaUXYXRCnUTVXswwItUmdOyDuxHnpod0KI83 Ceh2sdoae5B8xenS4rq71OPYHcZxwYT08NuhrTQPpwZYDpT4mQ9VfHgjUePK/Px56Axi kG3UjI1nMF+ArVPWQZViAuoJ94yL/pNtT5gPAuCZGsNYXFJ3bVQJBGy8qn65WEliYOVz ebgqIrxb64qNS9J9VYgk2WlDwa3qphDWVmwdT27UVe9E9O/VHoNR/ZnDXmHQ3Cw1cvQk e0IJaZ9dAs5DkWUyeuAL2BBKYQA4YMoSxQojJf+SzfGnB0nntehrrqOFX/tCk7Bq7BxO UVCw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14432-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14432-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id fc21-20020a05622a489500b004283020694asi1110587qtb.579.2024.01.02.05.43.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 05:43:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14432-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14432-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14432-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 F2A881C22188 for ; Tue, 2 Jan 2024 13:43:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DD53B12E5B; Tue, 2 Jan 2024 13:42:51 +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 D95CC125B5; Tue, 2 Jan 2024 13:42:48 +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 smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (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 4T4DM83spzz9tJ3; Tue, 2 Jan 2024 14:33:24 +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 3/4] Bluetooth: HCI: Add new state HCI_POWERING_DOWN Date: Tue, 2 Jan 2024 14:33:09 +0100 Message-ID: <20240102133311.6712-4-verdre@v0yd.nl> In-Reply-To: <20240102133311.6712-1-verdre@v0yd.nl> References: <20240102133311.6712-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: 4T4DM83spzz9tJ3 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786986386654627730 X-GMAIL-MSGID: 1786986386654627730 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 Tue Jan 2 13:33:10 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: 184338 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4446541dyb; Tue, 2 Jan 2024 05:34:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IFp5b30oH6UY/5qf7cB8lBUMiQHSldWySiS5zE3t+8Mnjz6kkfLFkb41vChMe0Lu/IODqbl X-Received: by 2002:a05:6512:3b0f:b0:50e:6b45:c915 with SMTP id f15-20020a0565123b0f00b0050e6b45c915mr9356046lfv.7.1704202481381; Tue, 02 Jan 2024 05:34:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704202481; cv=none; d=google.com; s=arc-20160816; b=i9V47eM7XJT+5nG+smfgxlQ7Vy2vbogfQ5PSrD335SDPsq8073QuL2FNLLUJEJECT+ Z7j8Bq05ECr8HoJnKwW8he0/LsctvdyRtnAIUuYH3BMy8bDbjz3O7P6TnezUHeLi4vAn CAE1D82yA0F9wETXjO1MBU++j/EgWT9Wejp78YG9A+mKakQYTXIvsZUX7kUIWbgKlTBd BDDCes/NiK2BqFEZIYT9s033QCxjbDGiwCM2dDzxTn4G6pfZvOkyMzNLRuFT42ONjo6/ LRwb6XlpkOoMeqavOd8kXezUkQEMGTJoB6BqZys1Z3rclRV0YJWmk2WHl7hVQg22Nsct bAPQ== 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=v1LJcC9ZvAsWCtzIkp4ijtyBiT7HQFW99bxrW6L9QN0=; fh=S5rf2bc7VLlSXYQ0EqFAIodb1qEiUfsxulvZhQKZRws=; b=geJSNrT9K5jnNaqKmQ/+bnGRbujhC/13qop80Q6zQx6hYoSZpQUQzZXnCIIBjmzq3C 0MSAgTV4S76gjrSRvktRCfMzWzALMCnZWwXNiF8W2JTstGaaTdBA+ovEu4XxWjmZQWf8 5NjR+qu71+BPO8aE8C20WjXh/ST5lqpsTBDtvL+81GrFnnNy88pW+7u+rf8fLf+8iwrT 8xCIBou7uA94ccuWz7UJ/uXQZKKmvVPP6YMHnlrZFzaq8n7IorjPBPucjmp+UV7HVNaC 7yVYq9NwDlpYPc/me2IXp2LdTTlmfEoBVCJQJWetTFrvePf5pIrUw6xYohKcOlR3YftM Zaeg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14406-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14406-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id n10-20020a170906700a00b00a26ea2ac390si4966537ejj.530.2024.01.02.05.34.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 05:34:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14406-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14406-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14406-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 am.mirrors.kernel.org (Postfix) with ESMTPS id F1D5C1F2160B for ; Tue, 2 Jan 2024 13:34:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BFAC812E52; Tue, 2 Jan 2024 13:33:40 +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 9F1B711C85; Tue, 2 Jan 2024 13:33:37 +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 smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (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 4T4DMD1n5Qz9sWC; Tue, 2 Jan 2024 14:33:28 +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 4/4] hci: Queue a HCI power-off command before rfkilling adapters Date: Tue, 2 Jan 2024 14:33:10 +0100 Message-ID: <20240102133311.6712-5-verdre@v0yd.nl> In-Reply-To: <20240102133311.6712-1-verdre@v0yd.nl> References: <20240102133311.6712-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: 4T4DMD1n5Qz9sWC X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786985821014349529 X-GMAIL-MSGID: 1786985821014349529 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 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 actually power the device off before rfkilling it. Note that the wifi subsystem is doing something similar by calling cfg80211_shutdown_all_interfaces() in it's rfkill set_block callback (see cfg80211_rfkill_set_block). Signed-off-by: Jonas Dreßler --- net/bluetooth/hci_core.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 1ec83985f..1c91d02f7 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -543,6 +543,23 @@ int hci_dev_open(__u16 dev) return err; } +static int set_powered_off_sync(struct hci_dev *hdev, void *data) +{ + return hci_set_powered_sync(hdev, false); +} + +static void set_powered_off_sync_complete(struct hci_dev *hdev, void *data, int err) +{ + if (err) + bt_dev_err(hdev, "Powering HCI device off before rfkilling failed (%d)", err); +} + +static int hci_dev_do_poweroff(struct hci_dev *hdev) +{ + return hci_cmd_sync_queue(hdev, set_powered_off_sync, + NULL, set_powered_off_sync_complete); +} + int hci_dev_do_close(struct hci_dev *hdev) { int err; @@ -943,17 +960,27 @@ int hci_get_dev_info(void __user *arg) 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, "Powering off device before rfkilling failed (%d)", + err); + } + } + + hci_dev_set_flag(hdev, HCI_RFKILLED); } else { hci_dev_clear_flag(hdev, HCI_RFKILLED); }