Skip to content
Merged
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
24 changes: 20 additions & 4 deletions drivers/bluetooth/btcentauri_t6050.c
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,8 @@ static int cen_request_irqs(struct cen_bt *bt)
return 0;
}

static int cen_transport_state(struct cen_bt *bt, bool asleep);

/*
* Called with the participant device locked, outside Control's boot_lock. Keep
* the transport alive through HCI unregister: its close may send final commands.
Expand All @@ -824,11 +826,23 @@ static int cen_request_irqs(struct cen_bt *bt)
static int cen_quiesce(void *data)
{
struct cen_bt *bt = data;
int wake_ret = 0;

if (bt->host_quiesced)
return 0;
if (bt->transport_sleep_sent) {
bt->transport_sleep_sent = false;
wake_ret = cen_transport_state(bt, false);
if (wake_ret)
dev_warn(&bt->pdev->dev,
"Beta ACIPC host wake failed during teardown (%d)\n",
wake_ret);
}
mutex_lock(&bt->lock);
bt->quiescing = true;
if (wake_ret)
bt->running = false;
WRITE_ONCE(bt->transport_paused, false);
mutex_unlock(&bt->lock);
if (bt->hci_registered) {
hci_unregister_dev(bt->hdev);
Expand Down Expand Up @@ -1153,9 +1167,11 @@ static int cen_suspend_noirq(struct device *dev)
if (!bt->transport_sleep_sent || !pm_suspend_via_firmware() || !pdev->pm_cap)
return 0;
if (!pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &pmctrl)) {
pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL,
(pmctrl & ~PCI_PM_CTRL_STATE_MASK) |
PCI_D3hot | PCI_PM_CTRL_PME_ENABLE);
pmctrl &= ~(PCI_PM_CTRL_STATE_MASK | PCI_PM_CTRL_PME_ENABLE);
pmctrl |= (__force u16)PCI_D3hot;
if (device_may_wakeup(dev) && READ_ONCE(bt->running))
pmctrl |= PCI_PM_CTRL_PME_ENABLE;
pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, pmctrl);
mdelay(pdev->d3hot_delay);
}
return 0;
Expand All @@ -1181,7 +1197,7 @@ static int cen_resume_noirq(struct device *dev)
}
if (pdev->pm_cap &&
!pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &pmctrl) &&
(pmctrl & PCI_PM_CTRL_STATE_MASK) != PCI_D0) {
(pmctrl & PCI_PM_CTRL_STATE_MASK) != (__force u16)PCI_D0) {
pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL,
pmctrl & ~PCI_PM_CTRL_STATE_MASK);
mdelay(pdev->d3hot_delay);
Expand Down
76 changes: 62 additions & 14 deletions drivers/net/wireless/apple/centauri/t6050/centauri_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -599,10 +599,10 @@ static void centauri_t6050_remove(struct pci_dev *pdev)
}

/*
* On a healthy firmware sleep, Beta (fn 2), Alpha (fn 1), and Control (fn 0) enter ACIPC
* host-sleep, save PCI config state, enter D3hot with PME_En, and ask pcie-apple to skip
* the wake warm reset so the N1 firmware, Bluetooth, and (when armed) Wi-Fi association
* survive across PERST#.
* On a healthy firmware sleep (WoWLAN-armed or unassociated), Beta (fn 2), Alpha (fn 1),
* and Control (fn 0) enter ACIPC host-sleep, save PCI config state, enter D3hot (with
* PME_En only when wake is armed), and ask pcie-apple to skip the wake warm reset so the
* N1 firmware, Bluetooth, and (when armed) Wi-Fi association survive across PERST#.
*
* If any function fails host-sleep or wake, or firmware is unhealthy, the driver falls back
* to teardown and warm-reset recovery:
Expand Down Expand Up @@ -764,8 +764,22 @@ static bool centauri_t6050_domain_fence(struct centauri_t6050_rewake *rw)
pci_clear_master(fn[i]);
}
for (i = 0; i < 3; i++) {
if (fn[i] && !centauri_t6050_stop_dma(fn[i]))
bool fn_stopped = !fn[i] || centauri_t6050_stop_dma(fn[i]);

if (!fn_stopped)
stopped = false;
/*
* Refresh any keep-alive PCI state saved before Control fell
* back to teardown so an aborted suspend cannot restore Bus
* Master or the old header onto a quiesced function whose DMA
* arena was freed. Never save an unreadable/gone function
* (which would snapshot 0xffff); clearing state_saved hands
* suspend_noirq state save and power-state selection back to
* the PCI core.
*/
if (fn[i] && i > 0 && fn[i]->state_saved &&
(!fn_stopped || pci_save_state(fn[i])))
fn[i]->state_saved = false;
pci_dev_put(fn[i]);
}
return stopped;
Expand Down Expand Up @@ -1022,16 +1036,18 @@ void apple_centauri_sleep_mark_fallback(struct pci_dev *fn)
}
EXPORT_SYMBOL_GPL(apple_centauri_sleep_mark_fallback);

static void centauri_t6050_set_d3hot(struct pci_dev *pdev)
static void centauri_t6050_set_d3hot(struct pci_dev *pdev, bool pme_enable)
{
u16 pmctrl;

if (!pdev || !pdev->pm_cap)
return;
if (!pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &pmctrl)) {
pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL,
(pmctrl & ~PCI_PM_CTRL_STATE_MASK) |
(__force u16)PCI_D3hot | PCI_PM_CTRL_PME_ENABLE);
pmctrl &= ~(PCI_PM_CTRL_STATE_MASK | PCI_PM_CTRL_PME_ENABLE);
pmctrl |= (__force u16)PCI_D3hot;
if (pme_enable)
pmctrl |= PCI_PM_CTRL_PME_ENABLE;
pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, pmctrl);
mdelay(pdev->d3hot_delay);
}
}
Expand Down Expand Up @@ -1128,19 +1144,26 @@ static int centauri_t6050_suspend(struct device *dev)

