From patchwork Tue Jan 2 18:19:17 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: 184411 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4609371dyb; Tue, 2 Jan 2024 10:20:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IGC0/gM15dkJNqwqmhBu7cUwxr3ubgZwUbihgSpt49vSOHzJEIb20reu4Fz3WcSVdoGBJNY X-Received: by 2002:a17:907:595:b0:a28:50dd:66c9 with SMTP id vw21-20020a170907059500b00a2850dd66c9mr1275206ejb.68.1704219643438; Tue, 02 Jan 2024 10:20:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704219643; cv=none; d=google.com; s=arc-20160816; b=w1rg/8Gmy7yjG8ZvLzbu29ix5AylXCwCbNjqYCF/WO0mQG/HhrcpKf+wXHf5oRMi+f c8Aaop46MEfYGk6L5rtMUepBiygsVeL2J6SWNWtV3SkI4YEwpoqqNWty5y01XrIcl9/7 Kk7+eSRrrRU3YQntbvT1H4724JWqN1eQC/Jcc2qPt1zMv33XxMHVDK4YG50OJEQlrCZC TARu66dNNmkmGsji2f7iOuyJOhxdnLVqvuOLM14VzTONezAAnEJLSu5PQ9nHOIjtfg/A TpvWI2fClz/hCUSthp9z8Dn4hVPZWqgQTt4Z8YXg9lmBWmsgFueem5dyzpQEd/ExToIt Lkrw== 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=DmtvO8mHiyXs9bPnAYZoiPUhbsusmmDsEX8XDgEH/+CSYvgIz+9k8ooGwTA1Wfje4T CjCv4EPBJOMJysIGTjPptFqKswOVLJTCtwUKYJnyeblcqBnn00Voj0ep61wZ9PoqHSN/ w+EaQsg/2Qlzv2biAb4+qH2+covS/zRfdvFDkHV8SBFooGm2qtcjVKRRY621/HSmZ5sZ Xjcga6fseQhiMFgMSamv2Vq5fosYq1N2gCXvXEVtqugxX7POPrVUdM1ShoxaTjEEmdqN LVYMs0H6eRtc1Hm3wNoGEQ4A6d/TjWHZs2TA0DE1UHsWkuvqCa7t2iZyrtsUyudiUwGa n9UQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14701-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14701-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 vl15-20020a17090730cf00b00a2362dbe5c3si10616199ejb.351.2024.01.02.10.20.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 10:20:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14701-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-14701-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14701-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 F28681F23261 for ; Tue, 2 Jan 2024 18:20:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DCC8015E98; Tue, 2 Jan 2024 18:19:57 +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 D6BC4156E3; Tue, 2 Jan 2024 18:19:54 +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 [10.196.197.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 4T4Ljg39m2z9ssH; Tue, 2 Jan 2024 19:19:51 +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 v2 1/4] Bluetooth: Remove HCI_POWER_OFF_TIMEOUT Date: Tue, 2 Jan 2024 19:19:17 +0100 Message-ID: <20240102181946.57288-2-verdre@v0yd.nl> In-Reply-To: <20240102181946.57288-1-verdre@v0yd.nl> References: <20240102181946.57288-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: 1787003816980770884 X-GMAIL-MSGID: 1787003816980770884 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 18:19:18 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: 184412 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4609564dyb; Tue, 2 Jan 2024 10:21:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IEBoKM5nlE6MaZN/c42NfFvQCVtXAZ0iTSfT2Cg53OFDe3XUSMLemxJs0+3vAYlUKw2jKKJ X-Received: by 2002:a25:ae65:0:b0:dbd:1254:414f with SMTP id g37-20020a25ae65000000b00dbd1254414fmr6232252ybe.42.1704219665245; Tue, 02 Jan 2024 10:21:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704219665; cv=none; d=google.com; s=arc-20160816; b=RNzmRpU+on1PxM9oDL535d8NdP6TXOPOiA9lrVzcVR3Ogx9BQoGCawX8lwkPezajfj DIl9ssabriKYH3ObZfrPYXX5+tHBU03VIyDqVlBGUQdnMhmHkrRkYkVpkET/Bi/lFC1R YacSKKHJS9v2TOFvdBp72GZMprkYbEMkeEtRa+f7HxtAclmKCpQSvZofuI9HvNUwyvyP XxNB1R4YeKv9rrxOZnK/q6NYXjBhG3pTwsHlmlFjKAwG8NcvxvanIHAxBtPC1p4fh/8M n5ZoXnERoJjyNd1V/twTZfPVWriG7l96IGeI0AjQS5rO8ixD7mX9IRkvMaXuaxLIXI/z CRMw== 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=mKWXIamLhYtUrzoRiU27kHy4TJkY6zR3cj3lesFG0UkyEwwPg8OaeDaI/QUG/cL4eS 3H+kpkefgs9A52mte3KD2g3d+HGSNC7VJ1I/UjcBsF/zKvcmtWIpGmqIRzq3bjQNNx1w kUv52pLabsQ72BeaGbtGnr7ZYo2JM5GK9orgJ0f4INfH3+wTqT6vYbCUIpu8TDCWQvXd JR9mIZCQ03zlXypV17SwXrXc0YwWiMtdMOLWlEoVnIartNN2/x5mr/gffjdMs1tqNXHc slLjP41BfjJNBgKRRIxHUiJC8iNQ+hY1RlppXJ059xjQ4mLHYUsx2YDktUheEPGKa/nv HqTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14702-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14702-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 l19-20020a05620a28d300b0077f5e12ded1si29144848qkp.618.2024.01.02.10.21.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 10:21:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14702-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-14702-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14702-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 0BE8A1C228AF for ; Tue, 2 Jan 2024 18:21:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 71A371641E; Tue, 2 Jan 2024 18:19:59 +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 6B382156FB; Tue, 2 Jan 2024 18:19:56 +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 [10.196.197.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 4T4Ljh4gf0z9sWQ; Tue, 2 Jan 2024 19:19:52 +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 v2 2/4] Bluetooth: mgmt: Remove leftover queuing of power_off work Date: Tue, 2 Jan 2024 19:19:18 +0100 Message-ID: <20240102181946.57288-3-verdre@v0yd.nl> In-Reply-To: <20240102181946.57288-1-verdre@v0yd.nl> References: <20240102181946.57288-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: 1787003839790115391 X-GMAIL-MSGID: 1787003839790115391 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 18:19:19 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: 184413 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4610083dyb; Tue, 2 Jan 2024 10:21:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IGFt/PdMI5RuP+0ktUqU4uXGLncIWEq+6jvetNWk0NeD/nM2bRYTikecwTdQVWme2h6m4dJ X-Received: by 2002:a05:6830:1684:b0:6db:d286:39eb with SMTP id k4-20020a056830168400b006dbd28639ebmr12819671otr.59.1704219703638; Tue, 02 Jan 2024 10:21:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704219703; cv=none; d=google.com; s=arc-20160816; b=n+6BYhKjL12Y/GeM7UJHDpGA/WV5mNIMl5Q39BMmhbToARTAwiMzfUptVvnwtPZSkw Mgmmp/VZWkXbHOzCcdZ/Z+BPKb6wmdYtwzOidfA5jmWwIcpVWFh0hCZB1h9CMj8Z40Pa e5y8mlccKtTf3Gkx8l+hHQ/O3FS2OFX+xYLVpJpfzo52rFQouTeubcM7fU3YDWy/jOHh jcGPceOdJ1G1QpbrzH7WAKFDOItzNuS2gvlknY/K1NMeMZitNXhLLDCIo+EY73E3rT2u Uf3loGlflF/NR0RjiDj4H2HC4QwL7ltdSSTTYjI3xc0Q7MuJkc8C0f1wA4QGcx3sPeRx Z5OA== 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=igYAxZKJsQvKbmWWd6cs0QEfjT8K3N1PDXoCPjrK1HQjibxz4s2uZ+I7A+Iz6yREQ3 4eRMXIpPl829HRl2Fjs7ZhdwHkqzRwfJqb3R3f8rsRHnkdNWF2IV4E+QCnD1sJ+RzqzS Du1zj5FJoskerJ0lvphL4ckc4xC9/0AkjvP2fG6juMelbGBraigfpwQbd5INxFfgJlLj bPiOnhQTjl68pXII/kliMuggzuikV9U+4msydj+nNI39W0iD3OnnV5U+ioka6sFDF0YX Kzv50LeQcqUIcrxSTWoNlodzIhBD7PXf7o4epxNdEsV5PyvaYB+vi5LDZ390LDZ/HMjM 6SeQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14703-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14703-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 fx4-20020a05622a4ac400b00427f29eea3dsi13860431qtb.327.2024.01.02.10.21.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 10:21:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14703-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-14703-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14703-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 6A8081C22933 for ; Tue, 2 Jan 2024 18:21:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 810CC168D4; Tue, 2 Jan 2024 18:20:01 +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 8430E15AF8; Tue, 2 Jan 2024 18:19:57 +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 [10.196.197.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 4T4Ljk06Ljz9st4; Tue, 2 Jan 2024 19:19:54 +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 v2 3/4] Bluetooth: Add new state HCI_POWERING_DOWN Date: Tue, 2 Jan 2024 19:19:19 +0100 Message-ID: <20240102181946.57288-4-verdre@v0yd.nl> In-Reply-To: <20240102181946.57288-1-verdre@v0yd.nl> References: <20240102181946.57288-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: 1787003879942152638 X-GMAIL-MSGID: 1787003879942152638 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 18:19:20 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: 184414 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4610173dyb; Tue, 2 Jan 2024 10:21:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IGJMIaEIpbkTNtixoDmIfuatjrJgpq2BgGcaPJ9hipfLodSyW+SHlN/sOW02tfzNdjvL2vH X-Received: by 2002:a17:903:2450:b0:1d4:bd30:3ec3 with SMTP id l16-20020a170903245000b001d4bd303ec3mr2349658pls.34.1704219711498; Tue, 02 Jan 2024 10:21:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704219711; cv=none; d=google.com; s=arc-20160816; b=jGB661BWf3I/ta39leGOP06zWBGB6A4BZIKby6L+N0sjZzeNoRzcXpQhq+A4xeifgj j3EE3xGTMaj16BWp7ZOKXHXwwNEYY9Gtlpkoe9Yjw5xgOoj6JBrpXrGZ/bgUONsviZqU ysMbeNOs/6/PVfOOm+5bjqFhTh9taXCy46enNfWKAOQ6PepECzQlkSHNYChvpDaiJ063 zg27WA5Od6hITlOygOBnb5oIe6KZ4EgcRv7QY+qVf2sHf0lNtowseGykrIy6m0bH6h7u konTBESNGC/o4Bvui9XTAF383xh5/U0aEH+uUecK1MeggBPrQrP5PEgiRrOhJwChrey4 NStA== 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=yxmyosxSnlp7Ei19yStyiMRCK9MftKNXnYm30akWgM2btfV4rzvdTV9vnqg+Gv41Y2 chFEpXOmz4IBhxAYce4J64YBxZ/PKKBdJNHyIpUAPsw5XHTHNzAdwxQ8bDAlRR2+DHcS qATR0RDTgt7UTX/JDj++CeeZopUex4tgX6axJszVbTLdYuQHVOf0TRDfqu8HUoU0GcJ5 xYPhZcDBEqmeHQ29gRWqfuEdEog57VGDAmRMPTX6tasGYAITHJ3/BKwcpi6rEnkfPWmB 8N4HF32O4/1l+zQIM4FoaWhOmTB9yHiSdCdqt+KCl4U1+AfnkHtgMdPMLwBGrp/5jvzY ddvQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14704-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14704-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 a10-20020a1709027d8a00b001d487bf25b0si9503255plm.507.2024.01.02.10.21.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 10:21:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14704-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-14704-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14704-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 45EFB2843AC for ; Tue, 2 Jan 2024 18:21:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3A7E3171A3; Tue, 2 Jan 2024 18:20:02 +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 2304F1641A; Tue, 2 Jan 2024 18:19:59 +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 [10.196.197.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 4T4Ljl5CxWz9snC; Tue, 2 Jan 2024 19:19:55 +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 v2 4/4] Bluetooth: Queue a HCI power-off command before rfkilling adapters Date: Tue, 2 Jan 2024 19:19:20 +0100 Message-ID: <20240102181946.57288-5-verdre@v0yd.nl> In-Reply-To: <20240102181946.57288-1-verdre@v0yd.nl> References: <20240102181946.57288-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: 1787003888097547276 X-GMAIL-MSGID: 1787003888097547276 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); }