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
90 changes: 78 additions & 12 deletions drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
Original file line number Diff line number Diff line change
Expand Up @@ -1263,21 +1263,46 @@ static void brcmf_pcie_bus_console_read(struct brcmf_pciedev_info *devinfo,
}


static void brcmf_pcie_intr_unmask(struct brcmf_pciedev_info *devinfo)
{
brcmf_pcie_write_pcie32(devinfo, devinfo->reginfo->mailboxmask,
devinfo->reginfo->int_d2h_db |
devinfo->reginfo->int_fn0);
}

/*
* The threaded handler services the rings and unmasks the dongle only while
* irq_ready is set. Clear it before masking, so a thread that sees it clear
* does neither.
*/
static void brcmf_pcie_intr_disable(struct brcmf_pciedev_info *devinfo)
{
WRITE_ONCE(devinfo->irq_ready, false);
brcmf_pcie_write_pcie32(devinfo, devinfo->reginfo->mailboxmask, 0);

devinfo->irq_ready = false;
}


/*
* Set irq_ready before unmasking: an interrupt raised as soon as the mask
* opens must find it set, or its thread would leave the dongle masked. The
* MMIO write orders the store before the unmask.
*/
static void brcmf_pcie_intr_enable(struct brcmf_pciedev_info *devinfo)
{
brcmf_pcie_write_pcie32(devinfo, devinfo->reginfo->mailboxmask,
devinfo->reginfo->int_d2h_db |
devinfo->reginfo->int_fn0);
WRITE_ONCE(devinfo->irq_ready, true);
brcmf_pcie_intr_unmask(devinfo);
}

devinfo->irq_ready = true;
/*
* Stop ring servicing and wait for a handler already running. A thread that
* read irq_ready before it was cleared can still have unmasked the dongle, so
* mask it again once the handlers are done.
*/
static void brcmf_pcie_intr_quiesce(struct brcmf_pciedev_info *devinfo)
{
brcmf_pcie_intr_disable(devinfo);
if (devinfo->irq_allocated)
synchronize_irq(devinfo->pdev->irq);
brcmf_pcie_write_pcie32(devinfo, devinfo->reginfo->mailboxmask, 0);
}

static void brcmf_pcie_hostready(struct brcmf_pciedev_info *devinfo)
Expand All @@ -1295,7 +1320,10 @@ static irqreturn_t brcmf_pcie_quick_check_isr(int irq, void *arg)
struct brcmf_pciedev_info *devinfo = (struct brcmf_pciedev_info *)arg;

if (brcmf_pcie_read_pcie32(devinfo, devinfo->reginfo->mailboxint)) {
brcmf_pcie_intr_disable(devinfo);
/* Mask the dongle only: irq_ready gates ring servicing while the
* rings are not set up or are being torn down, not this IRQ.
*/
brcmf_pcie_write_pcie32(devinfo, devinfo->reginfo->mailboxmask, 0);
brcmf_dbg(PCIE, "Enter\n");
return IRQ_WAKE_THREAD;
}
Expand Down Expand Up @@ -1330,13 +1358,17 @@ static irqreturn_t brcmf_pcie_isr_thread(int irq, void *arg)
brcmf_pcie_poll_mb_data(devinfo);
}
if (devinfo->have_msi || status & devinfo->reginfo->int_d2h_db) {
if (devinfo->state == BRCMFMAC_PCIE_STATE_UP && devinfo->irq_ready)
if (devinfo->state == BRCMFMAC_PCIE_STATE_UP &&
READ_ONCE(devinfo->irq_ready))
brcmf_proto_msgbuf_rx_trigger(&devinfo->pdev->dev);
}

brcmf_pcie_bus_console_read(devinfo, false);
if (devinfo->state == BRCMFMAC_PCIE_STATE_UP)
brcmf_pcie_intr_enable(devinfo);
/* Unmask, but leave irq_ready to the code that sets the rings up and
* tears them down.
*/
if (devinfo->state == BRCMFMAC_PCIE_STATE_UP && READ_ONCE(devinfo->irq_ready))
brcmf_pcie_intr_unmask(devinfo);
devinfo->in_irq = false;
return IRQ_HANDLED;
}
Expand Down Expand Up @@ -3467,10 +3499,22 @@ static void brcmf_pcie_wowl_wake(struct brcmf_bus *bus,
struct brcmf_pciedev_info *devinfo)
{
devinfo->wowl_sleeping = false;
/*
* Ring servicing stopped at the sleep. Turn it back on, with the mask
* set explicitly rather than left to whichever interrupt comes next,
* before the bus is up and TX queues wake.
*/
brcmf_pcie_intr_enable(devinfo);
brcmf_bus_change_state(bus, BRCMF_BUS_UP);
brcmf_msgbuf_resume(bus->drvr);
brcmf_pcie_fwcon_timer(devinfo, true);
/*
* Completions posted while the dongle was masked may have no interrupt
* of their own (in MSI mode the firmware clears mailboxint itself), so
* run the thread once.
*/
if (devinfo->irq_allocated)
irq_wake_thread(devinfo->pdev->irq, devinfo);
}

