aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/devicetree/bindings/pci/amlogic,meson-pcie.txt70
-rw-r--r--Documentation/driver-api/pci/p2pdma.rst4
-rw-r--r--MAINTAINERS8
-rw-r--r--arch/s390/pci/pci.c3
-rw-r--r--arch/x86/pci/broadcom_bus.c4
-rw-r--r--drivers/pci/Kconfig6
-rw-r--r--drivers/pci/controller/dwc/Kconfig10
-rw-r--r--drivers/pci/controller/dwc/Makefile1
-rw-r--r--drivers/pci/controller/dwc/pci-meson.c592
-rw-r--r--drivers/pci/iov.c48
-rw-r--r--drivers/pci/p2pdma.c14
-rw-r--r--drivers/pci/pci-driver.c27
-rw-r--r--drivers/pci/pci.h2
-rw-r--r--drivers/pci/pcie/aspm.c6
-rw-r--r--drivers/pci/pcie/portdrv.h16
-rw-r--r--drivers/pci/quirks.c24
-rw-r--r--drivers/pci/switch/switchtec.c154
-rw-r--r--drivers/usb/dwc3/dwc3-haps.c4
-rw-r--r--include/linux/pci.h7
-rw-r--r--include/linux/pci_ids.h3
-rw-r--r--include/linux/switchtec.h16
21 files changed, 940 insertions, 79 deletions
diff --git a/Documentation/devicetree/bindings/pci/amlogic,meson-pcie.txt b/Documentation/devicetree/bindings/pci/amlogic,meson-pcie.txt
new file mode 100644
index 000000000000..12b18f82d441
--- /dev/null
+++ b/Documentation/devicetree/bindings/pci/amlogic,meson-pcie.txt
@@ -0,0 +1,70 @@
1Amlogic Meson AXG DWC PCIE SoC controller
2
3Amlogic Meson PCIe host controller is based on the Synopsys DesignWare PCI core.
4It shares common functions with the PCIe DesignWare core driver and
5inherits common properties defined in
6Documentation/devicetree/bindings/pci/designware-pci.txt.
7
8Additional properties are described here:
9
10Required properties:
11- compatible:
12 should contain "amlogic,axg-pcie" to identify the core.
13- reg:
14 should contain the configuration address space.
15- reg-names: Must be
16 - "elbi" External local bus interface registers
17 - "cfg" Meson specific registers
18 - "phy" Meson PCIE PHY registers
19 - "config" PCIe configuration space
20- reset-gpios: The GPIO to generate PCIe PERST# assert and deassert signal.
21- clocks: Must contain an entry for each entry in clock-names.
22- clock-names: Must include the following entries:
23 - "pclk" PCIe GEN 100M PLL clock
24 - "port" PCIe_x(A or B) RC clock gate
25 - "general" PCIe Phy clock
26 - "mipi" PCIe_x(A or B) 100M ref clock gate
27- resets: phandle to the reset lines.
28- reset-names: must contain "phy" "port" and "apb"
29 - "phy" Share PHY reset
30 - "port" Port A or B reset
31 - "apb" Share APB reset
32- device_type:
33 should be "pci". As specified in designware-pcie.txt
34
35
36Example configuration:
37
38 pcie: pcie@f9800000 {
39 compatible = "amlogic,axg-pcie", "snps,dw-pcie";
40 reg = <0x0 0xf9800000 0x0 0x400000
41 0x0 0xff646000 0x0 0x2000
42 0x0 0xff644000 0x0 0x2000
43 0x0 0xf9f00000 0x0 0x100000>;
44 reg-names = "elbi", "cfg", "phy", "config";
45 reset-gpios = <&gpio GPIOX_19 GPIO_ACTIVE_HIGH>;
46 interrupts = <GIC_SPI 177 IRQ_TYPE_EDGE_RISING>;
47 #interrupt-cells = <1>;
48 interrupt-map-mask = <0 0 0 0>;
49 interrupt-map = <0 0 0 0 &gic GIC_SPI 179 IRQ_TYPE_EDGE_RISING>;
50 bus-range = <0x0 0xff>;
51 #address-cells = <3>;
52 #size-cells = <2>;
53 device_type = "pci";
54 ranges = <0x82000000 0 0 0x0 0xf9c00000 0 0x00300000>;
55
56 clocks = <&clkc CLKID_USB
57 &clkc CLKID_MIPI_ENABLE
58 &clkc CLKID_PCIE_A
59 &clkc CLKID_PCIE_CML_EN0>;
60 clock-names = "general",
61 "mipi",
62 "pclk",
63 "port";
64 resets = <&reset RESET_PCIE_PHY>,
65 <&reset RESET_PCIE_A>,
66 <&reset RESET_PCIE_APB>;
67 reset-names = "phy",
68 "port",
69 "apb";
70 };
diff --git a/Documentation/driver-api/pci/p2pdma.rst b/Documentation/driver-api/pci/p2pdma.rst
index 4c577fa7bef9..6d85b5a2598d 100644
--- a/Documentation/driver-api/pci/p2pdma.rst
+++ b/Documentation/driver-api/pci/p2pdma.rst
@@ -49,7 +49,7 @@ For example, in the NVMe Target Copy Offload implementation:
49 in that it exposes any CMB (Controller Memory Buffer) as a P2P memory 49 in that it exposes any CMB (Controller Memory Buffer) as a P2P memory
50 resource (provider), it accepts P2P memory pages as buffers in requests 50 resource (provider), it accepts P2P memory pages as buffers in requests
51 to be used directly (client) and it can also make use of the CMB as 51 to be used directly (client) and it can also make use of the CMB as
52 submission queue entries (orchastrator). 52 submission queue entries (orchestrator).
53* The RDMA driver is a client in this arrangement so that an RNIC 53* The RDMA driver is a client in this arrangement so that an RNIC
54 can DMA directly to the memory exposed by the NVMe device. 54 can DMA directly to the memory exposed by the NVMe device.
55* The NVMe Target driver (nvmet) can orchestrate the data from the RNIC 55* The NVMe Target driver (nvmet) can orchestrate the data from the RNIC
@@ -111,7 +111,7 @@ that's compatible with all clients using :c:func:`pci_p2pmem_find()`.
111If more than one provider is supported, the one nearest to all the clients will 111If more than one provider is supported, the one nearest to all the clients will
112be chosen first. If more than one provider is an equal distance away, the 112be chosen first. If more than one provider is an equal distance away, the
113one returned will be chosen at random (it is not an arbitrary but 113one returned will be chosen at random (it is not an arbitrary but
114truely random). This function returns the PCI device to use for the provider 114truly random). This function returns the PCI device to use for the provider
115with a reference taken and therefore when it's no longer needed it should be 115with a reference taken and therefore when it's no longer needed it should be
116returned with pci_dev_put(). 116returned with pci_dev_put().
117 117
diff --git a/MAINTAINERS b/MAINTAINERS
index 5d7beffe9935..4cdf07c51ef8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11500,6 +11500,7 @@ F: include/uapi/linux/pci*
11500F: lib/pci* 11500F: lib/pci*
11501F: arch/x86/pci/ 11501F: arch/x86/pci/
11502F: arch/x86/kernel/quirks.c 11502F: arch/x86/kernel/quirks.c
11503F: arch/x86/kernel/early-quirks.c
11503 11504
11504PCI NATIVE HOST BRIDGE AND ENDPOINT DRIVERS 11505PCI NATIVE HOST BRIDGE AND ENDPOINT DRIVERS
11505M: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> 11506M: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
@@ -11509,6 +11510,13 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/lpieralisi/pci.git/
11509S: Supported 11510S: Supported
11510F: drivers/pci/controller/ 11511F: drivers/pci/controller/
11511 11512
11513PCIE DRIVER FOR AMLOGIC MESON
11514M: Yue Wang <yue.wang@Amlogic.com>
11515L: linux-pci@vger.kernel.org
11516L: linux-amlogic@lists.infradead.org
11517S: Maintained
11518F: drivers/pci/controller/dwc/pci-meson.c
11519
11512PCIE DRIVER FOR AXIS ARTPEC 11520PCIE DRIVER FOR AXIS ARTPEC
11513M: Jesper Nilsson <jesper.nilsson@axis.com> 11521M: Jesper Nilsson <jesper.nilsson@axis.com>
11514L: linux-arm-kernel@axis.com 11522L: linux-arm-kernel@axis.com
diff --git a/arch/s390/pci/pci.c b/arch/s390/pci/pci.c
index 9f6f392a4461..4266a4de3160 100644
--- a/arch/s390/pci/pci.c
+++ b/arch/s390/pci/pci.c
@@ -651,6 +651,9 @@ int pcibios_add_device(struct pci_dev *pdev)
651 struct resource *res; 651 struct resource *res;
652 int i; 652 int i;
653 653
654 if (pdev->is_physfn)
655 pdev->no_vf_scan = 1;
656
654 pdev->dev.groups = zpci_attr_groups; 657 pdev->dev.groups = zpci_attr_groups;
655 pdev->dev.dma_ops = &s390_pci_dma_ops; 658 pdev->dev.dma_ops = &s390_pci_dma_ops;
656 zpci_map_resources(pdev); 659 zpci_map_resources(pdev);
diff --git a/arch/x86/pci/broadcom_bus.c b/arch/x86/pci/broadcom_bus.c
index 526536c81ddc..ca1e8e6dccc8 100644
--- a/arch/x86/pci/broadcom_bus.c
+++ b/arch/x86/pci/broadcom_bus.c
@@ -50,8 +50,8 @@ static void __init cnb20le_res(u8 bus, u8 slot, u8 func)
50 word1 = read_pci_config_16(bus, slot, func, 0xc0); 50 word1 = read_pci_config_16(bus, slot, func, 0xc0);
51 word2 = read_pci_config_16(bus, slot, func, 0xc2); 51 word2 = read_pci_config_16(bus, slot, func, 0xc2);
52 if (word1 != word2) { 52 if (word1 != word2) {
53 res.start = (word1 << 16) | 0x0000; 53 res.start = ((resource_size_t) word1 << 16) | 0x0000;
54 res.end = (word2 << 16) | 0xffff; 54 res.end = ((resource_size_t) word2 << 16) | 0xffff;
55 res.flags = IORESOURCE_MEM; 55 res.flags = IORESOURCE_MEM;
56 update_res(info, res.start, res.end, res.flags, 0); 56 update_res(info, res.start, res.end, res.flags, 0);
57 } 57 }
diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index 2dcc30429e8b..ffe7895aa880 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -73,9 +73,9 @@ config PCI_PF_STUB
73 depends on PCI_IOV 73 depends on PCI_IOV
74 help 74 help
75 Say Y or M here if you want to enable support for devices that 75 Say Y or M here if you want to enable support for devices that
76 require SR-IOV support, while at the same time the PF itself is 76 require SR-IOV support, while at the same time the PF (Physical
77 not providing any actual services on the host itself such as 77 Function) itself is not providing any actual services on the
78 storage or networking. 78 host itself such as storage or networking.
79 79
80 When in doubt, say N. 80 When in doubt, say N.
81 81
diff --git a/drivers/pci/controller/dwc/Kconfig b/drivers/pci/controller/dwc/Kconfig
index 6aafec3fad00..0b1ab6b5e234 100644
--- a/drivers/pci/controller/dwc/Kconfig
+++ b/drivers/pci/controller/dwc/Kconfig
@@ -193,4 +193,14 @@ config PCIE_HISI_STB
193 help 193 help
194 Say Y here if you want PCIe controller support on HiSilicon STB SoCs 194 Say Y here if you want PCIe controller support on HiSilicon STB SoCs
195 195
196config PCI_MESON
197 bool "MESON PCIe controller"
198 depends on PCI_MSI_IRQ_DOMAIN
199 select PCIE_DW_HOST
200 help
201 Say Y here if you want to enable PCI controller support on Amlogic
202 SoCs. The PCI controller on Amlogic is based on DesignWare hardware
203 and therefore the driver re-uses the DesignWare core functions to
204 implement the driver.
205
196endmenu 206endmenu
diff --git a/drivers/pci/controller/dwc/Makefile b/drivers/pci/controller/dwc/Makefile
index fcf91eacfc63..e05a0153ffc4 100644
--- a/drivers/pci/controller/dwc/Makefile
+++ b/drivers/pci/controller/dwc/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_PCIE_ARMADA_8K) += pcie-armada8k.o
14obj-$(CONFIG_PCIE_ARTPEC6) += pcie-artpec6.o 14obj-$(CONFIG_PCIE_ARTPEC6) += pcie-artpec6.o
15obj-$(CONFIG_PCIE_KIRIN) += pcie-kirin.o 15obj-$(CONFIG_PCIE_KIRIN) += pcie-kirin.o
16obj-$(CONFIG_PCIE_HISI_STB) += pcie-histb.o 16obj-$(CONFIG_PCIE_HISI_STB) += pcie-histb.o
17obj-$(CONFIG_PCI_MESON) += pci-meson.o
17 18
18# The following drivers are for devices that use the generic ACPI 19# The following drivers are for devices that use the generic ACPI
19# pci_root.c driver but don't support standard ECAM config access. 20# pci_root.c driver but don't support standard ECAM config access.
diff --git a/drivers/pci/controller/dwc/pci-meson.c b/drivers/pci/controller/dwc/pci-meson.c
new file mode 100644
index 000000000000..241ebe0c4505
--- /dev/null
+++ b/drivers/pci/controller/dwc/pci-meson.c
@@ -0,0 +1,592 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * PCIe host controller driver for Amlogic MESON SoCs
4 *
5 * Copyright (c) 2018 Amlogic, inc.
6 * Author: Yue Wang <yue.wang@amlogic.com>
7 */
8
9#include <linux/clk.h>
10#include <linux/delay.h>
11#include <linux/of_device.h>
12#include <linux/of_gpio.h>
13#include <linux/pci.h>
14#include <linux/platform_device.h>
15#include <linux/reset.h>
16#include <linux/resource.h>
17#include <linux/types.h>
18
19#include "pcie-designware.h"
20
21#define to_meson_pcie(x) dev_get_drvdata((x)->dev)
22
23/* External local bus interface registers */
24#define PLR_OFFSET 0x700
25#define PCIE_PORT_LINK_CTRL_OFF (PLR_OFFSET + 0x10)
26#define FAST_LINK_MODE BIT(7)
27#define LINK_CAPABLE_MASK GENMASK(21, 16)
28#define LINK_CAPABLE_X1 BIT(16)
29
30#define PCIE_GEN2_CTRL_OFF (PLR_OFFSET + 0x10c)
31#define NUM_OF_LANES_MASK GENMASK(12, 8)
32#define NUM_OF_LANES_X1 BIT(8)
33#define DIRECT_SPEED_CHANGE BIT(17)
34
35#define TYPE1_HDR_OFFSET 0x0
36#define PCIE_STATUS_COMMAND (TYPE1_HDR_OFFSET + 0x04)
37#define PCI_IO_EN BIT(0)
38#define PCI_MEM_SPACE_EN BIT(1)
39#define PCI_BUS_MASTER_EN BIT(2)
40
41#define PCIE_BASE_ADDR0 (TYPE1_HDR_OFFSET + 0x10)
42#define PCIE_BASE_ADDR1 (TYPE1_HDR_OFFSET + 0x14)
43
44#define PCIE_CAP_OFFSET 0x70
45#define PCIE_DEV_CTRL_DEV_STUS (PCIE_CAP_OFFSET + 0x08)
46#define PCIE_CAP_MAX_PAYLOAD_MASK GENMASK(7, 5)
47#define PCIE_CAP_MAX_PAYLOAD_SIZE(x) ((x) << 5)
48#define PCIE_CAP_MAX_READ_REQ_MASK GENMASK(14, 12)
49#define PCIE_CAP_MAX_READ_REQ_SIZE(x) ((x) << 12)
50
51/* PCIe specific config registers */
52#define PCIE_CFG0 0x0
53#define APP_LTSSM_ENABLE BIT(7)
54
55#define PCIE_CFG_STATUS12 0x30
56#define IS_SMLH_LINK_UP(x) ((x) & (1 << 6))
57#define IS_RDLH_LINK_UP(x) ((x) & (1 << 16))
58#define IS_LTSSM_UP(x) ((((x) >> 10) & 0x1f) == 0x11)
59
60#define PCIE_CFG_STATUS17 0x44
61#define PM_CURRENT_STATE(x) (((x) >> 7) & 0x1)
62
63#define WAIT_LINKUP_TIMEOUT 4000
64#define PORT_CLK_RATE 100000000UL
65#define MAX_PAYLOAD_SIZE 256
66#define MAX_READ_REQ_SIZE 256
67#define MESON_PCIE_PHY_POWERUP 0x1c
68#define PCIE_RESET_DELAY 500
69#define PCIE_SHARED_RESET 1
70#define PCIE_NORMAL_RESET 0
71
72enum pcie_data_rate {
73 PCIE_GEN1,
74 PCIE_GEN2,
75 PCIE_GEN3,
76 PCIE_GEN4
77};
78
79struct meson_pcie_mem_res {
80 void __iomem *elbi_base;
81 void __iomem *cfg_base;
82 void __iomem *phy_base;
83};
84
85struct meson_pcie_clk_res {
86 struct clk *clk;
87 struct clk *mipi_gate;
88 struct clk *port_clk;
89 struct clk *general_clk;
90};
91
92struct meson_pcie_rc_reset {
93 struct reset_control *phy;
94 struct reset_control *port;
95 struct reset_control *apb;
96};
97
98struct meson_pcie {
99 struct dw_pcie pci;
100 struct meson_pcie_mem_res mem_res;
101 struct meson_pcie_clk_res clk_res;
102 struct meson_pcie_rc_reset mrst;
103 struct gpio_desc *reset_gpio;
104};
105
106static struct reset_control *meson_pcie_get_reset(struct meson_pcie *mp,
107 const char *id,
108 u32 reset_type)
109{
110 struct device *dev = mp->pci.dev;
111 struct reset_control *reset;
112
113 if (reset_type == PCIE_SHARED_RESET)
114 reset = devm_reset_control_get_shared(dev, id);
115 else
116 reset = devm_reset_control_get(dev, id);
117
118 return reset;
119}
120
121static int meson_pcie_get_resets(struct meson_pcie *mp)
122{
123 struct meson_pcie_rc_reset *mrst = &mp->mrst;
124
125 mrst->phy = meson_pcie_get_reset(mp, "phy", PCIE_SHARED_RESET);
126 if (IS_ERR(mrst->phy))
127 return PTR_ERR(mrst->phy);
128 reset_control_deassert(mrst->phy);
129
130 mrst->port = meson_pcie_get_reset(mp, "port", PCIE_NORMAL_RESET);
131 if (IS_ERR(mrst->port))
132 return PTR_ERR(mrst->port);
133 reset_control_deassert(mrst->port);
134
135 mrst->apb = meson_pcie_get_reset(mp, "apb", PCIE_SHARED_RESET);
136 if (IS_ERR(mrst->apb))
137 return PTR_ERR(mrst->apb);
138 reset_control_deassert(mrst->apb);
139
140 return 0;
141}
142
143static void __iomem *meson_pcie_get_mem(struct platform_device *pdev,
144 struct meson_pcie *mp,
145 const char *id)
146{
147 struct device *dev = mp->pci.dev;
148 struct resource *res;
149
150 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, id);
151
152 return devm_ioremap_resource(dev, res);
153}
154
155static void __iomem *meson_pcie_get_mem_shared(struct platform_device *pdev,
156 struct meson_pcie *mp,
157 const char *id)
158{
159 struct device *dev = mp->pci.dev;
160 struct resource *res;
161
162 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, id);
163 if (!res) {
164 dev_err(dev, "No REG resource %s\n", id);
165 return ERR_PTR(-ENXIO);
166 }
167
168 return devm_ioremap(dev, res->start, resource_size(res));
169}
170
171static int meson_pcie_get_mems(struct platform_device *pdev,
172 struct meson_pcie *mp)
173{
174 mp->mem_res.elbi_base = meson_pcie_get_mem(pdev, mp, "elbi");
175 if (IS_ERR(mp->mem_res.elbi_base))
176 return PTR_ERR(mp->mem_res.elbi_base);
177
178 mp->mem_res.cfg_base = meson_pcie_get_mem(pdev, mp, "cfg");
179 if (IS_ERR(mp->mem_res.cfg_base))
180 return PTR_ERR(mp->mem_res.cfg_base);
181
182 /* Meson SoC has two PCI controllers use same phy register*/
183 mp->mem_res.phy_base = meson_pcie_get_mem_shared(pdev, mp, "phy");
184 if (IS_ERR(mp->mem_res.phy_base))
185 return PTR_ERR(mp->mem_res.phy_base);
186
187 return 0;
188}
189
190static void meson_pcie_power_on(struct meson_pcie *mp)
191{
192 writel(MESON_PCIE_PHY_POWERUP, mp->mem_res.phy_base);
193}
194
195static void meson_pcie_reset(struct meson_pcie *mp)
196{
197 struct meson_pcie_rc_reset *mrst = &mp->mrst;
198
199 reset_control_assert(mrst->phy);
200 udelay(PCIE_RESET_DELAY);
201 reset_control_deassert(mrst->phy);
202 udelay(PCIE_RESET_DELAY);
203
204 reset_control_assert(mrst->port);
205 reset_control_assert(mrst->apb);
206 udelay(PCIE_RESET_DELAY);
207 reset_control_deassert(mrst->port);
208 reset_control_deassert(mrst->apb);
209 udelay(PCIE_RESET_DELAY);
210}
211
212static inline struct clk *meson_pcie_probe_clock(struct device *dev,
213 const char *id, u64 rate)
214{
215 struct clk *clk;
216 int ret;
217
218 clk = devm_clk_get(dev, id);
219 if (IS_ERR(clk))
220 return clk;
221
222 if (rate) {
223 ret = clk_set_rate(clk, rate);
224 if (ret) {
225 dev_err(dev, "set clk rate failed, ret = %d\n", ret);
226 return ERR_PTR(ret);
227 }
228 }
229
230 ret = clk_prepare_enable(clk);
231 if (ret) {
232 dev_err(dev, "couldn't enable clk\n");
233 return ERR_PTR(ret);
234 }
235
236 devm_add_action_or_reset(dev,
237 (void (*) (void *))clk_disable_unprepare,
238 clk);
239
240 return clk;
241}
242
243static int meson_pcie_probe_clocks(struct meson_pcie *mp)
244{
245 struct device *dev = mp->pci.dev;
246 struct meson_pcie_clk_res *res = &mp->clk_res;
247
248 res->port_clk = meson_pcie_probe_clock(dev, "port", PORT_CLK_RATE);
249 if (IS_ERR(res->port_clk))
250 return PTR_ERR(res->port_clk);
251
252 res->mipi_gate = meson_pcie_probe_clock(dev, "pcie_mipi_en", 0);
253 if (IS_ERR(res->mipi_gate))
254 return PTR_ERR(res->mipi_gate);
255
256 res->general_clk = meson_pcie_probe_clock(dev, "pcie_general", 0);
257 if (IS_ERR(res->general_clk))
258 return PTR_ERR(res->general_clk);
259
260 res->clk = meson_pcie_probe_clock(dev, "pcie", 0);
261 if (IS_ERR(res->clk))
262 return PTR_ERR(res->clk);
263
264 return 0;
265}
266
267static inline void meson_elb_writel(struct meson_pcie *mp, u32 val, u32 reg)
268{
269 writel(val, mp->mem_res.elbi_base + reg);
270}
271
272static inline u32 meson_elb_readl(struct meson_pcie *mp, u32 reg)
273{
274 return readl(mp->mem_res.elbi_base + reg);
275}
276
277static inline u32 meson_cfg_readl(struct meson_pcie *mp, u32 reg)
278{
279 return readl(mp->mem_res.cfg_base + reg);
280}
281
282static inline void meson_cfg_writel(struct meson_pcie *mp, u32 val, u32 reg)
283{
284 writel(val, mp->mem_res.cfg_base + reg);
285}
286
287static void meson_pcie_assert_reset(struct meson_pcie *mp)
288{
289 gpiod_set_value_cansleep(mp->reset_gpio, 0);
290 udelay(500);
291 gpiod_set_value_cansleep(mp->reset_gpio, 1);
292}
293
294static void meson_pcie_init_dw(struct meson_pcie *mp)
295{
296 u32 val;
297
298 val = meson_cfg_readl(mp, PCIE_CFG0);
299 val |= APP_LTSSM_ENABLE;
300 meson_cfg_writel(mp, val, PCIE_CFG0);
301
302 val = meson_elb_readl(mp, PCIE_PORT_LINK_CTRL_OFF);
303 val &= ~LINK_CAPABLE_MASK;
304 meson_elb_writel(mp, val, PCIE_PORT_LINK_CTRL_OFF);
305
306 val = meson_elb_readl(mp, PCIE_PORT_LINK_CTRL_OFF);
307 val |= LINK_CAPABLE_X1 | FAST_LINK_MODE;
308 meson_elb_writel(mp, val, PCIE_PORT_LINK_CTRL_OFF);
309
310 val = meson_elb_readl(mp, PCIE_GEN2_CTRL_OFF);
311 val &= ~NUM_OF_LANES_MASK;
312 meson_elb_writel(mp, val, PCIE_GEN2_CTRL_OFF);
313
314 val = meson_elb_readl(mp, PCIE_GEN2_CTRL_OFF);
315 val |= NUM_OF_LANES_X1 | DIRECT_SPEED_CHANGE;
316 meson_elb_writel(mp, val, PCIE_GEN2_CTRL_OFF);
317
318 meson_elb_writel(mp, 0x0, PCIE_BASE_ADDR0);
319 meson_elb_writel(mp, 0x0, PCIE_BASE_ADDR1);
320}
321
322static int meson_size_to_payload(struct meson_pcie *mp, int size)
323{
324 struct device *dev = mp->pci.dev;
325
326 /*
327 * dwc supports 2^(val+7) payload size, which val is 0~5 default to 1.
328 * So if input size is not 2^order alignment or less than 2^7 or bigger
329 * than 2^12, just set to default size 2^(1+7).
330 */
331 if (!is_power_of_2(size) || size < 128 || size > 4096) {
332 dev_warn(dev, "payload size %d, set to default 256\n", size);
333 return 1;
334 }
335
336 return fls(size) - 8;
337}
338
339static void meson_set_max_payload(struct meson_pcie *mp, int size)
340{
341 u32 val;
342 int max_payload_size = meson_size_to_payload(mp, size);
343
344 val = meson_elb_readl(mp, PCIE_DEV_CTRL_DEV_STUS);
345 val &= ~PCIE_CAP_MAX_PAYLOAD_MASK;
346 meson_elb_writel(mp, val, PCIE_DEV_CTRL_DEV_STUS);
347
348 val = meson_elb_readl(mp, PCIE_DEV_CTRL_DEV_STUS);
349 val |= PCIE_CAP_MAX_PAYLOAD_SIZE(max_payload_size);
350 meson_elb_writel(mp, val, PCIE_DEV_CTRL_DEV_STUS);
351}
352
353static void meson_set_max_rd_req_size(struct meson_pcie *mp, int size)
354{
355 u32 val;
356 int max_rd_req_size = meson_size_to_payload(mp, size);
357
358 val = meson_elb_readl(mp, PCIE_DEV_CTRL_DEV_STUS);
359 val &= ~PCIE_CAP_MAX_READ_REQ_MASK;
360 meson_elb_writel(mp, val, PCIE_DEV_CTRL_DEV_STUS);
361
362 val = meson_elb_readl(mp, PCIE_DEV_CTRL_DEV_STUS);
363 val |= PCIE_CAP_MAX_READ_REQ_SIZE(max_rd_req_size);
364 meson_elb_writel(mp, val, PCIE_DEV_CTRL_DEV_STUS);
365}
366
367static inline void meson_enable_memory_space(struct meson_pcie *mp)
368{
369 /* Set the RC Bus Master, Memory Space and I/O Space enables */
370 meson_elb_writel(mp, PCI_IO_EN | PCI_MEM_SPACE_EN | PCI_BUS_MASTER_EN,
371 PCIE_STATUS_COMMAND);
372}
373
374static int meson_pcie_establish_link(struct meson_pcie *mp)
375{
376 struct dw_pcie *pci = &mp->pci;
377 struct pcie_port *pp = &pci->pp;
378
379 meson_pcie_init_dw(mp);
380 meson_set_max_payload(mp, MAX_PAYLOAD_SIZE);
381 meson_set_max_rd_req_size(mp, MAX_READ_REQ_SIZE);
382
383 dw_pcie_setup_rc(pp);
384 meson_enable_memory_space(mp);
385
386 meson_pcie_assert_reset(mp);
387
388 return dw_pcie_wait_for_link(pci);
389}
390
391static void meson_pcie_enable_interrupts(struct meson_pcie *mp)
392{
393 if (IS_ENABLED(CONFIG_PCI_MSI))
394 dw_pcie_msi_init(&mp->pci.pp);
395}
396
397static int meson_pcie_rd_own_conf(struct pcie_port *pp, int where, int size,
398 u32 *val)
399{
400 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
401 int ret;
402
403 ret = dw_pcie_read(pci->dbi_base + where, size, val);
404 if (ret != PCIBIOS_SUCCESSFUL)
405 return ret;
406
407 /*
408 * There is a bug in the MESON AXG PCIe controller whereby software
409 * cannot program the PCI_CLASS_DEVICE register, so we must fabricate
410 * the return value in the config accessors.
411 */
412 if (where == PCI_CLASS_REVISION && size == 4)
413 *val = (PCI_CLASS_BRIDGE_PCI << 16) | (*val & 0xffff);
414 else if (where == PCI_CLASS_DEVICE && size == 2)
415 *val = PCI_CLASS_BRIDGE_PCI;
416 else if (where == PCI_CLASS_DEVICE && size == 1)
417 *val = PCI_CLASS_BRIDGE_PCI & 0xff;
418 else if (where == PCI_CLASS_DEVICE + 1 && size == 1)
419 *val = (PCI_CLASS_BRIDGE_PCI >> 8) & 0xff;
420
421 return PCIBIOS_SUCCESSFUL;
422}
423
424static int meson_pcie_wr_own_conf(struct pcie_port *pp, int where,
425 int size, u32 val)
426{
427 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
428
429 return dw_pcie_write(pci->dbi_base + where, size, val);
430}
431
432static int meson_pcie_link_up(struct dw_pcie *pci)
433{
434 struct meson_pcie *mp = to_meson_pcie(pci);
435 struct device *dev = pci->dev;
436 u32 speed_okay = 0;
437 u32 cnt = 0;
438 u32 state12, state17, smlh_up, ltssm_up, rdlh_up;
439
440 do {
441 state12 = meson_cfg_readl(mp, PCIE_CFG_STATUS12);
442 state17 = meson_cfg_readl(mp, PCIE_CFG_STATUS17);
443 smlh_up = IS_SMLH_LINK_UP(state12);
444 rdlh_up = IS_RDLH_LINK_UP(state12);
445 ltssm_up = IS_LTSSM_UP(state12);
446
447 if (PM_CURRENT_STATE(state17) < PCIE_GEN3)
448 speed_okay = 1;
449
450 if (smlh_up)
451 dev_dbg(dev, "smlh_link_up is on\n");
452 if (rdlh_up)
453 dev_dbg(dev, "rdlh_link_up is on\n");
454 if (ltssm_up)
455 dev_dbg(dev, "ltssm_up is on\n");
456 if (speed_okay)
457 dev_dbg(dev, "speed_okay\n");
458
459 if (smlh_up && rdlh_up && ltssm_up && speed_okay)
460 return 1;
461
462 cnt++;
463
464 udelay(10);
465 } while (cnt < WAIT_LINKUP_TIMEOUT);
466
467 dev_err(dev, "error: wait linkup timeout\n");
468 return 0;
469}
470
471static int meson_pcie_host_init(struct pcie_port *pp)
472{
473 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
474 struct meson_pcie *mp = to_meson_pcie(pci);
475 int ret;
476
477 ret = meson_pcie_establish_link(mp);
478 if (ret)
479 return ret;
480
481 meson_pcie_enable_interrupts(mp);
482
483 return 0;
484}
485
486static const struct dw_pcie_host_ops meson_pcie_host_ops = {
487 .rd_own_conf = meson_pcie_rd_own_conf,
488 .wr_own_conf = meson_pcie_wr_own_conf,
489 .host_init = meson_pcie_host_init,
490};
491
492static int meson_add_pcie_port(struct meson_pcie *mp,
493 struct platform_device *pdev)
494{
495 struct dw_pcie *pci = &mp->pci;
496 struct pcie_port *pp = &pci->pp;
497 struct device *dev = &pdev->dev;
498 int ret;
499
500 if (IS_ENABLED(CONFIG_PCI_MSI)) {
501 pp->msi_irq = platform_get_irq(pdev, 0);
502 if (pp->msi_irq < 0) {
503 dev_err(dev, "failed to get MSI IRQ\n");
504 return pp->msi_irq;
505 }
506 }
507
508 pp->ops = &meson_pcie_host_ops;
509 pci->dbi_base = mp->mem_res.elbi_base;
510
511 ret = dw_pcie_host_init(pp);
512 if (ret) {
513 dev_err(dev, "failed to initialize host\n");
514 return ret;
515 }
516
517 return 0;
518}
519
520static const struct dw_pcie_ops dw_pcie_ops = {
521 .link_up = meson_pcie_link_up,
522};
523
524static int meson_pcie_probe(struct platform_device *pdev)
525{
526 struct device *dev = &pdev->dev;
527 struct dw_pcie *pci;
528 struct meson_pcie *mp;
529 int ret;
530
531 mp = devm_kzalloc(dev, sizeof(*mp), GFP_KERNEL);
532 if (!mp)
533 return -ENOMEM;
534
535 pci = &mp->pci;
536 pci->dev = dev;
537 pci->ops = &dw_pcie_ops;
538
539 mp->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
540 if (IS_ERR(mp->reset_gpio)) {
541 dev_err(dev, "get reset gpio failed\n");
542 return PTR_ERR(mp->reset_gpio);
543 }
544
545 ret = meson_pcie_get_resets(mp);
546 if (ret) {
547 dev_err(dev, "get reset resource failed, %d\n", ret);
548 return ret;
549 }
550
551 ret = meson_pcie_get_mems(pdev, mp);
552 if (ret) {
553 dev_err(dev, "get memory resource failed, %d\n", ret);
554 return ret;
555 }
556
557 meson_pcie_power_on(mp);
558 meson_pcie_reset(mp);
559
560 ret = meson_pcie_probe_clocks(mp);
561 if (ret) {
562 dev_err(dev, "init clock resources failed, %d\n", ret);
563 return ret;
564 }
565
566 platform_set_drvdata(pdev, mp);
567
568 ret = meson_add_pcie_port(mp, pdev);
569 if (ret < 0) {
570 dev_err(dev, "Add PCIe port failed, %d\n", ret);
571 return ret;
572 }
573
574 return 0;
575}
576
577static const struct of_device_id meson_pcie_of_match[] = {
578 {
579 .compatible = "amlogic,axg-pcie",
580 },
581 {},
582};
583
584static struct platform_driver meson_pcie_driver = {
585 .probe = meson_pcie_probe,
586 .driver = {
587 .name = "meson-pcie",
588 .of_match_table = meson_pcie_of_match,
589 },
590};
591
592builtin_platform_driver(meson_pcie_driver);
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index 9616eca3182f..3aa115ed3a65 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -252,6 +252,27 @@ int __weak pcibios_sriov_disable(struct pci_dev *pdev)
252 return 0; 252 return 0;
253} 253}
254 254
255static int sriov_add_vfs(struct pci_dev *dev, u16 num_vfs)
256{
257 unsigned int i;
258 int rc;
259
260 if (dev->no_vf_scan)
261 return 0;
262
263 for (i = 0; i < num_vfs; i++) {
264 rc = pci_iov_add_virtfn(dev, i);
265 if (rc)
266 goto failed;
267 }
268 return 0;
269failed:
270 while (i--)
271 pci_iov_remove_virtfn(dev, i);
272
273 return rc;
274}
275
255static int sriov_enable(struct pci_dev *dev, int nr_virtfn) 276static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
256{ 277{
257 int rc; 278 int rc;
@@ -337,21 +358,15 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
337 msleep(100); 358 msleep(100);
338 pci_cfg_access_unlock(dev); 359 pci_cfg_access_unlock(dev);
339 360
340 for (i = 0; i < initial; i++) { 361 rc = sriov_add_vfs(dev, initial);
341 rc = pci_iov_add_virtfn(dev, i); 362 if (rc)
342 if (rc) 363 goto err_pcibios;
343 goto failed;
344 }
345 364
346 kobject_uevent(&dev->dev.kobj, KOBJ_CHANGE); 365 kobject_uevent(&dev->dev.kobj, KOBJ_CHANGE);
347 iov->num_VFs = nr_virtfn; 366 iov->num_VFs = nr_virtfn;
348 367
349 return 0; 368 return 0;
350 369
351failed:
352 while (i--)
353 pci_iov_remove_virtfn(dev, i);
354
355err_pcibios: 370err_pcibios:
356 iov->ctrl &= ~(PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE); 371 iov->ctrl &= ~(PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE);
357 pci_cfg_access_lock(dev); 372 pci_cfg_access_lock(dev);
@@ -368,17 +383,26 @@ err_pcibios:
368 return rc; 383 return rc;
369} 384}
370 385
371static void sriov_disable(struct pci_dev *dev) 386static void sriov_del_vfs(struct pci_dev *dev)
372{ 387{
373 int i;
374 struct pci_sriov *iov = dev->sriov; 388 struct pci_sriov *iov = dev->sriov;
389 int i;
375 390
376 if (!iov->num_VFs) 391 if (dev->no_vf_scan)
377 return; 392 return;
378 393
379 for (i = 0; i < iov->num_VFs; i++) 394 for (i = 0; i < iov->num_VFs; i++)
380 pci_iov_remove_virtfn(dev, i); 395 pci_iov_remove_virtfn(dev, i);
396}
397
398static void sriov_disable(struct pci_dev *dev)
399{
400 struct pci_sriov *iov = dev->sriov;
401
402 if (!iov->num_VFs)
403 return;
381 404
405 sriov_del_vfs(dev);
382 iov->ctrl &= ~(PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE); 406 iov->ctrl &= ~(PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE);
383 pci_cfg_access_lock(dev); 407 pci_cfg_access_lock(dev);
384 pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl); 408 pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl);
diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c
index ae3c5b25dcc7..c25a69fc4fc7 100644
--- a/drivers/pci/p2pdma.c
+++ b/drivers/pci/p2pdma.c
@@ -422,7 +422,7 @@ static int upstream_bridge_distance_warn(struct pci_dev *provider,
422 * 422 *
423 * Returns -1 if any of the clients are not compatible (behind the same 423 * Returns -1 if any of the clients are not compatible (behind the same
424 * root port as the provider), otherwise returns a positive number where 424 * root port as the provider), otherwise returns a positive number where
425 * a lower number is the preferrable choice. (If there's one client 425 * a lower number is the preferable choice. (If there's one client
426 * that's the same as the provider it will return 0, which is best choice). 426 * that's the same as the provider it will return 0, which is best choice).
427 * 427 *
428 * For now, "compatible" means the provider and the clients are all behind 428 * For now, "compatible" means the provider and the clients are all behind
@@ -493,7 +493,7 @@ EXPORT_SYMBOL_GPL(pci_has_p2pmem);
493 * @num_clients: number of client devices in the list 493 * @num_clients: number of client devices in the list
494 * 494 *
495 * If multiple devices are behind the same switch, the one "closest" to the 495 * If multiple devices are behind the same switch, the one "closest" to the
496 * client devices in use will be chosen first. (So if one of the providers are 496 * client devices in use will be chosen first. (So if one of the providers is
497 * the same as one of the clients, that provider will be used ahead of any 497 * the same as one of the clients, that provider will be used ahead of any
498 * other providers that are unrelated). If multiple providers are an equal 498 * other providers that are unrelated). If multiple providers are an equal
499 * distance away, one will be chosen at random. 499 * distance away, one will be chosen at random.
@@ -580,7 +580,7 @@ EXPORT_SYMBOL_GPL(pci_alloc_p2pmem);
580 * pci_free_p2pmem - free peer-to-peer DMA memory 580 * pci_free_p2pmem - free peer-to-peer DMA memory
581 * @pdev: the device the memory was allocated from 581 * @pdev: the device the memory was allocated from
582 * @addr: address of the memory that was allocated 582 * @addr: address of the memory that was allocated
583 * @size: number of bytes that was allocated 583 * @size: number of bytes that were allocated
584 */ 584 */
585void pci_free_p2pmem(struct pci_dev *pdev, void *addr, size_t size) 585void pci_free_p2pmem(struct pci_dev *pdev, void *addr, size_t size)
586{ 586{
@@ -617,7 +617,7 @@ EXPORT_SYMBOL_GPL(pci_p2pmem_virt_to_bus);
617 * @nents: the number of SG entries in the list 617 * @nents: the number of SG entries in the list
618 * @length: number of bytes to allocate 618 * @length: number of bytes to allocate
619 * 619 *
620 * Returns 0 on success 620 * Return: %NULL on error or &struct scatterlist pointer and @nents on success
621 */ 621 */
622struct scatterlist *pci_p2pmem_alloc_sgl(struct pci_dev *pdev, 622struct scatterlist *pci_p2pmem_alloc_sgl(struct pci_dev *pdev,
623 unsigned int *nents, u32 length) 623 unsigned int *nents, u32 length)
@@ -673,7 +673,7 @@ EXPORT_SYMBOL_GPL(pci_p2pmem_free_sgl);
673 * 673 *
674 * Published memory can be used by other PCI device drivers for 674 * Published memory can be used by other PCI device drivers for
675 * peer-2-peer DMA operations. Non-published memory is reserved for 675 * peer-2-peer DMA operations. Non-published memory is reserved for
676 * exlusive use of the device driver that registers the peer-to-peer 676 * exclusive use of the device driver that registers the peer-to-peer
677 * memory. 677 * memory.
678 */ 678 */
679void pci_p2pmem_publish(struct pci_dev *pdev, bool publish) 679void pci_p2pmem_publish(struct pci_dev *pdev, bool publish)
@@ -733,7 +733,7 @@ EXPORT_SYMBOL_GPL(pci_p2pdma_map_sg);
733 * @use_p2pdma: returns whether to enable p2pdma or not 733 * @use_p2pdma: returns whether to enable p2pdma or not
734 * 734 *
735 * Parses an attribute value to decide whether to enable p2pdma. 735 * Parses an attribute value to decide whether to enable p2pdma.
736 * The value can select a PCI device (using it's full BDF device 736 * The value can select a PCI device (using its full BDF device
737 * name) or a boolean (in any format strtobool() accepts). A false 737 * name) or a boolean (in any format strtobool() accepts). A false
738 * value disables p2pdma, a true value expects the caller 738 * value disables p2pdma, a true value expects the caller
739 * to automatically find a compatible device and specifying a PCI device 739 * to automatically find a compatible device and specifying a PCI device
@@ -784,7 +784,7 @@ EXPORT_SYMBOL_GPL(pci_p2pdma_enable_store);
784 * whether p2pdma is enabled 784 * whether p2pdma is enabled
785 * @page: contents of the stored value 785 * @page: contents of the stored value
786 * @p2p_dev: the selected p2p device (NULL if no device is selected) 786 * @p2p_dev: the selected p2p device (NULL if no device is selected)
787 * @use_p2pdma: whether p2pdme has been enabled 787 * @use_p2pdma: whether p2pdma has been enabled
788 * 788 *
789 * Attributes that use pci_p2pdma_enable_store() should use this function 789 * Attributes that use pci_p2pdma_enable_store() should use this function
790 * to show the value of the attribute. 790 * to show the value of the attribute.
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index bef17c3fca67..33f3f475e5c6 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -1251,30 +1251,29 @@ static int pci_pm_runtime_suspend(struct device *dev)
1251 return 0; 1251 return 0;
1252 } 1252 }
1253 1253
1254 if (!pm || !pm->runtime_suspend)
1255 return -ENOSYS;
1256
1257 pci_dev->state_saved = false; 1254 pci_dev->state_saved = false;
1258 error = pm->runtime_suspend(dev); 1255 if (pm && pm->runtime_suspend) {
1259 if (error) { 1256 error = pm->runtime_suspend(dev);
1260 /* 1257 /*
1261 * -EBUSY and -EAGAIN is used to request the runtime PM core 1258 * -EBUSY and -EAGAIN is used to request the runtime PM core
1262 * to schedule a new suspend, so log the event only with debug 1259 * to schedule a new suspend, so log the event only with debug
1263 * log level. 1260 * log level.
1264 */ 1261 */
1265 if (error == -EBUSY || error == -EAGAIN) 1262 if (error == -EBUSY || error == -EAGAIN) {
1266 dev_dbg(dev, "can't suspend now (%pf returned %d)\n", 1263 dev_dbg(dev, "can't suspend now (%pf returned %d)\n",
1267 pm->runtime_suspend, error); 1264 pm->runtime_suspend, error);
1268 else 1265 return error;
1266 } else if (error) {
1269 dev_err(dev, "can't suspend (%pf returned %d)\n", 1267 dev_err(dev, "can't suspend (%pf returned %d)\n",
1270 pm->runtime_suspend, error); 1268 pm->runtime_suspend, error);
1271 1269 return error;
1272 return error; 1270 }
1273 } 1271 }
1274 1272
1275 pci_fixup_device(pci_fixup_suspend, pci_dev); 1273 pci_fixup_device(pci_fixup_suspend, pci_dev);
1276 1274
1277 if (!pci_dev->state_saved && pci_dev->current_state != PCI_D0 1275 if (pm && pm->runtime_suspend
1276 && !pci_dev->state_saved && pci_dev->current_state != PCI_D0
1278 && pci_dev->current_state != PCI_UNKNOWN) { 1277 && pci_dev->current_state != PCI_UNKNOWN) {
1279 WARN_ONCE(pci_dev->current_state != prev, 1278 WARN_ONCE(pci_dev->current_state != prev,
1280 "PCI PM: State of device not saved by %pF\n", 1279 "PCI PM: State of device not saved by %pF\n",
@@ -1292,7 +1291,7 @@ static int pci_pm_runtime_suspend(struct device *dev)
1292 1291
1293static int pci_pm_runtime_resume(struct device *dev) 1292static int pci_pm_runtime_resume(struct device *dev)
1294{ 1293{
1295 int rc; 1294 int rc = 0;
1296 struct pci_dev *pci_dev = to_pci_dev(dev); 1295 struct pci_dev *pci_dev = to_pci_dev(dev);
1297 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; 1296 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
1298 1297
@@ -1306,14 +1305,12 @@ static int pci_pm_runtime_resume(struct device *dev)
1306 if (!pci_dev->driver) 1305 if (!pci_dev->driver)
1307 return 0; 1306 return 0;
1308 1307
1309 if (!pm || !pm->runtime_resume)
1310 return -ENOSYS;
1311
1312 pci_fixup_device(pci_fixup_resume_early, pci_dev); 1308 pci_fixup_device(pci_fixup_resume_early, pci_dev);
1313 pci_enable_wake(pci_dev, PCI_D0, false); 1309 pci_enable_wake(pci_dev, PCI_D0, false);
1314 pci_fixup_device(pci_fixup_resume, pci_dev); 1310 pci_fixup_device(pci_fixup_resume, pci_dev);
1315 1311
1316 rc = pm->runtime_resume(dev); 1312 if (pm && pm->runtime_resume)
1313 rc = pm->runtime_resume(dev);
1317 1314
1318 pci_dev->runtime_d3cold = false; 1315 pci_dev->runtime_d3cold = false;
1319 1316
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 662b7457db23..224d88634115 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -2,6 +2,8 @@
2#ifndef DRIVERS_PCI_H 2#ifndef DRIVERS_PCI_H
3#define DRIVERS_PCI_H 3#define DRIVERS_PCI_H
4 4
5#include <linux/pci.h>
6
5#define PCI_FIND_CAP_TTL 48 7#define PCI_FIND_CAP_TTL 48
6 8
7#define PCI_VSEC_ID_INTEL_TBT 0x1234 /* Thunderbolt */ 9#define PCI_VSEC_ID_INTEL_TBT 0x1234 /* Thunderbolt */
diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index dcb29cb76dc6..2330ebf6df72 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -53,8 +53,6 @@ struct pcie_link_state {
53 struct pcie_link_state *root; /* pointer to the root port link */ 53 struct pcie_link_state *root; /* pointer to the root port link */
54 struct pcie_link_state *parent; /* pointer to the parent Link state */ 54 struct pcie_link_state *parent; /* pointer to the parent Link state */
55 struct list_head sibling; /* node in link_list */ 55 struct list_head sibling; /* node in link_list */
56 struct list_head children; /* list of child link states */
57 struct list_head link; /* node in parent's children list */
58 56
59 /* ASPM state */ 57 /* ASPM state */
60 u32 aspm_support:7; /* Supported ASPM state */ 58 u32 aspm_support:7; /* Supported ASPM state */
@@ -850,8 +848,6 @@ static struct pcie_link_state *alloc_pcie_link_state(struct pci_dev *pdev)
850 return NULL; 848 return NULL;
851 849
852 INIT_LIST_HEAD(&link->sibling); 850 INIT_LIST_HEAD(&link->sibling);
853 INIT_LIST_HEAD(&link->children);
854 INIT_LIST_HEAD(&link->link);
855 link->pdev = pdev; 851 link->pdev = pdev;
856 link->downstream = pci_function_0(pdev->subordinate); 852 link->downstream = pci_function_0(pdev->subordinate);
857 853
@@ -877,7 +873,6 @@ static struct pcie_link_state *alloc_pcie_link_state(struct pci_dev *pdev)
877 873
878 link->parent = parent; 874 link->parent = parent;
879 link->root = link->parent->root; 875 link->root = link->parent->root;
880 list_add(&link->link, &parent->children);
881 } 876 }
882 877
883 list_add(&link->sibling, &link_list); 878 list_add(&link->sibling, &link_list);
@@ -1001,7 +996,6 @@ void pcie_aspm_exit_link_state(struct pci_dev *pdev)
1001 /* All functions are removed, so just disable ASPM for the link */ 996 /* All functions are removed, so just disable ASPM for the link */
1002 pcie_config_aspm_link(link, 0); 997 pcie_config_aspm_link(link, 0);
1003 list_del(&link->sibling); 998 list_del(&link->sibling);
1004 list_del(&link->link);
1005 /* Clock PM is for endpoint device */ 999 /* Clock PM is for endpoint device */
1006 free_link_state(link); 1000 free_link_state(link);
1007 1001
diff --git a/drivers/pci/pcie/portdrv.h b/drivers/pci/pcie/portdrv.h
index e495f04394d0..fbbf00b0992e 100644
--- a/drivers/pci/pcie/portdrv.h
+++ b/drivers/pci/pcie/portdrv.h
@@ -71,19 +71,19 @@ static inline void *get_service_data(struct pcie_device *dev)
71 71
72struct pcie_port_service_driver { 72struct pcie_port_service_driver {
73 const char *name; 73 const char *name;
74 int (*probe) (struct pcie_device *dev); 74 int (*probe)(struct pcie_device *dev);
75 void (*remove) (struct pcie_device *dev); 75 void (*remove)(struct pcie_device *dev);
76 int (*suspend) (struct pcie_device *dev); 76 int (*suspend)(struct pcie_device *dev);
77 int (*resume_noirq) (struct pcie_device *dev); 77 int (*resume_noirq)(struct pcie_device *dev);
78 int (*resume) (struct pcie_device *dev); 78 int (*resume)(struct pcie_device *dev);
79 int (*runtime_suspend) (struct pcie_device *dev); 79 int (*runtime_suspend)(struct pcie_device *dev);
80 int (*runtime_resume) (struct pcie_device *dev); 80 int (*runtime_resume)(struct pcie_device *dev);
81 81
82 /* Device driver may resume normal operations */ 82 /* Device driver may resume normal operations */
83 void (*error_resume)(struct pci_dev *dev); 83 void (*error_resume)(struct pci_dev *dev);
84 84
85 /* Link Reset Capability - AER service driver specific */ 85 /* Link Reset Capability - AER service driver specific */
86 pci_ers_result_t (*reset_link) (struct pci_dev *dev); 86 pci_ers_result_t (*reset_link)(struct pci_dev *dev);
87 87
88 int port_type; /* Type of the port this driver can handle */ 88 int port_type; /* Type of the port this driver can handle */
89 u32 service; /* Port service this device represents */ 89 u32 service; /* Port service this device represents */
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 4700d24e5d55..b0a413f3f7ca 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -619,6 +619,30 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_NL_USB,
619 quirk_amd_nl_class); 619 quirk_amd_nl_class);
620 620
621/* 621/*
622 * Synopsys USB 3.x host HAPS platform has a class code of
623 * PCI_CLASS_SERIAL_USB_XHCI, and xhci driver can claim it. However, these
624 * devices should use dwc3-haps driver. Change these devices' class code to
625 * PCI_CLASS_SERIAL_USB_DEVICE to prevent the xhci-pci driver from claiming
626 * them.
627 */
628static void quirk_synopsys_haps(struct pci_dev *pdev)
629{
630 u32 class = pdev->class;
631
632 switch (pdev->device) {
633 case PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3:
634 case PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI:
635 case PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31:
636 pdev->class = PCI_CLASS_SERIAL_USB_DEVICE;
637 pci_info(pdev, "PCI class overridden (%#08x -> %#08x) so dwc3 driver can claim this instead of xhci\n",
638 class, pdev->class);
639 break;
640 }
641}
642DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SYNOPSYS, PCI_ANY_ID,
643 quirk_synopsys_haps);
644
645/*
622 * Let's make the southbridge information explicit instead of having to 646 * Let's make the southbridge information explicit instead of having to
623 * worry about people probing the ACPI areas, for example.. (Yes, it 647 * worry about people probing the ACPI areas, for example.. (Yes, it
624 * happens, and if you read the wrong ACPI register it will put the machine 648 * happens, and if you read the wrong ACPI register it will put the machine
diff --git a/drivers/pci/switch/switchtec.c b/drivers/pci/switch/switchtec.c
index 54a8b30dda38..6c5536d3d42a 100644
--- a/drivers/pci/switch/switchtec.c
+++ b/drivers/pci/switch/switchtec.c
@@ -13,7 +13,7 @@
13#include <linux/uaccess.h> 13#include <linux/uaccess.h>
14#include <linux/poll.h> 14#include <linux/poll.h>
15#include <linux/wait.h> 15#include <linux/wait.h>
16 16#include <linux/io-64-nonatomic-lo-hi.h>
17#include <linux/nospec.h> 17#include <linux/nospec.h>
18 18
19MODULE_DESCRIPTION("Microsemi Switchtec(tm) PCIe Management Driver"); 19MODULE_DESCRIPTION("Microsemi Switchtec(tm) PCIe Management Driver");
@@ -25,6 +25,11 @@ static int max_devices = 16;
25module_param(max_devices, int, 0644); 25module_param(max_devices, int, 0644);
26MODULE_PARM_DESC(max_devices, "max number of switchtec device instances"); 26MODULE_PARM_DESC(max_devices, "max number of switchtec device instances");
27 27
28static bool use_dma_mrpc = 1;
29module_param(use_dma_mrpc, bool, 0644);
30MODULE_PARM_DESC(use_dma_mrpc,
31 "Enable the use of the DMA MRPC feature");
32
28static dev_t switchtec_devt; 33static dev_t switchtec_devt;
29static DEFINE_IDA(switchtec_minor_ida); 34static DEFINE_IDA(switchtec_minor_ida);
30 35
@@ -113,6 +118,19 @@ static void stuser_set_state(struct switchtec_user *stuser,
113 118
114static void mrpc_complete_cmd(struct switchtec_dev *stdev); 119static void mrpc_complete_cmd(struct switchtec_dev *stdev);
115 120
121static void flush_wc_buf(struct switchtec_dev *stdev)
122{
123 struct ntb_dbmsg_regs __iomem *mmio_dbmsg;
124
125 /*
126 * odb (outbound doorbell) register is processed by low latency
127 * hardware and w/o side effect
128 */
129 mmio_dbmsg = (void __iomem *)stdev->mmio_ntb +
130 SWITCHTEC_NTB_REG_DBMSG_OFFSET;
131 ioread32(&mmio_dbmsg->odb);
132}
133
116static void mrpc_cmd_submit(struct switchtec_dev *stdev) 134static void mrpc_cmd_submit(struct switchtec_dev *stdev)
117{ 135{
118 /* requires the mrpc_mutex to already be held when called */ 136 /* requires the mrpc_mutex to already be held when called */
@@ -128,16 +146,18 @@ static void mrpc_cmd_submit(struct switchtec_dev *stdev)
128 stuser = list_entry(stdev->mrpc_queue.next, struct switchtec_user, 146 stuser = list_entry(stdev->mrpc_queue.next, struct switchtec_user,
129 list); 147 list);
130 148
149 if (stdev->dma_mrpc) {
150 stdev->dma_mrpc->status = SWITCHTEC_MRPC_STATUS_INPROGRESS;
151 memset(stdev->dma_mrpc->data, 0xFF, SWITCHTEC_MRPC_PAYLOAD_SIZE);
152 }
153
131 stuser_set_state(stuser, MRPC_RUNNING); 154 stuser_set_state(stuser, MRPC_RUNNING);
132 stdev->mrpc_busy = 1; 155 stdev->mrpc_busy = 1;
133 memcpy_toio(&stdev->mmio_mrpc->input_data, 156 memcpy_toio(&stdev->mmio_mrpc->input_data,
134 stuser->data, stuser->data_len); 157 stuser->data, stuser->data_len);
158 flush_wc_buf(stdev);
135 iowrite32(stuser->cmd, &stdev->mmio_mrpc->cmd); 159 iowrite32(stuser->cmd, &stdev->mmio_mrpc->cmd);
136 160
137 stuser->status = ioread32(&stdev->mmio_mrpc->status);
138 if (stuser->status != SWITCHTEC_MRPC_STATUS_INPROGRESS)
139 mrpc_complete_cmd(stdev);
140
141 schedule_delayed_work(&stdev->mrpc_timeout, 161 schedule_delayed_work(&stdev->mrpc_timeout,
142 msecs_to_jiffies(500)); 162 msecs_to_jiffies(500));
143} 163}
@@ -170,7 +190,11 @@ static void mrpc_complete_cmd(struct switchtec_dev *stdev)
170 stuser = list_entry(stdev->mrpc_queue.next, struct switchtec_user, 190 stuser = list_entry(stdev->mrpc_queue.next, struct switchtec_user,
171 list); 191 list);
172 192
173 stuser->status = ioread32(&stdev->mmio_mrpc->status); 193 if (stdev->dma_mrpc)
194 stuser->status = stdev->dma_mrpc->status;
195 else
196 stuser->status = ioread32(&stdev->mmio_mrpc->status);
197
174 if (stuser->status == SWITCHTEC_MRPC_STATUS_INPROGRESS) 198 if (stuser->status == SWITCHTEC_MRPC_STATUS_INPROGRESS)
175 return; 199 return;
176 200
@@ -180,13 +204,19 @@ static void mrpc_complete_cmd(struct switchtec_dev *stdev)
180 if (stuser->status != SWITCHTEC_MRPC_STATUS_DONE) 204 if (stuser->status != SWITCHTEC_MRPC_STATUS_DONE)
181 goto out; 205 goto out;
182 206
183 stuser->return_code = ioread32(&stdev->mmio_mrpc->ret_value); 207 if (stdev->dma_mrpc)
208 stuser->return_code = stdev->dma_mrpc->rtn_code;
209 else
210 stuser->return_code = ioread32(&stdev->mmio_mrpc->ret_value);
184 if (stuser->return_code != 0) 211 if (stuser->return_code != 0)
185 goto out; 212 goto out;
186 213
187 memcpy_fromio(stuser->data, &stdev->mmio_mrpc->output_data, 214 if (stdev->dma_mrpc)
188 stuser->read_len); 215 memcpy(stuser->data, &stdev->dma_mrpc->data,
189 216 stuser->read_len);
217 else
218 memcpy_fromio(stuser->data, &stdev->mmio_mrpc->output_data,
219 stuser->read_len);
190out: 220out:
191 complete_all(&stuser->comp); 221 complete_all(&stuser->comp);
192 list_del_init(&stuser->list); 222 list_del_init(&stuser->list);
@@ -221,7 +251,10 @@ static void mrpc_timeout_work(struct work_struct *work)
221 251
222 mutex_lock(&stdev->mrpc_mutex); 252 mutex_lock(&stdev->mrpc_mutex);
223 253
224 status = ioread32(&stdev->mmio_mrpc->status); 254 if (stdev->dma_mrpc)
255 status = stdev->dma_mrpc->status;
256 else
257 status = ioread32(&stdev->mmio_mrpc->status);
225 if (status == SWITCHTEC_MRPC_STATUS_INPROGRESS) { 258 if (status == SWITCHTEC_MRPC_STATUS_INPROGRESS) {
226 schedule_delayed_work(&stdev->mrpc_timeout, 259 schedule_delayed_work(&stdev->mrpc_timeout,
227 msecs_to_jiffies(500)); 260 msecs_to_jiffies(500));
@@ -229,7 +262,6 @@ static void mrpc_timeout_work(struct work_struct *work)
229 } 262 }
230 263
231 mrpc_complete_cmd(stdev); 264 mrpc_complete_cmd(stdev);
232
233out: 265out:
234 mutex_unlock(&stdev->mrpc_mutex); 266 mutex_unlock(&stdev->mrpc_mutex);
235} 267}
@@ -800,6 +832,7 @@ static int ioctl_event_ctl(struct switchtec_dev *stdev,
800{ 832{
801 int ret; 833 int ret;
802 int nr_idxs; 834 int nr_idxs;
835 unsigned int event_flags;
803 struct switchtec_ioctl_event_ctl ctl; 836 struct switchtec_ioctl_event_ctl ctl;
804 837
805 if (copy_from_user(&ctl, uctl, sizeof(ctl))) 838 if (copy_from_user(&ctl, uctl, sizeof(ctl)))
@@ -821,7 +854,9 @@ static int ioctl_event_ctl(struct switchtec_dev *stdev,
821 else 854 else
822 return -EINVAL; 855 return -EINVAL;
823 856
857 event_flags = ctl.flags;
824 for (ctl.index = 0; ctl.index < nr_idxs; ctl.index++) { 858 for (ctl.index = 0; ctl.index < nr_idxs; ctl.index++) {
859 ctl.flags = event_flags;
825 ret = event_ctl(stdev, &ctl); 860 ret = event_ctl(stdev, &ctl);
826 if (ret < 0) 861 if (ret < 0)
827 return ret; 862 return ret;
@@ -1017,10 +1052,24 @@ static void enable_link_state_events(struct switchtec_dev *stdev)
1017 } 1052 }
1018} 1053}
1019 1054
1055static void enable_dma_mrpc(struct switchtec_dev *stdev)
1056{
1057 writeq(stdev->dma_mrpc_dma_addr, &stdev->mmio_mrpc->dma_addr);
1058 flush_wc_buf(stdev);
1059 iowrite32(SWITCHTEC_DMA_MRPC_EN, &stdev->mmio_mrpc->dma_en);
1060}
1061
1020static void stdev_release(struct device *dev) 1062static void stdev_release(struct device *dev)
1021{ 1063{
1022 struct switchtec_dev *stdev = to_stdev(dev); 1064 struct switchtec_dev *stdev = to_stdev(dev);
1023 1065
1066 if (stdev->dma_mrpc) {
1067 iowrite32(0, &stdev->mmio_mrpc->dma_en);
1068 flush_wc_buf(stdev);
1069 writeq(0, &stdev->mmio_mrpc->dma_addr);
1070 dma_free_coherent(&stdev->pdev->dev, sizeof(*stdev->dma_mrpc),
1071 stdev->dma_mrpc, stdev->dma_mrpc_dma_addr);
1072 }
1024 kfree(stdev); 1073 kfree(stdev);
1025} 1074}
1026 1075
@@ -1176,10 +1225,27 @@ static irqreturn_t switchtec_event_isr(int irq, void *dev)
1176 return ret; 1225 return ret;
1177} 1226}
1178 1227
1228
1229static irqreturn_t switchtec_dma_mrpc_isr(int irq, void *dev)
1230{
1231 struct switchtec_dev *stdev = dev;
1232 irqreturn_t ret = IRQ_NONE;
1233
1234 iowrite32(SWITCHTEC_EVENT_CLEAR |
1235 SWITCHTEC_EVENT_EN_IRQ,
1236 &stdev->mmio_part_cfg->mrpc_comp_hdr);
1237 schedule_work(&stdev->mrpc_work);
1238
1239 ret = IRQ_HANDLED;
1240 return ret;
1241}
1242
1179static int switchtec_init_isr(struct switchtec_dev *stdev) 1243static int switchtec_init_isr(struct switchtec_dev *stdev)
1180{ 1244{
1181 int nvecs; 1245 int nvecs;
1182 int event_irq; 1246 int event_irq;
1247 int dma_mrpc_irq;
1248 int rc;
1183 1249
1184 nvecs = pci_alloc_irq_vectors(stdev->pdev, 1, 4, 1250 nvecs = pci_alloc_irq_vectors(stdev->pdev, 1, 4,
1185 PCI_IRQ_MSIX | PCI_IRQ_MSI); 1251 PCI_IRQ_MSIX | PCI_IRQ_MSI);
@@ -1194,9 +1260,29 @@ static int switchtec_init_isr(struct switchtec_dev *stdev)
1194 if (event_irq < 0) 1260 if (event_irq < 0)
1195 return event_irq; 1261 return event_irq;
1196 1262
1197 return devm_request_irq(&stdev->pdev->dev, event_irq, 1263 rc = devm_request_irq(&stdev->pdev->dev, event_irq,
1198 switchtec_event_isr, 0, 1264 switchtec_event_isr, 0,
1199 KBUILD_MODNAME, stdev); 1265 KBUILD_MODNAME, stdev);
1266
1267 if (rc)
1268 return rc;
1269
1270 if (!stdev->dma_mrpc)
1271 return rc;
1272
1273 dma_mrpc_irq = ioread32(&stdev->mmio_mrpc->dma_vector);
1274 if (dma_mrpc_irq < 0 || dma_mrpc_irq >= nvecs)
1275 return -EFAULT;
1276
1277 dma_mrpc_irq = pci_irq_vector(stdev->pdev, dma_mrpc_irq);
1278 if (dma_mrpc_irq < 0)
1279 return dma_mrpc_irq;
1280
1281 rc = devm_request_irq(&stdev->pdev->dev, dma_mrpc_irq,
1282 switchtec_dma_mrpc_isr, 0,
1283 KBUILD_MODNAME, stdev);
1284
1285 return rc;
1200} 1286}
1201 1287
1202static void init_pff(struct switchtec_dev *stdev) 1288static void init_pff(struct switchtec_dev *stdev)
@@ -1232,19 +1318,38 @@ static int switchtec_init_pci(struct switchtec_dev *stdev,
1232 struct pci_dev *pdev) 1318 struct pci_dev *pdev)
1233{ 1319{
1234 int rc; 1320 int rc;
1321 void __iomem *map;
1322 unsigned long res_start, res_len;
1235 1323
1236 rc = pcim_enable_device(pdev); 1324 rc = pcim_enable_device(pdev);
1237 if (rc) 1325 if (rc)
1238 return rc; 1326 return rc;
1239 1327
1240 rc = pcim_iomap_regions(pdev, 0x1, KBUILD_MODNAME); 1328 rc = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
1241 if (rc) 1329 if (rc)
1242 return rc; 1330 return rc;
1243 1331
1244 pci_set_master(pdev); 1332 pci_set_master(pdev);
1245 1333
1246 stdev->mmio = pcim_iomap_table(pdev)[0]; 1334 res_start = pci_resource_start(pdev, 0);
1247 stdev->mmio_mrpc = stdev->mmio + SWITCHTEC_GAS_MRPC_OFFSET; 1335 res_len = pci_resource_len(pdev, 0);
1336
1337 if (!devm_request_mem_region(&pdev->dev, res_start,
1338 res_len, KBUILD_MODNAME))
1339 return -EBUSY;
1340
1341 stdev->mmio_mrpc = devm_ioremap_wc(&pdev->dev, res_start,
1342 SWITCHTEC_GAS_TOP_CFG_OFFSET);
1343 if (!stdev->mmio_mrpc)
1344 return -ENOMEM;
1345
1346 map = devm_ioremap(&pdev->dev,
1347 res_start + SWITCHTEC_GAS_TOP_CFG_OFFSET,
1348 res_len - SWITCHTEC_GAS_TOP_CFG_OFFSET);
1349 if (!map)
1350 return -ENOMEM;
1351
1352 stdev->mmio = map - SWITCHTEC_GAS_TOP_CFG_OFFSET;
1248 stdev->mmio_sw_event = stdev->mmio + SWITCHTEC_GAS_SW_EVENT_OFFSET; 1353 stdev->mmio_sw_event = stdev->mmio + SWITCHTEC_GAS_SW_EVENT_OFFSET;
1249 stdev->mmio_sys_info = stdev->mmio + SWITCHTEC_GAS_SYS_INFO_OFFSET; 1354 stdev->mmio_sys_info = stdev->mmio + SWITCHTEC_GAS_SYS_INFO_OFFSET;
1250 stdev->mmio_flash_info = stdev->mmio + SWITCHTEC_GAS_FLASH_INFO_OFFSET; 1355 stdev->mmio_flash_info = stdev->mmio + SWITCHTEC_GAS_FLASH_INFO_OFFSET;
@@ -1262,6 +1367,19 @@ static int switchtec_init_pci(struct switchtec_dev *stdev,
1262 1367
1263 pci_set_drvdata(pdev, stdev); 1368 pci_set_drvdata(pdev, stdev);
1264 1369
1370 if (!use_dma_mrpc)
1371 return 0;
1372
1373 if (ioread32(&stdev->mmio_mrpc->dma_ver) == 0)
1374 return 0;
1375
1376 stdev->dma_mrpc = dma_zalloc_coherent(&stdev->pdev->dev,
1377 sizeof(*stdev->dma_mrpc),
1378 &stdev->dma_mrpc_dma_addr,
1379 GFP_KERNEL);
1380 if (stdev->dma_mrpc == NULL)
1381 return -ENOMEM;
1382
1265 return 0; 1383 return 0;
1266} 1384}
1267 1385
@@ -1293,6 +1411,9 @@ static int switchtec_pci_probe(struct pci_dev *pdev,
1293 &stdev->mmio_part_cfg->mrpc_comp_hdr); 1411 &stdev->mmio_part_cfg->mrpc_comp_hdr);
1294 enable_link_state_events(stdev); 1412 enable_link_state_events(stdev);
1295 1413
1414 if (stdev->dma_mrpc)
1415 enable_dma_mrpc(stdev);
1416
1296 rc = cdev_device_add(&stdev->cdev, &stdev->dev); 1417 rc = cdev_device_add(&stdev->cdev, &stdev->dev);
1297 if (rc) 1418 if (rc)
1298 goto err_devadd; 1419 goto err_devadd;
@@ -1318,7 +1439,6 @@ static void switchtec_pci_remove(struct pci_dev *pdev)
1318 cdev_device_del(&stdev->cdev, &stdev->dev); 1439 cdev_device_del(&stdev->cdev, &stdev->dev);
1319 ida_simple_remove(&switchtec_minor_ida, MINOR(stdev->dev.devt)); 1440 ida_simple_remove(&switchtec_minor_ida, MINOR(stdev->dev.devt));
1320 dev_info(&stdev->dev, "unregistered.\n"); 1441 dev_info(&stdev->dev, "unregistered.\n");
1321
1322 stdev_kill(stdev); 1442 stdev_kill(stdev);
1323 put_device(&stdev->dev); 1443 put_device(&stdev->dev);
1324} 1444}
diff --git a/drivers/usb/dwc3/dwc3-haps.c b/drivers/usb/dwc3/dwc3-haps.c
index c9cc33881bef..02d57d98ef9b 100644
--- a/drivers/usb/dwc3/dwc3-haps.c
+++ b/drivers/usb/dwc3/dwc3-haps.c
@@ -15,10 +15,6 @@
15#include <linux/platform_device.h> 15#include <linux/platform_device.h>
16#include <linux/property.h> 16#include <linux/property.h>
17 17
18#define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd
19#define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI 0xabce
20#define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31 0xabcf
21
22/** 18/**
23 * struct dwc3_haps - Driver private structure 19 * struct dwc3_haps - Driver private structure
24 * @dwc3: child dwc3 platform_device 20 * @dwc3: child dwc3 platform_device
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 11c71c4ecf75..8e3c646bc15c 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -405,6 +405,7 @@ struct pci_dev {
405 unsigned int non_compliant_bars:1; /* Broken BARs; ignore them */ 405 unsigned int non_compliant_bars:1; /* Broken BARs; ignore them */
406 unsigned int is_probed:1; /* Device probing in progress */ 406 unsigned int is_probed:1; /* Device probing in progress */
407 unsigned int link_active_reporting:1;/* Device capable of reporting link active */ 407 unsigned int link_active_reporting:1;/* Device capable of reporting link active */
408 unsigned int no_vf_scan:1; /* Don't scan for VFs after IOV enablement */
408 pci_dev_flags_t dev_flags; 409 pci_dev_flags_t dev_flags;
409 atomic_t enable_cnt; /* pci_enable_device has been called */ 410 atomic_t enable_cnt; /* pci_enable_device has been called */
410 411
@@ -764,9 +765,9 @@ struct pci_driver {
764 int (*suspend)(struct pci_dev *dev, pm_message_t state); /* Device suspended */ 765 int (*suspend)(struct pci_dev *dev, pm_message_t state); /* Device suspended */
765 int (*suspend_late)(struct pci_dev *dev, pm_message_t state); 766 int (*suspend_late)(struct pci_dev *dev, pm_message_t state);
766 int (*resume_early)(struct pci_dev *dev); 767 int (*resume_early)(struct pci_dev *dev);
767 int (*resume) (struct pci_dev *dev); /* Device woken up */ 768 int (*resume)(struct pci_dev *dev); /* Device woken up */
768 void (*shutdown) (struct pci_dev *dev); 769 void (*shutdown)(struct pci_dev *dev);
769 int (*sriov_configure) (struct pci_dev *dev, int num_vfs); /* On PF */ 770 int (*sriov_configure)(struct pci_dev *dev, int num_vfs); /* On PF */
770 const struct pci_error_handlers *err_handler; 771 const struct pci_error_handlers *err_handler;
771 const struct attribute_group **groups; 772 const struct attribute_group **groups;
772 struct device_driver driver; 773 struct device_driver driver;
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index 69f0abe1ba1a..25db0c1586ea 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -2358,6 +2358,9 @@
2358#define PCI_DEVICE_ID_CENATEK_IDE 0x0001 2358#define PCI_DEVICE_ID_CENATEK_IDE 0x0001
2359 2359
2360#define PCI_VENDOR_ID_SYNOPSYS 0x16c3 2360#define PCI_VENDOR_ID_SYNOPSYS 0x16c3
2361#define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd
2362#define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI 0xabce
2363#define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31 0xabcf
2361 2364
2362#define PCI_VENDOR_ID_VITESSE 0x1725 2365#define PCI_VENDOR_ID_VITESSE 0x1725
2363#define PCI_DEVICE_ID_VITESSE_VSC7174 0x7174 2366#define PCI_DEVICE_ID_VITESSE_VSC7174 0x7174
diff --git a/include/linux/switchtec.h b/include/linux/switchtec.h
index ab400af6f0ce..eee0412bdf4b 100644
--- a/include/linux/switchtec.h
+++ b/include/linux/switchtec.h
@@ -29,6 +29,7 @@
29#define SWITCHTEC_EVENT_EN_IRQ BIT(3) 29#define SWITCHTEC_EVENT_EN_IRQ BIT(3)
30#define SWITCHTEC_EVENT_FATAL BIT(4) 30#define SWITCHTEC_EVENT_FATAL BIT(4)
31 31
32#define SWITCHTEC_DMA_MRPC_EN BIT(0)
32enum { 33enum {
33 SWITCHTEC_GAS_MRPC_OFFSET = 0x0000, 34 SWITCHTEC_GAS_MRPC_OFFSET = 0x0000,
34 SWITCHTEC_GAS_TOP_CFG_OFFSET = 0x1000, 35 SWITCHTEC_GAS_TOP_CFG_OFFSET = 0x1000,
@@ -46,6 +47,10 @@ struct mrpc_regs {
46 u32 cmd; 47 u32 cmd;
47 u32 status; 48 u32 status;
48 u32 ret_value; 49 u32 ret_value;
50 u32 dma_en;
51 u64 dma_addr;
52 u32 dma_vector;
53 u32 dma_ver;
49} __packed; 54} __packed;
50 55
51enum mrpc_status { 56enum mrpc_status {
@@ -342,6 +347,14 @@ struct pff_csr_regs {
342 347
343struct switchtec_ntb; 348struct switchtec_ntb;
344 349
350struct dma_mrpc_output {
351 u32 status;
352 u32 cmd_id;
353 u32 rtn_code;
354 u32 output_size;
355 u8 data[SWITCHTEC_MRPC_PAYLOAD_SIZE];
356};
357
345struct switchtec_dev { 358struct switchtec_dev {
346 struct pci_dev *pdev; 359 struct pci_dev *pdev;
347 struct device dev; 360 struct device dev;
@@ -381,6 +394,9 @@ struct switchtec_dev {
381 u8 link_event_count[SWITCHTEC_MAX_PFF_CSR]; 394 u8 link_event_count[SWITCHTEC_MAX_PFF_CSR];
382 395
383 struct switchtec_ntb *sndev; 396 struct switchtec_ntb *sndev;
397
398 struct dma_mrpc_output *dma_mrpc;
399 dma_addr_t dma_mrpc_dma_addr;
384}; 400};
385 401
386static inline struct switchtec_dev *to_stdev(struct device *dev) 402static inline struct switchtec_dev *to_stdev(struct device *dev)