1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (C) 2015 Broadcom Corporation
7 #include <linux/kernel.h>
9 #include <linux/pci-ecam.h>
10 #include <linux/msi.h>
11 #include <linux/clk.h>
12 #include <linux/module.h>
13 #include <linux/mbus.h>
14 #include <linux/slab.h>
15 #include <linux/delay.h>
16 #include <linux/interrupt.h>
17 #include <linux/irqchip/arm-gic-v3.h>
18 #include <linux/platform_device.h>
19 #include <linux/of_address.h>
20 #include <linux/of_pci.h>
21 #include <linux/of_irq.h>
22 #include <linux/of_platform.h>
23 #include <linux/phy/phy.h>
25 #include "pcie-iproc.h"
27 #define EP_PERST_SOURCE_SELECT_SHIFT 2
28 #define EP_PERST_SOURCE_SELECT BIT(EP_PERST_SOURCE_SELECT_SHIFT)
29 #define EP_MODE_SURVIVE_PERST_SHIFT 1
30 #define EP_MODE_SURVIVE_PERST BIT(EP_MODE_SURVIVE_PERST_SHIFT)
31 #define RC_PCIE_RST_OUTPUT_SHIFT 0
32 #define RC_PCIE_RST_OUTPUT BIT(RC_PCIE_RST_OUTPUT_SHIFT)
33 #define PAXC_RESET_MASK 0x7f
35 #define GIC_V3_CFG_SHIFT 0
36 #define GIC_V3_CFG BIT(GIC_V3_CFG_SHIFT)
38 #define MSI_ENABLE_CFG_SHIFT 0
39 #define MSI_ENABLE_CFG BIT(MSI_ENABLE_CFG_SHIFT)
41 #define CFG_IND_ADDR_MASK 0x00001ffc
43 #define CFG_ADDR_REG_NUM_MASK 0x00000ffc
44 #define CFG_ADDR_CFG_TYPE_1 1
46 #define SYS_RC_INTX_MASK 0xf
48 #define PCIE_PHYLINKUP_SHIFT 3
49 #define PCIE_PHYLINKUP BIT(PCIE_PHYLINKUP_SHIFT)
50 #define PCIE_DL_ACTIVE_SHIFT 2
51 #define PCIE_DL_ACTIVE BIT(PCIE_DL_ACTIVE_SHIFT)
53 #define APB_ERR_EN_SHIFT 0
54 #define APB_ERR_EN BIT(APB_ERR_EN_SHIFT)
56 #define CFG_RD_SUCCESS 0
60 #define CFG_RETRY_STATUS 0xffff0001
61 #define CFG_RETRY_STATUS_TIMEOUT_US 500000 /* 500 milliseconds */
63 /* derive the enum index of the outbound/inbound mapping registers */
64 #define MAP_REG(base_reg, index) ((base_reg) + (index) * 2)
67 * Maximum number of outbound mapping window sizes that can be supported by any
68 * OARR/OMAP mapping pair
70 #define MAX_NUM_OB_WINDOW_SIZES 4
72 #define OARR_VALID_SHIFT 0
73 #define OARR_VALID BIT(OARR_VALID_SHIFT)
74 #define OARR_SIZE_CFG_SHIFT 1
77 * Maximum number of inbound mapping region sizes that can be supported by an
80 #define MAX_NUM_IB_REGION_SIZES 9
82 #define IMAP_VALID_SHIFT 0
83 #define IMAP_VALID BIT(IMAP_VALID_SHIFT)
85 #define IPROC_PCI_PM_CAP 0x48
86 #define IPROC_PCI_PM_CAP_MASK 0xffff
87 #define IPROC_PCI_EXP_CAP 0xac
89 #define IPROC_PCIE_REG_INVALID 0xffff
92 * struct iproc_pcie_ob_map - iProc PCIe outbound mapping controller-specific
94 * @window_sizes: list of supported outbound mapping window sizes in MB
95 * @nr_sizes: number of supported outbound mapping window sizes
97 struct iproc_pcie_ob_map {
98 resource_size_t window_sizes[MAX_NUM_OB_WINDOW_SIZES];
99 unsigned int nr_sizes;
102 static const struct iproc_pcie_ob_map paxb_ob_map[] = {
105 .window_sizes = { 128, 256 },
110 .window_sizes = { 128, 256 },
115 static const struct iproc_pcie_ob_map paxb_v2_ob_map[] = {
118 .window_sizes = { 128, 256 },
123 .window_sizes = { 128, 256 },
128 .window_sizes = { 128, 256, 512, 1024 },
133 .window_sizes = { 128, 256, 512, 1024 },
139 * enum iproc_pcie_ib_map_type - iProc PCIe inbound mapping type
140 * @IPROC_PCIE_IB_MAP_MEM: DDR memory
141 * @IPROC_PCIE_IB_MAP_IO: device I/O memory
142 * @IPROC_PCIE_IB_MAP_INVALID: invalid or unused
144 enum iproc_pcie_ib_map_type {
145 IPROC_PCIE_IB_MAP_MEM = 0,
146 IPROC_PCIE_IB_MAP_IO,
147 IPROC_PCIE_IB_MAP_INVALID
151 * struct iproc_pcie_ib_map - iProc PCIe inbound mapping controller-specific
153 * @type: inbound mapping region type
154 * @size_unit: inbound mapping region size unit, could be SZ_1K, SZ_1M, or
156 * @region_sizes: list of supported inbound mapping region sizes in KB, MB, or
157 * GB, depending on the size unit
158 * @nr_sizes: number of supported inbound mapping region sizes
159 * @nr_windows: number of supported inbound mapping windows for the region
160 * @imap_addr_offset: register offset between the upper and lower 32-bit
161 * IMAP address registers
162 * @imap_window_offset: register offset between each IMAP window
164 struct iproc_pcie_ib_map {
165 enum iproc_pcie_ib_map_type type;
166 unsigned int size_unit;
167 resource_size_t region_sizes[MAX_NUM_IB_REGION_SIZES];
168 unsigned int nr_sizes;
169 unsigned int nr_windows;
170 u16 imap_addr_offset;
171 u16 imap_window_offset;
174 static const struct iproc_pcie_ib_map paxb_v2_ib_map[] = {
177 .type = IPROC_PCIE_IB_MAP_IO,
179 .region_sizes = { 32 },
182 .imap_addr_offset = 0x40,
183 .imap_window_offset = 0x4,
187 .type = IPROC_PCIE_IB_MAP_MEM,
189 .region_sizes = { 8 },
192 .imap_addr_offset = 0x4,
193 .imap_window_offset = 0x8,
198 .type = IPROC_PCIE_IB_MAP_MEM,
200 .region_sizes = { 64, 128, 256, 512, 1024, 2048, 4096, 8192,
204 .imap_addr_offset = 0x4,
205 .imap_window_offset = 0x8,
209 .type = IPROC_PCIE_IB_MAP_MEM,
211 .region_sizes = { 1, 2, 4, 8, 16, 32 },
214 .imap_addr_offset = 0x4,
215 .imap_window_offset = 0x8,
219 .type = IPROC_PCIE_IB_MAP_MEM,
221 .region_sizes = { 32, 64, 128, 256, 512 },
224 .imap_addr_offset = 0x4,
225 .imap_window_offset = 0x8,
230 * iProc PCIe host registers
232 enum iproc_pcie_reg {
233 /* clock/reset signal control */
234 IPROC_PCIE_CLK_CTRL = 0,
237 * To allow MSI to be steered to an external MSI controller (e.g., ARM
240 IPROC_PCIE_MSI_GIC_MODE,
243 * IPROC_PCIE_MSI_BASE_ADDR and IPROC_PCIE_MSI_WINDOW_SIZE define the
244 * window where the MSI posted writes are written, for the writes to be
245 * interpreted as MSI writes.
247 IPROC_PCIE_MSI_BASE_ADDR,
248 IPROC_PCIE_MSI_WINDOW_SIZE,
251 * To hold the address of the register where the MSI writes are
252 * programed. When ARM GICv3 ITS is used, this should be programmed
253 * with the address of the GITS_TRANSLATER register.
255 IPROC_PCIE_MSI_ADDR_LO,
256 IPROC_PCIE_MSI_ADDR_HI,
259 IPROC_PCIE_MSI_EN_CFG,
261 /* allow access to root complex configuration space */
262 IPROC_PCIE_CFG_IND_ADDR,
263 IPROC_PCIE_CFG_IND_DATA,
265 /* allow access to device configuration space */
272 /* outbound address mapping */
282 /* inbound address mapping */
294 /* config read status */
295 IPROC_PCIE_CFG_RD_STATUS,
298 IPROC_PCIE_LINK_STATUS,
300 /* enable APB error for unsupported requests */
301 IPROC_PCIE_APB_ERR_EN,
303 /* total number of core registers */
304 IPROC_PCIE_MAX_NUM_REG,
307 /* iProc PCIe PAXB BCMA registers */
308 static const u16 iproc_pcie_reg_paxb_bcma[IPROC_PCIE_MAX_NUM_REG] = {
309 [IPROC_PCIE_CLK_CTRL] = 0x000,
310 [IPROC_PCIE_CFG_IND_ADDR] = 0x120,
311 [IPROC_PCIE_CFG_IND_DATA] = 0x124,
312 [IPROC_PCIE_CFG_ADDR] = 0x1f8,
313 [IPROC_PCIE_CFG_DATA] = 0x1fc,
314 [IPROC_PCIE_INTX_EN] = 0x330,
315 [IPROC_PCIE_LINK_STATUS] = 0xf0c,
318 /* iProc PCIe PAXB registers */
319 static const u16 iproc_pcie_reg_paxb[IPROC_PCIE_MAX_NUM_REG] = {
320 [IPROC_PCIE_CLK_CTRL] = 0x000,
321 [IPROC_PCIE_CFG_IND_ADDR] = 0x120,
322 [IPROC_PCIE_CFG_IND_DATA] = 0x124,
323 [IPROC_PCIE_CFG_ADDR] = 0x1f8,
324 [IPROC_PCIE_CFG_DATA] = 0x1fc,
325 [IPROC_PCIE_INTX_EN] = 0x330,
326 [IPROC_PCIE_OARR0] = 0xd20,
327 [IPROC_PCIE_OMAP0] = 0xd40,
328 [IPROC_PCIE_OARR1] = 0xd28,
329 [IPROC_PCIE_OMAP1] = 0xd48,
330 [IPROC_PCIE_LINK_STATUS] = 0xf0c,
331 [IPROC_PCIE_APB_ERR_EN] = 0xf40,
334 /* iProc PCIe PAXB v2 registers */
335 static const u16 iproc_pcie_reg_paxb_v2[IPROC_PCIE_MAX_NUM_REG] = {
336 [IPROC_PCIE_CLK_CTRL] = 0x000,
337 [IPROC_PCIE_CFG_IND_ADDR] = 0x120,
338 [IPROC_PCIE_CFG_IND_DATA] = 0x124,
339 [IPROC_PCIE_CFG_ADDR] = 0x1f8,
340 [IPROC_PCIE_CFG_DATA] = 0x1fc,
341 [IPROC_PCIE_INTX_EN] = 0x330,
342 [IPROC_PCIE_OARR0] = 0xd20,
343 [IPROC_PCIE_OMAP0] = 0xd40,
344 [IPROC_PCIE_OARR1] = 0xd28,
345 [IPROC_PCIE_OMAP1] = 0xd48,
346 [IPROC_PCIE_OARR2] = 0xd60,
347 [IPROC_PCIE_OMAP2] = 0xd68,
348 [IPROC_PCIE_OARR3] = 0xdf0,
349 [IPROC_PCIE_OMAP3] = 0xdf8,
350 [IPROC_PCIE_IARR0] = 0xd00,
351 [IPROC_PCIE_IMAP0] = 0xc00,
352 [IPROC_PCIE_IARR1] = 0xd08,
353 [IPROC_PCIE_IMAP1] = 0xd70,
354 [IPROC_PCIE_IARR2] = 0xd10,
355 [IPROC_PCIE_IMAP2] = 0xcc0,
356 [IPROC_PCIE_IARR3] = 0xe00,
357 [IPROC_PCIE_IMAP3] = 0xe08,
358 [IPROC_PCIE_IARR4] = 0xe68,
359 [IPROC_PCIE_IMAP4] = 0xe70,
360 [IPROC_PCIE_CFG_RD_STATUS] = 0xee0,
361 [IPROC_PCIE_LINK_STATUS] = 0xf0c,
362 [IPROC_PCIE_APB_ERR_EN] = 0xf40,
365 /* iProc PCIe PAXC v1 registers */
366 static const u16 iproc_pcie_reg_paxc[IPROC_PCIE_MAX_NUM_REG] = {
367 [IPROC_PCIE_CLK_CTRL] = 0x000,
368 [IPROC_PCIE_CFG_IND_ADDR] = 0x1f0,
369 [IPROC_PCIE_CFG_IND_DATA] = 0x1f4,
370 [IPROC_PCIE_CFG_ADDR] = 0x1f8,
371 [IPROC_PCIE_CFG_DATA] = 0x1fc,
374 /* iProc PCIe PAXC v2 registers */
375 static const u16 iproc_pcie_reg_paxc_v2[IPROC_PCIE_MAX_NUM_REG] = {
376 [IPROC_PCIE_MSI_GIC_MODE] = 0x050,
377 [IPROC_PCIE_MSI_BASE_ADDR] = 0x074,
378 [IPROC_PCIE_MSI_WINDOW_SIZE] = 0x078,
379 [IPROC_PCIE_MSI_ADDR_LO] = 0x07c,
380 [IPROC_PCIE_MSI_ADDR_HI] = 0x080,
381 [IPROC_PCIE_MSI_EN_CFG] = 0x09c,
382 [IPROC_PCIE_CFG_IND_ADDR] = 0x1f0,
383 [IPROC_PCIE_CFG_IND_DATA] = 0x1f4,
384 [IPROC_PCIE_CFG_ADDR] = 0x1f8,
385 [IPROC_PCIE_CFG_DATA] = 0x1fc,
389 * List of device IDs of controllers that have corrupted capability list that
392 static const u16 iproc_pcie_corrupt_cap_did[] = {
399 static inline struct iproc_pcie *iproc_data(struct pci_bus *bus)
401 struct iproc_pcie *pcie = bus->sysdata;
405 static inline bool iproc_pcie_reg_is_invalid(u16 reg_offset)
407 return !!(reg_offset == IPROC_PCIE_REG_INVALID);
410 static inline u16 iproc_pcie_reg_offset(struct iproc_pcie *pcie,
411 enum iproc_pcie_reg reg)
413 return pcie->reg_offsets[reg];
416 static inline u32 iproc_pcie_read_reg(struct iproc_pcie *pcie,
417 enum iproc_pcie_reg reg)
419 u16 offset = iproc_pcie_reg_offset(pcie, reg);
421 if (iproc_pcie_reg_is_invalid(offset))
424 return readl(pcie->base + offset);
427 static inline void iproc_pcie_write_reg(struct iproc_pcie *pcie,
428 enum iproc_pcie_reg reg, u32 val)
430 u16 offset = iproc_pcie_reg_offset(pcie, reg);
432 if (iproc_pcie_reg_is_invalid(offset))
435 writel(val, pcie->base + offset);
439 * APB error forwarding can be disabled during access of configuration
440 * registers of the endpoint device, to prevent unsupported requests
441 * (typically seen during enumeration with multi-function devices) from
442 * triggering a system exception.
444 static inline void iproc_pcie_apb_err_disable(struct pci_bus *bus,
447 struct iproc_pcie *pcie = iproc_data(bus);
450 if (bus->number && pcie->has_apb_err_disable) {
451 val = iproc_pcie_read_reg(pcie, IPROC_PCIE_APB_ERR_EN);
456 iproc_pcie_write_reg(pcie, IPROC_PCIE_APB_ERR_EN, val);
460 static void __iomem *iproc_pcie_map_ep_cfg_reg(struct iproc_pcie *pcie,
468 /* EP device access */
469 val = ALIGN_DOWN(PCIE_ECAM_OFFSET(busno, devfn, where), 4) |
472 iproc_pcie_write_reg(pcie, IPROC_PCIE_CFG_ADDR, val);
473 offset = iproc_pcie_reg_offset(pcie, IPROC_PCIE_CFG_DATA);
475 if (iproc_pcie_reg_is_invalid(offset))
478 return (pcie->base + offset);
481 static unsigned int iproc_pcie_cfg_retry(struct iproc_pcie *pcie,
482 void __iomem *cfg_data_p)
484 int timeout = CFG_RETRY_STATUS_TIMEOUT_US;
489 * As per PCIe spec r3.1, sec 2.3.2, CRS Software Visibility only
490 * affects config reads of the Vendor ID. For config writes or any
491 * other config reads, the Root may automatically reissue the
492 * configuration request again as a new request.
494 * For config reads, this hardware returns CFG_RETRY_STATUS data
495 * when it receives a CRS completion, regardless of the address of
496 * the read or the CRS Software Visibility Enable bit. As a
497 * partial workaround for this, we retry in software any read that
498 * returns CFG_RETRY_STATUS.
500 * Note that a non-Vendor ID config register may have a value of
501 * CFG_RETRY_STATUS. If we read that, we can't distinguish it from
502 * a CRS completion, so we will incorrectly retry the read and
503 * eventually return the wrong data (0xffffffff).
505 data = readl(cfg_data_p);
506 while (data == CFG_RETRY_STATUS && timeout--) {
508 * CRS state is set in CFG_RD status register
509 * This will handle the case where CFG_RETRY_STATUS is
512 status = iproc_pcie_read_reg(pcie, IPROC_PCIE_CFG_RD_STATUS);
513 if (status != CFG_RD_CRS)
517 data = readl(cfg_data_p);
520 if (data == CFG_RETRY_STATUS)
526 static void iproc_pcie_fix_cap(struct iproc_pcie *pcie, int where, u32 *val)
530 switch (where & ~0x3) {
535 * Activate fixup for those controllers that have corrupted
536 * capability list registers
538 for (i = 0; i < ARRAY_SIZE(iproc_pcie_corrupt_cap_did); i++)
539 if (dev_id == iproc_pcie_corrupt_cap_did[i])
540 pcie->fix_paxc_cap = true;
543 case IPROC_PCI_PM_CAP:
544 if (pcie->fix_paxc_cap) {
545 /* advertise PM, force next capability to PCIe */
546 *val &= ~IPROC_PCI_PM_CAP_MASK;
547 *val |= IPROC_PCI_EXP_CAP << 8 | PCI_CAP_ID_PM;
551 case IPROC_PCI_EXP_CAP:
552 if (pcie->fix_paxc_cap) {
553 /* advertise root port, version 2, terminate here */
554 *val = (PCI_EXP_TYPE_ROOT_PORT << 4 | 2) << 16 |
559 case IPROC_PCI_EXP_CAP + PCI_EXP_RTCTL:
560 /* Don't advertise CRS SV support */
561 *val &= ~(PCI_EXP_RTCAP_CRSVIS << 16);
569 static int iproc_pcie_config_read(struct pci_bus *bus, unsigned int devfn,
570 int where, int size, u32 *val)
572 struct iproc_pcie *pcie = iproc_data(bus);
573 unsigned int busno = bus->number;
574 void __iomem *cfg_data_p;
578 /* root complex access */
580 ret = pci_generic_config_read32(bus, devfn, where, size, val);
581 if (ret == PCIBIOS_SUCCESSFUL)
582 iproc_pcie_fix_cap(pcie, where, val);
587 cfg_data_p = iproc_pcie_map_ep_cfg_reg(pcie, busno, devfn, where);
590 return PCIBIOS_DEVICE_NOT_FOUND;
592 data = iproc_pcie_cfg_retry(pcie, cfg_data_p);
596 *val = (data >> (8 * (where & 3))) & ((1 << (size * 8)) - 1);
599 * For PAXC and PAXCv2, the total number of PFs that one can enumerate
600 * depends on the firmware configuration. Unfortunately, due to an ASIC
601 * bug, unconfigured PFs cannot be properly hidden from the root
602 * complex. As a result, write access to these PFs will cause bus lock
603 * up on the embedded processor
605 * Since all unconfigured PFs are left with an incorrect, staled device
606 * ID of 0x168e (PCI_DEVICE_ID_NX2_57810), we try to catch those access
607 * early here and reject them all
609 #define DEVICE_ID_MASK 0xffff0000
610 #define DEVICE_ID_SHIFT 16
611 if (pcie->rej_unconfig_pf &&
612 (where & CFG_ADDR_REG_NUM_MASK) == PCI_VENDOR_ID)
613 if ((*val & DEVICE_ID_MASK) ==
614 (PCI_DEVICE_ID_NX2_57810 << DEVICE_ID_SHIFT))
615 return PCIBIOS_FUNC_NOT_SUPPORTED;
617 return PCIBIOS_SUCCESSFUL;
621 * Note access to the configuration registers are protected at the higher layer
622 * by 'pci_lock' in drivers/pci/access.c
624 static void __iomem *iproc_pcie_map_cfg_bus(struct iproc_pcie *pcie,
625 int busno, unsigned int devfn,
630 /* root complex access */
632 if (PCIE_ECAM_DEVFN(devfn) > 0)
635 iproc_pcie_write_reg(pcie, IPROC_PCIE_CFG_IND_ADDR,
636 where & CFG_IND_ADDR_MASK);
637 offset = iproc_pcie_reg_offset(pcie, IPROC_PCIE_CFG_IND_DATA);
638 if (iproc_pcie_reg_is_invalid(offset))
641 return (pcie->base + offset);
644 return iproc_pcie_map_ep_cfg_reg(pcie, busno, devfn, where);
647 static void __iomem *iproc_pcie_bus_map_cfg_bus(struct pci_bus *bus,
651 return iproc_pcie_map_cfg_bus(iproc_data(bus), bus->number, devfn,
655 static int iproc_pci_raw_config_read32(struct iproc_pcie *pcie,
656 unsigned int devfn, int where,
661 addr = iproc_pcie_map_cfg_bus(pcie, 0, devfn, where & ~0x3);
664 return PCIBIOS_DEVICE_NOT_FOUND;
670 *val = (*val >> (8 * (where & 3))) & ((1 << (size * 8)) - 1);
672 return PCIBIOS_SUCCESSFUL;
675 static int iproc_pci_raw_config_write32(struct iproc_pcie *pcie,
676 unsigned int devfn, int where,
682 addr = iproc_pcie_map_cfg_bus(pcie, 0, devfn, where & ~0x3);
684 return PCIBIOS_DEVICE_NOT_FOUND;
688 return PCIBIOS_SUCCESSFUL;
691 mask = ~(((1 << (size * 8)) - 1) << ((where & 0x3) * 8));
692 tmp = readl(addr) & mask;
693 tmp |= val << ((where & 0x3) * 8);
696 return PCIBIOS_SUCCESSFUL;
699 static int iproc_pcie_config_read32(struct pci_bus *bus, unsigned int devfn,
700 int where, int size, u32 *val)
703 struct iproc_pcie *pcie = iproc_data(bus);
705 iproc_pcie_apb_err_disable(bus, true);
706 if (pcie->iproc_cfg_read)
707 ret = iproc_pcie_config_read(bus, devfn, where, size, val);
709 ret = pci_generic_config_read32(bus, devfn, where, size, val);
710 iproc_pcie_apb_err_disable(bus, false);
715 static int iproc_pcie_config_write32(struct pci_bus *bus, unsigned int devfn,
716 int where, int size, u32 val)
720 iproc_pcie_apb_err_disable(bus, true);
721 ret = pci_generic_config_write32(bus, devfn, where, size, val);
722 iproc_pcie_apb_err_disable(bus, false);
727 static struct pci_ops iproc_pcie_ops = {
728 .map_bus = iproc_pcie_bus_map_cfg_bus,
729 .read = iproc_pcie_config_read32,
730 .write = iproc_pcie_config_write32,
733 static void iproc_pcie_perst_ctrl(struct iproc_pcie *pcie, bool assert)
738 * PAXC and the internal emulated endpoint device downstream should not
739 * be reset. If firmware has been loaded on the endpoint device at an
740 * earlier boot stage, reset here causes issues.
742 if (pcie->ep_is_internal)
746 val = iproc_pcie_read_reg(pcie, IPROC_PCIE_CLK_CTRL);
747 val &= ~EP_PERST_SOURCE_SELECT & ~EP_MODE_SURVIVE_PERST &
749 iproc_pcie_write_reg(pcie, IPROC_PCIE_CLK_CTRL, val);
752 val = iproc_pcie_read_reg(pcie, IPROC_PCIE_CLK_CTRL);
753 val |= RC_PCIE_RST_OUTPUT;
754 iproc_pcie_write_reg(pcie, IPROC_PCIE_CLK_CTRL, val);
759 int iproc_pcie_shutdown(struct iproc_pcie *pcie)
761 iproc_pcie_perst_ctrl(pcie, true);
766 EXPORT_SYMBOL_GPL(iproc_pcie_shutdown);
768 static int iproc_pcie_check_link(struct iproc_pcie *pcie)
770 struct device *dev = pcie->dev;
771 u32 hdr_type, link_ctrl, link_status, class, val;
772 bool link_is_active = false;
775 * PAXC connects to emulated endpoint devices directly and does not
776 * have a Serdes. Therefore skip the link detection logic here.
778 if (pcie->ep_is_internal)
781 val = iproc_pcie_read_reg(pcie, IPROC_PCIE_LINK_STATUS);
782 if (!(val & PCIE_PHYLINKUP) || !(val & PCIE_DL_ACTIVE)) {
783 dev_err(dev, "PHY or data link is INACTIVE!\n");
787 /* make sure we are not in EP mode */
788 iproc_pci_raw_config_read32(pcie, 0, PCI_HEADER_TYPE, 1, &hdr_type);
789 if ((hdr_type & 0x7f) != PCI_HEADER_TYPE_BRIDGE) {
790 dev_err(dev, "in EP mode, hdr=%#02x\n", hdr_type);
794 /* force class to PCI_CLASS_BRIDGE_PCI (0x0604) */
795 #define PCI_BRIDGE_CTRL_REG_OFFSET 0x43c
796 #define PCI_CLASS_BRIDGE_MASK 0xffff00
797 #define PCI_CLASS_BRIDGE_SHIFT 8
798 iproc_pci_raw_config_read32(pcie, 0, PCI_BRIDGE_CTRL_REG_OFFSET,
800 class &= ~PCI_CLASS_BRIDGE_MASK;
801 class |= (PCI_CLASS_BRIDGE_PCI << PCI_CLASS_BRIDGE_SHIFT);
802 iproc_pci_raw_config_write32(pcie, 0, PCI_BRIDGE_CTRL_REG_OFFSET,
805 /* check link status to see if link is active */
806 iproc_pci_raw_config_read32(pcie, 0, IPROC_PCI_EXP_CAP + PCI_EXP_LNKSTA,
808 if (link_status & PCI_EXP_LNKSTA_NLW)
809 link_is_active = true;
811 if (!link_is_active) {
812 /* try GEN 1 link speed */
813 #define PCI_TARGET_LINK_SPEED_MASK 0xf
814 #define PCI_TARGET_LINK_SPEED_GEN2 0x2
815 #define PCI_TARGET_LINK_SPEED_GEN1 0x1
816 iproc_pci_raw_config_read32(pcie, 0,
817 IPROC_PCI_EXP_CAP + PCI_EXP_LNKCTL2,
819 if ((link_ctrl & PCI_TARGET_LINK_SPEED_MASK) ==
820 PCI_TARGET_LINK_SPEED_GEN2) {
821 link_ctrl &= ~PCI_TARGET_LINK_SPEED_MASK;
822 link_ctrl |= PCI_TARGET_LINK_SPEED_GEN1;
823 iproc_pci_raw_config_write32(pcie, 0,
824 IPROC_PCI_EXP_CAP + PCI_EXP_LNKCTL2,
828 iproc_pci_raw_config_read32(pcie, 0,
829 IPROC_PCI_EXP_CAP + PCI_EXP_LNKSTA,
831 if (link_status & PCI_EXP_LNKSTA_NLW)
832 link_is_active = true;
836 dev_info(dev, "link: %s\n", link_is_active ? "UP" : "DOWN");
838 return link_is_active ? 0 : -ENODEV;
841 static void iproc_pcie_enable(struct iproc_pcie *pcie)
843 iproc_pcie_write_reg(pcie, IPROC_PCIE_INTX_EN, SYS_RC_INTX_MASK);
846 static inline bool iproc_pcie_ob_is_valid(struct iproc_pcie *pcie,
851 val = iproc_pcie_read_reg(pcie, MAP_REG(IPROC_PCIE_OARR0, window_idx));
853 return !!(val & OARR_VALID);
856 static inline int iproc_pcie_ob_write(struct iproc_pcie *pcie, int window_idx,
857 int size_idx, u64 axi_addr, u64 pci_addr)
859 struct device *dev = pcie->dev;
860 u16 oarr_offset, omap_offset;
863 * Derive the OARR/OMAP offset from the first pair (OARR0/OMAP0) based
866 oarr_offset = iproc_pcie_reg_offset(pcie, MAP_REG(IPROC_PCIE_OARR0,
868 omap_offset = iproc_pcie_reg_offset(pcie, MAP_REG(IPROC_PCIE_OMAP0,
870 if (iproc_pcie_reg_is_invalid(oarr_offset) ||
871 iproc_pcie_reg_is_invalid(omap_offset))
875 * Program the OARR registers. The upper 32-bit OARR register is
876 * always right after the lower 32-bit OARR register.
878 writel(lower_32_bits(axi_addr) | (size_idx << OARR_SIZE_CFG_SHIFT) |
879 OARR_VALID, pcie->base + oarr_offset);
880 writel(upper_32_bits(axi_addr), pcie->base + oarr_offset + 4);
882 /* now program the OMAP registers */
883 writel(lower_32_bits(pci_addr), pcie->base + omap_offset);
884 writel(upper_32_bits(pci_addr), pcie->base + omap_offset + 4);
886 dev_dbg(dev, "ob window [%d]: offset 0x%x axi %pap pci %pap\n",
887 window_idx, oarr_offset, &axi_addr, &pci_addr);
888 dev_dbg(dev, "oarr lo 0x%x oarr hi 0x%x\n",
889 readl(pcie->base + oarr_offset),
890 readl(pcie->base + oarr_offset + 4));
891 dev_dbg(dev, "omap lo 0x%x omap hi 0x%x\n",
892 readl(pcie->base + omap_offset),
893 readl(pcie->base + omap_offset + 4));
899 * Some iProc SoCs require the SW to configure the outbound address mapping
901 * Outbound address translation:
903 * iproc_pcie_address = axi_address - axi_offset
904 * OARR = iproc_pcie_address
907 * axi_addr -> iproc_pcie_address -> OARR -> OMAP -> pci_address
909 static int iproc_pcie_setup_ob(struct iproc_pcie *pcie, u64 axi_addr,
910 u64 pci_addr, resource_size_t size)
912 struct iproc_pcie_ob *ob = &pcie->ob;
913 struct device *dev = pcie->dev;
914 int ret = -EINVAL, window_idx, size_idx;
916 if (axi_addr < ob->axi_offset) {
917 dev_err(dev, "axi address %pap less than offset %pap\n",
918 &axi_addr, &ob->axi_offset);
923 * Translate the AXI address to the internal address used by the iProc
924 * PCIe core before programming the OARR
926 axi_addr -= ob->axi_offset;
928 /* iterate through all OARR/OMAP mapping windows */
929 for (window_idx = ob->nr_windows - 1; window_idx >= 0; window_idx--) {
930 const struct iproc_pcie_ob_map *ob_map =
931 &pcie->ob_map[window_idx];
934 * If current outbound window is already in use, move on to the
937 if (iproc_pcie_ob_is_valid(pcie, window_idx))
941 * Iterate through all supported window sizes within the
942 * OARR/OMAP pair to find a match. Go through the window sizes
943 * in a descending order.
945 for (size_idx = ob_map->nr_sizes - 1; size_idx >= 0;
947 resource_size_t window_size =
948 ob_map->window_sizes[size_idx] * SZ_1M;
951 * Keep iterating until we reach the last window and
952 * with the minimal window size at index zero. In this
953 * case, we take a compromise by mapping it using the
954 * minimum window size that can be supported
956 if (size < window_size) {
957 if (size_idx > 0 || window_idx > 0)
961 * For the corner case of reaching the minimal
962 * window size that can be supported on the
965 axi_addr = ALIGN_DOWN(axi_addr, window_size);
966 pci_addr = ALIGN_DOWN(pci_addr, window_size);
970 if (!IS_ALIGNED(axi_addr, window_size) ||
971 !IS_ALIGNED(pci_addr, window_size)) {
973 "axi %pap or pci %pap not aligned\n",
974 &axi_addr, &pci_addr);
979 * Match found! Program both OARR and OMAP and mark
980 * them as a valid entry.
982 ret = iproc_pcie_ob_write(pcie, window_idx, size_idx,
992 * If we are here, we are done with the current window,
993 * but not yet finished all mappings. Need to move on
994 * to the next window.
996 axi_addr += window_size;
997 pci_addr += window_size;
1003 dev_err(dev, "unable to configure outbound mapping\n");
1005 "axi %pap, axi offset %pap, pci %pap, res size %pap\n",
1006 &axi_addr, &ob->axi_offset, &pci_addr, &size);
1011 static int iproc_pcie_map_ranges(struct iproc_pcie *pcie,
1012 struct list_head *resources)
1014 struct device *dev = pcie->dev;
1015 struct resource_entry *window;
1018 resource_list_for_each_entry(window, resources) {
1019 struct resource *res = window->res;
1020 u64 res_type = resource_type(res);
1024 case IORESOURCE_BUS:
1026 case IORESOURCE_MEM:
1027 ret = iproc_pcie_setup_ob(pcie, res->start,
1028 res->start - window->offset,
1029 resource_size(res));
1034 dev_err(dev, "invalid resource %pR\n", res);
1042 static inline bool iproc_pcie_ib_is_in_use(struct iproc_pcie *pcie,
1045 const struct iproc_pcie_ib_map *ib_map = &pcie->ib_map[region_idx];
1048 val = iproc_pcie_read_reg(pcie, MAP_REG(IPROC_PCIE_IARR0, region_idx));
1050 return !!(val & (BIT(ib_map->nr_sizes) - 1));
1053 static inline bool iproc_pcie_ib_check_type(const struct iproc_pcie_ib_map *ib_map,
1054 enum iproc_pcie_ib_map_type type)
1056 return !!(ib_map->type == type);
1059 static int iproc_pcie_ib_write(struct iproc_pcie *pcie, int region_idx,
1060 int size_idx, int nr_windows, u64 axi_addr,
1061 u64 pci_addr, resource_size_t size)
1063 struct device *dev = pcie->dev;
1064 const struct iproc_pcie_ib_map *ib_map = &pcie->ib_map[region_idx];
1065 u16 iarr_offset, imap_offset;
1069 iarr_offset = iproc_pcie_reg_offset(pcie,
1070 MAP_REG(IPROC_PCIE_IARR0, region_idx));
1071 imap_offset = iproc_pcie_reg_offset(pcie,
1072 MAP_REG(IPROC_PCIE_IMAP0, region_idx));
1073 if (iproc_pcie_reg_is_invalid(iarr_offset) ||
1074 iproc_pcie_reg_is_invalid(imap_offset))
1077 dev_dbg(dev, "ib region [%d]: offset 0x%x axi %pap pci %pap\n",
1078 region_idx, iarr_offset, &axi_addr, &pci_addr);
1081 * Program the IARR registers. The upper 32-bit IARR register is
1082 * always right after the lower 32-bit IARR register.
1084 writel(lower_32_bits(pci_addr) | BIT(size_idx),
1085 pcie->base + iarr_offset);
1086 writel(upper_32_bits(pci_addr), pcie->base + iarr_offset + 4);
1088 dev_dbg(dev, "iarr lo 0x%x iarr hi 0x%x\n",
1089 readl(pcie->base + iarr_offset),
1090 readl(pcie->base + iarr_offset + 4));
1093 * Now program the IMAP registers. Each IARR region may have one or
1094 * more IMAP windows.
1096 size >>= ilog2(nr_windows);
1097 for (window_idx = 0; window_idx < nr_windows; window_idx++) {
1098 val = readl(pcie->base + imap_offset);
1099 val |= lower_32_bits(axi_addr) | IMAP_VALID;
1100 writel(val, pcie->base + imap_offset);
1101 writel(upper_32_bits(axi_addr),
1102 pcie->base + imap_offset + ib_map->imap_addr_offset);
1104 dev_dbg(dev, "imap window [%d] lo 0x%x hi 0x%x\n",
1105 window_idx, readl(pcie->base + imap_offset),
1106 readl(pcie->base + imap_offset +
1107 ib_map->imap_addr_offset));
1109 imap_offset += ib_map->imap_window_offset;
1116 static int iproc_pcie_setup_ib(struct iproc_pcie *pcie,
1117 struct resource_entry *entry,
1118 enum iproc_pcie_ib_map_type type)
1120 struct device *dev = pcie->dev;
1121 struct iproc_pcie_ib *ib = &pcie->ib;
1123 unsigned int region_idx, size_idx;
1124 u64 axi_addr = entry->res->start;
1125 u64 pci_addr = entry->res->start - entry->offset;
1126 resource_size_t size = resource_size(entry->res);
1128 /* iterate through all IARR mapping regions */
1129 for (region_idx = 0; region_idx < ib->nr_regions; region_idx++) {
1130 const struct iproc_pcie_ib_map *ib_map =
1131 &pcie->ib_map[region_idx];
1134 * If current inbound region is already in use or not a
1135 * compatible type, move on to the next.
1137 if (iproc_pcie_ib_is_in_use(pcie, region_idx) ||
1138 !iproc_pcie_ib_check_type(ib_map, type))
1141 /* iterate through all supported region sizes to find a match */
1142 for (size_idx = 0; size_idx < ib_map->nr_sizes; size_idx++) {
1143 resource_size_t region_size =
1144 ib_map->region_sizes[size_idx] * ib_map->size_unit;
1146 if (size != region_size)
1149 if (!IS_ALIGNED(axi_addr, region_size) ||
1150 !IS_ALIGNED(pci_addr, region_size)) {
1152 "axi %pap or pci %pap not aligned\n",
1153 &axi_addr, &pci_addr);
1157 /* Match found! Program IARR and all IMAP windows. */
1158 ret = iproc_pcie_ib_write(pcie, region_idx, size_idx,
1159 ib_map->nr_windows, axi_addr,
1171 dev_err(dev, "unable to configure inbound mapping\n");
1172 dev_err(dev, "axi %pap, pci %pap, res size %pap\n",
1173 &axi_addr, &pci_addr, &size);
1178 static int iproc_pcie_map_dma_ranges(struct iproc_pcie *pcie)
1180 struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie);
1181 struct resource_entry *entry;
1184 resource_list_for_each_entry(entry, &host->dma_ranges) {
1185 /* Each range entry corresponds to an inbound mapping region */
1186 ret = iproc_pcie_setup_ib(pcie, entry, IPROC_PCIE_IB_MAP_MEM);
1194 static void iproc_pcie_invalidate_mapping(struct iproc_pcie *pcie)
1196 struct iproc_pcie_ib *ib = &pcie->ib;
1197 struct iproc_pcie_ob *ob = &pcie->ob;
1200 if (pcie->ep_is_internal)
1203 if (pcie->need_ob_cfg) {
1204 /* iterate through all OARR mapping regions */
1205 for (idx = ob->nr_windows - 1; idx >= 0; idx--) {
1206 iproc_pcie_write_reg(pcie,
1207 MAP_REG(IPROC_PCIE_OARR0, idx), 0);
1211 if (pcie->need_ib_cfg) {
1212 /* iterate through all IARR mapping regions */
1213 for (idx = 0; idx < ib->nr_regions; idx++) {
1214 iproc_pcie_write_reg(pcie,
1215 MAP_REG(IPROC_PCIE_IARR0, idx), 0);
1220 static int iproce_pcie_get_msi(struct iproc_pcie *pcie,
1221 struct device_node *msi_node,
1224 struct device *dev = pcie->dev;
1226 struct resource res;
1229 * Check if 'msi-map' points to ARM GICv3 ITS, which is the only
1230 * supported external MSI controller that requires steering.
1232 if (!of_device_is_compatible(msi_node, "arm,gic-v3-its")) {
1233 dev_err(dev, "unable to find compatible MSI controller\n");
1237 /* derive GITS_TRANSLATER address from GICv3 */
1238 ret = of_address_to_resource(msi_node, 0, &res);
1240 dev_err(dev, "unable to obtain MSI controller resources\n");
1244 *msi_addr = res.start + GITS_TRANSLATER;
1248 static int iproc_pcie_paxb_v2_msi_steer(struct iproc_pcie *pcie, u64 msi_addr)
1251 struct resource_entry entry;
1253 memset(&entry, 0, sizeof(entry));
1254 entry.res = &entry.__res;
1256 msi_addr &= ~(SZ_32K - 1);
1257 entry.res->start = msi_addr;
1258 entry.res->end = msi_addr + SZ_32K - 1;
1260 ret = iproc_pcie_setup_ib(pcie, &entry, IPROC_PCIE_IB_MAP_IO);
1264 static void iproc_pcie_paxc_v2_msi_steer(struct iproc_pcie *pcie, u64 msi_addr,
1271 * Disable PAXC MSI steering. All write transfers will be
1272 * treated as non-MSI transfers
1274 val = iproc_pcie_read_reg(pcie, IPROC_PCIE_MSI_EN_CFG);
1275 val &= ~MSI_ENABLE_CFG;
1276 iproc_pcie_write_reg(pcie, IPROC_PCIE_MSI_EN_CFG, val);
1281 * Program bits [43:13] of address of GITS_TRANSLATER register into
1282 * bits [30:0] of the MSI base address register. In fact, in all iProc
1283 * based SoCs, all I/O register bases are well below the 32-bit
1284 * boundary, so we can safely assume bits [43:32] are always zeros.
1286 iproc_pcie_write_reg(pcie, IPROC_PCIE_MSI_BASE_ADDR,
1287 (u32)(msi_addr >> 13));
1289 /* use a default 8K window size */
1290 iproc_pcie_write_reg(pcie, IPROC_PCIE_MSI_WINDOW_SIZE, 0);
1292 /* steering MSI to GICv3 ITS */
1293 val = iproc_pcie_read_reg(pcie, IPROC_PCIE_MSI_GIC_MODE);
1295 iproc_pcie_write_reg(pcie, IPROC_PCIE_MSI_GIC_MODE, val);
1298 * Program bits [43:2] of address of GITS_TRANSLATER register into the
1299 * iProc MSI address registers.
1302 iproc_pcie_write_reg(pcie, IPROC_PCIE_MSI_ADDR_HI,
1303 upper_32_bits(msi_addr));
1304 iproc_pcie_write_reg(pcie, IPROC_PCIE_MSI_ADDR_LO,
1305 lower_32_bits(msi_addr));
1308 val = iproc_pcie_read_reg(pcie, IPROC_PCIE_MSI_EN_CFG);
1309 val |= MSI_ENABLE_CFG;
1310 iproc_pcie_write_reg(pcie, IPROC_PCIE_MSI_EN_CFG, val);
1313 static int iproc_pcie_msi_steer(struct iproc_pcie *pcie,
1314 struct device_node *msi_node)
1316 struct device *dev = pcie->dev;
1320 ret = iproce_pcie_get_msi(pcie, msi_node, &msi_addr);
1322 dev_err(dev, "msi steering failed\n");
1326 switch (pcie->type) {
1327 case IPROC_PCIE_PAXB_V2:
1328 ret = iproc_pcie_paxb_v2_msi_steer(pcie, msi_addr);
1332 case IPROC_PCIE_PAXC_V2:
1333 iproc_pcie_paxc_v2_msi_steer(pcie, msi_addr, true);
1342 static int iproc_pcie_msi_enable(struct iproc_pcie *pcie)
1344 struct device_node *msi_node;
1348 * Either the "msi-parent" or the "msi-map" phandle needs to exist
1349 * for us to obtain the MSI node.
1352 msi_node = of_parse_phandle(pcie->dev->of_node, "msi-parent", 0);
1354 const __be32 *msi_map = NULL;
1358 msi_map = of_get_property(pcie->dev->of_node, "msi-map", &len);
1362 phandle = be32_to_cpup(msi_map + 1);
1363 msi_node = of_find_node_by_phandle(phandle);
1369 * Certain revisions of the iProc PCIe controller require additional
1370 * configurations to steer the MSI writes towards an external MSI
1373 if (pcie->need_msi_steer) {
1374 ret = iproc_pcie_msi_steer(pcie, msi_node);
1380 * If another MSI controller is being used, the call below should fail
1383 ret = iproc_msi_init(pcie, msi_node);
1386 of_node_put(msi_node);
1390 static void iproc_pcie_msi_disable(struct iproc_pcie *pcie)
1392 iproc_msi_exit(pcie);
1395 static int iproc_pcie_rev_init(struct iproc_pcie *pcie)
1397 struct device *dev = pcie->dev;
1398 unsigned int reg_idx;
1401 switch (pcie->type) {
1402 case IPROC_PCIE_PAXB_BCMA:
1403 regs = iproc_pcie_reg_paxb_bcma;
1405 case IPROC_PCIE_PAXB:
1406 regs = iproc_pcie_reg_paxb;
1407 pcie->has_apb_err_disable = true;
1408 if (pcie->need_ob_cfg) {
1409 pcie->ob_map = paxb_ob_map;
1410 pcie->ob.nr_windows = ARRAY_SIZE(paxb_ob_map);
1413 case IPROC_PCIE_PAXB_V2:
1414 regs = iproc_pcie_reg_paxb_v2;
1415 pcie->iproc_cfg_read = true;
1416 pcie->has_apb_err_disable = true;
1417 if (pcie->need_ob_cfg) {
1418 pcie->ob_map = paxb_v2_ob_map;
1419 pcie->ob.nr_windows = ARRAY_SIZE(paxb_v2_ob_map);
1421 pcie->ib.nr_regions = ARRAY_SIZE(paxb_v2_ib_map);
1422 pcie->ib_map = paxb_v2_ib_map;
1423 pcie->need_msi_steer = true;
1424 dev_warn(dev, "reads of config registers that contain %#x return incorrect data\n",
1427 case IPROC_PCIE_PAXC:
1428 regs = iproc_pcie_reg_paxc;
1429 pcie->ep_is_internal = true;
1430 pcie->iproc_cfg_read = true;
1431 pcie->rej_unconfig_pf = true;
1433 case IPROC_PCIE_PAXC_V2:
1434 regs = iproc_pcie_reg_paxc_v2;
1435 pcie->ep_is_internal = true;
1436 pcie->iproc_cfg_read = true;
1437 pcie->rej_unconfig_pf = true;
1438 pcie->need_msi_steer = true;
1441 dev_err(dev, "incompatible iProc PCIe interface\n");
1445 pcie->reg_offsets = devm_kcalloc(dev, IPROC_PCIE_MAX_NUM_REG,
1446 sizeof(*pcie->reg_offsets),
1448 if (!pcie->reg_offsets)
1451 /* go through the register table and populate all valid registers */
1452 pcie->reg_offsets[0] = (pcie->type == IPROC_PCIE_PAXC_V2) ?
1453 IPROC_PCIE_REG_INVALID : regs[0];
1454 for (reg_idx = 1; reg_idx < IPROC_PCIE_MAX_NUM_REG; reg_idx++)
1455 pcie->reg_offsets[reg_idx] = regs[reg_idx] ?
1456 regs[reg_idx] : IPROC_PCIE_REG_INVALID;
1461 int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res)
1465 struct pci_dev *pdev;
1466 struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie);
1470 ret = iproc_pcie_rev_init(pcie);
1472 dev_err(dev, "unable to initialize controller parameters\n");
1476 ret = phy_init(pcie->phy);
1478 dev_err(dev, "unable to initialize PCIe PHY\n");
1482 ret = phy_power_on(pcie->phy);
1484 dev_err(dev, "unable to power on PCIe PHY\n");
1488 iproc_pcie_perst_ctrl(pcie, true);
1489 iproc_pcie_perst_ctrl(pcie, false);
1491 iproc_pcie_invalidate_mapping(pcie);
1493 if (pcie->need_ob_cfg) {
1494 ret = iproc_pcie_map_ranges(pcie, res);
1496 dev_err(dev, "map failed\n");
1497 goto err_power_off_phy;
1501 if (pcie->need_ib_cfg) {
1502 ret = iproc_pcie_map_dma_ranges(pcie);
1503 if (ret && ret != -ENOENT)
1504 goto err_power_off_phy;
1507 ret = iproc_pcie_check_link(pcie);
1509 dev_err(dev, "no PCIe EP device detected\n");
1510 goto err_power_off_phy;
1513 iproc_pcie_enable(pcie);
1515 if (IS_ENABLED(CONFIG_PCI_MSI))
1516 if (iproc_pcie_msi_enable(pcie))
1517 dev_info(dev, "not using iProc MSI\n");
1519 host->ops = &iproc_pcie_ops;
1520 host->sysdata = pcie;
1521 host->map_irq = pcie->map_irq;
1523 ret = pci_host_probe(host);
1525 dev_err(dev, "failed to scan host: %d\n", ret);
1526 goto err_power_off_phy;
1529 for_each_pci_bridge(pdev, host->bus) {
1530 if (pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT)
1531 pcie_print_link_status(pdev);
1537 phy_power_off(pcie->phy);
1539 phy_exit(pcie->phy);
1542 EXPORT_SYMBOL(iproc_pcie_setup);
1544 int iproc_pcie_remove(struct iproc_pcie *pcie)
1546 struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie);
1548 pci_stop_root_bus(host->bus);
1549 pci_remove_root_bus(host->bus);
1551 iproc_pcie_msi_disable(pcie);
1553 phy_power_off(pcie->phy);
1554 phy_exit(pcie->phy);
1558 EXPORT_SYMBOL(iproc_pcie_remove);
1561 * The MSI parsing logic in certain revisions of Broadcom PAXC based root
1562 * complex does not work and needs to be disabled
1564 static void quirk_paxc_disable_msi_parsing(struct pci_dev *pdev)
1566 struct iproc_pcie *pcie = iproc_data(pdev->bus);
1568 if (pdev->hdr_type == PCI_HEADER_TYPE_BRIDGE)
1569 iproc_pcie_paxc_v2_msi_steer(pcie, 0, false);
1571 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0x16f0,
1572 quirk_paxc_disable_msi_parsing);
1573 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0xd802,
1574 quirk_paxc_disable_msi_parsing);
1575 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0xd804,
1576 quirk_paxc_disable_msi_parsing);
1578 static void quirk_paxc_bridge(struct pci_dev *pdev)
1581 * The PCI config space is shared with the PAXC root port and the first
1582 * Ethernet device. So, we need to workaround this by telling the PCI
1583 * code that the bridge is not an Ethernet device.
1585 if (pdev->hdr_type == PCI_HEADER_TYPE_BRIDGE)
1586 pdev->class = PCI_CLASS_BRIDGE_PCI << 8;
1589 * MPSS is not being set properly (as it is currently 0). This is
1590 * because that area of the PCI config space is hard coded to zero, and
1591 * is not modifiable by firmware. Set this to 2 (e.g., 512 byte MPS)
1592 * so that the MPS can be set to the real max value.
1594 pdev->pcie_mpss = 2;
1596 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0x16cd, quirk_paxc_bridge);
1597 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0x16f0, quirk_paxc_bridge);
1598 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0xd750, quirk_paxc_bridge);
1599 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0xd802, quirk_paxc_bridge);
1600 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0xd804, quirk_paxc_bridge);
1603 MODULE_DESCRIPTION("Broadcom iPROC PCIe common driver");
1604 MODULE_LICENSE("GPL v2");