kernel: bump 5.4 to 5.4.73
[openwrt/openwrt.git] / target / linux / lantiq / patches-5.4 / 0001-MIPS-lantiq-add-pcie-driver.patch
1 From 6f933347d0b4ed02d9534f5fa07f7b99f13eeaa1 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Thu, 7 Aug 2014 18:12:28 +0200
4 Subject: [PATCH 01/36] MIPS: lantiq: add pcie driver
5
6 Signed-off-by: John Crispin <blogic@openwrt.org>
7 ---
8 arch/mips/lantiq/Kconfig | 10 +
9 arch/mips/lantiq/xway/sysctrl.c | 2 +
10 arch/mips/pci/Makefile | 2 +
11 arch/mips/pci/fixup-lantiq-pcie.c | 82 +++
12 arch/mips/pci/fixup-lantiq.c | 5 +-
13 arch/mips/pci/ifxmips_pci_common.h | 57 ++
14 arch/mips/pci/ifxmips_pcie.c | 1099 ++++++++++++++++++++++++++++++
15 arch/mips/pci/ifxmips_pcie.h | 135 ++++
16 arch/mips/pci/ifxmips_pcie_ar10.h | 290 ++++++++
17 arch/mips/pci/ifxmips_pcie_msi.c | 392 +++++++++++
18 arch/mips/pci/ifxmips_pcie_phy.c | 478 +++++++++++++
19 arch/mips/pci/ifxmips_pcie_pm.c | 176 +++++
20 arch/mips/pci/ifxmips_pcie_pm.h | 36 +
21 arch/mips/pci/ifxmips_pcie_reg.h | 1001 +++++++++++++++++++++++++++
22 arch/mips/pci/ifxmips_pcie_vr9.h | 271 ++++++++
23 arch/mips/pci/pci.c | 25 +
24 arch/mips/pci/pcie-lantiq.h | 1305 ++++++++++++++++++++++++++++++++++++
25 drivers/pci/pcie/aer/Kconfig | 2 +-
26 include/linux/pci.h | 2 +
27 include/linux/pci_ids.h | 6 +
28 20 files changed, 5374 insertions(+), 2 deletions(-)
29 create mode 100644 arch/mips/pci/fixup-lantiq-pcie.c
30 create mode 100644 arch/mips/pci/ifxmips_pci_common.h
31 create mode 100644 arch/mips/pci/ifxmips_pcie.c
32 create mode 100644 arch/mips/pci/ifxmips_pcie.h
33 create mode 100644 arch/mips/pci/ifxmips_pcie_ar10.h
34 create mode 100644 arch/mips/pci/ifxmips_pcie_msi.c
35 create mode 100644 arch/mips/pci/ifxmips_pcie_phy.c
36 create mode 100644 arch/mips/pci/ifxmips_pcie_pm.c
37 create mode 100644 arch/mips/pci/ifxmips_pcie_pm.h
38 create mode 100644 arch/mips/pci/ifxmips_pcie_reg.h
39 create mode 100644 arch/mips/pci/ifxmips_pcie_vr9.h
40 create mode 100644 arch/mips/pci/pcie-lantiq.h
41
42 --- a/arch/mips/lantiq/Kconfig
43 +++ b/arch/mips/lantiq/Kconfig
44 @@ -20,6 +20,7 @@ config SOC_XWAY
45 bool "XWAY"
46 select SOC_TYPE_XWAY
47 select HAVE_PCI
48 + select ARCH_SUPPORTS_MSI
49 select MFD_SYSCON
50 select MFD_CORE
51
52 @@ -52,4 +53,13 @@ config PCI_LANTIQ
53 bool "PCI Support"
54 depends on SOC_XWAY && PCI
55
56 +config PCIE_LANTIQ
57 + bool "PCIE Support"
58 + depends on SOC_XWAY && PCI
59 +
60 +config PCIE_LANTIQ_MSI
61 + bool
62 + depends on PCIE_LANTIQ && PCI_MSI
63 + default y
64 +
65 endif
66 --- a/arch/mips/pci/Makefile
67 +++ b/arch/mips/pci/Makefile
68 @@ -51,6 +51,8 @@ obj-$(CONFIG_PCI_LANTIQ) += pci-lantiq.o
69 obj-$(CONFIG_SOC_MT7620) += pci-mt7620.o
70 obj-$(CONFIG_SOC_RT288X) += pci-rt2880.o
71 obj-$(CONFIG_SOC_RT3883) += pci-rt3883.o
72 +obj-$(CONFIG_PCIE_LANTIQ) += ifxmips_pcie_phy.o ifxmips_pcie.o fixup-lantiq-pcie.o
73 +obj-$(CONFIG_PCIE_LANTIQ_MSI) += pcie-lantiq-msi.o
74 obj-$(CONFIG_TANBAC_TB0219) += fixup-tb0219.o
75 obj-$(CONFIG_TANBAC_TB0226) += fixup-tb0226.o
76 obj-$(CONFIG_TANBAC_TB0287) += fixup-tb0287.o
77 --- /dev/null
78 +++ b/arch/mips/pci/fixup-lantiq-pcie.c
79 @@ -0,0 +1,74 @@
80 +/******************************************************************************
81 +**
82 +** FILE NAME : ifxmips_fixup_pcie.c
83 +** PROJECT : IFX UEIP for VRX200
84 +** MODULES : PCIe
85 +**
86 +** DATE : 02 Mar 2009
87 +** AUTHOR : Lei Chuanhua
88 +** DESCRIPTION : PCIe Root Complex Driver
89 +** COPYRIGHT : Copyright (c) 2009
90 +** Infineon Technologies AG
91 +** Am Campeon 1-12, 85579 Neubiberg, Germany
92 +**
93 +** This program is free software; you can redistribute it and/or modify
94 +** it under the terms of the GNU General Public License as published by
95 +** the Free Software Foundation; either version 2 of the License, or
96 +** (at your option) any later version.
97 +** HISTORY
98 +** $Version $Date $Author $Comment
99 +** 0.0.1 17 Mar,2009 Lei Chuanhua Initial version
100 +*******************************************************************************/
101 +/*!
102 + \file ifxmips_fixup_pcie.c
103 + \ingroup IFX_PCIE
104 + \brief PCIe Fixup functions source file
105 +*/
106 +#include <linux/pci.h>
107 +#include <linux/pci_regs.h>
108 +#include <linux/pci_ids.h>
109 +
110 +#include <lantiq_soc.h>
111 +
112 +#include "pcie-lantiq.h"
113 +
114 +static void
115 +ifx_pcie_fixup_resource(struct pci_dev *dev)
116 +{
117 + u32 reg;
118 +
119 + IFX_PCIE_PRINT(PCIE_MSG_FIXUP, "%s dev %s: enter\n", __func__, pci_name(dev));
120 +
121 + printk("%s: fixup host controller %s (%04x:%04x)\n",
122 + __func__, pci_name(dev), dev->vendor, dev->device);
123 +
124 + /* Setup COMMAND register */
125 + reg = PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER /* |
126 + PCI_COMMAND_INTX_DISABLE */| PCI_COMMAND_SERR;
127 + pci_write_config_word(dev, PCI_COMMAND, reg);
128 + IFX_PCIE_PRINT(PCIE_MSG_FIXUP, "%s dev %s: exit\n", __func__, pci_name(dev));
129 +}
130 +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INFINEON, PCI_DEVICE_ID_INFINEON_PCIE, ifx_pcie_fixup_resource);
131 +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_LANTIQ, PCI_VENDOR_ID_LANTIQ, ifx_pcie_fixup_resource);
132 +
133 +static void
134 +ifx_pcie_rc_class_early_fixup(struct pci_dev *dev)
135 +{
136 + IFX_PCIE_PRINT(PCIE_MSG_FIXUP, "%s dev %s: enter\n", __func__, pci_name(dev));
137 +
138 + if (dev->devfn == PCI_DEVFN(0, 0) &&
139 + (dev->class >> 8) == PCI_CLASS_BRIDGE_HOST) {
140 +
141 + dev->class = (PCI_CLASS_BRIDGE_PCI << 8) | (dev->class & 0xff);
142 +
143 + printk(KERN_INFO "%s: fixed pcie host bridge to pci-pci bridge\n", __func__);
144 + }
145 + IFX_PCIE_PRINT(PCIE_MSG_FIXUP, "%s dev %s: exit\n", __func__, pci_name(dev));
146 + mdelay(10);
147 +}
148 +
149 +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INFINEON, PCI_DEVICE_ID_INFINEON_PCIE,
150 + ifx_pcie_rc_class_early_fixup);
151 +
152 +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_LANTIQ, PCI_DEVICE_ID_LANTIQ_PCIE,
153 + ifx_pcie_rc_class_early_fixup);
154 --- a/arch/mips/pci/fixup-lantiq.c
155 +++ b/arch/mips/pci/fixup-lantiq.c
156 @@ -6,12 +6,18 @@
157
158 #include <linux/of_irq.h>
159 #include <linux/of_pci.h>
160 +#include "ifxmips_pci_common.h"
161
162 int (*ltq_pci_plat_arch_init)(struct pci_dev *dev) = NULL;
163 int (*ltq_pci_plat_dev_init)(struct pci_dev *dev) = NULL;
164
165 int pcibios_plat_dev_init(struct pci_dev *dev)
166 {
167 +#ifdef CONFIG_PCIE_LANTIQ
168 + if (pci_find_capability(dev, PCI_CAP_ID_EXP))
169 + ifx_pcie_bios_plat_dev_init(dev);
170 +#endif
171 +
172 if (ltq_pci_plat_arch_init)
173 return ltq_pci_plat_arch_init(dev);
174
175 @@ -23,5 +29,10 @@ int pcibios_plat_dev_init(struct pci_dev
176
177 int pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
178 {
179 +#ifdef CONFIG_PCIE_LANTIQ
180 + if (pci_find_capability(dev, PCI_CAP_ID_EXP))
181 + return ifx_pcie_bios_map_irq(dev, slot, pin);
182 +#endif
183 +
184 return of_irq_parse_and_map_pci(dev, slot, pin);
185 }
186 --- /dev/null
187 +++ b/arch/mips/pci/ifxmips_pci_common.h
188 @@ -0,0 +1,53 @@
189 +/******************************************************************************
190 +**
191 +** FILE NAME : ifxmips_pci_common.h
192 +** PROJECT : IFX UEIP
193 +** MODULES : PCI subsystem
194 +**
195 +** DATE : 30 June 2009
196 +** AUTHOR : Lei Chuanhua
197 +** DESCRIPTION : PCIe Root Complex Driver
198 +** COPYRIGHT : Copyright (c) 2009
199 +** Infineon Technologies AG
200 +** Am Campeon 1-12, 85579 Neubiberg, Germany
201 +**
202 +** This program is free software; you can redistribute it and/or modify
203 +** it under the terms of the GNU General Public License as published by
204 +** the Free Software Foundation; either version 2 of the License, or
205 +** (at your option) any later version.
206 +** HISTORY
207 +** $Version $Date $Author $Comment
208 +** 0.0.1 30 June,2009 Lei Chuanhua Initial version
209 +*******************************************************************************/
210 +
211 +#ifndef IFXMIPS_PCI_COMMON_H
212 +#define IFXMIPS_PCI_COMMON_H
213 +#include <linux/version.h>
214 +/*!
215 + \defgroup IFX_PCI_COM IFX PCI/PCIe common parts for OS integration
216 + \brief PCI/PCIe common parts
217 +*/
218 +
219 +/*!
220 + \defgroup IFX_PCI_COM_OS OS APIs
221 + \ingroup IFX_PCI_COM
222 + \brief PCI/PCIe bus driver OS interface functions
223 +*/
224 +/*!
225 + \file ifxmips_pci_common.h
226 + \ingroup IFX_PCI_COM
227 + \brief PCI/PCIe bus driver common OS header file
228 +*/
229 +#define IFX_PCI_CONST const
230 +#ifdef CONFIG_IFX_PCI
231 +extern int ifx_pci_bios_map_irq(IFX_PCI_CONST struct pci_dev *dev, u8 slot, u8 pin);
232 +extern int ifx_pci_bios_plat_dev_init(struct pci_dev *dev);
233 +#endif /* COFNIG_IFX_PCI */
234 +
235 +#ifdef CONFIG_PCIE_LANTIQ
236 +extern int ifx_pcie_bios_map_irq(IFX_PCI_CONST struct pci_dev *dev, u8 slot, u8 pin);
237 +extern int ifx_pcie_bios_plat_dev_init(struct pci_dev *dev);
238 +#endif
239 +
240 +#endif /* IFXMIPS_PCI_COMMON_H */
241 +
242 --- /dev/null
243 +++ b/arch/mips/pci/ifxmips_pcie.c
244 @@ -0,0 +1,1092 @@
245 +/*
246 + * This program is free software; you can redistribute it and/or modify it
247 + * under the terms of the GNU General Public License version 2 as published
248 + * by the Free Software Foundation.
249 + *
250 + * Copyright (C) 2009 Lei Chuanhua <chuanhua.lei@infineon.com>
251 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
252 + */
253 +
254 +#include <linux/types.h>
255 +#include <linux/pci.h>
256 +#include <linux/kernel.h>
257 +#include <linux/init.h>
258 +#include <linux/delay.h>
259 +#include <linux/mm.h>
260 +#include <asm/paccess.h>
261 +#include <linux/pci.h>
262 +#include <linux/pci_regs.h>
263 +#include <linux/module.h>
264 +
265 +#include "ifxmips_pcie.h"
266 +#include "ifxmips_pcie_reg.h"
267 +
268 +/* Enable 32bit io due to its mem mapped io nature */
269 +#define IFX_PCIE_ERROR_INT
270 +#define IFX_PCIE_IO_32BIT
271 +
272 +#define IFX_PCIE_IR (INT_NUM_IM4_IRL0 + 25)
273 +#define IFX_PCIE_INTA (INT_NUM_IM4_IRL0 + 8)
274 +#define IFX_PCIE_INTB (INT_NUM_IM4_IRL0 + 9)
275 +#define IFX_PCIE_INTC (INT_NUM_IM4_IRL0 + 10)
276 +#define IFX_PCIE_INTD (INT_NUM_IM4_IRL0 + 11)
277 +#define MS(_v, _f) (((_v) & (_f)) >> _f##_S)
278 +#define SM(_v, _f) (((_v) << _f##_S) & (_f))
279 +#define IFX_REG_SET_BIT(_f, _r) \
280 + IFX_REG_W32((IFX_REG_R32((_r)) &~ (_f)) | (_f), (_r))
281 +
282 +#define IFX_PCIE_LTSSM_ENABLE_TIMEOUT 10
283 +
284 +static DEFINE_SPINLOCK(ifx_pcie_lock);
285 +
286 +u32 g_pcie_debug_flag = PCIE_MSG_ANY & (~PCIE_MSG_CFG);
287 +
288 +static ifx_pcie_irq_t pcie_irqs[IFX_PCIE_CORE_NR] = {
289 + {
290 + .ir_irq = {
291 + .irq = IFX_PCIE_IR,
292 + .name = "ifx_pcie_rc0",
293 + },
294 +
295 + .legacy_irq = {
296 + {
297 + .irq_bit = PCIE_IRN_INTA,
298 + .irq = IFX_PCIE_INTA,
299 + },
300 + {
301 + .irq_bit = PCIE_IRN_INTB,
302 + .irq = IFX_PCIE_INTB,
303 + },
304 + {
305 + .irq_bit = PCIE_IRN_INTC,
306 + .irq = IFX_PCIE_INTC,
307 + },
308 + {
309 + .irq_bit = PCIE_IRN_INTD,
310 + .irq = IFX_PCIE_INTD,
311 + },
312 + },
313 + },
314 +
315 +};
316 +
317 +void ifx_pcie_debug(const char *fmt, ...)
318 +{
319 + static char buf[256] = {0}; /* XXX */
320 + va_list ap;
321 +
322 + va_start(ap, fmt);
323 + vsnprintf(buf, sizeof(buf), fmt, ap);
324 + va_end(ap);
325 +
326 + printk("%s", buf);
327 +}
328 +
329 +
330 +static inline int pcie_ltssm_enable(int pcie_port)
331 +{
332 + int i;
333 +
334 + /* Enable LTSSM */
335 + IFX_REG_W32(PCIE_RC_CCR_LTSSM_ENABLE, PCIE_RC_CCR(pcie_port));
336 +
337 + /* Wait for the link to come up */
338 + for (i = 0; i < IFX_PCIE_LTSSM_ENABLE_TIMEOUT; i++) {
339 + if (!(IFX_REG_R32(PCIE_LCTLSTS(pcie_port)) & PCIE_LCTLSTS_RETRAIN_PENDING))
340 + return 0;
341 + udelay(10);
342 + }
343 +
344 + printk("%s link timeout!!!!!\n", __func__);
345 + return -1;
346 +}
347 +
348 +static inline void pcie_status_register_clear(int pcie_port)
349 +{
350 + IFX_REG_W32(0, PCIE_RC_DR(pcie_port));
351 + IFX_REG_W32(0, PCIE_PCICMDSTS(pcie_port));
352 + IFX_REG_W32(0, PCIE_DCTLSTS(pcie_port));
353 + IFX_REG_W32(0, PCIE_LCTLSTS(pcie_port));
354 + IFX_REG_W32(0, PCIE_SLCTLSTS(pcie_port));
355 + IFX_REG_W32(0, PCIE_RSTS(pcie_port));
356 + IFX_REG_W32(0, PCIE_UES_R(pcie_port));
357 + IFX_REG_W32(0, PCIE_UEMR(pcie_port));
358 + IFX_REG_W32(0, PCIE_UESR(pcie_port));
359 + IFX_REG_W32(0, PCIE_CESR(pcie_port));
360 + IFX_REG_W32(0, PCIE_CEMR(pcie_port));
361 + IFX_REG_W32(0, PCIE_RESR(pcie_port));
362 + IFX_REG_W32(0, PCIE_PVCCRSR(pcie_port));
363 + IFX_REG_W32(0, PCIE_VC0_RSR0(pcie_port));
364 + IFX_REG_W32(0, PCIE_TPFCS(pcie_port));
365 + IFX_REG_W32(0, PCIE_TNPFCS(pcie_port));
366 + IFX_REG_W32(0, PCIE_TCFCS(pcie_port));
367 + IFX_REG_W32(0, PCIE_QSR(pcie_port));
368 + IFX_REG_W32(0, PCIE_IOBLSECS(pcie_port));
369 +}
370 +
371 +static inline int ifx_pcie_link_up(int pcie_port)
372 +{
373 + return (IFX_REG_R32(PCIE_PHY_SR(pcie_port)) & PCIE_PHY_SR_PHY_LINK_UP) ? 1 : 0;
374 +}
375 +
376 +
377 +static inline void pcie_mem_io_setup(int pcie_port)
378 +{
379 + u32 reg;
380 + /*
381 + * BAR[0:1] readonly register
382 + * RC contains only minimal BARs for packets mapped to this device
383 + * Mem/IO filters defines a range of memory occupied by memory mapped IO devices that
384 + * reside on the downstream side fo the bridge.
385 + */
386 + reg = SM((PCIE_MEM_PHY_PORT_TO_END(pcie_port) >> 20), PCIE_MBML_MEM_LIMIT_ADDR)
387 + | SM((PCIE_MEM_PHY_PORT_TO_BASE(pcie_port) >> 20), PCIE_MBML_MEM_BASE_ADDR);
388 +
389 + IFX_REG_W32(reg, PCIE_MBML(pcie_port));
390 +
391 +
392 +#ifdef IFX_PCIE_PREFETCH_MEM_64BIT
393 + reg = SM((PCIE_MEM_PHY_PORT_TO_END(pcie_port) >> 20), PCIE_PMBL_END_ADDR)
394 + | SM((PCIE_MEM_PHY_PORT_TO_BASE(pcie_port) >> 20), PCIE_PMBL_UPPER_12BIT)
395 + | PCIE_PMBL_64BIT_ADDR;
396 + IFX_REG_W32(reg, PCIE_PMBL(pcie_port));
397 +
398 + /* Must configure upper 32bit */
399 + IFX_REG_W32(0, PCIE_PMBU32(pcie_port));
400 + IFX_REG_W32(0, PCIE_PMLU32(pcie_port));
401 +#else
402 + /* PCIe_PBML, same as MBML */
403 + IFX_REG_W32(IFX_REG_R32(PCIE_MBML(pcie_port)), PCIE_PMBL(pcie_port));
404 +#endif
405 +
406 + /* IO Address Range */
407 + reg = SM((PCIE_IO_PHY_PORT_TO_END(pcie_port) >> 12), PCIE_IOBLSECS_IO_LIMIT_ADDR)
408 + | SM((PCIE_IO_PHY_PORT_TO_BASE(pcie_port) >> 12), PCIE_IOBLSECS_IO_BASE_ADDR);
409 +#ifdef IFX_PCIE_IO_32BIT
410 + reg |= PCIE_IOBLSECS_32BIT_IO_ADDR;
411 +#endif /* IFX_PCIE_IO_32BIT */
412 + IFX_REG_W32(reg, PCIE_IOBLSECS(pcie_port));
413 +
414 +#ifdef IFX_PCIE_IO_32BIT
415 + reg = SM((PCIE_IO_PHY_PORT_TO_END(pcie_port) >> 16), PCIE_IO_BANDL_UPPER_16BIT_IO_LIMIT)
416 + | SM((PCIE_IO_PHY_PORT_TO_BASE(pcie_port) >> 16), PCIE_IO_BANDL_UPPER_16BIT_IO_BASE);
417 + IFX_REG_W32(reg, PCIE_IO_BANDL(pcie_port));
418 +
419 +#endif /* IFX_PCIE_IO_32BIT */
420 +}
421 +
422 +static inline void
423 +pcie_device_setup(int pcie_port)
424 +{
425 + u32 reg;
426 +
427 + /* Device capability register, set up Maximum payload size */
428 + reg = IFX_REG_R32(PCIE_DCAP(pcie_port));
429 + reg |= PCIE_DCAP_ROLE_BASE_ERR_REPORT;
430 + reg |= SM(PCIE_MAX_PAYLOAD_128, PCIE_DCAP_MAX_PAYLOAD_SIZE);
431 +
432 + /* Only available for EP */
433 + reg &= ~(PCIE_DCAP_EP_L0S_LATENCY | PCIE_DCAP_EP_L1_LATENCY);
434 + IFX_REG_W32(reg, PCIE_DCAP(pcie_port));
435 +
436 + /* Device control and status register */
437 + /* Set Maximum Read Request size for the device as a Requestor */
438 + reg = IFX_REG_R32(PCIE_DCTLSTS(pcie_port));
439 +
440 + /*
441 + * Request size can be larger than the MPS used, but the completions returned
442 + * for the read will be bounded by the MPS size.
443 + * In our system, Max request size depends on AHB burst size. It is 64 bytes.
444 + * but we set it as 128 as minimum one.
445 + */
446 + reg |= SM(PCIE_MAX_PAYLOAD_128, PCIE_DCTLSTS_MAX_READ_SIZE)
447 + | SM(PCIE_MAX_PAYLOAD_128, PCIE_DCTLSTS_MAX_PAYLOAD_SIZE);
448 +
449 + /* Enable relaxed ordering, no snoop, and all kinds of errors */
450 + reg |= PCIE_DCTLSTS_RELAXED_ORDERING_EN | PCIE_DCTLSTS_ERR_EN | PCIE_DCTLSTS_NO_SNOOP_EN;
451 +
452 + IFX_REG_W32(reg, PCIE_DCTLSTS(pcie_port));
453 +}
454 +
455 +static inline void
456 +pcie_link_setup(int pcie_port)
457 +{
458 + u32 reg;
459 +
460 + /*
461 + * XXX, Link capability register, bit 18 for EP CLKREQ# dynamic clock management for L1, L2/3 CPM
462 + * L0s is reported during link training via TS1 order set by N_FTS
463 + */
464 + reg = IFX_REG_R32(PCIE_LCAP(pcie_port));
465 + reg &= ~PCIE_LCAP_L0S_EIXT_LATENCY;
466 + reg |= SM(3, PCIE_LCAP_L0S_EIXT_LATENCY);
467 + IFX_REG_W32(reg, PCIE_LCAP(pcie_port));
468 +
469 + /* Link control and status register */
470 + reg = IFX_REG_R32(PCIE_LCTLSTS(pcie_port));
471 +
472 + /* Link Enable, ASPM enabled */
473 + reg &= ~PCIE_LCTLSTS_LINK_DISABLE;
474 +
475 +#ifdef CONFIG_PCIEASPM
476 + /*
477 + * We use the same physical reference clock that the platform provides on the connector
478 + * It paved the way for ASPM to calculate the new exit Latency
479 + */
480 + reg |= PCIE_LCTLSTS_SLOT_CLK_CFG;
481 + reg |= PCIE_LCTLSTS_COM_CLK_CFG;
482 + /*
483 + * We should disable ASPM by default except that we have dedicated power management support
484 + * Enable ASPM will cause the system hangup/instability, performance degration
485 + */
486 + reg |= PCIE_LCTLSTS_ASPM_ENABLE;
487 +#else
488 + reg &= ~PCIE_LCTLSTS_ASPM_ENABLE;
489 +#endif /* CONFIG_PCIEASPM */
490 +
491 + /*
492 + * The maximum size of any completion with data packet is bounded by the MPS setting
493 + * in device control register
494 + */
495 +
496 + /* RCB may cause multiple split transactions, two options available, we use 64 byte RCB */
497 + reg &= ~ PCIE_LCTLSTS_RCB128;
498 +
499 + IFX_REG_W32(reg, PCIE_LCTLSTS(pcie_port));
500 +}
501 +
502 +static inline void pcie_error_setup(int pcie_port)
503 +{
504 + u32 reg;
505 +
506 + /*
507 + * Forward ERR_COR, ERR_NONFATAL, ERR_FATAL to the backbone
508 + * Poisoned write TLPs and completions indicating poisoned TLPs will set the PCIe_PCICMDSTS.MDPE
509 + */
510 + reg = IFX_REG_R32(PCIE_INTRBCTRL(pcie_port));
511 + reg |= PCIE_INTRBCTRL_SERR_ENABLE | PCIE_INTRBCTRL_PARITY_ERR_RESP_ENABLE;
512 +
513 + IFX_REG_W32(reg, PCIE_INTRBCTRL(pcie_port));
514 +
515 + /* Uncorrectable Error Mask Register, Unmask <enable> all bits in PCIE_UESR */
516 + reg = IFX_REG_R32(PCIE_UEMR(pcie_port));
517 + reg &= ~PCIE_ALL_UNCORRECTABLE_ERR;
518 + IFX_REG_W32(reg, PCIE_UEMR(pcie_port));
519 +
520 + /* Uncorrectable Error Severity Register, ALL errors are FATAL */
521 + IFX_REG_W32(PCIE_ALL_UNCORRECTABLE_ERR, PCIE_UESR(pcie_port));
522 +
523 + /* Correctable Error Mask Register, unmask <enable> all bits */
524 + reg = IFX_REG_R32(PCIE_CEMR(pcie_port));
525 + reg &= ~PCIE_CORRECTABLE_ERR;
526 + IFX_REG_W32(reg, PCIE_CEMR(pcie_port));
527 +
528 + /* Advanced Error Capabilities and Control Registr */
529 + reg = IFX_REG_R32(PCIE_AECCR(pcie_port));
530 + reg |= PCIE_AECCR_ECRC_CHECK_EN | PCIE_AECCR_ECRC_GEN_EN;
531 + IFX_REG_W32(reg, PCIE_AECCR(pcie_port));
532 +
533 + /* Root Error Command Register, Report all types of errors */
534 + reg = IFX_REG_R32(PCIE_RECR(pcie_port));
535 + reg |= PCIE_RECR_ERR_REPORT_EN;
536 + IFX_REG_W32(reg, PCIE_RECR(pcie_port));
537 +
538 + /* Clear the Root status register */
539 + reg = IFX_REG_R32(PCIE_RESR(pcie_port));
540 + IFX_REG_W32(reg, PCIE_RESR(pcie_port));
541 +}
542 +
543 +static inline void pcie_port_logic_setup(int pcie_port)
544 +{
545 + u32 reg;
546 +
547 + /* FTS number, default 12, increase to 63, may increase time from/to L0s to L0 */
548 + reg = IFX_REG_R32(PCIE_AFR(pcie_port));
549 + reg &= ~(PCIE_AFR_FTS_NUM | PCIE_AFR_COM_FTS_NUM);
550 + reg |= SM(PCIE_AFR_FTS_NUM_DEFAULT, PCIE_AFR_FTS_NUM)
551 + | SM(PCIE_AFR_FTS_NUM_DEFAULT, PCIE_AFR_COM_FTS_NUM);
552 + /* L0s and L1 entry latency */
553 + reg &= ~(PCIE_AFR_L0S_ENTRY_LATENCY | PCIE_AFR_L1_ENTRY_LATENCY);
554 + reg |= SM(PCIE_AFR_L0S_ENTRY_LATENCY_DEFAULT, PCIE_AFR_L0S_ENTRY_LATENCY)
555 + | SM(PCIE_AFR_L1_ENTRY_LATENCY_DEFAULT, PCIE_AFR_L1_ENTRY_LATENCY);
556 + IFX_REG_W32(reg, PCIE_AFR(pcie_port));
557 +
558 +
559 + /* Port Link Control Register */
560 + reg = IFX_REG_R32(PCIE_PLCR(pcie_port));
561 + reg |= PCIE_PLCR_DLL_LINK_EN; /* Enable the DLL link */
562 + IFX_REG_W32(reg, PCIE_PLCR(pcie_port));
563 +
564 + /* Lane Skew Register */
565 + reg = IFX_REG_R32(PCIE_LSR(pcie_port));
566 + /* Enable ACK/NACK and FC */
567 + reg &= ~(PCIE_LSR_ACKNAK_DISABLE | PCIE_LSR_FC_DISABLE);
568 + IFX_REG_W32(reg, PCIE_LSR(pcie_port));
569 +
570 + /* Symbol Timer Register and Filter Mask Register 1 */
571 + reg = IFX_REG_R32(PCIE_STRFMR(pcie_port));
572 +
573 + /* Default SKP interval is very accurate already, 5us */
574 + /* Enable IO/CFG transaction */
575 + reg |= PCIE_STRFMR_RX_CFG_TRANS_ENABLE | PCIE_STRFMR_RX_IO_TRANS_ENABLE;
576 + /* Disable FC WDT */
577 + reg &= ~PCIE_STRFMR_FC_WDT_DISABLE;
578 + IFX_REG_W32(reg, PCIE_STRFMR(pcie_port));
579 +
580 + /* Filter Masker Register 2 */
581 + reg = IFX_REG_R32(PCIE_FMR2(pcie_port));
582 + reg |= PCIE_FMR2_VENDOR_MSG1_PASSED_TO_TRGT1 | PCIE_FMR2_VENDOR_MSG0_PASSED_TO_TRGT1;
583 + IFX_REG_W32(reg, PCIE_FMR2(pcie_port));
584 +
585 + /* VC0 Completion Receive Queue Control Register */
586 + reg = IFX_REG_R32(PCIE_VC0_CRQCR(pcie_port));
587 + reg &= ~PCIE_VC0_CRQCR_CPL_TLP_QUEUE_MODE;
588 + reg |= SM(PCIE_VC0_TLP_QUEUE_MODE_BYPASS, PCIE_VC0_CRQCR_CPL_TLP_QUEUE_MODE);
589 + IFX_REG_W32(reg, PCIE_VC0_CRQCR(pcie_port));
590 +}
591 +
592 +static inline void pcie_rc_cfg_reg_setup(int pcie_port)
593 +{
594 + u32 reg;
595 +
596 + /* Disable LTSSM */
597 + IFX_REG_W32(0, PCIE_RC_CCR(pcie_port)); /* Disable LTSSM */
598 +
599 + pcie_mem_io_setup(pcie_port);
600 +
601 + /* XXX, MSI stuff should only apply to EP */
602 + /* MSI Capability: Only enable 32-bit addresses */
603 + reg = IFX_REG_R32(PCIE_MCAPR(pcie_port));
604 + reg &= ~PCIE_MCAPR_ADDR64_CAP;
605 +
606 + reg |= PCIE_MCAPR_MSI_ENABLE;
607 +
608 + /* Disable multiple message */
609 + reg &= ~(PCIE_MCAPR_MULTI_MSG_CAP | PCIE_MCAPR_MULTI_MSG_ENABLE);
610 + IFX_REG_W32(reg, PCIE_MCAPR(pcie_port));
611 +
612 +
613 + /* Enable PME, Soft reset enabled */
614 + reg = IFX_REG_R32(PCIE_PM_CSR(pcie_port));
615 + reg |= PCIE_PM_CSR_PME_ENABLE | PCIE_PM_CSR_SW_RST;
616 + IFX_REG_W32(reg, PCIE_PM_CSR(pcie_port));
617 +
618 + /* setup the bus */
619 + reg = SM(0, PCIE_BNR_PRIMARY_BUS_NUM) | SM(1, PCIE_PNR_SECONDARY_BUS_NUM) | SM(0xFF, PCIE_PNR_SUB_BUS_NUM);
620 + IFX_REG_W32(reg, PCIE_BNR(pcie_port));
621 +
622 +
623 + pcie_device_setup(pcie_port);
624 + pcie_link_setup(pcie_port);
625 + pcie_error_setup(pcie_port);
626 +
627 + /* Root control and capabilities register */
628 + reg = IFX_REG_R32(PCIE_RCTLCAP(pcie_port));
629 + reg |= PCIE_RCTLCAP_SERR_ENABLE | PCIE_RCTLCAP_PME_INT_EN;
630 + IFX_REG_W32(reg, PCIE_RCTLCAP(pcie_port));
631 +
632 + /* Port VC Capability Register 2 */
633 + reg = IFX_REG_R32(PCIE_PVC2(pcie_port));
634 + reg &= ~PCIE_PVC2_VC_ARB_WRR;
635 + reg |= PCIE_PVC2_VC_ARB_16P_FIXED_WRR;
636 + IFX_REG_W32(reg, PCIE_PVC2(pcie_port));
637 +
638 + /* VC0 Resource Capability Register */
639 + reg = IFX_REG_R32(PCIE_VC0_RC(pcie_port));
640 + reg &= ~PCIE_VC0_RC_REJECT_SNOOP;
641 + IFX_REG_W32(reg, PCIE_VC0_RC(pcie_port));
642 +
643 + pcie_port_logic_setup(pcie_port);
644 +}
645 +
646 +static int ifx_pcie_wait_phy_link_up(int pcie_port)
647 +{
648 +#define IFX_PCIE_PHY_LINK_UP_TIMEOUT 1000 /* XXX, tunable */
649 + int i;
650 +
651 + /* Wait for PHY link is up */
652 + for (i = 0; i < IFX_PCIE_PHY_LINK_UP_TIMEOUT; i++) {
653 + if (ifx_pcie_link_up(pcie_port)) {
654 + break;
655 + }
656 + udelay(100);
657 + }
658 + if (i >= IFX_PCIE_PHY_LINK_UP_TIMEOUT) {
659 + printk(KERN_ERR "%s timeout\n", __func__);
660 + return -1;
661 + }
662 +
663 + /* Check data link up or not */
664 + if (!(IFX_REG_R32(PCIE_RC_DR(pcie_port)) & PCIE_RC_DR_DLL_UP)) {
665 + printk(KERN_ERR "%s DLL link is still down\n", __func__);
666 + return -1;
667 + }
668 +
669 + /* Check Data link active or not */
670 + if (!(IFX_REG_R32(PCIE_LCTLSTS(pcie_port)) & PCIE_LCTLSTS_DLL_ACTIVE)) {
671 + printk(KERN_ERR "%s DLL is not active\n", __func__);
672 + return -1;
673 + }
674 + return 0;
675 +}
676 +
677 +static inline int pcie_app_loigc_setup(int pcie_port)
678 +{
679 + /* supress ahb bus errrors */
680 + IFX_REG_W32(PCIE_AHB_CTRL_BUS_ERROR_SUPPRESS, PCIE_AHB_CTRL(pcie_port));
681 +
682 + /* Pull PCIe EP out of reset */
683 + pcie_device_rst_deassert(pcie_port);
684 +
685 + /* Start LTSSM training between RC and EP */
686 + pcie_ltssm_enable(pcie_port);
687 +
688 + /* Check PHY status after enabling LTSSM */
689 + if (ifx_pcie_wait_phy_link_up(pcie_port) != 0)
690 + return -1;
691 +
692 + return 0;
693 +}
694 +
695 +/*
696 + * The numbers below are directly from the PCIe spec table 3-4/5.
697 + */
698 +static inline void pcie_replay_time_update(int pcie_port)
699 +{
700 + u32 reg;
701 + int nlw;
702 + int rtl;
703 +
704 + reg = IFX_REG_R32(PCIE_LCTLSTS(pcie_port));
705 +
706 + nlw = MS(reg, PCIE_LCTLSTS_NEGOTIATED_LINK_WIDTH);
707 + switch (nlw) {
708 + case PCIE_MAX_LENGTH_WIDTH_X1:
709 + rtl = 1677;
710 + break;
711 + case PCIE_MAX_LENGTH_WIDTH_X2:
712 + rtl = 867;
713 + break;
714 + case PCIE_MAX_LENGTH_WIDTH_X4:
715 + rtl = 462;
716 + break;
717 + case PCIE_MAX_LENGTH_WIDTH_X8:
718 + rtl = 258;
719 + break;
720 + default:
721 + rtl = 1677;
722 + break;
723 + }
724 + reg = IFX_REG_R32(PCIE_ALTRT(pcie_port));
725 + reg &= ~PCIE_ALTRT_REPLAY_TIME_LIMIT;
726 + reg |= SM(rtl, PCIE_ALTRT_REPLAY_TIME_LIMIT);
727 + IFX_REG_W32(reg, PCIE_ALTRT(pcie_port));
728 +}
729 +
730 +/*
731 + * Table 359 Enhanced Configuration Address Mapping1)
732 + * 1) This table is defined in Table 7-1, page 341, PCI Express Base Specification v1.1
733 + * Memory Address PCI Express Configuration Space
734 + * A[(20+n-1):20] Bus Number 1 < n < 8
735 + * A[19:15] Device Number
736 + * A[14:12] Function Number
737 + * A[11:8] Extended Register Number
738 + * A[7:2] Register Number
739 + * A[1:0] Along with size of the access, used to generate Byte Enables
740 + * For VR9, only the address bits [22:0] are mapped to the configuration space:
741 + * . Address bits [22:20] select the target bus (1-of-8)1)
742 + * . Address bits [19:15] select the target device (1-of-32) on the bus
743 + * . Address bits [14:12] select the target function (1-of-8) within the device.
744 + * . Address bits [11:2] selects the target dword (1-of-1024) within the selected function.s configuration space
745 + * . Address bits [1:0] define the start byte location within the selected dword.
746 + */
747 +static inline u32 pcie_bus_addr(u8 bus_num, u16 devfn, int where)
748 +{
749 + u32 addr;
750 + u8 bus;
751 +
752 + if (!bus_num) {
753 + /* type 0 */
754 + addr = ((PCI_SLOT(devfn) & 0x1F) << 15) | ((PCI_FUNC(devfn) & 0x7) << 12) | ((where & 0xFFF)& ~3);
755 + } else {
756 + bus = bus_num;
757 + /* type 1, only support 8 buses */
758 + addr = ((bus & 0x7) << 20) | ((PCI_SLOT(devfn) & 0x1F) << 15) |
759 + ((PCI_FUNC(devfn) & 0x7) << 12) | ((where & 0xFFF) & ~3);
760 + }
761 + return addr;
762 +}
763 +
764 +static int pcie_valid_config(int pcie_port, int bus, int dev)
765 +{
766 + /* RC itself */
767 + if ((bus == 0) && (dev == 0)) {
768 + return 1;
769 + }
770 +
771 + /* No physical link */
772 + if (!ifx_pcie_link_up(pcie_port)) {
773 + return 0;
774 + }
775 +
776 + /* Bus zero only has RC itself
777 + * XXX, check if EP will be integrated
778 + */
779 + if ((bus == 0) && (dev != 0)) {
780 + return 0;
781 + }
782 +
783 + /* Maximum 8 buses supported for VRX */
784 + if (bus > 9) {
785 + return 0;
786 + }
787 +
788 + /*
789 + * PCIe is PtP link, one bus only supports only one device
790 + * except bus zero and PCIe switch which is virtual bus device
791 + * The following two conditions really depends on the system design
792 + * and attached the device.
793 + * XXX, how about more new switch
794 + */
795 + if ((bus == 1) && (dev != 0)) {
796 + return 0;
797 + }
798 +
799 + if ((bus >= 3) && (dev != 0)) {
800 + return 0;
801 + }
802 + return 1;
803 +}
804 +
805 +static inline u32 ifx_pcie_cfg_rd(int pcie_port, u32 reg)
806 +{
807 + return IFX_REG_R32((volatile u32 *)(PCIE_CFG_PORT_TO_BASE(pcie_port) + reg));
808 +}
809 +
810 +static inline void ifx_pcie_cfg_wr(int pcie_port, unsigned int reg, u32 val)
811 +{
812 + IFX_REG_W32( val, (volatile u32 *)(PCIE_CFG_PORT_TO_BASE(pcie_port) + reg));
813 +}
814 +
815 +static inline u32 ifx_pcie_rc_cfg_rd(int pcie_port, u32 reg)
816 +{
817 + return IFX_REG_R32((volatile u32 *)(PCIE_RC_PORT_TO_BASE(pcie_port) + reg));
818 +}
819 +
820 +static inline void ifx_pcie_rc_cfg_wr(int pcie_port, unsigned int reg, u32 val)
821 +{
822 + IFX_REG_W32(val, (volatile u32 *)(PCIE_RC_PORT_TO_BASE(pcie_port) + reg));
823 +}
824 +
825 +u32 ifx_pcie_bus_enum_read_hack(int where, u32 value)
826 +{
827 + u32 tvalue = value;
828 +
829 + if (where == PCI_PRIMARY_BUS) {
830 + u8 primary, secondary, subordinate;
831 +
832 + primary = tvalue & 0xFF;
833 + secondary = (tvalue >> 8) & 0xFF;
834 + subordinate = (tvalue >> 16) & 0xFF;
835 + primary += pcibios_1st_host_bus_nr();
836 + secondary += pcibios_1st_host_bus_nr();
837 + subordinate += pcibios_1st_host_bus_nr();
838 + tvalue = (tvalue & 0xFF000000) | (u32)primary | (u32)(secondary << 8) | (u32)(subordinate << 16);
839 + }
840 + return tvalue;
841 +}
842 +
843 +u32 ifx_pcie_bus_enum_write_hack(int where, u32 value)
844 +{
845 + u32 tvalue = value;
846 +
847 + if (where == PCI_PRIMARY_BUS) {
848 + u8 primary, secondary, subordinate;
849 +
850 + primary = tvalue & 0xFF;
851 + secondary = (tvalue >> 8) & 0xFF;
852 + subordinate = (tvalue >> 16) & 0xFF;
853 + if (primary > 0 && primary != 0xFF) {
854 + primary -= pcibios_1st_host_bus_nr();
855 + }
856 +
857 + if (secondary > 0 && secondary != 0xFF) {
858 + secondary -= pcibios_1st_host_bus_nr();
859 + }
860 + if (subordinate > 0 && subordinate != 0xFF) {
861 + subordinate -= pcibios_1st_host_bus_nr();
862 + }
863 + tvalue = (tvalue & 0xFF000000) | (u32)primary | (u32)(secondary << 8) | (u32)(subordinate << 16);
864 + }
865 + else if (where == PCI_SUBORDINATE_BUS) {
866 + u8 subordinate = tvalue & 0xFF;
867 +
868 + subordinate = subordinate > 0 ? subordinate - pcibios_1st_host_bus_nr() : 0;
869 + tvalue = subordinate;
870 + }
871 + return tvalue;
872 +}
873 +
874 +static int ifx_pcie_read_config(struct pci_bus *bus, u32 devfn,
875 + int where, int size, u32 *value)
876 +{
877 + u32 data = 0;
878 + int bus_number = bus->number;
879 + static const u32 mask[8] = {0, 0xff, 0xffff, 0, 0xffffffff, 0, 0, 0};
880 + int ret = PCIBIOS_SUCCESSFUL;
881 + struct ifx_pci_controller *ctrl = bus->sysdata;
882 + int pcie_port = ctrl->port;
883 +
884 + if (unlikely(size != 1 && size != 2 && size != 4)){
885 + ret = PCIBIOS_BAD_REGISTER_NUMBER;
886 + goto out;
887 + }
888 +
889 + /* Make sure the address is aligned to natural boundary */
890 + if (unlikely(((size - 1) & where))) {
891 + ret = PCIBIOS_BAD_REGISTER_NUMBER;
892 + goto out;
893 + }
894 +
895 + /*
896 + * If we are second controller, we have to cheat OS so that it assume
897 + * its bus number starts from 0 in host controller
898 + */
899 + bus_number = ifx_pcie_bus_nr_deduct(bus_number, pcie_port);
900 +
901 + /*
902 + * We need to force the bus number to be zero on the root
903 + * bus. Linux numbers the 2nd root bus to start after all
904 + * busses on root 0.
905 + */
906 + if (bus->parent == NULL) {
907 + bus_number = 0;
908 + }
909 +
910 + /*
911 + * PCIe only has a single device connected to it. It is
912 + * always device ID 0. Don't bother doing reads for other
913 + * device IDs on the first segment.
914 + */
915 + if ((bus_number == 0) && (PCI_SLOT(devfn) != 0)) {
916 + ret = PCIBIOS_FUNC_NOT_SUPPORTED;
917 + goto out;
918 + }
919 +
920 + if (pcie_valid_config(pcie_port, bus_number, PCI_SLOT(devfn)) == 0) {
921 + *value = 0xffffffff;
922 + ret = PCIBIOS_DEVICE_NOT_FOUND;
923 + goto out;
924 + }
925 +
926 + PCIE_IRQ_LOCK(ifx_pcie_lock);
927 + if (bus_number == 0) { /* RC itself */
928 + u32 t;
929 +
930 + t = (where & ~3);
931 + data = ifx_pcie_rc_cfg_rd(pcie_port, t);
932 + } else {
933 + u32 addr = pcie_bus_addr(bus_number, devfn, where);
934 +
935 + data = ifx_pcie_cfg_rd(pcie_port, addr);
936 + #ifdef CONFIG_IFX_PCIE_HW_SWAP
937 + data = le32_to_cpu(data);
938 + #endif /* CONFIG_IFX_PCIE_HW_SWAP */
939 + }
940 + /* To get a correct PCI topology, we have to restore the bus number to OS */
941 + data = ifx_pcie_bus_enum_hack(bus, devfn, where, data, pcie_port, 1);
942 +
943 + PCIE_IRQ_UNLOCK(ifx_pcie_lock);
944 +
945 + *value = (data >> (8 * (where & 3))) & mask[size & 7];
946 +out:
947 + return ret;
948 +}
949 +
950 +static u32 ifx_pcie_size_to_value(int where, int size, u32 data, u32 value)
951 +{
952 + u32 shift;
953 + u32 tdata = data;
954 +
955 + switch (size) {
956 + case 1:
957 + shift = (where & 0x3) << 3;
958 + tdata &= ~(0xffU << shift);
959 + tdata |= ((value & 0xffU) << shift);
960 + break;
961 + case 2:
962 + shift = (where & 3) << 3;
963 + tdata &= ~(0xffffU << shift);
964 + tdata |= ((value & 0xffffU) << shift);
965 + break;
966 + case 4:
967 + tdata = value;
968 + break;
969 + }
970 + return tdata;
971 +}
972 +
973 +static int ifx_pcie_write_config(struct pci_bus *bus, u32 devfn,
974 + int where, int size, u32 value)
975 +{
976 + int bus_number = bus->number;
977 + int ret = PCIBIOS_SUCCESSFUL;
978 + struct ifx_pci_controller *ctrl = bus->sysdata;
979 + int pcie_port = ctrl->port;
980 + u32 tvalue = value;
981 + u32 data;
982 +
983 + /* Make sure the address is aligned to natural boundary */
984 + if (unlikely(((size - 1) & where))) {
985 + ret = PCIBIOS_BAD_REGISTER_NUMBER;
986 + goto out;
987 + }
988 + /*
989 + * If we are second controller, we have to cheat OS so that it assume
990 + * its bus number starts from 0 in host controller
991 + */
992 + bus_number = ifx_pcie_bus_nr_deduct(bus_number, pcie_port);
993 +
994 + /*
995 + * We need to force the bus number to be zero on the root
996 + * bus. Linux numbers the 2nd root bus to start after all
997 + * busses on root 0.
998 + */
999 + if (bus->parent == NULL) {
1000 + bus_number = 0;
1001 + }
1002 +
1003 + if (pcie_valid_config(pcie_port, bus_number, PCI_SLOT(devfn)) == 0) {
1004 + ret = PCIBIOS_DEVICE_NOT_FOUND;
1005 + goto out;
1006 + }
1007 +
1008 + /* XXX, some PCIe device may need some delay */
1009 + PCIE_IRQ_LOCK(ifx_pcie_lock);
1010 +
1011 + /*
1012 + * To configure the correct bus topology using native way, we have to cheat Os so that
1013 + * it can configure the PCIe hardware correctly.
1014 + */
1015 + tvalue = ifx_pcie_bus_enum_hack(bus, devfn, where, value, pcie_port, 0);
1016 +
1017 + if (bus_number == 0) { /* RC itself */
1018 + u32 t;
1019 +
1020 + t = (where & ~3);
1021 + data = ifx_pcie_rc_cfg_rd(pcie_port, t);
1022 +
1023 + data = ifx_pcie_size_to_value(where, size, data, tvalue);
1024 +
1025 + ifx_pcie_rc_cfg_wr(pcie_port, t, data);
1026 + } else {
1027 + u32 addr = pcie_bus_addr(bus_number, devfn, where);
1028 +
1029 + data = ifx_pcie_cfg_rd(pcie_port, addr);
1030 +#ifdef CONFIG_IFX_PCIE_HW_SWAP
1031 + data = le32_to_cpu(data);
1032 +#endif
1033 +
1034 + data = ifx_pcie_size_to_value(where, size, data, tvalue);
1035 +#ifdef CONFIG_IFX_PCIE_HW_SWAP
1036 + data = cpu_to_le32(data);
1037 +#endif
1038 + ifx_pcie_cfg_wr(pcie_port, addr, data);
1039 + }
1040 + PCIE_IRQ_UNLOCK(ifx_pcie_lock);
1041 +out:
1042 + return ret;
1043 +}
1044 +
1045 +static struct resource ifx_pcie_io_resource = {
1046 + .name = "PCIe0 I/O space",
1047 + .start = PCIE_IO_PHY_BASE,
1048 + .end = PCIE_IO_PHY_END,
1049 + .flags = IORESOURCE_IO,
1050 +};
1051 +
1052 +static struct resource ifx_pcie_mem_resource = {
1053 + .name = "PCIe0 Memory space",
1054 + .start = PCIE_MEM_PHY_BASE,
1055 + .end = PCIE_MEM_PHY_END,
1056 + .flags = IORESOURCE_MEM,
1057 +};
1058 +
1059 +static struct pci_ops ifx_pcie_ops = {
1060 + .read = ifx_pcie_read_config,
1061 + .write = ifx_pcie_write_config,
1062 +};
1063 +
1064 +static struct ifx_pci_controller ifx_pcie_controller[IFX_PCIE_CORE_NR] = {
1065 + {
1066 + .pcic = {
1067 + .pci_ops = &ifx_pcie_ops,
1068 + .mem_resource = &ifx_pcie_mem_resource,
1069 + .io_resource = &ifx_pcie_io_resource,
1070 + },
1071 + .port = IFX_PCIE_PORT0,
1072 + },
1073 +};
1074 +
1075 +#ifdef IFX_PCIE_ERROR_INT
1076 +
1077 +static irqreturn_t pcie_rc_core_isr(int irq, void *dev_id)
1078 +{
1079 + struct ifx_pci_controller *ctrl = (struct ifx_pci_controller *)dev_id;
1080 + int pcie_port = ctrl->port;
1081 + u32 reg;
1082 +
1083 + pr_debug("PCIe RC error intr %d\n", irq);
1084 + reg = IFX_REG_R32(PCIE_IRNCR(pcie_port));
1085 + reg &= PCIE_RC_CORE_COMBINED_INT;
1086 + IFX_REG_W32(reg, PCIE_IRNCR(pcie_port));
1087 +
1088 + return IRQ_HANDLED;
1089 +}
1090 +
1091 +static int
1092 +pcie_rc_core_int_init(int pcie_port)
1093 +{
1094 + int ret;
1095 +
1096 + /* Enable core interrupt */
1097 + IFX_REG_SET_BIT(PCIE_RC_CORE_COMBINED_INT, PCIE_IRNEN(pcie_port));
1098 +
1099 + /* Clear it first */
1100 + IFX_REG_SET_BIT(PCIE_RC_CORE_COMBINED_INT, PCIE_IRNCR(pcie_port));
1101 + ret = request_irq(pcie_irqs[pcie_port].ir_irq.irq, pcie_rc_core_isr, 0,
1102 + pcie_irqs[pcie_port].ir_irq.name, &ifx_pcie_controller[pcie_port]);
1103 + if (ret)
1104 + printk(KERN_ERR "%s request irq %d failed\n", __func__, IFX_PCIE_IR);
1105 +
1106 + return ret;
1107 +}
1108 +#endif
1109 +
1110 +int ifx_pcie_bios_map_irq(IFX_PCI_CONST struct pci_dev *dev, u8 slot, u8 pin)
1111 +{
1112 + u32 irq_bit = 0;
1113 + int irq = 0;
1114 + struct ifx_pci_controller *ctrl = dev->bus->sysdata;
1115 + int pcie_port = ctrl->port;
1116 +
1117 + printk("%s port %d dev %s slot %d pin %d \n", __func__, pcie_port, pci_name(dev), slot, pin);
1118 +
1119 + if ((pin == PCIE_LEGACY_DISABLE) || (pin > PCIE_LEGACY_INT_MAX)) {
1120 + printk(KERN_WARNING "WARNING: dev %s: invalid interrupt pin %d\n", pci_name(dev), pin);
1121 + return -1;
1122 + }
1123 +
1124 + /* Pin index so minus one */
1125 + irq_bit = pcie_irqs[pcie_port].legacy_irq[pin - 1].irq_bit;
1126 + irq = pcie_irqs[pcie_port].legacy_irq[pin - 1].irq;
1127 + IFX_REG_SET_BIT(irq_bit, PCIE_IRNEN(pcie_port));
1128 + IFX_REG_SET_BIT(irq_bit, PCIE_IRNCR(pcie_port));
1129 + printk("%s dev %s irq %d assigned\n", __func__, pci_name(dev), irq);
1130 + return irq;
1131 +}
1132 +
1133 +int ifx_pcie_bios_plat_dev_init(struct pci_dev *dev)
1134 +{
1135 + u16 config;
1136 +#ifdef IFX_PCIE_ERROR_INT
1137 + u32 dconfig;
1138 + int pos;
1139 +#endif
1140 +
1141 + /* Enable reporting System errors and parity errors on all devices */
1142 + /* Enable parity checking and error reporting */
1143 + pci_read_config_word(dev, PCI_COMMAND, &config);
1144 + config |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR /*| PCI_COMMAND_INVALIDATE |
1145 + PCI_COMMAND_FAST_BACK*/;
1146 + pci_write_config_word(dev, PCI_COMMAND, config);
1147 +
1148 + if (dev->subordinate) {
1149 + /* Set latency timers on sub bridges */
1150 + pci_write_config_byte(dev, PCI_SEC_LATENCY_TIMER, 0x40); /* XXX, */
1151 + /* More bridge error detection */
1152 + pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &config);
1153 + config |= PCI_BRIDGE_CTL_PARITY | PCI_BRIDGE_CTL_SERR;
1154 + pci_write_config_word(dev, PCI_BRIDGE_CONTROL, config);
1155 + }
1156 +#ifdef IFX_PCIE_ERROR_INT
1157 + /* Enable the PCIe normal error reporting */
1158 + pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
1159 + if (pos) {
1160 +
1161 + /* Disable system error generation in response to error messages */
1162 + pci_read_config_word(dev, pos + PCI_EXP_RTCTL, &config);
1163 + config &= ~(PCI_EXP_RTCTL_SECEE | PCI_EXP_RTCTL_SENFEE | PCI_EXP_RTCTL_SEFEE);
1164 + pci_write_config_word(dev, pos + PCI_EXP_RTCTL, config);
1165 +
1166 + /* Clear PCIE Capability's Device Status */
1167 + pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &config);
1168 + pci_write_config_word(dev, pos + PCI_EXP_DEVSTA, config);
1169 +
1170 + /* Update Device Control */
1171 + pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &config);
1172 + /* Correctable Error Reporting */
1173 + config |= PCI_EXP_DEVCTL_CERE;
1174 + /* Non-Fatal Error Reporting */
1175 + config |= PCI_EXP_DEVCTL_NFERE;
1176 + /* Fatal Error Reporting */
1177 + config |= PCI_EXP_DEVCTL_FERE;
1178 + /* Unsupported Request */
1179 + config |= PCI_EXP_DEVCTL_URRE;
1180 + pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, config);
1181 + }
1182 +
1183 + /* Find the Advanced Error Reporting capability */
1184 + pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
1185 + if (pos) {
1186 + /* Clear Uncorrectable Error Status */
1187 + pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &dconfig);
1188 + pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, dconfig);
1189 + /* Enable reporting of all uncorrectable errors */
1190 + /* Uncorrectable Error Mask - turned on bits disable errors */
1191 + pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_MASK, 0);
1192 + /*
1193 + * Leave severity at HW default. This only controls if
1194 + * errors are reported as uncorrectable or
1195 + * correctable, not if the error is reported.
1196 + */
1197 + /* PCI_ERR_UNCOR_SEVER - Uncorrectable Error Severity */
1198 + /* Clear Correctable Error Status */
1199 + pci_read_config_dword(dev, pos + PCI_ERR_COR_STATUS, &dconfig);
1200 + pci_write_config_dword(dev, pos + PCI_ERR_COR_STATUS, dconfig);
1201 + /* Enable reporting of all correctable errors */
1202 + /* Correctable Error Mask - turned on bits disable errors */
1203 + pci_write_config_dword(dev, pos + PCI_ERR_COR_MASK, 0);
1204 + /* Advanced Error Capabilities */
1205 + pci_read_config_dword(dev, pos + PCI_ERR_CAP, &dconfig);
1206 + /* ECRC Generation Enable */
1207 + if (dconfig & PCI_ERR_CAP_ECRC_GENC) {
1208 + dconfig |= PCI_ERR_CAP_ECRC_GENE;
1209 + }
1210 + /* ECRC Check Enable */
1211 + if (dconfig & PCI_ERR_CAP_ECRC_CHKC) {
1212 + dconfig |= PCI_ERR_CAP_ECRC_CHKE;
1213 + }
1214 + pci_write_config_dword(dev, pos + PCI_ERR_CAP, dconfig);
1215 +
1216 + /* PCI_ERR_HEADER_LOG - Header Log Register (16 bytes) */
1217 + /* Enable Root Port's interrupt in response to error messages */
1218 + pci_write_config_dword(dev, pos + PCI_ERR_ROOT_COMMAND,
1219 + PCI_ERR_ROOT_CMD_COR_EN |
1220 + PCI_ERR_ROOT_CMD_NONFATAL_EN |
1221 + PCI_ERR_ROOT_CMD_FATAL_EN);
1222 + /* Clear the Root status register */
1223 + pci_read_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, &dconfig);
1224 + pci_write_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, dconfig);
1225 + }
1226 +#endif /* IFX_PCIE_ERROR_INT */
1227 + /* WAR, only 128 MRRS is supported, force all EPs to support this value */
1228 + pcie_set_readrq(dev, 128);
1229 + return 0;
1230 +}
1231 +
1232 +static int
1233 +pcie_rc_initialize(int pcie_port)
1234 +{
1235 + int i;
1236 +#define IFX_PCIE_PHY_LOOP_CNT 5
1237 +
1238 + pcie_rcu_endian_setup(pcie_port);
1239 +
1240 + pcie_ep_gpio_rst_init(pcie_port);
1241 +
1242 + /*
1243 + * XXX, PCIe elastic buffer bug will cause not to be detected. One more
1244 + * reset PCIe PHY will solve this issue
1245 + */
1246 + for (i = 0; i < IFX_PCIE_PHY_LOOP_CNT; i++) {
1247 + /* Disable PCIe PHY Analog part for sanity check */
1248 + pcie_phy_pmu_disable(pcie_port);
1249 +
1250 + pcie_phy_rst_assert(pcie_port);
1251 + pcie_phy_rst_deassert(pcie_port);
1252 +
1253 + /* Make sure PHY PLL is stable */
1254 + udelay(20);
1255 +
1256 + /* PCIe Core reset enabled, low active, sw programmed */
1257 + pcie_core_rst_assert(pcie_port);
1258 +
1259 + /* Put PCIe EP in reset status */
1260 + pcie_device_rst_assert(pcie_port);
1261 +
1262 + /* PCI PHY & Core reset disabled, high active, sw programmed */
1263 + pcie_core_rst_deassert(pcie_port);
1264 +
1265 + /* Already in a quiet state, program PLL, enable PHY, check ready bit */
1266 + pcie_phy_clock_mode_setup(pcie_port);
1267 +
1268 + /* Enable PCIe PHY and Clock */
1269 + pcie_core_pmu_setup(pcie_port);
1270 +
1271 + /* Clear status registers */
1272 + pcie_status_register_clear(pcie_port);
1273 +
1274 +#ifdef CONFIG_PCI_MSI
1275 + pcie_msi_init(pcie_port);
1276 +#endif /* CONFIG_PCI_MSI */
1277 + pcie_rc_cfg_reg_setup(pcie_port);
1278 +
1279 + /* Once link is up, break out */
1280 + if (pcie_app_loigc_setup(pcie_port) == 0)
1281 + break;
1282 + }
1283 + if (i >= IFX_PCIE_PHY_LOOP_CNT) {
1284 + printk(KERN_ERR "%s link up failed!!!!!\n", __func__);
1285 + return -EIO;
1286 + }
1287 + /* NB, don't increase ACK/NACK timer timeout value, which will cause a lot of COR errors */
1288 + pcie_replay_time_update(pcie_port);
1289 + return 0;
1290 +}
1291 +
1292 +static int __init ifx_pcie_bios_init(void)
1293 +{
1294 + void __iomem *io_map_base;
1295 + int pcie_port;
1296 + int startup_port;
1297 +
1298 + /* Enable AHB Master/ Slave */
1299 + pcie_ahb_pmu_setup();
1300 +
1301 + startup_port = IFX_PCIE_PORT0;
1302 +
1303 + for (pcie_port = startup_port; pcie_port < IFX_PCIE_CORE_NR; pcie_port++){
1304 + if (pcie_rc_initialize(pcie_port) == 0) {
1305 + IFX_PCIE_PRINT(PCIE_MSG_INIT, "%s: ifx_pcie_cfg_base 0x%p\n",
1306 + __func__, PCIE_CFG_PORT_TO_BASE(pcie_port));
1307 + /* Otherwise, warning will pop up */
1308 + io_map_base = ioremap(PCIE_IO_PHY_PORT_TO_BASE(pcie_port), PCIE_IO_SIZE);
1309 + if (io_map_base == NULL) {
1310 + IFX_PCIE_PRINT(PCIE_MSG_ERR, "%s io space ioremap failed\n", __func__);
1311 + return -ENOMEM;
1312 + }
1313 + ifx_pcie_controller[pcie_port].pcic.io_map_base = (unsigned long)io_map_base;
1314 +
1315 + register_pci_controller(&ifx_pcie_controller[pcie_port].pcic);
1316 + /* XXX, clear error status */
1317 +
1318 + IFX_PCIE_PRINT(PCIE_MSG_INIT, "%s: mem_resource 0x%p, io_resource 0x%p\n",
1319 + __func__, &ifx_pcie_controller[pcie_port].pcic.mem_resource,
1320 + &ifx_pcie_controller[pcie_port].pcic.io_resource);
1321 +
1322 + #ifdef IFX_PCIE_ERROR_INT
1323 + pcie_rc_core_int_init(pcie_port);
1324 + #endif /* IFX_PCIE_ERROR_INT */
1325 + }
1326 + }
1327 +
1328 + return 0;
1329 +}
1330 +arch_initcall(ifx_pcie_bios_init);
1331 +
1332 +MODULE_LICENSE("GPL");
1333 +MODULE_AUTHOR("Chuanhua.Lei@infineon.com");
1334 +MODULE_SUPPORTED_DEVICE("Infineon builtin PCIe RC module");
1335 +MODULE_DESCRIPTION("Infineon builtin PCIe RC driver");
1336 +
1337 --- /dev/null
1338 +++ b/arch/mips/pci/ifxmips_pcie.h
1339 @@ -0,0 +1,131 @@
1340 +/******************************************************************************
1341 +**
1342 +** FILE NAME : ifxmips_pcie.h
1343 +** PROJECT : IFX UEIP for VRX200
1344 +** MODULES : PCIe module
1345 +**
1346 +** DATE : 02 Mar 2009
1347 +** AUTHOR : Lei Chuanhua
1348 +** DESCRIPTION : PCIe Root Complex Driver
1349 +** COPYRIGHT : Copyright (c) 2009
1350 +** Infineon Technologies AG
1351 +** Am Campeon 1-12, 85579 Neubiberg, Germany
1352 +**
1353 +** This program is free software; you can redistribute it and/or modify
1354 +** it under the terms of the GNU General Public License as published by
1355 +** the Free Software Foundation; either version 2 of the License, or
1356 +** (at your option) any later version.
1357 +** HISTORY
1358 +** $Version $Date $Author $Comment
1359 +** 0.0.1 17 Mar,2009 Lei Chuanhua Initial version
1360 +*******************************************************************************/
1361 +#ifndef IFXMIPS_PCIE_H
1362 +#define IFXMIPS_PCIE_H
1363 +#include <linux/version.h>
1364 +#include <linux/types.h>
1365 +#include <linux/pci.h>
1366 +#include <linux/interrupt.h>
1367 +#include "ifxmips_pci_common.h"
1368 +#include "ifxmips_pcie_reg.h"
1369 +
1370 +/*!
1371 + \defgroup IFX_PCIE PCI Express bus driver module
1372 + \brief PCI Express IP module support VRX200
1373 +*/
1374 +
1375 +/*!
1376 + \defgroup IFX_PCIE_OS OS APIs
1377 + \ingroup IFX_PCIE
1378 + \brief PCIe bus driver OS interface functions
1379 +*/
1380 +
1381 +/*!
1382 + \file ifxmips_pcie.h
1383 + \ingroup IFX_PCIE
1384 + \brief header file for PCIe module common header file
1385 +*/
1386 +#define PCIE_IRQ_LOCK(lock) do { \
1387 + unsigned long flags; \
1388 + spin_lock_irqsave(&(lock), flags);
1389 +#define PCIE_IRQ_UNLOCK(lock) \
1390 + spin_unlock_irqrestore(&(lock), flags); \
1391 +} while (0)
1392 +
1393 +#define PCIE_MSG_MSI 0x00000001
1394 +#define PCIE_MSG_ISR 0x00000002
1395 +#define PCIE_MSG_FIXUP 0x00000004
1396 +#define PCIE_MSG_READ_CFG 0x00000008
1397 +#define PCIE_MSG_WRITE_CFG 0x00000010
1398 +#define PCIE_MSG_CFG (PCIE_MSG_READ_CFG | PCIE_MSG_WRITE_CFG)
1399 +#define PCIE_MSG_REG 0x00000020
1400 +#define PCIE_MSG_INIT 0x00000040
1401 +#define PCIE_MSG_ERR 0x00000080
1402 +#define PCIE_MSG_PHY 0x00000100
1403 +#define PCIE_MSG_ANY 0x000001ff
1404 +
1405 +#define IFX_PCIE_PORT0 0
1406 +#define IFX_PCIE_PORT1 1
1407 +
1408 +#ifdef CONFIG_IFX_PCIE_2ND_CORE
1409 +#define IFX_PCIE_CORE_NR 2
1410 +#else
1411 +#define IFX_PCIE_CORE_NR 1
1412 +#endif
1413 +
1414 +#define IFX_PCIE_ERROR_INT
1415 +
1416 +//#define IFX_PCIE_DBG
1417 +
1418 +#if defined(IFX_PCIE_DBG)
1419 +#define IFX_PCIE_PRINT(_m, _fmt, args...) do { \
1420 + ifx_pcie_debug((_fmt), ##args); \
1421 +} while (0)
1422 +
1423 +#define INLINE
1424 +#else
1425 +#define IFX_PCIE_PRINT(_m, _fmt, args...) \
1426 + do {} while(0)
1427 +#define INLINE inline
1428 +#endif
1429 +
1430 +struct ifx_pci_controller {
1431 + struct pci_controller pcic;
1432 +
1433 + /* RC specific, per host bus information */
1434 + u32 port; /* Port index, 0 -- 1st core, 1 -- 2nd core */
1435 +};
1436 +
1437 +typedef struct ifx_pcie_ir_irq {
1438 + const unsigned int irq;
1439 + const char name[16];
1440 +}ifx_pcie_ir_irq_t;
1441 +
1442 +typedef struct ifx_pcie_legacy_irq{
1443 + const u32 irq_bit;
1444 + const int irq;
1445 +}ifx_pcie_legacy_irq_t;
1446 +
1447 +typedef struct ifx_pcie_irq {
1448 + ifx_pcie_ir_irq_t ir_irq;
1449 + ifx_pcie_legacy_irq_t legacy_irq[PCIE_LEGACY_INT_MAX];
1450 +}ifx_pcie_irq_t;
1451 +
1452 +extern u32 g_pcie_debug_flag;
1453 +extern void ifx_pcie_debug(const char *fmt, ...);
1454 +extern void pcie_phy_clock_mode_setup(int pcie_port);
1455 +extern void pcie_msi_pic_init(int pcie_port);
1456 +extern u32 ifx_pcie_bus_enum_read_hack(int where, u32 value);
1457 +extern u32 ifx_pcie_bus_enum_write_hack(int where, u32 value);
1458 +
1459 +#define CONFIG_VR9
1460 +
1461 +#ifdef CONFIG_VR9
1462 +#include "ifxmips_pcie_vr9.h"
1463 +#elif defined (CONFIG_AR10)
1464 +#include "ifxmips_pcie_ar10.h"
1465 +#else
1466 +#error "PCIE: platform not defined"
1467 +#endif /* CONFIG_VR9 */
1468 +
1469 +#endif /* IFXMIPS_PCIE_H */
1470 +
1471 --- /dev/null
1472 +++ b/arch/mips/pci/ifxmips_pcie_ar10.h
1473 @@ -0,0 +1,290 @@
1474 +/****************************************************************************
1475 + Copyright (c) 2010
1476 + Lantiq Deutschland GmbH
1477 + Am Campeon 3; 85579 Neubiberg, Germany
1478 +
1479 + For licensing information, see the file 'LICENSE' in the root folder of
1480 + this software module.
1481 +
1482 + *****************************************************************************/
1483 +/*!
1484 + \file ifxmips_pcie_ar10.h
1485 + \ingroup IFX_PCIE
1486 + \brief PCIe RC driver ar10 specific file
1487 +*/
1488 +
1489 +#ifndef IFXMIPS_PCIE_AR10_H
1490 +#define IFXMIPS_PCIE_AR10_H
1491 +#ifndef AUTOCONF_INCLUDED
1492 +#include <linux/config.h>
1493 +#endif /* AUTOCONF_INCLUDED */
1494 +#include <linux/types.h>
1495 +#include <linux/delay.h>
1496 +
1497 +/* Project header file */
1498 +#include <asm/ifx/ifx_types.h>
1499 +#include <asm/ifx/ifx_pmu.h>
1500 +#include <asm/ifx/ifx_gpio.h>
1501 +#include <asm/ifx/ifx_ebu_led.h>
1502 +
1503 +static inline void pcie_ep_gpio_rst_init(int pcie_port)
1504 +{
1505 + ifx_ebu_led_enable();
1506 + if (pcie_port == 0) {
1507 + ifx_ebu_led_set_data(11, 1);
1508 + }
1509 + else {
1510 + ifx_ebu_led_set_data(12, 1);
1511 + }
1512 +}
1513 +
1514 +static inline void pcie_ahb_pmu_setup(void)
1515 +{
1516 + /* XXX, moved to CGU to control AHBM */
1517 +}
1518 +
1519 +static inline void pcie_rcu_endian_setup(int pcie_port)
1520 +{
1521 + u32 reg;
1522 +
1523 + reg = IFX_REG_R32(IFX_RCU_AHB_ENDIAN);
1524 + /* Inbound, big endian */
1525 + reg |= IFX_RCU_BE_AHB4S;
1526 + if (pcie_port == 0) {
1527 + reg |= IFX_RCU_BE_PCIE0M;
1528 +
1529 + #ifdef CONFIG_IFX_PCIE_HW_SWAP
1530 + /* Outbound, software swap needed */
1531 + reg |= IFX_RCU_BE_AHB3M;
1532 + reg &= ~IFX_RCU_BE_PCIE0S;
1533 + #else
1534 + /* Outbound little endian */
1535 + reg &= ~IFX_RCU_BE_AHB3M;
1536 + reg &= ~IFX_RCU_BE_PCIE0S;
1537 + #endif
1538 + }
1539 + else {
1540 + reg |= IFX_RCU_BE_PCIE1M;
1541 + #ifdef CONFIG_IFX_PCIE1_HW_SWAP
1542 + /* Outbound, software swap needed */
1543 + reg |= IFX_RCU_BE_AHB3M;
1544 + reg &= ~IFX_RCU_BE_PCIE1S;
1545 + #else
1546 + /* Outbound little endian */
1547 + reg &= ~IFX_RCU_BE_AHB3M;
1548 + reg &= ~IFX_RCU_BE_PCIE1S;
1549 + #endif
1550 + }
1551 +
1552 + IFX_REG_W32(reg, IFX_RCU_AHB_ENDIAN);
1553 + IFX_PCIE_PRINT(PCIE_MSG_REG, "%s IFX_RCU_AHB_ENDIAN: 0x%08x\n", __func__, IFX_REG_R32(IFX_RCU_AHB_ENDIAN));
1554 +}
1555 +
1556 +static inline void pcie_phy_pmu_enable(int pcie_port)
1557 +{
1558 + if (pcie_port == 0) { /* XXX, should use macro*/
1559 + PCIE0_PHY_PMU_SETUP(IFX_PMU_ENABLE);
1560 + }
1561 + else {
1562 + PCIE1_PHY_PMU_SETUP(IFX_PMU_ENABLE);
1563 + }
1564 +}
1565 +
1566 +static inline void pcie_phy_pmu_disable(int pcie_port)
1567 +{
1568 + if (pcie_port == 0) { /* XXX, should use macro*/
1569 + PCIE0_PHY_PMU_SETUP(IFX_PMU_DISABLE);
1570 + }
1571 + else {
1572 + PCIE1_PHY_PMU_SETUP(IFX_PMU_DISABLE);
1573 + }
1574 +}
1575 +
1576 +static inline void pcie_pdi_big_endian(int pcie_port)
1577 +{
1578 + u32 reg;
1579 +
1580 + reg = IFX_REG_R32(IFX_RCU_AHB_ENDIAN);
1581 + if (pcie_port == 0) {
1582 + /* Config AHB->PCIe and PDI endianness */
1583 + reg |= IFX_RCU_BE_PCIE0_PDI;
1584 + }
1585 + else {
1586 + /* Config AHB->PCIe and PDI endianness */
1587 + reg |= IFX_RCU_BE_PCIE1_PDI;
1588 + }
1589 + IFX_REG_W32(reg, IFX_RCU_AHB_ENDIAN);
1590 +}
1591 +
1592 +static inline void pcie_pdi_pmu_enable(int pcie_port)
1593 +{
1594 + if (pcie_port == 0) {
1595 + /* Enable PDI to access PCIe PHY register */
1596 + PDI0_PMU_SETUP(IFX_PMU_ENABLE);
1597 + }
1598 + else {
1599 + PDI1_PMU_SETUP(IFX_PMU_ENABLE);
1600 + }
1601 +}
1602 +
1603 +static inline void pcie_core_rst_assert(int pcie_port)
1604 +{
1605 + u32 reg;
1606 +
1607 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
1608 +
1609 + /* Reset Core, bit 22 */
1610 + if (pcie_port == 0) {
1611 + reg |= 0x00400000;
1612 + }
1613 + else {
1614 + reg |= 0x08000000; /* Bit 27 */
1615 + }
1616 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
1617 +}
1618 +
1619 +static inline void pcie_core_rst_deassert(int pcie_port)
1620 +{
1621 + u32 reg;
1622 +
1623 + /* Make sure one micro-second delay */
1624 + udelay(1);
1625 +
1626 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
1627 + if (pcie_port == 0) {
1628 + reg &= ~0x00400000; /* bit 22 */
1629 + }
1630 + else {
1631 + reg &= ~0x08000000; /* Bit 27 */
1632 + }
1633 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
1634 +}
1635 +
1636 +static inline void pcie_phy_rst_assert(int pcie_port)
1637 +{
1638 + u32 reg;
1639 +
1640 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
1641 + if (pcie_port == 0) {
1642 + reg |= 0x00001000; /* Bit 12 */
1643 + }
1644 + else {
1645 + reg |= 0x00002000; /* Bit 13 */
1646 + }
1647 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
1648 +}
1649 +
1650 +static inline void pcie_phy_rst_deassert(int pcie_port)
1651 +{
1652 + u32 reg;
1653 +
1654 + /* Make sure one micro-second delay */
1655 + udelay(1);
1656 +
1657 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
1658 + if (pcie_port == 0) {
1659 + reg &= ~0x00001000; /* Bit 12 */
1660 + }
1661 + else {
1662 + reg &= ~0x00002000; /* Bit 13 */
1663 + }
1664 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
1665 +}
1666 +
1667 +static inline void pcie_device_rst_assert(int pcie_port)
1668 +{
1669 + if (pcie_port == 0) {
1670 + ifx_ebu_led_set_data(11, 0);
1671 + }
1672 + else {
1673 + ifx_ebu_led_set_data(12, 0);
1674 + }
1675 +}
1676 +
1677 +static inline void pcie_device_rst_deassert(int pcie_port)
1678 +{
1679 + mdelay(100);
1680 + if (pcie_port == 0) {
1681 + ifx_ebu_led_set_data(11, 1);
1682 + }
1683 + else {
1684 + ifx_ebu_led_set_data(12, 1);
1685 + }
1686 + ifx_ebu_led_disable();
1687 +}
1688 +
1689 +static inline void pcie_core_pmu_setup(int pcie_port)
1690 +{
1691 + if (pcie_port == 0) {
1692 + PCIE0_CTRL_PMU_SETUP(IFX_PMU_ENABLE);
1693 + }
1694 + else {
1695 + PCIE1_CTRL_PMU_SETUP(IFX_PMU_ENABLE);
1696 + }
1697 +}
1698 +
1699 +static inline void pcie_msi_init(int pcie_port)
1700 +{
1701 + pcie_msi_pic_init(pcie_port);
1702 + if (pcie_port == 0) {
1703 + MSI0_PMU_SETUP(IFX_PMU_ENABLE);
1704 + }
1705 + else {
1706 + MSI1_PMU_SETUP(IFX_PMU_ENABLE);
1707 + }
1708 +}
1709 +
1710 +static inline u32
1711 +ifx_pcie_bus_nr_deduct(u32 bus_number, int pcie_port)
1712 +{
1713 + u32 tbus_number = bus_number;
1714 +
1715 +#ifdef CONFIG_IFX_PCIE_2ND_CORE
1716 + if (pcie_port == IFX_PCIE_PORT1) { /* Port 1 must check if there are two cores enabled */
1717 + if (pcibios_host_nr() > 1) {
1718 + tbus_number -= pcibios_1st_host_bus_nr();
1719 + }
1720 + }
1721 +#endif /* CONFIG_IFX_PCI */
1722 + return tbus_number;
1723 +}
1724 +
1725 +static inline u32
1726 +ifx_pcie_bus_enum_hack(struct pci_bus *bus, u32 devfn, int where, u32 value, int pcie_port, int read)
1727 +{
1728 + struct pci_dev *pdev;
1729 + u32 tvalue = value;
1730 +
1731 + /* Sanity check */
1732 + pdev = pci_get_slot(bus, devfn);
1733 + if (pdev == NULL) {
1734 + return tvalue;
1735 + }
1736 +
1737 + /* Only care about PCI bridge */
1738 + if (pdev->hdr_type != PCI_HEADER_TYPE_BRIDGE) {
1739 + return tvalue;
1740 + }
1741 +
1742 + if (read) { /* Read hack */
1743 + #ifdef CONFIG_IFX_PCIE_2ND_CORE
1744 + if (pcie_port == IFX_PCIE_PORT1) { /* Port 1 must check if there are two cores enabled */
1745 + if (pcibios_host_nr() > 1) {
1746 + tvalue = ifx_pcie_bus_enum_read_hack(where, tvalue);
1747 + }
1748 + }
1749 + #endif /* CONFIG_IFX_PCIE_2ND_CORE */
1750 + }
1751 + else { /* Write hack */
1752 + #ifdef CONFIG_IFX_PCIE_2ND_CORE
1753 + if (pcie_port == IFX_PCIE_PORT1) { /* Port 1 must check if there are two cores enabled */
1754 + if (pcibios_host_nr() > 1) {
1755 + tvalue = ifx_pcie_bus_enum_write_hack(where, tvalue);
1756 + }
1757 + }
1758 + #endif
1759 + }
1760 + return tvalue;
1761 +}
1762 +
1763 +#endif /* IFXMIPS_PCIE_AR10_H */
1764 --- /dev/null
1765 +++ b/arch/mips/pci/ifxmips_pcie_msi.c
1766 @@ -0,0 +1,392 @@
1767 +/******************************************************************************
1768 +**
1769 +** FILE NAME : ifxmips_pcie_msi.c
1770 +** PROJECT : IFX UEIP for VRX200
1771 +** MODULES : PCI MSI sub module
1772 +**
1773 +** DATE : 02 Mar 2009
1774 +** AUTHOR : Lei Chuanhua
1775 +** DESCRIPTION : PCIe MSI Driver
1776 +** COPYRIGHT : Copyright (c) 2009
1777 +** Infineon Technologies AG
1778 +** Am Campeon 1-12, 85579 Neubiberg, Germany
1779 +**
1780 +** This program is free software; you can redistribute it and/or modify
1781 +** it under the terms of the GNU General Public License as published by
1782 +** the Free Software Foundation; either version 2 of the License, or
1783 +** (at your option) any later version.
1784 +** HISTORY
1785 +** $Date $Author $Comment
1786 +** 02 Mar,2009 Lei Chuanhua Initial version
1787 +*******************************************************************************/
1788 +/*!
1789 + \defgroup IFX_PCIE_MSI MSI OS APIs
1790 + \ingroup IFX_PCIE
1791 + \brief PCIe bus driver OS interface functions
1792 +*/
1793 +
1794 +/*!
1795 + \file ifxmips_pcie_msi.c
1796 + \ingroup IFX_PCIE
1797 + \brief PCIe MSI OS interface file
1798 +*/
1799 +
1800 +#ifndef AUTOCONF_INCLUDED
1801 +#include <linux/config.h>
1802 +#endif /* AUTOCONF_INCLUDED */
1803 +#include <linux/init.h>
1804 +#include <linux/sched.h>
1805 +#include <linux/slab.h>
1806 +#include <linux/interrupt.h>
1807 +#include <linux/kernel_stat.h>
1808 +#include <linux/pci.h>
1809 +#include <linux/msi.h>
1810 +#include <linux/module.h>
1811 +#include <asm/bootinfo.h>
1812 +#include <asm/irq.h>
1813 +#include <asm/traps.h>
1814 +
1815 +#include <asm/ifx/ifx_types.h>
1816 +#include <asm/ifx/ifx_regs.h>
1817 +#include <asm/ifx/common_routines.h>
1818 +#include <asm/ifx/irq.h>
1819 +
1820 +#include "ifxmips_pcie_reg.h"
1821 +#include "ifxmips_pcie.h"
1822 +
1823 +#define IFX_MSI_IRQ_NUM 16
1824 +
1825 +enum {
1826 + IFX_PCIE_MSI_IDX0 = 0,
1827 + IFX_PCIE_MSI_IDX1,
1828 + IFX_PCIE_MSI_IDX2,
1829 + IFX_PCIE_MSI_IDX3,
1830 +};
1831 +
1832 +typedef struct ifx_msi_irq_idx {
1833 + const int irq;
1834 + const int idx;
1835 +}ifx_msi_irq_idx_t;
1836 +
1837 +struct ifx_msi_pic {
1838 + volatile u32 pic_table[IFX_MSI_IRQ_NUM];
1839 + volatile u32 pic_endian; /* 0x40 */
1840 +};
1841 +typedef struct ifx_msi_pic *ifx_msi_pic_t;
1842 +
1843 +typedef struct ifx_msi_irq {
1844 + const volatile ifx_msi_pic_t msi_pic_p;
1845 + const u32 msi_phy_base;
1846 + const ifx_msi_irq_idx_t msi_irq_idx[IFX_MSI_IRQ_NUM];
1847 + /*
1848 + * Each bit in msi_free_irq_bitmask represents a MSI interrupt that is
1849 + * in use.
1850 + */
1851 + u16 msi_free_irq_bitmask;
1852 +
1853 + /*
1854 + * Each bit in msi_multiple_irq_bitmask tells that the device using
1855 + * this bit in msi_free_irq_bitmask is also using the next bit. This
1856 + * is used so we can disable all of the MSI interrupts when a device
1857 + * uses multiple.
1858 + */
1859 + u16 msi_multiple_irq_bitmask;
1860 +}ifx_msi_irq_t;
1861 +
1862 +static ifx_msi_irq_t msi_irqs[IFX_PCIE_CORE_NR] = {
1863 + {
1864 + .msi_pic_p = (const volatile ifx_msi_pic_t)IFX_MSI_PIC_REG_BASE,
1865 + .msi_phy_base = PCIE_MSI_PHY_BASE,
1866 + .msi_irq_idx = {
1867 + {IFX_PCIE_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE_MSI_IR1, IFX_PCIE_MSI_IDX1},
1868 + {IFX_PCIE_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE_MSI_IR3, IFX_PCIE_MSI_IDX3},
1869 + {IFX_PCIE_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE_MSI_IR1, IFX_PCIE_MSI_IDX1},
1870 + {IFX_PCIE_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE_MSI_IR3, IFX_PCIE_MSI_IDX3},
1871 + {IFX_PCIE_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE_MSI_IR1, IFX_PCIE_MSI_IDX1},
1872 + {IFX_PCIE_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE_MSI_IR3, IFX_PCIE_MSI_IDX3},
1873 + {IFX_PCIE_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE_MSI_IR1, IFX_PCIE_MSI_IDX1},
1874 + {IFX_PCIE_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE_MSI_IR3, IFX_PCIE_MSI_IDX3},
1875 + },
1876 + .msi_free_irq_bitmask = 0,
1877 + .msi_multiple_irq_bitmask= 0,
1878 + },
1879 +#ifdef CONFIG_IFX_PCIE_2ND_CORE
1880 + {
1881 + .msi_pic_p = (const volatile ifx_msi_pic_t)IFX_MSI1_PIC_REG_BASE,
1882 + .msi_phy_base = PCIE1_MSI_PHY_BASE,
1883 + .msi_irq_idx = {
1884 + {IFX_PCIE1_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE1_MSI_IR1, IFX_PCIE_MSI_IDX1},
1885 + {IFX_PCIE1_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE1_MSI_IR3, IFX_PCIE_MSI_IDX3},
1886 + {IFX_PCIE1_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE1_MSI_IR1, IFX_PCIE_MSI_IDX1},
1887 + {IFX_PCIE1_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE1_MSI_IR3, IFX_PCIE_MSI_IDX3},
1888 + {IFX_PCIE1_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE1_MSI_IR1, IFX_PCIE_MSI_IDX1},
1889 + {IFX_PCIE1_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE1_MSI_IR3, IFX_PCIE_MSI_IDX3},
1890 + {IFX_PCIE1_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE1_MSI_IR1, IFX_PCIE_MSI_IDX1},
1891 + {IFX_PCIE1_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE1_MSI_IR3, IFX_PCIE_MSI_IDX3},
1892 + },
1893 + .msi_free_irq_bitmask = 0,
1894 + .msi_multiple_irq_bitmask= 0,
1895 +
1896 + },
1897 +#endif /* CONFIG_IFX_PCIE_2ND_CORE */
1898 +};
1899 +
1900 +/*
1901 + * This lock controls updates to msi_free_irq_bitmask,
1902 + * msi_multiple_irq_bitmask and pic register settting
1903 + */
1904 +static DEFINE_SPINLOCK(ifx_pcie_msi_lock);
1905 +
1906 +void pcie_msi_pic_init(int pcie_port)
1907 +{
1908 + spin_lock(&ifx_pcie_msi_lock);
1909 + msi_irqs[pcie_port].msi_pic_p->pic_endian = IFX_MSI_PIC_BIG_ENDIAN;
1910 + spin_unlock(&ifx_pcie_msi_lock);
1911 +}
1912 +
1913 +/**
1914 + * \fn int arch_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *desc)
1915 + * \brief Called when a driver request MSI interrupts instead of the
1916 + * legacy INT A-D. This routine will allocate multiple interrupts
1917 + * for MSI devices that support them. A device can override this by
1918 + * programming the MSI control bits [6:4] before calling
1919 + * pci_enable_msi().
1920 + *
1921 + * \param[in] pdev Device requesting MSI interrupts
1922 + * \param[in] desc MSI descriptor
1923 + *
1924 + * \return -EINVAL Invalid pcie root port or invalid msi bit
1925 + * \return 0 OK
1926 + * \ingroup IFX_PCIE_MSI
1927 + */
1928 +int
1929 +arch_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *desc)
1930 +{
1931 + int irq, pos;
1932 + u16 control;
1933 + int irq_idx;
1934 + int irq_step;
1935 + int configured_private_bits;
1936 + int request_private_bits;
1937 + struct msi_msg msg;
1938 + u16 search_mask;
1939 + struct ifx_pci_controller *ctrl = pdev->bus->sysdata;
1940 + int pcie_port = ctrl->port;
1941 +
1942 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "%s %s enter\n", __func__, pci_name(pdev));
1943 +
1944 + /* XXX, skip RC MSI itself */
1945 + if (pdev->pcie_type == PCI_EXP_TYPE_ROOT_PORT) {
1946 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "%s RC itself doesn't use MSI interrupt\n", __func__);
1947 + return -EINVAL;
1948 + }
1949 +
1950 + /*
1951 + * Read the MSI config to figure out how many IRQs this device
1952 + * wants. Most devices only want 1, which will give
1953 + * configured_private_bits and request_private_bits equal 0.
1954 + */
1955 + pci_read_config_word(pdev, desc->msi_attrib.pos + PCI_MSI_FLAGS, &control);
1956 +
1957 + /*
1958 + * If the number of private bits has been configured then use
1959 + * that value instead of the requested number. This gives the
1960 + * driver the chance to override the number of interrupts
1961 + * before calling pci_enable_msi().
1962 + */
1963 + configured_private_bits = (control & PCI_MSI_FLAGS_QSIZE) >> 4;
1964 + if (configured_private_bits == 0) {
1965 + /* Nothing is configured, so use the hardware requested size */
1966 + request_private_bits = (control & PCI_MSI_FLAGS_QMASK) >> 1;
1967 + }
1968 + else {
1969 + /*
1970 + * Use the number of configured bits, assuming the
1971 + * driver wanted to override the hardware request
1972 + * value.
1973 + */
1974 + request_private_bits = configured_private_bits;
1975 + }
1976 +
1977 + /*
1978 + * The PCI 2.3 spec mandates that there are at most 32
1979 + * interrupts. If this device asks for more, only give it one.
1980 + */
1981 + if (request_private_bits > 5) {
1982 + request_private_bits = 0;
1983 + }
1984 +again:
1985 + /*
1986 + * The IRQs have to be aligned on a power of two based on the
1987 + * number being requested.
1988 + */
1989 + irq_step = (1 << request_private_bits);
1990 +
1991 + /* Mask with one bit for each IRQ */
1992 + search_mask = (1 << irq_step) - 1;
1993 +
1994 + /*
1995 + * We're going to search msi_free_irq_bitmask_lock for zero
1996 + * bits. This represents an MSI interrupt number that isn't in
1997 + * use.
1998 + */
1999 + spin_lock(&ifx_pcie_msi_lock);
2000 + for (pos = 0; pos < IFX_MSI_IRQ_NUM; pos += irq_step) {
2001 + if ((msi_irqs[pcie_port].msi_free_irq_bitmask & (search_mask << pos)) == 0) {
2002 + msi_irqs[pcie_port].msi_free_irq_bitmask |= search_mask << pos;
2003 + msi_irqs[pcie_port].msi_multiple_irq_bitmask |= (search_mask >> 1) << pos;
2004 + break;
2005 + }
2006 + }
2007 + spin_unlock(&ifx_pcie_msi_lock);
2008 +
2009 + /* Make sure the search for available interrupts didn't fail */
2010 + if (pos >= IFX_MSI_IRQ_NUM) {
2011 + if (request_private_bits) {
2012 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "%s: Unable to find %d free "
2013 + "interrupts, trying just one", __func__, 1 << request_private_bits);
2014 + request_private_bits = 0;
2015 + goto again;
2016 + }
2017 + else {
2018 + printk(KERN_ERR "%s: Unable to find a free MSI interrupt\n", __func__);
2019 + return -EINVAL;
2020 + }
2021 + }
2022 + irq = msi_irqs[pcie_port].msi_irq_idx[pos].irq;
2023 + irq_idx = msi_irqs[pcie_port].msi_irq_idx[pos].idx;
2024 +
2025 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "pos %d, irq %d irq_idx %d\n", pos, irq, irq_idx);
2026 +
2027 + /*
2028 + * Initialize MSI. This has to match the memory-write endianess from the device
2029 + * Address bits [23:12]
2030 + */
2031 + spin_lock(&ifx_pcie_msi_lock);
2032 + msi_irqs[pcie_port].msi_pic_p->pic_table[pos] = SM(irq_idx, IFX_MSI_PIC_INT_LINE) |
2033 + SM((msi_irqs[pcie_port].msi_phy_base >> 12), IFX_MSI_PIC_MSG_ADDR) |
2034 + SM((1 << pos), IFX_MSI_PIC_MSG_DATA);
2035 +
2036 + /* Enable this entry */
2037 + msi_irqs[pcie_port].msi_pic_p->pic_table[pos] &= ~IFX_MSI_PCI_INT_DISABLE;
2038 + spin_unlock(&ifx_pcie_msi_lock);
2039 +
2040 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "pic_table[%d]: 0x%08x\n",
2041 + pos, msi_irqs[pcie_port].msi_pic_p->pic_table[pos]);
2042 +
2043 + /* Update the number of IRQs the device has available to it */
2044 + control &= ~PCI_MSI_FLAGS_QSIZE;
2045 + control |= (request_private_bits << 4);
2046 + pci_write_config_word(pdev, desc->msi_attrib.pos + PCI_MSI_FLAGS, control);
2047 +
2048 + set_irq_msi(irq, desc);
2049 + msg.address_hi = 0x0;
2050 + msg.address_lo = msi_irqs[pcie_port].msi_phy_base;
2051 + msg.data = SM((1 << pos), IFX_MSI_PIC_MSG_DATA);
2052 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "msi_data: pos %d 0x%08x\n", pos, msg.data);
2053 +
2054 + write_msi_msg(irq, &msg);
2055 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "%s exit\n", __func__);
2056 + return 0;
2057 +}
2058 +
2059 +static int
2060 +pcie_msi_irq_to_port(unsigned int irq, int *port)
2061 +{
2062 + int ret = 0;
2063 +
2064 + if (irq == IFX_PCIE_MSI_IR0 || irq == IFX_PCIE_MSI_IR1 ||
2065 + irq == IFX_PCIE_MSI_IR2 || irq == IFX_PCIE_MSI_IR3) {
2066 + *port = IFX_PCIE_PORT0;
2067 + }
2068 +#ifdef CONFIG_IFX_PCIE_2ND_CORE
2069 + else if (irq == IFX_PCIE1_MSI_IR0 || irq == IFX_PCIE1_MSI_IR1 ||
2070 + irq == IFX_PCIE1_MSI_IR2 || irq == IFX_PCIE1_MSI_IR3) {
2071 + *port = IFX_PCIE_PORT1;
2072 + }
2073 +#endif /* CONFIG_IFX_PCIE_2ND_CORE */
2074 + else {
2075 + printk(KERN_ERR "%s: Attempted to teardown illegal "
2076 + "MSI interrupt (%d)\n", __func__, irq);
2077 + ret = -EINVAL;
2078 + }
2079 + return ret;
2080 +}
2081 +
2082 +/**
2083 + * \fn void arch_teardown_msi_irq(unsigned int irq)
2084 + * \brief Called when a device no longer needs its MSI interrupts. All
2085 + * MSI interrupts for the device are freed.
2086 + *
2087 + * \param irq The devices first irq number. There may be multple in sequence.
2088 + * \return none
2089 + * \ingroup IFX_PCIE_MSI
2090 + */
2091 +void
2092 +arch_teardown_msi_irq(unsigned int irq)
2093 +{
2094 + int pos;
2095 + int number_irqs;
2096 + u16 bitmask;
2097 + int pcie_port;
2098 +
2099 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "%s enter\n", __func__);
2100 +
2101 + BUG_ON(irq > INT_NUM_IM4_IRL31);
2102 +
2103 + if (pcie_msi_irq_to_port(irq, &pcie_port) != 0) {
2104 + return;
2105 + }
2106 +
2107 + /* Shift the mask to the correct bit location, not always correct
2108 + * Probally, the first match will be chosen.
2109 + */
2110 + for (pos = 0; pos < IFX_MSI_IRQ_NUM; pos++) {
2111 + if ((msi_irqs[pcie_port].msi_irq_idx[pos].irq == irq)
2112 + && (msi_irqs[pcie_port].msi_free_irq_bitmask & ( 1 << pos))) {
2113 + break;
2114 + }
2115 + }
2116 + if (pos >= IFX_MSI_IRQ_NUM) {
2117 + printk(KERN_ERR "%s: Unable to find a matched MSI interrupt\n", __func__);
2118 + return;
2119 + }
2120 + spin_lock(&ifx_pcie_msi_lock);
2121 + /* Disable this entry */
2122 + msi_irqs[pcie_port].msi_pic_p->pic_table[pos] |= IFX_MSI_PCI_INT_DISABLE;
2123 + msi_irqs[pcie_port].msi_pic_p->pic_table[pos] &= ~(IFX_MSI_PIC_INT_LINE | IFX_MSI_PIC_MSG_ADDR | IFX_MSI_PIC_MSG_DATA);
2124 + spin_unlock(&ifx_pcie_msi_lock);
2125 + /*
2126 + * Count the number of IRQs we need to free by looking at the
2127 + * msi_multiple_irq_bitmask. Each bit set means that the next
2128 + * IRQ is also owned by this device.
2129 + */
2130 + number_irqs = 0;
2131 + while (((pos + number_irqs) < IFX_MSI_IRQ_NUM) &&
2132 + (msi_irqs[pcie_port].msi_multiple_irq_bitmask & (1 << (pos + number_irqs)))) {
2133 + number_irqs++;
2134 + }
2135 + number_irqs++;
2136 +
2137 + /* Mask with one bit for each IRQ */
2138 + bitmask = (1 << number_irqs) - 1;
2139 +
2140 + bitmask <<= pos;
2141 + if ((msi_irqs[pcie_port].msi_free_irq_bitmask & bitmask) != bitmask) {
2142 + printk(KERN_ERR "%s: Attempted to teardown MSI "
2143 + "interrupt (%d) not in use\n", __func__, irq);
2144 + return;
2145 + }
2146 + /* Checks are done, update the in use bitmask */
2147 + spin_lock(&ifx_pcie_msi_lock);
2148 + msi_irqs[pcie_port].msi_free_irq_bitmask &= ~bitmask;
2149 + msi_irqs[pcie_port].msi_multiple_irq_bitmask &= ~(bitmask >> 1);
2150 + spin_unlock(&ifx_pcie_msi_lock);
2151 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "%s exit\n", __func__);
2152 +}
2153 +
2154 +MODULE_LICENSE("GPL");
2155 +MODULE_AUTHOR("Chuanhua.Lei@infineon.com");
2156 +MODULE_SUPPORTED_DEVICE("Infineon PCIe IP builtin MSI PIC module");
2157 +MODULE_DESCRIPTION("Infineon PCIe IP builtin MSI PIC driver");
2158 +
2159 --- /dev/null
2160 +++ b/arch/mips/pci/ifxmips_pcie_phy.c
2161 @@ -0,0 +1,478 @@
2162 +/******************************************************************************
2163 +**
2164 +** FILE NAME : ifxmips_pcie_phy.c
2165 +** PROJECT : IFX UEIP for VRX200
2166 +** MODULES : PCIe PHY sub module
2167 +**
2168 +** DATE : 14 May 2009
2169 +** AUTHOR : Lei Chuanhua
2170 +** DESCRIPTION : PCIe Root Complex Driver
2171 +** COPYRIGHT : Copyright (c) 2009
2172 +** Infineon Technologies AG
2173 +** Am Campeon 1-12, 85579 Neubiberg, Germany
2174 +**
2175 +** This program is free software; you can redistribute it and/or modify
2176 +** it under the terms of the GNU General Public License as published by
2177 +** the Free Software Foundation; either version 2 of the License, or
2178 +** (at your option) any later version.
2179 +** HISTORY
2180 +** $Version $Date $Author $Comment
2181 +** 0.0.1 14 May,2009 Lei Chuanhua Initial version
2182 +*******************************************************************************/
2183 +/*!
2184 + \file ifxmips_pcie_phy.c
2185 + \ingroup IFX_PCIE
2186 + \brief PCIe PHY PLL register programming source file
2187 +*/
2188 +#include <linux/types.h>
2189 +#include <linux/kernel.h>
2190 +#include <asm/paccess.h>
2191 +#include <linux/delay.h>
2192 +
2193 +#include "ifxmips_pcie_reg.h"
2194 +#include "ifxmips_pcie.h"
2195 +
2196 +/* PCIe PDI only supports 16 bit operation */
2197 +
2198 +#define IFX_PCIE_PHY_REG_WRITE16(__addr, __data) \
2199 + ((*(volatile u16 *) (__addr)) = (__data))
2200 +
2201 +#define IFX_PCIE_PHY_REG_READ16(__addr) \
2202 + (*(volatile u16 *) (__addr))
2203 +
2204 +#define IFX_PCIE_PHY_REG16(__addr) \
2205 + (*(volatile u16 *) (__addr))
2206 +
2207 +#define IFX_PCIE_PHY_REG(__reg, __value, __mask) do { \
2208 + u16 read_data; \
2209 + u16 write_data; \
2210 + read_data = IFX_PCIE_PHY_REG_READ16((__reg)); \
2211 + write_data = (read_data & ((u16)~(__mask))) | (((u16)(__value)) & ((u16)(__mask)));\
2212 + IFX_PCIE_PHY_REG_WRITE16((__reg), write_data); \
2213 +} while (0)
2214 +
2215 +#define IFX_PCIE_PLL_TIMEOUT 1000 /* Tunnable */
2216 +
2217 +//#define IFX_PCI_PHY_REG_DUMP
2218 +
2219 +#ifdef IFX_PCI_PHY_REG_DUMP
2220 +static void
2221 +pcie_phy_reg_dump(int pcie_port)
2222 +{
2223 + printk("PLL REGFILE\n");
2224 + printk("PCIE_PHY_PLL_CTRL1 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_PLL_CTRL1(pcie_port)));
2225 + printk("PCIE_PHY_PLL_CTRL2 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_PLL_CTRL2(pcie_port)));
2226 + printk("PCIE_PHY_PLL_CTRL3 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_PLL_CTRL3(pcie_port)));
2227 + printk("PCIE_PHY_PLL_CTRL4 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_PLL_CTRL4(pcie_port)));
2228 + printk("PCIE_PHY_PLL_CTRL5 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_PLL_CTRL5(pcie_port)));
2229 + printk("PCIE_PHY_PLL_CTRL6 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_PLL_CTRL6(pcie_port)));
2230 + printk("PCIE_PHY_PLL_CTRL7 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_PLL_CTRL7(pcie_port)));
2231 + printk("PCIE_PHY_PLL_A_CTRL1 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_PLL_A_CTRL1(pcie_port)));
2232 + printk("PCIE_PHY_PLL_A_CTRL2 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_PLL_A_CTRL2(pcie_port)));
2233 + printk("PCIE_PHY_PLL_A_CTRL3 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_PLL_A_CTRL3(pcie_port)));
2234 + printk("PCIE_PHY_PLL_STATUS 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_PLL_STATUS(pcie_port)));
2235 +
2236 + printk("TX1 REGFILE\n");
2237 + printk("PCIE_PHY_TX1_CTRL1 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX1_CTRL1(pcie_port)));
2238 + printk("PCIE_PHY_TX1_CTRL2 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX1_CTRL2(pcie_port)));
2239 + printk("PCIE_PHY_TX1_CTRL3 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX1_CTRL3(pcie_port)));
2240 + printk("PCIE_PHY_TX1_A_CTRL1 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX1_A_CTRL1(pcie_port)));
2241 + printk("PCIE_PHY_TX1_A_CTRL2 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX1_A_CTRL2(pcie_port)));
2242 + printk("PCIE_PHY_TX1_MOD1 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX1_MOD1(pcie_port)));
2243 + printk("PCIE_PHY_TX1_MOD2 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX1_MOD2(pcie_port)));
2244 + printk("PCIE_PHY_TX1_MOD3 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX1_MOD3(pcie_port)));
2245 +
2246 + printk("TX2 REGFILE\n");
2247 + printk("PCIE_PHY_TX2_CTRL1 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX2_CTRL1(pcie_port)));
2248 + printk("PCIE_PHY_TX2_CTRL2 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX2_CTRL2(pcie_port)));
2249 + printk("PCIE_PHY_TX2_A_CTRL1 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX2_A_CTRL1(pcie_port)));
2250 + printk("PCIE_PHY_TX2_A_CTRL2 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX2_A_CTRL2(pcie_port)));
2251 + printk("PCIE_PHY_TX2_MOD1 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX2_MOD1(pcie_port)));
2252 + printk("PCIE_PHY_TX2_MOD2 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX2_MOD2(pcie_port)));
2253 + printk("PCIE_PHY_TX2_MOD3 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX2_MOD3(pcie_port)));
2254 +
2255 + printk("RX1 REGFILE\n");
2256 + printk("PCIE_PHY_RX1_CTRL1 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_RX1_CTRL1(pcie_port)));
2257 + printk("PCIE_PHY_RX1_CTRL2 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_RX1_CTRL2(pcie_port)));
2258 + printk("PCIE_PHY_RX1_CDR 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_RX1_CDR(pcie_port)));
2259 + printk("PCIE_PHY_RX1_EI 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_RX1_EI(pcie_port)));
2260 + printk("PCIE_PHY_RX1_A_CTRL 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_RX1_A_CTRL(pcie_port)));
2261 +}
2262 +#endif /* IFX_PCI_PHY_REG_DUMP */
2263 +
2264 +static void
2265 +pcie_phy_comm_setup(int pcie_port)
2266 +{
2267 + /* PLL Setting */
2268 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL1(pcie_port), 0x120e, 0xFFFF);
2269 +
2270 + /* increase the bias reference voltage */
2271 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL2(pcie_port), 0x39D7, 0xFFFF);
2272 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL3(pcie_port), 0x0900, 0xFFFF);
2273 +
2274 + /* Endcnt */
2275 + IFX_PCIE_PHY_REG(PCIE_PHY_RX1_EI(pcie_port), 0x0004, 0xFFFF);
2276 + IFX_PCIE_PHY_REG(PCIE_PHY_RX1_A_CTRL(pcie_port), 0x6803, 0xFFFF);
2277 +
2278 + /* force */
2279 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL1(pcie_port), 0x0008, 0x0008);
2280 +
2281 + /* predrv_ser_en */
2282 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_A_CTRL2(pcie_port), 0x0706, 0xFFFF);
2283 +
2284 + /* ctrl_lim */
2285 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL3(pcie_port), 0x1FFF, 0xFFFF);
2286 +
2287 + /* ctrl */
2288 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_A_CTRL1(pcie_port), 0x0800, 0xFF00);
2289 +
2290 + /* predrv_ser_en */
2291 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_A_CTRL2(pcie_port), 0x4702, 0x7F00);
2292 +
2293 + /* RTERM*/
2294 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL2(pcie_port), 0x2e00, 0xFFFF);
2295 +
2296 + /* Improved 100MHz clock output */
2297 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_CTRL2(pcie_port), 0x3096, 0xFFFF);
2298 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_A_CTRL2(pcie_port), 0x4707, 0xFFFF);
2299 +
2300 + /* Reduced CDR BW to avoid glitches */
2301 + IFX_PCIE_PHY_REG(PCIE_PHY_RX1_CDR(pcie_port), 0x0235, 0xFFFF);
2302 +}
2303 +
2304 +#ifdef CONFIG_IFX_PCIE_PHY_36MHZ_MODE
2305 +static void
2306 +pcie_phy_36mhz_mode_setup(int pcie_port)
2307 +{
2308 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d enter\n", __func__, pcie_port);
2309 +#ifdef IFX_PCI_PHY_REG_DUMP
2310 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "Initial PHY register dump\n");
2311 + pcie_phy_reg_dump(pcie_port);
2312 +#endif
2313 +
2314 + /* en_ext_mmd_div_ratio */
2315 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0000, 0x0002);
2316 +
2317 + /* ext_mmd_div_ratio*/
2318 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0000, 0x0070);
2319 +
2320 + /* pll_ensdm */
2321 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0200, 0x0200);
2322 +
2323 + /* en_const_sdm */
2324 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0100, 0x0100);
2325 +
2326 + /* mmd */
2327 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL3(pcie_port), 0x2000, 0xe000);
2328 +
2329 + /* lf_mode */
2330 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL2(pcie_port), 0x0000, 0x4000);
2331 +
2332 + /* const_sdm */
2333 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL1(pcie_port), 0x38e4, 0xFFFF);
2334 +
2335 + /* const sdm */
2336 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x00ee, 0x00FF);
2337 +
2338 + /* pllmod */
2339 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL7(pcie_port), 0x0002, 0xFFFF);
2340 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL6(pcie_port), 0x3a04, 0xFFFF);
2341 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL5(pcie_port), 0xfae3, 0xFFFF);
2342 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL4(pcie_port), 0x1b72, 0xFFFF);
2343 +
2344 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d exit\n", __func__, pcie_port);
2345 +}
2346 +#endif /* CONFIG_IFX_PCIE_PHY_36MHZ_MODE */
2347 +
2348 +#ifdef CONFIG_IFX_PCIE_PHY_36MHZ_SSC_MODE
2349 +static void
2350 +pcie_phy_36mhz_ssc_mode_setup(int pcie_port)
2351 +{
2352 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d enter\n", __func__, pcie_port);
2353 +#ifdef IFX_PCI_PHY_REG_DUMP
2354 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "Initial PHY register dump\n");
2355 + pcie_phy_reg_dump(pcie_port);
2356 +#endif
2357 +
2358 + /* PLL Setting */
2359 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL1(pcie_port), 0x120e, 0xFFFF);
2360 +
2361 + /* Increase the bias reference voltage */
2362 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL2(pcie_port), 0x39D7, 0xFFFF);
2363 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL3(pcie_port), 0x0900, 0xFFFF);
2364 +
2365 + /* Endcnt */
2366 + IFX_PCIE_PHY_REG(PCIE_PHY_RX1_EI(pcie_port), 0x0004, 0xFFFF);
2367 + IFX_PCIE_PHY_REG(PCIE_PHY_RX1_A_CTRL(pcie_port), 0x6803, 0xFFFF);
2368 +
2369 + /* Force */
2370 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL1(pcie_port), 0x0008, 0x0008);
2371 +
2372 + /* Predrv_ser_en */
2373 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_A_CTRL2(pcie_port), 0x0706, 0xFFFF);
2374 +
2375 + /* ctrl_lim */
2376 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL3(pcie_port), 0x1FFF, 0xFFFF);
2377 +
2378 + /* ctrl */
2379 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_A_CTRL1(pcie_port), 0x0800, 0xFF00);
2380 +
2381 + /* predrv_ser_en */
2382 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_A_CTRL2(pcie_port), 0x4702, 0x7F00);
2383 +
2384 + /* RTERM*/
2385 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL2(pcie_port), 0x2e00, 0xFFFF);
2386 +
2387 + /* en_ext_mmd_div_ratio */
2388 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0000, 0x0002);
2389 +
2390 + /* ext_mmd_div_ratio*/
2391 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0000, 0x0070);
2392 +
2393 + /* pll_ensdm */
2394 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0400, 0x0400);
2395 +
2396 + /* en_const_sdm */
2397 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0200, 0x0200);
2398 +
2399 + /* mmd */
2400 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL3(pcie_port), 0x2000, 0xe000);
2401 +
2402 + /* lf_mode */
2403 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL2(pcie_port), 0x0000, 0x4000);
2404 +
2405 + /* const_sdm */
2406 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL1(pcie_port), 0x38e4, 0xFFFF);
2407 +
2408 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0000, 0x0100);
2409 + /* const sdm */
2410 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x00ee, 0x00FF);
2411 +
2412 + /* pllmod */
2413 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL7(pcie_port), 0x0002, 0xFFFF);
2414 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL6(pcie_port), 0x3a04, 0xFFFF);
2415 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL5(pcie_port), 0xfae3, 0xFFFF);
2416 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL4(pcie_port), 0x1c72, 0xFFFF);
2417 +
2418 + /* improved 100MHz clock output */
2419 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_CTRL2(pcie_port), 0x3096, 0xFFFF);
2420 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_A_CTRL2(pcie_port), 0x4707, 0xFFFF);
2421 +
2422 + /* reduced CDR BW to avoid glitches */
2423 + IFX_PCIE_PHY_REG(PCIE_PHY_RX1_CDR(pcie_port), 0x0235, 0xFFFF);
2424 +
2425 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d exit\n", __func__, pcie_port);
2426 +}
2427 +#endif /* CONFIG_IFX_PCIE_PHY_36MHZ_SSC_MODE */
2428 +
2429 +#ifdef CONFIG_IFX_PCIE_PHY_25MHZ_MODE
2430 +static void
2431 +pcie_phy_25mhz_mode_setup(int pcie_port)
2432 +{
2433 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d enter\n", __func__, pcie_port);
2434 +#ifdef IFX_PCI_PHY_REG_DUMP
2435 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "Initial PHY register dump\n");
2436 + pcie_phy_reg_dump(pcie_port);
2437 +#endif
2438 + /* en_const_sdm */
2439 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0100, 0x0100);
2440 +
2441 + /* pll_ensdm */
2442 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0000, 0x0200);
2443 +
2444 + /* en_ext_mmd_div_ratio*/
2445 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0002, 0x0002);
2446 +
2447 + /* ext_mmd_div_ratio*/
2448 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0040, 0x0070);
2449 +
2450 + /* mmd */
2451 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL3(pcie_port), 0x6000, 0xe000);
2452 +
2453 + /* lf_mode */
2454 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL2(pcie_port), 0x4000, 0x4000);
2455 +
2456 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d exit\n", __func__, pcie_port);
2457 +}
2458 +#endif /* CONFIG_IFX_PCIE_PHY_25MHZ_MODE */
2459 +
2460 +#ifdef CONFIG_IFX_PCIE_PHY_100MHZ_MODE
2461 +static void
2462 +pcie_phy_100mhz_mode_setup(int pcie_port)
2463 +{
2464 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d enter\n", __func__, pcie_port);
2465 +#ifdef IFX_PCI_PHY_REG_DUMP
2466 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "Initial PHY register dump\n");
2467 + pcie_phy_reg_dump(pcie_port);
2468 +#endif
2469 + /* en_ext_mmd_div_ratio */
2470 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0000, 0x0002);
2471 +
2472 + /* ext_mmd_div_ratio*/
2473 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0000, 0x0070);
2474 +
2475 + /* pll_ensdm */
2476 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0200, 0x0200);
2477 +
2478 + /* en_const_sdm */
2479 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0100, 0x0100);
2480 +
2481 + /* mmd */
2482 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL3(pcie_port), 0x2000, 0xe000);
2483 +
2484 + /* lf_mode */
2485 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL2(pcie_port), 0x0000, 0x4000);
2486 +
2487 + /* const_sdm */
2488 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL1(pcie_port), 0x38e4, 0xFFFF);
2489 +
2490 + /* const sdm */
2491 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x00ee, 0x00FF);
2492 +
2493 + /* pllmod */
2494 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL7(pcie_port), 0x0002, 0xFFFF);
2495 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL6(pcie_port), 0x3a04, 0xFFFF);
2496 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL5(pcie_port), 0xfae3, 0xFFFF);
2497 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL4(pcie_port), 0x1b72, 0xFFFF);
2498 +
2499 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d exit\n", __func__, pcie_port);
2500 +}
2501 +#endif /* CONFIG_IFX_PCIE_PHY_100MHZ_MODE */
2502 +
2503 +static int
2504 +pcie_phy_wait_startup_ready(int pcie_port)
2505 +{
2506 + int i;
2507 +
2508 + for (i = 0; i < IFX_PCIE_PLL_TIMEOUT; i++) {
2509 + if ((IFX_PCIE_PHY_REG16(PCIE_PHY_PLL_STATUS(pcie_port)) & 0x0040) != 0) {
2510 + break;
2511 + }
2512 + udelay(10);
2513 + }
2514 + if (i >= IFX_PCIE_PLL_TIMEOUT) {
2515 + printk(KERN_ERR "%s PLL Link timeout\n", __func__);
2516 + return -1;
2517 + }
2518 + return 0;
2519 +}
2520 +
2521 +static void
2522 +pcie_phy_load_enable(int pcie_port, int slice)
2523 +{
2524 + /* Set the load_en of tx/rx slice to '1' */
2525 + switch (slice) {
2526 + case 1:
2527 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL1(pcie_port), 0x0010, 0x0010);
2528 + break;
2529 + case 2:
2530 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_CTRL1(pcie_port), 0x0010, 0x0010);
2531 + break;
2532 + case 3:
2533 + IFX_PCIE_PHY_REG(PCIE_PHY_RX1_CTRL1(pcie_port), 0x0002, 0x0002);
2534 + break;
2535 + }
2536 +}
2537 +
2538 +static void
2539 +pcie_phy_load_disable(int pcie_port, int slice)
2540 +{
2541 + /* set the load_en of tx/rx slice to '0' */
2542 + switch (slice) {
2543 + case 1:
2544 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL1(pcie_port), 0x0000, 0x0010);
2545 + break;
2546 + case 2:
2547 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_CTRL1(pcie_port), 0x0000, 0x0010);
2548 + break;
2549 + case 3:
2550 + IFX_PCIE_PHY_REG(PCIE_PHY_RX1_CTRL1(pcie_port), 0x0000, 0x0002);
2551 + break;
2552 + }
2553 +}
2554 +
2555 +static void
2556 +pcie_phy_load_war(int pcie_port)
2557 +{
2558 + int slice;
2559 +
2560 + for (slice = 1; slice < 4; slice++) {
2561 + pcie_phy_load_enable(pcie_port, slice);
2562 + udelay(1);
2563 + pcie_phy_load_disable(pcie_port, slice);
2564 + }
2565 +}
2566 +
2567 +static void
2568 +pcie_phy_tx2_modulation(int pcie_port)
2569 +{
2570 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_MOD1(pcie_port), 0x1FFE, 0xFFFF);
2571 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_MOD2(pcie_port), 0xFFFE, 0xFFFF);
2572 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_MOD3(pcie_port), 0x0601, 0xFFFF);
2573 + mdelay(1);
2574 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_MOD3(pcie_port), 0x0001, 0xFFFF);
2575 +}
2576 +
2577 +static void
2578 +pcie_phy_tx1_modulation(int pcie_port)
2579 +{
2580 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_MOD1(pcie_port), 0x1FFE, 0xFFFF);
2581 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_MOD2(pcie_port), 0xFFFE, 0xFFFF);
2582 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_MOD3(pcie_port), 0x0601, 0xFFFF);
2583 + mdelay(1);
2584 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_MOD3(pcie_port), 0x0001, 0xFFFF);
2585 +}
2586 +
2587 +static void
2588 +pcie_phy_tx_modulation_war(int pcie_port)
2589 +{
2590 + int i;
2591 +
2592 +#define PCIE_PHY_MODULATION_NUM 5
2593 + for (i = 0; i < PCIE_PHY_MODULATION_NUM; i++) {
2594 + pcie_phy_tx2_modulation(pcie_port);
2595 + pcie_phy_tx1_modulation(pcie_port);
2596 + }
2597 +#undef PCIE_PHY_MODULATION_NUM
2598 +}
2599 +
2600 +void
2601 +pcie_phy_clock_mode_setup(int pcie_port)
2602 +{
2603 + pcie_pdi_big_endian(pcie_port);
2604 +
2605 + /* Enable PDI to access PCIe PHY register */
2606 + pcie_pdi_pmu_enable(pcie_port);
2607 +
2608 + /* Configure PLL and PHY clock */
2609 + pcie_phy_comm_setup(pcie_port);
2610 +
2611 +#ifdef CONFIG_IFX_PCIE_PHY_36MHZ_MODE
2612 + pcie_phy_36mhz_mode_setup(pcie_port);
2613 +#elif defined(CONFIG_IFX_PCIE_PHY_36MHZ_SSC_MODE)
2614 + pcie_phy_36mhz_ssc_mode_setup(pcie_port);
2615 +#elif defined(CONFIG_IFX_PCIE_PHY_25MHZ_MODE)
2616 + pcie_phy_25mhz_mode_setup(pcie_port);
2617 +#elif defined (CONFIG_IFX_PCIE_PHY_100MHZ_MODE)
2618 + pcie_phy_100mhz_mode_setup(pcie_port);
2619 +#else
2620 + #error "PCIE PHY Clock Mode must be chosen first!!!!"
2621 +#endif /* CONFIG_IFX_PCIE_PHY_36MHZ_MODE */
2622 +
2623 + /* Enable PCIe PHY and make PLL setting take effect */
2624 + pcie_phy_pmu_enable(pcie_port);
2625 +
2626 + /* Check if we are in startup_ready status */
2627 + pcie_phy_wait_startup_ready(pcie_port);
2628 +
2629 + pcie_phy_load_war(pcie_port);
2630 +
2631 + /* Apply TX modulation workarounds */
2632 + pcie_phy_tx_modulation_war(pcie_port);
2633 +
2634 +#ifdef IFX_PCI_PHY_REG_DUMP
2635 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "Modified PHY register dump\n");
2636 + pcie_phy_reg_dump(pcie_port);
2637 +#endif
2638 +}
2639 +
2640 --- /dev/null
2641 +++ b/arch/mips/pci/ifxmips_pcie_pm.c
2642 @@ -0,0 +1,176 @@
2643 +/******************************************************************************
2644 +**
2645 +** FILE NAME : ifxmips_pcie_pm.c
2646 +** PROJECT : IFX UEIP
2647 +** MODULES : PCIE Root Complex Driver
2648 +**
2649 +** DATE : 21 Dec 2009
2650 +** AUTHOR : Lei Chuanhua
2651 +** DESCRIPTION : PCIE Root Complex Driver Power Managment
2652 +** COPYRIGHT : Copyright (c) 2009
2653 +** Lantiq Deutschland GmbH
2654 +** Am Campeon 3, 85579 Neubiberg, Germany
2655 +**
2656 +** This program is free software; you can redistribute it and/or modify
2657 +** it under the terms of the GNU General Public License as published by
2658 +** the Free Software Foundation; either version 2 of the License, or
2659 +** (at your option) any later version.
2660 +**
2661 +** HISTORY
2662 +** $Date $Author $Comment
2663 +** 21 Dec,2009 Lei Chuanhua First UEIP release
2664 +*******************************************************************************/
2665 +/*!
2666 + \defgroup IFX_PCIE_PM Power Management functions
2667 + \ingroup IFX_PCIE
2668 + \brief IFX PCIE Root Complex Driver power management functions
2669 +*/
2670 +
2671 +/*!
2672 + \file ifxmips_pcie_pm.c
2673 + \ingroup IFX_PCIE
2674 + \brief source file for PCIE Root Complex Driver Power Management
2675 +*/
2676 +
2677 +#ifndef EXPORT_SYMTAB
2678 +#define EXPORT_SYMTAB
2679 +#endif
2680 +#ifndef AUTOCONF_INCLUDED
2681 +#include <linux/config.h>
2682 +#endif /* AUTOCONF_INCLUDED */
2683 +#include <linux/version.h>
2684 +#include <linux/module.h>
2685 +#include <linux/types.h>
2686 +#include <linux/kernel.h>
2687 +#include <asm/system.h>
2688 +
2689 +/* Project header */
2690 +#include <asm/ifx/ifx_types.h>
2691 +#include <asm/ifx/ifx_regs.h>
2692 +#include <asm/ifx/common_routines.h>
2693 +#include <asm/ifx/ifx_pmcu.h>
2694 +#include "ifxmips_pcie_pm.h"
2695 +
2696 +/**
2697 + * \fn static IFX_PMCU_RETURN_t ifx_pcie_pmcu_state_change(IFX_PMCU_STATE_t pmcuState)
2698 + * \brief the callback function to request pmcu state in the power management hardware-dependent module
2699 + *
2700 + * \param pmcuState This parameter is a PMCU state.
2701 + *
2702 + * \return IFX_PMCU_RETURN_SUCCESS Set Power State successfully
2703 + * \return IFX_PMCU_RETURN_ERROR Failed to set power state.
2704 + * \return IFX_PMCU_RETURN_DENIED Not allowed to operate power state
2705 + * \ingroup IFX_PCIE_PM
2706 + */
2707 +static IFX_PMCU_RETURN_t
2708 +ifx_pcie_pmcu_state_change(IFX_PMCU_STATE_t pmcuState)
2709 +{
2710 + switch(pmcuState)
2711 + {
2712 + case IFX_PMCU_STATE_D0:
2713 + return IFX_PMCU_RETURN_SUCCESS;
2714 + case IFX_PMCU_STATE_D1: // Not Applicable
2715 + return IFX_PMCU_RETURN_DENIED;
2716 + case IFX_PMCU_STATE_D2: // Not Applicable
2717 + return IFX_PMCU_RETURN_DENIED;
2718 + case IFX_PMCU_STATE_D3: // Module clock gating and Power gating
2719 + return IFX_PMCU_RETURN_SUCCESS;
2720 + default:
2721 + return IFX_PMCU_RETURN_DENIED;
2722 + }
2723 +}
2724 +
2725 +/**
2726 + * \fn static IFX_PMCU_RETURN_t ifx_pcie_pmcu_state_get(IFX_PMCU_STATE_t *pmcuState)
2727 + * \brief the callback function to get pmcu state in the power management hardware-dependent module
2728 +
2729 + * \param pmcuState Pointer to return power state.
2730 + *
2731 + * \return IFX_PMCU_RETURN_SUCCESS Set Power State successfully
2732 + * \return IFX_PMCU_RETURN_ERROR Failed to set power state.
2733 + * \return IFX_PMCU_RETURN_DENIED Not allowed to operate power state
2734 + * \ingroup IFX_PCIE_PM
2735 + */
2736 +static IFX_PMCU_RETURN_t
2737 +ifx_pcie_pmcu_state_get(IFX_PMCU_STATE_t *pmcuState)
2738 +{
2739 + return IFX_PMCU_RETURN_SUCCESS;
2740 +}
2741 +
2742 +/**
2743 + * \fn IFX_PMCU_RETURN_t ifx_pcie_pmcu_prechange(IFX_PMCU_MODULE_t pmcuModule, IFX_PMCU_STATE_t newState, IFX_PMCU_STATE_t oldState)
2744 + * \brief Apply all callbacks registered to be executed before a state change for pmcuModule
2745 + *
2746 + * \param pmcuModule Module
2747 + * \param newState New state
2748 + * \param oldState Old state
2749 + * \return IFX_PMCU_RETURN_SUCCESS Set Power State successfully
2750 + * \return IFX_PMCU_RETURN_ERROR Failed to set power state.
2751 + * \ingroup IFX_PCIE_PM
2752 + */
2753 +static IFX_PMCU_RETURN_t
2754 +ifx_pcie_pmcu_prechange(IFX_PMCU_MODULE_t pmcuModule, IFX_PMCU_STATE_t newState, IFX_PMCU_STATE_t oldState)
2755 +{
2756 + return IFX_PMCU_RETURN_SUCCESS;
2757 +}
2758 +
2759 +/**
2760 + * \fn IFX_PMCU_RETURN_t ifx_pcie_pmcu_postchange(IFX_PMCU_MODULE_t pmcuModule, IFX_PMCU_STATE_t newState, IFX_PMCU_STATE_t oldState)
2761 + * \brief Apply all callbacks registered to be executed before a state change for pmcuModule
2762 + *
2763 + * \param pmcuModule Module
2764 + * \param newState New state
2765 + * \param oldState Old state
2766 + * \return IFX_PMCU_RETURN_SUCCESS Set Power State successfully
2767 + * \return IFX_PMCU_RETURN_ERROR Failed to set power state.
2768 + * \ingroup IFX_PCIE_PM
2769 + */
2770 +static IFX_PMCU_RETURN_t
2771 +ifx_pcie_pmcu_postchange(IFX_PMCU_MODULE_t pmcuModule, IFX_PMCU_STATE_t newState, IFX_PMCU_STATE_t oldState)
2772 +{
2773 + return IFX_PMCU_RETURN_SUCCESS;
2774 +}
2775 +
2776 +/**
2777 + * \fn static void ifx_pcie_pmcu_init(void)
2778 + * \brief Register with central PMCU module
2779 + * \return none
2780 + * \ingroup IFX_PCIE_PM
2781 + */
2782 +void
2783 +ifx_pcie_pmcu_init(void)
2784 +{
2785 + IFX_PMCU_REGISTER_t pmcuRegister;
2786 +
2787 + /* XXX, hook driver context */
2788 +
2789 + /* State function register */
2790 + memset(&pmcuRegister, 0, sizeof(IFX_PMCU_REGISTER_t));
2791 + pmcuRegister.pmcuModule = IFX_PMCU_MODULE_PCIE;
2792 + pmcuRegister.pmcuModuleNr = 0;
2793 + pmcuRegister.ifx_pmcu_state_change = ifx_pcie_pmcu_state_change;
2794 + pmcuRegister.ifx_pmcu_state_get = ifx_pcie_pmcu_state_get;
2795 + pmcuRegister.pre = ifx_pcie_pmcu_prechange;
2796 + pmcuRegister.post= ifx_pcie_pmcu_postchange;
2797 + ifx_pmcu_register(&pmcuRegister);
2798 +}
2799 +
2800 +/**
2801 + * \fn static void ifx_pcie_pmcu_exit(void)
2802 + * \brief Unregister with central PMCU module
2803 + *
2804 + * \return none
2805 + * \ingroup IFX_PCIE_PM
2806 + */
2807 +void
2808 +ifx_pcie_pmcu_exit(void)
2809 +{
2810 + IFX_PMCU_REGISTER_t pmcuUnRegister;
2811 +
2812 + /* XXX, hook driver context */
2813 +
2814 + pmcuUnRegister.pmcuModule = IFX_PMCU_MODULE_PCIE;
2815 + pmcuUnRegister.pmcuModuleNr = 0;
2816 + ifx_pmcu_unregister(&pmcuUnRegister);
2817 +}
2818 +
2819 --- /dev/null
2820 +++ b/arch/mips/pci/ifxmips_pcie_pm.h
2821 @@ -0,0 +1,36 @@
2822 +/******************************************************************************
2823 +**
2824 +** FILE NAME : ifxmips_pcie_pm.h
2825 +** PROJECT : IFX UEIP
2826 +** MODULES : PCIe Root Complex Driver
2827 +**
2828 +** DATE : 21 Dec 2009
2829 +** AUTHOR : Lei Chuanhua
2830 +** DESCRIPTION : PCIe Root Complex Driver Power Managment
2831 +** COPYRIGHT : Copyright (c) 2009
2832 +** Lantiq Deutschland GmbH
2833 +** Am Campeon 3, 85579 Neubiberg, Germany
2834 +**
2835 +** This program is free software; you can redistribute it and/or modify
2836 +** it under the terms of the GNU General Public License as published by
2837 +** the Free Software Foundation; either version 2 of the License, or
2838 +** (at your option) any later version.
2839 +**
2840 +** HISTORY
2841 +** $Date $Author $Comment
2842 +** 21 Dec,2009 Lei Chuanhua First UEIP release
2843 +*******************************************************************************/
2844 +/*!
2845 + \file ifxmips_pcie_pm.h
2846 + \ingroup IFX_PCIE
2847 + \brief header file for PCIe Root Complex Driver Power Management
2848 +*/
2849 +
2850 +#ifndef IFXMIPS_PCIE_PM_H
2851 +#define IFXMIPS_PCIE_PM_H
2852 +
2853 +void ifx_pcie_pmcu_init(void);
2854 +void ifx_pcie_pmcu_exit(void);
2855 +
2856 +#endif /* IFXMIPS_PCIE_PM_H */
2857 +
2858 --- /dev/null
2859 +++ b/arch/mips/pci/ifxmips_pcie_reg.h
2860 @@ -0,0 +1,1001 @@
2861 +/******************************************************************************
2862 +**
2863 +** FILE NAME : ifxmips_pcie_reg.h
2864 +** PROJECT : IFX UEIP for VRX200
2865 +** MODULES : PCIe module
2866 +**
2867 +** DATE : 02 Mar 2009
2868 +** AUTHOR : Lei Chuanhua
2869 +** DESCRIPTION : PCIe Root Complex Driver
2870 +** COPYRIGHT : Copyright (c) 2009
2871 +** Infineon Technologies AG
2872 +** Am Campeon 1-12, 85579 Neubiberg, Germany
2873 +**
2874 +** This program is free software; you can redistribute it and/or modify
2875 +** it under the terms of the GNU General Public License as published by
2876 +** the Free Software Foundation; either version 2 of the License, or
2877 +** (at your option) any later version.
2878 +** HISTORY
2879 +** $Version $Date $Author $Comment
2880 +** 0.0.1 17 Mar,2009 Lei Chuanhua Initial version
2881 +*******************************************************************************/
2882 +#ifndef IFXMIPS_PCIE_REG_H
2883 +#define IFXMIPS_PCIE_REG_H
2884 +/*!
2885 + \file ifxmips_pcie_reg.h
2886 + \ingroup IFX_PCIE
2887 + \brief header file for PCIe module register definition
2888 +*/
2889 +/* PCIe Address Mapping Base */
2890 +#define PCIE_CFG_PHY_BASE 0x1D000000UL
2891 +#define PCIE_CFG_BASE (KSEG1 + PCIE_CFG_PHY_BASE)
2892 +#define PCIE_CFG_SIZE (8 * 1024 * 1024)
2893 +
2894 +#define PCIE_MEM_PHY_BASE 0x1C000000UL
2895 +#define PCIE_MEM_BASE (KSEG1 + PCIE_MEM_PHY_BASE)
2896 +#define PCIE_MEM_SIZE (16 * 1024 * 1024)
2897 +#define PCIE_MEM_PHY_END (PCIE_MEM_PHY_BASE + PCIE_MEM_SIZE - 1)
2898 +
2899 +#define PCIE_IO_PHY_BASE 0x1D800000UL
2900 +#define PCIE_IO_BASE (KSEG1 + PCIE_IO_PHY_BASE)
2901 +#define PCIE_IO_SIZE (1 * 1024 * 1024)
2902 +#define PCIE_IO_PHY_END (PCIE_IO_PHY_BASE + PCIE_IO_SIZE - 1)
2903 +
2904 +#define PCIE_RC_CFG_BASE (KSEG1 + 0x1D900000)
2905 +#define PCIE_APP_LOGIC_REG (KSEG1 + 0x1E100900)
2906 +#define PCIE_MSI_PHY_BASE 0x1F600000UL
2907 +
2908 +#define PCIE_PDI_PHY_BASE 0x1F106800UL
2909 +#define PCIE_PDI_BASE (KSEG1 + PCIE_PDI_PHY_BASE)
2910 +#define PCIE_PDI_SIZE 0x400
2911 +
2912 +#define PCIE1_CFG_PHY_BASE 0x19000000UL
2913 +#define PCIE1_CFG_BASE (KSEG1 + PCIE1_CFG_PHY_BASE)
2914 +#define PCIE1_CFG_SIZE (8 * 1024 * 1024)
2915 +
2916 +#define PCIE1_MEM_PHY_BASE 0x18000000UL
2917 +#define PCIE1_MEM_BASE (KSEG1 + PCIE1_MEM_PHY_BASE)
2918 +#define PCIE1_MEM_SIZE (16 * 1024 * 1024)
2919 +#define PCIE1_MEM_PHY_END (PCIE1_MEM_PHY_BASE + PCIE1_MEM_SIZE - 1)
2920 +
2921 +#define PCIE1_IO_PHY_BASE 0x19800000UL
2922 +#define PCIE1_IO_BASE (KSEG1 + PCIE1_IO_PHY_BASE)
2923 +#define PCIE1_IO_SIZE (1 * 1024 * 1024)
2924 +#define PCIE1_IO_PHY_END (PCIE1_IO_PHY_BASE + PCIE1_IO_SIZE - 1)
2925 +
2926 +#define PCIE1_RC_CFG_BASE (KSEG1 + 0x19900000)
2927 +#define PCIE1_APP_LOGIC_REG (KSEG1 + 0x1E100700)
2928 +#define PCIE1_MSI_PHY_BASE 0x1F400000UL
2929 +
2930 +#define PCIE1_PDI_PHY_BASE 0x1F700400UL
2931 +#define PCIE1_PDI_BASE (KSEG1 + PCIE1_PDI_PHY_BASE)
2932 +#define PCIE1_PDI_SIZE 0x400
2933 +
2934 +#define PCIE_CFG_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_CFG_BASE) : (PCIE_CFG_BASE))
2935 +#define PCIE_MEM_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_MEM_BASE) : (PCIE_MEM_BASE))
2936 +#define PCIE_IO_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_IO_BASE) : (PCIE_IO_BASE))
2937 +#define PCIE_MEM_PHY_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_MEM_PHY_BASE) : (PCIE_MEM_PHY_BASE))
2938 +#define PCIE_MEM_PHY_PORT_TO_END(X) ((X) > 0 ? (PCIE1_MEM_PHY_END) : (PCIE_MEM_PHY_END))
2939 +#define PCIE_IO_PHY_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_IO_PHY_BASE) : (PCIE_IO_PHY_BASE))
2940 +#define PCIE_IO_PHY_PORT_TO_END(X) ((X) > 0 ? (PCIE1_IO_PHY_END) : (PCIE_IO_PHY_END))
2941 +#define PCIE_APP_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_APP_LOGIC_REG) : (PCIE_APP_LOGIC_REG))
2942 +#define PCIE_RC_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_RC_CFG_BASE) : (PCIE_RC_CFG_BASE))
2943 +#define PCIE_PHY_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_PDI_BASE) : (PCIE_PDI_BASE))
2944 +
2945 +/* PCIe Application Logic Register */
2946 +/* RC Core Control Register */
2947 +#define PCIE_RC_CCR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x10)
2948 +/* This should be enabled after initializing configuratin registers
2949 + * Also should check link status retraining bit
2950 + */
2951 +#define PCIE_RC_CCR_LTSSM_ENABLE 0x00000001 /* Enable LTSSM to continue link establishment */
2952 +
2953 +/* RC Core Debug Register */
2954 +#define PCIE_RC_DR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x14)
2955 +#define PCIE_RC_DR_DLL_UP 0x00000001 /* Data Link Layer Up */
2956 +#define PCIE_RC_DR_CURRENT_POWER_STATE 0x0000000E /* Current Power State */
2957 +#define PCIE_RC_DR_CURRENT_POWER_STATE_S 1
2958 +#define PCIE_RC_DR_CURRENT_LTSSM_STATE 0x000001F0 /* Current LTSSM State */
2959 +#define PCIE_RC_DR_CURRENT_LTSSM_STATE_S 4
2960 +
2961 +#define PCIE_RC_DR_PM_DEV_STATE 0x00000E00 /* Power Management D-State */
2962 +#define PCIE_RC_DR_PM_DEV_STATE_S 9
2963 +
2964 +#define PCIE_RC_DR_PM_ENABLED 0x00001000 /* Power Management State from PMU */
2965 +#define PCIE_RC_DR_PME_EVENT_ENABLED 0x00002000 /* Power Management Event Enable State */
2966 +#define PCIE_RC_DR_AUX_POWER_ENABLED 0x00004000 /* Auxiliary Power Enable */
2967 +
2968 +/* Current Power State Definition */
2969 +enum {
2970 + PCIE_RC_DR_D0 = 0,
2971 + PCIE_RC_DR_D1, /* Not supported */
2972 + PCIE_RC_DR_D2, /* Not supported */
2973 + PCIE_RC_DR_D3,
2974 + PCIE_RC_DR_UN,
2975 +};
2976 +
2977 +/* PHY Link Status Register */
2978 +#define PCIE_PHY_SR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x18)
2979 +#define PCIE_PHY_SR_PHY_LINK_UP 0x00000001 /* PHY Link Up/Down Indicator */
2980 +
2981 +/* Electromechanical Control Register */
2982 +#define PCIE_EM_CR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x1C)
2983 +#define PCIE_EM_CR_CARD_IS_PRESENT 0x00000001 /* Card Presence Detect State */
2984 +#define PCIE_EM_CR_MRL_OPEN 0x00000002 /* MRL Sensor State */
2985 +#define PCIE_EM_CR_POWER_FAULT_SET 0x00000004 /* Power Fault Detected */
2986 +#define PCIE_EM_CR_MRL_SENSOR_SET 0x00000008 /* MRL Sensor Changed */
2987 +#define PCIE_EM_CR_PRESENT_DETECT_SET 0x00000010 /* Card Presense Detect Changed */
2988 +#define PCIE_EM_CR_CMD_CPL_INT_SET 0x00000020 /* Command Complete Interrupt */
2989 +#define PCIE_EM_CR_SYS_INTERLOCK_SET 0x00000040 /* System Electromechanical IterLock Engaged */
2990 +#define PCIE_EM_CR_ATTENTION_BUTTON_SET 0x00000080 /* Attention Button Pressed */
2991 +
2992 +/* Interrupt Status Register */
2993 +#define PCIE_IR_SR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x20)
2994 +#define PCIE_IR_SR_PME_CAUSE_MSI 0x00000002 /* MSI caused by PME */
2995 +#define PCIE_IR_SR_HP_PME_WAKE_GEN 0x00000004 /* Hotplug PME Wake Generation */
2996 +#define PCIE_IR_SR_HP_MSI 0x00000008 /* Hotplug MSI */
2997 +#define PCIE_IR_SR_AHB_LU_ERR 0x00000030 /* AHB Bridge Lookup Error Signals */
2998 +#define PCIE_IR_SR_AHB_LU_ERR_S 4
2999 +#define PCIE_IR_SR_INT_MSG_NUM 0x00003E00 /* Interrupt Message Number */
3000 +#define PCIE_IR_SR_INT_MSG_NUM_S 9
3001 +#define PCIE_IR_SR_AER_INT_MSG_NUM 0xF8000000 /* Advanced Error Interrupt Message Number */
3002 +#define PCIE_IR_SR_AER_INT_MSG_NUM_S 27
3003 +
3004 +/* Message Control Register */
3005 +#define PCIE_MSG_CR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x30)
3006 +#define PCIE_MSG_CR_GEN_PME_TURN_OFF_MSG 0x00000001 /* Generate PME Turn Off Message */
3007 +#define PCIE_MSG_CR_GEN_UNLOCK_MSG 0x00000002 /* Generate Unlock Message */
3008 +
3009 +#define PCIE_VDM_DR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x34)
3010 +
3011 +/* Vendor-Defined Message Requester ID Register */
3012 +#define PCIE_VDM_RID(X) (PCIE_APP_PORT_TO_BASE (X) + 0x38)
3013 +#define PCIE_VDM_RID_VENROR_MSG_REQ_ID 0x0000FFFF
3014 +#define PCIE_VDM_RID_VDMRID_S 0
3015 +
3016 +/* ASPM Control Register */
3017 +#define PCIE_ASPM_CR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x40)
3018 +#define PCIE_ASPM_CR_HOT_RST 0x00000001 /* Hot Reset Request to the downstream device */
3019 +#define PCIE_ASPM_CR_REQ_EXIT_L1 0x00000002 /* Request to Exit L1 */
3020 +#define PCIE_ASPM_CR_REQ_ENTER_L1 0x00000004 /* Request to Enter L1 */
3021 +
3022 +/* Vendor Message DW0 Register */
3023 +#define PCIE_VM_MSG_DW0(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x50)
3024 +#define PCIE_VM_MSG_DW0_TYPE 0x0000001F /* Message type */
3025 +#define PCIE_VM_MSG_DW0_TYPE_S 0
3026 +#define PCIE_VM_MSG_DW0_FORMAT 0x00000060 /* Format */
3027 +#define PCIE_VM_MSG_DW0_FORMAT_S 5
3028 +#define PCIE_VM_MSG_DW0_TC 0x00007000 /* Traffic Class */
3029 +#define PCIE_VM_MSG_DW0_TC_S 12
3030 +#define PCIE_VM_MSG_DW0_ATTR 0x000C0000 /* Atrributes */
3031 +#define PCIE_VM_MSG_DW0_ATTR_S 18
3032 +#define PCIE_VM_MSG_DW0_EP_TLP 0x00100000 /* Poisoned TLP */
3033 +#define PCIE_VM_MSG_DW0_TD 0x00200000 /* TLP Digest */
3034 +#define PCIE_VM_MSG_DW0_LEN 0xFFC00000 /* Length */
3035 +#define PCIE_VM_MSG_DW0_LEN_S 22
3036 +
3037 +/* Format Definition */
3038 +enum {
3039 + PCIE_VM_MSG_FORMAT_00 = 0, /* 3DW Hdr, no data*/
3040 + PCIE_VM_MSG_FORMAT_01, /* 4DW Hdr, no data */
3041 + PCIE_VM_MSG_FORMAT_10, /* 3DW Hdr, with data */
3042 + PCIE_VM_MSG_FORMAT_11, /* 4DW Hdr, with data */
3043 +};
3044 +
3045 +/* Traffic Class Definition */
3046 +enum {
3047 + PCIE_VM_MSG_TC0 = 0,
3048 + PCIE_VM_MSG_TC1,
3049 + PCIE_VM_MSG_TC2,
3050 + PCIE_VM_MSG_TC3,
3051 + PCIE_VM_MSG_TC4,
3052 + PCIE_VM_MSG_TC5,
3053 + PCIE_VM_MSG_TC6,
3054 + PCIE_VM_MSG_TC7,
3055 +};
3056 +
3057 +/* Attributes Definition */
3058 +enum {
3059 + PCIE_VM_MSG_ATTR_00 = 0, /* RO and No Snoop cleared */
3060 + PCIE_VM_MSG_ATTR_01, /* RO cleared , No Snoop set */
3061 + PCIE_VM_MSG_ATTR_10, /* RO set, No Snoop cleared*/
3062 + PCIE_VM_MSG_ATTR_11, /* RO and No Snoop set */
3063 +};
3064 +
3065 +/* Payload Size Definition */
3066 +#define PCIE_VM_MSG_LEN_MIN 0
3067 +#define PCIE_VM_MSG_LEN_MAX 1024
3068 +
3069 +/* Vendor Message DW1 Register */
3070 +#define PCIE_VM_MSG_DW1(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x54)
3071 +#define PCIE_VM_MSG_DW1_FUNC_NUM 0x00000070 /* Function Number */
3072 +#define PCIE_VM_MSG_DW1_FUNC_NUM_S 8
3073 +#define PCIE_VM_MSG_DW1_CODE 0x00FF0000 /* Message Code */
3074 +#define PCIE_VM_MSG_DW1_CODE_S 16
3075 +#define PCIE_VM_MSG_DW1_TAG 0xFF000000 /* Tag */
3076 +#define PCIE_VM_MSG_DW1_TAG_S 24
3077 +
3078 +#define PCIE_VM_MSG_DW2(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x58)
3079 +#define PCIE_VM_MSG_DW3(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x5C)
3080 +
3081 +/* Vendor Message Request Register */
3082 +#define PCIE_VM_MSG_REQR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x60)
3083 +#define PCIE_VM_MSG_REQR_REQ 0x00000001 /* Vendor Message Request */
3084 +
3085 +
3086 +/* AHB Slave Side Band Control Register */
3087 +#define PCIE_AHB_SSB(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x70)
3088 +#define PCIE_AHB_SSB_REQ_BCM 0x00000001 /* Slave Reques BCM filed */
3089 +#define PCIE_AHB_SSB_REQ_EP 0x00000002 /* Slave Reques EP filed */
3090 +#define PCIE_AHB_SSB_REQ_TD 0x00000004 /* Slave Reques TD filed */
3091 +#define PCIE_AHB_SSB_REQ_ATTR 0x00000018 /* Slave Reques Attribute number */
3092 +#define PCIE_AHB_SSB_REQ_ATTR_S 3
3093 +#define PCIE_AHB_SSB_REQ_TC 0x000000E0 /* Slave Request TC Field */
3094 +#define PCIE_AHB_SSB_REQ_TC_S 5
3095 +
3096 +/* AHB Master SideBand Ctrl Register */
3097 +#define PCIE_AHB_MSB(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x74)
3098 +#define PCIE_AHB_MSB_RESP_ATTR 0x00000003 /* Master Response Attribute number */
3099 +#define PCIE_AHB_MSB_RESP_ATTR_S 0
3100 +#define PCIE_AHB_MSB_RESP_BAD_EOT 0x00000004 /* Master Response Badeot filed */
3101 +#define PCIE_AHB_MSB_RESP_BCM 0x00000008 /* Master Response BCM filed */
3102 +#define PCIE_AHB_MSB_RESP_EP 0x00000010 /* Master Response EP filed */
3103 +#define PCIE_AHB_MSB_RESP_TD 0x00000020 /* Master Response TD filed */
3104 +#define PCIE_AHB_MSB_RESP_FUN_NUM 0x000003C0 /* Master Response Function number */
3105 +#define PCIE_AHB_MSB_RESP_FUN_NUM_S 6
3106 +
3107 +/* AHB Control Register, fixed bus enumeration exception */
3108 +#define PCIE_AHB_CTRL(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x78)
3109 +#define PCIE_AHB_CTRL_BUS_ERROR_SUPPRESS 0x00000001
3110 +
3111 +/* Interrupt Enalbe Register */
3112 +#define PCIE_IRNEN(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0xF4)
3113 +#define PCIE_IRNCR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0xF8)
3114 +#define PCIE_IRNICR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0xFC)
3115 +
3116 +/* PCIe interrupt enable/control/capture register definition */
3117 +#define PCIE_IRN_AER_REPORT 0x00000001 /* AER Interrupt */
3118 +#define PCIE_IRN_AER_MSIX 0x00000002 /* Advanced Error MSI-X Interrupt */
3119 +#define PCIE_IRN_PME 0x00000004 /* PME Interrupt */
3120 +#define PCIE_IRN_HOTPLUG 0x00000008 /* Hotplug Interrupt */
3121 +#define PCIE_IRN_RX_VDM_MSG 0x00000010 /* Vendor-Defined Message Interrupt */
3122 +#define PCIE_IRN_RX_CORRECTABLE_ERR_MSG 0x00000020 /* Correctable Error Message Interrupt */
3123 +#define PCIE_IRN_RX_NON_FATAL_ERR_MSG 0x00000040 /* Non-fatal Error Message */
3124 +#define PCIE_IRN_RX_FATAL_ERR_MSG 0x00000080 /* Fatal Error Message */
3125 +#define PCIE_IRN_RX_PME_MSG 0x00000100 /* PME Message Interrupt */
3126 +#define PCIE_IRN_RX_PME_TURNOFF_ACK 0x00000200 /* PME Turnoff Ack Message Interrupt */
3127 +#define PCIE_IRN_AHB_BR_FATAL_ERR 0x00000400 /* AHB Fatal Error Interrupt */
3128 +#define PCIE_IRN_LINK_AUTO_BW_STATUS 0x00000800 /* Link Auto Bandwidth Status Interrupt */
3129 +#define PCIE_IRN_BW_MGT 0x00001000 /* Bandwidth Managment Interrupt */
3130 +#define PCIE_IRN_INTA 0x00002000 /* INTA */
3131 +#define PCIE_IRN_INTB 0x00004000 /* INTB */
3132 +#define PCIE_IRN_INTC 0x00008000 /* INTC */
3133 +#define PCIE_IRN_INTD 0x00010000 /* INTD */
3134 +#define PCIE_IRN_WAKEUP 0x00020000 /* Wake up Interrupt */
3135 +
3136 +#define PCIE_RC_CORE_COMBINED_INT (PCIE_IRN_AER_REPORT | PCIE_IRN_AER_MSIX | PCIE_IRN_PME | \
3137 + PCIE_IRN_HOTPLUG | PCIE_IRN_RX_VDM_MSG | PCIE_IRN_RX_CORRECTABLE_ERR_MSG |\
3138 + PCIE_IRN_RX_NON_FATAL_ERR_MSG | PCIE_IRN_RX_FATAL_ERR_MSG | \
3139 + PCIE_IRN_RX_PME_MSG | PCIE_IRN_RX_PME_TURNOFF_ACK | PCIE_IRN_AHB_BR_FATAL_ERR | \
3140 + PCIE_IRN_LINK_AUTO_BW_STATUS | PCIE_IRN_BW_MGT)
3141 +/* PCIe RC Configuration Register */
3142 +#define PCIE_VDID(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x00)
3143 +
3144 +/* Bit definition from pci_reg.h */
3145 +#define PCIE_PCICMDSTS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x04)
3146 +#define PCIE_CCRID(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x08)
3147 +#define PCIE_CLSLTHTBR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x0C) /* EP only */
3148 +/* BAR0, BAR1,Only necessary if the bridges implements a device-specific register set or memory buffer */
3149 +#define PCIE_BAR0(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x10) /* Not used*/
3150 +#define PCIE_BAR1(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x14) /* Not used */
3151 +
3152 +#define PCIE_BNR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x18) /* Mandatory */
3153 +/* Bus Number Register bits */
3154 +#define PCIE_BNR_PRIMARY_BUS_NUM 0x000000FF
3155 +#define PCIE_BNR_PRIMARY_BUS_NUM_S 0
3156 +#define PCIE_PNR_SECONDARY_BUS_NUM 0x0000FF00
3157 +#define PCIE_PNR_SECONDARY_BUS_NUM_S 8
3158 +#define PCIE_PNR_SUB_BUS_NUM 0x00FF0000
3159 +#define PCIE_PNR_SUB_BUS_NUM_S 16
3160 +
3161 +/* IO Base/Limit Register bits */
3162 +#define PCIE_IOBLSECS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x1C) /* RC only */
3163 +#define PCIE_IOBLSECS_32BIT_IO_ADDR 0x00000001
3164 +#define PCIE_IOBLSECS_IO_BASE_ADDR 0x000000F0
3165 +#define PCIE_IOBLSECS_IO_BASE_ADDR_S 4
3166 +#define PCIE_IOBLSECS_32BIT_IOLIMT 0x00000100
3167 +#define PCIE_IOBLSECS_IO_LIMIT_ADDR 0x0000F000
3168 +#define PCIE_IOBLSECS_IO_LIMIT_ADDR_S 12
3169 +
3170 +/* Non-prefetchable Memory Base/Limit Register bit */
3171 +#define PCIE_MBML(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x20) /* RC only */
3172 +#define PCIE_MBML_MEM_BASE_ADDR 0x0000FFF0
3173 +#define PCIE_MBML_MEM_BASE_ADDR_S 4
3174 +#define PCIE_MBML_MEM_LIMIT_ADDR 0xFFF00000
3175 +#define PCIE_MBML_MEM_LIMIT_ADDR_S 20
3176 +
3177 +/* Prefetchable Memory Base/Limit Register bit */
3178 +#define PCIE_PMBL(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x24) /* RC only */
3179 +#define PCIE_PMBL_64BIT_ADDR 0x00000001
3180 +#define PCIE_PMBL_UPPER_12BIT 0x0000FFF0
3181 +#define PCIE_PMBL_UPPER_12BIT_S 4
3182 +#define PCIE_PMBL_E64MA 0x00010000
3183 +#define PCIE_PMBL_END_ADDR 0xFFF00000
3184 +#define PCIE_PMBL_END_ADDR_S 20
3185 +#define PCIE_PMBU32(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x28) /* RC only */
3186 +#define PCIE_PMLU32(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x2C) /* RC only */
3187 +
3188 +/* I/O Base/Limit Upper 16 bits register */
3189 +#define PCIE_IO_BANDL(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x30) /* RC only */
3190 +#define PCIE_IO_BANDL_UPPER_16BIT_IO_BASE 0x0000FFFF
3191 +#define PCIE_IO_BANDL_UPPER_16BIT_IO_BASE_S 0
3192 +#define PCIE_IO_BANDL_UPPER_16BIT_IO_LIMIT 0xFFFF0000
3193 +#define PCIE_IO_BANDL_UPPER_16BIT_IO_LIMIT_S 16
3194 +
3195 +#define PCIE_CPR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x34)
3196 +#define PCIE_EBBAR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x38)
3197 +
3198 +/* Interrupt and Secondary Bridge Control Register */
3199 +#define PCIE_INTRBCTRL(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x3C)
3200 +
3201 +#define PCIE_INTRBCTRL_INT_LINE 0x000000FF
3202 +#define PCIE_INTRBCTRL_INT_LINE_S 0
3203 +#define PCIE_INTRBCTRL_INT_PIN 0x0000FF00
3204 +#define PCIE_INTRBCTRL_INT_PIN_S 8
3205 +#define PCIE_INTRBCTRL_PARITY_ERR_RESP_ENABLE 0x00010000 /* #PERR */
3206 +#define PCIE_INTRBCTRL_SERR_ENABLE 0x00020000 /* #SERR */
3207 +#define PCIE_INTRBCTRL_ISA_ENABLE 0x00040000 /* ISA enable, IO 64KB only */
3208 +#define PCIE_INTRBCTRL_VGA_ENABLE 0x00080000 /* VGA enable */
3209 +#define PCIE_INTRBCTRL_VGA_16BIT_DECODE 0x00100000 /* VGA 16bit decode */
3210 +#define PCIE_INTRBCTRL_RST_SECONDARY_BUS 0x00400000 /* Secondary bus rest, hot rest, 1ms */
3211 +/* Others are read only */
3212 +enum {
3213 + PCIE_INTRBCTRL_INT_NON = 0,
3214 + PCIE_INTRBCTRL_INTA,
3215 + PCIE_INTRBCTRL_INTB,
3216 + PCIE_INTRBCTRL_INTC,
3217 + PCIE_INTRBCTRL_INTD,
3218 +};
3219 +
3220 +#define PCIE_PM_CAPR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x40)
3221 +
3222 +/* Power Management Control and Status Register */
3223 +#define PCIE_PM_CSR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x44)
3224 +
3225 +#define PCIE_PM_CSR_POWER_STATE 0x00000003 /* Power State */
3226 +#define PCIE_PM_CSR_POWER_STATE_S 0
3227 +#define PCIE_PM_CSR_SW_RST 0x00000008 /* Soft Reset Enabled */
3228 +#define PCIE_PM_CSR_PME_ENABLE 0x00000100 /* PME Enable */
3229 +#define PCIE_PM_CSR_PME_STATUS 0x00008000 /* PME status */
3230 +
3231 +/* MSI Capability Register for EP */
3232 +#define PCIE_MCAPR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x50)
3233 +
3234 +#define PCIE_MCAPR_MSI_CAP_ID 0x000000FF /* MSI Capability ID */
3235 +#define PCIE_MCAPR_MSI_CAP_ID_S 0
3236 +#define PCIE_MCAPR_MSI_NEXT_CAP_PTR 0x0000FF00 /* Next Capability Pointer */
3237 +#define PCIE_MCAPR_MSI_NEXT_CAP_PTR_S 8
3238 +#define PCIE_MCAPR_MSI_ENABLE 0x00010000 /* MSI Enable */
3239 +#define PCIE_MCAPR_MULTI_MSG_CAP 0x000E0000 /* Multiple Message Capable */
3240 +#define PCIE_MCAPR_MULTI_MSG_CAP_S 17
3241 +#define PCIE_MCAPR_MULTI_MSG_ENABLE 0x00700000 /* Multiple Message Enable */
3242 +#define PCIE_MCAPR_MULTI_MSG_ENABLE_S 20
3243 +#define PCIE_MCAPR_ADDR64_CAP 0X00800000 /* 64-bit Address Capable */
3244 +
3245 +/* MSI Message Address Register */
3246 +#define PCIE_MA(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x54)
3247 +
3248 +#define PCIE_MA_ADDR_MASK 0xFFFFFFFC /* Message Address */
3249 +
3250 +/* MSI Message Upper Address Register */
3251 +#define PCIE_MUA(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x58)
3252 +
3253 +/* MSI Message Data Register */
3254 +#define PCIE_MD(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x5C)
3255 +
3256 +#define PCIE_MD_DATA 0x0000FFFF /* Message Data */
3257 +#define PCIE_MD_DATA_S 0
3258 +
3259 +/* PCI Express Capability Register */
3260 +#define PCIE_XCAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x70)
3261 +
3262 +#define PCIE_XCAP_ID 0x000000FF /* PCI Express Capability ID */
3263 +#define PCIE_XCAP_ID_S 0
3264 +#define PCIE_XCAP_NEXT_CAP 0x0000FF00 /* Next Capability Pointer */
3265 +#define PCIE_XCAP_NEXT_CAP_S 8
3266 +#define PCIE_XCAP_VER 0x000F0000 /* PCI Express Capability Version */
3267 +#define PCIE_XCAP_VER_S 16
3268 +#define PCIE_XCAP_DEV_PORT_TYPE 0x00F00000 /* Device Port Type */
3269 +#define PCIE_XCAP_DEV_PORT_TYPE_S 20
3270 +#define PCIE_XCAP_SLOT_IMPLEMENTED 0x01000000 /* Slot Implemented */
3271 +#define PCIE_XCAP_MSG_INT_NUM 0x3E000000 /* Interrupt Message Number */
3272 +#define PCIE_XCAP_MSG_INT_NUM_S 25
3273 +
3274 +/* Device Capability Register */
3275 +#define PCIE_DCAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x74)
3276 +
3277 +#define PCIE_DCAP_MAX_PAYLOAD_SIZE 0x00000007 /* Max Payload size */
3278 +#define PCIE_DCAP_MAX_PAYLOAD_SIZE_S 0
3279 +#define PCIE_DCAP_PHANTOM_FUNC 0x00000018 /* Phanton Function, not supported */
3280 +#define PCIE_DCAP_PHANTOM_FUNC_S 3
3281 +#define PCIE_DCAP_EXT_TAG 0x00000020 /* Extended Tag Field */
3282 +#define PCIE_DCAP_EP_L0S_LATENCY 0x000001C0 /* EP L0s latency only */
3283 +#define PCIE_DCAP_EP_L0S_LATENCY_S 6
3284 +#define PCIE_DCAP_EP_L1_LATENCY 0x00000E00 /* EP L1 latency only */
3285 +#define PCIE_DCAP_EP_L1_LATENCY_S 9
3286 +#define PCIE_DCAP_ROLE_BASE_ERR_REPORT 0x00008000 /* Role Based ERR */
3287 +
3288 +/* Maximum payload size supported */
3289 +enum {
3290 + PCIE_MAX_PAYLOAD_128 = 0,
3291 + PCIE_MAX_PAYLOAD_256,
3292 + PCIE_MAX_PAYLOAD_512,
3293 + PCIE_MAX_PAYLOAD_1024,
3294 + PCIE_MAX_PAYLOAD_2048,
3295 + PCIE_MAX_PAYLOAD_4096,
3296 +};
3297 +
3298 +/* Device Control and Status Register */
3299 +#define PCIE_DCTLSTS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x78)
3300 +
3301 +#define PCIE_DCTLSTS_CORRECTABLE_ERR_EN 0x00000001 /* COR-ERR */
3302 +#define PCIE_DCTLSTS_NONFATAL_ERR_EN 0x00000002 /* Non-fatal ERR */
3303 +#define PCIE_DCTLSTS_FATAL_ERR_EN 0x00000004 /* Fatal ERR */
3304 +#define PCIE_DCTLSYS_UR_REQ_EN 0x00000008 /* UR ERR */
3305 +#define PCIE_DCTLSTS_RELAXED_ORDERING_EN 0x00000010 /* Enable relaxing ordering */
3306 +#define PCIE_DCTLSTS_MAX_PAYLOAD_SIZE 0x000000E0 /* Max payload mask */
3307 +#define PCIE_DCTLSTS_MAX_PAYLOAD_SIZE_S 5
3308 +#define PCIE_DCTLSTS_EXT_TAG_EN 0x00000100 /* Extended tag field */
3309 +#define PCIE_DCTLSTS_PHANTOM_FUNC_EN 0x00000200 /* Phantom Function Enable */
3310 +#define PCIE_DCTLSTS_AUX_PM_EN 0x00000400 /* AUX Power PM Enable */
3311 +#define PCIE_DCTLSTS_NO_SNOOP_EN 0x00000800 /* Enable no snoop, except root port*/
3312 +#define PCIE_DCTLSTS_MAX_READ_SIZE 0x00007000 /* Max Read Request size*/
3313 +#define PCIE_DCTLSTS_MAX_READ_SIZE_S 12
3314 +#define PCIE_DCTLSTS_CORRECTABLE_ERR 0x00010000 /* COR-ERR Detected */
3315 +#define PCIE_DCTLSTS_NONFATAL_ERR 0x00020000 /* Non-Fatal ERR Detected */
3316 +#define PCIE_DCTLSTS_FATAL_ER 0x00040000 /* Fatal ERR Detected */
3317 +#define PCIE_DCTLSTS_UNSUPPORTED_REQ 0x00080000 /* UR Detected */
3318 +#define PCIE_DCTLSTS_AUX_POWER 0x00100000 /* Aux Power Detected */
3319 +#define PCIE_DCTLSTS_TRANSACT_PENDING 0x00200000 /* Transaction pending */
3320 +
3321 +#define PCIE_DCTLSTS_ERR_EN (PCIE_DCTLSTS_CORRECTABLE_ERR_EN | \
3322 + PCIE_DCTLSTS_NONFATAL_ERR_EN | PCIE_DCTLSTS_FATAL_ERR_EN | \
3323 + PCIE_DCTLSYS_UR_REQ_EN)
3324 +
3325 +/* Link Capability Register */
3326 +#define PCIE_LCAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x7C)
3327 +#define PCIE_LCAP_MAX_LINK_SPEED 0x0000000F /* Max link speed, 0x1 by default */
3328 +#define PCIE_LCAP_MAX_LINK_SPEED_S 0
3329 +#define PCIE_LCAP_MAX_LENGTH_WIDTH 0x000003F0 /* Maxium Length Width */
3330 +#define PCIE_LCAP_MAX_LENGTH_WIDTH_S 4
3331 +#define PCIE_LCAP_ASPM_LEVEL 0x00000C00 /* Active State Link PM Support */
3332 +#define PCIE_LCAP_ASPM_LEVEL_S 10
3333 +#define PCIE_LCAP_L0S_EIXT_LATENCY 0x00007000 /* L0s Exit Latency */
3334 +#define PCIE_LCAP_L0S_EIXT_LATENCY_S 12
3335 +#define PCIE_LCAP_L1_EXIT_LATENCY 0x00038000 /* L1 Exit Latency */
3336 +#define PCIE_LCAP_L1_EXIT_LATENCY_S 15
3337 +#define PCIE_LCAP_CLK_PM 0x00040000 /* Clock Power Management */
3338 +#define PCIE_LCAP_SDER 0x00080000 /* Surprise Down Error Reporting */
3339 +#define PCIE_LCAP_DLL_ACTIVE_REPROT 0x00100000 /* Data Link Layer Active Reporting Capable */
3340 +#define PCIE_LCAP_PORT_NUM 0xFF0000000 /* Port number */
3341 +#define PCIE_LCAP_PORT_NUM_S 24
3342 +
3343 +/* Maximum Length width definition */
3344 +#define PCIE_MAX_LENGTH_WIDTH_RES 0x00
3345 +#define PCIE_MAX_LENGTH_WIDTH_X1 0x01 /* Default */
3346 +#define PCIE_MAX_LENGTH_WIDTH_X2 0x02
3347 +#define PCIE_MAX_LENGTH_WIDTH_X4 0x04
3348 +#define PCIE_MAX_LENGTH_WIDTH_X8 0x08
3349 +#define PCIE_MAX_LENGTH_WIDTH_X12 0x0C
3350 +#define PCIE_MAX_LENGTH_WIDTH_X16 0x10
3351 +#define PCIE_MAX_LENGTH_WIDTH_X32 0x20
3352 +
3353 +/* Active State Link PM definition */
3354 +enum {
3355 + PCIE_ASPM_RES0 = 0,
3356 + PCIE_ASPM_L0S_ENTRY_SUPPORT, /* L0s */
3357 + PCIE_ASPM_RES1,
3358 + PCIE_ASPM_L0S_L1_ENTRY_SUPPORT, /* L0s and L1, default */
3359 +};
3360 +
3361 +/* L0s Exit Latency definition */
3362 +enum {
3363 + PCIE_L0S_EIXT_LATENCY_L64NS = 0, /* < 64 ns */
3364 + PCIE_L0S_EIXT_LATENCY_B64A128, /* > 64 ns < 128 ns */
3365 + PCIE_L0S_EIXT_LATENCY_B128A256, /* > 128 ns < 256 ns */
3366 + PCIE_L0S_EIXT_LATENCY_B256A512, /* > 256 ns < 512 ns */
3367 + PCIE_L0S_EIXT_LATENCY_B512TO1U, /* > 512 ns < 1 us */
3368 + PCIE_L0S_EIXT_LATENCY_B1A2U, /* > 1 us < 2 us */
3369 + PCIE_L0S_EIXT_LATENCY_B2A4U, /* > 2 us < 4 us */
3370 + PCIE_L0S_EIXT_LATENCY_M4US, /* > 4 us */
3371 +};
3372 +
3373 +/* L1 Exit Latency definition */
3374 +enum {
3375 + PCIE_L1_EXIT_LATENCY_L1US = 0, /* < 1 us */
3376 + PCIE_L1_EXIT_LATENCY_B1A2, /* > 1 us < 2 us */
3377 + PCIE_L1_EXIT_LATENCY_B2A4, /* > 2 us < 4 us */
3378 + PCIE_L1_EXIT_LATENCY_B4A8, /* > 4 us < 8 us */
3379 + PCIE_L1_EXIT_LATENCY_B8A16, /* > 8 us < 16 us */
3380 + PCIE_L1_EXIT_LATENCY_B16A32, /* > 16 us < 32 us */
3381 + PCIE_L1_EXIT_LATENCY_B32A64, /* > 32 us < 64 us */
3382 + PCIE_L1_EXIT_LATENCY_M64US, /* > 64 us */
3383 +};
3384 +
3385 +/* Link Control and Status Register */
3386 +#define PCIE_LCTLSTS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x80)
3387 +#define PCIE_LCTLSTS_ASPM_ENABLE 0x00000003 /* Active State Link PM Control */
3388 +#define PCIE_LCTLSTS_ASPM_ENABLE_S 0
3389 +#define PCIE_LCTLSTS_RCB128 0x00000008 /* Read Completion Boundary 128*/
3390 +#define PCIE_LCTLSTS_LINK_DISABLE 0x00000010 /* Link Disable */
3391 +#define PCIE_LCTLSTS_RETRIAN_LINK 0x00000020 /* Retrain Link */
3392 +#define PCIE_LCTLSTS_COM_CLK_CFG 0x00000040 /* Common Clock Configuration */
3393 +#define PCIE_LCTLSTS_EXT_SYNC 0x00000080 /* Extended Synch */
3394 +#define PCIE_LCTLSTS_CLK_PM_EN 0x00000100 /* Enable Clock Powerm Management */
3395 +#define PCIE_LCTLSTS_LINK_SPEED 0x000F0000 /* Link Speed */
3396 +#define PCIE_LCTLSTS_LINK_SPEED_S 16
3397 +#define PCIE_LCTLSTS_NEGOTIATED_LINK_WIDTH 0x03F00000 /* Negotiated Link Width */
3398 +#define PCIE_LCTLSTS_NEGOTIATED_LINK_WIDTH_S 20
3399 +#define PCIE_LCTLSTS_RETRAIN_PENDING 0x08000000 /* Link training is ongoing */
3400 +#define PCIE_LCTLSTS_SLOT_CLK_CFG 0x10000000 /* Slot Clock Configuration */
3401 +#define PCIE_LCTLSTS_DLL_ACTIVE 0x20000000 /* Data Link Layer Active */
3402 +
3403 +/* Slot Capabilities Register */
3404 +#define PCIE_SLCAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x84)
3405 +
3406 +/* Slot Capabilities */
3407 +#define PCIE_SLCTLSTS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x88)
3408 +
3409 +/* Root Control and Capability Register */
3410 +#define PCIE_RCTLCAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x8C)
3411 +#define PCIE_RCTLCAP_SERR_ON_CORRECTABLE_ERR 0x00000001 /* #SERR on COR-ERR */
3412 +#define PCIE_RCTLCAP_SERR_ON_NONFATAL_ERR 0x00000002 /* #SERR on Non-Fatal ERR */
3413 +#define PCIE_RCTLCAP_SERR_ON_FATAL_ERR 0x00000004 /* #SERR on Fatal ERR */
3414 +#define PCIE_RCTLCAP_PME_INT_EN 0x00000008 /* PME Interrupt Enable */
3415 +#define PCIE_RCTLCAP_SERR_ENABLE (PCIE_RCTLCAP_SERR_ON_CORRECTABLE_ERR | \
3416 + PCIE_RCTLCAP_SERR_ON_NONFATAL_ERR | PCIE_RCTLCAP_SERR_ON_FATAL_ERR)
3417 +/* Root Status Register */
3418 +#define PCIE_RSTS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x90)
3419 +#define PCIE_RSTS_PME_REQ_ID 0x0000FFFF /* PME Request ID */
3420 +#define PCIE_RSTS_PME_REQ_ID_S 0
3421 +#define PCIE_RSTS_PME_STATUS 0x00010000 /* PME Status */
3422 +#define PCIE_RSTS_PME_PENDING 0x00020000 /* PME Pending */
3423 +
3424 +/* PCI Express Enhanced Capability Header */
3425 +#define PCIE_ENHANCED_CAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x100)
3426 +#define PCIE_ENHANCED_CAP_ID 0x0000FFFF /* PCI Express Extended Capability ID */
3427 +#define PCIE_ENHANCED_CAP_ID_S 0
3428 +#define PCIE_ENHANCED_CAP_VER 0x000F0000 /* Capability Version */
3429 +#define PCIE_ENHANCED_CAP_VER_S 16
3430 +#define PCIE_ENHANCED_CAP_NEXT_OFFSET 0xFFF00000 /* Next Capability Offset */
3431 +#define PCIE_ENHANCED_CAP_NEXT_OFFSET_S 20
3432 +
3433 +/* Uncorrectable Error Status Register */
3434 +#define PCIE_UES_R(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x104)
3435 +#define PCIE_DATA_LINK_PROTOCOL_ERR 0x00000010 /* Data Link Protocol Error Status */
3436 +#define PCIE_SURPRISE_DOWN_ERROR 0x00000020 /* Surprise Down Error Status */
3437 +#define PCIE_POISONED_TLP 0x00001000 /* Poisoned TLP Status */
3438 +#define PCIE_FC_PROTOCOL_ERR 0x00002000 /* Flow Control Protocol Error Status */
3439 +#define PCIE_COMPLETION_TIMEOUT 0x00004000 /* Completion Timeout Status */
3440 +#define PCIE_COMPLETOR_ABORT 0x00008000 /* Completer Abort Error */
3441 +#define PCIE_UNEXPECTED_COMPLETION 0x00010000 /* Unexpected Completion Status */
3442 +#define PCIE_RECEIVER_OVERFLOW 0x00020000 /* Receive Overflow Status */
3443 +#define PCIE_MALFORNED_TLP 0x00040000 /* Malformed TLP Stauts */
3444 +#define PCIE_ECRC_ERR 0x00080000 /* ECRC Error Stauts */
3445 +#define PCIE_UR_REQ 0x00100000 /* Unsupported Request Error Status */
3446 +#define PCIE_ALL_UNCORRECTABLE_ERR (PCIE_DATA_LINK_PROTOCOL_ERR | PCIE_SURPRISE_DOWN_ERROR | \
3447 + PCIE_POISONED_TLP | PCIE_FC_PROTOCOL_ERR | PCIE_COMPLETION_TIMEOUT | \
3448 + PCIE_COMPLETOR_ABORT | PCIE_UNEXPECTED_COMPLETION | PCIE_RECEIVER_OVERFLOW |\
3449 + PCIE_MALFORNED_TLP | PCIE_ECRC_ERR | PCIE_UR_REQ)
3450 +
3451 +/* Uncorrectable Error Mask Register, Mask means no report */
3452 +#define PCIE_UEMR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x108)
3453 +
3454 +/* Uncorrectable Error Severity Register */
3455 +#define PCIE_UESR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x10C)
3456 +
3457 +/* Correctable Error Status Register */
3458 +#define PCIE_CESR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x110)
3459 +#define PCIE_RX_ERR 0x00000001 /* Receive Error Status */
3460 +#define PCIE_BAD_TLP 0x00000040 /* Bad TLP Status */
3461 +#define PCIE_BAD_DLLP 0x00000080 /* Bad DLLP Status */
3462 +#define PCIE_REPLAY_NUM_ROLLOVER 0x00000100 /* Replay Number Rollover Status */
3463 +#define PCIE_REPLAY_TIMER_TIMEOUT_ERR 0x00001000 /* Reply Timer Timeout Status */
3464 +#define PCIE_ADVISORY_NONFTAL_ERR 0x00002000 /* Advisory Non-Fatal Error Status */
3465 +#define PCIE_CORRECTABLE_ERR (PCIE_RX_ERR | PCIE_BAD_TLP | PCIE_BAD_DLLP | PCIE_REPLAY_NUM_ROLLOVER |\
3466 + PCIE_REPLAY_TIMER_TIMEOUT_ERR | PCIE_ADVISORY_NONFTAL_ERR)
3467 +
3468 +/* Correctable Error Mask Register */
3469 +#define PCIE_CEMR(X) (volatile u32*)(PCIE_RC_CFG_BASE + 0x114)
3470 +
3471 +/* Advanced Error Capabilities and Control Register */
3472 +#define PCIE_AECCR(X) (volatile u32*)(PCIE_RC_CFG_BASE + 0x118)
3473 +#define PCIE_AECCR_FIRST_ERR_PTR 0x0000001F /* First Error Pointer */
3474 +#define PCIE_AECCR_FIRST_ERR_PTR_S 0
3475 +#define PCIE_AECCR_ECRC_GEN_CAP 0x00000020 /* ECRC Generation Capable */
3476 +#define PCIE_AECCR_ECRC_GEN_EN 0x00000040 /* ECRC Generation Enable */
3477 +#define PCIE_AECCR_ECRC_CHECK_CAP 0x00000080 /* ECRC Check Capable */
3478 +#define PCIE_AECCR_ECRC_CHECK_EN 0x00000100 /* ECRC Check Enable */
3479 +
3480 +/* Header Log Register 1 */
3481 +#define PCIE_HLR1(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x11C)
3482 +
3483 +/* Header Log Register 2 */
3484 +#define PCIE_HLR2(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x120)
3485 +
3486 +/* Header Log Register 3 */
3487 +#define PCIE_HLR3(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x124)
3488 +
3489 +/* Header Log Register 4 */
3490 +#define PCIE_HLR4(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x128)
3491 +
3492 +/* Root Error Command Register */
3493 +#define PCIE_RECR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x12C)
3494 +#define PCIE_RECR_CORRECTABLE_ERR_REPORT_EN 0x00000001 /* COR-ERR */
3495 +#define PCIE_RECR_NONFATAL_ERR_REPORT_EN 0x00000002 /* Non-Fatal ERR */
3496 +#define PCIE_RECR_FATAL_ERR_REPORT_EN 0x00000004 /* Fatal ERR */
3497 +#define PCIE_RECR_ERR_REPORT_EN (PCIE_RECR_CORRECTABLE_ERR_REPORT_EN | \
3498 + PCIE_RECR_NONFATAL_ERR_REPORT_EN | PCIE_RECR_FATAL_ERR_REPORT_EN)
3499 +
3500 +/* Root Error Status Register */
3501 +#define PCIE_RESR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x130)
3502 +#define PCIE_RESR_CORRECTABLE_ERR 0x00000001 /* COR-ERR Receveid */
3503 +#define PCIE_RESR_MULTI_CORRECTABLE_ERR 0x00000002 /* Multiple COR-ERR Received */
3504 +#define PCIE_RESR_FATAL_NOFATAL_ERR 0x00000004 /* ERR Fatal/Non-Fatal Received */
3505 +#define PCIE_RESR_MULTI_FATAL_NOFATAL_ERR 0x00000008 /* Multiple ERR Fatal/Non-Fatal Received */
3506 +#define PCIE_RESR_FIRST_UNCORRECTABLE_FATAL_ERR 0x00000010 /* First UN-COR Fatal */
3507 +#define PCIR_RESR_NON_FATAL_ERR 0x00000020 /* Non-Fatal Error Message Received */
3508 +#define PCIE_RESR_FATAL_ERR 0x00000040 /* Fatal Message Received */
3509 +#define PCIE_RESR_AER_INT_MSG_NUM 0xF8000000 /* Advanced Error Interrupt Message Number */
3510 +#define PCIE_RESR_AER_INT_MSG_NUM_S 27
3511 +
3512 +/* Error Source Indentification Register */
3513 +#define PCIE_ESIR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x134)
3514 +#define PCIE_ESIR_CORRECTABLE_ERR_SRC_ID 0x0000FFFF
3515 +#define PCIE_ESIR_CORRECTABLE_ERR_SRC_ID_S 0
3516 +#define PCIE_ESIR_FATAL_NON_FATAL_SRC_ID 0xFFFF0000
3517 +#define PCIE_ESIR_FATAL_NON_FATAL_SRC_ID_S 16
3518 +
3519 +/* VC Enhanced Capability Header */
3520 +#define PCIE_VC_ECH(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x140)
3521 +
3522 +/* Port VC Capability Register */
3523 +#define PCIE_PVC1(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x144)
3524 +#define PCIE_PVC1_EXT_VC_CNT 0x00000007 /* Extended VC Count */
3525 +#define PCIE_PVC1_EXT_VC_CNT_S 0
3526 +#define PCIE_PVC1_LOW_PRI_EXT_VC_CNT 0x00000070 /* Low Priority Extended VC Count */
3527 +#define PCIE_PVC1_LOW_PRI_EXT_VC_CNT_S 4
3528 +#define PCIE_PVC1_REF_CLK 0x00000300 /* Reference Clock */
3529 +#define PCIE_PVC1_REF_CLK_S 8
3530 +#define PCIE_PVC1_PORT_ARB_TAB_ENTRY_SIZE 0x00000C00 /* Port Arbitration Table Entry Size */
3531 +#define PCIE_PVC1_PORT_ARB_TAB_ENTRY_SIZE_S 10
3532 +
3533 +/* Extended Virtual Channel Count Defintion */
3534 +#define PCIE_EXT_VC_CNT_MIN 0
3535 +#define PCIE_EXT_VC_CNT_MAX 7
3536 +
3537 +/* Port Arbitration Table Entry Size Definition */
3538 +enum {
3539 + PCIE_PORT_ARB_TAB_ENTRY_SIZE_S1BIT = 0,
3540 + PCIE_PORT_ARB_TAB_ENTRY_SIZE_S2BIT,
3541 + PCIE_PORT_ARB_TAB_ENTRY_SIZE_S4BIT,
3542 + PCIE_PORT_ARB_TAB_ENTRY_SIZE_S8BIT,
3543 +};
3544 +
3545 +/* Port VC Capability Register 2 */
3546 +#define PCIE_PVC2(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x148)
3547 +#define PCIE_PVC2_VC_ARB_16P_FIXED_WRR 0x00000001 /* HW Fixed arbitration, 16 phase WRR */
3548 +#define PCIE_PVC2_VC_ARB_32P_WRR 0x00000002 /* 32 phase WRR */
3549 +#define PCIE_PVC2_VC_ARB_64P_WRR 0x00000004 /* 64 phase WRR */
3550 +#define PCIE_PVC2_VC_ARB_128P_WRR 0x00000008 /* 128 phase WRR */
3551 +#define PCIE_PVC2_VC_ARB_WRR 0x0000000F
3552 +#define PCIE_PVC2_VC_ARB_TAB_OFFSET 0xFF000000 /* VC arbitration table offset, not support */
3553 +#define PCIE_PVC2_VC_ARB_TAB_OFFSET_S 24
3554 +
3555 +/* Port VC Control and Status Register */
3556 +#define PCIE_PVCCRSR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x14C)
3557 +#define PCIE_PVCCRSR_LOAD_VC_ARB_TAB 0x00000001 /* Load VC Arbitration Table */
3558 +#define PCIE_PVCCRSR_VC_ARB_SEL 0x0000000E /* VC Arbitration Select */
3559 +#define PCIE_PVCCRSR_VC_ARB_SEL_S 1
3560 +#define PCIE_PVCCRSR_VC_ARB_TAB_STATUS 0x00010000 /* Arbitration Status */
3561 +
3562 +/* VC0 Resource Capability Register */
3563 +#define PCIE_VC0_RC(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x150)
3564 +#define PCIE_VC0_RC_PORT_ARB_HW_FIXED 0x00000001 /* HW Fixed arbitration */
3565 +#define PCIE_VC0_RC_PORT_ARB_32P_WRR 0x00000002 /* 32 phase WRR */
3566 +#define PCIE_VC0_RC_PORT_ARB_64P_WRR 0x00000004 /* 64 phase WRR */
3567 +#define PCIE_VC0_RC_PORT_ARB_128P_WRR 0x00000008 /* 128 phase WRR */
3568 +#define PCIE_VC0_RC_PORT_ARB_TM_128P_WRR 0x00000010 /* Time-based 128 phase WRR */
3569 +#define PCIE_VC0_RC_PORT_ARB_TM_256P_WRR 0x00000020 /* Time-based 256 phase WRR */
3570 +#define PCIE_VC0_RC_PORT_ARB (PCIE_VC0_RC_PORT_ARB_HW_FIXED | PCIE_VC0_RC_PORT_ARB_32P_WRR |\
3571 + PCIE_VC0_RC_PORT_ARB_64P_WRR | PCIE_VC0_RC_PORT_ARB_128P_WRR | \
3572 + PCIE_VC0_RC_PORT_ARB_TM_128P_WRR | PCIE_VC0_RC_PORT_ARB_TM_256P_WRR)
3573 +
3574 +#define PCIE_VC0_RC_REJECT_SNOOP 0x00008000 /* Reject Snoop Transactioin */
3575 +#define PCIE_VC0_RC_MAX_TIMESLOTS 0x007F0000 /* Maximum time Slots */
3576 +#define PCIE_VC0_RC_MAX_TIMESLOTS_S 16
3577 +#define PCIE_VC0_RC_PORT_ARB_TAB_OFFSET 0xFF000000 /* Port Arbitration Table Offset */
3578 +#define PCIE_VC0_RC_PORT_ARB_TAB_OFFSET_S 24
3579 +
3580 +/* VC0 Resource Control Register */
3581 +#define PCIE_VC0_RC0(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x154)
3582 +#define PCIE_VC0_RC0_TVM0 0x00000001 /* TC0 and VC0 */
3583 +#define PCIE_VC0_RC0_TVM1 0x00000002 /* TC1 and VC1 */
3584 +#define PCIE_VC0_RC0_TVM2 0x00000004 /* TC2 and VC2 */
3585 +#define PCIE_VC0_RC0_TVM3 0x00000008 /* TC3 and VC3 */
3586 +#define PCIE_VC0_RC0_TVM4 0x00000010 /* TC4 and VC4 */
3587 +#define PCIE_VC0_RC0_TVM5 0x00000020 /* TC5 and VC5 */
3588 +#define PCIE_VC0_RC0_TVM6 0x00000040 /* TC6 and VC6 */
3589 +#define PCIE_VC0_RC0_TVM7 0x00000080 /* TC7 and VC7 */
3590 +#define PCIE_VC0_RC0_TC_VC 0x000000FF /* TC/VC mask */
3591 +
3592 +#define PCIE_VC0_RC0_LOAD_PORT_ARB_TAB 0x00010000 /* Load Port Arbitration Table */
3593 +#define PCIE_VC0_RC0_PORT_ARB_SEL 0x000E0000 /* Port Arbitration Select */
3594 +#define PCIE_VC0_RC0_PORT_ARB_SEL_S 17
3595 +#define PCIE_VC0_RC0_VC_ID 0x07000000 /* VC ID */
3596 +#define PCIE_VC0_RC0_VC_ID_S 24
3597 +#define PCIE_VC0_RC0_VC_EN 0x80000000 /* VC Enable */
3598 +
3599 +/* VC0 Resource Status Register */
3600 +#define PCIE_VC0_RSR0(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x158)
3601 +#define PCIE_VC0_RSR0_PORT_ARB_TAB_STATUS 0x00010000 /* Port Arbitration Table Status,not used */
3602 +#define PCIE_VC0_RSR0_VC_NEG_PENDING 0x00020000 /* VC Negotiation Pending */
3603 +
3604 +/* Ack Latency Timer and Replay Timer Register */
3605 +#define PCIE_ALTRT(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x700)
3606 +#define PCIE_ALTRT_ROUND_TRIP_LATENCY_LIMIT 0x0000FFFF /* Round Trip Latency Time Limit */
3607 +#define PCIE_ALTRT_ROUND_TRIP_LATENCY_LIMIT_S 0
3608 +#define PCIE_ALTRT_REPLAY_TIME_LIMIT 0xFFFF0000 /* Replay Time Limit */
3609 +#define PCIE_ALTRT_REPLAY_TIME_LIMIT_S 16
3610 +
3611 +/* Other Message Register */
3612 +#define PCIE_OMR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x704)
3613 +
3614 +/* Port Force Link Register */
3615 +#define PCIE_PFLR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x708)
3616 +#define PCIE_PFLR_LINK_NUM 0x000000FF /* Link Number */
3617 +#define PCIE_PFLR_LINK_NUM_S 0
3618 +#define PCIE_PFLR_FORCE_LINK 0x00008000 /* Force link */
3619 +#define PCIE_PFLR_LINK_STATE 0x003F0000 /* Link State */
3620 +#define PCIE_PFLR_LINK_STATE_S 16
3621 +#define PCIE_PFLR_LOW_POWER_ENTRY_CNT 0xFF000000 /* Low Power Entrance Count, only for EP */
3622 +#define PCIE_PFLR_LOW_POWER_ENTRY_CNT_S 24
3623 +
3624 +/* Ack Frequency Register */
3625 +#define PCIE_AFR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x70C)
3626 +#define PCIE_AFR_AF 0x000000FF /* Ack Frequency */
3627 +#define PCIE_AFR_AF_S 0
3628 +#define PCIE_AFR_FTS_NUM 0x0000FF00 /* The number of Fast Training Sequence from L0S to L0 */
3629 +#define PCIE_AFR_FTS_NUM_S 8
3630 +#define PCIE_AFR_COM_FTS_NUM 0x00FF0000 /* N_FTS; when common clock is used*/
3631 +#define PCIE_AFR_COM_FTS_NUM_S 16
3632 +#define PCIE_AFR_L0S_ENTRY_LATENCY 0x07000000 /* L0s Entrance Latency */
3633 +#define PCIE_AFR_L0S_ENTRY_LATENCY_S 24
3634 +#define PCIE_AFR_L1_ENTRY_LATENCY 0x38000000 /* L1 Entrance Latency */
3635 +#define PCIE_AFR_L1_ENTRY_LATENCY_S 27
3636 +#define PCIE_AFR_FTS_NUM_DEFAULT 32
3637 +#define PCIE_AFR_L0S_ENTRY_LATENCY_DEFAULT 7
3638 +#define PCIE_AFR_L1_ENTRY_LATENCY_DEFAULT 5
3639 +
3640 +/* Port Link Control Register */
3641 +#define PCIE_PLCR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x710)
3642 +#define PCIE_PLCR_OTHER_MSG_REQ 0x00000001 /* Other Message Request */
3643 +#define PCIE_PLCR_SCRAMBLE_DISABLE 0x00000002 /* Scramble Disable */
3644 +#define PCIE_PLCR_LOOPBACK_EN 0x00000004 /* Loopback Enable */
3645 +#define PCIE_PLCR_LTSSM_HOT_RST 0x00000008 /* Force LTSSM to the hot reset */
3646 +#define PCIE_PLCR_DLL_LINK_EN 0x00000020 /* Enable Link initialization */
3647 +#define PCIE_PLCR_FAST_LINK_SIM_EN 0x00000080 /* Sets all internal timers to fast mode for simulation purposes */
3648 +#define PCIE_PLCR_LINK_MODE 0x003F0000 /* Link Mode Enable Mask */
3649 +#define PCIE_PLCR_LINK_MODE_S 16
3650 +#define PCIE_PLCR_CORRUPTED_CRC_EN 0x02000000 /* Enabled Corrupt CRC */
3651 +
3652 +/* Lane Skew Register */
3653 +#define PCIE_LSR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x714)
3654 +#define PCIE_LSR_LANE_SKEW_NUM 0x00FFFFFF /* Insert Lane Skew for Transmit, not applicable */
3655 +#define PCIE_LSR_LANE_SKEW_NUM_S 0
3656 +#define PCIE_LSR_FC_DISABLE 0x01000000 /* Disable of Flow Control */
3657 +#define PCIE_LSR_ACKNAK_DISABLE 0x02000000 /* Disable of Ack/Nak */
3658 +#define PCIE_LSR_LANE_DESKEW_DISABLE 0x80000000 /* Disable of Lane-to-Lane Skew */
3659 +
3660 +/* Symbol Number Register */
3661 +#define PCIE_SNR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x718)
3662 +#define PCIE_SNR_TS 0x0000000F /* Number of TS Symbol */
3663 +#define PCIE_SNR_TS_S 0
3664 +#define PCIE_SNR_SKP 0x00000700 /* Number of SKP Symbol */
3665 +#define PCIE_SNR_SKP_S 8
3666 +#define PCIE_SNR_REPLAY_TIMER 0x0007C000 /* Timer Modifier for Replay Timer */
3667 +#define PCIE_SNR_REPLAY_TIMER_S 14
3668 +#define PCIE_SNR_ACKNAK_LATENCY_TIMER 0x00F80000 /* Timer Modifier for Ack/Nak Latency Timer */
3669 +#define PCIE_SNR_ACKNAK_LATENCY_TIMER_S 19
3670 +#define PCIE_SNR_FC_TIMER 0x1F000000 /* Timer Modifier for Flow Control Watchdog Timer */
3671 +#define PCIE_SNR_FC_TIMER_S 28
3672 +
3673 +/* Symbol Timer Register and Filter Mask Register 1 */
3674 +#define PCIE_STRFMR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x71C)
3675 +#define PCIE_STRFMR_SKP_INTERVAL 0x000007FF /* SKP lnterval Value */
3676 +#define PCIE_STRFMR_SKP_INTERVAL_S 0
3677 +#define PCIE_STRFMR_FC_WDT_DISABLE 0x00008000 /* Disable of FC Watchdog Timer */
3678 +#define PCIE_STRFMR_TLP_FUNC_MISMATCH_OK 0x00010000 /* Mask Function Mismatch Filtering for Incoming Requests */
3679 +#define PCIE_STRFMR_POISONED_TLP_OK 0x00020000 /* Mask Poisoned TLP Filtering */
3680 +#define PCIE_STRFMR_BAR_MATCH_OK 0x00040000 /* Mask BAR Match Filtering */
3681 +#define PCIE_STRFMR_TYPE1_CFG_REQ_OK 0x00080000 /* Mask Type 1 Configuration Request Filtering */
3682 +#define PCIE_STRFMR_LOCKED_REQ_OK 0x00100000 /* Mask Locked Request Filtering */
3683 +#define PCIE_STRFMR_CPL_TAG_ERR_RULES_OK 0x00200000 /* Mask Tag Error Rules for Received Completions */
3684 +#define PCIE_STRFMR_CPL_REQUESTOR_ID_MISMATCH_OK 0x00400000 /* Mask Requester ID Mismatch Error for Received Completions */
3685 +#define PCIE_STRFMR_CPL_FUNC_MISMATCH_OK 0x00800000 /* Mask Function Mismatch Error for Received Completions */
3686 +#define PCIE_STRFMR_CPL_TC_MISMATCH_OK 0x01000000 /* Mask Traffic Class Mismatch Error for Received Completions */
3687 +#define PCIE_STRFMR_CPL_ATTR_MISMATCH_OK 0x02000000 /* Mask Attribute Mismatch Error for Received Completions */
3688 +#define PCIE_STRFMR_CPL_LENGTH_MISMATCH_OK 0x04000000 /* Mask Length Mismatch Error for Received Completions */
3689 +#define PCIE_STRFMR_TLP_ECRC_ERR_OK 0x08000000 /* Mask ECRC Error Filtering */
3690 +#define PCIE_STRFMR_CPL_TLP_ECRC_OK 0x10000000 /* Mask ECRC Error Filtering for Completions */
3691 +#define PCIE_STRFMR_RX_TLP_MSG_NO_DROP 0x20000000 /* Send Message TLPs */
3692 +#define PCIE_STRFMR_RX_IO_TRANS_ENABLE 0x40000000 /* Mask Filtering of received I/O Requests */
3693 +#define PCIE_STRFMR_RX_CFG_TRANS_ENABLE 0x80000000 /* Mask Filtering of Received Configuration Requests */
3694 +
3695 +#define PCIE_DEF_SKP_INTERVAL 700 /* 1180 ~1538 , 125MHz * 2, 250MHz * 1 */
3696 +
3697 +/* Filter Masker Register 2 */
3698 +#define PCIE_FMR2(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x720)
3699 +#define PCIE_FMR2_VENDOR_MSG0_PASSED_TO_TRGT1 0x00000001 /* Mask RADM Filtering and Error Handling Rules */
3700 +#define PCIE_FMR2_VENDOR_MSG1_PASSED_TO_TRGT1 0x00000002 /* Mask RADM Filtering and Error Handling Rules */
3701 +
3702 +/* Debug Register 0 */
3703 +#define PCIE_DBR0(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x728)
3704 +
3705 +/* Debug Register 1 */
3706 +#define PCIE_DBR1(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x72C)
3707 +
3708 +/* Transmit Posted FC Credit Status Register */
3709 +#define PCIE_TPFCS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x730)
3710 +#define PCIE_TPFCS_TX_P_DATA_FC_CREDITS 0x00000FFF /* Transmit Posted Data FC Credits */
3711 +#define PCIE_TPFCS_TX_P_DATA_FC_CREDITS_S 0
3712 +#define PCIE_TPFCS_TX_P_HDR_FC_CREDITS 0x000FF000 /* Transmit Posted Header FC Credits */
3713 +#define PCIE_TPFCS_TX_P_HDR_FC_CREDITS_S 12
3714 +
3715 +/* Transmit Non-Posted FC Credit Status */
3716 +#define PCIE_TNPFCS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x734)
3717 +#define PCIE_TNPFCS_TX_NP_DATA_FC_CREDITS 0x00000FFF /* Transmit Non-Posted Data FC Credits */
3718 +#define PCIE_TNPFCS_TX_NP_DATA_FC_CREDITS_S 0
3719 +#define PCIE_TNPFCS_TX_NP_HDR_FC_CREDITS 0x000FF000 /* Transmit Non-Posted Header FC Credits */
3720 +#define PCIE_TNPFCS_TX_NP_HDR_FC_CREDITS_S 12
3721 +
3722 +/* Transmit Complete FC Credit Status Register */
3723 +#define PCIE_TCFCS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x738)
3724 +#define PCIE_TCFCS_TX_CPL_DATA_FC_CREDITS 0x00000FFF /* Transmit Completion Data FC Credits */
3725 +#define PCIE_TCFCS_TX_CPL_DATA_FC_CREDITS_S 0
3726 +#define PCIE_TCFCS_TX_CPL_HDR_FC_CREDITS 0x000FF000 /* Transmit Completion Header FC Credits */
3727 +#define PCIE_TCFCS_TX_CPL_HDR_FC_CREDITS_S 12
3728 +
3729 +/* Queue Status Register */
3730 +#define PCIE_QSR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x73C)
3731 +#define PCIE_QSR_WAIT_UPDATE_FC_DLL 0x00000001 /* Received TLP FC Credits Not Returned */
3732 +#define PCIE_QSR_TX_RETRY_BUF_NOT_EMPTY 0x00000002 /* Transmit Retry Buffer Not Empty */
3733 +#define PCIE_QSR_RX_QUEUE_NOT_EMPTY 0x00000004 /* Received Queue Not Empty */
3734 +
3735 +/* VC Transmit Arbitration Register 1 */
3736 +#define PCIE_VCTAR1(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x740)
3737 +#define PCIE_VCTAR1_WRR_WEIGHT_VC0 0x000000FF /* WRR Weight for VC0 */
3738 +#define PCIE_VCTAR1_WRR_WEIGHT_VC1 0x0000FF00 /* WRR Weight for VC1 */
3739 +#define PCIE_VCTAR1_WRR_WEIGHT_VC2 0x00FF0000 /* WRR Weight for VC2 */
3740 +#define PCIE_VCTAR1_WRR_WEIGHT_VC3 0xFF000000 /* WRR Weight for VC3 */
3741 +
3742 +/* VC Transmit Arbitration Register 2 */
3743 +#define PCIE_VCTAR2(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x744)
3744 +#define PCIE_VCTAR2_WRR_WEIGHT_VC4 0x000000FF /* WRR Weight for VC4 */
3745 +#define PCIE_VCTAR2_WRR_WEIGHT_VC5 0x0000FF00 /* WRR Weight for VC5 */
3746 +#define PCIE_VCTAR2_WRR_WEIGHT_VC6 0x00FF0000 /* WRR Weight for VC6 */
3747 +#define PCIE_VCTAR2_WRR_WEIGHT_VC7 0xFF000000 /* WRR Weight for VC7 */
3748 +
3749 +/* VC0 Posted Receive Queue Control Register */
3750 +#define PCIE_VC0_PRQCR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x748)
3751 +#define PCIE_VC0_PRQCR_P_DATA_CREDITS 0x00000FFF /* VC0 Posted Data Credits */
3752 +#define PCIE_VC0_PRQCR_P_DATA_CREDITS_S 0
3753 +#define PCIE_VC0_PRQCR_P_HDR_CREDITS 0x000FF000 /* VC0 Posted Header Credits */
3754 +#define PCIE_VC0_PRQCR_P_HDR_CREDITS_S 12
3755 +#define PCIE_VC0_PRQCR_P_TLP_QUEUE_MODE 0x00E00000 /* VC0 Posted TLP Queue Mode */
3756 +#define PCIE_VC0_PRQCR_P_TLP_QUEUE_MODE_S 20
3757 +#define PCIE_VC0_PRQCR_TLP_RELAX_ORDER 0x40000000 /* TLP Type Ordering for VC0 */
3758 +#define PCIE_VC0_PRQCR_VC_STRICT_ORDER 0x80000000 /* VC0 Ordering for Receive Queues */
3759 +
3760 +/* VC0 Non-Posted Receive Queue Control */
3761 +#define PCIE_VC0_NPRQCR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x74C)
3762 +#define PCIE_VC0_NPRQCR_NP_DATA_CREDITS 0x00000FFF /* VC0 Non-Posted Data Credits */
3763 +#define PCIE_VC0_NPRQCR_NP_DATA_CREDITS_S 0
3764 +#define PCIE_VC0_NPRQCR_NP_HDR_CREDITS 0x000FF000 /* VC0 Non-Posted Header Credits */
3765 +#define PCIE_VC0_NPRQCR_NP_HDR_CREDITS_S 12
3766 +#define PCIE_VC0_NPRQCR_NP_TLP_QUEUE_MODE 0x00E00000 /* VC0 Non-Posted TLP Queue Mode */
3767 +#define PCIE_VC0_NPRQCR_NP_TLP_QUEUE_MODE_S 20
3768 +
3769 +/* VC0 Completion Receive Queue Control */
3770 +#define PCIE_VC0_CRQCR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x750)
3771 +#define PCIE_VC0_CRQCR_CPL_DATA_CREDITS 0x00000FFF /* VC0 Completion TLP Queue Mode */
3772 +#define PCIE_VC0_CRQCR_CPL_DATA_CREDITS_S 0
3773 +#define PCIE_VC0_CRQCR_CPL_HDR_CREDITS 0x000FF000 /* VC0 Completion Header Credits */
3774 +#define PCIE_VC0_CRQCR_CPL_HDR_CREDITS_S 12
3775 +#define PCIE_VC0_CRQCR_CPL_TLP_QUEUE_MODE 0x00E00000 /* VC0 Completion Data Credits */
3776 +#define PCIE_VC0_CRQCR_CPL_TLP_QUEUE_MODE_S 21
3777 +
3778 +/* Applicable to the above three registers */
3779 +enum {
3780 + PCIE_VC0_TLP_QUEUE_MODE_STORE_FORWARD = 1,
3781 + PCIE_VC0_TLP_QUEUE_MODE_CUT_THROUGH = 2,
3782 + PCIE_VC0_TLP_QUEUE_MODE_BYPASS = 4,
3783 +};
3784 +
3785 +/* VC0 Posted Buffer Depth Register */
3786 +#define PCIE_VC0_PBD(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x7A8)
3787 +#define PCIE_VC0_PBD_P_DATA_QUEUE_ENTRIES 0x00003FFF /* VC0 Posted Data Queue Depth */
3788 +#define PCIE_VC0_PBD_P_DATA_QUEUE_ENTRIES_S 0
3789 +#define PCIE_VC0_PBD_P_HDR_QUEUE_ENTRIES 0x03FF0000 /* VC0 Posted Header Queue Depth */
3790 +#define PCIE_VC0_PBD_P_HDR_QUEUE_ENTRIES_S 16
3791 +
3792 +/* VC0 Non-Posted Buffer Depth Register */
3793 +#define PCIE_VC0_NPBD(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x7AC)
3794 +#define PCIE_VC0_NPBD_NP_DATA_QUEUE_ENTRIES 0x00003FFF /* VC0 Non-Posted Data Queue Depth */
3795 +#define PCIE_VC0_NPBD_NP_DATA_QUEUE_ENTRIES_S 0
3796 +#define PCIE_VC0_NPBD_NP_HDR_QUEUE_ENTRIES 0x03FF0000 /* VC0 Non-Posted Header Queue Depth */
3797 +#define PCIE_VC0_NPBD_NP_HDR_QUEUE_ENTRIES_S 16
3798 +
3799 +/* VC0 Completion Buffer Depth Register */
3800 +#define PCIE_VC0_CBD(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x7B0)
3801 +#define PCIE_VC0_CBD_CPL_DATA_QUEUE_ENTRIES 0x00003FFF /* C0 Completion Data Queue Depth */
3802 +#define PCIE_VC0_CBD_CPL_DATA_QUEUE_ENTRIES_S 0
3803 +#define PCIE_VC0_CBD_CPL_HDR_QUEUE_ENTRIES 0x03FF0000 /* VC0 Completion Header Queue Depth */
3804 +#define PCIE_VC0_CBD_CPL_HDR_QUEUE_ENTRIES_S 16
3805 +
3806 +/* PHY Status Register, all zeros in VR9 */
3807 +#define PCIE_PHYSR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x810)
3808 +
3809 +/* PHY Control Register, all zeros in VR9 */
3810 +#define PCIE_PHYCR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x814)
3811 +
3812 +/*
3813 + * PCIe PDI PHY register definition, suppose all the following
3814 + * stuff is confidential.
3815 + * XXX, detailed bit definition
3816 + */
3817 +#define PCIE_PHY_PLL_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x22 << 1))
3818 +#define PCIE_PHY_PLL_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x23 << 1))
3819 +#define PCIE_PHY_PLL_CTRL3(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x24 << 1))
3820 +#define PCIE_PHY_PLL_CTRL4(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x25 << 1))
3821 +#define PCIE_PHY_PLL_CTRL5(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x26 << 1))
3822 +#define PCIE_PHY_PLL_CTRL6(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x27 << 1))
3823 +#define PCIE_PHY_PLL_CTRL7(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x28 << 1))
3824 +#define PCIE_PHY_PLL_A_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x29 << 1))
3825 +#define PCIE_PHY_PLL_A_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x2A << 1))
3826 +#define PCIE_PHY_PLL_A_CTRL3(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x2B << 1))
3827 +#define PCIE_PHY_PLL_STATUS(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x2C << 1))
3828 +
3829 +#define PCIE_PHY_TX1_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x30 << 1))
3830 +#define PCIE_PHY_TX1_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x31 << 1))
3831 +#define PCIE_PHY_TX1_CTRL3(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x32 << 1))
3832 +#define PCIE_PHY_TX1_A_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x33 << 1))
3833 +#define PCIE_PHY_TX1_A_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x34 << 1))
3834 +#define PCIE_PHY_TX1_MOD1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x35 << 1))
3835 +#define PCIE_PHY_TX1_MOD2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x36 << 1))
3836 +#define PCIE_PHY_TX1_MOD3(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x37 << 1))
3837 +
3838 +#define PCIE_PHY_TX2_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x38 << 1))
3839 +#define PCIE_PHY_TX2_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x39 << 1))
3840 +#define PCIE_PHY_TX2_A_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x3B << 1))
3841 +#define PCIE_PHY_TX2_A_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x3C << 1))
3842 +#define PCIE_PHY_TX2_MOD1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x3D << 1))
3843 +#define PCIE_PHY_TX2_MOD2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x3E << 1))
3844 +#define PCIE_PHY_TX2_MOD3(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x3F << 1))
3845 +
3846 +#define PCIE_PHY_RX1_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x50 << 1))
3847 +#define PCIE_PHY_RX1_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x51 << 1))
3848 +#define PCIE_PHY_RX1_CDR(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x52 << 1))
3849 +#define PCIE_PHY_RX1_EI(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x53 << 1))
3850 +#define PCIE_PHY_RX1_A_CTRL(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x55 << 1))
3851 +
3852 +/* Interrupt related stuff */
3853 +#define PCIE_LEGACY_DISABLE 0
3854 +#define PCIE_LEGACY_INTA 1
3855 +#define PCIE_LEGACY_INTB 2
3856 +#define PCIE_LEGACY_INTC 3
3857 +#define PCIE_LEGACY_INTD 4
3858 +#define PCIE_LEGACY_INT_MAX PCIE_LEGACY_INTD
3859 +
3860 +#endif /* IFXMIPS_PCIE_REG_H */
3861 +
3862 --- /dev/null
3863 +++ b/arch/mips/pci/ifxmips_pcie_vr9.h
3864 @@ -0,0 +1,269 @@
3865 +/****************************************************************************
3866 + Copyright (c) 2010
3867 + Lantiq Deutschland GmbH
3868 + Am Campeon 3; 85579 Neubiberg, Germany
3869 +
3870 + For licensing information, see the file 'LICENSE' in the root folder of
3871 + this software module.
3872 +
3873 + *****************************************************************************/
3874 +/*!
3875 + \file ifxmips_pcie_vr9.h
3876 + \ingroup IFX_PCIE
3877 + \brief PCIe RC driver vr9 specific file
3878 +*/
3879 +
3880 +#ifndef IFXMIPS_PCIE_VR9_H
3881 +#define IFXMIPS_PCIE_VR9_H
3882 +
3883 +#include <linux/types.h>
3884 +#include <linux/delay.h>
3885 +
3886 +#include <linux/gpio.h>
3887 +#include <lantiq_soc.h>
3888 +
3889 +#define IFX_PCIE_GPIO_RESET 494
3890 +
3891 +#define IFX_REG_R32 ltq_r32
3892 +#define IFX_REG_W32 ltq_w32
3893 +#define CONFIG_IFX_PCIE_HW_SWAP
3894 +#define IFX_RCU_AHB_ENDIAN ((volatile u32*)(IFX_RCU + 0x004C))
3895 +#define IFX_RCU_RST_REQ ((volatile u32*)(IFX_RCU + 0x0010))
3896 +#define IFX_RCU_AHB_BE_PCIE_PDI 0x00000080 /* Configure PCIE PDI module in big endian*/
3897 +
3898 +#define IFX_RCU (KSEG1 | 0x1F203000)
3899 +#define IFX_RCU_AHB_BE_PCIE_M 0x00000001 /* Configure AHB master port that connects to PCIe RC in big endian */
3900 +#define IFX_RCU_AHB_BE_PCIE_S 0x00000010 /* Configure AHB slave port that connects to PCIe RC in little endian */
3901 +#define IFX_RCU_AHB_BE_XBAR_M 0x00000002 /* Configure AHB master port that connects to XBAR in big endian */
3902 +#define CONFIG_IFX_PCIE_PHY_36MHZ_MODE
3903 +
3904 +#define IFX_PMU1_MODULE_PCIE_PHY (0)
3905 +#define IFX_PMU1_MODULE_PCIE_CTRL (1)
3906 +#define IFX_PMU1_MODULE_PDI (4)
3907 +#define IFX_PMU1_MODULE_MSI (5)
3908 +
3909 +#define IFX_PMU_MODULE_PCIE_L0_CLK (31)
3910 +
3911 +
3912 +#define IFX_GPIO (KSEG1 | 0x1E100B00)
3913 +#define ALT0 ((volatile u32*)(IFX_GPIO + 0x007c))
3914 +#define ALT1 ((volatile u32*)(IFX_GPIO + 0x0080))
3915 +#define OD ((volatile u32*)(IFX_GPIO + 0x0084))
3916 +#define DIR ((volatile u32*)(IFX_GPIO + 0x0078))
3917 +#define OUT ((volatile u32*)(IFX_GPIO + 0x0070))
3918 +
3919 +
3920 +static inline void pcie_ep_gpio_rst_init(int pcie_port)
3921 +{
3922 +
3923 + gpio_request(IFX_PCIE_GPIO_RESET, "pcie-reset");
3924 + gpio_direction_output(IFX_PCIE_GPIO_RESET, 1);
3925 + gpio_set_value(IFX_PCIE_GPIO_RESET, 1);
3926 +
3927 +/* ifx_gpio_pin_reserve(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
3928 + ifx_gpio_output_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
3929 + ifx_gpio_dir_out_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
3930 + ifx_gpio_altsel0_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
3931 + ifx_gpio_altsel1_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
3932 + ifx_gpio_open_drain_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);*/
3933 +}
3934 +
3935 +static inline void pcie_ahb_pmu_setup(void)
3936 +{
3937 + /* Enable AHB bus master/slave */
3938 + struct clk *clk;
3939 + clk = clk_get_sys("1d900000.pcie", "ahb");
3940 + clk_enable(clk);
3941 +
3942 + //AHBM_PMU_SETUP(IFX_PMU_ENABLE);
3943 + //AHBS_PMU_SETUP(IFX_PMU_ENABLE);
3944 +}
3945 +
3946 +static inline void pcie_rcu_endian_setup(int pcie_port)
3947 +{
3948 + u32 reg;
3949 +
3950 + reg = IFX_REG_R32(IFX_RCU_AHB_ENDIAN);
3951 +#ifdef CONFIG_IFX_PCIE_HW_SWAP
3952 + reg |= IFX_RCU_AHB_BE_PCIE_M;
3953 + reg |= IFX_RCU_AHB_BE_PCIE_S;
3954 + reg &= ~IFX_RCU_AHB_BE_XBAR_M;
3955 +#else
3956 + reg |= IFX_RCU_AHB_BE_PCIE_M;
3957 + reg &= ~IFX_RCU_AHB_BE_PCIE_S;
3958 + reg &= ~IFX_RCU_AHB_BE_XBAR_M;
3959 +#endif /* CONFIG_IFX_PCIE_HW_SWAP */
3960 + IFX_REG_W32(reg, IFX_RCU_AHB_ENDIAN);
3961 + IFX_PCIE_PRINT(PCIE_MSG_REG, "%s IFX_RCU_AHB_ENDIAN: 0x%08x\n", __func__, IFX_REG_R32(IFX_RCU_AHB_ENDIAN));
3962 +}
3963 +
3964 +static inline void pcie_phy_pmu_enable(int pcie_port)
3965 +{
3966 + struct clk *clk;
3967 + clk = clk_get_sys("1d900000.pcie", "phy");
3968 + clk_enable(clk);
3969 +
3970 + //PCIE_PHY_PMU_SETUP(IFX_PMU_ENABLE);
3971 +}
3972 +
3973 +static inline void pcie_phy_pmu_disable(int pcie_port)
3974 +{
3975 + struct clk *clk;
3976 + clk = clk_get_sys("1d900000.pcie", "phy");
3977 + clk_disable(clk);
3978 +
3979 +// PCIE_PHY_PMU_SETUP(IFX_PMU_DISABLE);
3980 +}
3981 +
3982 +static inline void pcie_pdi_big_endian(int pcie_port)
3983 +{
3984 + u32 reg;
3985 +
3986 + /* SRAM2PDI endianness control. */
3987 + reg = IFX_REG_R32(IFX_RCU_AHB_ENDIAN);
3988 + /* Config AHB->PCIe and PDI endianness */
3989 + reg |= IFX_RCU_AHB_BE_PCIE_PDI;
3990 + IFX_REG_W32(reg, IFX_RCU_AHB_ENDIAN);
3991 +}
3992 +
3993 +static inline void pcie_pdi_pmu_enable(int pcie_port)
3994 +{
3995 + /* Enable PDI to access PCIe PHY register */
3996 + struct clk *clk;
3997 + clk = clk_get_sys("1d900000.pcie", "pdi");
3998 + clk_enable(clk);
3999 + //PDI_PMU_SETUP(IFX_PMU_ENABLE);
4000 +}
4001 +
4002 +static inline void pcie_core_rst_assert(int pcie_port)
4003 +{
4004 + u32 reg;
4005 +
4006 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
4007 +
4008 + /* Reset PCIe PHY & Core, bit 22, bit 26 may be affected if write it directly */
4009 + reg |= 0x00400000;
4010 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
4011 +}
4012 +
4013 +static inline void pcie_core_rst_deassert(int pcie_port)
4014 +{
4015 + u32 reg;
4016 +
4017 + /* Make sure one micro-second delay */
4018 + udelay(1);
4019 +
4020 + /* Reset PCIe PHY & Core, bit 22 */
4021 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
4022 + reg &= ~0x00400000;
4023 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
4024 +}
4025 +
4026 +static inline void pcie_phy_rst_assert(int pcie_port)
4027 +{
4028 + u32 reg;
4029 +
4030 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
4031 + reg |= 0x00001000; /* Bit 12 */
4032 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
4033 +}
4034 +
4035 +static inline void pcie_phy_rst_deassert(int pcie_port)
4036 +{
4037 + u32 reg;
4038 +
4039 + /* Make sure one micro-second delay */
4040 + udelay(1);
4041 +
4042 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
4043 + reg &= ~0x00001000; /* Bit 12 */
4044 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
4045 +}
4046 +
4047 +static inline void pcie_device_rst_assert(int pcie_port)
4048 +{
4049 + gpio_set_value(IFX_PCIE_GPIO_RESET, 0);
4050 +// ifx_gpio_output_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
4051 +}
4052 +
4053 +static inline void pcie_device_rst_deassert(int pcie_port)
4054 +{
4055 + mdelay(100);
4056 + gpio_direction_output(IFX_PCIE_GPIO_RESET, 1);
4057 +// gpio_set_value(IFX_PCIE_GPIO_RESET, 1);
4058 + //ifx_gpio_output_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
4059 +}
4060 +
4061 +static inline void pcie_core_pmu_setup(int pcie_port)
4062 +{
4063 + struct clk *clk;
4064 + clk = clk_get_sys("1d900000.pcie", "ctl");
4065 + clk_enable(clk);
4066 + clk = clk_get_sys("1d900000.pcie", "bus");
4067 + clk_enable(clk);
4068 +
4069 + /* PCIe Core controller enabled */
4070 +// PCIE_CTRL_PMU_SETUP(IFX_PMU_ENABLE);
4071 +
4072 + /* Enable PCIe L0 Clock */
4073 +// PCIE_L0_CLK_PMU_SETUP(IFX_PMU_ENABLE);
4074 +}
4075 +
4076 +static inline void pcie_msi_init(int pcie_port)
4077 +{
4078 + struct clk *clk;
4079 + pcie_msi_pic_init(pcie_port);
4080 + clk = clk_get_sys("ltq_pcie", "msi");
4081 + clk_enable(clk);
4082 +// MSI_PMU_SETUP(IFX_PMU_ENABLE);
4083 +}
4084 +
4085 +static inline u32
4086 +ifx_pcie_bus_nr_deduct(u32 bus_number, int pcie_port)
4087 +{
4088 + u32 tbus_number = bus_number;
4089 +
4090 +#ifdef CONFIG_PCI_LANTIQ
4091 + if (pcibios_host_nr() > 1) {
4092 + tbus_number -= pcibios_1st_host_bus_nr();
4093 + }
4094 +#endif /* CONFIG_PCI_LANTIQ */
4095 + return tbus_number;
4096 +}
4097 +
4098 +static inline u32
4099 +ifx_pcie_bus_enum_hack(struct pci_bus *bus, u32 devfn, int where, u32 value, int pcie_port, int read)
4100 +{
4101 + struct pci_dev *pdev;
4102 + u32 tvalue = value;
4103 +
4104 + /* Sanity check */
4105 + pdev = pci_get_slot(bus, devfn);
4106 + if (pdev == NULL) {
4107 + return tvalue;
4108 + }
4109 +
4110 + /* Only care about PCI bridge */
4111 + if (pdev->hdr_type != PCI_HEADER_TYPE_BRIDGE) {
4112 + return tvalue;
4113 + }
4114 +
4115 + if (read) { /* Read hack */
4116 + #ifdef CONFIG_PCI_LANTIQ
4117 + if (pcibios_host_nr() > 1) {
4118 + tvalue = ifx_pcie_bus_enum_read_hack(where, tvalue);
4119 + }
4120 + #endif /* CONFIG_PCI_LANTIQ */
4121 + }
4122 + else { /* Write hack */
4123 + #ifdef CONFIG_PCI_LANTIQ
4124 + if (pcibios_host_nr() > 1) {
4125 + tvalue = ifx_pcie_bus_enum_write_hack(where, tvalue);
4126 + }
4127 + #endif
4128 + }
4129 + return tvalue;
4130 +}
4131 +
4132 +#endif /* IFXMIPS_PCIE_VR9_H */
4133 +
4134 --- a/arch/mips/pci/pci-legacy.c
4135 +++ b/arch/mips/pci/pci-legacy.c
4136 @@ -308,3 +308,30 @@ char *__init pcibios_setup(char *str)
4137 return pcibios_plat_setup(str);
4138 return str;
4139 }
4140 +
4141 +int pcibios_host_nr(void)
4142 +{
4143 + int count = 0;
4144 + struct pci_controller *hose;
4145 + list_for_each_entry(hose, &controllers, list) {
4146 + count++;
4147 + }
4148 + return count;
4149 +}
4150 +EXPORT_SYMBOL(pcibios_host_nr);
4151 +
4152 +int pcibios_1st_host_bus_nr(void)
4153 +{
4154 + int bus_nr = 0;
4155 + struct pci_controller *hose;
4156 +
4157 + hose = list_first_entry_or_null(&controllers, struct pci_controller, list);
4158 +
4159 + if (hose != NULL) {
4160 + if (hose->bus != NULL) {
4161 + bus_nr = hose->bus->number + 1;
4162 + }
4163 + }
4164 + return bus_nr;
4165 +}
4166 +EXPORT_SYMBOL(pcibios_1st_host_bus_nr);
4167 --- /dev/null
4168 +++ b/arch/mips/pci/pcie-lantiq.h
4169 @@ -0,0 +1,1301 @@
4170 +/******************************************************************************
4171 +**
4172 +** FILE NAME : ifxmips_pcie_reg.h
4173 +** PROJECT : IFX UEIP for VRX200
4174 +** MODULES : PCIe module
4175 +**
4176 +** DATE : 02 Mar 2009
4177 +** AUTHOR : Lei Chuanhua
4178 +** DESCRIPTION : PCIe Root Complex Driver
4179 +** COPYRIGHT : Copyright (c) 2009
4180 +** Infineon Technologies AG
4181 +** Am Campeon 1-12, 85579 Neubiberg, Germany
4182 +**
4183 +** This program is free software; you can redistribute it and/or modify
4184 +** it under the terms of the GNU General Public License as published by
4185 +** the Free Software Foundation; either version 2 of the License, or
4186 +** (at your option) any later version.
4187 +** HISTORY
4188 +** $Version $Date $Author $Comment
4189 +** 0.0.1 17 Mar,2009 Lei Chuanhua Initial version
4190 +*******************************************************************************/
4191 +#ifndef IFXMIPS_PCIE_REG_H
4192 +#define IFXMIPS_PCIE_REG_H
4193 +#include <linux/version.h>
4194 +#include <linux/types.h>
4195 +#include <linux/pci.h>
4196 +#include <linux/interrupt.h>
4197 +/*!
4198 + \file ifxmips_pcie_reg.h
4199 + \ingroup IFX_PCIE
4200 + \brief header file for PCIe module register definition
4201 +*/
4202 +/* PCIe Address Mapping Base */
4203 +#define PCIE_CFG_PHY_BASE 0x1D000000UL
4204 +#define PCIE_CFG_BASE (KSEG1 + PCIE_CFG_PHY_BASE)
4205 +#define PCIE_CFG_SIZE (8 * 1024 * 1024)
4206 +
4207 +#define PCIE_MEM_PHY_BASE 0x1C000000UL
4208 +#define PCIE_MEM_BASE (KSEG1 + PCIE_MEM_PHY_BASE)
4209 +#define PCIE_MEM_SIZE (16 * 1024 * 1024)
4210 +#define PCIE_MEM_PHY_END (PCIE_MEM_PHY_BASE + PCIE_MEM_SIZE - 1)
4211 +
4212 +#define PCIE_IO_PHY_BASE 0x1D800000UL
4213 +#define PCIE_IO_BASE (KSEG1 + PCIE_IO_PHY_BASE)
4214 +#define PCIE_IO_SIZE (1 * 1024 * 1024)
4215 +#define PCIE_IO_PHY_END (PCIE_IO_PHY_BASE + PCIE_IO_SIZE - 1)
4216 +
4217 +#define PCIE_RC_CFG_BASE (KSEG1 + 0x1D900000)
4218 +#define PCIE_APP_LOGIC_REG (KSEG1 + 0x1E100900)
4219 +#define PCIE_MSI_PHY_BASE 0x1F600000UL
4220 +
4221 +#define PCIE_PDI_PHY_BASE 0x1F106800UL
4222 +#define PCIE_PDI_BASE (KSEG1 + PCIE_PDI_PHY_BASE)
4223 +#define PCIE_PDI_SIZE 0x400
4224 +
4225 +#define PCIE1_CFG_PHY_BASE 0x19000000UL
4226 +#define PCIE1_CFG_BASE (KSEG1 + PCIE1_CFG_PHY_BASE)
4227 +#define PCIE1_CFG_SIZE (8 * 1024 * 1024)
4228 +
4229 +#define PCIE1_MEM_PHY_BASE 0x18000000UL
4230 +#define PCIE1_MEM_BASE (KSEG1 + PCIE1_MEM_PHY_BASE)
4231 +#define PCIE1_MEM_SIZE (16 * 1024 * 1024)
4232 +#define PCIE1_MEM_PHY_END (PCIE1_MEM_PHY_BASE + PCIE1_MEM_SIZE - 1)
4233 +
4234 +#define PCIE1_IO_PHY_BASE 0x19800000UL
4235 +#define PCIE1_IO_BASE (KSEG1 + PCIE1_IO_PHY_BASE)
4236 +#define PCIE1_IO_SIZE (1 * 1024 * 1024)
4237 +#define PCIE1_IO_PHY_END (PCIE1_IO_PHY_BASE + PCIE1_IO_SIZE - 1)
4238 +
4239 +#define PCIE1_RC_CFG_BASE (KSEG1 + 0x19900000)
4240 +#define PCIE1_APP_LOGIC_REG (KSEG1 + 0x1E100700)
4241 +#define PCIE1_MSI_PHY_BASE 0x1F400000UL
4242 +
4243 +#define PCIE1_PDI_PHY_BASE 0x1F700400UL
4244 +#define PCIE1_PDI_BASE (KSEG1 + PCIE1_PDI_PHY_BASE)
4245 +#define PCIE1_PDI_SIZE 0x400
4246 +
4247 +#define PCIE_CFG_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_CFG_BASE) : (PCIE_CFG_BASE))
4248 +#define PCIE_MEM_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_MEM_BASE) : (PCIE_MEM_BASE))
4249 +#define PCIE_IO_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_IO_BASE) : (PCIE_IO_BASE))
4250 +#define PCIE_MEM_PHY_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_MEM_PHY_BASE) : (PCIE_MEM_PHY_BASE))
4251 +#define PCIE_MEM_PHY_PORT_TO_END(X) ((X) > 0 ? (PCIE1_MEM_PHY_END) : (PCIE_MEM_PHY_END))
4252 +#define PCIE_IO_PHY_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_IO_PHY_BASE) : (PCIE_IO_PHY_BASE))
4253 +#define PCIE_IO_PHY_PORT_TO_END(X) ((X) > 0 ? (PCIE1_IO_PHY_END) : (PCIE_IO_PHY_END))
4254 +#define PCIE_APP_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_APP_LOGIC_REG) : (PCIE_APP_LOGIC_REG))
4255 +#define PCIE_RC_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_RC_CFG_BASE) : (PCIE_RC_CFG_BASE))
4256 +#define PCIE_PHY_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_PDI_BASE) : (PCIE_PDI_BASE))
4257 +
4258 +/* PCIe Application Logic Register */
4259 +/* RC Core Control Register */
4260 +#define PCIE_RC_CCR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x10)
4261 +/* This should be enabled after initializing configuratin registers
4262 + * Also should check link status retraining bit
4263 + */
4264 +#define PCIE_RC_CCR_LTSSM_ENABLE 0x00000001 /* Enable LTSSM to continue link establishment */
4265 +
4266 +/* RC Core Debug Register */
4267 +#define PCIE_RC_DR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x14)
4268 +#define PCIE_RC_DR_DLL_UP 0x00000001 /* Data Link Layer Up */
4269 +#define PCIE_RC_DR_CURRENT_POWER_STATE 0x0000000E /* Current Power State */
4270 +#define PCIE_RC_DR_CURRENT_POWER_STATE_S 1
4271 +#define PCIE_RC_DR_CURRENT_LTSSM_STATE 0x000001F0 /* Current LTSSM State */
4272 +#define PCIE_RC_DR_CURRENT_LTSSM_STATE_S 4
4273 +
4274 +#define PCIE_RC_DR_PM_DEV_STATE 0x00000E00 /* Power Management D-State */
4275 +#define PCIE_RC_DR_PM_DEV_STATE_S 9
4276 +
4277 +#define PCIE_RC_DR_PM_ENABLED 0x00001000 /* Power Management State from PMU */
4278 +#define PCIE_RC_DR_PME_EVENT_ENABLED 0x00002000 /* Power Management Event Enable State */
4279 +#define PCIE_RC_DR_AUX_POWER_ENABLED 0x00004000 /* Auxiliary Power Enable */
4280 +
4281 +/* Current Power State Definition */
4282 +enum {
4283 + PCIE_RC_DR_D0 = 0,
4284 + PCIE_RC_DR_D1, /* Not supported */
4285 + PCIE_RC_DR_D2, /* Not supported */
4286 + PCIE_RC_DR_D3,
4287 + PCIE_RC_DR_UN,
4288 +};
4289 +
4290 +/* PHY Link Status Register */
4291 +#define PCIE_PHY_SR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x18)
4292 +#define PCIE_PHY_SR_PHY_LINK_UP 0x00000001 /* PHY Link Up/Down Indicator */
4293 +
4294 +/* Electromechanical Control Register */
4295 +#define PCIE_EM_CR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x1C)
4296 +#define PCIE_EM_CR_CARD_IS_PRESENT 0x00000001 /* Card Presence Detect State */
4297 +#define PCIE_EM_CR_MRL_OPEN 0x00000002 /* MRL Sensor State */
4298 +#define PCIE_EM_CR_POWER_FAULT_SET 0x00000004 /* Power Fault Detected */
4299 +#define PCIE_EM_CR_MRL_SENSOR_SET 0x00000008 /* MRL Sensor Changed */
4300 +#define PCIE_EM_CR_PRESENT_DETECT_SET 0x00000010 /* Card Presense Detect Changed */
4301 +#define PCIE_EM_CR_CMD_CPL_INT_SET 0x00000020 /* Command Complete Interrupt */
4302 +#define PCIE_EM_CR_SYS_INTERLOCK_SET 0x00000040 /* System Electromechanical IterLock Engaged */
4303 +#define PCIE_EM_CR_ATTENTION_BUTTON_SET 0x00000080 /* Attention Button Pressed */
4304 +
4305 +/* Interrupt Status Register */
4306 +#define PCIE_IR_SR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x20)
4307 +#define PCIE_IR_SR_PME_CAUSE_MSI 0x00000002 /* MSI caused by PME */
4308 +#define PCIE_IR_SR_HP_PME_WAKE_GEN 0x00000004 /* Hotplug PME Wake Generation */
4309 +#define PCIE_IR_SR_HP_MSI 0x00000008 /* Hotplug MSI */
4310 +#define PCIE_IR_SR_AHB_LU_ERR 0x00000030 /* AHB Bridge Lookup Error Signals */
4311 +#define PCIE_IR_SR_AHB_LU_ERR_S 4
4312 +#define PCIE_IR_SR_INT_MSG_NUM 0x00003E00 /* Interrupt Message Number */
4313 +#define PCIE_IR_SR_INT_MSG_NUM_S 9
4314 +#define PCIE_IR_SR_AER_INT_MSG_NUM 0xF8000000 /* Advanced Error Interrupt Message Number */
4315 +#define PCIE_IR_SR_AER_INT_MSG_NUM_S 27
4316 +
4317 +/* Message Control Register */
4318 +#define PCIE_MSG_CR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x30)
4319 +#define PCIE_MSG_CR_GEN_PME_TURN_OFF_MSG 0x00000001 /* Generate PME Turn Off Message */
4320 +#define PCIE_MSG_CR_GEN_UNLOCK_MSG 0x00000002 /* Generate Unlock Message */
4321 +
4322 +#define PCIE_VDM_DR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x34)
4323 +
4324 +/* Vendor-Defined Message Requester ID Register */
4325 +#define PCIE_VDM_RID(X) (PCIE_APP_PORT_TO_BASE (X) + 0x38)
4326 +#define PCIE_VDM_RID_VENROR_MSG_REQ_ID 0x0000FFFF
4327 +#define PCIE_VDM_RID_VDMRID_S 0
4328 +
4329 +/* ASPM Control Register */
4330 +#define PCIE_ASPM_CR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x40)
4331 +#define PCIE_ASPM_CR_HOT_RST 0x00000001 /* Hot Reset Request to the downstream device */
4332 +#define PCIE_ASPM_CR_REQ_EXIT_L1 0x00000002 /* Request to Exit L1 */
4333 +#define PCIE_ASPM_CR_REQ_ENTER_L1 0x00000004 /* Request to Enter L1 */
4334 +
4335 +/* Vendor Message DW0 Register */
4336 +#define PCIE_VM_MSG_DW0(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x50)
4337 +#define PCIE_VM_MSG_DW0_TYPE 0x0000001F /* Message type */
4338 +#define PCIE_VM_MSG_DW0_TYPE_S 0
4339 +#define PCIE_VM_MSG_DW0_FORMAT 0x00000060 /* Format */
4340 +#define PCIE_VM_MSG_DW0_FORMAT_S 5
4341 +#define PCIE_VM_MSG_DW0_TC 0x00007000 /* Traffic Class */
4342 +#define PCIE_VM_MSG_DW0_TC_S 12
4343 +#define PCIE_VM_MSG_DW0_ATTR 0x000C0000 /* Atrributes */
4344 +#define PCIE_VM_MSG_DW0_ATTR_S 18
4345 +#define PCIE_VM_MSG_DW0_EP_TLP 0x00100000 /* Poisoned TLP */
4346 +#define PCIE_VM_MSG_DW0_TD 0x00200000 /* TLP Digest */
4347 +#define PCIE_VM_MSG_DW0_LEN 0xFFC00000 /* Length */
4348 +#define PCIE_VM_MSG_DW0_LEN_S 22
4349 +
4350 +/* Format Definition */
4351 +enum {
4352 + PCIE_VM_MSG_FORMAT_00 = 0, /* 3DW Hdr, no data*/
4353 + PCIE_VM_MSG_FORMAT_01, /* 4DW Hdr, no data */
4354 + PCIE_VM_MSG_FORMAT_10, /* 3DW Hdr, with data */
4355 + PCIE_VM_MSG_FORMAT_11, /* 4DW Hdr, with data */
4356 +};
4357 +
4358 +/* Traffic Class Definition */
4359 +enum {
4360 + PCIE_VM_MSG_TC0 = 0,
4361 + PCIE_VM_MSG_TC1,
4362 + PCIE_VM_MSG_TC2,
4363 + PCIE_VM_MSG_TC3,
4364 + PCIE_VM_MSG_TC4,
4365 + PCIE_VM_MSG_TC5,
4366 + PCIE_VM_MSG_TC6,
4367 + PCIE_VM_MSG_TC7,
4368 +};
4369 +
4370 +/* Attributes Definition */
4371 +enum {
4372 + PCIE_VM_MSG_ATTR_00 = 0, /* RO and No Snoop cleared */
4373 + PCIE_VM_MSG_ATTR_01, /* RO cleared , No Snoop set */
4374 + PCIE_VM_MSG_ATTR_10, /* RO set, No Snoop cleared*/
4375 + PCIE_VM_MSG_ATTR_11, /* RO and No Snoop set */
4376 +};
4377 +
4378 +/* Payload Size Definition */
4379 +#define PCIE_VM_MSG_LEN_MIN 0
4380 +#define PCIE_VM_MSG_LEN_MAX 1024
4381 +
4382 +/* Vendor Message DW1 Register */
4383 +#define PCIE_VM_MSG_DW1(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x54)
4384 +#define PCIE_VM_MSG_DW1_FUNC_NUM 0x00000070 /* Function Number */
4385 +#define PCIE_VM_MSG_DW1_FUNC_NUM_S 8
4386 +#define PCIE_VM_MSG_DW1_CODE 0x00FF0000 /* Message Code */
4387 +#define PCIE_VM_MSG_DW1_CODE_S 16
4388 +#define PCIE_VM_MSG_DW1_TAG 0xFF000000 /* Tag */
4389 +#define PCIE_VM_MSG_DW1_TAG_S 24
4390 +
4391 +#define PCIE_VM_MSG_DW2(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x58)
4392 +#define PCIE_VM_MSG_DW3(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x5C)
4393 +
4394 +/* Vendor Message Request Register */
4395 +#define PCIE_VM_MSG_REQR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x60)
4396 +#define PCIE_VM_MSG_REQR_REQ 0x00000001 /* Vendor Message Request */
4397 +
4398 +
4399 +/* AHB Slave Side Band Control Register */
4400 +#define PCIE_AHB_SSB(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x70)
4401 +#define PCIE_AHB_SSB_REQ_BCM 0x00000001 /* Slave Reques BCM filed */
4402 +#define PCIE_AHB_SSB_REQ_EP 0x00000002 /* Slave Reques EP filed */
4403 +#define PCIE_AHB_SSB_REQ_TD 0x00000004 /* Slave Reques TD filed */
4404 +#define PCIE_AHB_SSB_REQ_ATTR 0x00000018 /* Slave Reques Attribute number */
4405 +#define PCIE_AHB_SSB_REQ_ATTR_S 3
4406 +#define PCIE_AHB_SSB_REQ_TC 0x000000E0 /* Slave Request TC Field */
4407 +#define PCIE_AHB_SSB_REQ_TC_S 5
4408 +
4409 +/* AHB Master SideBand Ctrl Register */
4410 +#define PCIE_AHB_MSB(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x74)
4411 +#define PCIE_AHB_MSB_RESP_ATTR 0x00000003 /* Master Response Attribute number */
4412 +#define PCIE_AHB_MSB_RESP_ATTR_S 0
4413 +#define PCIE_AHB_MSB_RESP_BAD_EOT 0x00000004 /* Master Response Badeot filed */
4414 +#define PCIE_AHB_MSB_RESP_BCM 0x00000008 /* Master Response BCM filed */
4415 +#define PCIE_AHB_MSB_RESP_EP 0x00000010 /* Master Response EP filed */
4416 +#define PCIE_AHB_MSB_RESP_TD 0x00000020 /* Master Response TD filed */
4417 +#define PCIE_AHB_MSB_RESP_FUN_NUM 0x000003C0 /* Master Response Function number */
4418 +#define PCIE_AHB_MSB_RESP_FUN_NUM_S 6
4419 +
4420 +/* AHB Control Register, fixed bus enumeration exception */
4421 +#define PCIE_AHB_CTRL(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x78)
4422 +#define PCIE_AHB_CTRL_BUS_ERROR_SUPPRESS 0x00000001
4423 +
4424 +/* Interrupt Enalbe Register */
4425 +#define PCIE_IRNEN(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0xF4)
4426 +#define PCIE_IRNCR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0xF8)
4427 +#define PCIE_IRNICR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0xFC)
4428 +
4429 +/* PCIe interrupt enable/control/capture register definition */
4430 +#define PCIE_IRN_AER_REPORT 0x00000001 /* AER Interrupt */
4431 +#define PCIE_IRN_AER_MSIX 0x00000002 /* Advanced Error MSI-X Interrupt */
4432 +#define PCIE_IRN_PME 0x00000004 /* PME Interrupt */
4433 +#define PCIE_IRN_HOTPLUG 0x00000008 /* Hotplug Interrupt */
4434 +#define PCIE_IRN_RX_VDM_MSG 0x00000010 /* Vendor-Defined Message Interrupt */
4435 +#define PCIE_IRN_RX_CORRECTABLE_ERR_MSG 0x00000020 /* Correctable Error Message Interrupt */
4436 +#define PCIE_IRN_RX_NON_FATAL_ERR_MSG 0x00000040 /* Non-fatal Error Message */
4437 +#define PCIE_IRN_RX_FATAL_ERR_MSG 0x00000080 /* Fatal Error Message */
4438 +#define PCIE_IRN_RX_PME_MSG 0x00000100 /* PME Message Interrupt */
4439 +#define PCIE_IRN_RX_PME_TURNOFF_ACK 0x00000200 /* PME Turnoff Ack Message Interrupt */
4440 +#define PCIE_IRN_AHB_BR_FATAL_ERR 0x00000400 /* AHB Fatal Error Interrupt */
4441 +#define PCIE_IRN_LINK_AUTO_BW_STATUS 0x00000800 /* Link Auto Bandwidth Status Interrupt */
4442 +#define PCIE_IRN_BW_MGT 0x00001000 /* Bandwidth Managment Interrupt */
4443 +#define PCIE_IRN_INTA 0x00002000 /* INTA */
4444 +#define PCIE_IRN_INTB 0x00004000 /* INTB */
4445 +#define PCIE_IRN_INTC 0x00008000 /* INTC */
4446 +#define PCIE_IRN_INTD 0x00010000 /* INTD */
4447 +#define PCIE_IRN_WAKEUP 0x00020000 /* Wake up Interrupt */
4448 +
4449 +#define PCIE_RC_CORE_COMBINED_INT (PCIE_IRN_AER_REPORT | PCIE_IRN_AER_MSIX | PCIE_IRN_PME | \
4450 + PCIE_IRN_HOTPLUG | PCIE_IRN_RX_VDM_MSG | PCIE_IRN_RX_CORRECTABLE_ERR_MSG |\
4451 + PCIE_IRN_RX_NON_FATAL_ERR_MSG | PCIE_IRN_RX_FATAL_ERR_MSG | \
4452 + PCIE_IRN_RX_PME_MSG | PCIE_IRN_RX_PME_TURNOFF_ACK | PCIE_IRN_AHB_BR_FATAL_ERR | \
4453 + PCIE_IRN_LINK_AUTO_BW_STATUS | PCIE_IRN_BW_MGT)
4454 +/* PCIe RC Configuration Register */
4455 +#define PCIE_VDID(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x00)
4456 +
4457 +/* Bit definition from pci_reg.h */
4458 +#define PCIE_PCICMDSTS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x04)
4459 +#define PCIE_CCRID(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x08)
4460 +#define PCIE_CLSLTHTBR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x0C) /* EP only */
4461 +/* BAR0, BAR1,Only necessary if the bridges implements a device-specific register set or memory buffer */
4462 +#define PCIE_BAR0(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x10) /* Not used*/
4463 +#define PCIE_BAR1(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x14) /* Not used */
4464 +
4465 +#define PCIE_BNR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x18) /* Mandatory */
4466 +/* Bus Number Register bits */
4467 +#define PCIE_BNR_PRIMARY_BUS_NUM 0x000000FF
4468 +#define PCIE_BNR_PRIMARY_BUS_NUM_S 0
4469 +#define PCIE_PNR_SECONDARY_BUS_NUM 0x0000FF00
4470 +#define PCIE_PNR_SECONDARY_BUS_NUM_S 8
4471 +#define PCIE_PNR_SUB_BUS_NUM 0x00FF0000
4472 +#define PCIE_PNR_SUB_BUS_NUM_S 16
4473 +
4474 +/* IO Base/Limit Register bits */
4475 +#define PCIE_IOBLSECS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x1C) /* RC only */
4476 +#define PCIE_IOBLSECS_32BIT_IO_ADDR 0x00000001
4477 +#define PCIE_IOBLSECS_IO_BASE_ADDR 0x000000F0
4478 +#define PCIE_IOBLSECS_IO_BASE_ADDR_S 4
4479 +#define PCIE_IOBLSECS_32BIT_IOLIMT 0x00000100
4480 +#define PCIE_IOBLSECS_IO_LIMIT_ADDR 0x0000F000
4481 +#define PCIE_IOBLSECS_IO_LIMIT_ADDR_S 12
4482 +
4483 +/* Non-prefetchable Memory Base/Limit Register bit */
4484 +#define PCIE_MBML(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x20) /* RC only */
4485 +#define PCIE_MBML_MEM_BASE_ADDR 0x0000FFF0
4486 +#define PCIE_MBML_MEM_BASE_ADDR_S 4
4487 +#define PCIE_MBML_MEM_LIMIT_ADDR 0xFFF00000
4488 +#define PCIE_MBML_MEM_LIMIT_ADDR_S 20
4489 +
4490 +/* Prefetchable Memory Base/Limit Register bit */
4491 +#define PCIE_PMBL(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x24) /* RC only */
4492 +#define PCIE_PMBL_64BIT_ADDR 0x00000001
4493 +#define PCIE_PMBL_UPPER_12BIT 0x0000FFF0
4494 +#define PCIE_PMBL_UPPER_12BIT_S 4
4495 +#define PCIE_PMBL_E64MA 0x00010000
4496 +#define PCIE_PMBL_END_ADDR 0xFFF00000
4497 +#define PCIE_PMBL_END_ADDR_S 20
4498 +#define PCIE_PMBU32(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x28) /* RC only */
4499 +#define PCIE_PMLU32(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x2C) /* RC only */
4500 +
4501 +/* I/O Base/Limit Upper 16 bits register */
4502 +#define PCIE_IO_BANDL(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x30) /* RC only */
4503 +#define PCIE_IO_BANDL_UPPER_16BIT_IO_BASE 0x0000FFFF
4504 +#define PCIE_IO_BANDL_UPPER_16BIT_IO_BASE_S 0
4505 +#define PCIE_IO_BANDL_UPPER_16BIT_IO_LIMIT 0xFFFF0000
4506 +#define PCIE_IO_BANDL_UPPER_16BIT_IO_LIMIT_S 16
4507 +
4508 +#define PCIE_CPR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x34)
4509 +#define PCIE_EBBAR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x38)
4510 +
4511 +/* Interrupt and Secondary Bridge Control Register */
4512 +#define PCIE_INTRBCTRL(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x3C)
4513 +
4514 +#define PCIE_INTRBCTRL_INT_LINE 0x000000FF
4515 +#define PCIE_INTRBCTRL_INT_LINE_S 0
4516 +#define PCIE_INTRBCTRL_INT_PIN 0x0000FF00
4517 +#define PCIE_INTRBCTRL_INT_PIN_S 8
4518 +#define PCIE_INTRBCTRL_PARITY_ERR_RESP_ENABLE 0x00010000 /* #PERR */
4519 +#define PCIE_INTRBCTRL_SERR_ENABLE 0x00020000 /* #SERR */
4520 +#define PCIE_INTRBCTRL_ISA_ENABLE 0x00040000 /* ISA enable, IO 64KB only */
4521 +#define PCIE_INTRBCTRL_VGA_ENABLE 0x00080000 /* VGA enable */
4522 +#define PCIE_INTRBCTRL_VGA_16BIT_DECODE 0x00100000 /* VGA 16bit decode */
4523 +#define PCIE_INTRBCTRL_RST_SECONDARY_BUS 0x00400000 /* Secondary bus rest, hot rest, 1ms */
4524 +/* Others are read only */
4525 +enum {
4526 + PCIE_INTRBCTRL_INT_NON = 0,
4527 + PCIE_INTRBCTRL_INTA,
4528 + PCIE_INTRBCTRL_INTB,
4529 + PCIE_INTRBCTRL_INTC,
4530 + PCIE_INTRBCTRL_INTD,
4531 +};
4532 +
4533 +#define PCIE_PM_CAPR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x40)
4534 +
4535 +/* Power Management Control and Status Register */
4536 +#define PCIE_PM_CSR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x44)
4537 +
4538 +#define PCIE_PM_CSR_POWER_STATE 0x00000003 /* Power State */
4539 +#define PCIE_PM_CSR_POWER_STATE_S 0
4540 +#define PCIE_PM_CSR_SW_RST 0x00000008 /* Soft Reset Enabled */
4541 +#define PCIE_PM_CSR_PME_ENABLE 0x00000100 /* PME Enable */
4542 +#define PCIE_PM_CSR_PME_STATUS 0x00008000 /* PME status */
4543 +
4544 +/* MSI Capability Register for EP */
4545 +#define PCIE_MCAPR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x50)
4546 +
4547 +#define PCIE_MCAPR_MSI_CAP_ID 0x000000FF /* MSI Capability ID */
4548 +#define PCIE_MCAPR_MSI_CAP_ID_S 0
4549 +#define PCIE_MCAPR_MSI_NEXT_CAP_PTR 0x0000FF00 /* Next Capability Pointer */
4550 +#define PCIE_MCAPR_MSI_NEXT_CAP_PTR_S 8
4551 +#define PCIE_MCAPR_MSI_ENABLE 0x00010000 /* MSI Enable */
4552 +#define PCIE_MCAPR_MULTI_MSG_CAP 0x000E0000 /* Multiple Message Capable */
4553 +#define PCIE_MCAPR_MULTI_MSG_CAP_S 17
4554 +#define PCIE_MCAPR_MULTI_MSG_ENABLE 0x00700000 /* Multiple Message Enable */
4555 +#define PCIE_MCAPR_MULTI_MSG_ENABLE_S 20
4556 +#define PCIE_MCAPR_ADDR64_CAP 0X00800000 /* 64-bit Address Capable */
4557 +
4558 +/* MSI Message Address Register */
4559 +#define PCIE_MA(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x54)
4560 +
4561 +#define PCIE_MA_ADDR_MASK 0xFFFFFFFC /* Message Address */
4562 +
4563 +/* MSI Message Upper Address Register */
4564 +#define PCIE_MUA(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x58)
4565 +
4566 +/* MSI Message Data Register */
4567 +#define PCIE_MD(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x5C)
4568 +
4569 +#define PCIE_MD_DATA 0x0000FFFF /* Message Data */
4570 +#define PCIE_MD_DATA_S 0
4571 +
4572 +/* PCI Express Capability Register */
4573 +#define PCIE_XCAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x70)
4574 +
4575 +#define PCIE_XCAP_ID 0x000000FF /* PCI Express Capability ID */
4576 +#define PCIE_XCAP_ID_S 0
4577 +#define PCIE_XCAP_NEXT_CAP 0x0000FF00 /* Next Capability Pointer */
4578 +#define PCIE_XCAP_NEXT_CAP_S 8
4579 +#define PCIE_XCAP_VER 0x000F0000 /* PCI Express Capability Version */
4580 +#define PCIE_XCAP_VER_S 16
4581 +#define PCIE_XCAP_DEV_PORT_TYPE 0x00F00000 /* Device Port Type */
4582 +#define PCIE_XCAP_DEV_PORT_TYPE_S 20
4583 +#define PCIE_XCAP_SLOT_IMPLEMENTED 0x01000000 /* Slot Implemented */
4584 +#define PCIE_XCAP_MSG_INT_NUM 0x3E000000 /* Interrupt Message Number */
4585 +#define PCIE_XCAP_MSG_INT_NUM_S 25
4586 +
4587 +/* Device Capability Register */
4588 +#define PCIE_DCAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x74)
4589 +
4590 +#define PCIE_DCAP_MAX_PAYLOAD_SIZE 0x00000007 /* Max Payload size */
4591 +#define PCIE_DCAP_MAX_PAYLOAD_SIZE_S 0
4592 +#define PCIE_DCAP_PHANTOM_FUNC 0x00000018 /* Phanton Function, not supported */
4593 +#define PCIE_DCAP_PHANTOM_FUNC_S 3
4594 +#define PCIE_DCAP_EXT_TAG 0x00000020 /* Extended Tag Field */
4595 +#define PCIE_DCAP_EP_L0S_LATENCY 0x000001C0 /* EP L0s latency only */
4596 +#define PCIE_DCAP_EP_L0S_LATENCY_S 6
4597 +#define PCIE_DCAP_EP_L1_LATENCY 0x00000E00 /* EP L1 latency only */
4598 +#define PCIE_DCAP_EP_L1_LATENCY_S 9
4599 +#define PCIE_DCAP_ROLE_BASE_ERR_REPORT 0x00008000 /* Role Based ERR */
4600 +
4601 +/* Maximum payload size supported */
4602 +enum {
4603 + PCIE_MAX_PAYLOAD_128 = 0,
4604 + PCIE_MAX_PAYLOAD_256,
4605 + PCIE_MAX_PAYLOAD_512,
4606 + PCIE_MAX_PAYLOAD_1024,
4607 + PCIE_MAX_PAYLOAD_2048,
4608 + PCIE_MAX_PAYLOAD_4096,
4609 +};
4610 +
4611 +/* Device Control and Status Register */
4612 +#define PCIE_DCTLSTS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x78)
4613 +
4614 +#define PCIE_DCTLSTS_CORRECTABLE_ERR_EN 0x00000001 /* COR-ERR */
4615 +#define PCIE_DCTLSTS_NONFATAL_ERR_EN 0x00000002 /* Non-fatal ERR */
4616 +#define PCIE_DCTLSTS_FATAL_ERR_EN 0x00000004 /* Fatal ERR */
4617 +#define PCIE_DCTLSYS_UR_REQ_EN 0x00000008 /* UR ERR */
4618 +#define PCIE_DCTLSTS_RELAXED_ORDERING_EN 0x00000010 /* Enable relaxing ordering */
4619 +#define PCIE_DCTLSTS_MAX_PAYLOAD_SIZE 0x000000E0 /* Max payload mask */
4620 +#define PCIE_DCTLSTS_MAX_PAYLOAD_SIZE_S 5
4621 +#define PCIE_DCTLSTS_EXT_TAG_EN 0x00000100 /* Extended tag field */
4622 +#define PCIE_DCTLSTS_PHANTOM_FUNC_EN 0x00000200 /* Phantom Function Enable */
4623 +#define PCIE_DCTLSTS_AUX_PM_EN 0x00000400 /* AUX Power PM Enable */
4624 +#define PCIE_DCTLSTS_NO_SNOOP_EN 0x00000800 /* Enable no snoop, except root port*/
4625 +#define PCIE_DCTLSTS_MAX_READ_SIZE 0x00007000 /* Max Read Request size*/
4626 +#define PCIE_DCTLSTS_MAX_READ_SIZE_S 12
4627 +#define PCIE_DCTLSTS_CORRECTABLE_ERR 0x00010000 /* COR-ERR Detected */
4628 +#define PCIE_DCTLSTS_NONFATAL_ERR 0x00020000 /* Non-Fatal ERR Detected */
4629 +#define PCIE_DCTLSTS_FATAL_ER 0x00040000 /* Fatal ERR Detected */
4630 +#define PCIE_DCTLSTS_UNSUPPORTED_REQ 0x00080000 /* UR Detected */
4631 +#define PCIE_DCTLSTS_AUX_POWER 0x00100000 /* Aux Power Detected */
4632 +#define PCIE_DCTLSTS_TRANSACT_PENDING 0x00200000 /* Transaction pending */
4633 +
4634 +#define PCIE_DCTLSTS_ERR_EN (PCIE_DCTLSTS_CORRECTABLE_ERR_EN | \
4635 + PCIE_DCTLSTS_NONFATAL_ERR_EN | PCIE_DCTLSTS_FATAL_ERR_EN | \
4636 + PCIE_DCTLSYS_UR_REQ_EN)
4637 +
4638 +/* Link Capability Register */
4639 +#define PCIE_LCAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x7C)
4640 +#define PCIE_LCAP_MAX_LINK_SPEED 0x0000000F /* Max link speed, 0x1 by default */
4641 +#define PCIE_LCAP_MAX_LINK_SPEED_S 0
4642 +#define PCIE_LCAP_MAX_LENGTH_WIDTH 0x000003F0 /* Maxium Length Width */
4643 +#define PCIE_LCAP_MAX_LENGTH_WIDTH_S 4
4644 +#define PCIE_LCAP_ASPM_LEVEL 0x00000C00 /* Active State Link PM Support */
4645 +#define PCIE_LCAP_ASPM_LEVEL_S 10
4646 +#define PCIE_LCAP_L0S_EIXT_LATENCY 0x00007000 /* L0s Exit Latency */
4647 +#define PCIE_LCAP_L0S_EIXT_LATENCY_S 12
4648 +#define PCIE_LCAP_L1_EXIT_LATENCY 0x00038000 /* L1 Exit Latency */
4649 +#define PCIE_LCAP_L1_EXIT_LATENCY_S 15
4650 +#define PCIE_LCAP_CLK_PM 0x00040000 /* Clock Power Management */
4651 +#define PCIE_LCAP_SDER 0x00080000 /* Surprise Down Error Reporting */
4652 +#define PCIE_LCAP_DLL_ACTIVE_REPROT 0x00100000 /* Data Link Layer Active Reporting Capable */
4653 +#define PCIE_LCAP_PORT_NUM 0xFF0000000 /* Port number */
4654 +#define PCIE_LCAP_PORT_NUM_S 24
4655 +
4656 +/* Maximum Length width definition */
4657 +#define PCIE_MAX_LENGTH_WIDTH_RES 0x00
4658 +#define PCIE_MAX_LENGTH_WIDTH_X1 0x01 /* Default */
4659 +#define PCIE_MAX_LENGTH_WIDTH_X2 0x02
4660 +#define PCIE_MAX_LENGTH_WIDTH_X4 0x04
4661 +#define PCIE_MAX_LENGTH_WIDTH_X8 0x08
4662 +#define PCIE_MAX_LENGTH_WIDTH_X12 0x0C
4663 +#define PCIE_MAX_LENGTH_WIDTH_X16 0x10
4664 +#define PCIE_MAX_LENGTH_WIDTH_X32 0x20
4665 +
4666 +/* Active State Link PM definition */
4667 +enum {
4668 + PCIE_ASPM_RES0 = 0,
4669 + PCIE_ASPM_L0S_ENTRY_SUPPORT, /* L0s */
4670 + PCIE_ASPM_RES1,
4671 + PCIE_ASPM_L0S_L1_ENTRY_SUPPORT, /* L0s and L1, default */
4672 +};
4673 +
4674 +/* L0s Exit Latency definition */
4675 +enum {
4676 + PCIE_L0S_EIXT_LATENCY_L64NS = 0, /* < 64 ns */
4677 + PCIE_L0S_EIXT_LATENCY_B64A128, /* > 64 ns < 128 ns */
4678 + PCIE_L0S_EIXT_LATENCY_B128A256, /* > 128 ns < 256 ns */
4679 + PCIE_L0S_EIXT_LATENCY_B256A512, /* > 256 ns < 512 ns */
4680 + PCIE_L0S_EIXT_LATENCY_B512TO1U, /* > 512 ns < 1 us */
4681 + PCIE_L0S_EIXT_LATENCY_B1A2U, /* > 1 us < 2 us */
4682 + PCIE_L0S_EIXT_LATENCY_B2A4U, /* > 2 us < 4 us */
4683 + PCIE_L0S_EIXT_LATENCY_M4US, /* > 4 us */
4684 +};
4685 +
4686 +/* L1 Exit Latency definition */
4687 +enum {
4688 + PCIE_L1_EXIT_LATENCY_L1US = 0, /* < 1 us */
4689 + PCIE_L1_EXIT_LATENCY_B1A2, /* > 1 us < 2 us */
4690 + PCIE_L1_EXIT_LATENCY_B2A4, /* > 2 us < 4 us */
4691 + PCIE_L1_EXIT_LATENCY_B4A8, /* > 4 us < 8 us */
4692 + PCIE_L1_EXIT_LATENCY_B8A16, /* > 8 us < 16 us */
4693 + PCIE_L1_EXIT_LATENCY_B16A32, /* > 16 us < 32 us */
4694 + PCIE_L1_EXIT_LATENCY_B32A64, /* > 32 us < 64 us */
4695 + PCIE_L1_EXIT_LATENCY_M64US, /* > 64 us */
4696 +};
4697 +
4698 +/* Link Control and Status Register */
4699 +#define PCIE_LCTLSTS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x80)
4700 +#define PCIE_LCTLSTS_ASPM_ENABLE 0x00000003 /* Active State Link PM Control */
4701 +#define PCIE_LCTLSTS_ASPM_ENABLE_S 0
4702 +#define PCIE_LCTLSTS_RCB128 0x00000008 /* Read Completion Boundary 128*/
4703 +#define PCIE_LCTLSTS_LINK_DISABLE 0x00000010 /* Link Disable */
4704 +#define PCIE_LCTLSTS_RETRIAN_LINK 0x00000020 /* Retrain Link */
4705 +#define PCIE_LCTLSTS_COM_CLK_CFG 0x00000040 /* Common Clock Configuration */
4706 +#define PCIE_LCTLSTS_EXT_SYNC 0x00000080 /* Extended Synch */
4707 +#define PCIE_LCTLSTS_CLK_PM_EN 0x00000100 /* Enable Clock Powerm Management */
4708 +#define PCIE_LCTLSTS_LINK_SPEED 0x000F0000 /* Link Speed */
4709 +#define PCIE_LCTLSTS_LINK_SPEED_S 16
4710 +#define PCIE_LCTLSTS_NEGOTIATED_LINK_WIDTH 0x03F00000 /* Negotiated Link Width */
4711 +#define PCIE_LCTLSTS_NEGOTIATED_LINK_WIDTH_S 20
4712 +#define PCIE_LCTLSTS_RETRAIN_PENDING 0x08000000 /* Link training is ongoing */
4713 +#define PCIE_LCTLSTS_SLOT_CLK_CFG 0x10000000 /* Slot Clock Configuration */
4714 +#define PCIE_LCTLSTS_DLL_ACTIVE 0x20000000 /* Data Link Layer Active */
4715 +
4716 +/* Slot Capabilities Register */
4717 +#define PCIE_SLCAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x84)
4718 +
4719 +/* Slot Capabilities */
4720 +#define PCIE_SLCTLSTS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x88)
4721 +
4722 +/* Root Control and Capability Register */
4723 +#define PCIE_RCTLCAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x8C)
4724 +#define PCIE_RCTLCAP_SERR_ON_CORRECTABLE_ERR 0x00000001 /* #SERR on COR-ERR */
4725 +#define PCIE_RCTLCAP_SERR_ON_NONFATAL_ERR 0x00000002 /* #SERR on Non-Fatal ERR */
4726 +#define PCIE_RCTLCAP_SERR_ON_FATAL_ERR 0x00000004 /* #SERR on Fatal ERR */
4727 +#define PCIE_RCTLCAP_PME_INT_EN 0x00000008 /* PME Interrupt Enable */
4728 +#define PCIE_RCTLCAP_SERR_ENABLE (PCIE_RCTLCAP_SERR_ON_CORRECTABLE_ERR | \
4729 + PCIE_RCTLCAP_SERR_ON_NONFATAL_ERR | PCIE_RCTLCAP_SERR_ON_FATAL_ERR)
4730 +/* Root Status Register */
4731 +#define PCIE_RSTS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x90)
4732 +#define PCIE_RSTS_PME_REQ_ID 0x0000FFFF /* PME Request ID */
4733 +#define PCIE_RSTS_PME_REQ_ID_S 0
4734 +#define PCIE_RSTS_PME_STATUS 0x00010000 /* PME Status */
4735 +#define PCIE_RSTS_PME_PENDING 0x00020000 /* PME Pending */
4736 +
4737 +/* PCI Express Enhanced Capability Header */
4738 +#define PCIE_ENHANCED_CAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x100)
4739 +#define PCIE_ENHANCED_CAP_ID 0x0000FFFF /* PCI Express Extended Capability ID */
4740 +#define PCIE_ENHANCED_CAP_ID_S 0
4741 +#define PCIE_ENHANCED_CAP_VER 0x000F0000 /* Capability Version */
4742 +#define PCIE_ENHANCED_CAP_VER_S 16
4743 +#define PCIE_ENHANCED_CAP_NEXT_OFFSET 0xFFF00000 /* Next Capability Offset */
4744 +#define PCIE_ENHANCED_CAP_NEXT_OFFSET_S 20
4745 +
4746 +/* Uncorrectable Error Status Register */
4747 +#define PCIE_UES_R(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x104)
4748 +#define PCIE_DATA_LINK_PROTOCOL_ERR 0x00000010 /* Data Link Protocol Error Status */
4749 +#define PCIE_SURPRISE_DOWN_ERROR 0x00000020 /* Surprise Down Error Status */
4750 +#define PCIE_POISONED_TLP 0x00001000 /* Poisoned TLP Status */
4751 +#define PCIE_FC_PROTOCOL_ERR 0x00002000 /* Flow Control Protocol Error Status */
4752 +#define PCIE_COMPLETION_TIMEOUT 0x00004000 /* Completion Timeout Status */
4753 +#define PCIE_COMPLETOR_ABORT 0x00008000 /* Completer Abort Error */
4754 +#define PCIE_UNEXPECTED_COMPLETION 0x00010000 /* Unexpected Completion Status */
4755 +#define PCIE_RECEIVER_OVERFLOW 0x00020000 /* Receive Overflow Status */
4756 +#define PCIE_MALFORNED_TLP 0x00040000 /* Malformed TLP Stauts */
4757 +#define PCIE_ECRC_ERR 0x00080000 /* ECRC Error Stauts */
4758 +#define PCIE_UR_REQ 0x00100000 /* Unsupported Request Error Status */
4759 +#define PCIE_ALL_UNCORRECTABLE_ERR (PCIE_DATA_LINK_PROTOCOL_ERR | PCIE_SURPRISE_DOWN_ERROR | \
4760 + PCIE_POISONED_TLP | PCIE_FC_PROTOCOL_ERR | PCIE_COMPLETION_TIMEOUT | \
4761 + PCIE_COMPLETOR_ABORT | PCIE_UNEXPECTED_COMPLETION | PCIE_RECEIVER_OVERFLOW |\
4762 + PCIE_MALFORNED_TLP | PCIE_ECRC_ERR | PCIE_UR_REQ)
4763 +
4764 +/* Uncorrectable Error Mask Register, Mask means no report */
4765 +#define PCIE_UEMR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x108)
4766 +
4767 +/* Uncorrectable Error Severity Register */
4768 +#define PCIE_UESR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x10C)
4769 +
4770 +/* Correctable Error Status Register */
4771 +#define PCIE_CESR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x110)
4772 +#define PCIE_RX_ERR 0x00000001 /* Receive Error Status */
4773 +#define PCIE_BAD_TLP 0x00000040 /* Bad TLP Status */
4774 +#define PCIE_BAD_DLLP 0x00000080 /* Bad DLLP Status */
4775 +#define PCIE_REPLAY_NUM_ROLLOVER 0x00000100 /* Replay Number Rollover Status */
4776 +#define PCIE_REPLAY_TIMER_TIMEOUT_ERR 0x00001000 /* Reply Timer Timeout Status */
4777 +#define PCIE_ADVISORY_NONFTAL_ERR 0x00002000 /* Advisory Non-Fatal Error Status */
4778 +#define PCIE_CORRECTABLE_ERR (PCIE_RX_ERR | PCIE_BAD_TLP | PCIE_BAD_DLLP | PCIE_REPLAY_NUM_ROLLOVER |\
4779 + PCIE_REPLAY_TIMER_TIMEOUT_ERR | PCIE_ADVISORY_NONFTAL_ERR)
4780 +
4781 +/* Correctable Error Mask Register */
4782 +#define PCIE_CEMR(X) (volatile u32*)(PCIE_RC_CFG_BASE + 0x114)
4783 +
4784 +/* Advanced Error Capabilities and Control Register */
4785 +#define PCIE_AECCR(X) (volatile u32*)(PCIE_RC_CFG_BASE + 0x118)
4786 +#define PCIE_AECCR_FIRST_ERR_PTR 0x0000001F /* First Error Pointer */
4787 +#define PCIE_AECCR_FIRST_ERR_PTR_S 0
4788 +#define PCIE_AECCR_ECRC_GEN_CAP 0x00000020 /* ECRC Generation Capable */
4789 +#define PCIE_AECCR_ECRC_GEN_EN 0x00000040 /* ECRC Generation Enable */
4790 +#define PCIE_AECCR_ECRC_CHECK_CAP 0x00000080 /* ECRC Check Capable */
4791 +#define PCIE_AECCR_ECRC_CHECK_EN 0x00000100 /* ECRC Check Enable */
4792 +
4793 +/* Header Log Register 1 */
4794 +#define PCIE_HLR1(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x11C)
4795 +
4796 +/* Header Log Register 2 */
4797 +#define PCIE_HLR2(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x120)
4798 +
4799 +/* Header Log Register 3 */
4800 +#define PCIE_HLR3(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x124)
4801 +
4802 +/* Header Log Register 4 */
4803 +#define PCIE_HLR4(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x128)
4804 +
4805 +/* Root Error Command Register */
4806 +#define PCIE_RECR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x12C)
4807 +#define PCIE_RECR_CORRECTABLE_ERR_REPORT_EN 0x00000001 /* COR-ERR */
4808 +#define PCIE_RECR_NONFATAL_ERR_REPORT_EN 0x00000002 /* Non-Fatal ERR */
4809 +#define PCIE_RECR_FATAL_ERR_REPORT_EN 0x00000004 /* Fatal ERR */
4810 +#define PCIE_RECR_ERR_REPORT_EN (PCIE_RECR_CORRECTABLE_ERR_REPORT_EN | \
4811 + PCIE_RECR_NONFATAL_ERR_REPORT_EN | PCIE_RECR_FATAL_ERR_REPORT_EN)
4812 +
4813 +/* Root Error Status Register */
4814 +#define PCIE_RESR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x130)
4815 +#define PCIE_RESR_CORRECTABLE_ERR 0x00000001 /* COR-ERR Receveid */
4816 +#define PCIE_RESR_MULTI_CORRECTABLE_ERR 0x00000002 /* Multiple COR-ERR Received */
4817 +#define PCIE_RESR_FATAL_NOFATAL_ERR 0x00000004 /* ERR Fatal/Non-Fatal Received */
4818 +#define PCIE_RESR_MULTI_FATAL_NOFATAL_ERR 0x00000008 /* Multiple ERR Fatal/Non-Fatal Received */
4819 +#define PCIE_RESR_FIRST_UNCORRECTABLE_FATAL_ERR 0x00000010 /* First UN-COR Fatal */
4820 +#define PCIR_RESR_NON_FATAL_ERR 0x00000020 /* Non-Fatal Error Message Received */
4821 +#define PCIE_RESR_FATAL_ERR 0x00000040 /* Fatal Message Received */
4822 +#define PCIE_RESR_AER_INT_MSG_NUM 0xF8000000 /* Advanced Error Interrupt Message Number */
4823 +#define PCIE_RESR_AER_INT_MSG_NUM_S 27
4824 +
4825 +/* Error Source Indentification Register */
4826 +#define PCIE_ESIR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x134)
4827 +#define PCIE_ESIR_CORRECTABLE_ERR_SRC_ID 0x0000FFFF
4828 +#define PCIE_ESIR_CORRECTABLE_ERR_SRC_ID_S 0
4829 +#define PCIE_ESIR_FATAL_NON_FATAL_SRC_ID 0xFFFF0000
4830 +#define PCIE_ESIR_FATAL_NON_FATAL_SRC_ID_S 16
4831 +
4832 +/* VC Enhanced Capability Header */
4833 +#define PCIE_VC_ECH(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x140)
4834 +
4835 +/* Port VC Capability Register */
4836 +#define PCIE_PVC1(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x144)
4837 +#define PCIE_PVC1_EXT_VC_CNT 0x00000007 /* Extended VC Count */
4838 +#define PCIE_PVC1_EXT_VC_CNT_S 0
4839 +#define PCIE_PVC1_LOW_PRI_EXT_VC_CNT 0x00000070 /* Low Priority Extended VC Count */
4840 +#define PCIE_PVC1_LOW_PRI_EXT_VC_CNT_S 4
4841 +#define PCIE_PVC1_REF_CLK 0x00000300 /* Reference Clock */
4842 +#define PCIE_PVC1_REF_CLK_S 8
4843 +#define PCIE_PVC1_PORT_ARB_TAB_ENTRY_SIZE 0x00000C00 /* Port Arbitration Table Entry Size */
4844 +#define PCIE_PVC1_PORT_ARB_TAB_ENTRY_SIZE_S 10
4845 +
4846 +/* Extended Virtual Channel Count Defintion */
4847 +#define PCIE_EXT_VC_CNT_MIN 0
4848 +#define PCIE_EXT_VC_CNT_MAX 7
4849 +
4850 +/* Port Arbitration Table Entry Size Definition */
4851 +enum {
4852 + PCIE_PORT_ARB_TAB_ENTRY_SIZE_S1BIT = 0,
4853 + PCIE_PORT_ARB_TAB_ENTRY_SIZE_S2BIT,
4854 + PCIE_PORT_ARB_TAB_ENTRY_SIZE_S4BIT,
4855 + PCIE_PORT_ARB_TAB_ENTRY_SIZE_S8BIT,
4856 +};
4857 +
4858 +/* Port VC Capability Register 2 */
4859 +#define PCIE_PVC2(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x148)
4860 +#define PCIE_PVC2_VC_ARB_16P_FIXED_WRR 0x00000001 /* HW Fixed arbitration, 16 phase WRR */
4861 +#define PCIE_PVC2_VC_ARB_32P_WRR 0x00000002 /* 32 phase WRR */
4862 +#define PCIE_PVC2_VC_ARB_64P_WRR 0x00000004 /* 64 phase WRR */
4863 +#define PCIE_PVC2_VC_ARB_128P_WRR 0x00000008 /* 128 phase WRR */
4864 +#define PCIE_PVC2_VC_ARB_WRR 0x0000000F
4865 +#define PCIE_PVC2_VC_ARB_TAB_OFFSET 0xFF000000 /* VC arbitration table offset, not support */
4866 +#define PCIE_PVC2_VC_ARB_TAB_OFFSET_S 24
4867 +
4868 +/* Port VC Control and Status Register */
4869 +#define PCIE_PVCCRSR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x14C)
4870 +#define PCIE_PVCCRSR_LOAD_VC_ARB_TAB 0x00000001 /* Load VC Arbitration Table */
4871 +#define PCIE_PVCCRSR_VC_ARB_SEL 0x0000000E /* VC Arbitration Select */
4872 +#define PCIE_PVCCRSR_VC_ARB_SEL_S 1
4873 +#define PCIE_PVCCRSR_VC_ARB_TAB_STATUS 0x00010000 /* Arbitration Status */
4874 +
4875 +/* VC0 Resource Capability Register */
4876 +#define PCIE_VC0_RC(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x150)
4877 +#define PCIE_VC0_RC_PORT_ARB_HW_FIXED 0x00000001 /* HW Fixed arbitration */
4878 +#define PCIE_VC0_RC_PORT_ARB_32P_WRR 0x00000002 /* 32 phase WRR */
4879 +#define PCIE_VC0_RC_PORT_ARB_64P_WRR 0x00000004 /* 64 phase WRR */
4880 +#define PCIE_VC0_RC_PORT_ARB_128P_WRR 0x00000008 /* 128 phase WRR */
4881 +#define PCIE_VC0_RC_PORT_ARB_TM_128P_WRR 0x00000010 /* Time-based 128 phase WRR */
4882 +#define PCIE_VC0_RC_PORT_ARB_TM_256P_WRR 0x00000020 /* Time-based 256 phase WRR */
4883 +#define PCIE_VC0_RC_PORT_ARB (PCIE_VC0_RC_PORT_ARB_HW_FIXED | PCIE_VC0_RC_PORT_ARB_32P_WRR |\
4884 + PCIE_VC0_RC_PORT_ARB_64P_WRR | PCIE_VC0_RC_PORT_ARB_128P_WRR | \
4885 + PCIE_VC0_RC_PORT_ARB_TM_128P_WRR | PCIE_VC0_RC_PORT_ARB_TM_256P_WRR)
4886 +
4887 +#define PCIE_VC0_RC_REJECT_SNOOP 0x00008000 /* Reject Snoop Transactioin */
4888 +#define PCIE_VC0_RC_MAX_TIMESLOTS 0x007F0000 /* Maximum time Slots */
4889 +#define PCIE_VC0_RC_MAX_TIMESLOTS_S 16
4890 +#define PCIE_VC0_RC_PORT_ARB_TAB_OFFSET 0xFF000000 /* Port Arbitration Table Offset */
4891 +#define PCIE_VC0_RC_PORT_ARB_TAB_OFFSET_S 24
4892 +
4893 +/* VC0 Resource Control Register */
4894 +#define PCIE_VC0_RC0(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x154)
4895 +#define PCIE_VC0_RC0_TVM0 0x00000001 /* TC0 and VC0 */
4896 +#define PCIE_VC0_RC0_TVM1 0x00000002 /* TC1 and VC1 */
4897 +#define PCIE_VC0_RC0_TVM2 0x00000004 /* TC2 and VC2 */
4898 +#define PCIE_VC0_RC0_TVM3 0x00000008 /* TC3 and VC3 */
4899 +#define PCIE_VC0_RC0_TVM4 0x00000010 /* TC4 and VC4 */
4900 +#define PCIE_VC0_RC0_TVM5 0x00000020 /* TC5 and VC5 */
4901 +#define PCIE_VC0_RC0_TVM6 0x00000040 /* TC6 and VC6 */
4902 +#define PCIE_VC0_RC0_TVM7 0x00000080 /* TC7 and VC7 */
4903 +#define PCIE_VC0_RC0_TC_VC 0x000000FF /* TC/VC mask */
4904 +
4905 +#define PCIE_VC0_RC0_LOAD_PORT_ARB_TAB 0x00010000 /* Load Port Arbitration Table */
4906 +#define PCIE_VC0_RC0_PORT_ARB_SEL 0x000E0000 /* Port Arbitration Select */
4907 +#define PCIE_VC0_RC0_PORT_ARB_SEL_S 17
4908 +#define PCIE_VC0_RC0_VC_ID 0x07000000 /* VC ID */
4909 +#define PCIE_VC0_RC0_VC_ID_S 24
4910 +#define PCIE_VC0_RC0_VC_EN 0x80000000 /* VC Enable */
4911 +
4912 +/* VC0 Resource Status Register */
4913 +#define PCIE_VC0_RSR0(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x158)
4914 +#define PCIE_VC0_RSR0_PORT_ARB_TAB_STATUS 0x00010000 /* Port Arbitration Table Status,not used */
4915 +#define PCIE_VC0_RSR0_VC_NEG_PENDING 0x00020000 /* VC Negotiation Pending */
4916 +
4917 +/* Ack Latency Timer and Replay Timer Register */
4918 +#define PCIE_ALTRT(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x700)
4919 +#define PCIE_ALTRT_ROUND_TRIP_LATENCY_LIMIT 0x0000FFFF /* Round Trip Latency Time Limit */
4920 +#define PCIE_ALTRT_ROUND_TRIP_LATENCY_LIMIT_S 0
4921 +#define PCIE_ALTRT_REPLAY_TIME_LIMIT 0xFFFF0000 /* Replay Time Limit */
4922 +#define PCIE_ALTRT_REPLAY_TIME_LIMIT_S 16
4923 +
4924 +/* Other Message Register */
4925 +#define PCIE_OMR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x704)
4926 +
4927 +/* Port Force Link Register */
4928 +#define PCIE_PFLR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x708)
4929 +#define PCIE_PFLR_LINK_NUM 0x000000FF /* Link Number */
4930 +#define PCIE_PFLR_LINK_NUM_S 0
4931 +#define PCIE_PFLR_FORCE_LINK 0x00008000 /* Force link */
4932 +#define PCIE_PFLR_LINK_STATE 0x003F0000 /* Link State */
4933 +#define PCIE_PFLR_LINK_STATE_S 16
4934 +#define PCIE_PFLR_LOW_POWER_ENTRY_CNT 0xFF000000 /* Low Power Entrance Count, only for EP */
4935 +#define PCIE_PFLR_LOW_POWER_ENTRY_CNT_S 24
4936 +
4937 +/* Ack Frequency Register */
4938 +#define PCIE_AFR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x70C)
4939 +#define PCIE_AFR_AF 0x000000FF /* Ack Frequency */
4940 +#define PCIE_AFR_AF_S 0
4941 +#define PCIE_AFR_FTS_NUM 0x0000FF00 /* The number of Fast Training Sequence from L0S to L0 */
4942 +#define PCIE_AFR_FTS_NUM_S 8
4943 +#define PCIE_AFR_COM_FTS_NUM 0x00FF0000 /* N_FTS; when common clock is used*/
4944 +#define PCIE_AFR_COM_FTS_NUM_S 16
4945 +#define PCIE_AFR_L0S_ENTRY_LATENCY 0x07000000 /* L0s Entrance Latency */
4946 +#define PCIE_AFR_L0S_ENTRY_LATENCY_S 24
4947 +#define PCIE_AFR_L1_ENTRY_LATENCY 0x38000000 /* L1 Entrance Latency */
4948 +#define PCIE_AFR_L1_ENTRY_LATENCY_S 27
4949 +#define PCIE_AFR_FTS_NUM_DEFAULT 32
4950 +#define PCIE_AFR_L0S_ENTRY_LATENCY_DEFAULT 7
4951 +#define PCIE_AFR_L1_ENTRY_LATENCY_DEFAULT 5
4952 +
4953 +/* Port Link Control Register */
4954 +#define PCIE_PLCR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x710)
4955 +#define PCIE_PLCR_OTHER_MSG_REQ 0x00000001 /* Other Message Request */
4956 +#define PCIE_PLCR_SCRAMBLE_DISABLE 0x00000002 /* Scramble Disable */
4957 +#define PCIE_PLCR_LOOPBACK_EN 0x00000004 /* Loopback Enable */
4958 +#define PCIE_PLCR_LTSSM_HOT_RST 0x00000008 /* Force LTSSM to the hot reset */
4959 +#define PCIE_PLCR_DLL_LINK_EN 0x00000020 /* Enable Link initialization */
4960 +#define PCIE_PLCR_FAST_LINK_SIM_EN 0x00000080 /* Sets all internal timers to fast mode for simulation purposes */
4961 +#define PCIE_PLCR_LINK_MODE 0x003F0000 /* Link Mode Enable Mask */
4962 +#define PCIE_PLCR_LINK_MODE_S 16
4963 +#define PCIE_PLCR_CORRUPTED_CRC_EN 0x02000000 /* Enabled Corrupt CRC */
4964 +
4965 +/* Lane Skew Register */
4966 +#define PCIE_LSR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x714)
4967 +#define PCIE_LSR_LANE_SKEW_NUM 0x00FFFFFF /* Insert Lane Skew for Transmit, not applicable */
4968 +#define PCIE_LSR_LANE_SKEW_NUM_S 0
4969 +#define PCIE_LSR_FC_DISABLE 0x01000000 /* Disable of Flow Control */
4970 +#define PCIE_LSR_ACKNAK_DISABLE 0x02000000 /* Disable of Ack/Nak */
4971 +#define PCIE_LSR_LANE_DESKEW_DISABLE 0x80000000 /* Disable of Lane-to-Lane Skew */
4972 +
4973 +/* Symbol Number Register */
4974 +#define PCIE_SNR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x718)
4975 +#define PCIE_SNR_TS 0x0000000F /* Number of TS Symbol */
4976 +#define PCIE_SNR_TS_S 0
4977 +#define PCIE_SNR_SKP 0x00000700 /* Number of SKP Symbol */
4978 +#define PCIE_SNR_SKP_S 8
4979 +#define PCIE_SNR_REPLAY_TIMER 0x0007C000 /* Timer Modifier for Replay Timer */
4980 +#define PCIE_SNR_REPLAY_TIMER_S 14
4981 +#define PCIE_SNR_ACKNAK_LATENCY_TIMER 0x00F80000 /* Timer Modifier for Ack/Nak Latency Timer */
4982 +#define PCIE_SNR_ACKNAK_LATENCY_TIMER_S 19
4983 +#define PCIE_SNR_FC_TIMER 0x1F000000 /* Timer Modifier for Flow Control Watchdog Timer */
4984 +#define PCIE_SNR_FC_TIMER_S 28
4985 +
4986 +/* Symbol Timer Register and Filter Mask Register 1 */
4987 +#define PCIE_STRFMR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x71C)
4988 +#define PCIE_STRFMR_SKP_INTERVAL 0x000007FF /* SKP lnterval Value */
4989 +#define PCIE_STRFMR_SKP_INTERVAL_S 0
4990 +#define PCIE_STRFMR_FC_WDT_DISABLE 0x00008000 /* Disable of FC Watchdog Timer */
4991 +#define PCIE_STRFMR_TLP_FUNC_MISMATCH_OK 0x00010000 /* Mask Function Mismatch Filtering for Incoming Requests */
4992 +#define PCIE_STRFMR_POISONED_TLP_OK 0x00020000 /* Mask Poisoned TLP Filtering */
4993 +#define PCIE_STRFMR_BAR_MATCH_OK 0x00040000 /* Mask BAR Match Filtering */
4994 +#define PCIE_STRFMR_TYPE1_CFG_REQ_OK 0x00080000 /* Mask Type 1 Configuration Request Filtering */
4995 +#define PCIE_STRFMR_LOCKED_REQ_OK 0x00100000 /* Mask Locked Request Filtering */
4996 +#define PCIE_STRFMR_CPL_TAG_ERR_RULES_OK 0x00200000 /* Mask Tag Error Rules for Received Completions */
4997 +#define PCIE_STRFMR_CPL_REQUESTOR_ID_MISMATCH_OK 0x00400000 /* Mask Requester ID Mismatch Error for Received Completions */
4998 +#define PCIE_STRFMR_CPL_FUNC_MISMATCH_OK 0x00800000 /* Mask Function Mismatch Error for Received Completions */
4999 +#define PCIE_STRFMR_CPL_TC_MISMATCH_OK 0x01000000 /* Mask Traffic Class Mismatch Error for Received Completions */
5000 +#define PCIE_STRFMR_CPL_ATTR_MISMATCH_OK 0x02000000 /* Mask Attribute Mismatch Error for Received Completions */
5001 +#define PCIE_STRFMR_CPL_LENGTH_MISMATCH_OK 0x04000000 /* Mask Length Mismatch Error for Received Completions */
5002 +#define PCIE_STRFMR_TLP_ECRC_ERR_OK 0x08000000 /* Mask ECRC Error Filtering */
5003 +#define PCIE_STRFMR_CPL_TLP_ECRC_OK 0x10000000 /* Mask ECRC Error Filtering for Completions */
5004 +#define PCIE_STRFMR_RX_TLP_MSG_NO_DROP 0x20000000 /* Send Message TLPs */
5005 +#define PCIE_STRFMR_RX_IO_TRANS_ENABLE 0x40000000 /* Mask Filtering of received I/O Requests */
5006 +#define PCIE_STRFMR_RX_CFG_TRANS_ENABLE 0x80000000 /* Mask Filtering of Received Configuration Requests */
5007 +
5008 +#define PCIE_DEF_SKP_INTERVAL 700 /* 1180 ~1538 , 125MHz * 2, 250MHz * 1 */
5009 +
5010 +/* Filter Masker Register 2 */
5011 +#define PCIE_FMR2(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x720)
5012 +#define PCIE_FMR2_VENDOR_MSG0_PASSED_TO_TRGT1 0x00000001 /* Mask RADM Filtering and Error Handling Rules */
5013 +#define PCIE_FMR2_VENDOR_MSG1_PASSED_TO_TRGT1 0x00000002 /* Mask RADM Filtering and Error Handling Rules */
5014 +
5015 +/* Debug Register 0 */
5016 +#define PCIE_DBR0(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x728)
5017 +
5018 +/* Debug Register 1 */
5019 +#define PCIE_DBR1(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x72C)
5020 +
5021 +/* Transmit Posted FC Credit Status Register */
5022 +#define PCIE_TPFCS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x730)
5023 +#define PCIE_TPFCS_TX_P_DATA_FC_CREDITS 0x00000FFF /* Transmit Posted Data FC Credits */
5024 +#define PCIE_TPFCS_TX_P_DATA_FC_CREDITS_S 0
5025 +#define PCIE_TPFCS_TX_P_HDR_FC_CREDITS 0x000FF000 /* Transmit Posted Header FC Credits */
5026 +#define PCIE_TPFCS_TX_P_HDR_FC_CREDITS_S 12
5027 +
5028 +/* Transmit Non-Posted FC Credit Status */
5029 +#define PCIE_TNPFCS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x734)
5030 +#define PCIE_TNPFCS_TX_NP_DATA_FC_CREDITS 0x00000FFF /* Transmit Non-Posted Data FC Credits */
5031 +#define PCIE_TNPFCS_TX_NP_DATA_FC_CREDITS_S 0
5032 +#define PCIE_TNPFCS_TX_NP_HDR_FC_CREDITS 0x000FF000 /* Transmit Non-Posted Header FC Credits */
5033 +#define PCIE_TNPFCS_TX_NP_HDR_FC_CREDITS_S 12
5034 +
5035 +/* Transmit Complete FC Credit Status Register */
5036 +#define PCIE_TCFCS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x738)
5037 +#define PCIE_TCFCS_TX_CPL_DATA_FC_CREDITS 0x00000FFF /* Transmit Completion Data FC Credits */
5038 +#define PCIE_TCFCS_TX_CPL_DATA_FC_CREDITS_S 0
5039 +#define PCIE_TCFCS_TX_CPL_HDR_FC_CREDITS 0x000FF000 /* Transmit Completion Header FC Credits */
5040 +#define PCIE_TCFCS_TX_CPL_HDR_FC_CREDITS_S 12
5041 +
5042 +/* Queue Status Register */
5043 +#define PCIE_QSR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x73C)
5044 +#define PCIE_QSR_WAIT_UPDATE_FC_DLL 0x00000001 /* Received TLP FC Credits Not Returned */
5045 +#define PCIE_QSR_TX_RETRY_BUF_NOT_EMPTY 0x00000002 /* Transmit Retry Buffer Not Empty */
5046 +#define PCIE_QSR_RX_QUEUE_NOT_EMPTY 0x00000004 /* Received Queue Not Empty */
5047 +
5048 +/* VC Transmit Arbitration Register 1 */
5049 +#define PCIE_VCTAR1(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x740)
5050 +#define PCIE_VCTAR1_WRR_WEIGHT_VC0 0x000000FF /* WRR Weight for VC0 */
5051 +#define PCIE_VCTAR1_WRR_WEIGHT_VC1 0x0000FF00 /* WRR Weight for VC1 */
5052 +#define PCIE_VCTAR1_WRR_WEIGHT_VC2 0x00FF0000 /* WRR Weight for VC2 */
5053 +#define PCIE_VCTAR1_WRR_WEIGHT_VC3 0xFF000000 /* WRR Weight for VC3 */
5054 +
5055 +/* VC Transmit Arbitration Register 2 */
5056 +#define PCIE_VCTAR2(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x744)
5057 +#define PCIE_VCTAR2_WRR_WEIGHT_VC4 0x000000FF /* WRR Weight for VC4 */
5058 +#define PCIE_VCTAR2_WRR_WEIGHT_VC5 0x0000FF00 /* WRR Weight for VC5 */
5059 +#define PCIE_VCTAR2_WRR_WEIGHT_VC6 0x00FF0000 /* WRR Weight for VC6 */
5060 +#define PCIE_VCTAR2_WRR_WEIGHT_VC7 0xFF000000 /* WRR Weight for VC7 */
5061 +
5062 +/* VC0 Posted Receive Queue Control Register */
5063 +#define PCIE_VC0_PRQCR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x748)
5064 +#define PCIE_VC0_PRQCR_P_DATA_CREDITS 0x00000FFF /* VC0 Posted Data Credits */
5065 +#define PCIE_VC0_PRQCR_P_DATA_CREDITS_S 0
5066 +#define PCIE_VC0_PRQCR_P_HDR_CREDITS 0x000FF000 /* VC0 Posted Header Credits */
5067 +#define PCIE_VC0_PRQCR_P_HDR_CREDITS_S 12
5068 +#define PCIE_VC0_PRQCR_P_TLP_QUEUE_MODE 0x00E00000 /* VC0 Posted TLP Queue Mode */
5069 +#define PCIE_VC0_PRQCR_P_TLP_QUEUE_MODE_S 20
5070 +#define PCIE_VC0_PRQCR_TLP_RELAX_ORDER 0x40000000 /* TLP Type Ordering for VC0 */
5071 +#define PCIE_VC0_PRQCR_VC_STRICT_ORDER 0x80000000 /* VC0 Ordering for Receive Queues */
5072 +
5073 +/* VC0 Non-Posted Receive Queue Control */
5074 +#define PCIE_VC0_NPRQCR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x74C)
5075 +#define PCIE_VC0_NPRQCR_NP_DATA_CREDITS 0x00000FFF /* VC0 Non-Posted Data Credits */
5076 +#define PCIE_VC0_NPRQCR_NP_DATA_CREDITS_S 0
5077 +#define PCIE_VC0_NPRQCR_NP_HDR_CREDITS 0x000FF000 /* VC0 Non-Posted Header Credits */
5078 +#define PCIE_VC0_NPRQCR_NP_HDR_CREDITS_S 12
5079 +#define PCIE_VC0_NPRQCR_NP_TLP_QUEUE_MODE 0x00E00000 /* VC0 Non-Posted TLP Queue Mode */
5080 +#define PCIE_VC0_NPRQCR_NP_TLP_QUEUE_MODE_S 20
5081 +
5082 +/* VC0 Completion Receive Queue Control */
5083 +#define PCIE_VC0_CRQCR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x750)
5084 +#define PCIE_VC0_CRQCR_CPL_DATA_CREDITS 0x00000FFF /* VC0 Completion TLP Queue Mode */
5085 +#define PCIE_VC0_CRQCR_CPL_DATA_CREDITS_S 0
5086 +#define PCIE_VC0_CRQCR_CPL_HDR_CREDITS 0x000FF000 /* VC0 Completion Header Credits */
5087 +#define PCIE_VC0_CRQCR_CPL_HDR_CREDITS_S 12
5088 +#define PCIE_VC0_CRQCR_CPL_TLP_QUEUE_MODE 0x00E00000 /* VC0 Completion Data Credits */
5089 +#define PCIE_VC0_CRQCR_CPL_TLP_QUEUE_MODE_S 21
5090 +
5091 +/* Applicable to the above three registers */
5092 +enum {
5093 + PCIE_VC0_TLP_QUEUE_MODE_STORE_FORWARD = 1,
5094 + PCIE_VC0_TLP_QUEUE_MODE_CUT_THROUGH = 2,
5095 + PCIE_VC0_TLP_QUEUE_MODE_BYPASS = 4,
5096 +};
5097 +
5098 +/* VC0 Posted Buffer Depth Register */
5099 +#define PCIE_VC0_PBD(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x7A8)
5100 +#define PCIE_VC0_PBD_P_DATA_QUEUE_ENTRIES 0x00003FFF /* VC0 Posted Data Queue Depth */
5101 +#define PCIE_VC0_PBD_P_DATA_QUEUE_ENTRIES_S 0
5102 +#define PCIE_VC0_PBD_P_HDR_QUEUE_ENTRIES 0x03FF0000 /* VC0 Posted Header Queue Depth */
5103 +#define PCIE_VC0_PBD_P_HDR_QUEUE_ENTRIES_S 16
5104 +
5105 +/* VC0 Non-Posted Buffer Depth Register */
5106 +#define PCIE_VC0_NPBD(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x7AC)
5107 +#define PCIE_VC0_NPBD_NP_DATA_QUEUE_ENTRIES 0x00003FFF /* VC0 Non-Posted Data Queue Depth */
5108 +#define PCIE_VC0_NPBD_NP_DATA_QUEUE_ENTRIES_S 0
5109 +#define PCIE_VC0_NPBD_NP_HDR_QUEUE_ENTRIES 0x03FF0000 /* VC0 Non-Posted Header Queue Depth */
5110 +#define PCIE_VC0_NPBD_NP_HDR_QUEUE_ENTRIES_S 16
5111 +
5112 +/* VC0 Completion Buffer Depth Register */
5113 +#define PCIE_VC0_CBD(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x7B0)
5114 +#define PCIE_VC0_CBD_CPL_DATA_QUEUE_ENTRIES 0x00003FFF /* C0 Completion Data Queue Depth */
5115 +#define PCIE_VC0_CBD_CPL_DATA_QUEUE_ENTRIES_S 0
5116 +#define PCIE_VC0_CBD_CPL_HDR_QUEUE_ENTRIES 0x03FF0000 /* VC0 Completion Header Queue Depth */
5117 +#define PCIE_VC0_CBD_CPL_HDR_QUEUE_ENTRIES_S 16
5118 +
5119 +/* PHY Status Register, all zeros in VR9 */
5120 +#define PCIE_PHYSR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x810)
5121 +
5122 +/* PHY Control Register, all zeros in VR9 */
5123 +#define PCIE_PHYCR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x814)
5124 +
5125 +/*
5126 + * PCIe PDI PHY register definition, suppose all the following
5127 + * stuff is confidential.
5128 + * XXX, detailed bit definition
5129 + */
5130 +#define PCIE_PHY_PLL_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x22 << 1))
5131 +#define PCIE_PHY_PLL_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x23 << 1))
5132 +#define PCIE_PHY_PLL_CTRL3(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x24 << 1))
5133 +#define PCIE_PHY_PLL_CTRL4(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x25 << 1))
5134 +#define PCIE_PHY_PLL_CTRL5(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x26 << 1))
5135 +#define PCIE_PHY_PLL_CTRL6(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x27 << 1))
5136 +#define PCIE_PHY_PLL_CTRL7(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x28 << 1))
5137 +#define PCIE_PHY_PLL_A_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x29 << 1))
5138 +#define PCIE_PHY_PLL_A_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x2A << 1))
5139 +#define PCIE_PHY_PLL_A_CTRL3(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x2B << 1))
5140 +#define PCIE_PHY_PLL_STATUS(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x2C << 1))
5141 +
5142 +#define PCIE_PHY_TX1_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x30 << 1))
5143 +#define PCIE_PHY_TX1_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x31 << 1))
5144 +#define PCIE_PHY_TX1_CTRL3(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x32 << 1))
5145 +#define PCIE_PHY_TX1_A_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x33 << 1))
5146 +#define PCIE_PHY_TX1_A_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x34 << 1))
5147 +#define PCIE_PHY_TX1_MOD1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x35 << 1))
5148 +#define PCIE_PHY_TX1_MOD2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x36 << 1))
5149 +#define PCIE_PHY_TX1_MOD3(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x37 << 1))
5150 +
5151 +#define PCIE_PHY_TX2_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x38 << 1))
5152 +#define PCIE_PHY_TX2_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x39 << 1))
5153 +#define PCIE_PHY_TX2_A_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x3B << 1))
5154 +#define PCIE_PHY_TX2_A_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x3C << 1))
5155 +#define PCIE_PHY_TX2_MOD1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x3D << 1))
5156 +#define PCIE_PHY_TX2_MOD2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x3E << 1))
5157 +#define PCIE_PHY_TX2_MOD3(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x3F << 1))
5158 +
5159 +#define PCIE_PHY_RX1_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x50 << 1))
5160 +#define PCIE_PHY_RX1_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x51 << 1))
5161 +#define PCIE_PHY_RX1_CDR(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x52 << 1))
5162 +#define PCIE_PHY_RX1_EI(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x53 << 1))
5163 +#define PCIE_PHY_RX1_A_CTRL(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x55 << 1))
5164 +
5165 +/* Interrupt related stuff */
5166 +#define PCIE_LEGACY_DISABLE 0
5167 +#define PCIE_LEGACY_INTA 1
5168 +#define PCIE_LEGACY_INTB 2
5169 +#define PCIE_LEGACY_INTC 3
5170 +#define PCIE_LEGACY_INTD 4
5171 +#define PCIE_LEGACY_INT_MAX PCIE_LEGACY_INTD
5172 +
5173 +#define PCIE_IRQ_LOCK(lock) do { \
5174 + unsigned long flags; \
5175 + spin_lock_irqsave(&(lock), flags);
5176 +#define PCIE_IRQ_UNLOCK(lock) \
5177 + spin_unlock_irqrestore(&(lock), flags); \
5178 +} while (0)
5179 +
5180 +#define PCIE_MSG_MSI 0x00000001
5181 +#define PCIE_MSG_ISR 0x00000002
5182 +#define PCIE_MSG_FIXUP 0x00000004
5183 +#define PCIE_MSG_READ_CFG 0x00000008
5184 +#define PCIE_MSG_WRITE_CFG 0x00000010
5185 +#define PCIE_MSG_CFG (PCIE_MSG_READ_CFG | PCIE_MSG_WRITE_CFG)
5186 +#define PCIE_MSG_REG 0x00000020
5187 +#define PCIE_MSG_INIT 0x00000040
5188 +#define PCIE_MSG_ERR 0x00000080
5189 +#define PCIE_MSG_PHY 0x00000100
5190 +#define PCIE_MSG_ANY 0x000001ff
5191 +
5192 +#define IFX_PCIE_PORT0 0
5193 +#define IFX_PCIE_PORT1 1
5194 +
5195 +#ifdef CONFIG_IFX_PCIE_2ND_CORE
5196 +#define IFX_PCIE_CORE_NR 2
5197 +#else
5198 +#define IFX_PCIE_CORE_NR 1
5199 +#endif
5200 +
5201 +//#define IFX_PCIE_ERROR_INT
5202 +
5203 +//#define IFX_PCIE_DBG
5204 +
5205 +#if defined(IFX_PCIE_DBG)
5206 +#define IFX_PCIE_PRINT(_m, _fmt, args...) do { \
5207 + if (g_pcie_debug_flag & (_m)) { \
5208 + ifx_pcie_debug((_fmt), ##args); \
5209 + } \
5210 +} while (0)
5211 +
5212 +#define INLINE
5213 +#else
5214 +#define IFX_PCIE_PRINT(_m, _fmt, args...) \
5215 + do {} while(0)
5216 +#define INLINE inline
5217 +#endif
5218 +
5219 +struct ifx_pci_controller {
5220 + struct pci_controller pcic;
5221 +
5222 + /* RC specific, per host bus information */
5223 + u32 port; /* Port index, 0 -- 1st core, 1 -- 2nd core */
5224 +};
5225 +
5226 +typedef struct ifx_pcie_ir_irq {
5227 + const unsigned int irq;
5228 + const char name[16];
5229 +}ifx_pcie_ir_irq_t;
5230 +
5231 +typedef struct ifx_pcie_legacy_irq{
5232 + const u32 irq_bit;
5233 + const int irq;
5234 +}ifx_pcie_legacy_irq_t;
5235 +
5236 +typedef struct ifx_pcie_irq {
5237 + ifx_pcie_ir_irq_t ir_irq;
5238 + ifx_pcie_legacy_irq_t legacy_irq[PCIE_LEGACY_INT_MAX];
5239 +}ifx_pcie_irq_t;
5240 +
5241 +extern u32 g_pcie_debug_flag;
5242 +extern void ifx_pcie_debug(const char *fmt, ...);
5243 +extern void pcie_phy_clock_mode_setup(int pcie_port);
5244 +extern void pcie_msi_pic_init(int pcie_port);
5245 +extern u32 ifx_pcie_bus_enum_read_hack(int where, u32 value);
5246 +extern u32 ifx_pcie_bus_enum_write_hack(int where, u32 value);
5247 +
5248 +
5249 +#include <linux/types.h>
5250 +#include <linux/delay.h>
5251 +#include <linux/gpio.h>
5252 +#include <linux/clk.h>
5253 +
5254 +#include <lantiq_soc.h>
5255 +
5256 +#define IFX_PCIE_GPIO_RESET 38
5257 +#define IFX_REG_R32 ltq_r32
5258 +#define IFX_REG_W32 ltq_w32
5259 +#define CONFIG_IFX_PCIE_HW_SWAP
5260 +#define IFX_RCU_AHB_ENDIAN ((volatile u32*)(IFX_RCU + 0x004C))
5261 +#define IFX_RCU_RST_REQ ((volatile u32*)(IFX_RCU + 0x0010))
5262 +#define IFX_RCU_AHB_BE_PCIE_PDI 0x00000080 /* Configure PCIE PDI module in big endian*/
5263 +
5264 +#define IFX_RCU (KSEG1 | 0x1F203000)
5265 +#define IFX_RCU_AHB_BE_PCIE_M 0x00000001 /* Configure AHB master port that connects to PCIe RC in big endian */
5266 +#define IFX_RCU_AHB_BE_PCIE_S 0x00000010 /* Configure AHB slave port that connects to PCIe RC in little endian */
5267 +#define IFX_RCU_AHB_BE_XBAR_M 0x00000002 /* Configure AHB master port that connects to XBAR in big endian */
5268 +#define CONFIG_IFX_PCIE_PHY_36MHZ_MODE
5269 +
5270 +#define IFX_PMU1_MODULE_PCIE_PHY (0)
5271 +#define IFX_PMU1_MODULE_PCIE_CTRL (1)
5272 +#define IFX_PMU1_MODULE_PDI (4)
5273 +#define IFX_PMU1_MODULE_MSI (5)
5274 +
5275 +#define IFX_PMU_MODULE_PCIE_L0_CLK (31)
5276 +
5277 +
5278 +static inline void pcie_ep_gpio_rst_init(int pcie_port)
5279 +{
5280 +}
5281 +
5282 +static inline void pcie_ahb_pmu_setup(void)
5283 +{
5284 + struct clk *clk;
5285 + clk = clk_get_sys("ltq_pcie", "ahb");
5286 + clk_enable(clk);
5287 + //ltq_pmu_enable(PMU_AHBM | PMU_AHBS);
5288 +}
5289 +
5290 +static inline void pcie_rcu_endian_setup(int pcie_port)
5291 +{
5292 + u32 reg;
5293 +
5294 + reg = IFX_REG_R32(IFX_RCU_AHB_ENDIAN);
5295 +#ifdef CONFIG_IFX_PCIE_HW_SWAP
5296 + reg |= IFX_RCU_AHB_BE_PCIE_M;
5297 + reg |= IFX_RCU_AHB_BE_PCIE_S;
5298 + reg &= ~IFX_RCU_AHB_BE_XBAR_M;
5299 +#else
5300 + reg |= IFX_RCU_AHB_BE_PCIE_M;
5301 + reg &= ~IFX_RCU_AHB_BE_PCIE_S;
5302 + reg &= ~IFX_RCU_AHB_BE_XBAR_M;
5303 +#endif /* CONFIG_IFX_PCIE_HW_SWAP */
5304 + IFX_REG_W32(reg, IFX_RCU_AHB_ENDIAN);
5305 + IFX_PCIE_PRINT(PCIE_MSG_REG, "%s IFX_RCU_AHB_ENDIAN: 0x%08x\n", __func__, IFX_REG_R32(IFX_RCU_AHB_ENDIAN));
5306 +}
5307 +
5308 +static inline void pcie_phy_pmu_enable(int pcie_port)
5309 +{
5310 + struct clk *clk;
5311 + clk = clk_get_sys("ltq_pcie", "phy");
5312 + clk_enable(clk);
5313 + //ltq_pmu1_enable(1<<IFX_PMU1_MODULE_PCIE_PHY);
5314 +}
5315 +
5316 +static inline void pcie_phy_pmu_disable(int pcie_port)
5317 +{
5318 + struct clk *clk;
5319 + clk = clk_get_sys("ltq_pcie", "phy");
5320 + clk_disable(clk);
5321 + //ltq_pmu1_disable(1<<IFX_PMU1_MODULE_PCIE_PHY);
5322 +}
5323 +
5324 +static inline void pcie_pdi_big_endian(int pcie_port)
5325 +{
5326 + u32 reg;
5327 +
5328 + /* SRAM2PDI endianness control. */
5329 + reg = IFX_REG_R32(IFX_RCU_AHB_ENDIAN);
5330 + /* Config AHB->PCIe and PDI endianness */
5331 + reg |= IFX_RCU_AHB_BE_PCIE_PDI;
5332 + IFX_REG_W32(reg, IFX_RCU_AHB_ENDIAN);
5333 +}
5334 +
5335 +static inline void pcie_pdi_pmu_enable(int pcie_port)
5336 +{
5337 + struct clk *clk;
5338 + clk = clk_get_sys("ltq_pcie", "pdi");
5339 + clk_enable(clk);
5340 + //ltq_pmu1_enable(1<<IFX_PMU1_MODULE_PDI);
5341 +}
5342 +
5343 +static inline void pcie_core_rst_assert(int pcie_port)
5344 +{
5345 + u32 reg;
5346 +
5347 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
5348 +
5349 + /* Reset PCIe PHY & Core, bit 22, bit 26 may be affected if write it directly */
5350 + reg |= 0x00400000;
5351 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
5352 +}
5353 +
5354 +static inline void pcie_core_rst_deassert(int pcie_port)
5355 +{
5356 + u32 reg;
5357 +
5358 + /* Make sure one micro-second delay */
5359 + udelay(1);
5360 +
5361 + /* Reset PCIe PHY & Core, bit 22 */
5362 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
5363 + reg &= ~0x00400000;
5364 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
5365 +}
5366 +
5367 +static inline void pcie_phy_rst_assert(int pcie_port)
5368 +{
5369 + u32 reg;
5370 +
5371 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
5372 + reg |= 0x00001000; /* Bit 12 */
5373 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
5374 +}
5375 +
5376 +static inline void pcie_phy_rst_deassert(int pcie_port)
5377 +{
5378 + u32 reg;
5379 +
5380 + /* Make sure one micro-second delay */
5381 + udelay(1);
5382 +
5383 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
5384 + reg &= ~0x00001000; /* Bit 12 */
5385 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
5386 +}
5387 +
5388 +static inline void pcie_device_rst_assert(int pcie_port)
5389 +{
5390 + gpio_set_value(IFX_PCIE_GPIO_RESET, 0);
5391 + // ifx_gpio_output_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
5392 +}
5393 +
5394 +static inline void pcie_device_rst_deassert(int pcie_port)
5395 +{
5396 + mdelay(100);
5397 + gpio_set_value(IFX_PCIE_GPIO_RESET, 1);
5398 +// ifx_gpio_output_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
5399 +}
5400 +
5401 +static inline void pcie_core_pmu_setup(int pcie_port)
5402 +{
5403 + struct clk *clk;
5404 + clk = clk_get_sys("ltq_pcie", "ctl");
5405 + clk_enable(clk);
5406 + clk = clk_get_sys("ltq_pcie", "bus");
5407 + clk_enable(clk);
5408 +
5409 + //ltq_pmu1_enable(1 << IFX_PMU1_MODULE_PCIE_CTRL);
5410 + //ltq_pmu_enable(1 << IFX_PMU_MODULE_PCIE_L0_CLK);
5411 +}
5412 +
5413 +static inline void pcie_msi_init(int pcie_port)
5414 +{
5415 + struct clk *clk;
5416 + pcie_msi_pic_init(pcie_port);
5417 + clk = clk_get_sys("ltq_pcie", "msi");
5418 + clk_enable(clk);
5419 + //ltq_pmu1_enable(1 << IFX_PMU1_MODULE_MSI);
5420 +}
5421 +
5422 +static inline u32
5423 +ifx_pcie_bus_nr_deduct(u32 bus_number, int pcie_port)
5424 +{
5425 + u32 tbus_number = bus_number;
5426 +
5427 +#ifdef CONFIG_PCI_LANTIQ
5428 + if (pcibios_host_nr() > 1) {
5429 + tbus_number -= pcibios_1st_host_bus_nr();
5430 + }
5431 +#endif /* CONFIG_PCI_LANTIQ */
5432 + return tbus_number;
5433 +}
5434 +
5435 +static inline u32
5436 +ifx_pcie_bus_enum_hack(struct pci_bus *bus, u32 devfn, int where, u32 value, int pcie_port, int read)
5437 +{
5438 + struct pci_dev *pdev;
5439 + u32 tvalue = value;
5440 +
5441 + /* Sanity check */
5442 + pdev = pci_get_slot(bus, devfn);
5443 + if (pdev == NULL) {
5444 + return tvalue;
5445 + }
5446 +
5447 + /* Only care about PCI bridge */
5448 + if (pdev->hdr_type != PCI_HEADER_TYPE_BRIDGE) {
5449 + return tvalue;
5450 + }
5451 +
5452 + if (read) { /* Read hack */
5453 + #ifdef CONFIG_PCI_LANTIQ
5454 + if (pcibios_host_nr() > 1) {
5455 + tvalue = ifx_pcie_bus_enum_read_hack(where, tvalue);
5456 + }
5457 + #endif /* CONFIG_PCI_LANTIQ */
5458 + }
5459 + else { /* Write hack */
5460 + #ifdef CONFIG_PCI_LANTIQ
5461 + if (pcibios_host_nr() > 1) {
5462 + tvalue = ifx_pcie_bus_enum_write_hack(where, tvalue);
5463 + }
5464 + #endif
5465 + }
5466 + return tvalue;
5467 +}
5468 +
5469 +#endif /* IFXMIPS_PCIE_VR9_H */
5470 +
5471 --- a/drivers/pci/pcie/Kconfig
5472 +++ b/drivers/pci/pcie/Kconfig
5473 @@ -52,6 +52,7 @@ config PCIEAER_INJECT
5474 config PCIE_ECRC
5475 bool "PCI Express ECRC settings control"
5476 depends on PCIEAER
5477 + default n
5478 help
5479 Used to override firmware/bios settings for PCI Express ECRC
5480 (transaction layer end-to-end CRC checking).
5481 --- a/include/linux/pci.h
5482 +++ b/include/linux/pci.h
5483 @@ -1390,6 +1390,8 @@ void pci_walk_bus(struct pci_bus *top, i
5484 void *userdata);
5485 int pci_cfg_space_size(struct pci_dev *dev);
5486 unsigned char pci_bus_max_busnr(struct pci_bus *bus);
5487 +int pcibios_host_nr(void);
5488 +int pcibios_1st_host_bus_nr(void);
5489 void pci_setup_bridge(struct pci_bus *bus);
5490 resource_size_t pcibios_window_alignment(struct pci_bus *bus,
5491 unsigned long type);
5492 --- a/include/linux/pci_ids.h
5493 +++ b/include/linux/pci_ids.h
5494 @@ -1076,6 +1076,12 @@
5495 #define PCI_DEVICE_ID_SGI_IOC3 0x0003
5496 #define PCI_DEVICE_ID_SGI_LITHIUM 0x1002
5497
5498 +#define PCI_VENDOR_ID_INFINEON 0x15D1
5499 +#define PCI_DEVICE_ID_INFINEON_DANUBE 0x000F
5500 +#define PCI_DEVICE_ID_INFINEON_PCIE 0x0011
5501 +#define PCI_VENDOR_ID_LANTIQ 0x1BEF
5502 +#define PCI_DEVICE_ID_LANTIQ_PCIE 0x0011
5503 +
5504 #define PCI_VENDOR_ID_WINBOND 0x10ad
5505 #define PCI_DEVICE_ID_WINBOND_82C105 0x0105
5506 #define PCI_DEVICE_ID_WINBOND_83C553 0x0565