1 From patchwork Thu Sep 28 12:58:34 2017
2 Content-Type: text/plain; charset="utf-8"
4 Content-Transfer-Encoding: 7bit
6 3/7] PCI: aardvark: set host and device to the same MAX payload size
7 X-Patchwork-Submitter: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
9 Message-Id: <20170928125838.11887-4-thomas.petazzoni@free-electrons.com>
10 To: Bjorn Helgaas <bhelgaas@google.com>, linux-pci@vger.kernel.org
11 Cc: Jason Cooper <jason@lakedaemon.net>, Andrew Lunn <andrew@lunn.ch>,
12 Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>, Gregory Clement
13 <gregory.clement@free-electrons.com>,
14 Nadav Haklai <nadavh@marvell.com>, Hanna Hawa <hannah@marvell.com>,
15 Yehuda Yitschak <yehuday@marvell.com>,
16 linux-arm-kernel@lists.infradead.org, Antoine Tenart
17 <antoine.tenart@free-electrons.com>, =?utf-8?q?Miqu=C3=A8l_Raynal?=
18 <miquel.raynal@free-electrons.com>, Victor Gu <xigu@marvell.com>,
19 Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
20 Date: Thu, 28 Sep 2017 14:58:34 +0200
21 From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
22 List-Id: <linux-pci.vger.kernel.org>
24 From: Victor Gu <xigu@marvell.com>
26 Since the Aardvark does not implement a PCIe root bus, the Linux PCIe
27 subsystem will not align the MAX payload size between the host and the
28 device. This patch ensures that the host and device have the same MAX
29 payload size, fixing a number of problems with various PCIe devices.
31 This is part of fixing bug
32 https://bugzilla.kernel.org/show_bug.cgi?id=196339, this commit was
33 reported as the user to be important to get a Intel 7260 mini-PCIe
36 Fixes: Fixes: 8c39d710363c1 ("PCI: aardvark: Add Aardvark PCI host controller driver")
37 Signed-off-by: Victor Gu <xigu@marvell.com>
38 Reviewed-by: Evan Wang <xswang@marvell.com>
39 Reviewed-by: Nadav Haklai <nadavh@marvell.com>
40 [Thomas: tweak commit log.]
41 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
43 drivers/pci/host/pci-aardvark.c | 60 ++++++++++++++++++++++++++++++++++++++++-
44 1 file changed, 59 insertions(+), 1 deletion(-)
46 --- a/drivers/pci/host/pci-aardvark.c
47 +++ b/drivers/pci/host/pci-aardvark.c
49 #define PCIE_CORE_DEV_CTRL_STATS_REG 0xc8
50 #define PCIE_CORE_DEV_CTRL_STATS_RELAX_ORDER_DISABLE (0 << 4)
51 #define PCIE_CORE_DEV_CTRL_STATS_MAX_PAYLOAD_SZ_SHIFT 5
52 +#define PCIE_CORE_DEV_CTRL_STATS_MAX_PAYLOAD_SZ 0x2
53 #define PCIE_CORE_DEV_CTRL_STATS_SNOOP_DISABLE (0 << 11)
54 #define PCIE_CORE_DEV_CTRL_STATS_MAX_RD_REQ_SIZE_SHIFT 12
55 +#define PCIE_CORE_MPS_UNIT_BYTE 128
56 #define PCIE_CORE_LINK_CTRL_STAT_REG 0xd0
57 #define PCIE_CORE_LINK_L0S_ENTRY BIT(0)
58 #define PCIE_CORE_LINK_TRAINING BIT(5)
59 @@ -297,7 +299,8 @@ static void advk_pcie_setup_hw(struct ad
61 /* Set PCIe Device Control and Status 1 PF0 register */
62 reg = PCIE_CORE_DEV_CTRL_STATS_RELAX_ORDER_DISABLE |
63 - (7 << PCIE_CORE_DEV_CTRL_STATS_MAX_PAYLOAD_SZ_SHIFT) |
64 + (PCIE_CORE_DEV_CTRL_STATS_MAX_PAYLOAD_SZ <<
65 + PCIE_CORE_DEV_CTRL_STATS_MAX_PAYLOAD_SZ_SHIFT) |
66 PCIE_CORE_DEV_CTRL_STATS_SNOOP_DISABLE |
67 PCIE_CORE_DEV_CTRL_STATS_MAX_RD_REQ_SIZE_SHIFT;
68 advk_writel(pcie, reg, PCIE_CORE_DEV_CTRL_STATS_REG);
69 @@ -879,6 +882,58 @@ out_release_res:
73 +static int advk_pcie_find_smpss(struct pci_dev *dev, void *data)
80 + if (!pci_is_pcie(dev))
83 + if (*smpss > dev->pcie_mpss)
84 + *smpss = dev->pcie_mpss;
89 +static int advk_pcie_bus_configure_mps(struct pci_dev *dev, void *data)
96 + if (!pci_is_pcie(dev))
99 + mps = PCIE_CORE_MPS_UNIT_BYTE << *(u8 *)data;
100 + pcie_set_mps(dev, mps);
105 +static void advk_pcie_configure_mps(struct pci_bus *bus, struct advk_pcie *pcie)
107 + u8 smpss = PCIE_CORE_DEV_CTRL_STATS_MAX_PAYLOAD_SZ;
110 + /* Find the minimal supported MAX payload size */
111 + advk_pcie_find_smpss(bus->self, &smpss);
112 + pci_walk_bus(bus, advk_pcie_find_smpss, &smpss);
114 + /* Configure RC MAX payload size */
115 + reg = advk_readl(pcie, PCIE_CORE_DEV_CTRL_STATS_REG);
116 + reg &= ~PCI_EXP_DEVCTL_PAYLOAD;
117 + reg |= smpss << PCIE_CORE_DEV_CTRL_STATS_MAX_PAYLOAD_SZ_SHIFT;
118 + advk_writel(pcie, reg, PCIE_CORE_DEV_CTRL_STATS_REG);
120 + /* Configure device MAX payload size */
121 + advk_pcie_bus_configure_mps(bus->self, &smpss);
122 + pci_walk_bus(bus, advk_pcie_bus_configure_mps, &smpss);
125 static int advk_pcie_probe(struct platform_device *pdev)
127 struct device *dev = &pdev->dev;
128 @@ -952,6 +1007,9 @@ static int advk_pcie_probe(struct platfo
129 list_for_each_entry(child, &bus->children, node)
130 pcie_bus_configure_settings(child);
132 + /* Configure the MAX pay load size */
133 + advk_pcie_configure_mps(bus, pcie);
135 pci_bus_add_devices(bus);