void emac_sgmii_reset(struct emac_adapter *adpt)
{ if (!(adpt->phy.sgmii_ops && adpt->phy.sgmii_ops->reset)) return;
adpt->phy.sgmii_ops->reset(adpt);
}
/* Initialize the SGMII link between the internal and external PHYs. */ staticvoid emac_sgmii_link_init(struct emac_adapter *adpt)
{ struct emac_sgmii *phy = &adpt->phy;
u32 val;
/* Always use autonegotiation. It works no matter how the external * PHY is configured.
*/
val = readl(phy->base + EMAC_SGMII_PHY_AUTONEG_CFG2);
val &= ~(FORCE_AN_RX_CFG | FORCE_AN_TX_CFG);
val |= AN_ENABLE;
writel(val, phy->base + EMAC_SGMII_PHY_AUTONEG_CFG2);
}
writel_relaxed(irq_bits, phy->base + EMAC_SGMII_PHY_INTERRUPT_CLEAR);
writel_relaxed(IRQ_GLOBAL_CLEAR, phy->base + EMAC_SGMII_PHY_IRQ_CMD); /* Ensure interrupt clear command is written to HW */
wmb();
/* After set the IRQ_GLOBAL_CLEAR bit, the status clearing must * be confirmed before clearing the bits in other registers. * It takes a few cycles for hw to clear the interrupt status.
*/ if (readl_poll_timeout_atomic(phy->base +
EMAC_SGMII_PHY_INTERRUPT_STATUS,
status, !(status & irq_bits), 1,
SGMII_PHY_IRQ_CLR_WAIT_TIME)) {
net_err_ratelimited("%s: failed to clear SGMII irq: status:0x%x bits:0x%x\n",
adpt->netdev->name, status, irq_bits); return -EIO;
}
status = readl(phy->base + EMAC_SGMII_PHY_INTERRUPT_STATUS);
status &= SGMII_ISR_MASK; if (!status) return IRQ_HANDLED;
/* If we get a decoding error and CDR is not locked, then try * resetting the internal PHY. The internal PHY uses an embedded * clock with Clock and Data Recovery (CDR) to recover the * clock and data.
*/ if (status & SGMII_PHY_INTERRUPT_ERR) { int count;
/* The SGMII is capable of recovering from some decode * errors automatically. However, if we get multiple * decode errors in a row, then assume that something * is wrong and reset the interface.
*/
count = atomic_inc_return(&phy->decode_error_count); if (count == DECODE_ERROR_LIMIT) {
schedule_work(&adpt->work_thread);
atomic_set(&phy->decode_error_count, 0);
}
} else { /* We only care about consecutive decode errors. */
atomic_set(&phy->decode_error_count, 0);
}
if (emac_sgmii_irq_clear(adpt, status))
schedule_work(&adpt->work_thread);
if (sgmii->irq) { /* Make sure interrupts are cleared and disabled first */
ret = emac_sgmii_irq_clear(adpt, 0xff); if (ret) return ret;
writel(0, sgmii->base + EMAC_SGMII_PHY_INTERRUPT_MASK);
ret = request_irq(sgmii->irq, emac_sgmii_interrupt, 0, "emac-sgmii", adpt); if (ret) {
netdev_err(adpt->netdev, "could not register handler for internal PHY\n"); return ret;
}
}
/* Make sure interrupts are disabled */
writel(0, sgmii->base + EMAC_SGMII_PHY_INTERRUPT_MASK);
free_irq(sgmii->irq, adpt);
}
/* The error interrupts are only valid after the link is up */ staticint emac_sgmii_common_link_change(struct emac_adapter *adpt, bool linkup)
{ struct emac_sgmii *sgmii = &adpt->phy; int ret;
if (linkup) { /* Clear and enable interrupts */
ret = emac_sgmii_irq_clear(adpt, 0xff); if (ret) return ret;
status = acpi_evaluate_integer(handle, "_HRV", NULL, &hrv); if (status) { if (status == AE_NOT_FOUND) /* Older versions of the QDF2432 ACPI tables do * not have an _HRV property.
*/
hrv = 1; else /* Something is wrong with the tables */ return 0;
}
/* Base address is the first address */
res = platform_get_resource(sgmii_pdev, IORESOURCE_MEM, 0); if (!res) {
ret = -EINVAL; goto error_put_device;
}
phy->base = ioremap(res->start, resource_size(res)); if (!phy->base) {
ret = -ENOMEM; goto error_put_device;
}
/* v2 SGMII has a per-lane digital, so parse it if it exists */
res = platform_get_resource(sgmii_pdev, IORESOURCE_MEM, 1); if (res) {
phy->digital = ioremap(res->start, resource_size(res)); if (!phy->digital) {
ret = -ENOMEM; goto error_unmap_base;
}
}
ret = emac_sgmii_init(adpt); if (ret) goto error;
emac_sgmii_link_init(adpt);
ret = platform_get_irq(sgmii_pdev, 0); if (ret > 0)
phy->irq = ret;
/* We've remapped the addresses, so we don't need the device any * more. of_find_device_by_node() says we should release it.
*/
put_device(&sgmii_pdev->dev);
return 0;
error: if (phy->digital)
iounmap(phy->digital);
error_unmap_base:
iounmap(phy->base);
error_put_device:
put_device(&sgmii_pdev->dev);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.