Skip to content

Commit 2a81dd9

Browse files
paliLorenzo Pieralisi
authored andcommitted
PCI: mvebu: Correctly configure x1/x4 mode
If x1/x4 mode is not set correctly then link with endpoint card is not established. Use DTS property 'num-lanes' to deteriminate x1/x4 mode. Link: https://lore.kernel.org/r/20220222155030.988-6-pali@kernel.org Signed-off-by: Pali Rohár <pali@kernel.org> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
1 parent 26b982c commit 2a81dd9

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

drivers/pci/controller/pci-mvebu.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ struct mvebu_pcie_port {
9393
void __iomem *base;
9494
u32 port;
9595
u32 lane;
96+
bool is_x4;
9697
int devfn;
9798
unsigned int mem_target;
9899
unsigned int mem_attr;
@@ -233,13 +234,25 @@ static void mvebu_pcie_setup_wins(struct mvebu_pcie_port *port)
233234

234235
static void mvebu_pcie_setup_hw(struct mvebu_pcie_port *port)
235236
{
236-
u32 ctrl, cmd, dev_rev, mask;
237+
u32 ctrl, lnkcap, cmd, dev_rev, mask;
237238

238239
/* Setup PCIe controller to Root Complex mode. */
239240
ctrl = mvebu_readl(port, PCIE_CTRL_OFF);
240241
ctrl |= PCIE_CTRL_RC_MODE;
241242
mvebu_writel(port, ctrl, PCIE_CTRL_OFF);
242243

244+
/*
245+
* Set Maximum Link Width to X1 or X4 in Root Port's PCIe Link
246+
* Capability register. This register is defined by PCIe specification
247+
* as read-only but this mvebu controller has it as read-write and must
248+
* be set to number of SerDes PCIe lanes (1 or 4). If this register is
249+
* not set correctly then link with endpoint card is not established.
250+
*/
251+
lnkcap = mvebu_readl(port, PCIE_CAP_PCIEXP + PCI_EXP_LNKCAP);
252+
lnkcap &= ~PCI_EXP_LNKCAP_MLW;
253+
lnkcap |= (port->is_x4 ? 4 : 1) << 4;
254+
mvebu_writel(port, lnkcap, PCIE_CAP_PCIEXP + PCI_EXP_LNKCAP);
255+
243256
/* Disable Root Bridge I/O space, memory space and bus mastering. */
244257
cmd = mvebu_readl(port, PCIE_CMD_OFF);
245258
cmd &= ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
@@ -982,6 +995,7 @@ static int mvebu_pcie_parse_port(struct mvebu_pcie *pcie,
982995
struct device *dev = &pcie->pdev->dev;
983996
enum of_gpio_flags flags;
984997
int reset_gpio, ret;
998+
u32 num_lanes;
985999

9861000
port->pcie = pcie;
9871001

@@ -994,6 +1008,9 @@ static int mvebu_pcie_parse_port(struct mvebu_pcie *pcie,
9941008
if (of_property_read_u32(child, "marvell,pcie-lane", &port->lane))
9951009
port->lane = 0;
9961010

1011+
if (!of_property_read_u32(child, "num-lanes", &num_lanes) && num_lanes == 4)
1012+
port->is_x4 = true;
1013+
9971014
port->name = devm_kasprintf(dev, GFP_KERNEL, "pcie%d.%d", port->port,
9981015
port->lane);
9991016
if (!port->name) {

0 commit comments

Comments
 (0)