diff mbox series

[v2,3/3] Bluetooth: hci_vhci: Add force_prevent_wake entry

Message ID 20210928213653.3028439-3-luiz.dentz@gmail.com (mailing list archive)
State Accepted
Delegated to: Marcel Holtmann
Headers show
Series [v2,1/3] Bluetooth: Make use of hci_{suspend,resume}_dev on suspend notifier | expand

Checks

Context Check Description
tedd_an/checkpatch success Checkpatch PASS
tedd_an/gitlint success Gitlint PASS

Commit Message

Luiz Augusto von Dentz Sept. 28, 2021, 9:36 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds force_prevent_wake which can be used to force a certain state
while interacting with force_suspend.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
 drivers/bluetooth/hci_vhci.c | 48 ++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

Comments

Marcel Holtmann Sept. 29, 2021, 1:53 p.m. UTC | #1
Hi Luiz,

> This adds force_prevent_wake which can be used to force a certain state
> while interacting with force_suspend.
> 
> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> ---
> drivers/bluetooth/hci_vhci.c | 48 ++++++++++++++++++++++++++++++++++++
> 1 file changed, 48 insertions(+)
> 
> diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
> index 52f9106faeae..60a408a49828 100644
> --- a/drivers/bluetooth/hci_vhci.c
> +++ b/drivers/bluetooth/hci_vhci.c
> @@ -137,6 +137,51 @@ static const struct file_operations force_suspend_fops = {
> 	.llseek		= default_llseek,
> };
> 
> +static bool prevent_wake;

this needs to be in vhci_data since it should be per vhci.

> +
> +static ssize_t force_prevent_wake_read(struct file *file, char __user *user_buf,
> +				       size_t count, loff_t *ppos)
> +{
> +	char buf[3];
> +
> +	buf[0] = prevent_wake ? 'Y' : 'N';
> +	buf[1] = '\n';
> +	buf[2] = '\0';
> +	return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
> +}
> +
> +static bool hci_debugfs_prevent_wake(struct hci_dev *hdev)
> +{
> +	return prevent_wake;
> +}

The hci_debugfs prefix here is rather misleading. This is vhci_prevent_wake actually. And just move it to a more closer position with all the other hdev-> callbacks.

