pci: DesignWare PCIe big-endian CCSR and lane configuration for LS1046A

- qoriq_dw_pci: byte-swap CCSR register access for big-endian controller
- pci_dw: lane configuration support for proper link training
- DTS: enable PCIe3 for WiFi module (88W9098)
This commit is contained in:
Tomaz Zaman 2026-03-04 21:54:33 +01:00 • committed by Maurice Walker
parent 0e8c370df5
commit 0d8077ab97
3 changed files with 100 additions and 62 deletions

View file

@ -30,6 +30,7 @@
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/endian.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/devmap.h>
@ -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)) {

View file

@ -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>;
};

View file

@ -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);