Skip to content
Draft
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
3 changes: 3 additions & 0 deletions Documentation/devicetree/bindings/pci/google,gs201-pcie.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ properties:
- items:
- const: google,zumapro-pcie
- const: google,zuma-pcie
- items:
- const: google,gs201-lynx-pcie
- const: google,gs201-pcie

reg:
minItems: 3
Expand Down
1 change: 1 addition & 0 deletions drivers/pci/controller/dwc/pcie-designware-host.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ void dw_handle_msi_irq(struct dw_pcie_rp *pp)
generic_handle_demux_domain_irq(pp->irq_domain, irq_off + pos);
}
}
EXPORT_SYMBOL_GPL(dw_handle_msi_irq);

/* Chained MSI interrupt service routine */
static void dw_chained_msi_isr(struct irq_desc *desc)
Expand Down
117 changes: 106 additions & 11 deletions drivers/pci/controller/dwc/pcie-gs201.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
* controller/dwc-whi/pcie-exynos-rc.c (exynos_pcie_rc_resumed_phydown(),
* exynos_pcie_rc_poweron() and exynos_pcie_rc_establish_link()).
*
* Only legacy INTx interrupts are supported, which is what the Pixel 7 Wi-Fi
* uses on stock firmware too.
* Pixel 7 Wi-Fi uses legacy INTx. Pixel 7a uses the DWC iMSI-RX, demuxed
* from the shared ELBI interrupt after link reset has completed.
*
* Bring-up runs in numbered stages, each touching one more part of the
* hardware. The stop_after parameter ends probe after a given stage, and
Expand Down Expand Up @@ -54,6 +54,7 @@
#define GS201_ELBI_IRQ1_LINK_DOWN BIT(10)
#define GS201_ELBI_IRQ2 0x008
#define GS201_ELBI_IRQ2_CPL_TIMEOUT BIT(24)
#define GS201_ELBI_IRQ2_MSI_RISING BIT(17)
#define GS201_ELBI_IRQ0_EN 0x010
#define GS201_ELBI_IRQ1_EN 0x014
#define GS201_ELBI_IRQ2_EN 0x018
Expand Down Expand Up @@ -182,6 +183,7 @@ MODULE_PARM_DESC(cmu_acg_off,
* the soft power reset before the PHY powers down, as Google's
* exynos_pcie_rc_poweroff() does for the zuma family. Only zumapro so
* far: it hasn't run on a zuma board here.
* @wcn_msi: lynx's WCN endpoint requires iMSI-RX
*/
struct gs201_pcie_soc_data {
bool ctrl_reset_before_phy;
Expand All @@ -191,6 +193,7 @@ struct gs201_pcie_soc_data {
bool noncoherent_only;
bool skip_link_history;
unsigned int link_tries;
bool wcn_msi;
};

struct gs201_pcie {
Expand All @@ -217,6 +220,7 @@ struct gs201_pcie {
int irq;
struct irq_domain *intx_domain;
raw_spinlock_t lock;
bool msi_ready;
};

#define to_gs201_pcie(x) dev_get_drvdata((x)->dev)
Expand Down Expand Up @@ -452,8 +456,10 @@ static bool gs201_pcie_link_up(struct dw_pcie *pci)
ltssm <= DW_PCIE_LTSSM_L1_IDLE;
}

static void gs201_pcie_enable_irqs(struct gs201_pcie *gp)
static int gs201_pcie_enable_irqs(struct gs201_pcie *gp)
{
u32 enabled;

gs201_trace(gp, "about to clear ELBI IRQ0-2 and enable link-down and completion-timeout interrupts");

/* Clear anything latched during training */
Expand All @@ -466,6 +472,21 @@ static void gs201_pcie_enable_irqs(struct gs201_pcie *gp)

gs201_elbi_rmw(gp, GS201_ELBI_IRQ1_EN, 0, GS201_ELBI_IRQ1_LINK_DOWN);
gs201_elbi_rmw(gp, GS201_ELBI_IRQ2_EN, 0, GS201_ELBI_IRQ2_CPL_TIMEOUT);
/* Link soft reset clears this bit too. Arm only after the link is up. */
if (gp->data->wcn_msi) {
if (upper_32_bits(gp->pci.pp.msi_data))
return dev_err_probe(gp->pci.dev, -ERANGE,
"MSI target exceeds 32 bits\n");
gs201_elbi_rmw(gp, GS201_ELBI_IRQ2_EN, 0,
GS201_ELBI_IRQ2_MSI_RISING);
enabled = gs201_elbi_readl(gp, GS201_ELBI_IRQ2_EN);
if (!(enabled & GS201_ELBI_IRQ2_MSI_RISING))
return dev_err_probe(gp->pci.dev, -EIO,
"MSI interrupt enable did not latch\n");
dev_info(gp->pci.dev, "MSI armed after link up, ELBI IRQ2_EN %#x\n",
enabled);
}
return 0;
}

static void gs201_pcie_disable_irqs(struct gs201_pcie *gp)
Expand Down Expand Up @@ -850,14 +871,23 @@ static int gs201_pcie_start_link(struct dw_pcie *pci)
return ret;
}

/*
* Leave the LTSSM running even on failure: dw_pcie_wait_for_link()
* reports the final state, and a card that shows up late can still
* train.
*/
/* MSI must be armed before the DWC core can enumerate an endpoint. */
if (ret && gp->data->wcn_msi)
return ret;

/* The existing INTx path permits a card to train during DWC's wait. */
if (!ret) {
dev_info(dev, "link up on try %u\n", try);
gs201_pcie_enable_irqs(gp);
if (gp->data->wcn_msi)
/* Publish the domain before enabling its interrupt. */
smp_store_release(&gp->msi_ready, true);
ret = gs201_pcie_enable_irqs(gp);
if (ret) {
WRITE_ONCE(gp->msi_ready, false);
gs201_pcie_disable_irqs(gp);
synchronize_irq(gp->irq);
return ret;
}
gs201_pcie_check_iocc(gp, "after link up");
}

Expand All @@ -873,7 +903,11 @@ static void gs201_pcie_stop_link(struct dw_pcie *pci)
{
struct gs201_pcie *gp = to_gs201_pcie(pci);

if (gp->data->wcn_msi)
WRITE_ONCE(gp->msi_ready, false);
gs201_pcie_disable_irqs(gp);
if (gp->data->wcn_msi)
synchronize_irq(gp->irq);
gs201_elbi_writel(gp, GS201_ELBI_LTSSM_EN, 0);
}

Expand All @@ -884,7 +918,35 @@ static const struct dw_pcie_ops gs201_pcie_dw_ops = {
.stop_link = gs201_pcie_stop_link,
};

static void gs201_pcie_handle_msi(struct gs201_pcie *gp)
{
struct dw_pcie_rp *pp = &gp->pci.pp;
unsigned long flags;
unsigned int ctrl, num_ctrls;
u32 offset;

dw_handle_msi_irq(pp);

/*
* The wrapper latches a rising edge, while iMSI-RX remains asserted
* until all unmasked status bits are cleared. A lower vector arriving
* while an upper vector is handled can miss the status snapshot and
* leave the line high without another edge. As Google's combined-MSI
* handler does, pulse the mask to re-pend it. Preserve Linux's masks
* under the same lock used by the DWC IRQ chip's mask/unmask paths.
*/
num_ctrls = pp->num_vectors / MAX_MSI_IRQS_PER_CTRL;
raw_spin_lock_irqsave(&pp->lock, flags);
for (ctrl = 0; ctrl < num_ctrls; ctrl++) {
offset = PCIE_MSI_INTR0_MASK + ctrl * MSI_REG_CTRL_BLOCK_SIZE;
dw_pcie_writel_dbi(&gp->pci, offset, U32_MAX);
dw_pcie_writel_dbi(&gp->pci, offset, pp->irq_mask[ctrl]);
}
raw_spin_unlock_irqrestore(&pp->lock, flags);
}

static void gs201_pcie_irq_handler(struct irq_desc *desc);
static void gs201_pcie_msi_irq_handler(struct irq_desc *desc);

/*
* Stage 5 entry, from dw_pcie_host_init(): stages 1-2, the endpoint power
Expand All @@ -906,7 +968,8 @@ static int gs201_pcie_host_init(struct dw_pcie_rp *pp)
goto err_bringdown;

/* ELBI is reachable and its interrupt enables are off */
irq_set_chained_handler_and_data(gp->irq, gs201_pcie_irq_handler, gp);
irq_set_chained_handler_and_data(gp->irq, gp->data->wcn_msi ?
gs201_pcie_msi_irq_handler : gs201_pcie_irq_handler, gp);

dev_info(dev, "stage %u/%u: %s\n", GS201_STAGE_LINK, GS201_STAGE_LINK,
gs201_stage_names[GS201_STAGE_LINK]);
Expand Down Expand Up @@ -985,6 +1048,11 @@ static const struct dw_pcie_host_ops gs201_pcie_host_ops = {
.msi_init = gs201_pcie_msi_init,
};

static const struct dw_pcie_host_ops gs201_pcie_host_ops_msi = {
.init = gs201_pcie_host_init,
.deinit = gs201_pcie_host_deinit,
};

static void gs201_pcie_intx_mask(struct irq_data *d)
{
struct gs201_pcie *gp = irq_data_get_irq_chip_data(d);
Expand Down Expand Up @@ -1027,7 +1095,7 @@ static const struct irq_domain_ops gs201_pcie_intx_domain_ops = {
.xlate = pci_irqd_intx_xlate,
};

static void gs201_pcie_irq_handler(struct irq_desc *desc)
static __always_inline void gs201_pcie_handle_irq(struct irq_desc *desc, bool msi)
{
struct gs201_pcie *gp = irq_desc_get_handler_data(desc);
struct irq_chip *chip = irq_desc_get_chip(desc);
Expand Down Expand Up @@ -1060,9 +1128,24 @@ static void gs201_pcie_irq_handler(struct irq_desc *desc)
for_each_set_bit(bit, &intx, PCI_NUM_INTX)
generic_handle_domain_irq(gp->intx_domain, bit);

/* DWC owns the MSI domain; our handler owns the shared interrupt. */
/* Pairs with publication after link training, before IRQ enable. */
if (msi && (irq2 & GS201_ELBI_IRQ2_MSI_RISING) && smp_load_acquire(&gp->msi_ready))
gs201_pcie_handle_msi(gp);

chained_irq_exit(chip, desc);
}

static void gs201_pcie_irq_handler(struct irq_desc *desc)
{
gs201_pcie_handle_irq(desc, false);
}

static void gs201_pcie_msi_irq_handler(struct irq_desc *desc)
{
gs201_pcie_handle_irq(desc, true);
}

/*
* Only the INTx domain is created here; the chained handler is installed by
* host_init once the PHY is out of isolation and the ELBI interrupt enables
Expand Down Expand Up @@ -1217,6 +1300,13 @@ static int gs201_pcie_probe(struct platform_device *pdev)
pci->dev = dev;
pci->ops = &gs201_pcie_dw_ops;
pci->pp.ops = &gs201_pcie_host_ops;
if (gp->data->wcn_msi) {
if (!pci_msi_enabled())
return dev_err_probe(dev, -ENODEV, "lynx requires PCI MSI\n");
pci->pp.ops = &gs201_pcie_host_ops_msi;
pci->pp.msi_irq[0] = -ENXIO;
pci->pp.num_vectors = MAX_MSI_IRQS_PER_CTRL;
}

dev_info(dev, "stage 0/%u: %s (stop_after=%u, trace=%d, use_ia=%d, cmu_acg_off=%d)\n",
GS201_STAGE_LINK, gs201_stage_names[GS201_STAGE_NONE],
Expand Down Expand Up @@ -1324,6 +1414,10 @@ static const struct gs201_pcie_soc_data gs101_pcie_data = {
static const struct gs201_pcie_soc_data gs201_pcie_data = {
};

static const struct gs201_pcie_soc_data lynx_pcie_data = {
.wcn_msi = true,
};

static const struct gs201_pcie_soc_data zuma_pcie_data = {
.ctrl_reset_before_phy = true,
};
Expand All @@ -1335,6 +1429,7 @@ static const struct gs201_pcie_soc_data zumapro_pcie_data = {

static const struct of_device_id gs201_pcie_of_match[] = {
{ .compatible = "google,gs101-pcie", .data = &gs101_pcie_data },
{ .compatible = "google,gs201-lynx-pcie", .data = &lynx_pcie_data },
{ .compatible = "google,gs201-pcie", .data = &gs201_pcie_data },
{ .compatible = "google,zumapro-pcie", .data = &zumapro_pcie_data },
{ .compatible = "google,zuma-pcie", .data = &zuma_pcie_data },
Expand Down