c->firmware_kept = false;
c->control_sleep_sent = false;
c->keep_alive_pme = false;
if (!beta_fallback && c->boot_phase == CEN_BOOT_READY && c->ipc && c->wifi &&
!centauri_t6050_wifi_pm_error(c) &&
!centauri_t6050_wifi_pm_disconnected(c) &&
readl(c->bar + 0x8000) == 2 && readl(c->bar + 0x8050) == 2) {
bool wifi_sleep_sent = false;
int unwind_err = 0, wake_ret;
u32 id0 = 0, id1 = 0;

fn1 = centauri_t6050_ipc_alpha_dev(c);
if (!fn1 || pci_read_config_dword(pdev, PCI_VENDOR_ID, &id0) ||
pci_read_config_dword(fn1, PCI_VENDOR_ID, &id1) ||
(id0 & 0xffff) != pdev->vendor || (id1 & 0xffff) != fn1->vendor ||
id0 == ~0U || id1 == ~0U)
id0 == ~0U || id1 == ~0U) {
ret = -ENODEV;
else
} else {
ret = centauri_t6050_wifi_suspend(c);
if (!ret)
wifi_sleep_sent = true;
}
if (!ret) {
ret = centauri_t6050_ipc_control_sleep(c, true);
if (!ret)
Expand All @@ -1156,13 +1179,38 @@ static int centauri_t6050_suspend(struct device *dev)
centauri_t6050_save_memswap(pdev, c->saved_memswap[0]);
centauri_t6050_save_memswap(fn1, c->saved_memswap[1]);
apple_pcie_t6050_sleep_keep_alive(pdev->bus->self);
c->keep_alive_pme = centauri_t6050_wifi_wowlan_armed(c);
c->firmware_kept = true;
dev_dbg(dev, "N1 kept alive for firmware sleep\n");
return 0;
}
dev_warn(dev, "N1 keep-alive suspend failed (%d); falling back to warm-reset sleep\n",
ret);
c->control_sleep_sent = false;
if (c->control_sleep_sent) {
wake_ret = centauri_t6050_ipc_control_sleep(c, false);
if (wake_ret) {
dev_warn(dev,
"Control ACIPC host wake failed during fallback (%d)\n",
wake_ret);
unwind_err = wake_ret;
}
c->control_sleep_sent = false;
}
if (wifi_sleep_sent) {
wake_ret = centauri_t6050_wifi_resume(c);
if (wake_ret) {
dev_warn(dev,
"Alpha host wake failed during fallback (%d)\n",
wake_ret);
if (!unwind_err)
unwind_err = wake_ret;
}
}
if (unwind_err) {
centauri_t6050_wifi_mark_failed(c);
/* Also covers an aborted suspend where resume/rewake may not run. */
apple_centauri_sleep_recovery_needed(pdev, unwind_err);
}
}

ret = centauri_t6050_quiesce(c);
Expand All @@ -1189,8 +1237,8 @@ static int centauri_t6050_suspend_noirq(struct device *dev)
if (!c->firmware_kept || !pm_suspend_via_firmware())
return 0;
fn1 = centauri_t6050_ipc_alpha_dev(c);
centauri_t6050_set_d3hot(fn1);
centauri_t6050_set_d3hot(pdev);
centauri_t6050_set_d3hot(fn1, c->keep_alive_pme);
centauri_t6050_set_d3hot(pdev, c->keep_alive_pme);
return 0;
}

Expand Down
18 changes: 18 additions & 0 deletions drivers/net/wireless/apple/centauri/t6050/centauri_t6050.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct centauri_t6050 {
/* Kept alive across a firmware sleep via ACIPC host-sleep */
bool firmware_kept;
bool control_sleep_sent;
bool keep_alive_pme;
u32 saved_pci_id[2];
u32 saved_memswap[2][3];
struct centauri_t6050_ipc *ipc;
Expand All @@ -88,6 +89,9 @@ int centauri_t6050_wifi_register(struct centauri_t6050 *c);
void centauri_t6050_wifi_unregister(struct centauri_t6050 *c);
void centauri_t6050_wifi_pm_prepare(struct centauri_t6050 *c);
int centauri_t6050_wifi_pm_error(struct centauri_t6050 *c);
bool centauri_t6050_wifi_pm_disconnected(struct centauri_t6050 *c);
bool centauri_t6050_wifi_wowlan_armed(struct centauri_t6050 *c);
void centauri_t6050_wifi_mark_failed(struct centauri_t6050 *c);
void centauri_t6050_wifi_pm_complete(struct centauri_t6050 *c);
int centauri_t6050_wifi_suspend(struct centauri_t6050 *c);
int centauri_t6050_wifi_resume(struct centauri_t6050 *c);
Expand All @@ -113,6 +117,20 @@ static inline int centauri_t6050_wifi_pm_error(struct centauri_t6050 *c)
return 0;
}

static inline bool centauri_t6050_wifi_pm_disconnected(struct centauri_t6050 *c)
{
return false;
}

static inline bool centauri_t6050_wifi_wowlan_armed(struct centauri_t6050 *c)
{
return false;
}

static inline void centauri_t6050_wifi_mark_failed(struct centauri_t6050 *c)
{
}

static inline void centauri_t6050_wifi_pm_complete(struct centauri_t6050 *c)
{
}
Expand Down
Loading
Loading