Bjorn Helgaas | 8cfab3c | 2018-01-26 12:50:27 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2014 Hauke Mehrtens <hauke@hauke-m.de> |
Florian Fainelli | be908d2 | 2015-10-16 12:04:04 -0700 | [diff] [blame] | 4 | * Copyright (C) 2015 Broadcom Corporation |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/kernel.h> |
| 8 | #include <linux/pci.h> |
| 9 | #include <linux/msi.h> |
| 10 | #include <linux/clk.h> |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/mbus.h> |
| 13 | #include <linux/slab.h> |
| 14 | #include <linux/delay.h> |
| 15 | #include <linux/interrupt.h> |
Ray Jui | 787b3c4 | 2016-10-31 17:38:35 -0700 | [diff] [blame] | 16 | #include <linux/irqchip/arm-gic-v3.h> |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/of_address.h> |
| 19 | #include <linux/of_pci.h> |
| 20 | #include <linux/of_irq.h> |
| 21 | #include <linux/of_platform.h> |
| 22 | #include <linux/phy/phy.h> |
| 23 | |
| 24 | #include "pcie-iproc.h" |
| 25 | |
Bjorn Helgaas | ef685b3 | 2017-09-05 12:33:33 -0500 | [diff] [blame] | 26 | #define EP_PERST_SOURCE_SELECT_SHIFT 2 |
| 27 | #define EP_PERST_SOURCE_SELECT BIT(EP_PERST_SOURCE_SELECT_SHIFT) |
| 28 | #define EP_MODE_SURVIVE_PERST_SHIFT 1 |
| 29 | #define EP_MODE_SURVIVE_PERST BIT(EP_MODE_SURVIVE_PERST_SHIFT) |
| 30 | #define RC_PCIE_RST_OUTPUT_SHIFT 0 |
| 31 | #define RC_PCIE_RST_OUTPUT BIT(RC_PCIE_RST_OUTPUT_SHIFT) |
| 32 | #define PAXC_RESET_MASK 0x7f |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 33 | |
Bjorn Helgaas | ef685b3 | 2017-09-05 12:33:33 -0500 | [diff] [blame] | 34 | #define GIC_V3_CFG_SHIFT 0 |
| 35 | #define GIC_V3_CFG BIT(GIC_V3_CFG_SHIFT) |
Ray Jui | 787b3c4 | 2016-10-31 17:38:35 -0700 | [diff] [blame] | 36 | |
Bjorn Helgaas | ef685b3 | 2017-09-05 12:33:33 -0500 | [diff] [blame] | 37 | #define MSI_ENABLE_CFG_SHIFT 0 |
| 38 | #define MSI_ENABLE_CFG BIT(MSI_ENABLE_CFG_SHIFT) |
Ray Jui | 787b3c4 | 2016-10-31 17:38:35 -0700 | [diff] [blame] | 39 | |
Bjorn Helgaas | ef685b3 | 2017-09-05 12:33:33 -0500 | [diff] [blame] | 40 | #define CFG_IND_ADDR_MASK 0x00001ffc |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 41 | |
Bjorn Helgaas | ef685b3 | 2017-09-05 12:33:33 -0500 | [diff] [blame] | 42 | #define CFG_ADDR_BUS_NUM_SHIFT 20 |
| 43 | #define CFG_ADDR_BUS_NUM_MASK 0x0ff00000 |
| 44 | #define CFG_ADDR_DEV_NUM_SHIFT 15 |
| 45 | #define CFG_ADDR_DEV_NUM_MASK 0x000f8000 |
| 46 | #define CFG_ADDR_FUNC_NUM_SHIFT 12 |
| 47 | #define CFG_ADDR_FUNC_NUM_MASK 0x00007000 |
| 48 | #define CFG_ADDR_REG_NUM_SHIFT 2 |
| 49 | #define CFG_ADDR_REG_NUM_MASK 0x00000ffc |
| 50 | #define CFG_ADDR_CFG_TYPE_SHIFT 0 |
| 51 | #define CFG_ADDR_CFG_TYPE_MASK 0x00000003 |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 52 | |
Bjorn Helgaas | ef685b3 | 2017-09-05 12:33:33 -0500 | [diff] [blame] | 53 | #define SYS_RC_INTX_MASK 0xf |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 54 | |
Bjorn Helgaas | ef685b3 | 2017-09-05 12:33:33 -0500 | [diff] [blame] | 55 | #define PCIE_PHYLINKUP_SHIFT 3 |
| 56 | #define PCIE_PHYLINKUP BIT(PCIE_PHYLINKUP_SHIFT) |
| 57 | #define PCIE_DL_ACTIVE_SHIFT 2 |
| 58 | #define PCIE_DL_ACTIVE BIT(PCIE_DL_ACTIVE_SHIFT) |
Ray Jui | aaf22ab | 2015-09-15 17:39:19 -0700 | [diff] [blame] | 59 | |
Bjorn Helgaas | ef685b3 | 2017-09-05 12:33:33 -0500 | [diff] [blame] | 60 | #define APB_ERR_EN_SHIFT 0 |
| 61 | #define APB_ERR_EN BIT(APB_ERR_EN_SHIFT) |
Ray Jui | 538928f | 2016-10-31 17:38:33 -0700 | [diff] [blame] | 62 | |
Bjorn Helgaas | ef685b3 | 2017-09-05 12:33:33 -0500 | [diff] [blame] | 63 | #define CFG_RETRY_STATUS 0xffff0001 |
| 64 | #define CFG_RETRY_STATUS_TIMEOUT_US 500000 /* 500 milliseconds */ |
Oza Pawandeep | 39b7a4f | 2017-08-28 16:43:30 -0500 | [diff] [blame] | 65 | |
Ray Jui | 4213e15 | 2016-10-31 17:38:37 -0700 | [diff] [blame] | 66 | /* derive the enum index of the outbound/inbound mapping registers */ |
Bjorn Helgaas | ef685b3 | 2017-09-05 12:33:33 -0500 | [diff] [blame] | 67 | #define MAP_REG(base_reg, index) ((base_reg) + (index) * 2) |
Ray Jui | 4213e15 | 2016-10-31 17:38:37 -0700 | [diff] [blame] | 68 | |
| 69 | /* |
| 70 | * Maximum number of outbound mapping window sizes that can be supported by any |
| 71 | * OARR/OMAP mapping pair |
| 72 | */ |
Bjorn Helgaas | ef685b3 | 2017-09-05 12:33:33 -0500 | [diff] [blame] | 73 | #define MAX_NUM_OB_WINDOW_SIZES 4 |
Ray Jui | 4213e15 | 2016-10-31 17:38:37 -0700 | [diff] [blame] | 74 | |
Bjorn Helgaas | ef685b3 | 2017-09-05 12:33:33 -0500 | [diff] [blame] | 75 | #define OARR_VALID_SHIFT 0 |
| 76 | #define OARR_VALID BIT(OARR_VALID_SHIFT) |
| 77 | #define OARR_SIZE_CFG_SHIFT 1 |
Ray Jui | e99a187 | 2015-10-16 08:18:24 -0500 | [diff] [blame] | 78 | |
Ray Jui | dd9d4e7 | 2016-10-31 17:38:39 -0700 | [diff] [blame] | 79 | /* |
| 80 | * Maximum number of inbound mapping region sizes that can be supported by an |
| 81 | * IARR |
| 82 | */ |
Bjorn Helgaas | ef685b3 | 2017-09-05 12:33:33 -0500 | [diff] [blame] | 83 | #define MAX_NUM_IB_REGION_SIZES 9 |
Ray Jui | dd9d4e7 | 2016-10-31 17:38:39 -0700 | [diff] [blame] | 84 | |
Bjorn Helgaas | ef685b3 | 2017-09-05 12:33:33 -0500 | [diff] [blame] | 85 | #define IMAP_VALID_SHIFT 0 |
| 86 | #define IMAP_VALID BIT(IMAP_VALID_SHIFT) |
Ray Jui | dd9d4e7 | 2016-10-31 17:38:39 -0700 | [diff] [blame] | 87 | |
Ray Jui | 3bc7082 | 2018-06-11 17:21:04 -0700 | [diff] [blame^] | 88 | #define IPROC_PCI_PM_CAP 0x48 |
| 89 | #define IPROC_PCI_PM_CAP_MASK 0xffff |
Bjorn Helgaas | d8fa934 | 2017-09-05 12:27:11 -0500 | [diff] [blame] | 90 | #define IPROC_PCI_EXP_CAP 0xac |
Bjorn Helgaas | e3a1698 | 2016-10-06 13:36:07 -0500 | [diff] [blame] | 91 | |
Bjorn Helgaas | ef685b3 | 2017-09-05 12:33:33 -0500 | [diff] [blame] | 92 | #define IPROC_PCIE_REG_INVALID 0xffff |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 93 | |
Ray Jui | 4213e15 | 2016-10-31 17:38:37 -0700 | [diff] [blame] | 94 | /** |
| 95 | * iProc PCIe outbound mapping controller specific parameters |
| 96 | * |
| 97 | * @window_sizes: list of supported outbound mapping window sizes in MB |
| 98 | * @nr_sizes: number of supported outbound mapping window sizes |
| 99 | */ |
| 100 | struct iproc_pcie_ob_map { |
| 101 | resource_size_t window_sizes[MAX_NUM_OB_WINDOW_SIZES]; |
| 102 | unsigned int nr_sizes; |
| 103 | }; |
| 104 | |
| 105 | static const struct iproc_pcie_ob_map paxb_ob_map[] = { |
| 106 | { |
| 107 | /* OARR0/OMAP0 */ |
| 108 | .window_sizes = { 128, 256 }, |
| 109 | .nr_sizes = 2, |
| 110 | }, |
| 111 | { |
| 112 | /* OARR1/OMAP1 */ |
| 113 | .window_sizes = { 128, 256 }, |
| 114 | .nr_sizes = 2, |
| 115 | }, |
| 116 | }; |
| 117 | |
Ray Jui | c7c4452 | 2016-10-31 17:38:41 -0700 | [diff] [blame] | 118 | static const struct iproc_pcie_ob_map paxb_v2_ob_map[] = { |
| 119 | { |
| 120 | /* OARR0/OMAP0 */ |
| 121 | .window_sizes = { 128, 256 }, |
| 122 | .nr_sizes = 2, |
| 123 | }, |
| 124 | { |
| 125 | /* OARR1/OMAP1 */ |
| 126 | .window_sizes = { 128, 256 }, |
| 127 | .nr_sizes = 2, |
| 128 | }, |
| 129 | { |
| 130 | /* OARR2/OMAP2 */ |
| 131 | .window_sizes = { 128, 256, 512, 1024 }, |
| 132 | .nr_sizes = 4, |
| 133 | }, |
| 134 | { |
| 135 | /* OARR3/OMAP3 */ |
| 136 | .window_sizes = { 128, 256, 512, 1024 }, |
| 137 | .nr_sizes = 4, |
| 138 | }, |
| 139 | }; |
| 140 | |
Ray Jui | dd9d4e7 | 2016-10-31 17:38:39 -0700 | [diff] [blame] | 141 | /** |
| 142 | * iProc PCIe inbound mapping type |
| 143 | */ |
| 144 | enum iproc_pcie_ib_map_type { |
| 145 | /* for DDR memory */ |
| 146 | IPROC_PCIE_IB_MAP_MEM = 0, |
| 147 | |
| 148 | /* for device I/O memory */ |
| 149 | IPROC_PCIE_IB_MAP_IO, |
| 150 | |
| 151 | /* invalid or unused */ |
| 152 | IPROC_PCIE_IB_MAP_INVALID |
| 153 | }; |
| 154 | |
| 155 | /** |
| 156 | * iProc PCIe inbound mapping controller specific parameters |
| 157 | * |
| 158 | * @type: inbound mapping region type |
| 159 | * @size_unit: inbound mapping region size unit, could be SZ_1K, SZ_1M, or |
| 160 | * SZ_1G |
| 161 | * @region_sizes: list of supported inbound mapping region sizes in KB, MB, or |
| 162 | * GB, depedning on the size unit |
| 163 | * @nr_sizes: number of supported inbound mapping region sizes |
| 164 | * @nr_windows: number of supported inbound mapping windows for the region |
| 165 | * @imap_addr_offset: register offset between the upper and lower 32-bit |
| 166 | * IMAP address registers |
| 167 | * @imap_window_offset: register offset between each IMAP window |
| 168 | */ |
| 169 | struct iproc_pcie_ib_map { |
| 170 | enum iproc_pcie_ib_map_type type; |
| 171 | unsigned int size_unit; |
| 172 | resource_size_t region_sizes[MAX_NUM_IB_REGION_SIZES]; |
| 173 | unsigned int nr_sizes; |
| 174 | unsigned int nr_windows; |
| 175 | u16 imap_addr_offset; |
| 176 | u16 imap_window_offset; |
| 177 | }; |
| 178 | |
Ray Jui | c7c4452 | 2016-10-31 17:38:41 -0700 | [diff] [blame] | 179 | static const struct iproc_pcie_ib_map paxb_v2_ib_map[] = { |
| 180 | { |
| 181 | /* IARR0/IMAP0 */ |
| 182 | .type = IPROC_PCIE_IB_MAP_IO, |
| 183 | .size_unit = SZ_1K, |
| 184 | .region_sizes = { 32 }, |
| 185 | .nr_sizes = 1, |
| 186 | .nr_windows = 8, |
| 187 | .imap_addr_offset = 0x40, |
| 188 | .imap_window_offset = 0x4, |
| 189 | }, |
| 190 | { |
| 191 | /* IARR1/IMAP1 (currently unused) */ |
| 192 | .type = IPROC_PCIE_IB_MAP_INVALID, |
| 193 | }, |
| 194 | { |
| 195 | /* IARR2/IMAP2 */ |
| 196 | .type = IPROC_PCIE_IB_MAP_MEM, |
| 197 | .size_unit = SZ_1M, |
| 198 | .region_sizes = { 64, 128, 256, 512, 1024, 2048, 4096, 8192, |
| 199 | 16384 }, |
| 200 | .nr_sizes = 9, |
| 201 | .nr_windows = 1, |
| 202 | .imap_addr_offset = 0x4, |
| 203 | .imap_window_offset = 0x8, |
| 204 | }, |
| 205 | { |
| 206 | /* IARR3/IMAP3 */ |
| 207 | .type = IPROC_PCIE_IB_MAP_MEM, |
| 208 | .size_unit = SZ_1G, |
| 209 | .region_sizes = { 1, 2, 4, 8, 16, 32 }, |
| 210 | .nr_sizes = 6, |
| 211 | .nr_windows = 8, |
| 212 | .imap_addr_offset = 0x4, |
| 213 | .imap_window_offset = 0x8, |
| 214 | }, |
| 215 | { |
| 216 | /* IARR4/IMAP4 */ |
| 217 | .type = IPROC_PCIE_IB_MAP_MEM, |
| 218 | .size_unit = SZ_1G, |
| 219 | .region_sizes = { 32, 64, 128, 256, 512 }, |
| 220 | .nr_sizes = 5, |
| 221 | .nr_windows = 8, |
| 222 | .imap_addr_offset = 0x4, |
| 223 | .imap_window_offset = 0x8, |
| 224 | }, |
| 225 | }; |
| 226 | |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 227 | /* |
| 228 | * iProc PCIe host registers |
| 229 | */ |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 230 | enum iproc_pcie_reg { |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 231 | /* clock/reset signal control */ |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 232 | IPROC_PCIE_CLK_CTRL = 0, |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 233 | |
Ray Jui | 787b3c4 | 2016-10-31 17:38:35 -0700 | [diff] [blame] | 234 | /* |
| 235 | * To allow MSI to be steered to an external MSI controller (e.g., ARM |
| 236 | * GICv3 ITS) |
| 237 | */ |
| 238 | IPROC_PCIE_MSI_GIC_MODE, |
| 239 | |
| 240 | /* |
| 241 | * IPROC_PCIE_MSI_BASE_ADDR and IPROC_PCIE_MSI_WINDOW_SIZE define the |
| 242 | * window where the MSI posted writes are written, for the writes to be |
| 243 | * interpreted as MSI writes. |
| 244 | */ |
| 245 | IPROC_PCIE_MSI_BASE_ADDR, |
| 246 | IPROC_PCIE_MSI_WINDOW_SIZE, |
| 247 | |
| 248 | /* |
| 249 | * To hold the address of the register where the MSI writes are |
| 250 | * programed. When ARM GICv3 ITS is used, this should be programmed |
| 251 | * with the address of the GITS_TRANSLATER register. |
| 252 | */ |
| 253 | IPROC_PCIE_MSI_ADDR_LO, |
| 254 | IPROC_PCIE_MSI_ADDR_HI, |
| 255 | |
| 256 | /* enable MSI */ |
| 257 | IPROC_PCIE_MSI_EN_CFG, |
| 258 | |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 259 | /* allow access to root complex configuration space */ |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 260 | IPROC_PCIE_CFG_IND_ADDR, |
| 261 | IPROC_PCIE_CFG_IND_DATA, |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 262 | |
| 263 | /* allow access to device configuration space */ |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 264 | IPROC_PCIE_CFG_ADDR, |
| 265 | IPROC_PCIE_CFG_DATA, |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 266 | |
| 267 | /* enable INTx */ |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 268 | IPROC_PCIE_INTX_EN, |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 269 | |
| 270 | /* outbound address mapping */ |
Ray Jui | 4213e15 | 2016-10-31 17:38:37 -0700 | [diff] [blame] | 271 | IPROC_PCIE_OARR0, |
| 272 | IPROC_PCIE_OMAP0, |
| 273 | IPROC_PCIE_OARR1, |
| 274 | IPROC_PCIE_OMAP1, |
| 275 | IPROC_PCIE_OARR2, |
| 276 | IPROC_PCIE_OMAP2, |
| 277 | IPROC_PCIE_OARR3, |
| 278 | IPROC_PCIE_OMAP3, |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 279 | |
Ray Jui | dd9d4e7 | 2016-10-31 17:38:39 -0700 | [diff] [blame] | 280 | /* inbound address mapping */ |
| 281 | IPROC_PCIE_IARR0, |
| 282 | IPROC_PCIE_IMAP0, |
| 283 | IPROC_PCIE_IARR1, |
| 284 | IPROC_PCIE_IMAP1, |
| 285 | IPROC_PCIE_IARR2, |
| 286 | IPROC_PCIE_IMAP2, |
| 287 | IPROC_PCIE_IARR3, |
| 288 | IPROC_PCIE_IMAP3, |
| 289 | IPROC_PCIE_IARR4, |
| 290 | IPROC_PCIE_IMAP4, |
| 291 | |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 292 | /* link status */ |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 293 | IPROC_PCIE_LINK_STATUS, |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 294 | |
Ray Jui | 538928f | 2016-10-31 17:38:33 -0700 | [diff] [blame] | 295 | /* enable APB error for unsupported requests */ |
| 296 | IPROC_PCIE_APB_ERR_EN, |
| 297 | |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 298 | /* total number of core registers */ |
| 299 | IPROC_PCIE_MAX_NUM_REG, |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 300 | }; |
| 301 | |
Ray Jui | 404349c | 2016-10-31 17:38:32 -0700 | [diff] [blame] | 302 | /* iProc PCIe PAXB BCMA registers */ |
| 303 | static const u16 iproc_pcie_reg_paxb_bcma[] = { |
Bjorn Helgaas | ef685b3 | 2017-09-05 12:33:33 -0500 | [diff] [blame] | 304 | [IPROC_PCIE_CLK_CTRL] = 0x000, |
| 305 | [IPROC_PCIE_CFG_IND_ADDR] = 0x120, |
| 306 | [IPROC_PCIE_CFG_IND_DATA] = 0x124, |
| 307 | [IPROC_PCIE_CFG_ADDR] = 0x1f8, |
| 308 | [IPROC_PCIE_CFG_DATA] = 0x1fc, |
| 309 | [IPROC_PCIE_INTX_EN] = 0x330, |
| 310 | [IPROC_PCIE_LINK_STATUS] = 0xf0c, |
Ray Jui | 404349c | 2016-10-31 17:38:32 -0700 | [diff] [blame] | 311 | }; |
| 312 | |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 313 | /* iProc PCIe PAXB registers */ |
| 314 | static const u16 iproc_pcie_reg_paxb[] = { |
Bjorn Helgaas | ef685b3 | 2017-09-05 12:33:33 -0500 | [diff] [blame] | 315 | [IPROC_PCIE_CLK_CTRL] = 0x000, |
| 316 | [IPROC_PCIE_CFG_IND_ADDR] = 0x120, |
| 317 | [IPROC_PCIE_CFG_IND_DATA] = 0x124, |
| 318 | [IPROC_PCIE_CFG_ADDR] = 0x1f8, |
| 319 | [IPROC_PCIE_CFG_DATA] = 0x1fc, |
| 320 | [IPROC_PCIE_INTX_EN] = 0x330, |
| 321 | [IPROC_PCIE_OARR0] = 0xd20, |
| 322 | [IPROC_PCIE_OMAP0] = 0xd40, |
| 323 | [IPROC_PCIE_OARR1] = 0xd28, |
| 324 | [IPROC_PCIE_OMAP1] = 0xd48, |
| 325 | [IPROC_PCIE_LINK_STATUS] = 0xf0c, |
| 326 | [IPROC_PCIE_APB_ERR_EN] = 0xf40, |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 327 | }; |
| 328 | |
Ray Jui | c7c4452 | 2016-10-31 17:38:41 -0700 | [diff] [blame] | 329 | /* iProc PCIe PAXB v2 registers */ |
| 330 | static const u16 iproc_pcie_reg_paxb_v2[] = { |
Bjorn Helgaas | ef685b3 | 2017-09-05 12:33:33 -0500 | [diff] [blame] | 331 | [IPROC_PCIE_CLK_CTRL] = 0x000, |
| 332 | [IPROC_PCIE_CFG_IND_ADDR] = 0x120, |
| 333 | [IPROC_PCIE_CFG_IND_DATA] = 0x124, |
| 334 | [IPROC_PCIE_CFG_ADDR] = 0x1f8, |
| 335 | [IPROC_PCIE_CFG_DATA] = 0x1fc, |
| 336 | [IPROC_PCIE_INTX_EN] = 0x330, |
| 337 | [IPROC_PCIE_OARR0] = 0xd20, |
| 338 | [IPROC_PCIE_OMAP0] = 0xd40, |
| 339 | [IPROC_PCIE_OARR1] = 0xd28, |
| 340 | [IPROC_PCIE_OMAP1] = 0xd48, |
| 341 | [IPROC_PCIE_OARR2] = 0xd60, |
| 342 | [IPROC_PCIE_OMAP2] = 0xd68, |
| 343 | [IPROC_PCIE_OARR3] = 0xdf0, |
| 344 | [IPROC_PCIE_OMAP3] = 0xdf8, |
| 345 | [IPROC_PCIE_IARR0] = 0xd00, |
| 346 | [IPROC_PCIE_IMAP0] = 0xc00, |
| 347 | [IPROC_PCIE_IARR2] = 0xd10, |
| 348 | [IPROC_PCIE_IMAP2] = 0xcc0, |
| 349 | [IPROC_PCIE_IARR3] = 0xe00, |
| 350 | [IPROC_PCIE_IMAP3] = 0xe08, |
| 351 | [IPROC_PCIE_IARR4] = 0xe68, |
| 352 | [IPROC_PCIE_IMAP4] = 0xe70, |
| 353 | [IPROC_PCIE_LINK_STATUS] = 0xf0c, |
| 354 | [IPROC_PCIE_APB_ERR_EN] = 0xf40, |
Ray Jui | c7c4452 | 2016-10-31 17:38:41 -0700 | [diff] [blame] | 355 | }; |
| 356 | |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 357 | /* iProc PCIe PAXC v1 registers */ |
| 358 | static const u16 iproc_pcie_reg_paxc[] = { |
Bjorn Helgaas | ef685b3 | 2017-09-05 12:33:33 -0500 | [diff] [blame] | 359 | [IPROC_PCIE_CLK_CTRL] = 0x000, |
| 360 | [IPROC_PCIE_CFG_IND_ADDR] = 0x1f0, |
| 361 | [IPROC_PCIE_CFG_IND_DATA] = 0x1f4, |
| 362 | [IPROC_PCIE_CFG_ADDR] = 0x1f8, |
| 363 | [IPROC_PCIE_CFG_DATA] = 0x1fc, |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 364 | }; |
Ray Jui | e99a187 | 2015-10-16 08:18:24 -0500 | [diff] [blame] | 365 | |
Ray Jui | 787b3c4 | 2016-10-31 17:38:35 -0700 | [diff] [blame] | 366 | /* iProc PCIe PAXC v2 registers */ |
| 367 | static const u16 iproc_pcie_reg_paxc_v2[] = { |
Bjorn Helgaas | ef685b3 | 2017-09-05 12:33:33 -0500 | [diff] [blame] | 368 | [IPROC_PCIE_MSI_GIC_MODE] = 0x050, |
| 369 | [IPROC_PCIE_MSI_BASE_ADDR] = 0x074, |
| 370 | [IPROC_PCIE_MSI_WINDOW_SIZE] = 0x078, |
| 371 | [IPROC_PCIE_MSI_ADDR_LO] = 0x07c, |
| 372 | [IPROC_PCIE_MSI_ADDR_HI] = 0x080, |
| 373 | [IPROC_PCIE_MSI_EN_CFG] = 0x09c, |
| 374 | [IPROC_PCIE_CFG_IND_ADDR] = 0x1f0, |
| 375 | [IPROC_PCIE_CFG_IND_DATA] = 0x1f4, |
| 376 | [IPROC_PCIE_CFG_ADDR] = 0x1f8, |
| 377 | [IPROC_PCIE_CFG_DATA] = 0x1fc, |
Ray Jui | 787b3c4 | 2016-10-31 17:38:35 -0700 | [diff] [blame] | 378 | }; |
| 379 | |
Ray Jui | 3bc7082 | 2018-06-11 17:21:04 -0700 | [diff] [blame^] | 380 | /* |
| 381 | * List of device IDs of controllers that have corrupted capability list that |
| 382 | * require SW fixup |
| 383 | */ |
| 384 | static const u16 iproc_pcie_corrupt_cap_did[] = { |
| 385 | 0x16cd, |
| 386 | 0x16f0, |
| 387 | 0xd802, |
| 388 | 0xd804 |
| 389 | }; |
| 390 | |
Ray Jui | 8d9bfe3 | 2015-07-21 18:29:40 -0700 | [diff] [blame] | 391 | static inline struct iproc_pcie *iproc_data(struct pci_bus *bus) |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 392 | { |
Rob Herring | a1b363a | 2018-03-07 09:42:36 -0600 | [diff] [blame] | 393 | struct iproc_pcie *pcie = bus->sysdata; |
Ray Jui | 8d9bfe3 | 2015-07-21 18:29:40 -0700 | [diff] [blame] | 394 | return pcie; |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 397 | static inline bool iproc_pcie_reg_is_invalid(u16 reg_offset) |
| 398 | { |
| 399 | return !!(reg_offset == IPROC_PCIE_REG_INVALID); |
| 400 | } |
| 401 | |
| 402 | static inline u16 iproc_pcie_reg_offset(struct iproc_pcie *pcie, |
| 403 | enum iproc_pcie_reg reg) |
| 404 | { |
| 405 | return pcie->reg_offsets[reg]; |
| 406 | } |
| 407 | |
| 408 | static inline u32 iproc_pcie_read_reg(struct iproc_pcie *pcie, |
| 409 | enum iproc_pcie_reg reg) |
| 410 | { |
| 411 | u16 offset = iproc_pcie_reg_offset(pcie, reg); |
| 412 | |
| 413 | if (iproc_pcie_reg_is_invalid(offset)) |
| 414 | return 0; |
| 415 | |
| 416 | return readl(pcie->base + offset); |
| 417 | } |
| 418 | |
| 419 | static inline void iproc_pcie_write_reg(struct iproc_pcie *pcie, |
| 420 | enum iproc_pcie_reg reg, u32 val) |
| 421 | { |
| 422 | u16 offset = iproc_pcie_reg_offset(pcie, reg); |
| 423 | |
| 424 | if (iproc_pcie_reg_is_invalid(offset)) |
| 425 | return; |
| 426 | |
| 427 | writel(val, pcie->base + offset); |
| 428 | } |
| 429 | |
Ray Jui | 538928f | 2016-10-31 17:38:33 -0700 | [diff] [blame] | 430 | /** |
| 431 | * APB error forwarding can be disabled during access of configuration |
| 432 | * registers of the endpoint device, to prevent unsupported requests |
| 433 | * (typically seen during enumeration with multi-function devices) from |
| 434 | * triggering a system exception. |
| 435 | */ |
| 436 | static inline void iproc_pcie_apb_err_disable(struct pci_bus *bus, |
| 437 | bool disable) |
| 438 | { |
| 439 | struct iproc_pcie *pcie = iproc_data(bus); |
| 440 | u32 val; |
| 441 | |
| 442 | if (bus->number && pcie->has_apb_err_disable) { |
| 443 | val = iproc_pcie_read_reg(pcie, IPROC_PCIE_APB_ERR_EN); |
| 444 | if (disable) |
| 445 | val &= ~APB_ERR_EN; |
| 446 | else |
| 447 | val |= APB_ERR_EN; |
| 448 | iproc_pcie_write_reg(pcie, IPROC_PCIE_APB_ERR_EN, val); |
| 449 | } |
| 450 | } |
| 451 | |
Oza Pawandeep | d005045 | 2017-08-28 16:43:24 -0500 | [diff] [blame] | 452 | static void __iomem *iproc_pcie_map_ep_cfg_reg(struct iproc_pcie *pcie, |
| 453 | unsigned int busno, |
| 454 | unsigned int slot, |
| 455 | unsigned int fn, |
| 456 | int where) |
| 457 | { |
| 458 | u16 offset; |
| 459 | u32 val; |
| 460 | |
| 461 | /* EP device access */ |
| 462 | val = (busno << CFG_ADDR_BUS_NUM_SHIFT) | |
| 463 | (slot << CFG_ADDR_DEV_NUM_SHIFT) | |
| 464 | (fn << CFG_ADDR_FUNC_NUM_SHIFT) | |
| 465 | (where & CFG_ADDR_REG_NUM_MASK) | |
| 466 | (1 & CFG_ADDR_CFG_TYPE_MASK); |
| 467 | |
| 468 | iproc_pcie_write_reg(pcie, IPROC_PCIE_CFG_ADDR, val); |
| 469 | offset = iproc_pcie_reg_offset(pcie, IPROC_PCIE_CFG_DATA); |
| 470 | |
| 471 | if (iproc_pcie_reg_is_invalid(offset)) |
| 472 | return NULL; |
| 473 | |
| 474 | return (pcie->base + offset); |
| 475 | } |
| 476 | |
Oza Pawandeep | 39b7a4f | 2017-08-28 16:43:30 -0500 | [diff] [blame] | 477 | static unsigned int iproc_pcie_cfg_retry(void __iomem *cfg_data_p) |
| 478 | { |
| 479 | int timeout = CFG_RETRY_STATUS_TIMEOUT_US; |
| 480 | unsigned int data; |
| 481 | |
| 482 | /* |
| 483 | * As per PCIe spec r3.1, sec 2.3.2, CRS Software Visibility only |
| 484 | * affects config reads of the Vendor ID. For config writes or any |
| 485 | * other config reads, the Root may automatically reissue the |
| 486 | * configuration request again as a new request. |
| 487 | * |
| 488 | * For config reads, this hardware returns CFG_RETRY_STATUS data |
| 489 | * when it receives a CRS completion, regardless of the address of |
| 490 | * the read or the CRS Software Visibility Enable bit. As a |
| 491 | * partial workaround for this, we retry in software any read that |
| 492 | * returns CFG_RETRY_STATUS. |
| 493 | * |
| 494 | * Note that a non-Vendor ID config register may have a value of |
| 495 | * CFG_RETRY_STATUS. If we read that, we can't distinguish it from |
| 496 | * a CRS completion, so we will incorrectly retry the read and |
| 497 | * eventually return the wrong data (0xffffffff). |
| 498 | */ |
| 499 | data = readl(cfg_data_p); |
| 500 | while (data == CFG_RETRY_STATUS && timeout--) { |
| 501 | udelay(1); |
| 502 | data = readl(cfg_data_p); |
| 503 | } |
| 504 | |
| 505 | if (data == CFG_RETRY_STATUS) |
| 506 | data = 0xffffffff; |
| 507 | |
| 508 | return data; |
| 509 | } |
| 510 | |
Ray Jui | 3bc7082 | 2018-06-11 17:21:04 -0700 | [diff] [blame^] | 511 | static void iproc_pcie_fix_cap(struct iproc_pcie *pcie, int where, u32 *val) |
| 512 | { |
| 513 | u32 i, dev_id; |
| 514 | |
| 515 | switch (where & ~0x3) { |
| 516 | case PCI_VENDOR_ID: |
| 517 | dev_id = *val >> 16; |
| 518 | |
| 519 | /* |
| 520 | * Activate fixup for those controllers that have corrupted |
| 521 | * capability list registers |
| 522 | */ |
| 523 | for (i = 0; i < ARRAY_SIZE(iproc_pcie_corrupt_cap_did); i++) |
| 524 | if (dev_id == iproc_pcie_corrupt_cap_did[i]) |
| 525 | pcie->fix_paxc_cap = true; |
| 526 | break; |
| 527 | |
| 528 | case IPROC_PCI_PM_CAP: |
| 529 | if (pcie->fix_paxc_cap) { |
| 530 | /* advertise PM, force next capability to PCIe */ |
| 531 | *val &= ~IPROC_PCI_PM_CAP_MASK; |
| 532 | *val |= IPROC_PCI_EXP_CAP << 8 | PCI_CAP_ID_PM; |
| 533 | } |
| 534 | break; |
| 535 | |
| 536 | case IPROC_PCI_EXP_CAP: |
| 537 | if (pcie->fix_paxc_cap) { |
| 538 | /* advertise root port, version 2, terminate here */ |
| 539 | *val = (PCI_EXP_TYPE_ROOT_PORT << 4 | 2) << 16 | |
| 540 | PCI_CAP_ID_EXP; |
| 541 | } |
| 542 | break; |
| 543 | |
| 544 | case IPROC_PCI_EXP_CAP + PCI_EXP_RTCTL: |
| 545 | /* Don't advertise CRS SV support */ |
| 546 | *val &= ~(PCI_EXP_RTCAP_CRSVIS << 16); |
| 547 | break; |
| 548 | |
| 549 | default: |
| 550 | break; |
| 551 | } |
| 552 | } |
| 553 | |
Oza Pawandeep | 39b7a4f | 2017-08-28 16:43:30 -0500 | [diff] [blame] | 554 | static int iproc_pcie_config_read(struct pci_bus *bus, unsigned int devfn, |
Bjorn Helgaas | ef685b3 | 2017-09-05 12:33:33 -0500 | [diff] [blame] | 555 | int where, int size, u32 *val) |
Oza Pawandeep | 39b7a4f | 2017-08-28 16:43:30 -0500 | [diff] [blame] | 556 | { |
| 557 | struct iproc_pcie *pcie = iproc_data(bus); |
| 558 | unsigned int slot = PCI_SLOT(devfn); |
| 559 | unsigned int fn = PCI_FUNC(devfn); |
| 560 | unsigned int busno = bus->number; |
| 561 | void __iomem *cfg_data_p; |
| 562 | unsigned int data; |
| 563 | int ret; |
| 564 | |
| 565 | /* root complex access */ |
| 566 | if (busno == 0) { |
| 567 | ret = pci_generic_config_read32(bus, devfn, where, size, val); |
Ray Jui | 3bc7082 | 2018-06-11 17:21:04 -0700 | [diff] [blame^] | 568 | if (ret == PCIBIOS_SUCCESSFUL) |
| 569 | iproc_pcie_fix_cap(pcie, where, val); |
Oza Pawandeep | 39b7a4f | 2017-08-28 16:43:30 -0500 | [diff] [blame] | 570 | |
Ray Jui | 3bc7082 | 2018-06-11 17:21:04 -0700 | [diff] [blame^] | 571 | return ret; |
Oza Pawandeep | 39b7a4f | 2017-08-28 16:43:30 -0500 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | cfg_data_p = iproc_pcie_map_ep_cfg_reg(pcie, busno, slot, fn, where); |
| 575 | |
| 576 | if (!cfg_data_p) |
| 577 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 578 | |
| 579 | data = iproc_pcie_cfg_retry(cfg_data_p); |
| 580 | |
| 581 | *val = data; |
| 582 | if (size <= 2) |
| 583 | *val = (data >> (8 * (where & 3))) & ((1 << (size * 8)) - 1); |
| 584 | |
| 585 | return PCIBIOS_SUCCESSFUL; |
| 586 | } |
| 587 | |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 588 | /** |
| 589 | * Note access to the configuration registers are protected at the higher layer |
| 590 | * by 'pci_lock' in drivers/pci/access.c |
| 591 | */ |
Lorenzo Pieralisi | 022adcf | 2017-06-28 15:13:50 -0500 | [diff] [blame] | 592 | static void __iomem *iproc_pcie_map_cfg_bus(struct iproc_pcie *pcie, |
Bjorn Helgaas | ef685b3 | 2017-09-05 12:33:33 -0500 | [diff] [blame] | 593 | int busno, unsigned int devfn, |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 594 | int where) |
| 595 | { |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 596 | unsigned slot = PCI_SLOT(devfn); |
| 597 | unsigned fn = PCI_FUNC(devfn); |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 598 | u16 offset; |
| 599 | |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 600 | /* root complex access */ |
| 601 | if (busno == 0) { |
Ray Jui | 4656038 | 2016-01-27 16:52:24 -0600 | [diff] [blame] | 602 | if (slot > 0 || fn > 0) |
| 603 | return NULL; |
| 604 | |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 605 | iproc_pcie_write_reg(pcie, IPROC_PCIE_CFG_IND_ADDR, |
| 606 | where & CFG_IND_ADDR_MASK); |
| 607 | offset = iproc_pcie_reg_offset(pcie, IPROC_PCIE_CFG_IND_DATA); |
| 608 | if (iproc_pcie_reg_is_invalid(offset)) |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 609 | return NULL; |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 610 | else |
| 611 | return (pcie->base + offset); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 612 | } |
| 613 | |
Ray Jui | 4656038 | 2016-01-27 16:52:24 -0600 | [diff] [blame] | 614 | /* |
| 615 | * PAXC is connected to an internally emulated EP within the SoC. It |
| 616 | * allows only one device. |
| 617 | */ |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 618 | if (pcie->ep_is_internal) |
Ray Jui | 4656038 | 2016-01-27 16:52:24 -0600 | [diff] [blame] | 619 | if (slot > 0) |
| 620 | return NULL; |
| 621 | |
Oza Pawandeep | d005045 | 2017-08-28 16:43:24 -0500 | [diff] [blame] | 622 | return iproc_pcie_map_ep_cfg_reg(pcie, busno, slot, fn, where); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 623 | } |
| 624 | |
Lorenzo Pieralisi | 022adcf | 2017-06-28 15:13:50 -0500 | [diff] [blame] | 625 | static void __iomem *iproc_pcie_bus_map_cfg_bus(struct pci_bus *bus, |
| 626 | unsigned int devfn, |
| 627 | int where) |
| 628 | { |
| 629 | return iproc_pcie_map_cfg_bus(iproc_data(bus), bus->number, devfn, |
| 630 | where); |
| 631 | } |
| 632 | |
| 633 | static int iproc_pci_raw_config_read32(struct iproc_pcie *pcie, |
| 634 | unsigned int devfn, int where, |
| 635 | int size, u32 *val) |
| 636 | { |
| 637 | void __iomem *addr; |
| 638 | |
| 639 | addr = iproc_pcie_map_cfg_bus(pcie, 0, devfn, where & ~0x3); |
| 640 | if (!addr) { |
| 641 | *val = ~0; |
| 642 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 643 | } |
| 644 | |
| 645 | *val = readl(addr); |
| 646 | |
| 647 | if (size <= 2) |
| 648 | *val = (*val >> (8 * (where & 3))) & ((1 << (size * 8)) - 1); |
| 649 | |
| 650 | return PCIBIOS_SUCCESSFUL; |
| 651 | } |
| 652 | |
| 653 | static int iproc_pci_raw_config_write32(struct iproc_pcie *pcie, |
| 654 | unsigned int devfn, int where, |
| 655 | int size, u32 val) |
| 656 | { |
| 657 | void __iomem *addr; |
| 658 | u32 mask, tmp; |
| 659 | |
| 660 | addr = iproc_pcie_map_cfg_bus(pcie, 0, devfn, where & ~0x3); |
| 661 | if (!addr) |
| 662 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 663 | |
| 664 | if (size == 4) { |
| 665 | writel(val, addr); |
| 666 | return PCIBIOS_SUCCESSFUL; |
| 667 | } |
| 668 | |
| 669 | mask = ~(((1 << (size * 8)) - 1) << ((where & 0x3) * 8)); |
| 670 | tmp = readl(addr) & mask; |
| 671 | tmp |= val << ((where & 0x3) * 8); |
| 672 | writel(tmp, addr); |
| 673 | |
| 674 | return PCIBIOS_SUCCESSFUL; |
| 675 | } |
| 676 | |
Ray Jui | 538928f | 2016-10-31 17:38:33 -0700 | [diff] [blame] | 677 | static int iproc_pcie_config_read32(struct pci_bus *bus, unsigned int devfn, |
| 678 | int where, int size, u32 *val) |
| 679 | { |
| 680 | int ret; |
Oza Pawandeep | 39b7a4f | 2017-08-28 16:43:30 -0500 | [diff] [blame] | 681 | struct iproc_pcie *pcie = iproc_data(bus); |
Ray Jui | 538928f | 2016-10-31 17:38:33 -0700 | [diff] [blame] | 682 | |
| 683 | iproc_pcie_apb_err_disable(bus, true); |
Oza Pawandeep | 39b7a4f | 2017-08-28 16:43:30 -0500 | [diff] [blame] | 684 | if (pcie->type == IPROC_PCIE_PAXB_V2) |
| 685 | ret = iproc_pcie_config_read(bus, devfn, where, size, val); |
| 686 | else |
| 687 | ret = pci_generic_config_read32(bus, devfn, where, size, val); |
Ray Jui | 538928f | 2016-10-31 17:38:33 -0700 | [diff] [blame] | 688 | iproc_pcie_apb_err_disable(bus, false); |
| 689 | |
| 690 | return ret; |
| 691 | } |
| 692 | |
| 693 | static int iproc_pcie_config_write32(struct pci_bus *bus, unsigned int devfn, |
| 694 | int where, int size, u32 val) |
| 695 | { |
| 696 | int ret; |
| 697 | |
| 698 | iproc_pcie_apb_err_disable(bus, true); |
| 699 | ret = pci_generic_config_write32(bus, devfn, where, size, val); |
| 700 | iproc_pcie_apb_err_disable(bus, false); |
| 701 | |
| 702 | return ret; |
| 703 | } |
| 704 | |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 705 | static struct pci_ops iproc_pcie_ops = { |
Lorenzo Pieralisi | 022adcf | 2017-06-28 15:13:50 -0500 | [diff] [blame] | 706 | .map_bus = iproc_pcie_bus_map_cfg_bus, |
Ray Jui | 538928f | 2016-10-31 17:38:33 -0700 | [diff] [blame] | 707 | .read = iproc_pcie_config_read32, |
| 708 | .write = iproc_pcie_config_write32, |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 709 | }; |
| 710 | |
Oza Pawandeep | b91c26c | 2017-08-28 16:43:35 -0500 | [diff] [blame] | 711 | static void iproc_pcie_perst_ctrl(struct iproc_pcie *pcie, bool assert) |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 712 | { |
| 713 | u32 val; |
| 714 | |
Ray Jui | 7cbd50d | 2016-10-31 17:38:31 -0700 | [diff] [blame] | 715 | /* |
| 716 | * PAXC and the internal emulated endpoint device downstream should not |
| 717 | * be reset. If firmware has been loaded on the endpoint device at an |
| 718 | * earlier boot stage, reset here causes issues. |
| 719 | */ |
| 720 | if (pcie->ep_is_internal) |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 721 | return; |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 722 | |
Oza Pawandeep | b91c26c | 2017-08-28 16:43:35 -0500 | [diff] [blame] | 723 | if (assert) { |
| 724 | val = iproc_pcie_read_reg(pcie, IPROC_PCIE_CLK_CTRL); |
| 725 | val &= ~EP_PERST_SOURCE_SELECT & ~EP_MODE_SURVIVE_PERST & |
| 726 | ~RC_PCIE_RST_OUTPUT; |
| 727 | iproc_pcie_write_reg(pcie, IPROC_PCIE_CLK_CTRL, val); |
| 728 | udelay(250); |
| 729 | } else { |
| 730 | val = iproc_pcie_read_reg(pcie, IPROC_PCIE_CLK_CTRL); |
| 731 | val |= RC_PCIE_RST_OUTPUT; |
| 732 | iproc_pcie_write_reg(pcie, IPROC_PCIE_CLK_CTRL, val); |
| 733 | msleep(100); |
| 734 | } |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 735 | } |
| 736 | |
Oza Pawandeep | b91c26c | 2017-08-28 16:43:35 -0500 | [diff] [blame] | 737 | int iproc_pcie_shutdown(struct iproc_pcie *pcie) |
| 738 | { |
| 739 | iproc_pcie_perst_ctrl(pcie, true); |
| 740 | msleep(500); |
| 741 | |
| 742 | return 0; |
| 743 | } |
| 744 | EXPORT_SYMBOL_GPL(iproc_pcie_shutdown); |
| 745 | |
Lorenzo Pieralisi | 022adcf | 2017-06-28 15:13:50 -0500 | [diff] [blame] | 746 | static int iproc_pcie_check_link(struct iproc_pcie *pcie) |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 747 | { |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 748 | struct device *dev = pcie->dev; |
Lorenzo Pieralisi | 022adcf | 2017-06-28 15:13:50 -0500 | [diff] [blame] | 749 | u32 hdr_type, link_ctrl, link_status, class, val; |
Ray Jui | aaf22ab | 2015-09-15 17:39:19 -0700 | [diff] [blame] | 750 | bool link_is_active = false; |
| 751 | |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 752 | /* |
| 753 | * PAXC connects to emulated endpoint devices directly and does not |
| 754 | * have a Serdes. Therefore skip the link detection logic here. |
| 755 | */ |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 756 | if (pcie->ep_is_internal) |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 757 | return 0; |
| 758 | |
| 759 | val = iproc_pcie_read_reg(pcie, IPROC_PCIE_LINK_STATUS); |
Ray Jui | aaf22ab | 2015-09-15 17:39:19 -0700 | [diff] [blame] | 760 | if (!(val & PCIE_PHYLINKUP) || !(val & PCIE_DL_ACTIVE)) { |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 761 | dev_err(dev, "PHY or data link is INACTIVE!\n"); |
Ray Jui | aaf22ab | 2015-09-15 17:39:19 -0700 | [diff] [blame] | 762 | return -ENODEV; |
| 763 | } |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 764 | |
| 765 | /* make sure we are not in EP mode */ |
Bjorn Helgaas | ef685b3 | 2017-09-05 12:33:33 -0500 | [diff] [blame] | 766 | iproc_pci_raw_config_read32(pcie, 0, PCI_HEADER_TYPE, 1, &hdr_type); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 767 | if ((hdr_type & 0x7f) != PCI_HEADER_TYPE_BRIDGE) { |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 768 | dev_err(dev, "in EP mode, hdr=%#02x\n", hdr_type); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 769 | return -EFAULT; |
| 770 | } |
| 771 | |
| 772 | /* force class to PCI_CLASS_BRIDGE_PCI (0x0604) */ |
Bjorn Helgaas | ef685b3 | 2017-09-05 12:33:33 -0500 | [diff] [blame] | 773 | #define PCI_BRIDGE_CTRL_REG_OFFSET 0x43c |
| 774 | #define PCI_CLASS_BRIDGE_MASK 0xffff00 |
| 775 | #define PCI_CLASS_BRIDGE_SHIFT 8 |
Lorenzo Pieralisi | 022adcf | 2017-06-28 15:13:50 -0500 | [diff] [blame] | 776 | iproc_pci_raw_config_read32(pcie, 0, PCI_BRIDGE_CTRL_REG_OFFSET, |
| 777 | 4, &class); |
Ray Jui | aaf22ab | 2015-09-15 17:39:19 -0700 | [diff] [blame] | 778 | class &= ~PCI_CLASS_BRIDGE_MASK; |
| 779 | class |= (PCI_CLASS_BRIDGE_PCI << PCI_CLASS_BRIDGE_SHIFT); |
Lorenzo Pieralisi | 022adcf | 2017-06-28 15:13:50 -0500 | [diff] [blame] | 780 | iproc_pci_raw_config_write32(pcie, 0, PCI_BRIDGE_CTRL_REG_OFFSET, |
| 781 | 4, class); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 782 | |
| 783 | /* check link status to see if link is active */ |
Bjorn Helgaas | d8fa934 | 2017-09-05 12:27:11 -0500 | [diff] [blame] | 784 | iproc_pci_raw_config_read32(pcie, 0, IPROC_PCI_EXP_CAP + PCI_EXP_LNKSTA, |
Lorenzo Pieralisi | 022adcf | 2017-06-28 15:13:50 -0500 | [diff] [blame] | 785 | 2, &link_status); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 786 | if (link_status & PCI_EXP_LNKSTA_NLW) |
Ray Jui | aaf22ab | 2015-09-15 17:39:19 -0700 | [diff] [blame] | 787 | link_is_active = true; |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 788 | |
| 789 | if (!link_is_active) { |
| 790 | /* try GEN 1 link speed */ |
Bjorn Helgaas | ef685b3 | 2017-09-05 12:33:33 -0500 | [diff] [blame] | 791 | #define PCI_TARGET_LINK_SPEED_MASK 0xf |
| 792 | #define PCI_TARGET_LINK_SPEED_GEN2 0x2 |
| 793 | #define PCI_TARGET_LINK_SPEED_GEN1 0x1 |
Lorenzo Pieralisi | 022adcf | 2017-06-28 15:13:50 -0500 | [diff] [blame] | 794 | iproc_pci_raw_config_read32(pcie, 0, |
Bjorn Helgaas | d8fa934 | 2017-09-05 12:27:11 -0500 | [diff] [blame] | 795 | IPROC_PCI_EXP_CAP + PCI_EXP_LNKCTL2, |
| 796 | 4, &link_ctrl); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 797 | if ((link_ctrl & PCI_TARGET_LINK_SPEED_MASK) == |
| 798 | PCI_TARGET_LINK_SPEED_GEN2) { |
| 799 | link_ctrl &= ~PCI_TARGET_LINK_SPEED_MASK; |
| 800 | link_ctrl |= PCI_TARGET_LINK_SPEED_GEN1; |
Lorenzo Pieralisi | 022adcf | 2017-06-28 15:13:50 -0500 | [diff] [blame] | 801 | iproc_pci_raw_config_write32(pcie, 0, |
Bjorn Helgaas | d8fa934 | 2017-09-05 12:27:11 -0500 | [diff] [blame] | 802 | IPROC_PCI_EXP_CAP + PCI_EXP_LNKCTL2, |
| 803 | 4, link_ctrl); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 804 | msleep(100); |
| 805 | |
Lorenzo Pieralisi | 022adcf | 2017-06-28 15:13:50 -0500 | [diff] [blame] | 806 | iproc_pci_raw_config_read32(pcie, 0, |
Bjorn Helgaas | d8fa934 | 2017-09-05 12:27:11 -0500 | [diff] [blame] | 807 | IPROC_PCI_EXP_CAP + PCI_EXP_LNKSTA, |
| 808 | 2, &link_status); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 809 | if (link_status & PCI_EXP_LNKSTA_NLW) |
Ray Jui | aaf22ab | 2015-09-15 17:39:19 -0700 | [diff] [blame] | 810 | link_is_active = true; |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 811 | } |
| 812 | } |
| 813 | |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 814 | dev_info(dev, "link: %s\n", link_is_active ? "UP" : "DOWN"); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 815 | |
| 816 | return link_is_active ? 0 : -ENODEV; |
| 817 | } |
| 818 | |
| 819 | static void iproc_pcie_enable(struct iproc_pcie *pcie) |
| 820 | { |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 821 | iproc_pcie_write_reg(pcie, IPROC_PCIE_INTX_EN, SYS_RC_INTX_MASK); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 822 | } |
| 823 | |
Ray Jui | 4213e15 | 2016-10-31 17:38:37 -0700 | [diff] [blame] | 824 | static inline bool iproc_pcie_ob_is_valid(struct iproc_pcie *pcie, |
| 825 | int window_idx) |
| 826 | { |
| 827 | u32 val; |
| 828 | |
| 829 | val = iproc_pcie_read_reg(pcie, MAP_REG(IPROC_PCIE_OARR0, window_idx)); |
| 830 | |
| 831 | return !!(val & OARR_VALID); |
| 832 | } |
| 833 | |
| 834 | static inline int iproc_pcie_ob_write(struct iproc_pcie *pcie, int window_idx, |
| 835 | int size_idx, u64 axi_addr, u64 pci_addr) |
| 836 | { |
| 837 | struct device *dev = pcie->dev; |
| 838 | u16 oarr_offset, omap_offset; |
| 839 | |
| 840 | /* |
| 841 | * Derive the OARR/OMAP offset from the first pair (OARR0/OMAP0) based |
| 842 | * on window index. |
| 843 | */ |
| 844 | oarr_offset = iproc_pcie_reg_offset(pcie, MAP_REG(IPROC_PCIE_OARR0, |
| 845 | window_idx)); |
| 846 | omap_offset = iproc_pcie_reg_offset(pcie, MAP_REG(IPROC_PCIE_OMAP0, |
| 847 | window_idx)); |
| 848 | if (iproc_pcie_reg_is_invalid(oarr_offset) || |
| 849 | iproc_pcie_reg_is_invalid(omap_offset)) |
| 850 | return -EINVAL; |
| 851 | |
| 852 | /* |
| 853 | * Program the OARR registers. The upper 32-bit OARR register is |
| 854 | * always right after the lower 32-bit OARR register. |
| 855 | */ |
| 856 | writel(lower_32_bits(axi_addr) | (size_idx << OARR_SIZE_CFG_SHIFT) | |
| 857 | OARR_VALID, pcie->base + oarr_offset); |
| 858 | writel(upper_32_bits(axi_addr), pcie->base + oarr_offset + 4); |
| 859 | |
| 860 | /* now program the OMAP registers */ |
| 861 | writel(lower_32_bits(pci_addr), pcie->base + omap_offset); |
| 862 | writel(upper_32_bits(pci_addr), pcie->base + omap_offset + 4); |
| 863 | |
| 864 | dev_info(dev, "ob window [%d]: offset 0x%x axi %pap pci %pap\n", |
| 865 | window_idx, oarr_offset, &axi_addr, &pci_addr); |
| 866 | dev_info(dev, "oarr lo 0x%x oarr hi 0x%x\n", |
| 867 | readl(pcie->base + oarr_offset), |
| 868 | readl(pcie->base + oarr_offset + 4)); |
| 869 | dev_info(dev, "omap lo 0x%x omap hi 0x%x\n", |
| 870 | readl(pcie->base + omap_offset), |
| 871 | readl(pcie->base + omap_offset + 4)); |
| 872 | |
| 873 | return 0; |
| 874 | } |
| 875 | |
Ray Jui | e99a187 | 2015-10-16 08:18:24 -0500 | [diff] [blame] | 876 | /** |
| 877 | * Some iProc SoCs require the SW to configure the outbound address mapping |
| 878 | * |
| 879 | * Outbound address translation: |
| 880 | * |
| 881 | * iproc_pcie_address = axi_address - axi_offset |
| 882 | * OARR = iproc_pcie_address |
| 883 | * OMAP = pci_addr |
| 884 | * |
| 885 | * axi_addr -> iproc_pcie_address -> OARR -> OMAP -> pci_address |
| 886 | */ |
| 887 | static int iproc_pcie_setup_ob(struct iproc_pcie *pcie, u64 axi_addr, |
| 888 | u64 pci_addr, resource_size_t size) |
| 889 | { |
| 890 | struct iproc_pcie_ob *ob = &pcie->ob; |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 891 | struct device *dev = pcie->dev; |
Ray Jui | 4213e15 | 2016-10-31 17:38:37 -0700 | [diff] [blame] | 892 | int ret = -EINVAL, window_idx, size_idx; |
Ray Jui | e99a187 | 2015-10-16 08:18:24 -0500 | [diff] [blame] | 893 | |
| 894 | if (axi_addr < ob->axi_offset) { |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 895 | dev_err(dev, "axi address %pap less than offset %pap\n", |
Ray Jui | e99a187 | 2015-10-16 08:18:24 -0500 | [diff] [blame] | 896 | &axi_addr, &ob->axi_offset); |
| 897 | return -EINVAL; |
| 898 | } |
| 899 | |
| 900 | /* |
| 901 | * Translate the AXI address to the internal address used by the iProc |
| 902 | * PCIe core before programming the OARR |
| 903 | */ |
| 904 | axi_addr -= ob->axi_offset; |
| 905 | |
Ray Jui | 4213e15 | 2016-10-31 17:38:37 -0700 | [diff] [blame] | 906 | /* iterate through all OARR/OMAP mapping windows */ |
| 907 | for (window_idx = ob->nr_windows - 1; window_idx >= 0; window_idx--) { |
| 908 | const struct iproc_pcie_ob_map *ob_map = |
| 909 | &pcie->ob_map[window_idx]; |
Ray Jui | e99a187 | 2015-10-16 08:18:24 -0500 | [diff] [blame] | 910 | |
Ray Jui | 4213e15 | 2016-10-31 17:38:37 -0700 | [diff] [blame] | 911 | /* |
| 912 | * If current outbound window is already in use, move on to the |
| 913 | * next one. |
| 914 | */ |
| 915 | if (iproc_pcie_ob_is_valid(pcie, window_idx)) |
| 916 | continue; |
| 917 | |
| 918 | /* |
| 919 | * Iterate through all supported window sizes within the |
| 920 | * OARR/OMAP pair to find a match. Go through the window sizes |
| 921 | * in a descending order. |
| 922 | */ |
| 923 | for (size_idx = ob_map->nr_sizes - 1; size_idx >= 0; |
| 924 | size_idx--) { |
| 925 | resource_size_t window_size = |
| 926 | ob_map->window_sizes[size_idx] * SZ_1M; |
| 927 | |
| 928 | if (size < window_size) |
| 929 | continue; |
| 930 | |
| 931 | if (!IS_ALIGNED(axi_addr, window_size) || |
| 932 | !IS_ALIGNED(pci_addr, window_size)) { |
| 933 | dev_err(dev, |
| 934 | "axi %pap or pci %pap not aligned\n", |
| 935 | &axi_addr, &pci_addr); |
| 936 | return -EINVAL; |
| 937 | } |
| 938 | |
| 939 | /* |
| 940 | * Match found! Program both OARR and OMAP and mark |
| 941 | * them as a valid entry. |
| 942 | */ |
| 943 | ret = iproc_pcie_ob_write(pcie, window_idx, size_idx, |
| 944 | axi_addr, pci_addr); |
| 945 | if (ret) |
| 946 | goto err_ob; |
| 947 | |
| 948 | size -= window_size; |
| 949 | if (size == 0) |
| 950 | return 0; |
| 951 | |
| 952 | /* |
| 953 | * If we are here, we are done with the current window, |
| 954 | * but not yet finished all mappings. Need to move on |
| 955 | * to the next window. |
| 956 | */ |
| 957 | axi_addr += window_size; |
| 958 | pci_addr += window_size; |
Ray Jui | e99a187 | 2015-10-16 08:18:24 -0500 | [diff] [blame] | 959 | break; |
Ray Jui | 4213e15 | 2016-10-31 17:38:37 -0700 | [diff] [blame] | 960 | } |
Ray Jui | e99a187 | 2015-10-16 08:18:24 -0500 | [diff] [blame] | 961 | } |
| 962 | |
Ray Jui | 4213e15 | 2016-10-31 17:38:37 -0700 | [diff] [blame] | 963 | err_ob: |
| 964 | dev_err(dev, "unable to configure outbound mapping\n"); |
| 965 | dev_err(dev, |
| 966 | "axi %pap, axi offset %pap, pci %pap, res size %pap\n", |
| 967 | &axi_addr, &ob->axi_offset, &pci_addr, &size); |
| 968 | |
| 969 | return ret; |
Ray Jui | e99a187 | 2015-10-16 08:18:24 -0500 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | static int iproc_pcie_map_ranges(struct iproc_pcie *pcie, |
| 973 | struct list_head *resources) |
| 974 | { |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 975 | struct device *dev = pcie->dev; |
Ray Jui | e99a187 | 2015-10-16 08:18:24 -0500 | [diff] [blame] | 976 | struct resource_entry *window; |
| 977 | int ret; |
| 978 | |
| 979 | resource_list_for_each_entry(window, resources) { |
| 980 | struct resource *res = window->res; |
| 981 | u64 res_type = resource_type(res); |
| 982 | |
| 983 | switch (res_type) { |
| 984 | case IORESOURCE_IO: |
| 985 | case IORESOURCE_BUS: |
| 986 | break; |
| 987 | case IORESOURCE_MEM: |
| 988 | ret = iproc_pcie_setup_ob(pcie, res->start, |
| 989 | res->start - window->offset, |
| 990 | resource_size(res)); |
| 991 | if (ret) |
| 992 | return ret; |
| 993 | break; |
| 994 | default: |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 995 | dev_err(dev, "invalid resource %pR\n", res); |
Ray Jui | e99a187 | 2015-10-16 08:18:24 -0500 | [diff] [blame] | 996 | return -EINVAL; |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | return 0; |
| 1001 | } |
| 1002 | |
Ray Jui | dd9d4e7 | 2016-10-31 17:38:39 -0700 | [diff] [blame] | 1003 | static inline bool iproc_pcie_ib_is_in_use(struct iproc_pcie *pcie, |
| 1004 | int region_idx) |
| 1005 | { |
| 1006 | const struct iproc_pcie_ib_map *ib_map = &pcie->ib_map[region_idx]; |
| 1007 | u32 val; |
| 1008 | |
| 1009 | val = iproc_pcie_read_reg(pcie, MAP_REG(IPROC_PCIE_IARR0, region_idx)); |
| 1010 | |
| 1011 | return !!(val & (BIT(ib_map->nr_sizes) - 1)); |
| 1012 | } |
| 1013 | |
| 1014 | static inline bool iproc_pcie_ib_check_type(const struct iproc_pcie_ib_map *ib_map, |
| 1015 | enum iproc_pcie_ib_map_type type) |
| 1016 | { |
| 1017 | return !!(ib_map->type == type); |
| 1018 | } |
| 1019 | |
| 1020 | static int iproc_pcie_ib_write(struct iproc_pcie *pcie, int region_idx, |
| 1021 | int size_idx, int nr_windows, u64 axi_addr, |
| 1022 | u64 pci_addr, resource_size_t size) |
| 1023 | { |
| 1024 | struct device *dev = pcie->dev; |
| 1025 | const struct iproc_pcie_ib_map *ib_map = &pcie->ib_map[region_idx]; |
| 1026 | u16 iarr_offset, imap_offset; |
| 1027 | u32 val; |
| 1028 | int window_idx; |
| 1029 | |
| 1030 | iarr_offset = iproc_pcie_reg_offset(pcie, |
| 1031 | MAP_REG(IPROC_PCIE_IARR0, region_idx)); |
| 1032 | imap_offset = iproc_pcie_reg_offset(pcie, |
| 1033 | MAP_REG(IPROC_PCIE_IMAP0, region_idx)); |
| 1034 | if (iproc_pcie_reg_is_invalid(iarr_offset) || |
| 1035 | iproc_pcie_reg_is_invalid(imap_offset)) |
| 1036 | return -EINVAL; |
| 1037 | |
| 1038 | dev_info(dev, "ib region [%d]: offset 0x%x axi %pap pci %pap\n", |
| 1039 | region_idx, iarr_offset, &axi_addr, &pci_addr); |
| 1040 | |
| 1041 | /* |
| 1042 | * Program the IARR registers. The upper 32-bit IARR register is |
| 1043 | * always right after the lower 32-bit IARR register. |
| 1044 | */ |
| 1045 | writel(lower_32_bits(pci_addr) | BIT(size_idx), |
| 1046 | pcie->base + iarr_offset); |
| 1047 | writel(upper_32_bits(pci_addr), pcie->base + iarr_offset + 4); |
| 1048 | |
| 1049 | dev_info(dev, "iarr lo 0x%x iarr hi 0x%x\n", |
| 1050 | readl(pcie->base + iarr_offset), |
| 1051 | readl(pcie->base + iarr_offset + 4)); |
| 1052 | |
| 1053 | /* |
| 1054 | * Now program the IMAP registers. Each IARR region may have one or |
| 1055 | * more IMAP windows. |
| 1056 | */ |
| 1057 | size >>= ilog2(nr_windows); |
| 1058 | for (window_idx = 0; window_idx < nr_windows; window_idx++) { |
| 1059 | val = readl(pcie->base + imap_offset); |
| 1060 | val |= lower_32_bits(axi_addr) | IMAP_VALID; |
| 1061 | writel(val, pcie->base + imap_offset); |
| 1062 | writel(upper_32_bits(axi_addr), |
| 1063 | pcie->base + imap_offset + ib_map->imap_addr_offset); |
| 1064 | |
| 1065 | dev_info(dev, "imap window [%d] lo 0x%x hi 0x%x\n", |
| 1066 | window_idx, readl(pcie->base + imap_offset), |
| 1067 | readl(pcie->base + imap_offset + |
| 1068 | ib_map->imap_addr_offset)); |
| 1069 | |
| 1070 | imap_offset += ib_map->imap_window_offset; |
| 1071 | axi_addr += size; |
| 1072 | } |
| 1073 | |
| 1074 | return 0; |
| 1075 | } |
| 1076 | |
| 1077 | static int iproc_pcie_setup_ib(struct iproc_pcie *pcie, |
| 1078 | struct of_pci_range *range, |
| 1079 | enum iproc_pcie_ib_map_type type) |
| 1080 | { |
| 1081 | struct device *dev = pcie->dev; |
| 1082 | struct iproc_pcie_ib *ib = &pcie->ib; |
| 1083 | int ret; |
| 1084 | unsigned int region_idx, size_idx; |
| 1085 | u64 axi_addr = range->cpu_addr, pci_addr = range->pci_addr; |
| 1086 | resource_size_t size = range->size; |
| 1087 | |
| 1088 | /* iterate through all IARR mapping regions */ |
| 1089 | for (region_idx = 0; region_idx < ib->nr_regions; region_idx++) { |
| 1090 | const struct iproc_pcie_ib_map *ib_map = |
| 1091 | &pcie->ib_map[region_idx]; |
| 1092 | |
| 1093 | /* |
| 1094 | * If current inbound region is already in use or not a |
| 1095 | * compatible type, move on to the next. |
| 1096 | */ |
| 1097 | if (iproc_pcie_ib_is_in_use(pcie, region_idx) || |
| 1098 | !iproc_pcie_ib_check_type(ib_map, type)) |
| 1099 | continue; |
| 1100 | |
| 1101 | /* iterate through all supported region sizes to find a match */ |
| 1102 | for (size_idx = 0; size_idx < ib_map->nr_sizes; size_idx++) { |
| 1103 | resource_size_t region_size = |
| 1104 | ib_map->region_sizes[size_idx] * ib_map->size_unit; |
| 1105 | |
| 1106 | if (size != region_size) |
| 1107 | continue; |
| 1108 | |
| 1109 | if (!IS_ALIGNED(axi_addr, region_size) || |
| 1110 | !IS_ALIGNED(pci_addr, region_size)) { |
| 1111 | dev_err(dev, |
| 1112 | "axi %pap or pci %pap not aligned\n", |
| 1113 | &axi_addr, &pci_addr); |
| 1114 | return -EINVAL; |
| 1115 | } |
| 1116 | |
| 1117 | /* Match found! Program IARR and all IMAP windows. */ |
| 1118 | ret = iproc_pcie_ib_write(pcie, region_idx, size_idx, |
| 1119 | ib_map->nr_windows, axi_addr, |
| 1120 | pci_addr, size); |
| 1121 | if (ret) |
| 1122 | goto err_ib; |
| 1123 | else |
| 1124 | return 0; |
| 1125 | |
| 1126 | } |
| 1127 | } |
| 1128 | ret = -EINVAL; |
| 1129 | |
| 1130 | err_ib: |
| 1131 | dev_err(dev, "unable to configure inbound mapping\n"); |
| 1132 | dev_err(dev, "axi %pap, pci %pap, res size %pap\n", |
| 1133 | &axi_addr, &pci_addr, &size); |
| 1134 | |
| 1135 | return ret; |
| 1136 | } |
| 1137 | |
Ray Jui | dd9d4e7 | 2016-10-31 17:38:39 -0700 | [diff] [blame] | 1138 | static int iproc_pcie_map_dma_ranges(struct iproc_pcie *pcie) |
| 1139 | { |
| 1140 | struct of_pci_range range; |
| 1141 | struct of_pci_range_parser parser; |
| 1142 | int ret; |
| 1143 | |
| 1144 | /* Get the dma-ranges from DT */ |
Marc Gonzalez | 1e61a57 | 2017-09-26 12:26:55 +0200 | [diff] [blame] | 1145 | ret = of_pci_dma_range_parser_init(&parser, pcie->dev->of_node); |
Ray Jui | dd9d4e7 | 2016-10-31 17:38:39 -0700 | [diff] [blame] | 1146 | if (ret) |
| 1147 | return ret; |
| 1148 | |
| 1149 | for_each_of_pci_range(&parser, &range) { |
| 1150 | /* Each range entry corresponds to an inbound mapping region */ |
| 1151 | ret = iproc_pcie_setup_ib(pcie, &range, IPROC_PCIE_IB_MAP_MEM); |
| 1152 | if (ret) |
| 1153 | return ret; |
| 1154 | } |
| 1155 | |
| 1156 | return 0; |
| 1157 | } |
| 1158 | |
Ray Jui | 787b3c4 | 2016-10-31 17:38:35 -0700 | [diff] [blame] | 1159 | static int iproce_pcie_get_msi(struct iproc_pcie *pcie, |
| 1160 | struct device_node *msi_node, |
| 1161 | u64 *msi_addr) |
| 1162 | { |
| 1163 | struct device *dev = pcie->dev; |
| 1164 | int ret; |
| 1165 | struct resource res; |
| 1166 | |
| 1167 | /* |
| 1168 | * Check if 'msi-map' points to ARM GICv3 ITS, which is the only |
| 1169 | * supported external MSI controller that requires steering. |
| 1170 | */ |
| 1171 | if (!of_device_is_compatible(msi_node, "arm,gic-v3-its")) { |
| 1172 | dev_err(dev, "unable to find compatible MSI controller\n"); |
| 1173 | return -ENODEV; |
| 1174 | } |
| 1175 | |
| 1176 | /* derive GITS_TRANSLATER address from GICv3 */ |
| 1177 | ret = of_address_to_resource(msi_node, 0, &res); |
| 1178 | if (ret < 0) { |
| 1179 | dev_err(dev, "unable to obtain MSI controller resources\n"); |
| 1180 | return ret; |
| 1181 | } |
| 1182 | |
| 1183 | *msi_addr = res.start + GITS_TRANSLATER; |
| 1184 | return 0; |
| 1185 | } |
| 1186 | |
Ray Jui | c7c4452 | 2016-10-31 17:38:41 -0700 | [diff] [blame] | 1187 | static int iproc_pcie_paxb_v2_msi_steer(struct iproc_pcie *pcie, u64 msi_addr) |
| 1188 | { |
| 1189 | int ret; |
| 1190 | struct of_pci_range range; |
| 1191 | |
| 1192 | memset(&range, 0, sizeof(range)); |
| 1193 | range.size = SZ_32K; |
Ray Jui | feacdb4 | 2016-11-21 17:48:30 -0800 | [diff] [blame] | 1194 | range.pci_addr = range.cpu_addr = msi_addr & ~(range.size - 1); |
Ray Jui | c7c4452 | 2016-10-31 17:38:41 -0700 | [diff] [blame] | 1195 | |
| 1196 | ret = iproc_pcie_setup_ib(pcie, &range, IPROC_PCIE_IB_MAP_IO); |
| 1197 | return ret; |
| 1198 | } |
| 1199 | |
Ray Jui | 787b3c4 | 2016-10-31 17:38:35 -0700 | [diff] [blame] | 1200 | static void iproc_pcie_paxc_v2_msi_steer(struct iproc_pcie *pcie, u64 msi_addr) |
| 1201 | { |
| 1202 | u32 val; |
| 1203 | |
| 1204 | /* |
| 1205 | * Program bits [43:13] of address of GITS_TRANSLATER register into |
| 1206 | * bits [30:0] of the MSI base address register. In fact, in all iProc |
| 1207 | * based SoCs, all I/O register bases are well below the 32-bit |
| 1208 | * boundary, so we can safely assume bits [43:32] are always zeros. |
| 1209 | */ |
| 1210 | iproc_pcie_write_reg(pcie, IPROC_PCIE_MSI_BASE_ADDR, |
| 1211 | (u32)(msi_addr >> 13)); |
| 1212 | |
| 1213 | /* use a default 8K window size */ |
| 1214 | iproc_pcie_write_reg(pcie, IPROC_PCIE_MSI_WINDOW_SIZE, 0); |
| 1215 | |
| 1216 | /* steering MSI to GICv3 ITS */ |
| 1217 | val = iproc_pcie_read_reg(pcie, IPROC_PCIE_MSI_GIC_MODE); |
| 1218 | val |= GIC_V3_CFG; |
| 1219 | iproc_pcie_write_reg(pcie, IPROC_PCIE_MSI_GIC_MODE, val); |
| 1220 | |
| 1221 | /* |
| 1222 | * Program bits [43:2] of address of GITS_TRANSLATER register into the |
| 1223 | * iProc MSI address registers. |
| 1224 | */ |
| 1225 | msi_addr >>= 2; |
| 1226 | iproc_pcie_write_reg(pcie, IPROC_PCIE_MSI_ADDR_HI, |
| 1227 | upper_32_bits(msi_addr)); |
| 1228 | iproc_pcie_write_reg(pcie, IPROC_PCIE_MSI_ADDR_LO, |
| 1229 | lower_32_bits(msi_addr)); |
| 1230 | |
| 1231 | /* enable MSI */ |
| 1232 | val = iproc_pcie_read_reg(pcie, IPROC_PCIE_MSI_EN_CFG); |
| 1233 | val |= MSI_ENABLE_CFG; |
| 1234 | iproc_pcie_write_reg(pcie, IPROC_PCIE_MSI_EN_CFG, val); |
| 1235 | } |
| 1236 | |
| 1237 | static int iproc_pcie_msi_steer(struct iproc_pcie *pcie, |
| 1238 | struct device_node *msi_node) |
| 1239 | { |
| 1240 | struct device *dev = pcie->dev; |
| 1241 | int ret; |
| 1242 | u64 msi_addr; |
| 1243 | |
| 1244 | ret = iproce_pcie_get_msi(pcie, msi_node, &msi_addr); |
| 1245 | if (ret < 0) { |
| 1246 | dev_err(dev, "msi steering failed\n"); |
| 1247 | return ret; |
| 1248 | } |
| 1249 | |
| 1250 | switch (pcie->type) { |
Ray Jui | c7c4452 | 2016-10-31 17:38:41 -0700 | [diff] [blame] | 1251 | case IPROC_PCIE_PAXB_V2: |
| 1252 | ret = iproc_pcie_paxb_v2_msi_steer(pcie, msi_addr); |
| 1253 | if (ret) |
| 1254 | return ret; |
| 1255 | break; |
Ray Jui | 787b3c4 | 2016-10-31 17:38:35 -0700 | [diff] [blame] | 1256 | case IPROC_PCIE_PAXC_V2: |
| 1257 | iproc_pcie_paxc_v2_msi_steer(pcie, msi_addr); |
| 1258 | break; |
| 1259 | default: |
| 1260 | return -EINVAL; |
| 1261 | } |
| 1262 | |
| 1263 | return 0; |
| 1264 | } |
| 1265 | |
Ray Jui | 3bc2b23 | 2016-01-06 18:04:35 -0600 | [diff] [blame] | 1266 | static int iproc_pcie_msi_enable(struct iproc_pcie *pcie) |
| 1267 | { |
| 1268 | struct device_node *msi_node; |
Ray Jui | 787b3c4 | 2016-10-31 17:38:35 -0700 | [diff] [blame] | 1269 | int ret; |
| 1270 | |
| 1271 | /* |
| 1272 | * Either the "msi-parent" or the "msi-map" phandle needs to exist |
| 1273 | * for us to obtain the MSI node. |
| 1274 | */ |
Ray Jui | 3bc2b23 | 2016-01-06 18:04:35 -0600 | [diff] [blame] | 1275 | |
| 1276 | msi_node = of_parse_phandle(pcie->dev->of_node, "msi-parent", 0); |
Ray Jui | 787b3c4 | 2016-10-31 17:38:35 -0700 | [diff] [blame] | 1277 | if (!msi_node) { |
| 1278 | const __be32 *msi_map = NULL; |
| 1279 | int len; |
| 1280 | u32 phandle; |
| 1281 | |
| 1282 | msi_map = of_get_property(pcie->dev->of_node, "msi-map", &len); |
| 1283 | if (!msi_map) |
| 1284 | return -ENODEV; |
| 1285 | |
| 1286 | phandle = be32_to_cpup(msi_map + 1); |
| 1287 | msi_node = of_find_node_by_phandle(phandle); |
| 1288 | if (!msi_node) |
| 1289 | return -ENODEV; |
| 1290 | } |
| 1291 | |
| 1292 | /* |
| 1293 | * Certain revisions of the iProc PCIe controller require additional |
| 1294 | * configurations to steer the MSI writes towards an external MSI |
| 1295 | * controller. |
| 1296 | */ |
| 1297 | if (pcie->need_msi_steer) { |
| 1298 | ret = iproc_pcie_msi_steer(pcie, msi_node); |
| 1299 | if (ret) |
| 1300 | return ret; |
| 1301 | } |
Ray Jui | 3bc2b23 | 2016-01-06 18:04:35 -0600 | [diff] [blame] | 1302 | |
| 1303 | /* |
| 1304 | * If another MSI controller is being used, the call below should fail |
| 1305 | * but that is okay |
| 1306 | */ |
| 1307 | return iproc_msi_init(pcie, msi_node); |
| 1308 | } |
| 1309 | |
| 1310 | static void iproc_pcie_msi_disable(struct iproc_pcie *pcie) |
| 1311 | { |
| 1312 | iproc_msi_exit(pcie); |
| 1313 | } |
| 1314 | |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 1315 | static int iproc_pcie_rev_init(struct iproc_pcie *pcie) |
| 1316 | { |
| 1317 | struct device *dev = pcie->dev; |
| 1318 | unsigned int reg_idx; |
| 1319 | const u16 *regs; |
| 1320 | |
| 1321 | switch (pcie->type) { |
Ray Jui | 404349c | 2016-10-31 17:38:32 -0700 | [diff] [blame] | 1322 | case IPROC_PCIE_PAXB_BCMA: |
| 1323 | regs = iproc_pcie_reg_paxb_bcma; |
| 1324 | break; |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 1325 | case IPROC_PCIE_PAXB: |
| 1326 | regs = iproc_pcie_reg_paxb; |
Ray Jui | 538928f | 2016-10-31 17:38:33 -0700 | [diff] [blame] | 1327 | pcie->has_apb_err_disable = true; |
Ray Jui | 4213e15 | 2016-10-31 17:38:37 -0700 | [diff] [blame] | 1328 | if (pcie->need_ob_cfg) { |
| 1329 | pcie->ob_map = paxb_ob_map; |
| 1330 | pcie->ob.nr_windows = ARRAY_SIZE(paxb_ob_map); |
| 1331 | } |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 1332 | break; |
Ray Jui | c7c4452 | 2016-10-31 17:38:41 -0700 | [diff] [blame] | 1333 | case IPROC_PCIE_PAXB_V2: |
| 1334 | regs = iproc_pcie_reg_paxb_v2; |
| 1335 | pcie->has_apb_err_disable = true; |
| 1336 | if (pcie->need_ob_cfg) { |
| 1337 | pcie->ob_map = paxb_v2_ob_map; |
| 1338 | pcie->ob.nr_windows = ARRAY_SIZE(paxb_v2_ob_map); |
| 1339 | } |
| 1340 | pcie->ib.nr_regions = ARRAY_SIZE(paxb_v2_ib_map); |
| 1341 | pcie->ib_map = paxb_v2_ib_map; |
| 1342 | pcie->need_msi_steer = true; |
Oza Pawandeep | 39b7a4f | 2017-08-28 16:43:30 -0500 | [diff] [blame] | 1343 | dev_warn(dev, "reads of config registers that contain %#x return incorrect data\n", |
| 1344 | CFG_RETRY_STATUS); |
Ray Jui | c7c4452 | 2016-10-31 17:38:41 -0700 | [diff] [blame] | 1345 | break; |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 1346 | case IPROC_PCIE_PAXC: |
| 1347 | regs = iproc_pcie_reg_paxc; |
| 1348 | pcie->ep_is_internal = true; |
| 1349 | break; |
Ray Jui | 787b3c4 | 2016-10-31 17:38:35 -0700 | [diff] [blame] | 1350 | case IPROC_PCIE_PAXC_V2: |
| 1351 | regs = iproc_pcie_reg_paxc_v2; |
| 1352 | pcie->ep_is_internal = true; |
| 1353 | pcie->need_msi_steer = true; |
| 1354 | break; |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 1355 | default: |
| 1356 | dev_err(dev, "incompatible iProc PCIe interface\n"); |
| 1357 | return -EINVAL; |
| 1358 | } |
| 1359 | |
| 1360 | pcie->reg_offsets = devm_kcalloc(dev, IPROC_PCIE_MAX_NUM_REG, |
| 1361 | sizeof(*pcie->reg_offsets), |
| 1362 | GFP_KERNEL); |
| 1363 | if (!pcie->reg_offsets) |
| 1364 | return -ENOMEM; |
| 1365 | |
| 1366 | /* go through the register table and populate all valid registers */ |
Ray Jui | 787b3c4 | 2016-10-31 17:38:35 -0700 | [diff] [blame] | 1367 | pcie->reg_offsets[0] = (pcie->type == IPROC_PCIE_PAXC_V2) ? |
| 1368 | IPROC_PCIE_REG_INVALID : regs[0]; |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 1369 | for (reg_idx = 1; reg_idx < IPROC_PCIE_MAX_NUM_REG; reg_idx++) |
| 1370 | pcie->reg_offsets[reg_idx] = regs[reg_idx] ? |
| 1371 | regs[reg_idx] : IPROC_PCIE_REG_INVALID; |
| 1372 | |
| 1373 | return 0; |
| 1374 | } |
| 1375 | |
Hauke Mehrtens | 18c4342 | 2015-05-24 22:37:02 +0200 | [diff] [blame] | 1376 | int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res) |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 1377 | { |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 1378 | struct device *dev; |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 1379 | int ret; |
Lorenzo Pieralisi | 5277407 | 2017-06-28 15:13:57 -0500 | [diff] [blame] | 1380 | struct pci_bus *child; |
| 1381 | struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 1382 | |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 1383 | dev = pcie->dev; |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 1384 | |
| 1385 | ret = iproc_pcie_rev_init(pcie); |
| 1386 | if (ret) { |
| 1387 | dev_err(dev, "unable to initialize controller parameters\n"); |
| 1388 | return ret; |
| 1389 | } |
| 1390 | |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 1391 | ret = devm_request_pci_bus_resources(dev, res); |
Bjorn Helgaas | c3245a5 | 2016-05-28 18:22:24 -0500 | [diff] [blame] | 1392 | if (ret) |
| 1393 | return ret; |
| 1394 | |
Markus Elfring | 93972d1 | 2015-06-28 16:42:04 +0200 | [diff] [blame] | 1395 | ret = phy_init(pcie->phy); |
| 1396 | if (ret) { |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 1397 | dev_err(dev, "unable to initialize PCIe PHY\n"); |
Markus Elfring | 93972d1 | 2015-06-28 16:42:04 +0200 | [diff] [blame] | 1398 | return ret; |
| 1399 | } |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 1400 | |
Markus Elfring | 93972d1 | 2015-06-28 16:42:04 +0200 | [diff] [blame] | 1401 | ret = phy_power_on(pcie->phy); |
| 1402 | if (ret) { |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 1403 | dev_err(dev, "unable to power on PCIe PHY\n"); |
Markus Elfring | 93972d1 | 2015-06-28 16:42:04 +0200 | [diff] [blame] | 1404 | goto err_exit_phy; |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 1405 | } |
| 1406 | |
Oza Pawandeep | b91c26c | 2017-08-28 16:43:35 -0500 | [diff] [blame] | 1407 | iproc_pcie_perst_ctrl(pcie, true); |
| 1408 | iproc_pcie_perst_ctrl(pcie, false); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 1409 | |
Ray Jui | e99a187 | 2015-10-16 08:18:24 -0500 | [diff] [blame] | 1410 | if (pcie->need_ob_cfg) { |
| 1411 | ret = iproc_pcie_map_ranges(pcie, res); |
| 1412 | if (ret) { |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 1413 | dev_err(dev, "map failed\n"); |
Ray Jui | e99a187 | 2015-10-16 08:18:24 -0500 | [diff] [blame] | 1414 | goto err_power_off_phy; |
| 1415 | } |
| 1416 | } |
| 1417 | |
Ray Jui | 3b65ca5 | 2018-01-11 12:36:16 -0800 | [diff] [blame] | 1418 | if (pcie->need_ib_cfg) { |
| 1419 | ret = iproc_pcie_map_dma_ranges(pcie); |
| 1420 | if (ret && ret != -ENOENT) |
| 1421 | goto err_power_off_phy; |
| 1422 | } |
Ray Jui | dd9d4e7 | 2016-10-31 17:38:39 -0700 | [diff] [blame] | 1423 | |
Lorenzo Pieralisi | 022adcf | 2017-06-28 15:13:50 -0500 | [diff] [blame] | 1424 | ret = iproc_pcie_check_link(pcie); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 1425 | if (ret) { |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 1426 | dev_err(dev, "no PCIe EP device detected\n"); |
Lorenzo Pieralisi | 5277407 | 2017-06-28 15:13:57 -0500 | [diff] [blame] | 1427 | goto err_power_off_phy; |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | iproc_pcie_enable(pcie); |
| 1431 | |
Ray Jui | 3bc2b23 | 2016-01-06 18:04:35 -0600 | [diff] [blame] | 1432 | if (IS_ENABLED(CONFIG_PCI_MSI)) |
| 1433 | if (iproc_pcie_msi_enable(pcie)) |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 1434 | dev_info(dev, "not using iProc MSI\n"); |
Ray Jui | 3bc2b23 | 2016-01-06 18:04:35 -0600 | [diff] [blame] | 1435 | |
Lorenzo Pieralisi | 5277407 | 2017-06-28 15:13:57 -0500 | [diff] [blame] | 1436 | list_splice_init(res, &host->windows); |
| 1437 | host->busnr = 0; |
| 1438 | host->dev.parent = dev; |
| 1439 | host->ops = &iproc_pcie_ops; |
Rob Herring | a1b363a | 2018-03-07 09:42:36 -0600 | [diff] [blame] | 1440 | host->sysdata = pcie; |
Lorenzo Pieralisi | 64bcd00 | 2017-06-28 15:14:07 -0500 | [diff] [blame] | 1441 | host->map_irq = pcie->map_irq; |
| 1442 | host->swizzle_irq = pci_common_swizzle; |
Lorenzo Pieralisi | 5277407 | 2017-06-28 15:13:57 -0500 | [diff] [blame] | 1443 | |
| 1444 | ret = pci_scan_root_bus_bridge(host); |
| 1445 | if (ret < 0) { |
| 1446 | dev_err(dev, "failed to scan host: %d\n", ret); |
| 1447 | goto err_power_off_phy; |
| 1448 | } |
Andy Gospodarek | ffbd796 | 2016-12-01 15:34:52 -0500 | [diff] [blame] | 1449 | |
Lorenzo Pieralisi | 5277407 | 2017-06-28 15:13:57 -0500 | [diff] [blame] | 1450 | pci_assign_unassigned_bus_resources(host->bus); |
| 1451 | |
| 1452 | pcie->root_bus = host->bus; |
| 1453 | |
| 1454 | list_for_each_entry(child, &host->bus->children, node) |
Jon Mason | 4d4836a | 2017-01-27 16:44:08 -0500 | [diff] [blame] | 1455 | pcie_bus_configure_settings(child); |
| 1456 | |
Lorenzo Pieralisi | 5277407 | 2017-06-28 15:13:57 -0500 | [diff] [blame] | 1457 | pci_bus_add_devices(host->bus); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 1458 | |
| 1459 | return 0; |
| 1460 | |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 1461 | err_power_off_phy: |
Markus Elfring | 93972d1 | 2015-06-28 16:42:04 +0200 | [diff] [blame] | 1462 | phy_power_off(pcie->phy); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 1463 | err_exit_phy: |
Markus Elfring | 93972d1 | 2015-06-28 16:42:04 +0200 | [diff] [blame] | 1464 | phy_exit(pcie->phy); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 1465 | return ret; |
| 1466 | } |
| 1467 | EXPORT_SYMBOL(iproc_pcie_setup); |
| 1468 | |
| 1469 | int iproc_pcie_remove(struct iproc_pcie *pcie) |
| 1470 | { |
| 1471 | pci_stop_root_bus(pcie->root_bus); |
| 1472 | pci_remove_root_bus(pcie->root_bus); |
| 1473 | |
Ray Jui | 3bc2b23 | 2016-01-06 18:04:35 -0600 | [diff] [blame] | 1474 | iproc_pcie_msi_disable(pcie); |
| 1475 | |
Markus Elfring | 93972d1 | 2015-06-28 16:42:04 +0200 | [diff] [blame] | 1476 | phy_power_off(pcie->phy); |
| 1477 | phy_exit(pcie->phy); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 1478 | |
| 1479 | return 0; |
| 1480 | } |
| 1481 | EXPORT_SYMBOL(iproc_pcie_remove); |
| 1482 | |
| 1483 | MODULE_AUTHOR("Ray Jui <rjui@broadcom.com>"); |
| 1484 | MODULE_DESCRIPTION("Broadcom iPROC PCIe common driver"); |
| 1485 | MODULE_LICENSE("GPL v2"); |