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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ description: |
native driver selects personalized firmware and transport data from its
root-board match table rather than the T6050 wire-protocol properties.

On T8142 the root port above function zero may describe the N1's warm
reset with apple,function-warm-reset and apple,warm-reset-writes, as in
pci/apple,pcie.yaml. With both, the native driver restarts a firmware
that stopped; without them it never resets the chip.

properties:
compatible:
oneOf:
Expand Down
7 changes: 7 additions & 0 deletions arch/arm64/boot/dts/apple/t8142-j813.dts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@
#address-cells = <3>;
#size-cells = <2>;
ranges;
/*
* The N1's warm reset: the ADT's pci-bridge0 function-warm_reset (the SMC, key
* 'bpli', the same key and argument as on the T6050 boards) and the T6050 writes.
* The N1 driver restarts a stopped firmware with it.
*/
apple,function-warm-reset = <&smc 0x62706c69 0x1000000>;
apple,warm-reset-writes = <0x00010001 17000>, <0x00010001 20000>;

n1_control: control@0,0 {
compatible = "apple,t8142-centauri-control", "pci106b,1900";
Expand Down
6 changes: 6 additions & 0 deletions arch/arm64/boot/dts/apple/t8142-j815.dts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@
#address-cells = <3>;
#size-cells = <2>;
ranges;
/*
* The N1's warm reset, as on J813: the J815 ADT's pci-bridge0
* function-warm_reset names the same SMC key 'bpli' and argument.
*/
apple,function-warm-reset = <&smc 0x62706c69 0x1000000>;
apple,warm-reset-writes = <0x00010001 17000>, <0x00010001 20000>;

n1_control: control@0,0 {
compatible = "apple,t8142-centauri-control", "pci106b,1900";
Expand Down
13 changes: 9 additions & 4 deletions drivers/bluetooth/btcentauri.c
Original file line number Diff line number Diff line change
Expand Up @@ -1040,10 +1040,15 @@ static int cen_probe(struct pci_dev *pdev, const struct pci_device_id *id)
if (ret)
return ret;
bt->bar = pcim_iomap_table(pdev)[0];
if (readl(bt->bar + 0x18) != 2 || readl(bt->bar) != 0)
return dev_err_probe(&pdev->dev, -EBUSY,
"Beta requires running firmware and unowned IPC (exec=%u ipc=%u)\n",
readl(bt->bar + 0x18), readl(bt->bar));
/*
* The function appears with the N1's IPC start, before Beta's firmware runs.
* apple_centauri attaches it again once that firmware is up.
*/
if (readl(bt->bar + 0x18) != 2 || readl(bt->bar) != 0) {
dev_info(&pdev->dev, "waiting for Beta's firmware (exec=%u ipc=%u)\n",
readl(bt->bar + 0x18), readl(bt->bar));
return -ENXIO;
}
ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(40));
if (ret)
return ret;
Expand Down
64 changes: 64 additions & 0 deletions drivers/mfd/macsmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,70 @@ int apple_smc_write_noirq(struct apple_smc *smc, smc_key key, const void *buf, s
}
EXPORT_SYMBOL_GPL(apple_smc_write_noirq);

int apple_smc_warm_reset_parse(struct device_node *np, struct apple_smc_warm_reset *wr)
{
struct of_phandle_args fn;
int count, i;

memset(wr, 0, sizeof(*wr));
if (!np || of_parse_phandle_with_fixed_args(np, "apple,function-warm-reset", 2, 0, &fn))
return -ENODEV;
wr->smc = of_find_device_by_node(fn.np);
of_node_put(fn.np);
if (!wr->smc)
return -ENODEV;
count = of_property_count_u32_elems(np, "apple,warm-reset-writes");
if (count < 2 || count % 2 || count > ARRAY_SIZE(wr->writes) ||
of_property_read_u32_array(np, "apple,warm-reset-writes", wr->writes, count))
goto bad;
for (i = 1; i < count; i += 2)
if (wr->writes[i] > 100 * USEC_PER_MSEC)
goto bad;
wr->key = fn.args[0];
wr->count = count / 2;
return 0;
bad:
apple_smc_warm_reset_put(wr);
return -EINVAL;
}
EXPORT_SYMBOL_GPL(apple_smc_warm_reset_parse);

void apple_smc_warm_reset_put(struct apple_smc_warm_reset *wr)
{
if (wr->smc)
put_device(&wr->smc->dev);
memset(wr, 0, sizeof(*wr));
}
EXPORT_SYMBOL_GPL(apple_smc_warm_reset_put);

int apple_smc_warm_reset(const struct apple_smc_warm_reset *wr, bool noirq)
{
struct apple_smc *smc = wr->smc ? platform_get_drvdata(wr->smc) : NULL;
unsigned int i;
int ret = 0;

if (!smc || !wr->count)
return -ENODEV;
for (i = 0; i < wr->count && !ret; i++) {
__be32 value = cpu_to_be32(wr->writes[2 * i]);
u32 wait = wr->writes[2 * i + 1];

if (noirq) {
ret = apple_smc_write_noirq(smc, wr->key, &value, sizeof(value));
if (!ret) {
mdelay(wait / USEC_PER_MSEC);
udelay(wait % USEC_PER_MSEC);
}
} else {
ret = apple_smc_write(smc, wr->key, &value, sizeof(value));
if (!ret)
fsleep(wait);
}
}
return ret;
}
EXPORT_SYMBOL_GPL(apple_smc_warm_reset);

static void apple_smc_write_mbse(struct apple_smc *smc, smc_key value)
{
int ret;
Expand Down
1 change: 1 addition & 0 deletions drivers/net/wireless/apple/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ config APPLE_CENTAURI
tristate "Apple N1 Centauri experimental J813 Wi-Fi"
depends on ARCH_APPLE || COMPILE_TEST
depends on PCI && CFG80211 && DEBUG_FS
depends on MFD_MACSMC
select FW_LOADER
help
Experimental Apple N1 PCIe and ACIPC Wi-Fi support for the J813
Expand Down
17 changes: 15 additions & 2 deletions drivers/net/wireless/apple/centauri/centauri.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <linux/of.h>
#include <linux/pci.h>
#include <linux/sizes.h>
#include <linux/workqueue.h>

#define CEN_ALPHA_SCRATCH_OFFSET SZ_8M
#define CEN_ALPHA_SCRATCH_SIZE (5 * SZ_1M)
Expand All @@ -23,7 +24,7 @@ struct centauri {
void __iomem *bar;
resource_size_t size;
u32 stage_offset;
struct dentry *debug;
struct dentry *debug, *crash_file;
struct mutex boot_lock;
void *firmware, *descriptor, *msi_page;
dma_addr_t firmware_dma, descriptor_dma, msi_dma;
Expand All @@ -35,6 +36,14 @@ struct centauri {
bool link_ready;
struct centauri_ipc *ipc;
struct centauri_wifi *wifi;
/* Restart of a stopped firmware: requested by the Wi-Fi code, confirmed and run here */
struct delayed_work recover_work;
unsigned long recover_at[3];
bool removing;
bool recover_gave_up; /* restart limit reached: requests are ignored */
bool restart_failed; /* the last restart failed with the link up: try again */
bool warm_reset; /* the root port describes the N1's warm reset: restart on a stop */
bool inject_stall; /* debugfs test: the next check finds the firmware stopped */
};

/* One row per machine with an N1: the FTAB file name, the word written to BAR+0x807c,
Expand Down Expand Up @@ -92,8 +101,10 @@ static inline const struct centauri_board *centauri_board(void)
return NULL;
}

int centauri_port_cycle(struct pci_dev *pdev);
int centauri_port_cycle(struct pci_dev *pdev, int *reset_ret);
bool centauri_warm_reset_described(struct pci_dev *pdev);
int centauri_start_ipc(struct centauri *c);
bool centauri_beta_running(struct centauri *c);
void centauri_free_ipc(struct centauri *c);
int centauri_alpha_resources(struct centauri *c, struct cen_alpha_resources *resources);
int centauri_alpha_log_buffer(struct centauri *c, void **cpu, dma_addr_t *dma, size_t *size);
Expand All @@ -102,4 +113,6 @@ void centauri_wifi_unregister(struct centauri *c);
int centauri_wifi_suspend(struct centauri *c);
int centauri_wifi_resume(struct centauri *c);
void centauri_wifi_kick(struct centauri *c);
bool centauri_wifi_stalled(struct centauri *c);
void centauri_recovery_request(struct centauri *c, const char *why);
#endif
19 changes: 18 additions & 1 deletion drivers/net/wireless/apple/centauri/centauri_ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,13 @@ static int secondary_init(struct centauri *c)
pci_write_config_dword(c->pdev, 0xf8c, upper_32_bits(c->ipc->secondary->dma));
pci_write_config_dword(c->pdev, 0xf90, required);
dev_info(&c->pdev->dev, "secondary memory: seed=%u required=%u\n", length, required);
debugfs_create_file("firmware_crash", 0400, c->debug, c, &firmware_crash_fops);
/*
* Created once and kept across restarts: its reader looks up c->ipc under boot_lock,
* and removing it here, under boot_lock, would wait for a reader blocked on that lock.
*/
if (!c->crash_file)
c->crash_file = debugfs_create_file("firmware_crash", 0400, c->debug, c,
&firmware_crash_fops);
return 0;
}

Expand Down Expand Up @@ -546,6 +552,17 @@ int centauri_start_ipc(struct centauri *c)
return ret;
}

/*
* Whether Beta's (Bluetooth's) firmware runs with its IPC still unowned: the state
* btcentauri needs to take function 2. Called with the boot lock held.
*/
bool centauri_beta_running(struct centauri *c)
{
void __iomem *bar = c->ipc ? c->ipc->bar[2] : NULL;

return bar && readl(bar + 0x18) == 2 && !readl(bar);
}

void centauri_free_ipc(struct centauri *c)
{
struct centauri_ipc *ipc = c->ipc;
Expand Down
Loading
Loading