Skip to content

Commit

Permalink
vhci: delayed resume
Browse files Browse the repository at this point in the history
should show up in /sys/kernel/debug/apple-bce-vhci/finish_resume. After
you suspend and resume, do

echo foo | sudo tee /sys/kernel/debug/apple-bce-vhci/finish_resume

and it should then finish resuming vhci.

Hopefully this means it will be easy to have a terminal open and watch
logs.
  • Loading branch information
Redecorating committed Nov 24, 2023
1 parent 27ca725 commit 642a270
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
39 changes: 29 additions & 10 deletions vhci/vhci.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <linux/module.h>
#include <linux/version.h>
#include <linux/delay.h>
#include <linux/debugfs.h>

static dev_t bce_vhci_chrdev;
static struct class *bce_vhci_class;
Expand All @@ -23,6 +24,22 @@ static void bce_vhci_firmware_event_completion(struct bce_queue_sq *sq);
static int bce_vhci_bus_suspend(struct usb_hcd *hcd);
static int bce_vhci_bus_resume(struct usb_hcd *hcd);

static ssize_t vhci_finish_resume_write(struct file *file,
const char __user *userbuf, size_t count, loff_t *ppos)
{
struct bce_vhci *vhci = file->private_data;
int status;
status = bce_vhci_bus_resume(vhci->hcd);
if (status)
return status;
return count;
}

static const struct file_operations vhci_finish_resume_ops = {
.open = simple_open,
.write = vhci_finish_resume_write,
};

int bce_vhci_create(struct auxiliary_device *aux_dev, const struct auxiliary_device_id *id)
{
struct bce_vhci *vhci = NULL;
Expand Down Expand Up @@ -77,14 +94,10 @@ int bce_vhci_create(struct auxiliary_device *aux_dev, const struct auxiliary_dev

global_vhci = vhci;

pr_warn("bce_vhci: init finished. Doing test suspend and resume cycle now.\n");
msleep(800);
status = bce_vhci_bus_suspend(vhci->hcd);
pr_warn("bce_vhci: suspended (%d). Waiting three seconds till resume...\n",status);
msleep(3000);
status = bce_vhci_bus_resume(vhci->hcd);
pr_warn("bce_vhci: resume finished (%d).\n", status);
msleep(800);
vhci->debug_dentry = debugfs_create_dir(KBUILD_MODNAME, NULL);
debugfs_create_file("finish_resume", 0644, vhci->debug_dentry,
vhci, &vhci_finish_resume_ops);


return 0;

Expand All @@ -104,11 +117,12 @@ int bce_vhci_create(struct auxiliary_device *aux_dev, const struct auxiliary_dev

void bce_vhci_destroy(struct auxiliary_device *aux_dev)
{
struct bce_vhci *vhci = auxiliary_get_drvdata(aux_dev);
struct bce_vhci *vhci = auxiliary_get_drvdata(aux_dev);
usb_remove_hcd(vhci->hcd);
bce_vhci_destroy_event_queues(vhci);
bce_vhci_destroy_message_queues(vhci);
device_destroy(bce_vhci_class, vhci->vdevt);
debugfs_remove_recursive(vhci->debug_dentry);
}

struct bce_vhci *bce_vhci_from_hcd(struct usb_hcd *hcd)
Expand Down Expand Up @@ -397,6 +411,11 @@ static int bce_vhci_bus_suspend(struct usb_hcd *hcd)
return 0;
}

static int bce_vhci_bus_resume_dummy(struct usb_hcd *hcd)
{
return -EINVAL;
}

static int bce_vhci_bus_resume(struct usb_hcd *hcd)
{
int i, j;
Expand Down Expand Up @@ -769,7 +788,7 @@ static const struct hc_driver bce_vhci_driver = {
.check_bandwidth = bce_vhci_check_bandwidth,
.get_frame_number = bce_vhci_get_frame_number,
.bus_suspend = bce_vhci_bus_suspend,
.bus_resume = bce_vhci_bus_resume
.bus_resume = bce_vhci_bus_resume_dummy
};

static const struct auxiliary_device_id apple_bridge_vhci_ids[] = {
Expand Down
3 changes: 3 additions & 0 deletions vhci/vhci.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "queue.h"
#include "transfer.h"
#include <linux/debugfs.h>

struct usb_hcd;
struct bce_queue_cq;
Expand Down Expand Up @@ -46,6 +47,8 @@ struct bce_vhci {
struct bce_vhci_device *devices[16];
struct workqueue_struct *tq_state_wq;
struct work_struct w_fw_events;

struct dentry *debug_dentry;
};

#endif //BCE_VHCI_H

1 comment on commit 642a270

@aboulfad
Copy link

@aboulfad aboulfad commented on 642a270 Dec 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/sys/kernel/debug/apple_bce_vhci/finish_resume not /sys/kernel/debug/apple-bce-vhci/finish_resume ;-)

Please sign in to comment.