Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions drivers/net/wireless/apple/centauri/t6050/centauri_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ struct centauri_t6050_rewake {
size_t arena_size;
bool beta_lease;
bool beta_fallback;
/* The host's reset of the last wake already went to an enumeration. */
bool host_reset_used;
};

static LIST_HEAD(cen_recovery_owners);
Expand Down Expand Up @@ -95,6 +97,13 @@ static struct centauri_t6050_rewake *centauri_t6050_owner_get(struct pci_dev *fn
INIT_DELAYED_WORK(&rw->fault_work, centauri_t6050_fault_worker);
rw->bridge = pci_dev_get(fn->bus->self);
rw->slot = PCI_SLOT(fn->devfn);
/*
* A new owner (first probe, or a module reload in the middle of a
* wake) cannot know whether this wake's host warm reset was already
* used: take it as used, so the next recovery cycles the port. The
* suspend-prepare notifier clears it for the first sleep it sees.
*/
rw->host_reset_used = true;
list_add_tail(&rw->node, &cen_recovery_owners);
kref_get(&rw->ref);
return rw;
Expand Down Expand Up @@ -1014,7 +1023,7 @@ static void centauri_t6050_rewake_worker(struct work_struct *work)
ktime_t begin, start, up_at;
unsigned int sleep_flags;
u16 lnksta = 0, first = 0;
bool force_recycle, need_recycle, smc_locked = false, exiting;
bool force_recycle, reset_used, need_recycle, smc_locked = false, exiting;
int i, ret;

sleep_flags = lock_system_sleep();
Expand All @@ -1039,8 +1048,14 @@ static void centauri_t6050_rewake_worker(struct work_struct *work)
goto unlock;
mutex_lock(&cen_recovery_lock);
force_recycle = rw->force_recycle;
reset_used = rw->host_reset_used;
mutex_unlock(&cen_recovery_lock);
need_recycle = force_recycle || !apple_pcie_t6050_warm_reset_done(bridge);
/*
* The host's flag stays set until the next suspend: once a new enumeration has run on
* this wake's reset (or a port cycle since), a later recovery needs its own reset.
*/
need_recycle = force_recycle || reset_used ||
!apple_pcie_t6050_warm_reset_done(bridge);
if (need_recycle) {
smc_locked = apple_pcie_t6050_recycle_lock(bridge);
if (!smc_locked) {
Expand All @@ -1066,6 +1081,7 @@ static void centauri_t6050_rewake_worker(struct work_struct *work)
rw->teardown_active = false;
rw->force_recycle = false;
rw->fault_only = false;
rw->host_reset_used = true;
mutex_unlock(&cen_recovery_lock);
/*
* The host resets the N1 in its noirq resume, while the port is still down. A reset given
Expand Down Expand Up @@ -1679,6 +1695,24 @@ static struct notifier_block cen_reboot_nb = {
.notifier_call = centauri_t6050_reboot_notify,
};

/* The host clears its warm-reset flag here too; the next wake's reset is unused. */
static int centauri_t6050_pm_notify(struct notifier_block *nb,
unsigned long action, void *data)
{
struct centauri_t6050_rewake *rw;

if (action != PM_SUSPEND_PREPARE)
return NOTIFY_DONE;
guard(mutex)(&cen_recovery_lock);
list_for_each_entry(rw, &cen_recovery_owners, node)
rw->host_reset_used = false;
return NOTIFY_DONE;
}

static struct notifier_block cen_pm_nb = {
.notifier_call = centauri_t6050_pm_notify,
};

static const struct dev_pm_ops centauri_t6050_pm_ops = {
.prepare = centauri_t6050_prepare,
.complete = centauri_t6050_complete,
Expand Down Expand Up @@ -1720,8 +1754,15 @@ static int __init centauri_t6050_init(void)
destroy_workqueue(cen_rewake_wq);
return ret;
}
ret = register_pm_notifier(&cen_pm_nb);
if (ret) {
unregister_reboot_notifier(&cen_reboot_nb);
destroy_workqueue(cen_rewake_wq);
return ret;
}
ret = pci_register_driver(&centauri_t6050_driver);
if (ret) {
unregister_pm_notifier(&cen_pm_nb);
unregister_reboot_notifier(&cen_reboot_nb);
destroy_workqueue(cen_rewake_wq);
}
Expand All @@ -1733,6 +1774,7 @@ static void __exit centauri_t6050_exit(void)
{
struct centauri_t6050_rewake *rw, *next;

unregister_pm_notifier(&cen_pm_nb);
unregister_reboot_notifier(&cen_reboot_nb);
/* Drain before unregister: no worker can race callback data destruction. */
centauri_t6050_stop_recovery();
Expand Down
Loading
Loading