> +
> +static ssize_t force_prevent_wake_write(struct file *file,
> +					const char __user *user_buf,
> +					size_t count, loff_t *ppos)
> +{
> +	struct hci_dev *hdev = file->private_data;
> +	bool enable;
> +	int err;
> +
> +	err = kstrtobool_from_user(user_buf, count, &enable);
> +	if (err)
> +		return err;
> +
> +	if (prevent_wake == enable)
> +		return -EALREADY;
> +
> +	hdev->prevent_wake = hci_debugfs_prevent_wake;

You need to set these with the other hdev-> callback and not in debugfs callback.

> +
> +	return count;
> +}
> +
> +static const struct file_operations force_prevent_wake_fops = {
> +	.open		= simple_open,
> +	.read		= force_prevent_wake_read,
> +	.write		= force_prevent_wake_write,
> +	.llseek		= default_llseek,
> +};
> +
> static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
> {
> 	struct hci_dev *hdev;
> @@ -198,6 +243,9 @@ static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
> 	debugfs_create_file("force_suspend", 0644, hdev->debugfs, hdev,
> 			    &force_suspend_fops);
> 
> +	debugfs_create_file("force_prevent_wake", 0644, hdev->debugfs, hdev,
> +			    &force_prevent_wake_fops);
> +

Regards

Marcel
Luiz Augusto von Dentz Sept. 29, 2021, 6:07 p.m. UTC | #2
Hi Marcel,

On Wed, Sep 29, 2021 at 6:53 AM Marcel Holtmann <marcel@holtmann.org> wrote:
>
> Hi Luiz,
>
> > This adds force_prevent_wake which can be used to force a certain state
> > while interacting with force_suspend.
> >
> > Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> > ---
> > drivers/bluetooth/hci_vhci.c | 48 ++++++++++++++++++++++++++++++++++++
> > 1 file changed, 48 insertions(+)
> >
> > diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
> > index 52f9106faeae..60a408a49828 100644
> > --- a/drivers/bluetooth/hci_vhci.c
> > +++ b/drivers/bluetooth/hci_vhci.c
> > @@ -137,6 +137,51 @@ static const struct file_operations force_suspend_fops = {
> >       .llseek         = default_llseek,
> > };
> >
> > +static bool prevent_wake;
>
> this needs to be in vhci_data since it should be per vhci.

Ack.

> > +
> > +static ssize_t force_prevent_wake_read(struct file *file, char __user *user_buf,
> > +                                    size_t count, loff_t *ppos)
> > +{
> > +     char buf[3];
> > +
> > +     buf[0] = prevent_wake ? 'Y' : 'N';
> > +     buf[1] = '\n';
> > +     buf[2] = '\0';
> > +     return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
> > +}
> > +
> > +static bool hci_debugfs_prevent_wake(struct hci_dev *hdev)
> > +{
> > +     return prevent_wake;
> > +}
>
> The hci_debugfs prefix here is rather misleading. This is vhci_prevent_wake actually. And just move it to a more closer position with all the other hdev-> callbacks.

Ack.

> > +
> > +static ssize_t force_prevent_wake_write(struct file *file,
> > +                                     const char __user *user_buf,
> > +                                     size_t count, loff_t *ppos)
> > +{
> > +     struct hci_dev *hdev = file->private_data;
> > +     bool enable;
> > +     int err;
> > +
> > +     err = kstrtobool_from_user(user_buf, count, &enable);
> > +     if (err)
> > +             return err;
> > +
> > +     if (prevent_wake == enable)
> > +             return -EALREADY;
> > +
> > +     hdev->prevent_wake = hci_debugfs_prevent_wake;
>
> You need to set these with the other hdev-> callback and not in debugfs callback.

Will do and also change its naming as well.

> > +
> > +     return count;
> > +}
> > +
> > +static const struct file_operations force_prevent_wake_fops = {
> > +     .open           = simple_open,
> > +     .read           = force_prevent_wake_read,
> > +     .write          = force_prevent_wake_write,
> > +     .llseek         = default_llseek,
> > +};
> > +
> > static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
> > {
> >       struct hci_dev *hdev;
> > @@ -198,6 +243,9 @@ static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
> >       debugfs_create_file("force_suspend", 0644, hdev->debugfs, hdev,
> >                           &force_suspend_fops);
> >
> > +     debugfs_create_file("force_prevent_wake", 0644, hdev->debugfs, hdev,
> > +                         &force_prevent_wake_fops);
> > +
>
> Regards
>
> Marcel
>
diff mbox series

Patch

diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
index 52f9106faeae..60a408a49828 100644
--- a/drivers/bluetooth/hci_vhci.c
+++ b/drivers/bluetooth/hci_vhci.c
@@ -137,6 +137,51 @@  static const struct file_operations force_suspend_fops = {
 	.llseek		= default_llseek,
 };
 
+static bool prevent_wake;
+
+static ssize_t force_prevent_wake_read(struct file *file, char __user *user_buf,
+				       size_t count, loff_t *ppos)
+{
+	char buf[3];
+
+	buf[0] = prevent_wake ? 'Y' : 'N';
+	buf[1] = '\n';
+	buf[2] = '\0';
+	return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
+}
+
+static bool hci_debugfs_prevent_wake(struct hci_dev *hdev)
+{
+	return prevent_wake;
+}
+
+static ssize_t force_prevent_wake_write(struct file *file,
+					const char __user *user_buf,
+					size_t count, loff_t *ppos)
+{
+	struct hci_dev *hdev = file->private_data;
+	bool enable;
+	int err;
+
+	err = kstrtobool_from_user(user_buf, count, &enable);
+	if (err)
+		return err;
+
+	if (prevent_wake == enable)
+		return -EALREADY;
+
+	hdev->prevent_wake = hci_debugfs_prevent_wake;
+
+	return count;
+}
+
+static const struct file_operations force_prevent_wake_fops = {
+	.open		= simple_open,
+	.read		= force_prevent_wake_read,
+	.write		= force_prevent_wake_write,
+	.llseek		= default_llseek,
+};
+
 static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
 {
 	struct hci_dev *hdev;
@@ -198,6 +243,9 @@  static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
 	debugfs_create_file("force_suspend", 0644, hdev->debugfs, hdev,
 			    &force_suspend_fops);
 
+	debugfs_create_file("force_prevent_wake", 0644, hdev->debugfs, hdev,
+			    &force_prevent_wake_fops);
+
 	hci_skb_pkt_type(skb) = HCI_VENDOR_PKT;
 
 	skb_put_u8(skb, 0xff);