/*
Expand All @@ -3495,12 +3539,21 @@ static int brcmf_pcie_wowl_sleep(struct device *dev)
}
devinfo->irq_wake_enabled = true;

/*
* No ring servicing until the wake. A matched frame must still raise
* the MSI, so unmask the dongle again with irq_ready clear: its thread
* reports the wakeup and leaves the dongle masked. wowl_sleeping is set
* first so that interrupt is never taken for an ordinary one.
*/
brcmf_pcie_intr_quiesce(devinfo);
devinfo->wowl_sleeping = true;
brcmf_pcie_intr_unmask(devinfo);

ret = pci_save_state(devinfo->pdev);
if (ret) {
brcmf_pcie_disable_irq_wake(devinfo);
goto fail;
}
devinfo->wowl_sleeping = true;
return 0;

fail:
Expand All @@ -3526,8 +3579,12 @@ static int brcmf_pcie_s2idle_sleep(struct device *dev)
struct brcmf_pciedev_info *devinfo = bus->bus_priv.pcie->devinfo;
int ret;

/* Nothing touches the rings until brcmf_pcie_wowl_wake() at resume. */
brcmf_pcie_intr_quiesce(devinfo);

ret = pci_save_state(devinfo->pdev);
if (ret) {
brcmf_pcie_intr_enable(devinfo);
brcmf_bus_change_state(bus, BRCMF_BUS_UP);
brcmf_msgbuf_resume(bus->drvr);
brcmf_pcie_fwcon_timer(devinfo, true);
Expand Down Expand Up @@ -3625,16 +3682,25 @@ static int brcmf_pcie_pm_leave_D3(struct device *dev)
devinfo = bus->bus_priv.pcie->devinfo;
brcmf_dbg(PCIE, "Enter, dev=%p, bus=%p\n", dev, bus);

/*
* In both sleeps the function and its link stayed in D0. Keep the
* handlers off the device while pci_restore_state() rewrites its config
* space, ASPM/L1SS and MSI state.
*/
if (devinfo->wowl_sleeping) {
disable_irq(devinfo->pdev->irq);
pci_restore_state(devinfo->pdev);
enable_irq(devinfo->pdev->irq);
brcmf_pcie_disable_irq_wake(devinfo);
brcmf_pcie_wowl_wake(bus, devinfo);
return 0;
}

if (devinfo->s2idle_d0) {
devinfo->s2idle_d0 = false;
disable_irq(devinfo->pdev->irq);
pci_restore_state(devinfo->pdev);
enable_irq(devinfo->pdev->irq);
brcmf_pcie_wowl_wake(bus, devinfo);
return 0;
}
Expand Down
40 changes: 33 additions & 7 deletions tools/asahi/brcmf-suspend-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def function(source, name):
struct pci_dev { struct device dev; int irq; bool state_saved; };
struct brcmf_pciedev_info { bool mbdata_completed, intr, ready, timer, sleep_reset_blocked, setup_complete;
bool wowl_irq, wowl_enabled, irq_wake_enabled, wowl_sleeping, fwseed, s2idle_d0;
bool irq_allocated, unmasked;
int state, mbdata_resp_wait; void *ci; struct pci_dev *pdev;
struct { int intmask, mailboxmask; } *reginfo; };
struct pcie_priv { struct brcmf_pciedev_info *devinfo; };
Expand Down Expand Up @@ -161,7 +162,12 @@ def function(source, name):
static int wake_error, save_error; static unsigned d3_informs, d0_informs;
static int enable_irq_wake(int irq) {(void)irq;return wake_error;}
static int pci_save_state(struct pci_dev *p) {if(save_error)return save_error;p->state_saved=true;return 0;}
static void pci_restore_state(struct pci_dev *p) {p->state_saved=false;}
static int irq_depth; static unsigned kicks;
static void disable_irq(int irq) {(void)irq;irq_depth++;}
static void enable_irq(int irq) {(void)irq;assert(irq_depth>0);irq_depth--;}
static void irq_wake_thread(int irq,void *id) {(void)irq;(void)id;kicks++;}
/* The function stayed in D0 with its link up: no handler may run during the restore. */
static void pci_restore_state(struct pci_dev *p) {assert(irq_depth==1);p->state_saved=false;}
static void brcmf_pcie_disable_irq_wake(struct brcmf_pciedev_info *d) {d->irq_wake_enabled=false;}
static int brcmf_pcie_pm_leave_D3(struct device *dev);
static int brcmf_pcie_send_mb_data(struct brcmf_pciedev_info *d,int mb) {
Expand All @@ -173,7 +179,11 @@ def function(source, name):
}
static int brcmf_pcie_read_pcie32(struct brcmf_pciedev_info *d,int r) {(void)d;(void)r;return retain;}
static void brcmf_pcie_select_core(struct brcmf_pciedev_info *d,int c) {(void)d;(void)c;}
static void brcmf_pcie_intr_enable(struct brcmf_pciedev_info *d) {d->intr=true;}
static void brcmf_pcie_intr_enable(struct brcmf_pciedev_info *d) {d->intr=d->unmasked=true;}
/* Ring servicing off and no handler running: the thread neither services the rings nor unmasks. */
static void brcmf_pcie_intr_quiesce(struct brcmf_pciedev_info *d) {d->intr=d->unmasked=false;}
/* The dongle's interrupt only, for the WoWLAN wake: ring servicing stays off. */
static void brcmf_pcie_intr_unmask(struct brcmf_pciedev_info *d) {assert(d->wowl_sleeping);d->unmasked=true;}
static void brcmf_pcie_hostready(struct brcmf_pciedev_info *d) {assert(d->intr);d->ready=true;}
static void brcmf_chip_detach(void *c) {(void)c;}
static void brcmf_pcie_remove(struct pci_dev *p) {(void)p;removes++;}
Expand Down Expand Up @@ -285,6 +295,7 @@ def function(source, name):
cfg.pub=&pub;cfg.wiphy=&wiphy;wiphy.cfg=&cfg;vif_up=true;device.data=&bus;devinfo.pdev=&pdev;
static typeof(*devinfo.reginfo) regs;devinfo.reginfo=&regs;
devinfo.state=BRCMFMAC_PCIE_STATE_UP;devinfo.intr=devinfo.ready=devinfo.timer=true;
devinfo.irq_allocated=devinfo.unmasked=true;irq_depth=0;kicks=0;
country_gets=sets=bands=txflows=creates=cancels=removes=probes=0;
failure=translation=d0_error=probe_error=wake_error=save_error=0;ack=true;retain=1;d3_informs=d0_informs=0;
pm_suspend_target_state=PM_SUSPEND_TO_IDLE;feats=0;
Expand Down Expand Up @@ -442,13 +453,16 @@ def function(source, name):
assert(!d3_informs && devinfo.state==BRCMFMAC_PCIE_STATE_UP);
if(fail) {
assert(ret==-EINVAL && !devinfo.wowl_sleeping && !devinfo.irq_wake_enabled);
assert(bus.state==BRCMF_BUS_UP && !msgbuf.tx_suspended && devinfo.timer);cases++;continue;
assert(bus.state==BRCMF_BUS_UP && !msgbuf.tx_suspended && devinfo.timer);
assert(devinfo.intr && devinfo.unmasked);cases++;continue;
}
assert(!ret && devinfo.wowl_sleeping && devinfo.irq_wake_enabled && pdev.state_saved);
assert(bus.state==BRCMF_BUS_DOWN && msgbuf.tx_suspended && !devinfo.timer && ndev[0].stopped);
devinfo.intr=false;
/* No ring servicing across the sleep, but the wake interrupt stays unmasked. */
assert(!devinfo.intr && devinfo.unmasked);
assert(!brcmf_pcie_pm_leave_D3(&device));
assert(!devinfo.wowl_sleeping && !devinfo.irq_wake_enabled && !pdev.state_saved && devinfo.intr);
assert(devinfo.unmasked && !irq_depth && kicks==1);
assert(bus.state==BRCMF_BUS_UP && !msgbuf.tx_suspended && devinfo.timer && !ndev[0].stopped);
assert(!d0_informs && !removes && !probes);cases++;
}
Expand All @@ -461,13 +475,16 @@ def function(source, name):
assert(!d3_informs && devinfo.state==BRCMFMAC_PCIE_STATE_UP && !devinfo.wowl_sleeping);
if(fail) {
assert(ret==-EINVAL && !devinfo.s2idle_d0 && !pdev.state_saved);
assert(bus.state==BRCMF_BUS_UP && !msgbuf.tx_suspended && devinfo.timer);cases++;continue;
assert(bus.state==BRCMF_BUS_UP && !msgbuf.tx_suspended && devinfo.timer);
assert(devinfo.intr && devinfo.unmasked);cases++;continue;
}
assert(!ret && devinfo.s2idle_d0 && pdev.state_saved && !devinfo.irq_wake_enabled);
assert(bus.state==BRCMF_BUS_DOWN && msgbuf.tx_suspended && !devinfo.timer && ndev[0].stopped);
devinfo.intr=false;
/* No ring servicing and the dongle masked across the sleep. */
assert(!devinfo.intr && !devinfo.unmasked);
assert(!brcmf_pcie_pm_leave_D3(&device));
assert(!devinfo.s2idle_d0 && !pdev.state_saved && devinfo.intr);
assert(devinfo.unmasked && !irq_depth && kicks==1);
assert(bus.state==BRCMF_BUS_UP && !msgbuf.tx_suspended && devinfo.timer && !ndev[0].stopped);
assert(msgbuf.flowring_work.queued && msgbuf.txflow_work.queued);
assert(!d0_informs && !removes && !probes);cases++;
Expand Down Expand Up @@ -523,7 +540,8 @@ def main():
parser.add_argument('--mutation', choices=['country-gate', 'queue-reasons', 'worker-gate',
'resume-order', 'tx-drain', 'lpas-resume',
's2idle-d3', 'wowl-s2idle-only', 'restore-pm',
'resume-join', 'down-error-fence'])
'resume-join', 'down-error-fence',
'd0-quiesce', 'd0-restore-irq', 'd0-kick'])
args = parser.parse_args()
sources = {name: (DRIVER / (name + '.c')).read_text()
for name in ('cfg80211', 'core', 'pcie', 'msgbuf')}
Expand Down Expand Up @@ -566,6 +584,14 @@ def main():
elif args.mutation == 'wowl-s2idle-only':
body = body.replace('if (wowl && cfg->pub->bus_if->wowl_s2idle_only &&\n\t pm_suspend_target_state != PM_SUSPEND_TO_IDLE)',
'if (false)')
elif args.mutation == 'd0-quiesce':
body = body.replace('\t/* Nothing touches the rings until brcmf_pcie_wowl_wake() at resume. */\n'
'\tbrcmf_pcie_intr_quiesce(devinfo);\n', '')
elif args.mutation == 'd0-restore-irq':
body = body.replace('\t\tdisable_irq(devinfo->pdev->irq);\n', '')
body = body.replace('\t\tenable_irq(devinfo->pdev->irq);\n', '')
elif args.mutation == 'd0-kick':
body = body.replace('irq_wake_thread(devinfo->pdev->irq, devinfo);', ';')
elif args.mutation == 'tx-drain':
body = body.replace('netif_tx_disable(ifp->ndev);', '(void)ifp;')
code = PREFIX.replace('/* STOP_REASONS */', reasons) + CALLBACK_STUBS + body + MAIN
Expand Down
3 changes: 2 additions & 1 deletion tools/asahi/run-host-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ def mutations(flag, names, base, expect=KILL):
+ mutations('--mutation', ('country-gate', 'queue-reasons', 'worker-gate',
'resume-order', 'tx-drain', 'lpas-resume',
'wowl-s2idle-only', 'restore-pm', 'resume-join',
'down-error-fence'), out()),
'down-error-fence', 'd0-quiesce', 'd0-restore-irq',
'd0-kick'), out()),
'brcmf-wowl-filter-tests.py': [(out(), PASS)]
+ mutations('--mutation', ('base-order', 'mask-last', 'totsize', 'no-track'), out()),
'brcmfmac-scan-timeout-tests.py': [(out('--output'), PASS)],
Expand Down
Loading