Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp34597pxb; Wed, 18 Nov 2020 15:45:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJylhdXfMCCj15qfiUwJUPuPXRCssQ0PdMgnobp25htTMwNQxLdwTYyi6p3GGW+R/V7hH0x1 X-Received: by 2002:a17:906:1902:: with SMTP id a2mr25074945eje.269.1605743140116; Wed, 18 Nov 2020 15:45:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605743140; cv=none; d=google.com; s=arc-20160816; b=pgXNp2SsJT9vEtvcasbVOCej6xAnXTQPgFUAcCoPCNfmoiVd5lT4Afm+DvZtmBx0p3 NZudcfJYpNC+wCYfmhRtaY3pngpJfxtGzLIBpTmh1qM62Vc3/Vc0bBTBkgN7VfPtNKQ0 Tp9mFeKO/nQLcF5k6nTUNydzH1gs6MBrR04y0v2IDObaYbCtDec56qY2lj3BSKv08xt8 vZ0JoIg72NDuJ+JAXIB5DG0kaDsHUvzT5nJz+KiWuv1I9k378/W+94Xnx6rCQGsJhqRe JriR2he3MloYkGHqtmKJSNUz0S7phTvWwn1qWepQkUqMNZxKxGFppmZkamuFou75JXQI 1pVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YNVmomPsfoKndzhCgIIwvVulBDHSaUyYS9Lmo0Fh/4g=; b=tWVSsrU8b6BHEg9fJFZfrkjM49SPD7gb/W55BGfXhBHCbNJpiv/ui0/fohcELEN9Dq ZUBXneApfXK2E0khypbWBXGhz8+MHcvYEOtuSTWrX0eJMsC32ldzBNIsuL5iU488Y2C9 xDDovvkZuP9WSAtAds5SqtOLZbHmjQ9HbVSnzG7zpUYxnjHQYdnQ3Stjy4XVXaxpK0by SVzTTUmulNG0OLI4ed7gUaZeLf1XWdLTeYP6gJM83SWqQ9r7ViXMpPL8STIkwGHGf3PN 6FDIuryvO4lC6nbONiyre+rSHaeUop+8fsCgMgn3gPFM/ekGRYjZI/F0hbM1tj4ZMBLW x7YQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=nk0Ghbdp; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id df6si16517217edb.508.2020.11.18.15.45.15; Wed, 18 Nov 2020 15:45:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=nk0Ghbdp; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727305AbgKRXoH (ORCPT + 99 others); Wed, 18 Nov 2020 18:44:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727294AbgKRXoG (ORCPT ); Wed, 18 Nov 2020 18:44:06 -0500 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 251FEC0617A7 for ; Wed, 18 Nov 2020 15:44:06 -0800 (PST) Received: by mail-pg1-x543.google.com with SMTP id 81so2508980pgf.0 for ; Wed, 18 Nov 2020 15:44:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YNVmomPsfoKndzhCgIIwvVulBDHSaUyYS9Lmo0Fh/4g=; b=nk0GhbdpNORnDl6nwa8uen7IN7R0ti5psYLfmNxsQms1GpbKULyrzSWIg0BePVl1Wo mCRcnyHsVEGxEhYU/M1dPxjBr+SvW5i0aY9SYkTMMS+uLIAzlpC1QNHxWOwitZ8sdJst URUi+ZmlnyPas/Jr3Sz6DnLgu4c+lfg8X2Bn8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YNVmomPsfoKndzhCgIIwvVulBDHSaUyYS9Lmo0Fh/4g=; b=G2t7hGhVHQeO7FCAdYHbItjna9TpaJIYQLUdKMFxAdytHXN2zB/mSjghaYE9ZdNqWX wXHHJ/s16eWkr/M+qFjCt0DmaBBYhW5gI4BXAPriaJ+B6SUeu7+tgSAPC44MWolpGneg ndgV63c46h939VlzN7HqtKYaDwvM9byDOmXTg5JbnmvURMF+V9lqGZNoGcK4doz1nkoW 6b2QR9Tl4FF890cVK5W1ySFejU3IV2Tqpp6DL+s5Z5zp7hc53gEfmeTM+eTNfiMh4axC rGQ1zOm3Syvt/A/EIyWUj9Ez99v93qPKTvTvL4Pn3UrA05ClyvNXaljDVa4mvoucYTil ulZQ== X-Gm-Message-State: AOAM532M15OMT6aGgT2LSt+IJ8RCiqa5cLrXD+/9Gg6HKLwca18m2TdZ gl62A4t80pzVIe1YB1UlKSVKuw== X-Received: by 2002:aa7:8c16:0:b029:196:33d2:721f with SMTP id c22-20020aa78c160000b029019633d2721fmr6414397pfd.70.1605743045713; Wed, 18 Nov 2020 15:44:05 -0800 (PST) Received: from apsdesk.mtv.corp.google.com ([2620:15c:202:1:7220:84ff:fe09:2b94]) by smtp.gmail.com with ESMTPSA id f6sm21437435pgi.70.2020.11.18.15.44.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 15:44:05 -0800 (PST) From: Abhishek Pandit-Subedi To: marcel@holtmann.org, linux-bluetooth@vger.kernel.org Cc: chromeos-bluetooth-upstreaming@chromium.org, mcchou@chromium.org, danielwinkler@chromium.org, Abhishek Pandit-Subedi , Daniel Winkler , "David S. Miller" , Johan Hedberg , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jakub Kicinski Subject: [PATCH 1/3] Bluetooth: Rename and move clean_up_hci_state Date: Wed, 18 Nov 2020 15:43:50 -0800 Message-Id: <20201118154349.1.I088e8a8c015ee9cc5fb5fc52c02ff4caf9a79031@changeid> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog In-Reply-To: <20201118234352.2138694-1-abhishekpandit@chromium.org> References: <20201118234352.2138694-1-abhishekpandit@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Rename clean_up_hci_state and move to the core header so that we can power down the controller from within the kernel rather than just via mgmt commands. Signed-off-by: Abhishek Pandit-Subedi Reviewed-by: Daniel Winkler Reviewed-by: Miao-chen Chou --- include/net/bluetooth/hci_core.h | 2 ++ net/bluetooth/hci_core.c | 45 +++++++++++++++++++++++++++++++ net/bluetooth/mgmt.c | 46 +------------------------------- 3 files changed, 48 insertions(+), 45 deletions(-) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 9873e1c8cd163b..ff32d5a856f17f 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -1072,6 +1072,8 @@ void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active); void hci_le_conn_failed(struct hci_conn *conn, u8 status); +int hci_clean_up_state(struct hci_dev *hdev); + /* * hci_conn_get() and hci_conn_put() are used to control the life-time of an * "hci_conn" object. They do not guarantee that the hci_conn object is running, diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 502552d6e9aff3..8e90850d6d769e 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -2290,6 +2290,51 @@ static void hci_power_on(struct work_struct *work) } } +static void clean_up_hci_complete(struct hci_dev *hdev, u8 status, u16 opcode) +{ + BT_DBG("%s status 0x%02x", hdev->name, status); + + if (hci_conn_count(hdev) == 0) { + cancel_delayed_work(&hdev->power_off); + queue_work(hdev->req_workqueue, &hdev->power_off.work); + } +} + +/* This function requires the caller holds hdev->lock */ +int hci_clean_up_state(struct hci_dev *hdev) +{ + struct hci_request req; + struct hci_conn *conn; + bool discov_stopped; + int err; + u8 scan = 0x00; + + hci_req_init(&req, hdev); + + if (test_bit(HCI_ISCAN, &hdev->flags) || + test_bit(HCI_PSCAN, &hdev->flags)) { + hci_req_add(&req, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan); + } + + hci_req_clear_adv_instance(hdev, NULL, NULL, 0x00, false); + + if (hci_dev_test_flag(hdev, HCI_LE_ADV)) + __hci_req_disable_advertising(&req); + + discov_stopped = hci_req_stop_discovery(&req); + + list_for_each_entry(conn, &hdev->conn_hash.list, list) { + /* 0x15 == Terminated due to Power Off */ + __hci_abort_conn(&req, conn, 0x15); + } + + err = hci_req_run(&req, clean_up_hci_complete); + if (!err && discov_stopped) + hci_discovery_set_state(hdev, DISCOVERY_STOPPING); + + return err; +} + static void hci_power_off(struct work_struct *work) { struct hci_dev *hdev = container_of(work, struct hci_dev, diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 12d7b368b428e8..ea136a6b730f9a 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -1122,16 +1122,6 @@ static int send_settings_rsp(struct sock *sk, u16 opcode, struct hci_dev *hdev) sizeof(settings)); } -static void clean_up_hci_complete(struct hci_dev *hdev, u8 status, u16 opcode) -{ - bt_dev_dbg(hdev, "status 0x%02x", status); - - if (hci_conn_count(hdev) == 0) { - cancel_delayed_work(&hdev->power_off); - queue_work(hdev->req_workqueue, &hdev->power_off.work); - } -} - void mgmt_advertising_added(struct sock *sk, struct hci_dev *hdev, u8 instance) { struct mgmt_ev_advertising_added ev; @@ -1159,40 +1149,6 @@ static void cancel_adv_timeout(struct hci_dev *hdev) } } -static int clean_up_hci_state(struct hci_dev *hdev) -{ - struct hci_request req; - struct hci_conn *conn; - bool discov_stopped; - int err; - - hci_req_init(&req, hdev); - - if (test_bit(HCI_ISCAN, &hdev->flags) || - test_bit(HCI_PSCAN, &hdev->flags)) { - u8 scan = 0x00; - hci_req_add(&req, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan); - } - - hci_req_clear_adv_instance(hdev, NULL, NULL, 0x00, false); - - if (hci_dev_test_flag(hdev, HCI_LE_ADV)) - __hci_req_disable_advertising(&req); - - discov_stopped = hci_req_stop_discovery(&req); - - list_for_each_entry(conn, &hdev->conn_hash.list, list) { - /* 0x15 == Terminated due to Power Off */ - __hci_abort_conn(&req, conn, 0x15); - } - - err = hci_req_run(&req, clean_up_hci_complete); - if (!err && discov_stopped) - hci_discovery_set_state(hdev, DISCOVERY_STOPPING); - - return err; -} - static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) { @@ -1230,7 +1186,7 @@ static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data, err = 0; } else { /* Disconnect connections, stop scans, etc */ - err = clean_up_hci_state(hdev); + err = hci_clean_up_state(hdev); if (!err) queue_delayed_work(hdev->req_workqueue, &hdev->power_off, HCI_POWER_OFF_TIMEOUT); -- 2.29.2.299.gdc1121823c-goog