diff --git a/sys/arm64/qoriq/qoriq_dw_pci.c b/sys/arm64/qoriq/qoriq_dw_pci.c index 2323b4bc5e1..20ca672d79f 100644 --- a/sys/arm64/qoriq/qoriq_dw_pci.c +++ b/sys/arm64/qoriq/qoriq_dw_pci.c @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -71,7 +72,7 @@ struct qorif_dw_pci_softc { struct resource *irq_res; void *intr_cookie; struct qoriq_dw_pci_cfg *soc_cfg; - + bool big_endian; /* CCSR registers are BE */ }; static struct qoriq_dw_pci_cfg ls1043_cfg = { @@ -100,7 +101,7 @@ static struct ofw_compat_data compat_data[] = { {"fsl,ls1012a-pcie", (uintptr_t)&ls1012_cfg}, {"fsl,ls1028a-pcie", (uintptr_t)&ls2028_cfg}, {"fsl,ls1043a-pcie", (uintptr_t)&ls1043_cfg}, - {"fsl,ls1046a-pcie", (uintptr_t)&ls1012_cfg}, + {"fsl,ls1046a-pcie", (uintptr_t)&ls2028_cfg}, {"fsl,ls2080a-pcie", (uintptr_t)&ls2080_cfg}, {"fsl,ls2085a-pcie", (uintptr_t)&ls2080_cfg}, {"fsl,ls2088a-pcie", (uintptr_t)&ls2028_cfg}, @@ -141,10 +142,11 @@ static int qorif_dw_pci_get_link(device_t dev, bool *status) { struct qorif_dw_pci_softc *sc; - uint32_t reg; + uint32_t reg, raw; sc = device_get_softc(dev); - reg = pci_dw_dbi_rd4(sc->dev, sc->soc_cfg->pex_pf0_dgb); + raw = pci_dw_dbi_rd4(sc->dev, sc->soc_cfg->pex_pf0_dgb); + reg = sc->big_endian ? bswap32(raw) : raw; reg >>= sc->soc_cfg->ltssm_bit; reg &= 0x3F; *status = (reg == 0x11) ? true : false; @@ -198,6 +200,7 @@ qorif_dw_pci_attach(device_t dev) sc->node = node; sc->soc_cfg = (struct qoriq_dw_pci_cfg *) ofw_bus_search_compatible(dev, compat_data)->ocd_data; + sc->big_endian = OF_hasprop(node, "big-endian"); rid = 0; sc->dw_sc.dbi_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, @@ -234,6 +237,20 @@ qorif_dw_pci_attach(device_t dev) qorif_dw_pci_init(sc); + /* Report link status */ + { + uint32_t raw, ltssm; + bool link_up; + + raw = pci_dw_dbi_rd4(dev, sc->soc_cfg->pex_pf0_dgb); + ltssm = sc->big_endian ? bswap32(raw) : raw; + ltssm = (ltssm >> sc->soc_cfg->ltssm_bit) & 0x3F; + link_up = (ltssm == 0x11); + device_printf(dev, + "PCIe link: LTSSM=0x%02x (%s), PEX_PF0_DBG=0x%08x (raw), big_endian=%d\n", + ltssm, link_up ? "L0/up" : "not up", raw, sc->big_endian); + } + /* Setup interrupt */ if (bus_setup_intr(dev, sc->irq_res, INTR_TYPE_MISC | INTR_MPSAFE, qorif_dw_pci_intr, NULL, sc, &sc->intr_cookie)) { diff --git a/sys/contrib/device-tree/src/arm64/freescale/mono-gateway-dk.dts b/sys/contrib/device-tree/src/arm64/freescale/mono-gateway-dk.dts index 3e3a9839fd5..fd39c8c2101 100644 --- a/sys/contrib/device-tree/src/arm64/freescale/mono-gateway-dk.dts +++ b/sys/contrib/device-tree/src/arm64/freescale/mono-gateway-dk.dts @@ -442,3 +442,9 @@ reg = <0 0xc3000000 0 0x800000>; /* 8MB at 0xC3000000 */ }; +/* PCIe3: Jody W337 WiFi module (NXP 88W9098) */ +&pcie3 { + status = "okay"; + num-lanes = <1>; +}; + diff --git a/sys/dev/pci/pci_dw.c b/sys/dev/pci/pci_dw.c index eae90e8f5f9..e7fcc9a47eb 100644 --- a/sys/dev/pci/pci_dw.c +++ b/sys/dev/pci/pci_dw.c @@ -366,64 +366,79 @@ pci_dw_setup_hw(struct pci_dw_softc *sc) return (rv); } - /* Adjust number of lanes */ - reg = DBI_RD4(sc, DW_PORT_LINK_CTRL); - reg &= ~PORT_LINK_CAPABLE(~0); - switch (sc->num_lanes) { - case 1: - reg |= PORT_LINK_CAPABLE(PORT_LINK_CAPABLE_1); - break; - case 2: - reg |= PORT_LINK_CAPABLE(PORT_LINK_CAPABLE_2); - break; - case 4: - reg |= PORT_LINK_CAPABLE(PORT_LINK_CAPABLE_4); - break; - case 8: - reg |= PORT_LINK_CAPABLE(PORT_LINK_CAPABLE_8); - break; - case 16: - reg |= PORT_LINK_CAPABLE(PORT_LINK_CAPABLE_16); - break; - case 32: - reg |= PORT_LINK_CAPABLE(PORT_LINK_CAPABLE_32); - break; - default: - device_printf(sc->dev, - "'num-lanes' property have invalid value: %d\n", - sc->num_lanes); - return (EINVAL); - } - DBI_WR4(sc, DW_PORT_LINK_CTRL, reg); + /* + * Adjust number of lanes and trigger link retraining only if + * "num-lanes" is explicitly specified in DT. When absent + * (num_lanes == 0), preserve the link configuration established + * by firmware/bootloader. This matches Linux behavior where + * dw_pcie_link_set_max_link_width() returns early if num_lanes + * is zero. + */ + if (sc->num_lanes > 0) { + reg = DBI_RD4(sc, DW_PORT_LINK_CTRL); + reg &= ~PORT_LINK_CAPABLE(~0); + switch (sc->num_lanes) { + case 1: + reg |= PORT_LINK_CAPABLE(PORT_LINK_CAPABLE_1); + break; + case 2: + reg |= PORT_LINK_CAPABLE(PORT_LINK_CAPABLE_2); + break; + case 4: + reg |= PORT_LINK_CAPABLE(PORT_LINK_CAPABLE_4); + break; + case 8: + reg |= PORT_LINK_CAPABLE(PORT_LINK_CAPABLE_8); + break; + case 16: + reg |= PORT_LINK_CAPABLE(PORT_LINK_CAPABLE_16); + break; + case 32: + reg |= PORT_LINK_CAPABLE(PORT_LINK_CAPABLE_32); + break; + default: + device_printf(sc->dev, + "'num-lanes' property have invalid value: %d\n", + sc->num_lanes); + return (EINVAL); + } + DBI_WR4(sc, DW_PORT_LINK_CTRL, reg); - /* And link width */ - reg = DBI_RD4(sc, DW_GEN2_CTRL); - reg &= ~GEN2_CTRL_NUM_OF_LANES(~0); - switch (sc->num_lanes) { - case 1: - reg |= GEN2_CTRL_NUM_OF_LANES(GEN2_CTRL_NUM_OF_LANES_1); - break; - case 2: - reg |= GEN2_CTRL_NUM_OF_LANES(GEN2_CTRL_NUM_OF_LANES_2); - break; - case 4: - reg |= GEN2_CTRL_NUM_OF_LANES(GEN2_CTRL_NUM_OF_LANES_4); - break; - case 8: - reg |= GEN2_CTRL_NUM_OF_LANES(GEN2_CTRL_NUM_OF_LANES_8); - break; - case 16: - reg |= GEN2_CTRL_NUM_OF_LANES(GEN2_CTRL_NUM_OF_LANES_16); - break; - case 32: - reg |= GEN2_CTRL_NUM_OF_LANES(GEN2_CTRL_NUM_OF_LANES_32); - break; - } - DBI_WR4(sc, DW_GEN2_CTRL, reg); + /* And link width */ + reg = DBI_RD4(sc, DW_GEN2_CTRL); + reg &= ~GEN2_CTRL_NUM_OF_LANES(~0); + switch (sc->num_lanes) { + case 1: + reg |= GEN2_CTRL_NUM_OF_LANES( + GEN2_CTRL_NUM_OF_LANES_1); + break; + case 2: + reg |= GEN2_CTRL_NUM_OF_LANES( + GEN2_CTRL_NUM_OF_LANES_2); + break; + case 4: + reg |= GEN2_CTRL_NUM_OF_LANES( + GEN2_CTRL_NUM_OF_LANES_4); + break; + case 8: + reg |= GEN2_CTRL_NUM_OF_LANES( + GEN2_CTRL_NUM_OF_LANES_8); + break; + case 16: + reg |= GEN2_CTRL_NUM_OF_LANES( + GEN2_CTRL_NUM_OF_LANES_16); + break; + case 32: + reg |= GEN2_CTRL_NUM_OF_LANES( + GEN2_CTRL_NUM_OF_LANES_32); + break; + } + DBI_WR4(sc, DW_GEN2_CTRL, reg); - reg = DBI_RD4(sc, DW_GEN2_CTRL); - reg |= DIRECT_SPEED_CHANGE; - DBI_WR4(sc, DW_GEN2_CTRL, reg); + reg = DBI_RD4(sc, DW_GEN2_CTRL); + reg |= DIRECT_SPEED_CHANGE; + DBI_WR4(sc, DW_GEN2_CTRL, reg); + } return (0); } @@ -725,8 +740,8 @@ pci_dw_init(device_t dev) rv = OF_getencprop(sc->node, "num-lanes", &sc->num_lanes, sizeof(sc->num_lanes)); if (rv != sizeof(sc->num_lanes)) - sc->num_lanes = 1; - if (sc->num_lanes != 1 && sc->num_lanes != 2 && + sc->num_lanes = 0; + if (sc->num_lanes != 0 && sc->num_lanes != 1 && sc->num_lanes != 2 && sc->num_lanes != 4 && sc->num_lanes != 8) { device_printf(dev, "invalid number of lanes: %d\n",sc->num_lanes);