1 This patch adds support for PCI and PCIe to the base Cavium OCTEON
4 Signed-off-by: David Daney <ddaney@caviumnetworks.com>
6 arch/mips/Kconfig | 2 +
7 arch/mips/cavium-octeon/Makefile | 4 +
8 arch/mips/cavium-octeon/dma-octeon.c | 310 ++++++-
9 arch/mips/cavium-octeon/executive/Makefile | 2 +
10 .../cavium-octeon/executive/cvmx-helper-errata.c | 379 +++++++
11 .../cavium-octeon/executive/cvmx-helper-util.c | 502 ++++++++++
12 arch/mips/cavium-octeon/executive/cvmx-pcie.c | 1053 ++++++++++++++++++++
13 arch/mips/cavium-octeon/msi.c | 288 ++++++
14 arch/mips/cavium-octeon/octeon-irq.c | 2 +
15 arch/mips/cavium-octeon/pci-common.c | 137 +++
16 arch/mips/cavium-octeon/pci-common.h | 39 +
17 arch/mips/cavium-octeon/pci.c | 568 +++++++++++
18 arch/mips/cavium-octeon/pcie.c | 441 ++++++++
19 arch/mips/include/asm/octeon/cvmx-asm.h | 3 +-
20 arch/mips/include/asm/octeon/cvmx-helper-errata.h | 92 ++
21 arch/mips/include/asm/octeon/cvmx-helper-util.h | 266 +++++
22 arch/mips/include/asm/octeon/cvmx-packet.h | 16 +-
23 arch/mips/include/asm/octeon/cvmx-pcie.h | 284 ++++++
24 arch/mips/include/asm/octeon/cvmx-wqe.h | 422 ++++++++
25 arch/mips/include/asm/octeon/cvmx.h | 12 +
26 arch/mips/include/asm/octeon/octeon.h | 2 +
27 21 files changed, 4816 insertions(+), 8 deletions(-)
28 create mode 100644 arch/mips/cavium-octeon/executive/cvmx-helper-errata.c
29 create mode 100644 arch/mips/cavium-octeon/executive/cvmx-helper-util.c
30 create mode 100644 arch/mips/cavium-octeon/executive/cvmx-pcie.c
31 create mode 100644 arch/mips/cavium-octeon/msi.c
32 create mode 100644 arch/mips/cavium-octeon/pci-common.c
33 create mode 100644 arch/mips/cavium-octeon/pci-common.h
34 create mode 100644 arch/mips/cavium-octeon/pci.c
35 create mode 100644 arch/mips/cavium-octeon/pcie.c
36 create mode 100644 arch/mips/include/asm/octeon/cvmx-helper-errata.h
37 create mode 100644 arch/mips/include/asm/octeon/cvmx-helper-util.h
38 create mode 100644 arch/mips/include/asm/octeon/cvmx-pcie.h
39 create mode 100644 arch/mips/include/asm/octeon/cvmx-wqe.h
41 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
42 index ea2b262..f009496 100644
43 --- a/arch/mips/Kconfig
44 +++ b/arch/mips/Kconfig
45 @@ -620,6 +620,8 @@ config CAVIUM_OCTEON_REFERENCE_BOARD
46 select SYS_HAS_EARLY_PRINTK
47 select CPU_CAVIUM_OCTEON
50 + select ARCH_SUPPORTS_MSI
52 This option supports all of the Octeon reference boards from Cavium
53 Networks. It builds a kernel that dynamically determines the Octeon
54 diff --git a/arch/mips/cavium-octeon/Makefile b/arch/mips/cavium-octeon/Makefile
55 index 1c2a7fa..2b5f08f 100644
56 --- a/arch/mips/cavium-octeon/Makefile
57 +++ b/arch/mips/cavium-octeon/Makefile
58 @@ -14,3 +14,7 @@ obj-y += dma-octeon.o flash_setup.o
59 obj-y += octeon-memcpy.o
61 obj-$(CONFIG_SMP) += smp.o
62 +obj-$(CONFIG_PCI) += pci-common.o
63 +obj-$(CONFIG_PCI) += pci.o
64 +obj-$(CONFIG_PCI) += pcie.o
65 +obj-$(CONFIG_PCI_MSI) += msi.o
66 diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
67 index 01b1ef9..af3c26f 100644
68 --- a/arch/mips/cavium-octeon/dma-octeon.c
69 +++ b/arch/mips/cavium-octeon/dma-octeon.c
72 #include <linux/types.h>
74 +#include <linux/module.h>
75 +#include <linux/string.h>
76 +#include <linux/dma-mapping.h>
77 +#include <linux/platform_device.h>
78 +#include <linux/scatterlist.h>
80 +#include <linux/cache.h>
81 +#include <linux/io.h>
83 +#include <asm/octeon/octeon.h>
84 +#include <asm/octeon/cvmx-npi-defs.h>
85 +#include <asm/octeon/cvmx-pci-defs.h>
87 #include <dma-coherence.h>
90 +#include "pci-common.h"
93 +#define BAR2_PCI_ADDRESS 0x8000000000ul
95 +struct bar1_index_state {
96 + int16_t ref_count; /* Number of PCI mappings using this index */
97 + uint16_t address_bits; /* Upper bits of physical address. This is
102 +static DEFINE_SPINLOCK(bar1_lock);
103 +static struct bar1_index_state bar1_state[32];
106 dma_addr_t octeon_map_dma_mem(struct device *dev, void *ptr, size_t size)
109 /* Without PCI/PCIe this function can be called for Octeon internal
110 devices such as USB. These devices all support 64bit addressing */
112 return virt_to_phys(ptr);
114 + unsigned long flags;
116 + int64_t start_index;
117 + dma_addr_t result = -1;
118 + uint64_t physical = virt_to_phys(ptr);
123 + * Use the DMA masks to determine the allowed memory
124 + * region. For us it doesn't limit the actual memory, just the
125 + * address visible over PCI. Devices with limits need to use
126 + * lower indexed Bar1 entries.
129 + dma_mask = dev->coherent_dma_mask;
131 + dma_mask = *dev->dma_mask;
133 + dma_mask = 0xfffffffful;
136 + * Platform devices, such as the internal USB, skip all
137 + * translation and use Octeon physical addresses directly.
139 + if (dev->bus == &platform_bus_type)
142 + switch (octeon_dma_bar_type) {
143 + case OCTEON_DMA_BAR_TYPE_PCIE:
144 + if (unlikely(physical < (16ul << 10)))
145 + panic("dma_map_single: Not allowed to map first 16KB."
146 + " It interferes with BAR0 special area\n");
147 + else if ((physical + size >= (256ul << 20)) &&
148 + (physical < (512ul << 20)))
149 + panic("dma_map_single: Not allowed to map bootbus\n");
150 + else if ((physical + size >= 0x400000000ull) &&
151 + physical < 0x410000000ull)
152 + panic("dma_map_single: "
153 + "Attempt to map illegal memory address 0x%lx\n",
155 + else if (physical >= 0x420000000ull)
156 + panic("dma_map_single: "
157 + "Attempt to map illegal memory address 0x%lx\n",
159 + else if ((physical + size >=
160 + (4ull<<30) - (OCTEON_PCI_BAR1_HOLE_SIZE<<20))
161 + && physical < (4ull<<30))
162 + pr_warning("dma_map_single: Warning: "
163 + "Mapping memory address that might "
164 + "conflict with devices 0x%lx-0x%lx\n",
165 + physical, physical+size-1);
166 + /* The 2nd 256MB is mapped at 256<<20 instead of 0x410000000 */
167 + if ((physical >= 0x410000000ull) && physical < 0x420000000ull)
168 + result = physical - 0x400000000ull;
171 + if (((result+size-1) & dma_mask) != result+size-1)
172 + panic("dma_map_single: Attempt to map address "
173 + "0x%lx-0x%lx, which can't be accessed according "
174 + "to the dma mask 0x%lx\n",
175 + physical, physical+size-1, dma_mask);
178 + case OCTEON_DMA_BAR_TYPE_BIG:
180 + /* If the device supports 64bit addressing, then use BAR2 */
181 + if (dma_mask > BAR2_PCI_ADDRESS) {
182 + result = physical + BAR2_PCI_ADDRESS;
186 + if (unlikely(physical < (4ul << 10))) {
187 + panic("dma_map_single: Not allowed to map first 4KB. "
188 + "It interferes with BAR0 special area\n");
189 + } else if (physical < (256ul << 20)) {
190 + if (unlikely(physical + size > (256ul << 20)))
191 + panic("dma_map_single: Requested memory spans "
192 + "Bar0 0:256MB and bootbus\n");
195 + } else if (unlikely(physical < (512ul << 20))) {
196 + panic("dma_map_single: Not allowed to map bootbus\n");
197 + } else if (physical < (2ul << 30)) {
198 + if (unlikely(physical + size > (2ul << 30)))
199 + panic("dma_map_single: Requested memory spans "
200 + "Bar0 512MB:2GB and BAR1\n");
203 + } else if (physical < (2ul << 30) + (128 << 20)) {
205 + } else if (physical <
206 + (4ul << 30) - (OCTEON_PCI_BAR1_HOLE_SIZE << 20)) {
209 + (4ul << 30) - (OCTEON_PCI_BAR1_HOLE_SIZE << 20)))
210 + panic("dma_map_single: Requested memory "
211 + "extends past Bar1 (4GB-%luMB)\n",
212 + OCTEON_PCI_BAR1_HOLE_SIZE);
215 + } else if ((physical >= 0x410000000ull) &&
216 + (physical < 0x420000000ull)) {
217 + if (unlikely(physical + size > 0x420000000ull))
218 + panic("dma_map_single: Requested memory spans "
219 + "non existant memory\n");
220 + /* BAR0 fixed mapping 256MB:512MB ->
221 + * 16GB+256MB:16GB+512MB */
222 + result = physical - 0x400000000ull;
225 + /* Continued below switch statement */
229 + case OCTEON_DMA_BAR_TYPE_SMALL:
231 + /* If the device supports 64bit addressing, then use BAR2 */
232 + if (dma_mask > BAR2_PCI_ADDRESS) {
233 + result = physical + BAR2_PCI_ADDRESS;
237 + /* Continued below switch statement */
241 + panic("dma_map_single: Invalid octeon_dma_bar_type\n");
244 + /* Don't allow mapping to span multiple Bar entries. The hardware guys
245 + won't guarantee that DMA across boards work */
246 + if (unlikely((physical >> 22) != ((physical + size - 1) >> 22)))
247 + panic("dma_map_single: "
248 + "Requested memory spans more than one Bar1 entry\n");
250 + if (octeon_dma_bar_type == OCTEON_DMA_BAR_TYPE_BIG)
252 + else if (unlikely(dma_mask < (1ul << 27)))
253 + start_index = (dma_mask >> 22);
257 + /* Only one processor can access the Bar register at once */
258 + spin_lock_irqsave(&bar1_lock, flags);
260 + /* Look through Bar1 for existing mapping that will work */
261 + for (index = start_index; index >= 0; index--) {
262 + if ((bar1_state[index].address_bits == physical >> 22) &&
263 + (bar1_state[index].ref_count)) {
264 + /* An existing mapping will work, use it */
265 + bar1_state[index].ref_count++;
266 + if (unlikely(bar1_state[index].ref_count < 0))
267 + panic("dma_map_single: "
268 + "Bar1[%d] reference count overflowed\n",
270 + result = (index << 22) | (physical & ((1 << 22) - 1));
271 + /* Large BAR1 is offset at 2GB */
272 + if (octeon_dma_bar_type == OCTEON_DMA_BAR_TYPE_BIG)
273 + result += 2ul << 30;
278 + /* No existing mappings, look for a free entry */
279 + for (index = start_index; index >= 0; index--) {
280 + if (unlikely(bar1_state[index].ref_count == 0)) {
281 + union cvmx_pci_bar1_indexx bar1_index;
282 + /* We have a free entry, use it */
283 + bar1_state[index].ref_count = 1;
284 + bar1_state[index].address_bits = physical >> 22;
285 + bar1_index.u32 = 0;
286 + /* Address bits[35:22] sent to L2C */
287 + bar1_index.s.addr_idx = physical >> 22;
288 + /* Don't put PCI accesses in L2. */
289 + bar1_index.s.ca = 1;
290 + /* Endian Swap Mode */
291 + bar1_index.s.end_swp = 1;
292 + /* Set '1' when the selected address range is valid. */
293 + bar1_index.s.addr_v = 1;
294 + octeon_npi_write32(CVMX_NPI_PCI_BAR1_INDEXX(index),
296 + /* An existing mapping will work, use it */
297 + result = (index << 22) | (physical & ((1 << 22) - 1));
298 + /* Large BAR1 is offset at 2GB */
299 + if (octeon_dma_bar_type == OCTEON_DMA_BAR_TYPE_BIG)
300 + result += 2ul << 30;
305 + pr_err("dma_map_single: "
306 + "Can't find empty BAR1 index for physical mapping 0x%llx\n",
307 + (unsigned long long) physical);
310 + spin_unlock_irqrestore(&bar1_lock, flags);
312 + pr_debug("dma_map_single 0x%lx->0x%lx\n", physical, result);
317 void octeon_unmap_dma_mem(struct device *dev, dma_addr_t dma_addr)
319 - /* Without PCI/PCIe this function can be called for Octeon internal
320 - * devices such as USB. These devices all support 64bit addressing */
323 + * Without PCI/PCIe this function can be called for Octeon internal
324 + * devices such as USB. These devices all support 64bit addressing.
328 + unsigned long flags;
332 + * Platform devices, such as the internal USB, skip all
333 + * translation and use Octeon physical addresses directly.
335 + if (dev->bus == &platform_bus_type)
338 + switch (octeon_dma_bar_type) {
339 + case OCTEON_DMA_BAR_TYPE_PCIE:
340 + /* Nothing to do, all mappings are static */
343 + case OCTEON_DMA_BAR_TYPE_BIG:
345 + /* Nothing to do for addresses using BAR2 */
346 + if (dma_addr >= BAR2_PCI_ADDRESS)
349 + if (unlikely(dma_addr < (4ul << 10)))
350 + panic("dma_unmap_single: Unexpect DMA address 0x%lx\n",
352 + else if (dma_addr < (2ul << 30))
353 + /* Nothing to do for addresses using BAR0 */
355 + else if (dma_addr < (2ul << 30) + (128ul << 20))
356 + /* Need to unmap, fall through */
357 + index = (dma_addr - (2ul << 30)) >> 22;
358 + else if (dma_addr <
359 + (4ul << 30) - (OCTEON_PCI_BAR1_HOLE_SIZE << 20))
360 + goto done; /* Nothing to do for the rest of BAR1 */
362 + panic("dma_unmap_single: Unexpect DMA address 0x%lx\n",
364 + /* Continued below switch statement */
367 + case OCTEON_DMA_BAR_TYPE_SMALL:
369 + /* Nothing to do for addresses using BAR2 */
370 + if (dma_addr >= BAR2_PCI_ADDRESS)
373 + index = dma_addr >> 22;
374 + /* Continued below switch statement */
378 + panic("dma_unmap_single: Invalid octeon_dma_bar_type\n");
381 + if (unlikely(index > 31))
382 + panic("dma_unmap_single: "
383 + "Attempt to unmap an invalid address (0x%llx)\n",
384 + (unsigned long long) dma_addr);
386 + spin_lock_irqsave(&bar1_lock, flags);
387 + bar1_state[index].ref_count--;
388 + if (bar1_state[index].ref_count == 0)
389 + octeon_npi_write32(CVMX_NPI_PCI_BAR1_INDEXX(index), 0);
390 + else if (unlikely(bar1_state[index].ref_count < 0))
391 + panic("dma_unmap_single: Bar1[%u] reference count < 0\n",
393 + spin_unlock_irqrestore(&bar1_lock, flags);
395 + pr_debug("dma_unmap_single 0x%lx\n", dma_addr);
399 diff --git a/arch/mips/cavium-octeon/executive/Makefile b/arch/mips/cavium-octeon/executive/Makefile
400 index 80d6cb2..9b470dd 100644
401 --- a/arch/mips/cavium-octeon/executive/Makefile
402 +++ b/arch/mips/cavium-octeon/executive/Makefile
405 obj-y += cvmx-bootmem.o cvmx-l2c.o cvmx-sysinfo.o octeon-model.o
407 +obj-$(CONFIG_PCI) += cvmx-pcie.o
408 +obj-$(CONFIG_PCI) += cvmx-helper-errata.o cvmx-helper-util.o
409 diff --git a/arch/mips/cavium-octeon/executive/cvmx-helper-errata.c b/arch/mips/cavium-octeon/executive/cvmx-helper-errata.c
411 index 0000000..98822c1
413 +++ b/arch/mips/cavium-octeon/executive/cvmx-helper-errata.c
415 +/***********************license start***************
416 + * Author: Cavium Networks
418 + * Contact: support@caviumnetworks.com
419 + * This file is part of the OCTEON SDK
421 + * Copyright (c) 2003-2008 Cavium Networks
423 + * This file is free software; you can redistribute it and/or modify
424 + * it under the terms of the GNU General Public License, Version 2, as
425 + * published by the Free Software Foundation.
427 + * This file is distributed in the hope that it will be useful, but
428 + * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
429 + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
430 + * NONINFRINGEMENT. See the GNU General Public License for more
433 + * You should have received a copy of the GNU General Public License
434 + * along with this file; if not, write to the Free Software
435 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
436 + * or visit http://www.gnu.org/licenses/.
438 + * This file may also be available under a different license from Cavium.
439 + * Contact Cavium Networks for more information
440 + ***********************license end**************************************/
444 + * Fixes and workaround for Octeon chip errata. This file
445 + * contains functions called by cvmx-helper to workaround known
446 + * chip errata. For the most part, code doesn't need to call
447 + * these functions directly.
450 +#include <asm/octeon/octeon.h>
452 +#include <asm/octeon/cvmx-helper-util.h>
454 +#ifdef CVMX_ENABLE_PKO_FUNCTIONS
458 + * Function to adjust internal IPD pointer alignments
460 + * Returns 0 on success
463 +int __cvmx_helper_errata_fix_ipd_ptr_alignment(void)
465 +#define FIX_IPD_FIRST_BUFF_PAYLOAD_BYTES \
466 + (CVMX_FPA_PACKET_POOL_SIZE - 8 - CVMX_HELPER_FIRST_MBUFF_SKIP)
467 +#define FIX_IPD_NON_FIRST_BUFF_PAYLOAD_BYTES \
468 + (CVMX_FPA_PACKET_POOL_SIZE - 8 - CVMX_HELPER_NOT_FIRST_MBUFF_SKIP)
469 +#define FIX_IPD_OUTPORT 0
470 + /* Ports 0-15 are interface 0, 16-31 are interface 1 */
471 +#define INTERFACE(port) (port >> 4)
472 +#define INDEX(port) (port & 0xf)
474 + cvmx_pko_command_word0_t pko_command;
475 + cvmx_buf_ptr_t g_buffer, pkt_buffer;
477 + int size, num_segs = 0, wqe_pcnt, pkt_pcnt;
478 + cvmx_gmxx_prtx_cfg_t gmx_cfg;
480 + int retry_loop_cnt;
483 + cvmx_helper_link_info_t link_info;
485 + /* Save values for restore at end */
486 + uint64_t prtx_cfg =
487 + cvmx_read_csr(CVMX_GMXX_PRTX_CFG(INDEX(FIX_IPD_OUTPORT),
488 + INTERFACE(FIX_IPD_OUTPORT)));
489 + uint64_t tx_ptr_en =
490 + cvmx_read_csr(CVMX_ASXX_TX_PRT_EN(INTERFACE(FIX_IPD_OUTPORT)));
491 + uint64_t rx_ptr_en =
492 + cvmx_read_csr(CVMX_ASXX_RX_PRT_EN(INTERFACE(FIX_IPD_OUTPORT)));
493 + uint64_t rxx_jabber =
494 + cvmx_read_csr(CVMX_GMXX_RXX_JABBER(INDEX(FIX_IPD_OUTPORT),
495 + INTERFACE(FIX_IPD_OUTPORT)));
496 + uint64_t frame_max =
497 + cvmx_read_csr(CVMX_GMXX_RXX_FRM_MAX(INDEX(FIX_IPD_OUTPORT),
498 + INTERFACE(FIX_IPD_OUTPORT)));
500 + /* Configure port to gig FDX as required for loopback mode */
501 + cvmx_helper_rgmii_internal_loopback(FIX_IPD_OUTPORT);
504 + * Disable reception on all ports so if traffic is present it
505 + * will not interfere.
507 + cvmx_write_csr(CVMX_ASXX_RX_PRT_EN(INTERFACE(FIX_IPD_OUTPORT)), 0);
509 + cvmx_wait(100000000ull);
511 + for (retry_loop_cnt = 0; retry_loop_cnt < 10; retry_loop_cnt++) {
512 + retry_cnt = 100000;
513 + wqe_pcnt = cvmx_read_csr(CVMX_IPD_PTR_COUNT);
514 + pkt_pcnt = (wqe_pcnt >> 7) & 0x7f;
517 + num_segs = (2 + pkt_pcnt - wqe_pcnt) & 3;
525 + FIX_IPD_FIRST_BUFF_PAYLOAD_BYTES +
526 + ((num_segs - 1) * FIX_IPD_NON_FIRST_BUFF_PAYLOAD_BYTES) -
527 + (FIX_IPD_NON_FIRST_BUFF_PAYLOAD_BYTES / 2);
529 + cvmx_write_csr(CVMX_ASXX_PRT_LOOP(INTERFACE(FIX_IPD_OUTPORT)),
530 + 1 << INDEX(FIX_IPD_OUTPORT));
535 + cvmx_ptr_to_phys(cvmx_fpa_alloc(CVMX_FPA_WQE_POOL));
536 + if (g_buffer.s.addr == 0) {
537 + cvmx_dprintf("WARNING: FIX_IPD_PTR_ALIGNMENT buffer "
538 + "allocation failure.\n");
542 + g_buffer.s.pool = CVMX_FPA_WQE_POOL;
543 + g_buffer.s.size = num_segs;
545 + pkt_buffer.u64 = 0;
546 + pkt_buffer.s.addr =
547 + cvmx_ptr_to_phys(cvmx_fpa_alloc(CVMX_FPA_PACKET_POOL));
548 + if (pkt_buffer.s.addr == 0) {
549 + cvmx_dprintf("WARNING: FIX_IPD_PTR_ALIGNMENT buffer "
550 + "allocation failure.\n");
553 + pkt_buffer.s.i = 1;
554 + pkt_buffer.s.pool = CVMX_FPA_PACKET_POOL;
555 + pkt_buffer.s.size = FIX_IPD_FIRST_BUFF_PAYLOAD_BYTES;
557 + p64 = (uint64_t *) cvmx_phys_to_ptr(pkt_buffer.s.addr);
558 + p64[0] = 0xffffffffffff0000ull;
559 + p64[1] = 0x08004510ull;
560 + p64[2] = ((uint64_t) (size - 14) << 48) | 0x5ae740004000ull;
561 + p64[3] = 0x3a5fc0a81073c0a8ull;
563 + for (i = 0; i < num_segs; i++) {
565 + pkt_buffer.s.size =
566 + FIX_IPD_NON_FIRST_BUFF_PAYLOAD_BYTES;
568 + if (i == (num_segs - 1))
569 + pkt_buffer.s.i = 0;
571 + *(uint64_t *) cvmx_phys_to_ptr(g_buffer.s.addr +
572 + 8 * i) = pkt_buffer.u64;
575 + /* Build the PKO command */
576 + pko_command.u64 = 0;
577 + pko_command.s.segs = num_segs;
578 + pko_command.s.total_bytes = size;
579 + pko_command.s.dontfree = 0;
580 + pko_command.s.gather = 1;
583 + cvmx_read_csr(CVMX_GMXX_PRTX_CFG
584 + (INDEX(FIX_IPD_OUTPORT),
585 + INTERFACE(FIX_IPD_OUTPORT)));
587 + cvmx_write_csr(CVMX_GMXX_PRTX_CFG
588 + (INDEX(FIX_IPD_OUTPORT),
589 + INTERFACE(FIX_IPD_OUTPORT)), gmx_cfg.u64);
590 + cvmx_write_csr(CVMX_ASXX_TX_PRT_EN(INTERFACE(FIX_IPD_OUTPORT)),
591 + 1 << INDEX(FIX_IPD_OUTPORT));
592 + cvmx_write_csr(CVMX_ASXX_RX_PRT_EN(INTERFACE(FIX_IPD_OUTPORT)),
593 + 1 << INDEX(FIX_IPD_OUTPORT));
596 + cvmx_read_csr(CVMX_GMXX_RXX_JABBER
597 + (INDEX(FIX_IPD_OUTPORT),
598 + INTERFACE(FIX_IPD_OUTPORT)));
599 + cvmx_write_csr(CVMX_GMXX_RXX_JABBER
600 + (INDEX(FIX_IPD_OUTPORT),
601 + INTERFACE(FIX_IPD_OUTPORT)), 65392 - 14 - 4);
602 + cvmx_write_csr(CVMX_GMXX_RXX_FRM_MAX
603 + (INDEX(FIX_IPD_OUTPORT),
604 + INTERFACE(FIX_IPD_OUTPORT)), 65392 - 14 - 4);
606 +#if CVMX_PKO_USE_FAU_FOR_OUTPUT_QUEUES
607 + cvmx_pko_send_packet_prepare(FIX_IPD_OUTPORT,
608 + cvmx_pko_get_base_queue
610 + CVMX_PKO_LOCK_NONE);
611 + cvmx_pko_send_packet_finish(FIX_IPD_OUTPORT,
612 + cvmx_pko_get_base_queue
613 + (FIX_IPD_OUTPORT), pko_command,
614 + g_buffer, CVMX_PKO_LOCK_NONE);
616 + cvmx_pko_send_packet_prepare(FIX_IPD_OUTPORT,
617 + cvmx_pko_get_base_queue
619 + CVMX_PKO_LOCK_CMD_QUEUE);
620 + cvmx_pko_send_packet_finish(FIX_IPD_OUTPORT,
621 + cvmx_pko_get_base_queue
622 + (FIX_IPD_OUTPORT), pko_command,
623 + g_buffer, CVMX_PKO_LOCK_CMD_QUEUE);
628 + work = cvmx_pow_work_request_sync(CVMX_POW_WAIT);
630 + } while ((work == NULL) && (retry_cnt > 0));
633 + cvmx_dprintf("WARNING: FIX_IPD_PTR_ALIGNMENT "
634 + "get_work() timeout occured.\n");
638 + cvmx_helper_free_packet_data(work);
643 + /* Return CSR configs to saved values */
644 + cvmx_write_csr(CVMX_GMXX_PRTX_CFG
645 + (INDEX(FIX_IPD_OUTPORT), INTERFACE(FIX_IPD_OUTPORT)),
647 + cvmx_write_csr(CVMX_ASXX_TX_PRT_EN(INTERFACE(FIX_IPD_OUTPORT)),
649 + cvmx_write_csr(CVMX_ASXX_RX_PRT_EN(INTERFACE(FIX_IPD_OUTPORT)),
651 + cvmx_write_csr(CVMX_GMXX_RXX_JABBER
652 + (INDEX(FIX_IPD_OUTPORT), INTERFACE(FIX_IPD_OUTPORT)),
654 + cvmx_write_csr(CVMX_GMXX_RXX_FRM_MAX
655 + (INDEX(FIX_IPD_OUTPORT), INTERFACE(FIX_IPD_OUTPORT)),
657 + cvmx_write_csr(CVMX_ASXX_PRT_LOOP(INTERFACE(FIX_IPD_OUTPORT)), 0);
658 + /* Set link to down so autonegotiation will set it up again */
660 + cvmx_helper_link_set(FIX_IPD_OUTPORT, link_info);
663 + * Bring the link back up as autonegotiation is not done in
664 + * user applications.
666 + cvmx_helper_link_autoconf(FIX_IPD_OUTPORT);
670 + cvmx_dprintf("WARNING: FIX_IPD_PTR_ALIGNMENT failed.\n");
678 + * Workaround ASX setup errata with CN38XX pass1
680 + * @interface: Interface to setup
681 + * @port: Port to setup (0..3)
683 + * Chip frequency in Hertz
685 + * Returns Zero on success, negative on failure
687 +int __cvmx_helper_errata_asx_pass1(int interface, int port, int cpu_clock_hz)
689 + /* Set hi water mark as per errata GMX-4 */
690 + if (cpu_clock_hz >= 325000000 && cpu_clock_hz < 375000000)
691 + cvmx_write_csr(CVMX_ASXX_TX_HI_WATERX(port, interface), 12);
692 + else if (cpu_clock_hz >= 375000000 && cpu_clock_hz < 437000000)
693 + cvmx_write_csr(CVMX_ASXX_TX_HI_WATERX(port, interface), 11);
694 + else if (cpu_clock_hz >= 437000000 && cpu_clock_hz < 550000000)
695 + cvmx_write_csr(CVMX_ASXX_TX_HI_WATERX(port, interface), 10);
696 + else if (cpu_clock_hz >= 550000000 && cpu_clock_hz < 687000000)
697 + cvmx_write_csr(CVMX_ASXX_TX_HI_WATERX(port, interface), 9);
699 + cvmx_dprintf("Illegal clock frequency (%d). "
700 + "CVMX_ASXX_TX_HI_WATERX not set\n",
706 + * This function needs to be called on all Octeon chips with
709 + * The Size field is 8 too large in WQE and next pointers
711 + * The Size field generated by IPD is 8 larger than it should
712 + * be. The Size field is <55:40> of both:
713 + * - WORD3 in the work queue entry, and
714 + * - the next buffer pointer (which precedes the packet data
717 + * @work: Work queue entry to fix
718 + * Returns Zero on success. Negative on failure
720 +int cvmx_helper_fix_ipd_packet_chain(cvmx_wqe_t *work)
722 + uint64_t number_buffers = work->word2.s.bufs;
724 + /* We only need to do this if the work has buffers */
725 + if (number_buffers) {
726 + cvmx_buf_ptr_t buffer_ptr = work->packet_ptr;
727 + /* Check for errata PKI-100 */
728 + if ((buffer_ptr.s.pool == 0) &&
729 + (((uint64_t) buffer_ptr.s.size +
730 + ((uint64_t) buffer_ptr.s.back << 7) +
731 + ((uint64_t) buffer_ptr.s.addr & 0x7F)) !=
732 + (CVMX_FPA_PACKET_POOL_SIZE + 8))) {
733 + /* fix is not needed */
736 + /* Decrement the work packet pointer */
737 + buffer_ptr.s.size -= 8;
738 + work->packet_ptr = buffer_ptr;
741 + * Now loop through decrementing the size for each
742 + * additional buffer.
744 + while (--number_buffers) {
745 + /* Chain pointers are 8 bytes before the data */
746 + cvmx_buf_ptr_t *ptr =
747 + (cvmx_buf_ptr_t *) cvmx_phys_to_ptr(buffer_ptr.s.addr - 8);
749 + buffer_ptr.s.size -= 8;
754 + * Make sure that these write go out before other operations
755 + * such as FPA frees.
761 +#endif /* CVMX_ENABLE_PKO_FUNCTIONS */
764 + * Due to errata G-720, the 2nd order CDR circuit on CN52XX pass
765 + * 1 doesn't work properly. The following code disables 2nd order
766 + * CDR for the specified QLM.
768 + * @qlm: QLM to disable 2nd order CDR for.
770 +void __cvmx_helper_errata_qlm_disable_2nd_order_cdr(int qlm)
773 + cvmx_helper_qlm_jtag_init();
774 + /* We need to load all four lanes of the QLM, a total of 1072 bits */
775 + for (lane = 0; lane < 4; lane++) {
777 + * Each lane has 268 bits. We need to set
778 + * cfg_cdr_incx<67:64> = 3 and cfg_cdr_secord<77> =
779 + * 1. All other bits are zero. Bits go in LSB first,
780 + * so start off with the zeros for bits <63:0>.
782 + cvmx_helper_qlm_jtag_shift_zeros(qlm, 63 - 0 + 1);
783 + /* cfg_cdr_incx<67:64>=3 */
784 + cvmx_helper_qlm_jtag_shift(qlm, 67 - 64 + 1, 3);
785 + /* Zeros for bits <76:68> */
786 + cvmx_helper_qlm_jtag_shift_zeros(qlm, 76 - 68 + 1);
787 + /* cfg_cdr_secord<77>=1 */
788 + cvmx_helper_qlm_jtag_shift(qlm, 77 - 77 + 1, 1);
789 + /* Zeros for bits <267:78> */
790 + cvmx_helper_qlm_jtag_shift_zeros(qlm, 267 - 78 + 1);
792 + cvmx_helper_qlm_jtag_update(qlm);
794 diff --git a/arch/mips/cavium-octeon/executive/cvmx-helper-util.c b/arch/mips/cavium-octeon/executive/cvmx-helper-util.c
796 index 0000000..dc0087c
798 +++ b/arch/mips/cavium-octeon/executive/cvmx-helper-util.c
800 +/***********************license start***************
801 + * Author: Cavium Networks
803 + * Contact: support@caviumnetworks.com
804 + * This file is part of the OCTEON SDK
806 + * Copyright (c) 2003-2008 Cavium Networks
808 + * This file is free software; you can redistribute it and/or modify
809 + * it under the terms of the GNU General Public License, Version 2, as
810 + * published by the Free Software Foundation.
812 + * This file is distributed in the hope that it will be useful, but
813 + * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
814 + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
815 + * NONINFRINGEMENT. See the GNU General Public License for more
818 + * You should have received a copy of the GNU General Public License
819 + * along with this file; if not, write to the Free Software
820 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
821 + * or visit http://www.gnu.org/licenses/.
823 + * This file may also be available under a different license from Cavium.
824 + * Contact Cavium Networks for more information
825 + ***********************license end**************************************/
829 + * Small helper utilities.
833 +#include <asm/octeon/octeon.h>
835 +#include <asm/octeon/cvmx-helper-util.h>
837 +#ifdef CVMX_ENABLE_HELPER_FUNCTIONS
840 + * Get the version of the CVMX libraries.
842 + * Returns Version string. Note this buffer is allocated statically
843 + * and will be shared by all callers.
845 +const char *cvmx_helper_get_version(void)
847 + return OCTEON_SDK_VERSION_STRING;
851 + * Convert a interface mode into a human readable string
853 + * @mode: Mode to convert
857 +const char *cvmx_helper_interface_mode_to_string(cvmx_helper_interface_mode_t
861 + case CVMX_HELPER_INTERFACE_MODE_DISABLED:
863 + case CVMX_HELPER_INTERFACE_MODE_RGMII:
865 + case CVMX_HELPER_INTERFACE_MODE_GMII:
867 + case CVMX_HELPER_INTERFACE_MODE_SPI:
869 + case CVMX_HELPER_INTERFACE_MODE_PCIE:
871 + case CVMX_HELPER_INTERFACE_MODE_XAUI:
873 + case CVMX_HELPER_INTERFACE_MODE_SGMII:
875 + case CVMX_HELPER_INTERFACE_MODE_PICMG:
877 + case CVMX_HELPER_INTERFACE_MODE_NPI:
879 + case CVMX_HELPER_INTERFACE_MODE_LOOP:
886 + * Debug routine to dump the packet structure to the console
888 + * @work: Work queue entry containing the packet to dump
890 +int cvmx_helper_dump_packet(cvmx_wqe_t *work)
893 + uint64_t remaining_bytes;
894 + cvmx_buf_ptr_t buffer_ptr;
895 + uint64_t start_of_buffer;
896 + uint8_t *data_address;
897 + uint8_t *end_of_data;
899 + cvmx_dprintf("Packet Length: %u\n", work->len);
900 + cvmx_dprintf(" Input Port: %u\n", work->ipprt);
901 + cvmx_dprintf(" QoS: %u\n", work->qos);
902 + cvmx_dprintf(" Buffers: %u\n", work->word2.s.bufs);
904 + if (work->word2.s.bufs == 0) {
905 + cvmx_ipd_wqe_fpa_queue_t wqe_pool;
906 + wqe_pool.u64 = cvmx_read_csr(CVMX_IPD_WQE_FPA_QUEUE);
907 + buffer_ptr.u64 = 0;
908 + buffer_ptr.s.pool = wqe_pool.s.wqe_pool;
909 + buffer_ptr.s.size = 128;
910 + buffer_ptr.s.addr = cvmx_ptr_to_phys(work->packet_data);
911 + if (cvmx_likely(!work->word2.s.not_IP)) {
912 + if (work->word2.s.is_v6)
913 + buffer_ptr.s.addr += 2;
915 + buffer_ptr.s.addr += 6;
918 + buffer_ptr = work->packet_ptr;
919 + remaining_bytes = work->len;
921 + while (remaining_bytes) {
923 + ((buffer_ptr.s.addr >> 7) - buffer_ptr.s.back) << 7;
924 + cvmx_dprintf(" Buffer Start:%llx\n",
925 + (unsigned long long)start_of_buffer);
926 + cvmx_dprintf(" Buffer I : %u\n", buffer_ptr.s.i);
927 + cvmx_dprintf(" Buffer Back: %u\n", buffer_ptr.s.back);
928 + cvmx_dprintf(" Buffer Pool: %u\n", buffer_ptr.s.pool);
929 + cvmx_dprintf(" Buffer Data: %llx\n",
930 + (unsigned long long)buffer_ptr.s.addr);
931 + cvmx_dprintf(" Buffer Size: %u\n", buffer_ptr.s.size);
933 + cvmx_dprintf("\t\t");
934 + data_address = (uint8_t *) cvmx_phys_to_ptr(buffer_ptr.s.addr);
935 + end_of_data = data_address + buffer_ptr.s.size;
937 + while (data_address < end_of_data) {
938 + if (remaining_bytes == 0)
942 + cvmx_dprintf("%02x", (unsigned int)*data_address);
944 + if (remaining_bytes && (count == 7)) {
945 + cvmx_dprintf("\n\t\t");
950 + cvmx_dprintf("\n");
952 + if (remaining_bytes)
954 + *(cvmx_buf_ptr_t *) cvmx_phys_to_ptr(buffer_ptr.s.
961 + * Setup Random Early Drop on a specific input queue
963 + * @queue: Input queue to setup RED on (0-7)
965 + * Packets will begin slowly dropping when there are less than
966 + * this many packet buffers free in FPA 0.
968 + * All incomming packets will be dropped when there are less
969 + * than this many free packet buffers in FPA 0.
970 + * Returns Zero on success. Negative on failure
972 +int cvmx_helper_setup_red_queue(int queue, int pass_thresh, int drop_thresh)
974 + cvmx_ipd_qos_red_marks_t red_marks;
975 + cvmx_ipd_red_quex_param_t red_param;
978 + * Set RED to begin dropping packets when there are
979 + * pass_thresh buffers left. It will linearly drop more
980 + * packets until reaching drop_thresh buffers.
983 + red_marks.s.drop = drop_thresh;
984 + red_marks.s.pass = pass_thresh;
985 + cvmx_write_csr(CVMX_IPD_QOSX_RED_MARKS(queue), red_marks.u64);
987 + /* Use the actual queue 0 counter, not the average */
989 + red_param.s.prb_con =
990 + (255ul << 24) / (red_marks.s.pass - red_marks.s.drop);
991 + red_param.s.avg_con = 1;
992 + red_param.s.new_con = 255;
993 + red_param.s.use_pcnt = 1;
994 + cvmx_write_csr(CVMX_IPD_RED_QUEX_PARAM(queue), red_param.u64);
999 + * Setup Random Early Drop to automatically begin dropping packets.
1002 + * Packets will begin slowly dropping when there are less than
1003 + * this many packet buffers free in FPA 0.
1005 + * All incomming packets will be dropped when there are less
1006 + * than this many free packet buffers in FPA 0.
1007 + * Returns Zero on success. Negative on failure
1009 +int cvmx_helper_setup_red(int pass_thresh, int drop_thresh)
1011 + cvmx_ipd_portx_bp_page_cnt_t page_cnt;
1012 + cvmx_ipd_bp_prt_red_end_t ipd_bp_prt_red_end;
1013 + cvmx_ipd_red_port_enable_t red_port_enable;
1018 + /* Disable backpressure based on queued buffers. It needs SW support */
1020 + page_cnt.s.bp_enb = 0;
1021 + page_cnt.s.page_cnt = 100;
1022 + for (interface = 0; interface < 2; interface++) {
1023 + for (port = cvmx_helper_get_first_ipd_port(interface);
1024 + port < cvmx_helper_get_last_ipd_port(interface); port++)
1025 + cvmx_write_csr(CVMX_IPD_PORTX_BP_PAGE_CNT(port),
1029 + for (queue = 0; queue < 8; queue++)
1030 + cvmx_helper_setup_red_queue(queue, pass_thresh, drop_thresh);
1032 + /* Shutoff the dropping based on the per port page count. SW isn't
1033 + decrementing it right now */
1034 + ipd_bp_prt_red_end.u64 = 0;
1035 + ipd_bp_prt_red_end.s.prt_enb = 0;
1036 + cvmx_write_csr(CVMX_IPD_BP_PRT_RED_END, ipd_bp_prt_red_end.u64);
1038 + red_port_enable.u64 = 0;
1039 + red_port_enable.s.prt_enb = 0xfffffffffull;
1040 + red_port_enable.s.avg_dly = 10000;
1041 + red_port_enable.s.prb_dly = 10000;
1042 + cvmx_write_csr(CVMX_IPD_RED_PORT_ENABLE, red_port_enable.u64);
1048 + * Setup the common GMX settings that determine the number of
1049 + * ports. These setting apply to almost all configurations of all
1052 + * @interface: Interface to configure
1053 + * @num_ports: Number of ports on the interface
1055 + * Returns Zero on success, negative on failure
1057 +int __cvmx_helper_setup_gmx(int interface, int num_ports)
1059 + cvmx_gmxx_tx_prts_t gmx_tx_prts;
1060 + cvmx_gmxx_rx_prts_t gmx_rx_prts;
1061 + cvmx_pko_reg_gmx_port_mode_t pko_mode;
1063 + /* Tell GMX the number of TX ports on this interface */
1064 + gmx_tx_prts.u64 = cvmx_read_csr(CVMX_GMXX_TX_PRTS(interface));
1065 + gmx_tx_prts.s.prts = num_ports;
1066 + cvmx_write_csr(CVMX_GMXX_TX_PRTS(interface), gmx_tx_prts.u64);
1069 + * Tell GMX the number of RX ports on this interface. This only
1070 + * applies to *GMII and XAUI ports.
1072 + if (cvmx_helper_interface_get_mode(interface) ==
1073 + CVMX_HELPER_INTERFACE_MODE_RGMII
1074 + || cvmx_helper_interface_get_mode(interface) ==
1075 + CVMX_HELPER_INTERFACE_MODE_SGMII
1076 + || cvmx_helper_interface_get_mode(interface) ==
1077 + CVMX_HELPER_INTERFACE_MODE_GMII
1078 + || cvmx_helper_interface_get_mode(interface) ==
1079 + CVMX_HELPER_INTERFACE_MODE_XAUI) {
1080 + if (num_ports > 4) {
1081 + cvmx_dprintf("__cvmx_helper_setup_gmx: "
1082 + "Illegal num_ports\n");
1086 + gmx_rx_prts.u64 = cvmx_read_csr(CVMX_GMXX_RX_PRTS(interface));
1087 + gmx_rx_prts.s.prts = num_ports;
1088 + cvmx_write_csr(CVMX_GMXX_RX_PRTS(interface), gmx_rx_prts.u64);
1091 + /* Skip setting CVMX_PKO_REG_GMX_PORT_MODE on 30XX and 31XX */
1092 + if (OCTEON_IS_MODEL(OCTEON_CN30XX) || OCTEON_IS_MODEL(OCTEON_CN31XX)
1093 + || OCTEON_IS_MODEL(OCTEON_CN50XX))
1096 + /* Tell PKO the number of ports on this interface */
1097 + pko_mode.u64 = cvmx_read_csr(CVMX_PKO_REG_GMX_PORT_MODE);
1098 + if (interface == 0) {
1099 + if (num_ports == 1)
1100 + pko_mode.s.mode0 = 4;
1101 + else if (num_ports == 2)
1102 + pko_mode.s.mode0 = 3;
1103 + else if (num_ports <= 4)
1104 + pko_mode.s.mode0 = 2;
1105 + else if (num_ports <= 8)
1106 + pko_mode.s.mode0 = 1;
1108 + pko_mode.s.mode0 = 0;
1110 + if (num_ports == 1)
1111 + pko_mode.s.mode1 = 4;
1112 + else if (num_ports == 2)
1113 + pko_mode.s.mode1 = 3;
1114 + else if (num_ports <= 4)
1115 + pko_mode.s.mode1 = 2;
1116 + else if (num_ports <= 8)
1117 + pko_mode.s.mode1 = 1;
1119 + pko_mode.s.mode1 = 0;
1121 + cvmx_write_csr(CVMX_PKO_REG_GMX_PORT_MODE, pko_mode.u64);
1126 + * Returns the IPD/PKO port number for a port on the given
1129 + * @interface: Interface to use
1130 + * @port: Port on the interface
1132 + * Returns IPD/PKO port number
1134 +int cvmx_helper_get_ipd_port(int interface, int port)
1136 + switch (interface) {
1149 +#endif /* CVMX_ENABLE_HELPER_FUNCTIONS */
1152 + * Returns the interface number for an IPD/PKO port number.
1154 + * @ipd_port: IPD/PKO port number
1156 + * Returns Interface number
1158 +int cvmx_helper_get_interface_num(int ipd_port)
1160 + if (ipd_port < 16)
1162 + else if (ipd_port < 32)
1164 + else if (ipd_port < 36)
1166 + else if (ipd_port < 40)
1169 + cvmx_dprintf("cvmx_helper_get_interface_num: "
1170 + "Illegal IPD port number\n");
1176 + * Returns the interface index number for an IPD/PKO port
1179 + * @ipd_port: IPD/PKO port number
1181 + * Returns Interface index number
1183 +int cvmx_helper_get_interface_index_num(int ipd_port)
1185 + if (ipd_port < 32)
1186 + return ipd_port & 15;
1187 + else if (ipd_port < 36)
1188 + return ipd_port & 3;
1189 + else if (ipd_port < 40)
1190 + return ipd_port & 3;
1192 + cvmx_dprintf("cvmx_helper_get_interface_index_num: "
1193 + "Illegal IPD port number\n");
1199 + * Initialize the internal QLM JTAG logic to allow programming
1200 + * of the JTAG chain by the cvmx_helper_qlm_jtag_*() functions.
1201 + * These functions should only be used at the direction of Cavium
1202 + * Networks. Programming incorrect values into the JTAG chain
1203 + * can cause chip damage.
1205 +void cvmx_helper_qlm_jtag_init(void)
1207 + union cvmx_ciu_qlm_jtgc jtgc;
1208 + int clock_div = 0;
1209 + int divisor = cvmx_sysinfo_get()->cpu_clock_hz / (25 * 1000000);
1210 + divisor = (divisor - 1) >> 2;
1211 + /* Convert the divisor into a power of 2 shift */
1212 + CVMX_CLZ(clock_div, divisor);
1213 + clock_div = 32 - clock_div;
1216 + * Clock divider for QLM JTAG operations. eclk is divided by
1217 + * 2^(CLK_DIV + 2).
1220 + jtgc.s.clk_div = clock_div;
1221 + jtgc.s.mux_sel = 0;
1222 + if (OCTEON_IS_MODEL(OCTEON_CN52XX))
1223 + jtgc.s.bypass = 0x3;
1225 + jtgc.s.bypass = 0xf;
1226 + cvmx_write_csr(CVMX_CIU_QLM_JTGC, jtgc.u64);
1227 + cvmx_read_csr(CVMX_CIU_QLM_JTGC);
1231 + * Write up to 32bits into the QLM jtag chain. Bits are shifted
1232 + * into the MSB and out the LSB, so you should shift in the low
1233 + * order bits followed by the high order bits. The JTAG chain is
1234 + * 4 * 268 bits long, or 1072.
1236 + * @qlm: QLM to shift value into
1237 + * @bits: Number of bits to shift in (1-32).
1238 + * @data: Data to shift in. Bit 0 enters the chain first, followed by
1241 + * Returns The low order bits of the JTAG chain that shifted out of the
1244 +uint32_t cvmx_helper_qlm_jtag_shift(int qlm, int bits, uint32_t data)
1246 + union cvmx_ciu_qlm_jtgd jtgd;
1249 + jtgd.s.shft_cnt = bits - 1;
1250 + jtgd.s.shft_reg = data;
1251 + if (!OCTEON_IS_MODEL(OCTEON_CN56XX_PASS1_X))
1252 + jtgd.s.select = 1 << qlm;
1253 + cvmx_write_csr(CVMX_CIU_QLM_JTGD, jtgd.u64);
1255 + jtgd.u64 = cvmx_read_csr(CVMX_CIU_QLM_JTGD);
1256 + } while (jtgd.s.shift);
1257 + return jtgd.s.shft_reg >> (32 - bits);
1261 + * Shift long sequences of zeros into the QLM JTAG chain. It is
1262 + * common to need to shift more than 32 bits of zeros into the
1263 + * chain. This function is a convience wrapper around
1264 + * cvmx_helper_qlm_jtag_shift() to shift more than 32 bits of
1265 + * zeros at a time.
1267 + * @qlm: QLM to shift zeros into
1270 +void cvmx_helper_qlm_jtag_shift_zeros(int qlm, int bits)
1272 + while (bits > 0) {
1276 + cvmx_helper_qlm_jtag_shift(qlm, n, 0);
1282 + * Program the QLM JTAG chain into all lanes of the QLM. You must
1283 + * have already shifted in 268*4, or 1072 bits into the JTAG
1284 + * chain. Updating invalid values can possibly cause chip damage.
1286 + * @qlm: QLM to program
1288 +void cvmx_helper_qlm_jtag_update(int qlm)
1290 + union cvmx_ciu_qlm_jtgd jtgd;
1292 + /* Update the new data */
1294 + jtgd.s.update = 1;
1295 + if (!OCTEON_IS_MODEL(OCTEON_CN56XX_PASS1_X))
1296 + jtgd.s.select = 1 << qlm;
1297 + cvmx_write_csr(CVMX_CIU_QLM_JTGD, jtgd.u64);
1299 + jtgd.u64 = cvmx_read_csr(CVMX_CIU_QLM_JTGD);
1300 + } while (jtgd.s.update);
1302 diff --git a/arch/mips/cavium-octeon/executive/cvmx-pcie.c b/arch/mips/cavium-octeon/executive/cvmx-pcie.c
1303 new file mode 100644
1304 index 0000000..710f21f
1306 +++ b/arch/mips/cavium-octeon/executive/cvmx-pcie.c
1308 +/***********************license start***************
1309 + * Author: Cavium Networks
1311 + * Contact: support@caviumnetworks.com
1312 + * This file is part of the OCTEON SDK
1314 + * Copyright (c) 2003-2008 Cavium Networks
1316 + * This file is free software; you can redistribute it and/or modify
1317 + * it under the terms of the GNU General Public License, Version 2, as
1318 + * published by the Free Software Foundation.
1320 + * This file is distributed in the hope that it will be useful, but
1321 + * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
1322 + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
1323 + * NONINFRINGEMENT. See the GNU General Public License for more
1326 + * You should have received a copy of the GNU General Public License
1327 + * along with this file; if not, write to the Free Software
1328 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1329 + * 02110-1301 USA or visit http://www.gnu.org/licenses/.
1331 + * This file may also be available under a different license from Cavium.
1332 + * Contact Cavium Networks for more information
1333 + ***********************license end**************************************/
1337 + * Interface to PCIe as a host(RC) or target(EP)
1340 +#include <linux/delay.h>
1341 +#include <asm/byteorder.h>
1343 +#include <asm/octeon/octeon.h>
1344 +#include <asm/octeon/cvmx-npei-defs.h>
1345 +#include <asm/octeon/cvmx-pciercx-defs.h>
1346 +#include <asm/octeon/cvmx-pescx-defs.h>
1347 +#include <asm/octeon/cvmx-pexp-defs.h>
1348 +#include <asm/octeon/cvmx-pcieep-defs.h>
1349 +#include <asm/octeon/cvmx-helper-errata.h>
1350 +#include <asm/octeon/cvmx-pcie.h>
1353 + * Return the Core virtual base address for PCIe IO access. IOs are
1354 + * read/written as an offset from this address.
1356 + * @pcie_port: PCIe port the IO is for
1358 + * Returns 64bit Octeon IO base address for read/write
1360 +uint64_t cvmx_pcie_get_io_base_address(int pcie_port)
1362 + union cvmx_pcie_address pcie_addr;
1363 + pcie_addr.u64 = 0;
1364 + pcie_addr.io.upper = 0;
1365 + pcie_addr.io.io = 1;
1366 + pcie_addr.io.did = 3;
1367 + pcie_addr.io.subdid = 2;
1368 + pcie_addr.io.es = 1;
1369 + pcie_addr.io.port = pcie_port;
1370 + return pcie_addr.u64;
1374 + * Size of the IO address region returned at address
1375 + * cvmx_pcie_get_io_base_address()
1377 + * @pcie_port: PCIe port the IO is for
1379 + * Returns Size of the IO window
1381 +uint64_t cvmx_pcie_get_io_size(int pcie_port)
1383 + return 1ull << 32;
1387 + * Return the Core virtual base address for PCIe MEM access. Memory is
1388 + * read/written as an offset from this address.
1390 + * @pcie_port: PCIe port the IO is for
1392 + * Returns 64bit Octeon IO base address for read/write
1394 +uint64_t cvmx_pcie_get_mem_base_address(int pcie_port)
1396 + union cvmx_pcie_address pcie_addr;
1397 + pcie_addr.u64 = 0;
1398 + pcie_addr.mem.upper = 0;
1399 + pcie_addr.mem.io = 1;
1400 + pcie_addr.mem.did = 3;
1401 + pcie_addr.mem.subdid = 3 + pcie_port;
1402 + return pcie_addr.u64;
1406 + * Size of the Mem address region returned at address
1407 + * cvmx_pcie_get_mem_base_address()
1409 + * @pcie_port: PCIe port the IO is for
1411 + * Returns Size of the Mem window
1413 +uint64_t cvmx_pcie_get_mem_size(int pcie_port)
1415 + return 1ull << 36;
1419 + * Initialize the RC config space CSRs
1421 + * @pcie_port: PCIe port to initialize
1423 +static void __cvmx_pcie_rc_initialize_config_space(int pcie_port)
1425 + union cvmx_pciercx_cfg030 pciercx_cfg030;
1426 + union cvmx_npei_ctl_status2 npei_ctl_status2;
1427 + union cvmx_pciercx_cfg070 pciercx_cfg070;
1428 + union cvmx_pciercx_cfg001 pciercx_cfg001;
1429 + union cvmx_pciercx_cfg032 pciercx_cfg032;
1430 + union cvmx_pciercx_cfg006 pciercx_cfg006;
1431 + union cvmx_pciercx_cfg008 pciercx_cfg008;
1432 + union cvmx_pciercx_cfg009 pciercx_cfg009;
1433 + union cvmx_pciercx_cfg010 pciercx_cfg010;
1434 + union cvmx_pciercx_cfg011 pciercx_cfg011;
1435 + union cvmx_pciercx_cfg035 pciercx_cfg035;
1436 + union cvmx_pciercx_cfg075 pciercx_cfg075;
1437 + union cvmx_pciercx_cfg034 pciercx_cfg034;
1439 + /* Max Payload Size (PCIE*_CFG030[MPS]) */
1440 + /* Max Read Request Size (PCIE*_CFG030[MRRS]) */
1441 + /* Relaxed-order, no-snoop enables (PCIE*_CFG030[RO_EN,NS_EN] */
1442 + /* Error Message Enables (PCIE*_CFG030[CE_EN,NFE_EN,FE_EN,UR_EN]) */
1443 + pciercx_cfg030.u32 =
1444 + cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG030(pcie_port));
1446 + * Max payload size = 128 bytes for best Octeon DMA
1449 + pciercx_cfg030.s.mps = 0;
1451 + * Max read request size = 128 bytes for best Octeon DMA
1454 + pciercx_cfg030.s.mrrs = 0;
1455 + /* Enable relaxed ordering. */
1456 + pciercx_cfg030.s.ro_en = 1;
1457 + /* Enable no snoop. */
1458 + pciercx_cfg030.s.ns_en = 1;
1459 + /* Correctable error reporting enable. */
1460 + pciercx_cfg030.s.ce_en = 1;
1461 + /* Non-fatal error reporting enable. */
1462 + pciercx_cfg030.s.nfe_en = 1;
1463 + /* Fatal error reporting enable. */
1464 + pciercx_cfg030.s.fe_en = 1;
1465 + /* Unsupported request reporting enable. */
1466 + pciercx_cfg030.s.ur_en = 1;
1467 + cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG030(pcie_port),
1468 + pciercx_cfg030.u32);
1471 + * Max Payload Size (NPEI_CTL_STATUS2[MPS]) must match
1472 + * PCIE*_CFG030[MPS]
1474 + * Max Read Request Size (NPEI_CTL_STATUS2[MRRS]) must not
1475 + * exceed PCIE*_CFG030[MRRS].
1477 + npei_ctl_status2.u64 = cvmx_read_csr(CVMX_PEXP_NPEI_CTL_STATUS2);
1478 + /* Max payload size = 128 bytes for best Octeon DMA performance */
1479 + npei_ctl_status2.s.mps = 0;
1480 + /* Max read request size = 128 bytes for best Octeon DMA performance */
1481 + npei_ctl_status2.s.mrrs = 0;
1482 + cvmx_write_csr(CVMX_PEXP_NPEI_CTL_STATUS2, npei_ctl_status2.u64);
1484 + /* ECRC Generation (PCIE*_CFG070[GE,CE]) */
1485 + pciercx_cfg070.u32 =
1486 + cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG070(pcie_port));
1487 + pciercx_cfg070.s.ge = 1; /* ECRC generation enable. */
1488 + pciercx_cfg070.s.ce = 1; /* ECRC check enable. */
1489 + cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG070(pcie_port),
1490 + pciercx_cfg070.u32);
1493 + * Access Enables (PCIE*_CFG001[MSAE,ME]) ME and MSAE should
1496 + * Interrupt Disable (PCIE*_CFG001[I_DIS]) System Error
1497 + * Message Enable (PCIE*_CFG001[SEE])
1499 + pciercx_cfg001.u32 =
1500 + cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG001(pcie_port));
1501 + pciercx_cfg001.s.msae = 1; /* Memory space enable. */
1502 + pciercx_cfg001.s.me = 1; /* Bus master enable. */
1503 + pciercx_cfg001.s.i_dis = 1; /* INTx assertion disable. */
1504 + pciercx_cfg001.s.see = 1; /* SERR# enable */
1505 + cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG001(pcie_port),
1506 + pciercx_cfg001.u32);
1508 + /* Advanced Error Recovery Message Enables */
1509 + /* (PCIE*_CFG066,PCIE*_CFG067,PCIE*_CFG069) */
1510 + cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG066(pcie_port), 0);
1511 + /* Use CVMX_PCIERCX_CFG067 hardware default */
1512 + cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG069(pcie_port), 0);
1514 + /* Active State Power Management (PCIE*_CFG032[ASLPC]) */
1515 + pciercx_cfg032.u32 =
1516 + cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG032(pcie_port));
1517 + pciercx_cfg032.s.aslpc = 0; /* Active state Link PM control. */
1518 + cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG032(pcie_port),
1519 + pciercx_cfg032.u32);
1521 + /* Entrance Latencies (PCIE*_CFG451[L0EL,L1EL]) */
1524 + * Link Width Mode (PCIERCn_CFG452[LME]) - Set during
1525 + * cvmx_pcie_rc_initialize_link()
1527 + * Primary Bus Number (PCIERCn_CFG006[PBNUM])
1529 + * We set the primary bus number to 1 so IDT bridges are
1530 + * happy. They don't like zero.
1532 + pciercx_cfg006.u32 = 0;
1533 + pciercx_cfg006.s.pbnum = 1;
1534 + pciercx_cfg006.s.sbnum = 1;
1535 + pciercx_cfg006.s.subbnum = 1;
1536 + cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG006(pcie_port),
1537 + pciercx_cfg006.u32);
1540 + * Memory-mapped I/O BAR (PCIERCn_CFG008)
1541 + * Most applications should disable the memory-mapped I/O BAR by
1542 + * setting PCIERCn_CFG008[ML_ADDR] < PCIERCn_CFG008[MB_ADDR]
1544 + pciercx_cfg008.u32 = 0;
1545 + pciercx_cfg008.s.mb_addr = 0x100;
1546 + pciercx_cfg008.s.ml_addr = 0;
1547 + cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG008(pcie_port),
1548 + pciercx_cfg008.u32);
1551 + * Prefetchable BAR (PCIERCn_CFG009,PCIERCn_CFG010,PCIERCn_CFG011)
1552 + * Most applications should disable the prefetchable BAR by setting
1553 + * PCIERCn_CFG011[UMEM_LIMIT],PCIERCn_CFG009[LMEM_LIMIT] <
1554 + * PCIERCn_CFG010[UMEM_BASE],PCIERCn_CFG009[LMEM_BASE]
1556 + pciercx_cfg009.u32 =
1557 + cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG009(pcie_port));
1558 + pciercx_cfg010.u32 =
1559 + cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG010(pcie_port));
1560 + pciercx_cfg011.u32 =
1561 + cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG011(pcie_port));
1562 + pciercx_cfg009.s.lmem_base = 0x100;
1563 + pciercx_cfg009.s.lmem_limit = 0;
1564 + pciercx_cfg010.s.umem_base = 0x100;
1565 + pciercx_cfg011.s.umem_limit = 0;
1566 + cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG009(pcie_port),
1567 + pciercx_cfg009.u32);
1568 + cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG010(pcie_port),
1569 + pciercx_cfg010.u32);
1570 + cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG011(pcie_port),
1571 + pciercx_cfg011.u32);
1574 + * System Error Interrupt Enables (PCIERCn_CFG035[SECEE,SEFEE,SENFEE])
1575 + * PME Interrupt Enables (PCIERCn_CFG035[PMEIE])
1577 + pciercx_cfg035.u32 =
1578 + cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG035(pcie_port));
1579 + /* System error on correctable error enable. */
1580 + pciercx_cfg035.s.secee = 1;
1581 + /* System error on fatal error enable. */
1582 + pciercx_cfg035.s.sefee = 1;
1583 + /* System error on non-fatal error enable. */
1584 + pciercx_cfg035.s.senfee = 1;
1585 + /* PME interrupt enable. */
1586 + pciercx_cfg035.s.pmeie = 1;
1587 + cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG035(pcie_port),
1588 + pciercx_cfg035.u32);
1591 + * Advanced Error Recovery Interrupt Enables
1592 + * (PCIERCn_CFG075[CERE,NFERE,FERE])
1594 + pciercx_cfg075.u32 =
1595 + cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG075(pcie_port));
1596 + /* Correctable error reporting enable. */
1597 + pciercx_cfg075.s.cere = 1;
1598 + /* Non-fatal error reporting enable. */
1599 + pciercx_cfg075.s.nfere = 1;
1600 + /* Fatal error reporting enable. */
1601 + pciercx_cfg075.s.fere = 1;
1602 + cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG075(pcie_port),
1603 + pciercx_cfg075.u32);
1605 + /* HP Interrupt Enables (PCIERCn_CFG034[HPINT_EN],
1606 + * PCIERCn_CFG034[DLLS_EN,CCINT_EN])
1608 + pciercx_cfg034.u32 =
1609 + cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG034(pcie_port));
1610 + /* Hot-plug interrupt enable. */
1611 + pciercx_cfg034.s.hpint_en = 1;
1612 + /* Data Link Layer state changed enable */
1613 + pciercx_cfg034.s.dlls_en = 1;
1614 + /* Command completed interrupt enable. */
1615 + pciercx_cfg034.s.ccint_en = 1;
1616 + cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG034(pcie_port),
1617 + pciercx_cfg034.u32);
1621 + * Initialize a host mode PCIe link. This function takes a PCIe
1622 + * port from reset to a link up state. Software can then begin
1623 + * configuring the rest of the link.
1625 + * @pcie_port: PCIe port to initialize
1627 + * Returns Zero on success
1629 +static int __cvmx_pcie_rc_initialize_link(int pcie_port)
1631 + uint64_t start_cycle;
1632 + union cvmx_pescx_ctl_status pescx_ctl_status;
1633 + union cvmx_pciercx_cfg452 pciercx_cfg452;
1634 + union cvmx_pciercx_cfg032 pciercx_cfg032;
1635 + union cvmx_pciercx_cfg448 pciercx_cfg448;
1637 + /* Set the lane width */
1638 + pciercx_cfg452.u32 =
1639 + cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG452(pcie_port));
1640 + pescx_ctl_status.u64 = cvmx_read_csr(CVMX_PESCX_CTL_STATUS(pcie_port));
1641 + if (pescx_ctl_status.s.qlm_cfg == 0) {
1642 + /* We're in 8 lane (56XX) or 4 lane (54XX) mode */
1643 + pciercx_cfg452.s.lme = 0xf;
1645 + /* We're in 4 lane (56XX) or 2 lane (52XX) mode */
1646 + pciercx_cfg452.s.lme = 0x7;
1648 + cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG452(pcie_port),
1649 + pciercx_cfg452.u32);
1652 + * CN52XX pass 1.x has an errata where length mismatches on UR
1653 + * responses can cause bus errors on 64bit memory
1654 + * reads. Turning off length error checking fixes this.
1656 + if (OCTEON_IS_MODEL(OCTEON_CN52XX_PASS1_X)) {
1657 + union cvmx_pciercx_cfg455 pciercx_cfg455;
1658 + pciercx_cfg455.u32 =
1659 + cvmx_pcie_cfgx_read(pcie_port,
1660 + CVMX_PCIERCX_CFG455(pcie_port));
1661 + pciercx_cfg455.s.m_cpl_len_err = 1;
1662 + cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG455(pcie_port),
1663 + pciercx_cfg455.u32);
1666 + /* Lane swap needs to be manually enabled for CN52XX */
1667 + if (OCTEON_IS_MODEL(OCTEON_CN52XX) && (pcie_port == 1)) {
1668 + pescx_ctl_status.s.lane_swp = 1;
1669 + cvmx_write_csr(CVMX_PESCX_CTL_STATUS(pcie_port),
1670 + pescx_ctl_status.u64);
1673 + /* Bring up the link */
1674 + pescx_ctl_status.u64 = cvmx_read_csr(CVMX_PESCX_CTL_STATUS(pcie_port));
1675 + pescx_ctl_status.s.lnk_enb = 1;
1676 + cvmx_write_csr(CVMX_PESCX_CTL_STATUS(pcie_port), pescx_ctl_status.u64);
1679 + * CN52XX pass 1.0: Due to a bug in 2nd order CDR, it needs to
1682 + if (OCTEON_IS_MODEL(OCTEON_CN52XX_PASS1_0))
1683 + __cvmx_helper_errata_qlm_disable_2nd_order_cdr(0);
1685 + /* Wait for the link to come up */
1686 + cvmx_dprintf("PCIe: Waiting for port %d link\n", pcie_port);
1687 + start_cycle = cvmx_get_cycle();
1689 + if (cvmx_get_cycle() - start_cycle >
1690 + 2 * cvmx_sysinfo_get()->cpu_clock_hz) {
1691 + cvmx_dprintf("PCIe: Port %d link timeout\n",
1696 + pciercx_cfg032.u32 =
1697 + cvmx_pcie_cfgx_read(pcie_port,
1698 + CVMX_PCIERCX_CFG032(pcie_port));
1699 + } while (pciercx_cfg032.s.dlla == 0);
1701 + /* Display the link status */
1702 + cvmx_dprintf("PCIe: Port %d link active, %d lanes\n", pcie_port,
1703 + pciercx_cfg032.s.nlw);
1706 + * Update the Replay Time Limit. Empirically, some PCIe
1707 + * devices take a little longer to respond than expected under
1708 + * load. As a workaround for this we configure the Replay Time
1709 + * Limit to the value expected for a 512 byte MPS instead of
1710 + * our actual 256 byte MPS. The numbers below are directly
1711 + * from the PCIe spec table 3-4.
1713 + pciercx_cfg448.u32 =
1714 + cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG448(pcie_port));
1715 + switch (pciercx_cfg032.s.nlw) {
1716 + case 1: /* 1 lane */
1717 + pciercx_cfg448.s.rtl = 1677;
1719 + case 2: /* 2 lanes */
1720 + pciercx_cfg448.s.rtl = 867;
1722 + case 4: /* 4 lanes */
1723 + pciercx_cfg448.s.rtl = 462;
1725 + case 8: /* 8 lanes */
1726 + pciercx_cfg448.s.rtl = 258;
1729 + cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG448(pcie_port),
1730 + pciercx_cfg448.u32);
1736 + * Initialize a PCIe port for use in host(RC) mode. It doesn't
1737 + * enumerate the bus.
1739 + * @pcie_port: PCIe port to initialize
1741 + * Returns Zero on success
1743 +int cvmx_pcie_rc_initialize(int pcie_port)
1746 + union cvmx_ciu_soft_prst ciu_soft_prst;
1747 + union cvmx_pescx_bist_status pescx_bist_status;
1748 + union cvmx_pescx_bist_status2 pescx_bist_status2;
1749 + union cvmx_npei_ctl_status npei_ctl_status;
1750 + union cvmx_npei_mem_access_ctl npei_mem_access_ctl;
1751 + union cvmx_npei_mem_access_subidx mem_access_subid;
1752 + union cvmx_npei_dbg_data npei_dbg_data;
1753 + union cvmx_pescx_ctl_status2 pescx_ctl_status2;
1756 + * Make sure we aren't trying to setup a target mode interface
1759 + npei_ctl_status.u64 = cvmx_read_csr(CVMX_PEXP_NPEI_CTL_STATUS);
1760 + if ((pcie_port == 0) && !npei_ctl_status.s.host_mode) {
1761 + cvmx_dprintf("PCIe: ERROR: cvmx_pcie_rc_initialize() called "
1762 + "on port0, but port0 is not in host mode\n");
1767 + * Make sure a CN52XX isn't trying to bring up port 1 when it
1770 + if (OCTEON_IS_MODEL(OCTEON_CN52XX)) {
1771 + npei_dbg_data.u64 = cvmx_read_csr(CVMX_PEXP_NPEI_DBG_DATA);
1772 + if ((pcie_port == 1) && npei_dbg_data.cn52xx.qlm0_link_width) {
1773 + cvmx_dprintf("PCIe: ERROR: cvmx_pcie_rc_initialize() "
1774 + "called on port1, but port1 is disabled\n");
1780 + * PCIe switch arbitration mode. '0' == fixed priority NPEI,
1781 + * PCIe0, then PCIe1. '1' == round robin.
1783 + npei_ctl_status.s.arb = 1;
1784 + /* Allow up to 0x20 config retries */
1785 + npei_ctl_status.s.cfg_rtry = 0x20;
1787 + * CN52XX pass1.x has an errata where P0_NTAGS and P1_NTAGS
1790 + if (OCTEON_IS_MODEL(OCTEON_CN52XX_PASS1_X)) {
1791 + npei_ctl_status.s.p0_ntags = 0x20;
1792 + npei_ctl_status.s.p1_ntags = 0x20;
1794 + cvmx_write_csr(CVMX_PEXP_NPEI_CTL_STATUS, npei_ctl_status.u64);
1796 + /* Bring the PCIe out of reset */
1797 + if (cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_EBH5200) {
1799 + * The EBH5200 board swapped the PCIe reset lines on
1800 + * the board. As a workaround for this bug, we bring
1801 + * both PCIe ports out of reset at the same time
1802 + * instead of on separate calls. So for port 0, we
1803 + * bring both out of reset and do nothing on port 1.
1805 + if (pcie_port == 0) {
1806 + ciu_soft_prst.u64 = cvmx_read_csr(CVMX_CIU_SOFT_PRST);
1808 + * After a chip reset the PCIe will also be in
1809 + * reset. If it isn't, most likely someone is
1810 + * trying to init it again without a proper
1813 + if (ciu_soft_prst.s.soft_prst == 0) {
1814 + /* Reset the ports */
1815 + ciu_soft_prst.s.soft_prst = 1;
1816 + cvmx_write_csr(CVMX_CIU_SOFT_PRST,
1817 + ciu_soft_prst.u64);
1818 + ciu_soft_prst.u64 =
1819 + cvmx_read_csr(CVMX_CIU_SOFT_PRST1);
1820 + ciu_soft_prst.s.soft_prst = 1;
1821 + cvmx_write_csr(CVMX_CIU_SOFT_PRST1,
1822 + ciu_soft_prst.u64);
1823 + /* Wait until pcie resets the ports. */
1826 + ciu_soft_prst.u64 = cvmx_read_csr(CVMX_CIU_SOFT_PRST1);
1827 + ciu_soft_prst.s.soft_prst = 0;
1828 + cvmx_write_csr(CVMX_CIU_SOFT_PRST1, ciu_soft_prst.u64);
1829 + ciu_soft_prst.u64 = cvmx_read_csr(CVMX_CIU_SOFT_PRST);
1830 + ciu_soft_prst.s.soft_prst = 0;
1831 + cvmx_write_csr(CVMX_CIU_SOFT_PRST, ciu_soft_prst.u64);
1835 + * The normal case: The PCIe ports are completely
1836 + * separate and can be brought out of reset
1840 + ciu_soft_prst.u64 = cvmx_read_csr(CVMX_CIU_SOFT_PRST1);
1842 + ciu_soft_prst.u64 = cvmx_read_csr(CVMX_CIU_SOFT_PRST);
1844 + * After a chip reset the PCIe will also be in
1845 + * reset. If it isn't, most likely someone is trying
1846 + * to init it again without a proper PCIe reset.
1848 + if (ciu_soft_prst.s.soft_prst == 0) {
1849 + /* Reset the port */
1850 + ciu_soft_prst.s.soft_prst = 1;
1852 + cvmx_write_csr(CVMX_CIU_SOFT_PRST1,
1853 + ciu_soft_prst.u64);
1855 + cvmx_write_csr(CVMX_CIU_SOFT_PRST,
1856 + ciu_soft_prst.u64);
1857 + /* Wait until pcie resets the ports. */
1861 + ciu_soft_prst.u64 = cvmx_read_csr(CVMX_CIU_SOFT_PRST1);
1862 + ciu_soft_prst.s.soft_prst = 0;
1863 + cvmx_write_csr(CVMX_CIU_SOFT_PRST1, ciu_soft_prst.u64);
1865 + ciu_soft_prst.u64 = cvmx_read_csr(CVMX_CIU_SOFT_PRST);
1866 + ciu_soft_prst.s.soft_prst = 0;
1867 + cvmx_write_csr(CVMX_CIU_SOFT_PRST, ciu_soft_prst.u64);
1872 + * Wait for PCIe reset to complete. Due to errata PCIE-700, we
1873 + * don't poll PESCX_CTL_STATUS2[PCIERST], but simply wait a
1874 + * fixed number of cycles.
1876 + cvmx_wait(400000);
1878 + /* PESCX_BIST_STATUS2[PCLK_RUN] was missing on pass 1 of CN56XX and
1879 + CN52XX, so we only probe it on newer chips */
1880 + if (!OCTEON_IS_MODEL(OCTEON_CN56XX_PASS1_X)
1881 + && !OCTEON_IS_MODEL(OCTEON_CN52XX_PASS1_X)) {
1882 + /* Clear PCLK_RUN so we can check if the clock is running */
1883 + pescx_ctl_status2.u64 =
1884 + cvmx_read_csr(CVMX_PESCX_CTL_STATUS2(pcie_port));
1885 + pescx_ctl_status2.s.pclk_run = 1;
1886 + cvmx_write_csr(CVMX_PESCX_CTL_STATUS2(pcie_port),
1887 + pescx_ctl_status2.u64);
1889 + * Now that we cleared PCLK_RUN, wait for it to be set
1890 + * again telling us the clock is running.
1892 + if (CVMX_WAIT_FOR_FIELD64(CVMX_PESCX_CTL_STATUS2(pcie_port),
1893 + union cvmx_pescx_ctl_status2,
1894 + pclk_run, ==, 1, 10000)) {
1895 + cvmx_dprintf("PCIe: Port %d isn't clocked, skipping.\n",
1902 + * Check and make sure PCIe came out of reset. If it doesn't
1903 + * the board probably hasn't wired the clocks up and the
1904 + * interface should be skipped.
1906 + pescx_ctl_status2.u64 =
1907 + cvmx_read_csr(CVMX_PESCX_CTL_STATUS2(pcie_port));
1908 + if (pescx_ctl_status2.s.pcierst) {
1909 + cvmx_dprintf("PCIe: Port %d stuck in reset, skipping.\n",
1915 + * Check BIST2 status. If any bits are set skip this interface. This
1916 + * is an attempt to catch PCIE-813 on pass 1 parts.
1918 + pescx_bist_status2.u64 =
1919 + cvmx_read_csr(CVMX_PESCX_BIST_STATUS2(pcie_port));
1920 + if (pescx_bist_status2.u64) {
1921 + cvmx_dprintf("PCIe: Port %d BIST2 failed. Most likely this "
1922 + "port isn't hooked up, skipping.\n",
1927 + /* Check BIST status */
1928 + pescx_bist_status.u64 =
1929 + cvmx_read_csr(CVMX_PESCX_BIST_STATUS(pcie_port));
1930 + if (pescx_bist_status.u64)
1931 + cvmx_dprintf("PCIe: BIST FAILED for port %d (0x%016llx)\n",
1932 + pcie_port, CAST64(pescx_bist_status.u64));
1934 + /* Initialize the config space CSRs */
1935 + __cvmx_pcie_rc_initialize_config_space(pcie_port);
1937 + /* Bring the link up */
1938 + if (__cvmx_pcie_rc_initialize_link(pcie_port)) {
1940 + ("PCIe: ERROR: cvmx_pcie_rc_initialize_link() failed\n");
1944 + /* Store merge control (NPEI_MEM_ACCESS_CTL[TIMER,MAX_WORD]) */
1945 + npei_mem_access_ctl.u64 = cvmx_read_csr(CVMX_PEXP_NPEI_MEM_ACCESS_CTL);
1946 + /* Allow 16 words to combine */
1947 + npei_mem_access_ctl.s.max_word = 0;
1948 + /* Wait up to 127 cycles for more data */
1949 + npei_mem_access_ctl.s.timer = 127;
1950 + cvmx_write_csr(CVMX_PEXP_NPEI_MEM_ACCESS_CTL, npei_mem_access_ctl.u64);
1952 + /* Setup Mem access SubDIDs */
1953 + mem_access_subid.u64 = 0;
1954 + /* Port the request is sent to. */
1955 + mem_access_subid.s.port = pcie_port;
1956 + /* Due to an errata on pass 1 chips, no merging is allowed. */
1957 + mem_access_subid.s.nmerge = 1;
1958 + /* Endian-swap for Reads. */
1959 + mem_access_subid.s.esr = 1;
1960 + /* Endian-swap for Writes. */
1961 + mem_access_subid.s.esw = 1;
1962 + /* No Snoop for Reads. */
1963 + mem_access_subid.s.nsr = 1;
1964 + /* No Snoop for Writes. */
1965 + mem_access_subid.s.nsw = 1;
1966 + /* Disable Relaxed Ordering for Reads. */
1967 + mem_access_subid.s.ror = 0;
1968 + /* Disable Relaxed Ordering for Writes. */
1969 + mem_access_subid.s.row = 0;
1970 + /* PCIe Adddress Bits <63:34>. */
1971 + mem_access_subid.s.ba = 0;
1974 + * Setup mem access 12-15 for port 0, 16-19 for port 1,
1975 + * supplying 36 bits of address space.
1977 + for (i = 12 + pcie_port * 4; i < 16 + pcie_port * 4; i++) {
1978 + cvmx_write_csr(CVMX_PEXP_NPEI_MEM_ACCESS_SUBIDX(i),
1979 + mem_access_subid.u64);
1980 + /* Set each SUBID to extend the addressable range */
1981 + mem_access_subid.s.ba += 1;
1985 + * Disable the peer to peer forwarding register. This must be
1986 + * setup by the OS after it enumerates the bus and assigns
1987 + * addresses to the PCIe busses.
1989 + for (i = 0; i < 4; i++) {
1990 + cvmx_write_csr(CVMX_PESCX_P2P_BARX_START(i, pcie_port), -1);
1991 + cvmx_write_csr(CVMX_PESCX_P2P_BARX_END(i, pcie_port), -1);
1994 + /* Set Octeon's BAR0 to decode 0-16KB. It overlaps with Bar2 */
1995 + cvmx_write_csr(CVMX_PESCX_P2N_BAR0_START(pcie_port), 0);
1998 + * Disable Octeon's BAR1. It isn't needed in RC mode since
1999 + * BAR2 maps all of memory. BAR2 also maps 256MB-512MB into
2000 + * the 2nd 256MB of memory.
2002 + cvmx_write_csr(CVMX_PESCX_P2N_BAR1_START(pcie_port), -1);
2005 + * Set Octeon's BAR2 to decode 0-2^39. Bar0 and Bar1 take
2006 + * precedence where they overlap. It also overlaps with the
2007 + * device addresses, so make sure the peer to peer forwarding
2010 + cvmx_write_csr(CVMX_PESCX_P2N_BAR2_START(pcie_port), 0);
2013 + * Setup BAR2 attributes
2015 + * Relaxed Ordering (NPEI_CTL_PORTn[PTLP_RO,CTLP_RO, WAIT_COM])
2016 + * - PTLP_RO,CTLP_RO should normally be set (except for debug).
2017 + * - WAIT_COM=0 will likely work for all applications.
2019 + * Load completion relaxed ordering (NPEI_CTL_PORTn[WAITL_COM]).
2022 + union cvmx_npei_ctl_port1 npei_ctl_port;
2023 + npei_ctl_port.u64 = cvmx_read_csr(CVMX_PEXP_NPEI_CTL_PORT1);
2024 + npei_ctl_port.s.bar2_enb = 1;
2025 + npei_ctl_port.s.bar2_esx = 1;
2026 + npei_ctl_port.s.bar2_cax = 0;
2027 + npei_ctl_port.s.ptlp_ro = 1;
2028 + npei_ctl_port.s.ctlp_ro = 1;
2029 + npei_ctl_port.s.wait_com = 0;
2030 + npei_ctl_port.s.waitl_com = 0;
2031 + cvmx_write_csr(CVMX_PEXP_NPEI_CTL_PORT1, npei_ctl_port.u64);
2033 + union cvmx_npei_ctl_port0 npei_ctl_port;
2034 + npei_ctl_port.u64 = cvmx_read_csr(CVMX_PEXP_NPEI_CTL_PORT0);
2035 + npei_ctl_port.s.bar2_enb = 1;
2036 + npei_ctl_port.s.bar2_esx = 1;
2037 + npei_ctl_port.s.bar2_cax = 0;
2038 + npei_ctl_port.s.ptlp_ro = 1;
2039 + npei_ctl_port.s.ctlp_ro = 1;
2040 + npei_ctl_port.s.wait_com = 0;
2041 + npei_ctl_port.s.waitl_com = 0;
2042 + cvmx_write_csr(CVMX_PEXP_NPEI_CTL_PORT0, npei_ctl_port.u64);
2048 + * Shutdown a PCIe port and put it in reset
2050 + * @pcie_port: PCIe port to shutdown
2052 + * Returns Zero on success
2054 +int cvmx_pcie_rc_shutdown(int pcie_port)
2056 + /* Wait for all pending operations to complete */
2057 + if (CVMX_WAIT_FOR_FIELD64(CVMX_PESCX_CPL_LUT_VALID(pcie_port),
2058 + union cvmx_pescx_cpl_lut_valid,
2059 + tag, ==, 0, 2000))
2060 + cvmx_dprintf("PCIe: Port %d shutdown timeout\n", pcie_port);
2064 + union cvmx_ciu_soft_prst ciu_soft_prst;
2065 + ciu_soft_prst.u64 = cvmx_read_csr(CVMX_CIU_SOFT_PRST1);
2066 + ciu_soft_prst.s.soft_prst = 1;
2067 + cvmx_write_csr(CVMX_CIU_SOFT_PRST1, ciu_soft_prst.u64);
2069 + union cvmx_ciu_soft_prst ciu_soft_prst;
2070 + ciu_soft_prst.u64 = cvmx_read_csr(CVMX_CIU_SOFT_PRST);
2071 + ciu_soft_prst.s.soft_prst = 1;
2072 + cvmx_write_csr(CVMX_CIU_SOFT_PRST, ciu_soft_prst.u64);
2078 + * Build a PCIe config space request address for a device
2080 + * @pcie_port: PCIe port to access
2083 + * @fn: Device sub function
2084 + * @reg: Register to access
2086 + * Returns 64bit Octeon IO address
2088 +static inline uint64_t __cvmx_pcie_build_config_addr(int pcie_port, int bus,
2089 + int dev, int fn, int reg)
2091 + union cvmx_pcie_address pcie_addr;
2092 + union cvmx_pciercx_cfg006 pciercx_cfg006;
2094 + pciercx_cfg006.u32 =
2095 + cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG006(pcie_port));
2096 + if ((bus <= pciercx_cfg006.s.pbnum) && (dev != 0))
2099 + pcie_addr.u64 = 0;
2100 + pcie_addr.config.upper = 2;
2101 + pcie_addr.config.io = 1;
2102 + pcie_addr.config.did = 3;
2103 + pcie_addr.config.subdid = 1;
2104 + pcie_addr.config.es = 1;
2105 + pcie_addr.config.port = pcie_port;
2106 + pcie_addr.config.ty = (bus > pciercx_cfg006.s.pbnum);
2107 + pcie_addr.config.bus = bus;
2108 + pcie_addr.config.dev = dev;
2109 + pcie_addr.config.func = fn;
2110 + pcie_addr.config.reg = reg;
2111 + return pcie_addr.u64;
2115 + * Read 8bits from a Device's config space
2117 + * @pcie_port: PCIe port the device is on
2120 + * @fn: Device sub function
2121 + * @reg: Register to access
2123 + * Returns Result of the read
2125 +uint8_t cvmx_pcie_config_read8(int pcie_port, int bus, int dev,
2128 + uint64_t address =
2129 + __cvmx_pcie_build_config_addr(pcie_port, bus, dev, fn, reg);
2131 + return cvmx_read64_uint8(address);
2137 + * Read 16bits from a Device's config space
2139 + * @pcie_port: PCIe port the device is on
2142 + * @fn: Device sub function
2143 + * @reg: Register to access
2145 + * Returns Result of the read
2147 +uint16_t cvmx_pcie_config_read16(int pcie_port, int bus, int dev, int fn,
2150 + uint64_t address =
2151 + __cvmx_pcie_build_config_addr(pcie_port, bus, dev, fn, reg);
2153 + return le16_to_cpu(cvmx_read64_uint16(address));
2159 + * Read 32bits from a Device's config space
2161 + * @pcie_port: PCIe port the device is on
2164 + * @fn: Device sub function
2165 + * @reg: Register to access
2167 + * Returns Result of the read
2169 +uint32_t cvmx_pcie_config_read32(int pcie_port, int bus, int dev, int fn,
2172 + uint64_t address =
2173 + __cvmx_pcie_build_config_addr(pcie_port, bus, dev, fn, reg);
2175 + return le32_to_cpu(cvmx_read64_uint32(address));
2177 + return 0xffffffff;
2181 + * Write 8bits to a Device's config space
2183 + * @pcie_port: PCIe port the device is on
2186 + * @fn: Device sub function
2187 + * @reg: Register to access
2188 + * @val: Value to write
2190 +void cvmx_pcie_config_write8(int pcie_port, int bus, int dev, int fn,
2191 + int reg, uint8_t val)
2193 + uint64_t address =
2194 + __cvmx_pcie_build_config_addr(pcie_port, bus, dev, fn, reg);
2196 + cvmx_write64_uint8(address, val);
2200 + * Write 16bits to a Device's config space
2202 + * @pcie_port: PCIe port the device is on
2205 + * @fn: Device sub function
2206 + * @reg: Register to access
2207 + * @val: Value to write
2209 +void cvmx_pcie_config_write16(int pcie_port, int bus, int dev, int fn,
2210 + int reg, uint16_t val)
2212 + uint64_t address =
2213 + __cvmx_pcie_build_config_addr(pcie_port, bus, dev, fn, reg);
2215 + cvmx_write64_uint16(address, cpu_to_le16(val));
2219 + * Write 32bits to a Device's config space
2221 + * @pcie_port: PCIe port the device is on
2224 + * @fn: Device sub function
2225 + * @reg: Register to access
2226 + * @val: Value to write
2228 +void cvmx_pcie_config_write32(int pcie_port, int bus, int dev, int fn,
2229 + int reg, uint32_t val)
2231 + uint64_t address =
2232 + __cvmx_pcie_build_config_addr(pcie_port, bus, dev, fn, reg);
2234 + cvmx_write64_uint32(address, cpu_to_le32(val));
2238 + * Read a PCIe config space register indirectly. This is used for
2239 + * registers of the form PCIEEP_CFG??? and PCIERC?_CFG???.
2241 + * @pcie_port: PCIe port to read from
2242 + * @cfg_offset: Address to read
2244 + * Returns Value read
2246 +uint32_t cvmx_pcie_cfgx_read(int pcie_port, uint32_t cfg_offset)
2248 + union cvmx_pescx_cfg_rd pescx_cfg_rd;
2249 + pescx_cfg_rd.u64 = 0;
2250 + pescx_cfg_rd.s.addr = cfg_offset;
2251 + cvmx_write_csr(CVMX_PESCX_CFG_RD(pcie_port), pescx_cfg_rd.u64);
2252 + pescx_cfg_rd.u64 = cvmx_read_csr(CVMX_PESCX_CFG_RD(pcie_port));
2253 + return pescx_cfg_rd.s.data;
2257 + * Write a PCIe config space register indirectly. This is used for
2258 + * registers of the form PCIEEP_CFG??? and PCIERC?_CFG???.
2260 + * @pcie_port: PCIe port to write to
2261 + * @cfg_offset: Address to write
2262 + * @val: Value to write
2264 +void cvmx_pcie_cfgx_write(int pcie_port, uint32_t cfg_offset, uint32_t val)
2266 + union cvmx_pescx_cfg_wr pescx_cfg_wr;
2267 + pescx_cfg_wr.u64 = 0;
2268 + pescx_cfg_wr.s.addr = cfg_offset;
2269 + pescx_cfg_wr.s.data = val;
2270 + cvmx_write_csr(CVMX_PESCX_CFG_WR(pcie_port), pescx_cfg_wr.u64);
2274 + * Initialize a PCIe port for use in target(EP) mode.
2276 + * Returns Zero on success
2278 +int cvmx_pcie_ep_initialize(void)
2280 + int pcie_port = 0;
2281 + union cvmx_npei_ctl_status npei_ctl_status;
2282 + union cvmx_pciercx_cfg030 pciercx_cfg030;
2283 + union cvmx_npei_ctl_status2 npei_ctl_status2;
2284 + union cvmx_npei_mem_access_subidx mem_access_subid;
2286 + npei_ctl_status.u64 = cvmx_read_csr(CVMX_PEXP_NPEI_CTL_STATUS);
2287 + if (npei_ctl_status.s.host_mode)
2290 + /* Enable bus master and memory */
2291 + cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIEEP_CFG001, 0x6);
2294 + * Max Payload Size (PCIE*_CFG030[MPS])
2295 + * Max Read Request Size (PCIE*_CFG030[MRRS])
2296 + * Relaxed-order, no-snoop enables (PCIE*_CFG030[RO_EN,NS_EN]
2297 + * Error Message Enables (PCIE*_CFG030[CE_EN,NFE_EN,FE_EN,UR_EN])
2299 + pciercx_cfg030.u32 =
2300 + cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG030(pcie_port));
2301 + /* Max payload size = 128 bytes (Limit of most PCs) */
2302 + pciercx_cfg030.s.mps = 0;
2304 + * Max read request size = 128 bytes for best Octeon DMA
2307 + pciercx_cfg030.s.mrrs = 0;
2308 + /* Enable relaxed ordering. */
2309 + pciercx_cfg030.s.ro_en = 1;
2310 + /* Enable no snoop. */
2311 + pciercx_cfg030.s.ns_en = 1;
2312 + /* Correctable error reporting enable. */
2313 + pciercx_cfg030.s.ce_en = 1;
2314 + /* Non-fatal error reporting enable. */
2315 + pciercx_cfg030.s.nfe_en = 1;
2316 + /* Fatal error reporting enable. */
2317 + pciercx_cfg030.s.fe_en = 1;
2318 + /* Unsupported request reporting enable. */
2319 + pciercx_cfg030.s.ur_en = 1;
2320 + cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG030(pcie_port),
2321 + pciercx_cfg030.u32);
2324 + * Max Payload Size (NPEI_CTL_STATUS2[MPS]) must match
2325 + * PCIE*_CFG030[MPS]
2327 + * Max Read Request Size (NPEI_CTL_STATUS2[MRRS]) must not
2328 + * exceed PCIE*_CFG030[MRRS]
2330 + npei_ctl_status2.u64 = cvmx_read_csr(CVMX_PEXP_NPEI_CTL_STATUS2);
2331 + /* Max payload size = 128 bytes (Limit of most PCs) */
2332 + npei_ctl_status2.s.mps = 0;
2333 + /* Max read request size = 128 bytes for best Octeon DMA performance */
2334 + npei_ctl_status2.s.mrrs = 0;
2335 + cvmx_write_csr(CVMX_PEXP_NPEI_CTL_STATUS2, npei_ctl_status2.u64);
2337 + /* Setup Mem access SubDID 12 to access Host memory */
2338 + mem_access_subid.u64 = 0;
2339 + /* Port the request is sent to. */
2340 + mem_access_subid.s.port = pcie_port;
2341 + /* Merging is allowed in this window. */
2342 + mem_access_subid.s.nmerge = 1;
2343 + /* Endian-swap for Reads. */
2344 + mem_access_subid.s.esr = 0;
2345 + /* Endian-swap for Writes. */
2346 + mem_access_subid.s.esw = 0;
2347 + /* No Snoop for Reads. */
2348 + mem_access_subid.s.nsr = 1;
2349 + /* No Snoop for Writes. */
2350 + mem_access_subid.s.nsw = 1;
2351 + /* Disable Relaxed Ordering for Reads. */
2352 + mem_access_subid.s.ror = 0;
2353 + /* Disable Relaxed Ordering for Writes. */
2354 + mem_access_subid.s.row = 0;
2355 + /* PCIe Adddress Bits <63:34>. */
2356 + mem_access_subid.s.ba = 0;
2357 + cvmx_write_csr(CVMX_PEXP_NPEI_MEM_ACCESS_SUBIDX(12),
2358 + mem_access_subid.u64);
2361 diff --git a/arch/mips/cavium-octeon/msi.c b/arch/mips/cavium-octeon/msi.c
2362 new file mode 100644
2363 index 0000000..964b03b
2365 +++ b/arch/mips/cavium-octeon/msi.c
2368 + * This file is subject to the terms and conditions of the GNU General Public
2369 + * License. See the file "COPYING" in the main directory of this archive
2370 + * for more details.
2372 + * Copyright (C) 2005-2007 Cavium Networks
2374 +#include <linux/kernel.h>
2375 +#include <linux/init.h>
2376 +#include <linux/msi.h>
2377 +#include <linux/spinlock.h>
2378 +#include <linux/interrupt.h>
2380 +#include <asm/octeon/octeon.h>
2381 +#include <asm/octeon/cvmx-npi-defs.h>
2382 +#include <asm/octeon/cvmx-pci-defs.h>
2383 +#include <asm/octeon/cvmx-npei-defs.h>
2384 +#include <asm/octeon/cvmx-pexp-defs.h>
2386 +#include "pci-common.h"
2389 + * Each bit in msi_free_irq_bitmask represents a MSI interrupt that is
2392 +static uint64_t msi_free_irq_bitmask;
2395 + * Each bit in msi_multiple_irq_bitmask tells that the device using
2396 + * this bit in msi_free_irq_bitmask is also using the next bit. This
2397 + * is used so we can disable all of the MSI interrupts when a device
2400 +static uint64_t msi_multiple_irq_bitmask;
2403 + * This lock controls updates to msi_free_irq_bitmask and
2404 + * msi_multiple_irq_bitmask.
2406 +static DEFINE_SPINLOCK(msi_free_irq_bitmask_lock);
2410 + * Called when a driver request MSI interrupts instead of the
2411 + * legacy INT A-D. This routine will allocate multiple interrupts
2412 + * for MSI devices that support them. A device can override this by
2413 + * programming the MSI control bits [6:4] before calling
2414 + * pci_enable_msi().
2416 + * @param dev Device requesting MSI interrupts
2417 + * @param desc MSI descriptor
2419 + * Returns 0 on success.
2421 +int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc)
2423 + struct msi_msg msg;
2425 + int configured_private_bits;
2426 + int request_private_bits;
2429 + uint64_t search_mask;
2432 + * Read the MSI config to figure out how many IRQs this device
2433 + * wants. Most devices only want 1, which will give
2434 + * configured_private_bits and request_private_bits equal 0.
2436 + pci_read_config_word(dev, desc->msi_attrib.pos + PCI_MSI_FLAGS,
2440 + * If the number of private bits has been configured then use
2441 + * that value instead of the requested number. This gives the
2442 + * driver the chance to override the number of interrupts
2443 + * before calling pci_enable_msi().
2445 + configured_private_bits = (control & PCI_MSI_FLAGS_QSIZE) >> 4;
2446 + if (configured_private_bits == 0) {
2447 + /* Nothing is configured, so use the hardware requested size */
2448 + request_private_bits = (control & PCI_MSI_FLAGS_QMASK) >> 1;
2451 + * Use the number of configured bits, assuming the
2452 + * driver wanted to override the hardware request
2455 + request_private_bits = configured_private_bits;
2459 + * The PCI 2.3 spec mandates that there are at most 32
2460 + * interrupts. If this device asks for more, only give it one.
2462 + if (request_private_bits > 5)
2463 + request_private_bits = 0;
2467 + * The IRQs have to be aligned on a power of two based on the
2468 + * number being requested.
2470 + irq_step = 1 << request_private_bits;
2472 + /* Mask with one bit for each IRQ */
2473 + search_mask = (1 << irq_step) - 1;
2476 + * We're going to search msi_free_irq_bitmask_lock for zero
2477 + * bits. This represents an MSI interrupt number that isn't in
2480 + spin_lock(&msi_free_irq_bitmask_lock);
2481 + for (irq = 0; irq < 64; irq += irq_step) {
2482 + if ((msi_free_irq_bitmask & (search_mask << irq)) == 0) {
2483 + msi_free_irq_bitmask |= search_mask << irq;
2484 + msi_multiple_irq_bitmask |= (search_mask >> 1) << irq;
2488 + spin_unlock(&msi_free_irq_bitmask_lock);
2490 + /* Make sure the search for available interrupts didn't fail */
2492 + if (request_private_bits) {
2493 + pr_err("arch_setup_msi_irq: Unable to find %d free "
2494 + "interrupts, trying just one",
2495 + 1 << request_private_bits);
2496 + request_private_bits = 0;
2497 + goto try_only_one;
2499 + panic("arch_setup_msi_irq: Unable to find a free MSI "
2503 + /* MSI interrupts start at logical IRQ OCTEON_IRQ_MSI_BIT0 */
2504 + irq += OCTEON_IRQ_MSI_BIT0;
2506 + switch (octeon_dma_bar_type) {
2507 + case OCTEON_DMA_BAR_TYPE_SMALL:
2508 + /* When not using big bar, Bar 0 is based at 128MB */
2510 + ((128ul << 20) + CVMX_PCI_MSI_RCV) & 0xffffffff;
2511 + msg.address_hi = ((128ul << 20) + CVMX_PCI_MSI_RCV) >> 32;
2512 + case OCTEON_DMA_BAR_TYPE_BIG:
2513 + /* When using big bar, Bar 0 is based at 0 */
2514 + msg.address_lo = (0 + CVMX_PCI_MSI_RCV) & 0xffffffff;
2515 + msg.address_hi = (0 + CVMX_PCI_MSI_RCV) >> 32;
2517 + case OCTEON_DMA_BAR_TYPE_PCIE:
2518 + /* When using PCIe, Bar 0 is based at 0 */
2519 + /* FIXME CVMX_NPEI_MSI_RCV* other than 0? */
2520 + msg.address_lo = (0 + CVMX_NPEI_PCIE_MSI_RCV) & 0xffffffff;
2521 + msg.address_hi = (0 + CVMX_NPEI_PCIE_MSI_RCV) >> 32;
2524 + panic("arch_setup_msi_irq: Invalid octeon_dma_bar_type\n");
2526 + msg.data = irq - OCTEON_IRQ_MSI_BIT0;
2528 + /* Update the number of IRQs the device has available to it */
2529 + control &= ~PCI_MSI_FLAGS_QSIZE;
2530 + control |= request_private_bits << 4;
2531 + pci_write_config_word(dev, desc->msi_attrib.pos + PCI_MSI_FLAGS,
2534 + set_irq_msi(irq, desc);
2535 + write_msi_msg(irq, &msg);
2541 + * Called when a device no longer needs its MSI interrupts. All
2542 + * MSI interrupts for the device are freed.
2544 + * @irq: The devices first irq number. There may be multple in sequence.
2546 +void arch_teardown_msi_irq(unsigned int irq)
2551 + if ((irq < OCTEON_IRQ_MSI_BIT0) || (irq > OCTEON_IRQ_MSI_BIT63))
2552 + panic("arch_teardown_msi_irq: Attempted to teardown illegal "
2553 + "MSI interrupt (%d)", irq);
2554 + irq -= OCTEON_IRQ_MSI_BIT0;
2557 + * Count the number of IRQs we need to free by looking at the
2558 + * msi_multiple_irq_bitmask. Each bit set means that the next
2559 + * IRQ is also owned by this device.
2562 + while ((irq+number_irqs < 64) &&
2563 + (msi_multiple_irq_bitmask & (1ull << (irq + number_irqs))))
2566 + /* Mask with one bit for each IRQ */
2567 + bitmask = (1 << number_irqs) - 1;
2568 + /* Shift the mask to the correct bit location */
2570 + if ((msi_free_irq_bitmask & bitmask) != bitmask)
2571 + panic("arch_teardown_msi_irq: Attempted to teardown MSI "
2572 + "interrupt (%d) not in use", irq);
2574 + /* Checks are done, update the in use bitmask */
2575 + spin_lock(&msi_free_irq_bitmask_lock);
2576 + msi_free_irq_bitmask &= ~bitmask;
2577 + msi_multiple_irq_bitmask &= ~bitmask;
2578 + spin_unlock(&msi_free_irq_bitmask_lock);
2583 + * Called by the interrupt handling code when an MSI interrupt
2591 +static irqreturn_t octeon_msi_interrupt(int cpl, void *dev_id)
2593 + uint64_t msi_bits;
2596 + if (octeon_dma_bar_type == OCTEON_DMA_BAR_TYPE_PCIE)
2597 + msi_bits = cvmx_read_csr(CVMX_PEXP_NPEI_MSI_RCV0);
2599 + msi_bits = cvmx_read_csr(CVMX_NPI_NPI_MSI_RCV);
2600 + irq = fls64(msi_bits);
2602 + irq += OCTEON_IRQ_MSI_BIT0 - 1;
2603 + if (irq_desc[irq].action) {
2605 + return IRQ_HANDLED;
2607 + pr_err("Spurious MSI interrupt %d\n", irq);
2608 + if (octeon_has_feature(OCTEON_FEATURE_PCIE)) {
2609 + /* These chips have PCIe */
2610 + cvmx_write_csr(CVMX_PEXP_NPEI_MSI_RCV0,
2612 + OCTEON_IRQ_MSI_BIT0));
2614 + /* These chips have PCI */
2615 + cvmx_write_csr(CVMX_NPI_NPI_MSI_RCV,
2617 + OCTEON_IRQ_MSI_BIT0));
2626 + * Initializes the MSI interrupt handling code
2630 +int octeon_msi_initialize(void)
2633 + if (octeon_has_feature(OCTEON_FEATURE_PCIE)) {
2634 + r = request_irq(OCTEON_IRQ_PCI_MSI0, octeon_msi_interrupt,
2636 + "MSI[0:63]", octeon_msi_interrupt);
2637 + } else if (octeon_is_pci_host()) {
2638 + r = request_irq(OCTEON_IRQ_PCI_MSI0, octeon_msi_interrupt,
2640 + "MSI[0:15]", octeon_msi_interrupt);
2641 + r += request_irq(OCTEON_IRQ_PCI_MSI1, octeon_msi_interrupt,
2643 + "MSI[16:31]", octeon_msi_interrupt);
2644 + r += request_irq(OCTEON_IRQ_PCI_MSI2, octeon_msi_interrupt,
2646 + "MSI[32:47]", octeon_msi_interrupt);
2647 + r += request_irq(OCTEON_IRQ_PCI_MSI3, octeon_msi_interrupt,
2649 + "MSI[48:63]", octeon_msi_interrupt);
2654 +subsys_initcall(octeon_msi_initialize);
2655 diff --git a/arch/mips/cavium-octeon/octeon-irq.c b/arch/mips/cavium-octeon/octeon-irq.c
2656 index 788d588..3d7be84 100644
2657 --- a/arch/mips/cavium-octeon/octeon-irq.c
2658 +++ b/arch/mips/cavium-octeon/octeon-irq.c
2660 #include <linux/hardirq.h>
2662 #include <asm/octeon/octeon.h>
2663 +#include <asm/octeon/cvmx-pexp-defs.h>
2664 +#include <asm/octeon/cvmx-npi-defs.h>
2666 DEFINE_RWLOCK(octeon_irq_ciu0_rwlock);
2667 DEFINE_RWLOCK(octeon_irq_ciu1_rwlock);
2668 diff --git a/arch/mips/cavium-octeon/pci-common.c b/arch/mips/cavium-octeon/pci-common.c
2669 new file mode 100644
2670 index 0000000..cd029f8
2672 +++ b/arch/mips/cavium-octeon/pci-common.c
2675 + * This file is subject to the terms and conditions of the GNU General Public
2676 + * License. See the file "COPYING" in the main directory of this archive
2677 + * for more details.
2679 + * Copyright (C) 2005-2007 Cavium Networks
2681 +#include <linux/kernel.h>
2682 +#include <linux/init.h>
2683 +#include <linux/pci.h>
2684 +#include <linux/interrupt.h>
2685 +#include <linux/time.h>
2686 +#include <linux/delay.h>
2687 +#include "pci-common.h"
2689 +typeof(pcibios_map_irq) *octeon_pcibios_map_irq;
2690 +enum octeon_dma_bar_type octeon_dma_bar_type = OCTEON_DMA_BAR_TYPE_INVALID;
2693 + * Map a PCI device to the appropriate interrupt line
2695 + * @param dev The Linux PCI device structure for the device to map
2696 + * @param slot The slot number for this device on __BUS 0__. Linux
2697 + * enumerates through all the bridges and figures out the
2698 + * slot on Bus 0 where this device eventually hooks to.
2699 + * @param pin The PCI interrupt pin read from the device, then swizzled
2700 + * as it goes through each bridge.
2701 + * @return Interrupt number for the device
2703 +int __init pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
2705 + if (octeon_pcibios_map_irq)
2706 + return octeon_pcibios_map_irq(dev, slot, pin);
2708 + panic("octeon_pcibios_map_irq doesn't point to a "
2709 + "pcibios_map_irq() function");
2714 + * Called to perform platform specific PCI setup
2719 +int pcibios_plat_dev_init(struct pci_dev *dev)
2725 + * Force the Cache line setting to 64 bytes. The standard
2726 + * Linux bus scan doesn't seem to set it. Octeon really has
2727 + * 128 byte lines, but Intel bridges get really upset if you
2728 + * try and set values above 64 bytes. Value is specified in
2731 + pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, 64 / 4);
2732 + /* Set latency timers for all devices */
2733 + pci_write_config_byte(dev, PCI_LATENCY_TIMER, 48);
2735 + /* Enable reporting System errors and parity errors on all devices */
2736 + /* Enable parity checking and error reporting */
2737 + pci_read_config_word(dev, PCI_COMMAND, &config);
2738 + config |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
2739 + pci_write_config_word(dev, PCI_COMMAND, config);
2741 + if (dev->subordinate) {
2742 + /* Set latency timers on sub bridges */
2743 + pci_write_config_byte(dev, PCI_SEC_LATENCY_TIMER, 48);
2744 + /* More bridge error detection */
2745 + pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &config);
2746 + config |= PCI_BRIDGE_CTL_PARITY | PCI_BRIDGE_CTL_SERR;
2747 + pci_write_config_word(dev, PCI_BRIDGE_CONTROL, config);
2750 + /* Enable the PCIe normal error reporting */
2751 + pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
2753 + /* Update Device Control */
2754 + pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &config);
2755 + /* Correctable Error Reporting */
2756 + config |= PCI_EXP_DEVCTL_CERE;
2757 + /* Non-Fatal Error Reporting */
2758 + config |= PCI_EXP_DEVCTL_NFERE;
2759 + /* Fatal Error Reporting */
2760 + config |= PCI_EXP_DEVCTL_FERE;
2761 + /* Unsupported Request */
2762 + config |= PCI_EXP_DEVCTL_URRE;
2763 + pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, config);
2766 + /* Find the Advanced Error Reporting capability */
2767 + pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
2769 + /* Clear Uncorrectable Error Status */
2770 + pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS,
2772 + pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS,
2774 + /* Enable reporting of all uncorrectable errors */
2775 + /* Uncorrectable Error Mask - turned on bits disable errors */
2776 + pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_MASK, 0);
2778 + * Leave severity at HW default. This only controls if
2779 + * errors are reported as uncorrectable or
2780 + * correctable, not if the error is reported.
2782 + /* PCI_ERR_UNCOR_SEVER - Uncorrectable Error Severity */
2783 + /* Clear Correctable Error Status */
2784 + pci_read_config_dword(dev, pos + PCI_ERR_COR_STATUS, &dconfig);
2785 + pci_write_config_dword(dev, pos + PCI_ERR_COR_STATUS, dconfig);
2786 + /* Enable reporting of all correctable errors */
2787 + /* Correctable Error Mask - turned on bits disable errors */
2788 + pci_write_config_dword(dev, pos + PCI_ERR_COR_MASK, 0);
2789 + /* Advanced Error Capabilities */
2790 + pci_read_config_dword(dev, pos + PCI_ERR_CAP, &dconfig);
2791 + /* ECRC Generation Enable */
2792 + if (config & PCI_ERR_CAP_ECRC_GENC)
2793 + config |= PCI_ERR_CAP_ECRC_GENE;
2794 + /* ECRC Check Enable */
2795 + if (config & PCI_ERR_CAP_ECRC_CHKC)
2796 + config |= PCI_ERR_CAP_ECRC_CHKE;
2797 + pci_write_config_dword(dev, pos + PCI_ERR_CAP, dconfig);
2798 + /* PCI_ERR_HEADER_LOG - Header Log Register (16 bytes) */
2799 + /* Report all errors to the root complex */
2800 + pci_write_config_dword(dev, pos + PCI_ERR_ROOT_COMMAND,
2801 + PCI_ERR_ROOT_CMD_COR_EN |
2802 + PCI_ERR_ROOT_CMD_NONFATAL_EN |
2803 + PCI_ERR_ROOT_CMD_FATAL_EN);
2804 + /* Clear the Root status register */
2805 + pci_read_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, &dconfig);
2806 + pci_write_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, dconfig);
2811 diff --git a/arch/mips/cavium-octeon/pci-common.h b/arch/mips/cavium-octeon/pci-common.h
2812 new file mode 100644
2813 index 0000000..74ae799
2815 +++ b/arch/mips/cavium-octeon/pci-common.h
2818 + * This file is subject to the terms and conditions of the GNU General Public
2819 + * License. See the file "COPYING" in the main directory of this archive
2820 + * for more details.
2822 + * Copyright (C) 2005-2007 Cavium Networks
2824 +#ifndef __OCTEON_PCI_COMMON_H__
2825 +#define __OCTEON_PCI_COMMON_H__
2827 +#include <linux/pci.h>
2829 +/* Some PCI cards require delays when accessing config space. */
2830 +#define PCI_CONFIG_SPACE_DELAY 10000
2832 +/* pcibios_map_irq() is defined inside pci-common.c. All it does is call the
2833 + Octeon specific version pointed to by this variable. This function needs to
2834 + change for PCI or PCIe based hosts */
2835 +extern typeof(pcibios_map_irq) *octeon_pcibios_map_irq;
2837 +/* The following defines are only used when octeon_dma_bar_type =
2838 + OCTEON_DMA_BAR_TYPE_BIG */
2839 +#define OCTEON_PCI_BAR1_HOLE_BITS 5
2840 +#define OCTEON_PCI_BAR1_HOLE_SIZE (1ul<<(OCTEON_PCI_BAR1_HOLE_BITS+3))
2842 +enum octeon_dma_bar_type {
2843 + OCTEON_DMA_BAR_TYPE_INVALID,
2844 + OCTEON_DMA_BAR_TYPE_SMALL,
2845 + OCTEON_DMA_BAR_TYPE_BIG,
2846 + OCTEON_DMA_BAR_TYPE_PCIE
2850 + * This is a variable to tell the DMA mapping system in dma-octeon.c
2851 + * how to map PCI DMA addresses.
2853 +extern enum octeon_dma_bar_type octeon_dma_bar_type;
2856 diff --git a/arch/mips/cavium-octeon/pci.c b/arch/mips/cavium-octeon/pci.c
2857 new file mode 100644
2858 index 0000000..67c0ff5
2860 +++ b/arch/mips/cavium-octeon/pci.c
2863 + * This file is subject to the terms and conditions of the GNU General Public
2864 + * License. See the file "COPYING" in the main directory of this archive
2865 + * for more details.
2867 + * Copyright (C) 2005-2007 Cavium Networks
2869 +#include <linux/kernel.h>
2870 +#include <linux/init.h>
2871 +#include <linux/pci.h>
2872 +#include <linux/interrupt.h>
2873 +#include <linux/time.h>
2874 +#include <linux/delay.h>
2876 +#include <asm/time.h>
2878 +#include <asm/octeon/octeon.h>
2879 +#include <asm/octeon/cvmx-npi-defs.h>
2880 +#include <asm/octeon/cvmx-pci-defs.h>
2882 +#include "pci-common.h"
2884 +#define USE_OCTEON_INTERNAL_ARBITER
2887 + * Octeon's PCI controller uses did=3, subdid=2 for PCI IO
2888 + * addresses. Use PCI endian swapping 1 so no address swapping is
2889 + * necessary. The Linux io routines will endian swap the data.
2891 +#define OCTEON_PCI_IOSPACE_BASE 0x80011a0400000000ull
2892 +#define OCTEON_PCI_IOSPACE_SIZE (1ull<<32)
2894 +/* Octeon't PCI controller uses did=3, subdid=3 for PCI memory. */
2895 +#define OCTEON_PCI_MEMSPACE_OFFSET (0x00011b0000000000ull)
2898 + * This is the bit decoding used for the Octeon PCI controller addresses
2900 +union octeon_pci_address {
2904 + uint64_t reserved:13;
2907 + uint64_t subdid:3;
2908 + uint64_t reserved2:4;
2909 + uint64_t endian_swap:2;
2910 + uint64_t reserved3:10;
2919 + * Return the mapping of PCI device number to IRQ line. Each
2920 + * character in the return string represents the interrupt
2921 + * line for the device at that position. Device 1 maps to the
2922 + * first character, etc. The characters A-D are used for PCI
2925 + * Returns PCI interrupt mapping
2927 +const char *octeon_get_pci_interrupts(void)
2930 + * Returning an empty string causes the interrupts to be
2931 + * routed based on the PCI specification. From the PCI spec:
2933 + * INTA# of Device Number 0 is connected to IRQW on the system
2934 + * board. (Device Number has no significance regarding being
2935 + * located on the system board or in a connector.) INTA# of
2936 + * Device Number 1 is connected to IRQX on the system
2937 + * board. INTA# of Device Number 2 is connected to IRQY on the
2938 + * system board. INTA# of Device Number 3 is connected to IRQZ
2939 + * on the system board. The table below describes how each
2940 + * agent's INTx# lines are connected to the system board
2941 + * interrupt lines. The following equation can be used to
2942 + * determine to which INTx# signal on the system board a given
2943 + * device's INTx# line(s) is connected.
2945 + * MB = (D + I) MOD 4 MB = System board Interrupt (IRQW = 0,
2946 + * IRQX = 1, IRQY = 2, and IRQZ = 3) D = Device Number I =
2947 + * Interrupt Number (INTA# = 0, INTB# = 1, INTC# = 2, and
2950 + switch (octeon_bootinfo->board_type) {
2951 + case CVMX_BOARD_TYPE_NAO38:
2952 + /* This is really the NAC38 */
2953 + return "AAAAADABAAAAAAAAAAAAAAAAAAAAAAAA";
2954 + case CVMX_BOARD_TYPE_THUNDER:
2956 + case CVMX_BOARD_TYPE_EBH3000:
2958 + case CVMX_BOARD_TYPE_EBH3100:
2959 + case CVMX_BOARD_TYPE_CN3010_EVB_HS5:
2960 + case CVMX_BOARD_TYPE_CN3005_EVB_HS5:
2961 + return "AAABAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
2962 + case CVMX_BOARD_TYPE_BBGW_REF:
2970 + * Map a PCI device to the appropriate interrupt line
2972 + * @dev: The Linux PCI device structure for the device to map
2973 + * @slot: The slot number for this device on __BUS 0__. Linux
2974 + * enumerates through all the bridges and figures out the
2975 + * slot on Bus 0 where this device eventually hooks to.
2976 + * @pin: The PCI interrupt pin read from the device, then swizzled
2977 + * as it goes through each bridge.
2978 + * Returns Interrupt number for the device
2980 +int __init octeon_pci_pcibios_map_irq(const struct pci_dev *dev,
2984 + const char *interrupts;
2987 + /* Get the board specific interrupt mapping */
2988 + interrupts = octeon_get_pci_interrupts();
2990 + dev_num = dev->devfn >> 3;
2991 + if (dev_num < strlen(interrupts))
2992 + irq_num = ((interrupts[dev_num] - 'A' + pin - 1) & 3) +
2993 + OCTEON_IRQ_PCI_INT0;
2995 + irq_num = ((slot + pin - 3) & 3) + OCTEON_IRQ_PCI_INT0;
3001 + * Read a value from configuration space
3004 +static int octeon_read_config(struct pci_bus *bus, unsigned int devfn,
3005 + int reg, int size, u32 *val)
3007 + union octeon_pci_address pci_addr;
3010 + pci_addr.s.upper = 2;
3011 + pci_addr.s.io = 1;
3012 + pci_addr.s.did = 3;
3013 + pci_addr.s.subdid = 1;
3014 + pci_addr.s.endian_swap = 1;
3015 + pci_addr.s.bus = bus->number;
3016 + pci_addr.s.dev = devfn >> 3;
3017 + pci_addr.s.func = devfn & 0x7;
3018 + pci_addr.s.reg = reg;
3020 +#if PCI_CONFIG_SPACE_DELAY
3021 + udelay(PCI_CONFIG_SPACE_DELAY);
3025 + *val = le32_to_cpu(cvmx_read64_uint32(pci_addr.u64));
3026 + return PCIBIOS_SUCCESSFUL;
3028 + *val = le16_to_cpu(cvmx_read64_uint16(pci_addr.u64));
3029 + return PCIBIOS_SUCCESSFUL;
3031 + *val = cvmx_read64_uint8(pci_addr.u64);
3032 + return PCIBIOS_SUCCESSFUL;
3034 + return PCIBIOS_FUNC_NOT_SUPPORTED;
3039 + * Write a value to PCI configuration space
3048 +static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
3049 + int reg, int size, u32 val)
3051 + union octeon_pci_address pci_addr;
3054 + pci_addr.s.upper = 2;
3055 + pci_addr.s.io = 1;
3056 + pci_addr.s.did = 3;
3057 + pci_addr.s.subdid = 1;
3058 + pci_addr.s.endian_swap = 1;
3059 + pci_addr.s.bus = bus->number;
3060 + pci_addr.s.dev = devfn >> 3;
3061 + pci_addr.s.func = devfn & 0x7;
3062 + pci_addr.s.reg = reg;
3064 +#if PCI_CONFIG_SPACE_DELAY
3065 + udelay(PCI_CONFIG_SPACE_DELAY);
3069 + cvmx_write64_uint32(pci_addr.u64, cpu_to_le32(val));
3070 + return PCIBIOS_SUCCESSFUL;
3072 + cvmx_write64_uint16(pci_addr.u64, cpu_to_le16(val));
3073 + return PCIBIOS_SUCCESSFUL;
3075 + cvmx_write64_uint8(pci_addr.u64, val);
3076 + return PCIBIOS_SUCCESSFUL;
3078 + return PCIBIOS_FUNC_NOT_SUPPORTED;
3082 +static struct pci_ops octeon_pci_ops = {
3083 + octeon_read_config,
3084 + octeon_write_config,
3087 +static struct resource octeon_pci_mem_resource = {
3090 + .name = "Octeon PCI MEM",
3091 + .flags = IORESOURCE_MEM,
3095 + * PCI ports must be above 16KB so the ISA bus filtering in the PCI-X to PCI
3098 +static struct resource octeon_pci_io_resource = {
3100 + .end = OCTEON_PCI_IOSPACE_SIZE - 1,
3101 + .name = "Octeon PCI IO",
3102 + .flags = IORESOURCE_IO,
3105 +static struct pci_controller octeon_pci_controller = {
3106 + .pci_ops = &octeon_pci_ops,
3107 + .mem_resource = &octeon_pci_mem_resource,
3108 + .mem_offset = OCTEON_PCI_MEMSPACE_OFFSET,
3109 + .io_resource = &octeon_pci_io_resource,
3111 + .io_map_base = OCTEON_PCI_IOSPACE_BASE,
3116 + * Low level initialize the Octeon PCI controller
3120 +static void octeon_pci_initialize(void)
3122 + union cvmx_pci_cfg01 cfg01;
3123 + union cvmx_npi_ctl_status ctl_status;
3124 + union cvmx_pci_ctl_status_2 ctl_status_2;
3125 + union cvmx_pci_cfg19 cfg19;
3126 + union cvmx_pci_cfg16 cfg16;
3127 + union cvmx_pci_cfg22 cfg22;
3128 + union cvmx_pci_cfg56 cfg56;
3130 + /* Reset the PCI Bus */
3131 + cvmx_write_csr(CVMX_CIU_SOFT_PRST, 0x1);
3132 + cvmx_read_csr(CVMX_CIU_SOFT_PRST);
3134 + udelay(2000); /* Hold PCI reset for 2 ms */
3136 + ctl_status.u64 = 0; /* cvmx_read_csr(CVMX_NPI_CTL_STATUS); */
3137 + ctl_status.s.max_word = 1;
3138 + ctl_status.s.timer = 1;
3139 + cvmx_write_csr(CVMX_NPI_CTL_STATUS, ctl_status.u64);
3141 + /* Deassert PCI reset and advertize PCX Host Mode Device Capability
3143 + cvmx_write_csr(CVMX_CIU_SOFT_PRST, 0x4);
3144 + cvmx_read_csr(CVMX_CIU_SOFT_PRST);
3146 + udelay(2000); /* Wait 2 ms after deasserting PCI reset */
3148 + ctl_status_2.u32 = 0;
3149 + ctl_status_2.s.tsr_hwm = 1; /* Initializes to 0. Must be set
3150 + before any PCI reads. */
3151 + ctl_status_2.s.bar2pres = 1; /* Enable BAR2 */
3152 + ctl_status_2.s.bar2_enb = 1;
3153 + ctl_status_2.s.bar2_cax = 1; /* Don't use L2 */
3154 + ctl_status_2.s.bar2_esx = 1;
3155 + ctl_status_2.s.pmo_amod = 1; /* Round robin priority */
3156 + if (octeon_dma_bar_type == OCTEON_DMA_BAR_TYPE_BIG) {
3158 + ctl_status_2.s.bb1_hole = OCTEON_PCI_BAR1_HOLE_BITS;
3159 + ctl_status_2.s.bb1_siz = 1; /* BAR1 is 2GB */
3160 + ctl_status_2.s.bb_ca = 1; /* Don't use L2 with big bars */
3161 + ctl_status_2.s.bb_es = 1; /* Big bar in byte swap mode */
3162 + ctl_status_2.s.bb1 = 1; /* BAR1 is big */
3163 + ctl_status_2.s.bb0 = 1; /* BAR0 is big */
3166 + octeon_npi_write32(CVMX_NPI_PCI_CTL_STATUS_2, ctl_status_2.u32);
3167 + udelay(2000); /* Wait 2 ms before doing PCI reads */
3169 + ctl_status_2.u32 = octeon_npi_read32(CVMX_NPI_PCI_CTL_STATUS_2);
3170 + pr_notice("PCI Status: %s %s-bit\n",
3171 + ctl_status_2.s.ap_pcix ? "PCI-X" : "PCI",
3172 + ctl_status_2.s.ap_64ad ? "64" : "32");
3174 + if (OCTEON_IS_MODEL(OCTEON_CN58XX) || OCTEON_IS_MODEL(OCTEON_CN50XX)) {
3175 + union cvmx_pci_cnt_reg cnt_reg_start;
3176 + union cvmx_pci_cnt_reg cnt_reg_end;
3177 + unsigned long cycles, pci_clock;
3179 + cnt_reg_start.u64 = cvmx_read_csr(CVMX_NPI_PCI_CNT_REG);
3180 + cycles = read_c0_cvmcount();
3182 + cnt_reg_end.u64 = cvmx_read_csr(CVMX_NPI_PCI_CNT_REG);
3183 + cycles = read_c0_cvmcount() - cycles;
3184 + pci_clock = (cnt_reg_end.s.pcicnt - cnt_reg_start.s.pcicnt) /
3185 + (cycles / (mips_hpt_frequency / 1000000));
3186 + pr_notice("PCI Clock: %lu MHz\n", pci_clock);
3190 + * TDOMC must be set to one in PCI mode. TDOMC should be set to 4
3191 + * in PCI-X mode to allow four oustanding splits. Otherwise,
3192 + * should not change from its reset value. Don't write PCI_CFG19
3193 + * in PCI mode (0x82000001 reset value), write it to 0x82000004
3194 + * after PCI-X mode is known. MRBCI,MDWE,MDRE -> must be zero.
3195 + * MRBCM -> must be one.
3197 + if (ctl_status_2.s.ap_pcix) {
3200 + * Target Delayed/Split request outstanding maximum
3201 + * count. [1..31] and 0=32. NOTE: If the user
3202 + * programs these bits beyond the Designed Maximum
3203 + * outstanding count, then the designed maximum table
3204 + * depth will be used instead. No additional
3205 + * Deferred/Split transactions will be accepted if
3206 + * this outstanding maximum count is
3207 + * reached. Furthermore, no additional deferred/split
3208 + * transactions will be accepted if the I/O delay/ I/O
3209 + * Split Request outstanding maximum is reached.
3211 + cfg19.s.tdomc = 4;
3213 + * Master Deferred Read Request Outstanding Max Count
3214 + * (PCI only). CR4C[26:24] Max SAC cycles MAX DAC
3215 + * cycles 000 8 4 001 1 0 010 2 1 011 3 1 100 4 2 101
3216 + * 5 2 110 6 3 111 7 3 For example, if these bits are
3217 + * programmed to 100, the core can support 2 DAC
3218 + * cycles, 4 SAC cycles or a combination of 1 DAC and
3219 + * 2 SAC cycles. NOTE: For the PCI-X maximum
3220 + * outstanding split transactions, refer to
3223 + cfg19.s.mdrrmc = 2;
3225 + * Master Request (Memory Read) Byte Count/Byte Enable
3226 + * select. 0 = Byte Enables valid. In PCI mode, a
3227 + * burst transaction cannot be performed using Memory
3228 + * Read command=4?h6. 1 = DWORD Byte Count valid
3229 + * (default). In PCI Mode, the memory read byte
3230 + * enables are automatically generated by the
3231 + * core. Note: N3 Master Request transaction sizes are
3232 + * always determined through the
3233 + * am_attr[<35:32>|<7:0>] field.
3235 + cfg19.s.mrbcm = 1;
3236 + octeon_npi_write32(CVMX_NPI_PCI_CFG19, cfg19.u32);
3241 + cfg01.s.msae = 1; /* Memory Space Access Enable */
3242 + cfg01.s.me = 1; /* Master Enable */
3243 + cfg01.s.pee = 1; /* PERR# Enable */
3244 + cfg01.s.see = 1; /* System Error Enable */
3245 + cfg01.s.fbbe = 1; /* Fast Back to Back Transaction Enable */
3247 + octeon_npi_write32(CVMX_NPI_PCI_CFG01, cfg01.u32);
3249 +#ifdef USE_OCTEON_INTERNAL_ARBITER
3251 + * When OCTEON is a PCI host, most systems will use OCTEON's
3252 + * internal arbiter, so must enable it before any PCI/PCI-X
3253 + * traffic can occur.
3256 + union cvmx_npi_pci_int_arb_cfg pci_int_arb_cfg;
3258 + pci_int_arb_cfg.u64 = 0;
3259 + pci_int_arb_cfg.s.en = 1; /* Internal arbiter enable */
3260 + cvmx_write_csr(CVMX_NPI_PCI_INT_ARB_CFG, pci_int_arb_cfg.u64);
3262 +#endif /* USE_OCTEON_INTERNAL_ARBITER */
3265 + * Preferrably written to 1 to set MLTD. [RDSATI,TRTAE,
3266 + * TWTAE,TMAE,DPPMR -> must be zero. TILT -> must not be set to
3270 + cfg16.s.mltd = 1; /* Master Latency Timer Disable */
3271 + octeon_npi_write32(CVMX_NPI_PCI_CFG16, cfg16.u32);
3274 + * Should be written to 0x4ff00. MTTV -> must be zero.
3275 + * FLUSH -> must be 1. MRV -> should be 0xFF.
3278 + /* Master Retry Value [1..255] and 0=infinite */
3279 + cfg22.s.mrv = 0xff;
3281 + * AM_DO_FLUSH_I control NOTE: This bit MUST BE ONE for proper
3284 + cfg22.s.flush = 1;
3285 + octeon_npi_write32(CVMX_NPI_PCI_CFG22, cfg22.u32);
3288 + * MOST Indicates the maximum number of outstanding splits (in -1
3289 + * notation) when OCTEON is in PCI-X mode. PCI-X performance is
3290 + * affected by the MOST selection. Should generally be written
3291 + * with one of 0x3be807, 0x2be807, 0x1be807, or 0x0be807,
3292 + * depending on the desired MOST of 3, 2, 1, or 0, respectively.
3295 + cfg56.s.pxcid = 7; /* RO - PCI-X Capability ID */
3296 + cfg56.s.ncp = 0xe8; /* RO - Next Capability Pointer */
3297 + cfg56.s.dpere = 1; /* Data Parity Error Recovery Enable */
3298 + cfg56.s.roe = 1; /* Relaxed Ordering Enable */
3299 + cfg56.s.mmbc = 1; /* Maximum Memory Byte Count
3300 + [0=512B,1=1024B,2=2048B,3=4096B] */
3301 + cfg56.s.most = 3; /* Maximum outstanding Split transactions [0=1
3304 + octeon_npi_write32(CVMX_NPI_PCI_CFG56, cfg56.u32);
3307 + * Affects PCI performance when OCTEON services reads to its
3308 + * BAR1/BAR2. Refer to Section 10.6.1. The recommended values are
3309 + * 0x22, 0x33, and 0x33 for PCI_READ_CMD_6, PCI_READ_CMD_C, and
3310 + * PCI_READ_CMD_E, respectively. Unfortunately due to errata DDR-700,
3311 + * these values need to be changed so they won't possibly prefetch off
3312 + * of the end of memory if PCI is DMAing a buffer at the end of
3313 + * memory. Note that these values differ from their reset values.
3315 + octeon_npi_write32(CVMX_NPI_PCI_READ_CMD_6, 0x21);
3316 + octeon_npi_write32(CVMX_NPI_PCI_READ_CMD_C, 0x31);
3317 + octeon_npi_write32(CVMX_NPI_PCI_READ_CMD_E, 0x31);
3322 + * Initialize the Octeon PCI controller
3326 +static int __init octeon_pci_setup(void)
3328 + union cvmx_npi_mem_access_subidx mem_access;
3331 + /* Only these chips have PCI */
3332 + if (octeon_has_feature(OCTEON_FEATURE_PCIE))
3335 + /* Point pcibios_map_irq() to the PCI version of it */
3336 + octeon_pcibios_map_irq = octeon_pci_pcibios_map_irq;
3338 + /* Only use the big bars on chips that support it */
3339 + if (OCTEON_IS_MODEL(OCTEON_CN31XX) ||
3340 + OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2) ||
3341 + OCTEON_IS_MODEL(OCTEON_CN38XX_PASS1))
3342 + octeon_dma_bar_type = OCTEON_DMA_BAR_TYPE_SMALL;
3344 + octeon_dma_bar_type = OCTEON_DMA_BAR_TYPE_BIG;
3346 + /* PCI I/O and PCI MEM values */
3347 + set_io_port_base(OCTEON_PCI_IOSPACE_BASE);
3348 + ioport_resource.start = 0;
3349 + ioport_resource.end = OCTEON_PCI_IOSPACE_SIZE - 1;
3350 + if (!octeon_is_pci_host()) {
3351 + pr_notice("Not in host mode, PCI Controller not initialized\n");
3355 + pr_notice("%s Octeon big bar support\n",
3356 + (octeon_dma_bar_type ==
3357 + OCTEON_DMA_BAR_TYPE_BIG) ? "Enabling" : "Disabling");
3359 + octeon_pci_initialize();
3361 + mem_access.u64 = 0;
3362 + mem_access.s.esr = 1; /* Endian-Swap on read. */
3363 + mem_access.s.esw = 1; /* Endian-Swap on write. */
3364 + mem_access.s.nsr = 0; /* No-Snoop on read. */
3365 + mem_access.s.nsw = 0; /* No-Snoop on write. */
3366 + mem_access.s.ror = 0; /* Relax Read on read. */
3367 + mem_access.s.row = 0; /* Relax Order on write. */
3368 + mem_access.s.ba = 0; /* PCI Address bits [63:36]. */
3369 + cvmx_write_csr(CVMX_NPI_MEM_ACCESS_SUBID3, mem_access.u64);
3372 + * Remap the Octeon BAR 2 above all 32 bit devices
3373 + * (0x8000000000ul). This is done here so it is remapped
3374 + * before the readl()'s below. We don't want BAR2 overlapping
3375 + * with BAR0/BAR1 during these reads.
3377 + octeon_npi_write32(CVMX_NPI_PCI_CFG08, 0);
3378 + octeon_npi_write32(CVMX_NPI_PCI_CFG09, 0x80);
3380 + /* Disable the BAR1 movable mappings */
3381 + for (index = 0; index < 32; index++)
3382 + octeon_npi_write32(CVMX_NPI_PCI_BAR1_INDEXX(index), 0);
3384 + if (octeon_dma_bar_type == OCTEON_DMA_BAR_TYPE_BIG) {
3385 + /* Remap the Octeon BAR 0 to 0-2GB */
3386 + octeon_npi_write32(CVMX_NPI_PCI_CFG04, 0);
3387 + octeon_npi_write32(CVMX_NPI_PCI_CFG05, 0);
3390 + * Remap the Octeon BAR 1 to map 2GB-4GB (minus the
3393 + octeon_npi_write32(CVMX_NPI_PCI_CFG06, 2ul << 30);
3394 + octeon_npi_write32(CVMX_NPI_PCI_CFG07, 0);
3396 + /* Devices go after BAR1 */
3397 + octeon_pci_mem_resource.start =
3398 + OCTEON_PCI_MEMSPACE_OFFSET + (4ul << 30) -
3399 + (OCTEON_PCI_BAR1_HOLE_SIZE << 20);
3400 + octeon_pci_mem_resource.end =
3401 + octeon_pci_mem_resource.start + (1ul << 30);
3403 + /* Remap the Octeon BAR 0 to map 128MB-(128MB+4KB) */
3404 + octeon_npi_write32(CVMX_NPI_PCI_CFG04, 128ul << 20);
3405 + octeon_npi_write32(CVMX_NPI_PCI_CFG05, 0);
3407 + /* Remap the Octeon BAR 1 to map 0-128MB */
3408 + octeon_npi_write32(CVMX_NPI_PCI_CFG06, 0);
3409 + octeon_npi_write32(CVMX_NPI_PCI_CFG07, 0);
3411 + /* Devices go after BAR0 */
3412 + octeon_pci_mem_resource.start =
3413 + OCTEON_PCI_MEMSPACE_OFFSET + (128ul << 20) +
3415 + octeon_pci_mem_resource.end =
3416 + octeon_pci_mem_resource.start + (1ul << 30);
3419 + register_pci_controller(&octeon_pci_controller);
3422 + * Clear any errors that might be pending from before the bus
3423 + * was setup properly.
3425 + cvmx_write_csr(CVMX_NPI_PCI_INT_SUM2, -1);
3429 +arch_initcall(octeon_pci_setup);
3430 diff --git a/arch/mips/cavium-octeon/pcie.c b/arch/mips/cavium-octeon/pcie.c
3431 new file mode 100644
3432 index 0000000..cb6662c
3434 +++ b/arch/mips/cavium-octeon/pcie.c
3437 + * This file is subject to the terms and conditions of the GNU General Public
3438 + * License. See the file "COPYING" in the main directory of this archive
3439 + * for more details.
3441 + * Copyright (C) 2007, 2008 Cavium Networks
3443 +#include <linux/kernel.h>
3444 +#include <linux/init.h>
3445 +#include <linux/pci.h>
3446 +#include <linux/interrupt.h>
3447 +#include <linux/time.h>
3448 +#include <linux/delay.h>
3450 +#include <asm/octeon/octeon.h>
3451 +#include <asm/octeon/cvmx-pcie.h>
3452 +#include <asm/octeon/cvmx-npei-defs.h>
3453 +#include <asm/octeon/cvmx-pexp-defs.h>
3455 +#include "pci-common.h"
3458 + * Map a PCI device to the appropriate interrupt line
3460 + * @param dev The Linux PCI device structure for the device to map
3461 + * @param slot The slot number for this device on __BUS 0__. Linux
3462 + * enumerates through all the bridges and figures out the
3463 + * slot on Bus 0 where this device eventually hooks to.
3464 + * @param pin The PCI interrupt pin read from the device, then swizzled
3465 + * as it goes through each bridge.
3466 + * @return Interrupt number for the device
3468 +int __init octeon_pcie_pcibios_map_irq(const struct pci_dev *dev,
3472 + * The EBH5600 board with the PCI to PCIe bridge mistakenly
3473 + * wires the first slot for both device id 2 and interrupt
3474 + * A. According to the PCI spec, device id 2 should be C. The
3475 + * following kludge attempts to fix this.
3477 + if (strstr(octeon_board_type_string(), "EBH5600") &&
3478 + dev->bus && dev->bus->parent) {
3480 + * Iterate all the way up the device chain and find
3483 + while (dev->bus && dev->bus->parent)
3484 + dev = to_pci_dev(dev->bus->bridge);
3485 + /* If the root bus is number 0 and the PEX 8114 is the
3486 + * root, assume we are behind the miswired bus. We
3487 + * need to correct the swizzle level by two. Yuck.
3489 + if ((dev->bus->number == 0) &&
3490 + (dev->vendor == 0x10b5) && (dev->device == 0x8114)) {
3492 + * The pin field is one based, not zero. We
3493 + * need to swizzle it by minus two.
3495 + pin = ((pin - 3) & 3) + 1;
3499 + * The -1 is because pin starts with one, not zero. It might
3500 + * be that this equation needs to include the slot number, but
3501 + * I don't have hardware to check that against.
3503 + return pin - 1 + OCTEON_IRQ_PCI_INT0;
3507 + * Read a value from configuration space
3516 +static inline int octeon_pcie_read_config(int pcie_port, struct pci_bus *bus,
3517 + unsigned int devfn, int reg, int size,
3520 + union octeon_cvmemctl cvmmemctl;
3521 + union octeon_cvmemctl cvmmemctl_save;
3522 + int bus_number = bus->number;
3525 + * We need to force the bus number to be zero on the root
3526 + * bus. Linux numbers the 2nd root bus to start after all
3527 + * buses on root 0.
3529 + if (bus->parent == NULL)
3533 + * PCIe only has a single device connected to Octeon. It is
3534 + * always device ID 0. Don't bother doing reads for other
3535 + * device IDs on the first segment.
3537 + if ((bus_number == 0) && (devfn >> 3 != 0))
3538 + return PCIBIOS_FUNC_NOT_SUPPORTED;
3541 + * The following is a workaround for the CN57XX, CN56XX,
3542 + * CN55XX, and CN54XX errata with PCIe config reads from non
3543 + * existent devices. These chips will hang the PCIe link if a
3544 + * config read is performed that causes a UR response.
3546 + if (OCTEON_IS_MODEL(OCTEON_CN56XX_PASS1) ||
3547 + OCTEON_IS_MODEL(OCTEON_CN56XX_PASS1_1)) {
3549 + * For our EBH5600 board, port 0 has a bridge with two
3550 + * PCI-X slots. We need a new special checks to make
3551 + * sure we only probe valid stuff. The PCIe->PCI-X
3552 + * bridge only respondes to device ID 0, function
3555 + if ((bus_number == 0) && (devfn >= 2))
3556 + return PCIBIOS_FUNC_NOT_SUPPORTED;
3558 + * The PCI-X slots are device ID 2,3. Choose one of
3559 + * the below "if" blocks based on what is plugged into
3563 + /* Use this option if you aren't using either slot */
3564 + if (bus_number == 1)
3565 + return PCIBIOS_FUNC_NOT_SUPPORTED;
3568 + * Use this option if you are using the first slot but
3571 + if ((bus_number == 1) && (devfn >> 3 != 2))
3572 + return PCIBIOS_FUNC_NOT_SUPPORTED;
3575 + * Use this option if you are using the second slot
3576 + * but not the first.
3578 + if ((bus_number == 1) && (devfn >> 3 != 3))
3579 + return PCIBIOS_FUNC_NOT_SUPPORTED;
3581 + /* Use this opion if you are using both slots */
3582 + if ((bus_number == 1) &&
3583 + !((devfn == (2 << 3)) || (devfn == (3 << 3))))
3584 + return PCIBIOS_FUNC_NOT_SUPPORTED;
3588 + * The following #if gives a more complicated
3589 + * example. This is the required checks for running a
3590 + * Nitrox CN16XX-NHBX in the slot of the EBH5600. This
3591 + * card has a PLX PCIe bridge with four Nitrox PLX
3592 + * parts behind it.
3595 + /* PLX bridge with 4 ports */
3596 + if ((bus_number == 3) &&
3597 + !((devfn >> 3 >= 1) && (devfn >> 3 <= 4)))
3598 + return PCIBIOS_FUNC_NOT_SUPPORTED;
3599 + /* Nitrox behind PLX 1 */
3600 + if ((bus_number == 4) && (devfn >> 3 != 0))
3601 + return PCIBIOS_FUNC_NOT_SUPPORTED;
3602 + /* Nitrox behind PLX 2 */
3603 + if ((bus_number == 5) && (devfn >> 3 != 0))
3604 + return PCIBIOS_FUNC_NOT_SUPPORTED;
3605 + /* Nitrox behind PLX 3 */
3606 + if ((bus_number == 6) && (devfn >> 3 != 0))
3607 + return PCIBIOS_FUNC_NOT_SUPPORTED;
3608 + /* Nitrox behind PLX 4 */
3609 + if ((bus_number == 7) && (devfn >> 3 != 0))
3610 + return PCIBIOS_FUNC_NOT_SUPPORTED;
3613 + * Shorten the DID timeout so bus errors for PCIe
3614 + * config reads from non existent devices happen
3615 + * faster. This allows us to continue booting even if
3616 + * the above "if" checks are wrong. Once one of these
3617 + * errors happens, the PCIe port is dead.
3619 + cvmmemctl_save.u64 = __read_64bit_c0_register($11, 7);
3620 + cvmmemctl.u64 = cvmmemctl_save.u64;
3621 + cvmmemctl.s.didtto = 2;
3622 + __write_64bit_c0_register($11, 7, cvmmemctl.u64);
3627 + *val = cvmx_pcie_config_read32(pcie_port, bus_number,
3628 + devfn >> 3, devfn & 0x7, reg);
3631 + *val = cvmx_pcie_config_read16(pcie_port, bus_number,
3632 + devfn >> 3, devfn & 0x7, reg);
3635 + *val = cvmx_pcie_config_read8(pcie_port, bus_number, devfn >> 3,
3636 + devfn & 0x7, reg);
3639 + return PCIBIOS_FUNC_NOT_SUPPORTED;
3642 + if (OCTEON_IS_MODEL(OCTEON_CN56XX_PASS1) ||
3643 + OCTEON_IS_MODEL(OCTEON_CN56XX_PASS1_1))
3644 + __write_64bit_c0_register($11, 7, cvmmemctl_save.u64);
3645 + return PCIBIOS_SUCCESSFUL;
3648 +static int octeon_pcie0_read_config(struct pci_bus *bus, unsigned int devfn,
3649 + int reg, int size, u32 *val)
3651 + return octeon_pcie_read_config(0, bus, devfn, reg, size, val);
3654 +static int octeon_pcie1_read_config(struct pci_bus *bus, unsigned int devfn,
3655 + int reg, int size, u32 *val)
3657 + return octeon_pcie_read_config(1, bus, devfn, reg, size, val);
3663 + * Write a value to PCI configuration space
3672 +static inline int octeon_pcie_write_config(int pcie_port, struct pci_bus *bus,
3673 + unsigned int devfn, int reg,
3674 + int size, u32 val)
3676 + int bus_number = bus->number;
3678 + * We need to force the bus number to be zero on the root
3679 + * bus. Linux numbers the 2nd root bus to start after all
3680 + * busses on root 0.
3682 + if (bus->parent == NULL)
3687 + cvmx_pcie_config_write32(pcie_port, bus_number, devfn >> 3,
3688 + devfn & 0x7, reg, val);
3689 + return PCIBIOS_SUCCESSFUL;
3691 + cvmx_pcie_config_write16(pcie_port, bus_number, devfn >> 3,
3692 + devfn & 0x7, reg, val);
3693 + return PCIBIOS_SUCCESSFUL;
3695 + cvmx_pcie_config_write8(pcie_port, bus_number, devfn >> 3,
3696 + devfn & 0x7, reg, val);
3697 + return PCIBIOS_SUCCESSFUL;
3699 +#if PCI_CONFIG_SPACE_DELAY
3700 + udelay(PCI_CONFIG_SPACE_DELAY);
3702 + return PCIBIOS_FUNC_NOT_SUPPORTED;
3705 +static int octeon_pcie0_write_config(struct pci_bus *bus, unsigned int devfn,
3706 + int reg, int size, u32 val)
3708 + return octeon_pcie_write_config(0, bus, devfn, reg, size, val);
3711 +static int octeon_pcie1_write_config(struct pci_bus *bus, unsigned int devfn,
3712 + int reg, int size, u32 val)
3714 + return octeon_pcie_write_config(1, bus, devfn, reg, size, val);
3717 +static struct pci_ops octeon_pcie0_ops = {
3718 + octeon_pcie0_read_config,
3719 + octeon_pcie0_write_config,
3722 +static struct resource octeon_pcie0_mem_resource = {
3723 + .name = "Octeon PCIe0 MEM",
3724 + .flags = IORESOURCE_MEM,
3727 +static struct resource octeon_pcie0_io_resource = {
3728 + .name = "Octeon PCIe0 IO",
3729 + .flags = IORESOURCE_IO,
3732 +static struct pci_controller octeon_pcie0_controller = {
3733 + .pci_ops = &octeon_pcie0_ops,
3734 + .mem_resource = &octeon_pcie0_mem_resource,
3735 + .io_resource = &octeon_pcie0_io_resource,
3738 +static struct pci_ops octeon_pcie1_ops = {
3739 + octeon_pcie1_read_config,
3740 + octeon_pcie1_write_config,
3743 +static struct resource octeon_pcie1_mem_resource = {
3744 + .name = "Octeon PCIe1 MEM",
3745 + .flags = IORESOURCE_MEM,
3748 +static struct resource octeon_pcie1_io_resource = {
3749 + .name = "Octeon PCIe1 IO",
3750 + .flags = IORESOURCE_IO,
3753 +static struct pci_controller octeon_pcie1_controller = {
3754 + .pci_ops = &octeon_pcie1_ops,
3755 + .mem_resource = &octeon_pcie1_mem_resource,
3756 + .io_resource = &octeon_pcie1_io_resource,
3761 + * Initialize the Octeon PCIe controllers
3765 +static int __init octeon_pcie_setup(void)
3767 + union cvmx_npei_ctl_status npei_ctl_status;
3770 + /* These chips don't have PCIe */
3771 + if (!octeon_has_feature(OCTEON_FEATURE_PCIE))
3774 + /* Point pcibios_map_irq() to the PCIe version of it */
3775 + octeon_pcibios_map_irq = octeon_pcie_pcibios_map_irq;
3777 + /* Use the PCIe based DMA mappings */
3778 + octeon_dma_bar_type = OCTEON_DMA_BAR_TYPE_PCIE;
3781 + * PCIe I/O range. It is based on port 0 but includes up until
3784 + set_io_port_base(CVMX_ADD_IO_SEG(cvmx_pcie_get_io_base_address(0)));
3785 + ioport_resource.start = 0;
3786 + ioport_resource.end =
3787 + cvmx_pcie_get_io_base_address(1) -
3788 + cvmx_pcie_get_io_base_address(0) + cvmx_pcie_get_io_size(1) - 1;
3790 + npei_ctl_status.u64 = cvmx_read_csr(CVMX_PEXP_NPEI_CTL_STATUS);
3791 + if (npei_ctl_status.s.host_mode) {
3792 + pr_notice("PCIe: Initializing port 0\n");
3793 + result = cvmx_pcie_rc_initialize(0);
3794 + if (result == 0) {
3795 + /* Memory offsets are physical addresses */
3796 + octeon_pcie0_controller.mem_offset =
3797 + cvmx_pcie_get_mem_base_address(0);
3798 + /* IO offsets are Mips virtual addresses */
3799 + octeon_pcie0_controller.io_map_base =
3800 + CVMX_ADD_IO_SEG(cvmx_pcie_get_io_base_address
3802 + octeon_pcie0_controller.io_offset = 0;
3804 + * To keep things similar to PCI, we start
3805 + * device addresses at the same place as PCI
3806 + * uisng big bar support. This normally
3807 + * translates to 4GB-256MB, which is the same
3808 + * as most x86 PCs.
3810 + octeon_pcie0_controller.mem_resource->start =
3811 + cvmx_pcie_get_mem_base_address(0) +
3812 + (4ul << 30) - (OCTEON_PCI_BAR1_HOLE_SIZE << 20);
3813 + octeon_pcie0_controller.mem_resource->end =
3814 + cvmx_pcie_get_mem_base_address(0) +
3815 + cvmx_pcie_get_mem_size(0) - 1;
3817 + * Ports must be above 16KB for the ISA bus
3818 + * filtering in the PCI-X to PCI bridge.
3820 + octeon_pcie0_controller.io_resource->start = 4 << 10;
3821 + octeon_pcie0_controller.io_resource->end =
3822 + cvmx_pcie_get_io_size(0) - 1;
3823 + register_pci_controller(&octeon_pcie0_controller);
3826 + pr_notice("PCIe: Port 0 in endpoint mode, skipping.\n");
3829 + /* Skip the 2nd port on CN52XX if port 0 is in 4 lane mode */
3830 + if (OCTEON_IS_MODEL(OCTEON_CN52XX)) {
3831 + union cvmx_npei_dbg_data npei_dbg_data;
3832 + npei_dbg_data.u64 = cvmx_read_csr(CVMX_PEXP_NPEI_DBG_DATA);
3833 + if (npei_dbg_data.cn52xx.qlm0_link_width)
3837 + pr_notice("PCIe: Initializing port 1\n");
3838 + result = cvmx_pcie_rc_initialize(1);
3839 + if (result == 0) {
3840 + /* Memory offsets are physical addresses */
3841 + octeon_pcie1_controller.mem_offset =
3842 + cvmx_pcie_get_mem_base_address(1);
3843 + /* IO offsets are Mips virtual addresses */
3844 + octeon_pcie1_controller.io_map_base =
3845 + CVMX_ADD_IO_SEG(cvmx_pcie_get_io_base_address(1));
3846 + octeon_pcie1_controller.io_offset =
3847 + cvmx_pcie_get_io_base_address(1) -
3848 + cvmx_pcie_get_io_base_address(0);
3850 + * To keep things similar to PCI, we start device
3851 + * addresses at the same place as PCI uisng big bar
3852 + * support. This normally translates to 4GB-256MB,
3853 + * which is the same as most x86 PCs.
3855 + octeon_pcie1_controller.mem_resource->start =
3856 + cvmx_pcie_get_mem_base_address(1) + (4ul << 30) -
3857 + (OCTEON_PCI_BAR1_HOLE_SIZE << 20);
3858 + octeon_pcie1_controller.mem_resource->end =
3859 + cvmx_pcie_get_mem_base_address(1) +
3860 + cvmx_pcie_get_mem_size(1) - 1;
3862 + * Ports must be above 16KB for the ISA bus filtering
3863 + * in the PCI-X to PCI bridge.
3865 + octeon_pcie1_controller.io_resource->start =
3866 + cvmx_pcie_get_io_base_address(1) -
3867 + cvmx_pcie_get_io_base_address(0);
3868 + octeon_pcie1_controller.io_resource->end =
3869 + octeon_pcie1_controller.io_resource->start +
3870 + cvmx_pcie_get_io_size(1) - 1;
3871 + register_pci_controller(&octeon_pcie1_controller);
3876 +arch_initcall(octeon_pcie_setup);
3877 diff --git a/arch/mips/include/asm/octeon/cvmx-asm.h b/arch/mips/include/asm/octeon/cvmx-asm.h
3878 index b21d3fc..093bcaf 100644
3879 --- a/arch/mips/include/asm/octeon/cvmx-asm.h
3880 +++ b/arch/mips/include/asm/octeon/cvmx-asm.h
3882 asm ("pop %[rd],%[rs]" : [rd] "=d" (result) : [rs] "d" (input))
3883 #define CVMX_DPOP(result, input) \
3884 asm ("dpop %[rd],%[rs]" : [rd] "=d" (result) : [rs] "d" (input))
3886 +#define CVMX_CLZ(result, input) \
3887 + asm ("clz %[rd],%[rs]" : [rd] "=d" (result) : [rs] "d" (input))
3888 /* some new cop0-like stuff */
3889 #define CVMX_RDHWR(result, regstr) \
3890 asm volatile ("rdhwr %[rt],$" CVMX_TMP_STR(regstr) : [rt] "=d" (result))
3891 diff --git a/arch/mips/include/asm/octeon/cvmx-helper-errata.h b/arch/mips/include/asm/octeon/cvmx-helper-errata.h
3892 new file mode 100644
3893 index 0000000..ce5deea
3895 +++ b/arch/mips/include/asm/octeon/cvmx-helper-errata.h
3897 +/***********************license start***************
3898 + * Author: Cavium Networks
3900 + * Contact: support@caviumnetworks.com
3901 + * This file is part of the OCTEON SDK
3903 + * Copyright (c) 2003-2008 Cavium Networks
3905 + * This file is free software; you can redistribute it and/or modify
3906 + * it under the terms of the GNU General Public License, Version 2, as
3907 + * published by the Free Software Foundation.
3909 + * This file is distributed in the hope that it will be useful, but
3910 + * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
3911 + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
3912 + * NONINFRINGEMENT. See the GNU General Public License for more
3915 + * You should have received a copy of the GNU General Public License
3916 + * along with this file; if not, write to the Free Software
3917 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3918 + * or visit http://www.gnu.org/licenses/.
3920 + * This file may also be available under a different license from Cavium.
3921 + * Contact Cavium Networks for more information
3922 + ***********************license end**************************************/
3927 + * Fixes and workaround for Octeon chip errata. This file
3928 + * contains functions called by cvmx-helper to workaround known
3929 + * chip errata. For the most part, code doesn't need to call
3930 + * these functions directly.
3933 +#ifndef __CVMX_HELPER_ERRATA_H__
3934 +#define __CVMX_HELPER_ERRATA_H__
3937 +#include "cvmx-wqe.h"
3941 + * Function to adjust internal IPD pointer alignments
3943 + * Returns 0 on success
3946 +extern int __cvmx_helper_errata_fix_ipd_ptr_alignment(void);
3950 + * Workaround ASX setup errata with CN38XX pass1
3952 + * @interface: Interface to setup
3953 + * @port: Port to setup (0..3)
3955 + * Chip frequency in Hertz
3957 + * Returns Zero on success, negative on failure
3959 +extern int __cvmx_helper_errata_asx_pass1(int interface, int port,
3960 + int cpu_clock_hz);
3963 + * This function needs to be called on all Octeon chips with
3966 + * The Size field is 8 too large in WQE and next pointers
3968 + * The Size field generated by IPD is 8 larger than it should
3969 + * be. The Size field is <55:40> of both:
3970 + * - WORD3 in the work queue entry, and
3971 + * - the next buffer pointer (which precedes the packet data
3972 + * in each buffer).
3974 + * @work: Work queue entry to fix
3975 + * Returns Zero on success. Negative on failure
3977 +extern int cvmx_helper_fix_ipd_packet_chain(struct cvmx_wqe *work);
3980 + * Due to errata G-720, the 2nd order CDR circuit on CN52XX pass
3981 + * 1 doesn't work properly. The following code disables 2nd order
3982 + * CDR for the specified QLM.
3984 + * @qlm: QLM to disable 2nd order CDR for.
3986 +extern void __cvmx_helper_errata_qlm_disable_2nd_order_cdr(int qlm);
3989 diff --git a/arch/mips/include/asm/octeon/cvmx-helper-util.h b/arch/mips/include/asm/octeon/cvmx-helper-util.h
3990 new file mode 100644
3991 index 0000000..d720217
3993 +++ b/arch/mips/include/asm/octeon/cvmx-helper-util.h
3995 +/***********************license start***************
3996 + * Author: Cavium Networks
3998 + * Contact: support@caviumnetworks.com
3999 + * This file is part of the OCTEON SDK
4001 + * Copyright (c) 2003-2008 Cavium Networks
4003 + * This file is free software; you can redistribute it and/or modify
4004 + * it under the terms of the GNU General Public License, Version 2, as
4005 + * published by the Free Software Foundation.
4007 + * This file is distributed in the hope that it will be useful, but
4008 + * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
4009 + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
4010 + * NONINFRINGEMENT. See the GNU General Public License for more
4013 + * You should have received a copy of the GNU General Public License
4014 + * along with this file; if not, write to the Free Software
4015 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4016 + * or visit http://www.gnu.org/licenses/.
4018 + * This file may also be available under a different license from Cavium.
4019 + * Contact Cavium Networks for more information
4020 + ***********************license end**************************************/
4024 + * Small helper utilities.
4028 +#ifndef __CVMX_HELPER_UTIL_H__
4029 +#define __CVMX_HELPER_UTIL_H__
4031 +#ifdef CVMX_ENABLE_HELPER_FUNCTIONS
4034 + * Convert a interface mode into a human readable string
4036 + * @mode: Mode to convert
4041 + *cvmx_helper_interface_mode_to_string(cvmx_helper_interface_mode_t mode);
4044 + * Debug routine to dump the packet structure to the console
4046 + * @work: Work queue entry containing the packet to dump
4049 +extern int cvmx_helper_dump_packet(cvmx_wqe_t *work);
4052 + * Setup Random Early Drop on a specific input queue
4054 + * @queue: Input queue to setup RED on (0-7)
4056 + * Packets will begin slowly dropping when there are less than
4057 + * this many packet buffers free in FPA 0.
4059 + * All incomming packets will be dropped when there are less
4060 + * than this many free packet buffers in FPA 0.
4061 + * Returns Zero on success. Negative on failure
4063 +extern int cvmx_helper_setup_red_queue(int queue, int pass_thresh,
4067 + * Setup Random Early Drop to automatically begin dropping packets.
4070 + * Packets will begin slowly dropping when there are less than
4071 + * this many packet buffers free in FPA 0.
4073 + * All incomming packets will be dropped when there are less
4074 + * than this many free packet buffers in FPA 0.
4075 + * Returns Zero on success. Negative on failure
4077 +extern int cvmx_helper_setup_red(int pass_thresh, int drop_thresh);
4080 + * Get the version of the CVMX libraries.
4082 + * Returns Version string. Note this buffer is allocated statically
4083 + * and will be shared by all callers.
4085 +extern const char *cvmx_helper_get_version(void);
4089 + * Setup the common GMX settings that determine the number of
4090 + * ports. These setting apply to almost all configurations of all
4093 + * @interface: Interface to configure
4094 + * @num_ports: Number of ports on the interface
4096 + * Returns Zero on success, negative on failure
4098 +extern int __cvmx_helper_setup_gmx(int interface, int num_ports);
4101 + * Returns the IPD/PKO port number for a port on the given
4104 + * @interface: Interface to use
4105 + * @port: Port on the interface
4107 + * Returns IPD/PKO port number
4109 +extern int cvmx_helper_get_ipd_port(int interface, int port);
4112 + * Returns the IPD/PKO port number for the first port on the given
4115 + * @interface: Interface to use
4117 + * Returns IPD/PKO port number
4119 +static inline int cvmx_helper_get_first_ipd_port(int interface)
4121 + return cvmx_helper_get_ipd_port(interface, 0);
4125 + * Returns the IPD/PKO port number for the last port on the given
4128 + * @interface: Interface to use
4130 + * Returns IPD/PKO port number
4132 +static inline int cvmx_helper_get_last_ipd_port(int interface)
4134 + extern int cvmx_helper_ports_on_interface(int interface);
4136 + return cvmx_helper_get_first_ipd_port(interface) +
4137 + cvmx_helper_ports_on_interface(interface) - 1;
4141 + * Free the packet buffers contained in a work queue entry.
4142 + * The work queue entry is not freed.
4144 + * @work: Work queue entry with packet to free
4146 +static inline void cvmx_helper_free_packet_data(cvmx_wqe_t *work)
4148 + uint64_t number_buffers;
4149 + cvmx_buf_ptr_t buffer_ptr;
4150 + cvmx_buf_ptr_t next_buffer_ptr;
4151 + uint64_t start_of_buffer;
4153 + number_buffers = work->word2.s.bufs;
4154 + if (number_buffers == 0)
4156 + buffer_ptr = work->packet_ptr;
4159 + * Since the number of buffers is not zero, we know this is
4160 + * not a dynamic short packet. We need to check if it is a
4161 + * packet received with IPD_CTL_STATUS[NO_WPTR]. If this is
4162 + * true, we need to free all buffers except for the first
4163 + * one. The caller doesn't expect their WQE pointer to be
4166 + start_of_buffer = ((buffer_ptr.s.addr >> 7) - buffer_ptr.s.back) << 7;
4167 + if (cvmx_ptr_to_phys(work) == start_of_buffer) {
4169 + *(cvmx_buf_ptr_t *) cvmx_phys_to_ptr(buffer_ptr.s.addr - 8);
4170 + buffer_ptr = next_buffer_ptr;
4174 + while (number_buffers--) {
4176 + * Remember the back pointer is in cache lines, not
4180 + ((buffer_ptr.s.addr >> 7) - buffer_ptr.s.back) << 7;
4182 + * Read pointer to next buffer before we free the
4186 + *(cvmx_buf_ptr_t *) cvmx_phys_to_ptr(buffer_ptr.s.addr - 8);
4187 + cvmx_fpa_free(cvmx_phys_to_ptr(start_of_buffer),
4188 + buffer_ptr.s.pool, 0);
4189 + buffer_ptr = next_buffer_ptr;
4193 +#endif /* CVMX_ENABLE_HELPER_FUNCTIONS */
4196 + * Returns the interface number for an IPD/PKO port number.
4198 + * @ipd_port: IPD/PKO port number
4200 + * Returns Interface number
4202 +extern int cvmx_helper_get_interface_num(int ipd_port);
4205 + * Returns the interface index number for an IPD/PKO port
4208 + * @ipd_port: IPD/PKO port number
4210 + * Returns Interface index number
4212 +extern int cvmx_helper_get_interface_index_num(int ipd_port);
4215 + * Initialize the internal QLM JTAG logic to allow programming
4216 + * of the JTAG chain by the cvmx_helper_qlm_jtag_*() functions.
4217 + * These functions should only be used at the direction of Cavium
4218 + * Networks. Programming incorrect values into the JTAG chain
4219 + * can cause chip damage.
4221 +extern void cvmx_helper_qlm_jtag_init(void);
4224 + * Write up to 32bits into the QLM jtag chain. Bits are shifted
4225 + * into the MSB and out the LSB, so you should shift in the low
4226 + * order bits followed by the high order bits. The JTAG chain is
4227 + * 4 * 268 bits long, or 1072.
4229 + * @qlm: QLM to shift value into
4230 + * @bits: Number of bits to shift in (1-32).
4231 + * @data: Data to shift in. Bit 0 enters the chain first, followed by
4234 + * Returns The low order bits of the JTAG chain that shifted out of the
4237 +extern uint32_t cvmx_helper_qlm_jtag_shift(int qlm, int bits, uint32_t data);
4240 + * Shift long sequences of zeros into the QLM JTAG chain. It is
4241 + * common to need to shift more than 32 bits of zeros into the
4242 + * chain. This function is a convience wrapper around
4243 + * cvmx_helper_qlm_jtag_shift() to shift more than 32 bits of
4244 + * zeros at a time.
4246 + * @qlm: QLM to shift zeros into
4249 +extern void cvmx_helper_qlm_jtag_shift_zeros(int qlm, int bits);
4252 + * Program the QLM JTAG chain into all lanes of the QLM. You must
4253 + * have already shifted in 268*4, or 1072 bits into the JTAG
4254 + * chain. Updating invalid values can possibly cause chip damage.
4256 + * @qlm: QLM to program
4258 +extern void cvmx_helper_qlm_jtag_update(int qlm);
4260 +#endif /* __CVMX_HELPER_H__ */
4261 diff --git a/arch/mips/include/asm/octeon/cvmx-packet.h b/arch/mips/include/asm/octeon/cvmx-packet.h
4262 index 38aefa1..1cb3419 100644
4263 --- a/arch/mips/include/asm/octeon/cvmx-packet.h
4264 +++ b/arch/mips/include/asm/octeon/cvmx-packet.h
4266 * Contact Cavium Networks for more information
4267 ***********************license end**************************************/
4272 * Packet buffer defines.
4275 @@ -39,18 +40,23 @@ union cvmx_buf_ptr {
4279 - /* if set, invert the "free" pick of the overall
4281 + * If set, invert the "free" pick of the overall
4282 * packet. HW always sets this bit to 0 on inbound
4288 - /* Indicates the amount to back up to get to the
4290 + * Indicates the amount to back up to get to the
4291 * buffer start in cache lines. In most cases this is
4292 * less than one complete cache line, so the value is
4297 /* The pool that the buffer came from / goes to */
4300 /* The size of the segment pointed to by addr (in bytes) */
4302 /* Pointer to the first byte of the data, NOT buffer */
4303 diff --git a/arch/mips/include/asm/octeon/cvmx-pcie.h b/arch/mips/include/asm/octeon/cvmx-pcie.h
4304 new file mode 100644
4305 index 0000000..55a5ac1
4307 +++ b/arch/mips/include/asm/octeon/cvmx-pcie.h
4309 +/***********************license start***************
4310 + * Author: Cavium Networks
4312 + * Contact: support@caviumnetworks.com
4313 + * This file is part of the OCTEON SDK
4315 + * Copyright (c) 2003-2008 Cavium Networks
4317 + * This file is free software; you can redistribute it and/or modify
4318 + * it under the terms of the GNU General Public License, Version 2, as
4319 + * published by the Free Software Foundation.
4321 + * This file is distributed in the hope that it will be useful, but
4322 + * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
4323 + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
4324 + * NONINFRINGEMENT. See the GNU General Public License for more
4327 + * You should have received a copy of the GNU General Public License
4328 + * along with this file; if not, write to the Free Software
4329 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4330 + * or visit http://www.gnu.org/licenses/.
4332 + * This file may also be available under a different license from Cavium.
4333 + * Contact Cavium Networks for more information
4334 + ***********************license end**************************************/
4339 + * Interface to PCIe as a host(RC) or target(EP)
4343 +#ifndef __CVMX_PCIE_H__
4344 +#define __CVMX_PCIE_H__
4346 +union cvmx_pcie_address {
4349 + uint64_t upper:2; /* Normally 2 for XKPHYS */
4350 + uint64_t reserved_49_61:13; /* Must be zero */
4351 + uint64_t io:1; /* 1 for IO space access */
4352 + uint64_t did:5; /* PCIe DID = 3 */
4353 + uint64_t subdid:3; /* PCIe SubDID = 1 */
4354 + uint64_t reserved_36_39:4; /* Must be zero */
4355 + uint64_t es:2; /* Endian swap = 1 */
4356 + uint64_t port:2; /* PCIe port 0,1 */
4357 + uint64_t reserved_29_31:3; /* Must be zero */
4359 + * Selects the type of the configuration request (0 = type 0,
4363 + /* Target bus number sent in the ID in the request. */
4366 + * Target device number sent in the ID in the
4367 + * request. Note that Dev must be zero for type 0
4368 + * configuration requests.
4371 + /* Target function number sent in the ID in the request. */
4374 + * Selects a register in the configuration space of
4380 + uint64_t upper:2; /* Normally 2 for XKPHYS */
4381 + uint64_t reserved_49_61:13; /* Must be zero */
4382 + uint64_t io:1; /* 1 for IO space access */
4383 + uint64_t did:5; /* PCIe DID = 3 */
4384 + uint64_t subdid:3; /* PCIe SubDID = 2 */
4385 + uint64_t reserved_36_39:4; /* Must be zero */
4386 + uint64_t es:2; /* Endian swap = 1 */
4387 + uint64_t port:2; /* PCIe port 0,1 */
4388 + uint64_t address:32; /* PCIe IO address */
4391 + uint64_t upper:2; /* Normally 2 for XKPHYS */
4392 + uint64_t reserved_49_61:13; /* Must be zero */
4393 + uint64_t io:1; /* 1 for IO space access */
4394 + uint64_t did:5; /* PCIe DID = 3 */
4395 + uint64_t subdid:3; /* PCIe SubDID = 3-6 */
4396 + uint64_t reserved_36_39:4; /* Must be zero */
4397 + uint64_t address:36; /* PCIe Mem address */
4402 + * Return the Core virtual base address for PCIe IO access. IOs are
4403 + * read/written as an offset from this address.
4405 + * @pcie_port: PCIe port the IO is for
4407 + * Returns 64bit Octeon IO base address for read/write
4409 +uint64_t cvmx_pcie_get_io_base_address(int pcie_port);
4412 + * Size of the IO address region returned at address
4413 + * cvmx_pcie_get_io_base_address()
4415 + * @pcie_port: PCIe port the IO is for
4417 + * Returns Size of the IO window
4419 +uint64_t cvmx_pcie_get_io_size(int pcie_port);
4422 + * Return the Core virtual base address for PCIe MEM access. Memory is
4423 + * read/written as an offset from this address.
4425 + * @pcie_port: PCIe port the IO is for
4427 + * Returns 64bit Octeon IO base address for read/write
4429 +uint64_t cvmx_pcie_get_mem_base_address(int pcie_port);
4432 + * Size of the Mem address region returned at address
4433 + * cvmx_pcie_get_mem_base_address()
4435 + * @pcie_port: PCIe port the IO is for
4437 + * Returns Size of the Mem window
4439 +uint64_t cvmx_pcie_get_mem_size(int pcie_port);
4442 + * Initialize a PCIe port for use in host(RC) mode. It doesn't
4443 + * enumerate the bus.
4445 + * @pcie_port: PCIe port to initialize
4447 + * Returns Zero on success
4449 +int cvmx_pcie_rc_initialize(int pcie_port);
4452 + * Shutdown a PCIe port and put it in reset
4454 + * @pcie_port: PCIe port to shutdown
4456 + * Returns Zero on success
4458 +int cvmx_pcie_rc_shutdown(int pcie_port);
4461 + * Read 8bits from a Device's config space
4463 + * @pcie_port: PCIe port the device is on
4466 + * @fn: Device sub function
4467 + * @reg: Register to access
4469 + * Returns Result of the read
4471 +uint8_t cvmx_pcie_config_read8(int pcie_port, int bus, int dev, int fn,
4475 + * Read 16bits from a Device's config space
4477 + * @pcie_port: PCIe port the device is on
4480 + * @fn: Device sub function
4481 + * @reg: Register to access
4483 + * Returns Result of the read
4485 +uint16_t cvmx_pcie_config_read16(int pcie_port, int bus, int dev, int fn,
4489 + * Read 32bits from a Device's config space
4491 + * @pcie_port: PCIe port the device is on
4494 + * @fn: Device sub function
4495 + * @reg: Register to access
4497 + * Returns Result of the read
4499 +uint32_t cvmx_pcie_config_read32(int pcie_port, int bus, int dev, int fn,
4503 + * Write 8bits to a Device's config space
4505 + * @pcie_port: PCIe port the device is on
4508 + * @fn: Device sub function
4509 + * @reg: Register to access
4510 + * @val: Value to write
4512 +void cvmx_pcie_config_write8(int pcie_port, int bus, int dev, int fn, int reg,
4516 + * Write 16bits to a Device's config space
4518 + * @pcie_port: PCIe port the device is on
4521 + * @fn: Device sub function
4522 + * @reg: Register to access
4523 + * @val: Value to write
4525 +void cvmx_pcie_config_write16(int pcie_port, int bus, int dev, int fn, int reg,
4529 + * Write 32bits to a Device's config space
4531 + * @pcie_port: PCIe port the device is on
4534 + * @fn: Device sub function
4535 + * @reg: Register to access
4536 + * @val: Value to write
4538 +void cvmx_pcie_config_write32(int pcie_port, int bus, int dev, int fn, int reg,
4542 + * Read a PCIe config space register indirectly. This is used for
4543 + * registers of the form PCIEEP_CFG??? and PCIERC?_CFG???.
4545 + * @pcie_port: PCIe port to read from
4546 + * @cfg_offset: Address to read
4548 + * Returns Value read
4550 +uint32_t cvmx_pcie_cfgx_read(int pcie_port, uint32_t cfg_offset);
4553 + * Write a PCIe config space register indirectly. This is used for
4554 + * registers of the form PCIEEP_CFG??? and PCIERC?_CFG???.
4556 + * @pcie_port: PCIe port to write to
4557 + * @cfg_offset: Address to write
4558 + * @val: Value to write
4560 +void cvmx_pcie_cfgx_write(int pcie_port, uint32_t cfg_offset, uint32_t val);
4563 + * Write a 32bit value to the Octeon NPEI register space
4565 + * @address: Address to write to
4566 + * @val: Value to write
4568 +static inline void cvmx_pcie_npei_write32(uint64_t address, uint32_t val)
4570 + cvmx_write64_uint32(address ^ 4, val);
4571 + cvmx_read64_uint32(address ^ 4);
4575 + * Read a 32bit value from the Octeon NPEI register space
4577 + * @address: Address to read
4578 + * Returns The result
4580 +static inline uint32_t cvmx_pcie_npei_read32(uint64_t address)
4582 + return cvmx_read64_uint32(address ^ 4);
4586 + * Initialize a PCIe port for use in target(EP) mode.
4588 + * Returns Zero on success
4590 +int cvmx_pcie_ep_initialize(void);
4593 diff --git a/arch/mips/include/asm/octeon/cvmx-wqe.h b/arch/mips/include/asm/octeon/cvmx-wqe.h
4594 new file mode 100644
4595 index 0000000..fadc700
4597 +++ b/arch/mips/include/asm/octeon/cvmx-wqe.h
4599 +/***********************license start***************
4600 + * Author: Cavium Networks
4602 + * Contact: support@caviumnetworks.com
4603 + * This file is part of the OCTEON SDK
4605 + * Copyright (c) 2003-2008 Cavium Networks
4607 + * This file is free software; you can redistribute it and/or modify
4608 + * it under the terms of the GNU General Public License, Version 2, as
4609 + * published by the Free Software Foundation.
4611 + * This file is distributed in the hope that it will be useful, but
4612 + * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
4613 + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
4614 + * NONINFRINGEMENT. See the GNU General Public License for more
4617 + * You should have received a copy of the GNU General Public License
4618 + * along with this file; if not, write to the Free Software
4619 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4620 + * or visit http://www.gnu.org/licenses/.
4622 + * This file may also be available under a different license from Cavium.
4623 + * Contact Cavium Networks for more information
4624 + ***********************license end**************************************/
4628 + * This header file defines the work queue entry (wqe) data structure.
4629 + * Since this is a commonly used structure that depends on structures
4630 + * from several hardware blocks, those definitions have been placed
4631 + * in this file to create a single point of definition of the wqe
4634 + * Data structures are still named according to the block that they
4639 +#ifndef __CVMX_WQE_H__
4640 +#define __CVMX_WQE_H__
4642 +#include "cvmx-packet.h"
4644 +#define OCT_TAG_TYPE_STRING(x) ( \
4648 + case CVMX_POW_TAG_TYPE_ORDERED: \
4651 + case CVMX_POW_TAG_TYPE_ATOMIC: \
4654 + case CVMX_POW_TAG_TYPE_NULL: \
4658 + r = "NULL_NULL"; \
4665 + * HW decode / err_code in work queue entry
4667 +union cvmx_pip_wqe_word2{
4670 + /* Use this struct if the hardware determines that the packet is IP */
4672 + /* HW sets this to the number of buffers used by this packet */
4674 + /* HW sets to the number of L2 bytes prior to the IP */
4675 + uint64_t ip_offset:8;
4676 + /* Set to 1 if we found VLAN in the L2 */
4677 + uint64_t vlan_valid:1;
4678 + uint64_t unassigned:2;
4679 + /* HW sets to the VLAN CFI flag (valid when vlan_valid) */
4680 + uint64_t vlan_cfi:1;
4681 + /* HW sets to the VLAN_ID field (valid when vlan_valid) */
4682 + uint64_t vlan_id:12;
4684 + uint64_t unassigned2:12;
4685 + /* The packet needs to be decompressed */
4686 + uint64_t dec_ipcomp:1;
4687 + /* The packet is either TCP or UDP */
4688 + uint64_t tcp_or_udp:1;
4689 + /* The packet needs to be decrypted (ESP or AH) */
4690 + uint64_t dec_ipsec:1;
4691 + /* The packet is IPv6 */
4695 + * rcv_error, not_IP, IP_exc, is_frag, L4_error,
4700 + * Reserved for software use, hardware will clear on
4701 + * packet creation.
4703 + uint64_t software:1;
4704 + /* exceptional conditions below. */
4707 + * The receive interface hardware detected an L4 error
4708 + * (only applies if !is_frag) (only applies if
4709 + * !rcv_error && !not_IP && !IP_exc && !is_frag)
4710 + * failure indicated in err_code below, decode:
4712 + * - 1 = Malformed L4
4714 + * - 2 = L4 Checksum Error: the L4 checksum value is
4716 + * - 3 = UDP Length Error: The UDP length field would
4717 + * make the UDP data longer than what remains in
4718 + * the IP packet (as defined by the IP header
4721 + * - 4 = Bad L4 Port: either the source or destination
4722 + * TCP/UDP port is 0.
4724 + * - 8 = TCP FIN Only: the packet is TCP and only the
4727 + * - 9 = TCP No Flags: the packet is TCP and no flags
4730 + * - 10 = TCP FIN RST: the packet is TCP and both FIN
4731 + * and RST are set.
4733 + * - 11 = TCP SYN URG: the packet is TCP and both SYN
4734 + * and URG are set.
4736 + * - 12 = TCP SYN RST: the packet is TCP and both SYN
4737 + * and RST are set.
4739 + * - 13 = TCP SYN FIN: the packet is TCP and both SYN
4740 + * and FIN are set.
4743 + uint64_t L4_error:1;
4744 + /* Set if the packet is a fragment */
4745 + uint64_t is_frag:1;
4748 + * The receive interface hardware detected an IP error
4749 + * / exception (only applies if !rcv_error && !not_IP)
4750 + * failure indicated in err_code below, decode:
4752 + * - 1 = Not IP: the IP version field is neither 4 nor
4755 + * - 2 = IPv4 Header Checksum Error: the IPv4 header
4756 + * has a checksum violation.
4758 + * - 3 = IP Malformed Header: the packet is not long
4759 + * enough to contain the IP header.
4761 + * - 4 = IP Malformed: the packet is not long enough
4762 + * to contain the bytes indicated by the IP
4763 + * header. Pad is allowed.
4765 + * - 5 = IP TTL Hop: the IPv4 TTL field or the IPv6
4766 + * Hop Count field are zero.
4768 + * - 6 = IP Options.
4770 + uint64_t IP_exc:1;
4772 + * Set if the hardware determined that the packet is a
4775 + uint64_t is_bcast:1;
4777 + * Set if the hardware determined that the packet is a
4780 + uint64_t is_mcast:1;
4782 + * Set if the packet may not be IP (must be zero in
4785 + uint64_t not_IP:1;
4787 + * The receive interface hardware detected a receive
4788 + * error (must be zero in this case)
4790 + * lower err_code = first-level descriptor of the work
4792 + * zero for packet submitted by hardware that isn't on
4795 + uint64_t rcv_error:1;
4797 + /* Type is cvmx_pip_err_t */
4798 + uint64_t err_code:8;
4801 + /* Use this to get at the 16 vlan bits */
4803 + uint64_t unused1:16;
4805 + uint64_t unused2:32;
4809 + * Use this struct if the hardware could not determine that
4810 + * the packet is ip.
4813 + /* HW sets this to the number of buffers used by this packet. */
4815 + uint64_t unused:8;
4816 + /* Set to 1 if we found VLAN in the L2. */
4817 + uint64_t vlan_valid:1;
4818 + uint64_t unassigned:2;
4819 + /* HW sets to the VLAN CFI flag (valid when vlan_valid). */
4820 + uint64_t vlan_cfi:1;
4821 + /* HW sets to the VLAN_ID field (valid when vlan_valid). */
4822 + uint64_t vlan_id:12;
4824 + uint64_t unassigned2:16;
4826 + * Reserved for software use, hardware will clear on
4827 + * packet creation.
4829 + uint64_t software:1;
4830 + uint64_t unassigned3:1;
4831 + /* Set if the hardware determined that the packet is rarp. */
4832 + uint64_t is_rarp:1;
4833 + /* Set if the hardware determined that the packet is arp. */
4834 + uint64_t is_arp:1;
4836 + * Set if the hardware determined that the packet is a
4839 + uint64_t is_bcast:1;
4841 + * Set if the hardware determined that the packet is a
4844 + uint64_t is_mcast:1;
4846 + * Set if the packet may not be IP (must be one in
4849 + uint64_t not_IP:1;
4851 + * The receive interface hardware detected a receive
4852 + * error. Failure indicated in err_code below, decode:
4854 + * - 1 = partial error: a packet was partially
4855 + * received, but internal buffering / bandwidth
4856 + * was not adequate to receive the entire
4859 + * - 2 = jabber error: the RGMII packet was too large
4860 + * and is truncated.
4862 + * - 3 = overrun error: the RGMII packet is longer
4863 + * than allowed and had an FCS error.
4865 + * - 4 = oversize error: the RGMII packet is longer
4868 + * - 5 = alignment error: the RGMII packet is not an
4869 + * integer number of bytes and had an FCS error
4870 + * (100M and 10M only).
4872 + * - 6 = fragment error: the RGMII packet is shorter
4873 + * than allowed and had an FCS error.
4875 + * - 7 = GMX FCS error: the RGMII packet had an FCS
4878 + * - 8 = undersize error: the RGMII packet is shorter
4881 + * - 9 = extend error: the RGMII packet had an extend
4884 + * - 10 = length mismatch error: the RGMII packet had
4885 + * a length that did not match the length field
4888 + * - 11 = RGMII RX error/SPI4 DIP4 Error: the RGMII
4889 + * packet had one or more data reception errors
4890 + * (RXERR) or the SPI4 packet had one or more
4893 + * - 12 = RGMII skip error/SPI4 Abort Error: the RGMII
4894 + * packet was not large enough to cover the
4895 + * skipped bytes or the SPI4 packet was
4896 + * terminated with an About EOPS.
4898 + * - 13 = RGMII nibble error/SPI4 Port NXA Error: the
4899 + * RGMII packet had a studder error (data not
4900 + * repeated - 10/100M only) or the SPI4 packet
4901 + * was sent to an NXA.
4903 + * - 16 = FCS error: a SPI4.2 packet had an FCS error.
4905 + * - 17 = Skip error: a packet was not large enough to
4906 + * cover the skipped bytes.
4908 + * - 18 = L2 header malformed: the packet is not long
4909 + * enough to contain the L2
4913 + * lower err_code = first-level descriptor of the
4916 + * zero for packet submitted by hardware that isn't on
4919 + uint64_t rcv_error:1;
4921 + /* Type is cvmx_pip_err_t (union, so can't use directly. */
4922 + uint64_t err_code:8;
4928 + * Work queue entry format
4930 + * must be 8-byte aligned
4934 + /*****************************************************************
4936 + * HW WRITE: the following 64 bits are filled by HW when a packet arrives
4940 + * raw chksum result generated by the HW
4942 + uint16_t hw_chksum;
4944 + * Field unused by hardware - available for software
4948 + * Next pointer used by hardware for list maintenance.
4949 + * May be written/read by HW before the work queue
4950 + * entry is scheduled to a PP
4951 + * (Only 36 bits used in Octeon 1)
4953 + uint64_t next_ptr:40;
4955 + /*****************************************************************
4957 + * HW WRITE: the following 64 bits are filled by HW when a packet arrives
4961 + * HW sets to the total number of bytes in the packet
4965 + * HW sets this to input physical port
4970 + * HW sets this to what it thought the priority of the input packet was
4975 + * the group that the work queue entry will be scheduled to
4979 + * the type of the tag (ORDERED, ATOMIC, NULL)
4981 + uint64_t tag_type:3;
4983 + * the synchronization/ordering tag
4988 + * WORD 2 HW WRITE: the following 64-bits are filled in by
4989 + * hardware when a packet arrives This indicates a variety of
4990 + * status and error conditions.
4992 + union cvmx_pip_wqe_word2 word2;
4995 + * Pointer to the first segment of the packet.
4997 + union cvmx_buf_ptr packet_ptr;
5000 + * HW WRITE: octeon will fill in a programmable amount from the
5001 + * packet, up to (at most, but perhaps less) the amount
5002 + * needed to fill the work queue entry to 128 bytes
5003 + * If the packet is recognized to be IP, the hardware starts (except that
5004 + * the IPv4 header is padded for appropriate alignment) writing here where
5005 + * the IP header starts.
5006 + * If the packet is not recognized to be IP, the hardware starts writing
5007 + * the beginning of the packet here.
5009 + uint8_t packet_data[96];
5012 + * If desired, SW can make the work Q entry any length. For the
5013 + * purposes of discussion here, Assume 128B always, as this is all that
5014 + * the hardware deals with.
5018 +} CVMX_CACHE_LINE_ALIGNED;
5020 +#endif /* __CVMX_WQE_H__ */
5021 diff --git a/arch/mips/include/asm/octeon/cvmx.h b/arch/mips/include/asm/octeon/cvmx.h
5022 index 03fddfa..e31e3fe 100644
5023 --- a/arch/mips/include/asm/octeon/cvmx.h
5024 +++ b/arch/mips/include/asm/octeon/cvmx.h
5025 @@ -376,6 +376,18 @@ static inline uint64_t cvmx_get_cycle(void)
5029 + * Wait for the specified number of cycle
5032 +static inline void cvmx_wait(uint64_t cycles)
5034 + uint64_t done = cvmx_get_cycle() + cycles;
5036 + while (cvmx_get_cycle() < done)
5041 * Reads a chip global cycle counter. This counts CPU cycles since
5042 * chip reset. The counter is 64 bit.
5043 * This register does not exist on CN38XX pass 1 silicion
5044 diff --git a/arch/mips/include/asm/octeon/octeon.h b/arch/mips/include/asm/octeon/octeon.h
5045 index edc6760..cac9b1a 100644
5046 --- a/arch/mips/include/asm/octeon/octeon.h
5047 +++ b/arch/mips/include/asm/octeon/octeon.h
5048 @@ -245,4 +245,6 @@ static inline uint32_t octeon_npi_read32(uint64_t address)
5049 return cvmx_read64_uint32(address ^ 4);
5052 +extern struct cvmx_bootinfo *octeon_bootinfo;
5054 #endif /* __ASM_OCTEON_OCTEON_H */