mips: Add Octeon DDR4 init code
v3 cover mips: Add Octeon DDR4 init code
This patch adds the DDR4 init code. It is ported from the 2013 Cavium / Marvell U-Boot version with no functional change. This was done intentionally, as this code is very large and complex and is known to work on many boards "as-is". So any functional change might have introduced (hidden) incompatibilities.
Please note that the code has undergone many hours (read many days) of code cleanup and restructuring. Unfortunately its still not 100% checkpatch clean, as some warnings and checks can practically not be removed / addresses, like these here:
CHECK: Prefer kernel type 's8' over 'int8_t'
-> 's8' can't be used on MIPS platforms, as its a register macro
or:
WARNING: Too many leading tabs - consider code refactoring
+ while (xor != 0) {
-> I've restructured the code already and its very hard to remove all
these "Too many leading tabs" warnings.
or other warnings / checks.
But compared to the original code in much better shape (checkpatch wise). I would have liked to include a checkpatch summary in this cover- letter, showing the "before" (original code) and "after" (this code) numbers, but unfortunately currently running checkpatch on the really big file (octeon3_lmc.c) leads to many false errors. I can only suspect that checkpatch has an issue handling this big file because of its size.
This code is tested on the Octeon3 EBB7304 EVK and works without any known issues with 1 or 2 DDR4 DIMM configurations (8 & 16 GiB).
Thanks,
Stefan
Changes in v3:
- Remove "https://spdx.org/licenses" line
- Move multiple comment blocks into one
- Remove "https://spdx.org/licenses" line
- Remove "https://spdx.org/licenses" line
- Remove inclusion of "common.h"
- Remove duplicate comment line
- Remove "test-only" comment (leftover after cleanup)
- Remove "https://spdx.org/licenses" line
- Remove inclusion of "common.h"
- Remove all internal defines that resulted in dead code, as they have never been changed via external config files or Kconfig. This results in a smaller (~13KiB of source code saved, > 450 lines removed) and much cleaner code base.
- Remove "https://spdx.org/licenses" line
- Remove "https://spdx.org/licenses" line
- Remove inclusion of "common.h"
Changes in v2:
- Some unsupported Octeon families removed (only Octeon 2 & 3 supported in general)
- Some unsupported Octeon families removed (only Octeon 2 & 3 supported in general)
- Use readq/writeq in cvmx_read64_uint64/cvmx_write64_uint64 instead of readl/writel
- Don't re-init after relocation
- Some unsupported Octeon families removed (only Octeon 2 & 3 supported in general)
- Only map 256MiB of RAM in U-Boot and print total size as well
- Add year to copyright line
Aaron Williams (6):
mips: octeon: Add octeon-model.h header
mips: octeon Add cvmx/cvmx-lmcx-defs.h header
mips: octeon: Add octeon_ddr.h header
ram: octeon: Add MIPS Octeon3 DDR4 support (part 1/3)
ram: octeon: Add MIPS Octeon3 DDR4 support (part 2/3)
ram: octeon: Add MIPS Octeon3 DDR4 support (part 3/3)
Stefan Roese (3):
mips: octeon: dts: mrvl,cn73xx.dtsi: Add memory controller DT node
mips: octeon: dram.c: Add RAM driver support
mips: octeon: octeon_ebb7304: Add DDR4 support
arch/mips/dts/mrvl,cn73xx.dtsi | 17 + arch/mips/mach-octeon/dram.c | 72 +- .../include/mach/cvmx/cvmx-lmcx-defs.h | 4574 +++++++ .../mach-octeon/include/mach/octeon-model.h | 313 + .../mach-octeon/include/mach/octeon_ddr.h | 982 ++ board/Marvell/octeon_ebb7304/board.c | 25 +- board/Marvell/octeon_ebb7304/board_ddr.h | 447 + configs/octeon_ebb7304_defconfig | 3 + drivers/ram/Kconfig | 1 + drivers/ram/Makefile | 2 + drivers/ram/octeon/Kconfig | 17 + drivers/ram/octeon/Makefile | 8 + drivers/ram/octeon/dimm_spd_eeprom.c | 407 + drivers/ram/octeon/octeon3_lmc.c | 11030 ++++++++++++++++ drivers/ram/octeon/octeon_ddr.c | 2728 ++++ include/configs/octeon_common.h | 11 +- 16 files changed, 20622 insertions(+), 15 deletions(-) create mode 100644 arch/mips/mach-octeon/include/mach/cvmx/cvmx-lmcx-defs.h create mode 100644 arch/mips/mach-octeon/include/mach/octeon-model.h create mode 100644 arch/mips/mach-octeon/include/mach/octeon_ddr.h create mode 100644 board/Marvell/octeon_ebb7304/board_ddr.h create mode 100644 drivers/ram/octeon/Kconfig create mode 100644 drivers/ram/octeon/Makefile create mode 100644 drivers/ram/octeon/dimm_spd_eeprom.c create mode 100644 drivers/ram/octeon/octeon3_lmc.c create mode 100644 drivers/ram/octeon/octeon_ddr.c
Signature · 1 line
2.28.0
PATCH v3 1/9 mips: octeon: dts: mrvl, cn73xx.dtsi: Add memory controller DT node
This patch adds the memory controller (LMC) DT node to the Octeon 3 dtsi file. It also adds the L2C DT node, as this is referenced by the DDR driver.
---
(no changes since v1)
arch/mips/dts/mrvl,cn73xx.dtsi | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
arch/mips/dts/mrvl,cn73xx.dtsi +17 -0
@@ -72,6 +72,23 @@ <0x0300e 4>, <0x0300f 4>; }; + l2c: l2c at 1180080000000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "cavium,octeon-7xxx-l2c"; + reg = <0x11800 0x80000000 0x0 0x01000000>; + u-boot,dm-pre-reloc; + }; + + lmc: lmc at 1180088000000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "cavium,octeon-7xxx-ddr4"; + reg = <0x11800 0x88000000 0x0 0x02000000>; // 2 IFs + u-boot,dm-pre-reloc; + l2c-handle = <&l2c>; + }; + reset: reset at 1180006001600 { compatible = "mrvl,cn7xxx-rst"; reg = <0x11800 0x06001600 0x0 0x200>;
Signature · 1 line
2.28.0
PATCH v3 2/9 mips: octeon: Add octeon-model.h header
In reply to Stefan RoeseFrom: Aaron Williams <[email protected]>
This header is used by the upcoming DDR driver and potentially by other drivers ported from the 2013 Cavium / Marvell U-Boot repository.
---
Changes in v3:
- Remove "https://spdx.org/licenses" line
- Move multiple comment blocks into one
Changes in v2:
- Some unsupported Octeon families removed (only Octeon 2 & 3 supported in general)
.../mach-octeon/include/mach/octeon-model.h | 313 ++++++++++++++++++ 1 file changed, 313 insertions(+) create mode 100644 arch/mips/mach-octeon/include/mach/octeon-model.h
arch/mips/mach-octeon/include/mach/octeon-model.h new file +313 -0
@@ -0,0 +1,313 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020 Marvell International Ltd. +*/ + +#ifndef __OCTEON_MODEL_H__ +#define __OCTEON_MODEL_H__ + +/* +* NOTE: These must match what is checked in common-config.mk +* Defines to represent the different versions of Octeon. +* +* IMPORTANT: When the default pass is updated for an Octeon Model, +* the corresponding change must also be made in the oct-sim script. +* +* The defines below should be used with the OCTEON_IS_MODEL() macro to +* determine what model of chip the software is running on. Models ending +* in 'XX' match multiple models (families), while specific models match only +* that model. If a pass (revision) is specified, then only that revision +* will be matched. Care should be taken when checking for both specific +* models and families that the specific models are checked for first. +* While these defines are similar to the processor ID, they are not intended +* to be used by anything other that the OCTEON_IS_MODEL framework, and +* the values are subject to change at anytime without notice. +* +* NOTE: only the OCTEON_IS_MODEL() macro/function and the OCTEON_CN* macros +* should be used outside of this file. All other macros are for internal +* use only, and may change without notice. +*/ + +#define OCTEON_FAMILY_MASK 0x00ffff00 +#define OCTEON_PRID_MASK 0x00ffffff + +/* Flag bits in top byte */ +/* Ignores revision in model checks */ +#define OM_IGNORE_REVISION 0x01000000 +/* Check submodels */ +#define OM_CHECK_SUBMODEL 0x02000000 +/* Match all models previous than the one specified */ +#define OM_MATCH_PREVIOUS_MODELS 0x04000000 +/* Ignores the minor revison on newer parts */ +#define OM_IGNORE_MINOR_REVISION 0x08000000 +#define OM_FLAG_MASK 0xff000000 + +/* Match all cn5XXX Octeon models. */ +#define OM_MATCH_5XXX_FAMILY_MODELS 0x20000000 +/* Match all cn6XXX Octeon models. */ +#define OM_MATCH_6XXX_FAMILY_MODELS 0x40000000 +/* Match all cnf7XXX Octeon models. */ +#define OM_MATCH_F7XXX_FAMILY_MODELS 0x80000000 +/* Match all cn7XXX Octeon models. */ +#define OM_MATCH_7XXX_FAMILY_MODELS 0x10000000 +#define OM_MATCH_FAMILY_MODELS (OM_MATCH_5XXX_FAMILY_MODELS | \ + OM_MATCH_6XXX_FAMILY_MODELS | \ + OM_MATCH_F7XXX_FAMILY_MODELS | \ + OM_MATCH_7XXX_FAMILY_MODELS) + +/* +* CN7XXX models with new revision encoding +*/ + +#define OCTEON_CNF75XX_PASS1_0 0x000d9800 +#define OCTEON_CNF75XX_PASS1_2 0x000d9802 +#define OCTEON_CNF75XX_PASS1_3 0x000d9803 +#define OCTEON_CNF75XX (OCTEON_CNF75XX_PASS1_0 | OM_IGNORE_REVISION) +#define OCTEON_CNF75XX_PASS1_X \ + (OCTEON_CNF75XX_PASS1_0 | OM_IGNORE_MINOR_REVISION) + +#define OCTEON_CN73XX_PASS1_0 0x000d9700 +#define OCTEON_CN73XX_PASS1_1 0x000d9701 +#define OCTEON_CN73XX_PASS1_2 0x000d9702 +#define OCTEON_CN73XX_PASS1_3 0x000d9703 +#define OCTEON_CN73XX (OCTEON_CN73XX_PASS1_0 | OM_IGNORE_REVISION) +#define OCTEON_CN73XX_PASS1_X \ + (OCTEON_CN73XX_PASS1_0 | OM_IGNORE_MINOR_REVISION) + +#define OCTEON_CN72XX OCTEON_CN73XX + +#define OCTEON_CN23XX OCTEON_CN73XX +#define OCTEON_CN23XX_PASS1_2 OCTEON_CN73XX_PASS1_2 +#define OCTEON_CN23XX_PASS1_3 OCTEON_CN73XX_PASS1_3 + +#define OCTEON_CN70XX_PASS1_0 0x000d9600 +#define OCTEON_CN70XX_PASS1_1 0x000d9601 +#define OCTEON_CN70XX_PASS1_2 0x000d9602 + +#define OCTEON_CN70XX_PASS2_0 0x000d9608 + +#define OCTEON_CN70XX (OCTEON_CN70XX_PASS1_0 | OM_IGNORE_REVISION) +#define OCTEON_CN70XX_PASS1_X \ + (OCTEON_CN70XX_PASS1_0 | OM_IGNORE_MINOR_REVISION) +#define OCTEON_CN70XX_PASS2_X \ + (OCTEON_CN70XX_PASS2_0 | OM_IGNORE_MINOR_REVISION) + +#define OCTEON_CN71XX OCTEON_CN70XX + +#define OCTEON_CN78XX_PASS1_0 0x000d9500 +#define OCTEON_CN78XX_PASS1_1 0x000d9501 +#define OCTEON_CN78XX_PASS2_0 0x000d9508 + +#define OCTEON_CN78XX (OCTEON_CN78XX_PASS2_0 | OM_IGNORE_REVISION) +#define OCTEON_CN78XX_PASS1_X \ + (OCTEON_CN78XX_PASS1_0 | OM_IGNORE_MINOR_REVISION) +#define OCTEON_CN78XX_PASS2_X \ + (OCTEON_CN78XX_PASS2_0 | OM_IGNORE_MINOR_REVISION) + +#define OCTEON_CN76XX (0x000d9540 | OM_CHECK_SUBMODEL) + +/* +* CNF7XXX models with new revision encoding +*/ +#define OCTEON_CNF71XX_PASS1_0 0x000d9400 +#define OCTEON_CNF71XX_PASS1_1 0x000d9401 + +#define OCTEON_CNF71XX (OCTEON_CNF71XX_PASS1_0 | OM_IGNORE_REVISION) +#define OCTEON_CNF71XX_PASS1_X \ + (OCTEON_CNF71XX_PASS1_0 | OM_IGNORE_MINOR_REVISION) + +/* +* CN6XXX models with new revision encoding +*/ +#define OCTEON_CN68XX_PASS1_0 0x000d9100 +#define OCTEON_CN68XX_PASS1_1 0x000d9101 +#define OCTEON_CN68XX_PASS2_0 0x000d9108 +#define OCTEON_CN68XX_PASS2_1 0x000d9109 +#define OCTEON_CN68XX_PASS2_2 0x000d910a + +#define OCTEON_CN68XX (OCTEON_CN68XX_PASS2_0 | OM_IGNORE_REVISION) +#define OCTEON_CN68XX_PASS1_X \ + (OCTEON_CN68XX_PASS1_0 | OM_IGNORE_MINOR_REVISION) +#define OCTEON_CN68XX_PASS2_X \ + (OCTEON_CN68XX_PASS2_0 | OM_IGNORE_MINOR_REVISION) + +#define OCTEON_CN68XX_PASS1 OCTEON_CN68XX_PASS1_X +#define OCTEON_CN68XX_PASS2 OCTEON_CN68XX_PASS2_X + +#define OCTEON_CN66XX_PASS1_0 0x000d9200 +#define OCTEON_CN66XX_PASS1_2 0x000d9202 + +#define OCTEON_CN66XX (OCTEON_CN66XX_PASS1_0 | OM_IGNORE_REVISION) +#define OCTEON_CN66XX_PASS1_X \ + (OCTEON_CN66XX_PASS1_0 | OM_IGNORE_MINOR_REVISION) + +#define OCTEON_CN63XX_PASS1_0 0x000d9000 +#define OCTEON_CN63XX_PASS1_1 0x000d9001 +#define OCTEON_CN63XX_PASS1_2 0x000d9002 +#define OCTEON_CN63XX_PASS2_0 0x000d9008 +#define OCTEON_CN63XX_PASS2_1 0x000d9009 +#define OCTEON_CN63XX_PASS2_2 0x000d900a + +#define OCTEON_CN63XX (OCTEON_CN63XX_PASS2_0 | OM_IGNORE_REVISION) +#define OCTEON_CN63XX_PASS1_X \ + (OCTEON_CN63XX_PASS1_0 | OM_IGNORE_MINOR_REVISION) +#define OCTEON_CN63XX_PASS2_X \ + (OCTEON_CN63XX_PASS2_0 | OM_IGNORE_MINOR_REVISION) + +/* CN62XX is same as CN63XX with 1 MB cache */ +#define OCTEON_CN62XX OCTEON_CN63XX + +#define OCTEON_CN61XX_PASS1_0 0x000d9300 +#define OCTEON_CN61XX_PASS1_1 0x000d9301 + +#define OCTEON_CN61XX (OCTEON_CN61XX_PASS1_0 | OM_IGNORE_REVISION) +#define OCTEON_CN61XX_PASS1_X \ + (OCTEON_CN61XX_PASS1_0 | OM_IGNORE_MINOR_REVISION) + +/* CN60XX is same as CN61XX with 512 KB cache */ +#define OCTEON_CN60XX OCTEON_CN61XX + +/* This matches the complete family of CN3xxx CPUs, and not subsequent models */ +#define OCTEON_CN6XXX \ + (OCTEON_CN63XX_PASS1_0 | OM_MATCH_6XXX_FAMILY_MODELS) +#define OCTEON_CNF7XXX \ + (OCTEON_CNF71XX_PASS1_0 | OM_MATCH_F7XXX_FAMILY_MODELS) +#define OCTEON_CN7XXX \ + (OCTEON_CN78XX_PASS1_0 | OM_MATCH_7XXX_FAMILY_MODELS) + +/* +* The revision byte (low byte) has two different encodings. +* CN3XXX: +* +* bits +* <7:5>: reserved (0) +* <4>: alternate package +* <3:0>: revision +* +* CN5XXX and older models: +* +* bits +* <7>: reserved (0) +* <6>: alternate package +* <5:3>: major revision +* <2:0>: minor revision +*/ + +/* Masks used for the various types of model/family/revision matching */ +#define OCTEON_38XX_FAMILY_MASK 0x00ffff00 +#define OCTEON_38XX_FAMILY_REV_MASK 0x00ffff0f +#define OCTEON_38XX_MODEL_MASK 0x00ffff10 +#define OCTEON_38XX_MODEL_REV_MASK \ + (OCTEON_38XX_FAMILY_REV_MASK | OCTEON_38XX_MODEL_MASK) + +/* CN5XXX and later use different layout of bits in the revision ID field */ +#define OCTEON_58XX_FAMILY_MASK OCTEON_38XX_FAMILY_MASK +#define OCTEON_58XX_FAMILY_REV_MASK 0x00ffff3f +#define OCTEON_58XX_MODEL_MASK 0x00ffff40 +#define OCTEON_58XX_MODEL_REV_MASK \ + (OCTEON_58XX_FAMILY_REV_MASK | OCTEON_58XX_MODEL_MASK) +#define OCTEON_58XX_MODEL_MINOR_REV_MASK \ + (OCTEON_58XX_MODEL_REV_MASK & 0x00ffff38) +#define OCTEON_5XXX_MODEL_MASK 0x00ff0fc0 + +#define __OCTEON_MATCH_MASK__ (X ,Y ,Z ) \ + ({ \ + typeof(X) x = (X); \ + typeof(Y) y = (Y); \ + typeof(Z) z = (Z); \ + (x & z) == (y & z); \ + }) + +/* +* __OCTEON_IS_MODEL_COMPILE__(arg_model, chip_model) +* returns true if chip_model is identical or belong to the OCTEON +* model group specified in arg_model. +*/ + +/* Helper macros to make to following macro compacter */ +#define OM_MASK OM_FLAG_MASK +#define OM_MATCH_MASK __OCTEON_MATCH_MASK__ +#define OM_MATCH_PREVIOUS OM_MATCH_PREVIOUS_MODELS + +#define __OCTEON_IS_MODEL_COMPILE__ (A ,B ) \ + ({ \ + typeof(A) a = (A); \ + typeof(B) b = (B); \ + (((((((a) & OM_MASK) == (OM_IGNORE_REVISION | OM_CHECK_SUBMODEL)) && \ + OM_MATCH_MASK((b), (a), OCTEON_58XX_MODEL_MASK)) || \ + ((((a) & OM_MASK) == 0) && \ + OM_MATCH_MASK((b), (a), OCTEON_58XX_FAMILY_REV_MASK)) || \ + ((((a) & OM_MASK) == OM_IGNORE_MINOR_REVISION) && \ + OM_MATCH_MASK((b), (a), OCTEON_58XX_MODEL_MINOR_REV_MASK)) || \ + ((((a) & OM_MASK) == OM_CHECK_SUBMODEL) && \ + OM_MATCH_MASK((b), (a), OCTEON_58XX_MODEL_MASK)) || \ + ((((a) & OM_MASK) == OM_IGNORE_REVISION) && \ + OM_MATCH_MASK((b), (a), OCTEON_58XX_FAMILY_MASK)) || \ + ((((a) & (OM_MATCH_5XXX_FAMILY_MODELS)) == \ + OM_MATCH_5XXX_FAMILY_MODELS) && \ + ((b & OCTEON_PRID_MASK) < OCTEON_CN63XX_PASS1_0)) || \ + ((((a) & (OM_MATCH_6XXX_FAMILY_MODELS)) == \ + OM_MATCH_6XXX_FAMILY_MODELS) && \ + ((b & OCTEON_PRID_MASK) >= OCTEON_CN63XX_PASS1_0) && \ + ((b & OCTEON_PRID_MASK) < OCTEON_CNF71XX_PASS1_0)) || \ + ((((a) & (OM_MATCH_F7XXX_FAMILY_MODELS)) == \ + OM_MATCH_F7XXX_FAMILY_MODELS) && \ + ((b & OCTEON_PRID_MASK) >= OCTEON_CNF71XX_PASS1_0) && \ + ((b & OCTEON_PRID_MASK) < OCTEON_CN78XX_PASS1_0)) || \ + ((((a) & (OM_MATCH_7XXX_FAMILY_MODELS)) == \ + OM_MATCH_7XXX_FAMILY_MODELS) && ((b & OCTEON_PRID_MASK) >= \ + OCTEON_CN78XX_PASS1_0)) || \ + ((((a) & (OM_MATCH_PREVIOUS)) == OM_MATCH_PREVIOUS) && \ + (((b) & OCTEON_58XX_MODEL_MASK) < ((a) & OCTEON_58XX_MODEL_MASK))) \ + ))); \ + }) + +#ifndef OCTEON_IS_MODEL + +static inline int __octeon_is_model_runtime_internal__ (u32 model) +{ +u32 cpuid =read_c0_prid (); + +return __OCTEON_IS_MODEL_COMPILE__ (model, cpuid); +} + +static inline int __octeon_is_model_runtime__ (u32 model) +{ +return __octeon_is_model_runtime_internal__ (model); +} + +/* +* The OCTEON_IS_MODEL macro should be used for all Octeon model checking done +* in a program. +* This should be kept runtime if@all possible and must be conditionalized +* with OCTEON_IS_COMMON_BINARY() if runtime checking support is required. +* +* Use of the macro in preprocessor directives ( #if OCTEON_IS_MODEL(...) ) +* is NOT SUPPORTED, and should be replaced with CVMX_COMPILED_FOR() +* I.e.: +* #if OCTEON_IS_MODEL(OCTEON_CN56XX) -> #if CVMX_COMPILED_FOR(OCTEON_CN56XX) +*/ +#define OCTEON_IS_MODEL (x) __octeon_is_model_runtime__(x) +#define OCTEON_IS_COMMON_BINARY () 1 +#undef OCTEON_MODEL +#endif + +#define OCTEON_IS_OCTEON2 () \ + (OCTEON_IS_MODEL(OCTEON_CN6XXX) || OCTEON_IS_MODEL(OCTEON_CNF71XX)) + +#define OCTEON_IS_OCTEON3 () OCTEON_IS_MODEL(OCTEON_CN7XXX) + +const char *octeon_model_get_string (u32 chip_id); +const char *octeon_model_get_string_buffer (u32 chip_id,char *buffer); + +/** +* Return the octeon family, i.e., ProcessorID of the PrID register. +* +* @return the octeon family on success, ((u32)-1) on error. +*/ +static inline u32 cvmx_get_octeon_family (void ) +{ +return (read_c0_prid () &OCTEON_FAMILY_MASK ); +} + +#endif /* __OCTEON_MODEL_H__ */
Signature · 1 line
2.28.0
PATCH v3 3/9 mips: octeon Add cvmx/cvmx-lmcx-defs.h header
In reply to Stefan RoeseFrom: Aaron Williams <[email protected]>
This header will be used by the DDR driver (lmc). Its ported from the 2013 Cavium / Marvell U-Boot repository.
---
Changes in v3:
- Remove "https://spdx.org/licenses" line
Changes in v2:
- Some unsupported Octeon families removed (only Octeon 2 & 3 supported in general)
.../include/mach/cvmx/cvmx-lmcx-defs.h | 4574 +++++++++++++++++ 1 file changed, 4574 insertions(+) create mode 100644 arch/mips/mach-octeon/include/mach/cvmx/cvmx-lmcx-defs.h
arch/mips/mach-octeon/include/mach/cvmx/cvmx-lmcx-defs.h new file +4574 -0
@@ -0,0 +1,4574 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020 Marvell International Ltd. +*/ + +#ifndef __CVMX_LMCX_DEFS_H__ +#define __CVMX_LMCX_DEFS_H__ + +#define CVMX_LMCX_BANK_CONFLICT1(offs) \ + ((0x000360ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_BANK_CONFLICT2(offs) \ + ((0x000368ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_BIST_RESULT(offs) \ + ((0x0000F8ull) + ((offs) & 1) * 0x60000000ull) +#define CVMX_LMCX_CHAR_CTL(offs) \ + ((0x000220ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_CHAR_DQ_ERR_COUNT(offs) \ + ((0x000040ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_CHAR_MASK0(offs) \ + ((0x000228ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_CHAR_MASK1(offs) \ + ((0x000230ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_CHAR_MASK2(offs) \ + ((0x000238ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_CHAR_MASK3(offs) \ + ((0x000240ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_CHAR_MASK4(offs) \ + ((0x000318ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_COMP_CTL(offs) \ + ((0x000028ull) + ((offs) & 1) * 0x60000000ull) +#define CVMX_LMCX_COMP_CTL2(offs) \ + ((0x0001B8ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_CONFIG(offs) \ + ((0x000188ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_CONTROL(offs) \ + ((0x000190ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_CTL(offs) \ + ((0x000010ull) + ((offs) & 1) * 0x60000000ull) +#define CVMX_LMCX_CTL1(offs) \ + ((0x000090ull) + ((offs) & 1) * 0x60000000ull) +#define CVMX_LMCX_DBTRAIN_CTL(offs) \ + ((0x0003F8ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_DCLK_CNT(offs) \ + ((0x0001E0ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_DCLK_CNT_HI(offs) \ + ((0x000070ull) + ((offs) & 1) * 0x60000000ull) +#define CVMX_LMCX_DCLK_CNT_LO(offs) \ + ((0x000068ull) + ((offs) & 1) * 0x60000000ull) +#define CVMX_LMCX_DCLK_CTL(offs) \ + ((0x0000B8ull) + ((offs) & 1) * 0x60000000ull) +#define CVMX_LMCX_DDR2_CTL(offs) \ + ((0x000018ull) + ((offs) & 1) * 0x60000000ull) +#define CVMX_LMCX_DDR4_DIMM_CTL(offs) \ + ((0x0003F0ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_DDR_PLL_CTL(offs) \ + ((0x000258ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_DELAY_CFG(offs) \ + ((0x000088ull) + ((offs) & 1) * 0x60000000ull) +#define CVMX_LMCX_DIMMX_DDR4_PARAMS0(offs, id) \ + ((0x0000D0ull) + (((offs) & 1) + ((id) & 3) * 0x200000ull) * 8) +#define CVMX_LMCX_DIMMX_DDR4_PARAMS1(offs, id) \ + ((0x000140ull) + (((offs) & 1) + ((id) & 3) * 0x200000ull) * 8) +#define CVMX_LMCX_DIMMX_PARAMS(offs, id) \ + ((0x000270ull) + (((offs) & 1) + ((id) & 3) * 0x200000ull) * 8) +#define CVMX_LMCX_DIMM_CTL(offs) \ + ((0x000310ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_DLL_CTL(offs) \ + ((0x0000C0ull) + ((offs) & 1) * 0x60000000ull) +#define CVMX_LMCX_DLL_CTL2(offs) \ + ((0x0001C8ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_DLL_CTL3(offs) \ + ((0x000218ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_ECC_PARITY_TEST(offs) \ + ((0x000108ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_EXT_CONFIG(offs) \ + ((0x000030ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_EXT_CONFIG2(offs) \ + ((0x000090ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_GENERAL_PURPOSE0(offs) \ + ((0x000340ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_GENERAL_PURPOSE1(offs) \ + ((0x000348ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_GENERAL_PURPOSE2(offs) \ + ((0x000350ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_IFB_CNT(offs) \ + ((0x0001D0ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_IFB_CNT_HI(offs) \ + ((0x000050ull) + ((offs) & 1) * 0x60000000ull) +#define CVMX_LMCX_IFB_CNT_LO(offs) \ + ((0x000048ull) + ((offs) & 1) * 0x60000000ull) +#define CVMX_LMCX_INT(offs) \ + ((0x0001F0ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_INT_EN(offs) \ + ((0x0001E8ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_LANEX_CRC_SWIZ(x, id) \ + ((0x000380ull) + (((offs) & 15) + ((id) & 3) * 0x200000ull) * 8) +#define CVMX_LMCX_MEM_CFG0(offs) \ + ((0x000000ull) + ((offs) & 1) * 0x60000000ull) +#define CVMX_LMCX_MEM_CFG1(offs) \ + ((0x000008ull) + ((offs) & 1) * 0x60000000ull) +#define CVMX_LMCX_MODEREG_PARAMS0(offs) \ + ((0x0001A8ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_MODEREG_PARAMS1(offs) \ + ((0x000260ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_MODEREG_PARAMS2(offs) \ + ((0x000050ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_MODEREG_PARAMS3(offs) \ + ((0x000058ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_MPR_DATA0(offs) \ + ((0x000070ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_MPR_DATA1(offs) \ + ((0x000078ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_MPR_DATA2(offs) \ + ((0x000080ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_MR_MPR_CTL(offs) \ + ((0x000068ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_NS_CTL(offs) \ + ((0x000178ull) + ((offs) & 3) * 0x1000000ull) + +static inline uint64_t CVMX_LMCX_NXM(unsigned long offs) +{ + switch (cvmx_get_octeon_family()) { + case OCTEON_CNF71XX & OCTEON_FAMILY_MASK: + case OCTEON_CN61XX & OCTEON_FAMILY_MASK: + case OCTEON_CN70XX & OCTEON_FAMILY_MASK: + case OCTEON_CN66XX & OCTEON_FAMILY_MASK: + case OCTEON_CN63XX & OCTEON_FAMILY_MASK: + return (0x0000C8ull) + (offs) * 0x60000000ull; + case OCTEON_CNF75XX & OCTEON_FAMILY_MASK: + case OCTEON_CN73XX & OCTEON_FAMILY_MASK: + return (0x0000C8ull) + (offs) * 0x1000000ull; + case OCTEON_CN78XX & OCTEON_FAMILY_MASK: + if (OCTEON_IS_MODEL(OCTEON_CN78XX_PASS1_X)) + return (0x0000C8ull) + (offs) * 0x1000000ull; + if (OCTEON_IS_MODEL(OCTEON_CN78XX)) + return (0x0000C8ull) + (offs) * 0x1000000ull; + case OCTEON_CN68XX & OCTEON_FAMILY_MASK: + return (0x0000C8ull) + (offs) * 0x1000000ull; + } + return (0x0000C8ull) + (offs) * 0x1000000ull; +} + +#define CVMX_LMCX_NXM_FADR(offs) \ + ((0x000028ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_OPS_CNT(offs) \ + ((0x0001D8ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_OPS_CNT_HI(offs) \ + ((0x000060ull) + ((offs) & 1) * 0x60000000ull) +#define CVMX_LMCX_OPS_CNT_LO(offs) \ + ((0x000058ull) + ((offs) & 1) * 0x60000000ull) +#define CVMX_LMCX_PHY_CTL(offs) \ + ((0x000210ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_PHY_CTL2(offs) \ + ((0x000250ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_PLL_BWCTL(offs) \ + ((0x000040ull)) +#define CVMX_LMCX_PLL_CTL(offs) \ + ((0x0000A8ull) + ((offs) & 1) * 0x60000000ull) +#define CVMX_LMCX_PLL_STATUS(offs) \ + ((0x0000B0ull) + ((offs) & 1) * 0x60000000ull) +#define CVMX_LMCX_PPR_CTL(offs) \ + ((0x0003E0ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_READ_LEVEL_CTL(offs) \ + ((0x000140ull) + ((offs) & 1) * 0x60000000ull) +#define CVMX_LMCX_READ_LEVEL_DBG(offs) \ + ((0x000148ull) + ((offs) & 1) * 0x60000000ull) +#define CVMX_LMCX_READ_LEVEL_RANKX(offs, id) \ + ((0x000100ull) + (((offs) & 3) + ((id) & 1) * 0xC000000ull) * 8) +#define CVMX_LMCX_REF_STATUS(offs) \ + ((0x0000A0ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_RESET_CTL(offs) \ + ((0x000180ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_RETRY_CONFIG(offs) \ + ((0x000110ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_RETRY_STATUS(offs) \ + ((0x000118ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_RLEVEL_CTL(offs) \ + ((0x0002A0ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_RLEVEL_DBG(offs) \ + ((0x0002A8ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_RLEVEL_RANKX(offs, id) \ + ((0x000280ull) + (((offs) & 3) + ((id) & 3) * 0x200000ull) * 8) +#define CVMX_LMCX_RODT_COMP_CTL(offs) \ + ((0x0000A0ull) + ((offs) & 1) * 0x60000000ull) +#define CVMX_LMCX_RODT_CTL(offs) \ + ((0x000078ull) + ((offs) & 1) * 0x60000000ull) +#define CVMX_LMCX_RODT_MASK(offs) \ + ((0x000268ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_SCRAMBLED_FADR(offs) \ + ((0x000330ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_SCRAMBLE_CFG0(offs) \ + ((0x000320ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_SCRAMBLE_CFG1(offs) \ + ((0x000328ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_SCRAMBLE_CFG2(offs) \ + ((0x000338ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_SEQ_CTL(offs) \ + ((0x000048ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_SLOT_CTL0(offs) \ + ((0x0001F8ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_SLOT_CTL1(offs) \ + ((0x000200ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_SLOT_CTL2(offs) \ + ((0x000208ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_SLOT_CTL3(offs) \ + ((0x000248ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_TIMING_PARAMS0(offs) \ + ((0x000198ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_TIMING_PARAMS1(offs) \ + ((0x0001A0ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_TIMING_PARAMS2(offs) \ + ((0x000060ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_TRO_CTL(offs) \ + ((0x000248ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_TRO_STAT(offs) \ + ((0x000250ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_WLEVEL_CTL(offs) \ + ((0x000300ull) + ((offs) & 3) * 0x1000000ull) +#define CVMX_LMCX_WLEVEL_DBG(offs) \ + ((0x000308ull) + ((offs) & 3) * 0x1000000ull) + +static inline uint64_t CVMX_LMCX_WLEVEL_RANKX(unsigned long offs, + unsigned long id) +{ + switch (cvmx_get_octeon_family()) { + case OCTEON_CN70XX & OCTEON_FAMILY_MASK: + return (0x0002C0ull) + ((offs) + (id) * 0x200000ull) * 8; + case OCTEON_CNF75XX & OCTEON_FAMILY_MASK: + case OCTEON_CN73XX & OCTEON_FAMILY_MASK: + return (0x0002C0ull) + ((offs) + (id) * 0x200000ull) * 8; + case OCTEON_CN78XX & OCTEON_FAMILY_MASK: + if (OCTEON_IS_MODEL(OCTEON_CN78XX_PASS1_X)) + return (0x0002C0ull) + ((offs) + + (id) * 0x200000ull) * 8; + if (OCTEON_IS_MODEL(OCTEON_CN78XX)) + return (0x0002C0ull) + ((offs) + + (id) * 0x200000ull) * 8; + + case OCTEON_CN66XX & OCTEON_FAMILY_MASK: + case OCTEON_CN63XX & OCTEON_FAMILY_MASK: + return (0x0002B0ull) + ((offs) + (id) * 0x0ull) * 8; + case OCTEON_CNF71XX & OCTEON_FAMILY_MASK: + case OCTEON_CN61XX & OCTEON_FAMILY_MASK: + return (0x0002B0ull) + ((offs) + (id) * 0x200000ull) * 8; + case OCTEON_CN68XX & OCTEON_FAMILY_MASK: + return (0x0002B0ull) + ((offs) + (id) * 0x200000ull) * 8; + } + return (0x0002C0ull) + ((offs) + (id) * 0x200000ull) * 8; +} + +#define CVMX_LMCX_WODT_CTL0(offs) \ + ((0x000030ull) + ((offs) & 1) * 0x60000000ull) +#define CVMX_LMCX_WODT_CTL1(offs) \ + ((0x000080ull) + ((offs) & 1) * 0x60000000ull) +#define CVMX_LMCX_WODT_MASK(offs) \ + ((0x0001B0ull) + ((offs) & 3) * 0x1000000ull) + +/** + * cvmx_lmc#_char_ctl + * + * This register provides an assortment of various control fields needed + * to characterize the DDR3 interface. + */ +union cvmx_lmcx_char_ctl { + u64 u64; + struct cvmx_lmcx_char_ctl_s { + uint64_t reserved_54_63:10; + uint64_t dq_char_byte_check:1; + uint64_t dq_char_check_lock:1; + uint64_t dq_char_check_enable:1; + uint64_t dq_char_bit_sel:3; + uint64_t dq_char_byte_sel:4; + uint64_t dr:1; + uint64_t skew_on:1; + uint64_t en:1; + uint64_t sel:1; + uint64_t prog:8; + uint64_t prbs:32; + } s; + struct cvmx_lmcx_char_ctl_cn61xx { + uint64_t reserved_44_63:20; + uint64_t dr:1; + uint64_t skew_on:1; + uint64_t en:1; + uint64_t sel:1; + uint64_t prog:8; + uint64_t prbs:32; + } cn61xx; + struct cvmx_lmcx_char_ctl_cn63xx { + uint64_t reserved_42_63:22; + uint64_t en:1; + uint64_t sel:1; + uint64_t prog:8; + uint64_t prbs:32; + } cn63xx; + struct cvmx_lmcx_char_ctl_cn63xx cn63xxp1; + struct cvmx_lmcx_char_ctl_cn61xx cn66xx; + struct cvmx_lmcx_char_ctl_cn61xx cn68xx; + struct cvmx_lmcx_char_ctl_cn63xx cn68xxp1; + struct cvmx_lmcx_char_ctl_cn70xx { + uint64_t reserved_53_63:11; + uint64_t dq_char_check_lock:1; + uint64_t dq_char_check_enable:1; + uint64_t dq_char_bit_sel:3; + uint64_t dq_char_byte_sel:4; + uint64_t dr:1; + uint64_t skew_on:1; + uint64_t en:1; + uint64_t sel:1; + uint64_t prog:8; + uint64_t prbs:32; + } cn70xx; + struct cvmx_lmcx_char_ctl_cn70xx cn70xxp1; + struct cvmx_lmcx_char_ctl_s cn73xx; + struct cvmx_lmcx_char_ctl_s cn78xx; + struct cvmx_lmcx_char_ctl_s cn78xxp1; + struct cvmx_lmcx_char_ctl_cn61xx cnf71xx; + struct cvmx_lmcx_char_ctl_s cnf75xx; +}; + +/** + * cvmx_lmc#_comp_ctl2 + * + * LMC_COMP_CTL2 = LMC Compensation control + * + */ +union cvmx_lmcx_comp_ctl2 { + u64 u64; + struct cvmx_lmcx_comp_ctl2_s { + uint64_t reserved_51_63:13; + uint64_t rclk_char_mode:1; + uint64_t reserved_40_49:10; + uint64_t ptune_offset:4; + uint64_t reserved_12_35:24; + uint64_t cmd_ctl:4; + uint64_t ck_ctl:4; + uint64_t dqx_ctl:4; + } s; + struct cvmx_lmcx_comp_ctl2_cn61xx { + uint64_t reserved_34_63:30; + uint64_t ddr__ptune:4; + uint64_t ddr__ntune:4; + uint64_t m180:1; + uint64_t byp:1; + uint64_t ptune:4; + uint64_t ntune:4; + uint64_t rodt_ctl:4; + uint64_t cmd_ctl:4; + uint64_t ck_ctl:4; + uint64_t dqx_ctl:4; + } cn61xx; + struct cvmx_lmcx_comp_ctl2_cn61xx cn63xx; + struct cvmx_lmcx_comp_ctl2_cn61xx cn63xxp1; + struct cvmx_lmcx_comp_ctl2_cn61xx cn66xx; + struct cvmx_lmcx_comp_ctl2_cn61xx cn68xx; + struct cvmx_lmcx_comp_ctl2_cn61xx cn68xxp1; + struct cvmx_lmcx_comp_ctl2_cn70xx { + uint64_t reserved_51_63:13; + uint64_t rclk_char_mode:1; + uint64_t ddr__ptune:5; + uint64_t ddr__ntune:5; + uint64_t ptune_offset:4; + uint64_t ntune_offset:4; + uint64_t m180:1; + uint64_t byp:1; + uint64_t ptune:5; + uint64_t ntune:5; + uint64_t rodt_ctl:4; + uint64_t control_ctl:4; + uint64_t cmd_ctl:4; + uint64_t ck_ctl:4; + uint64_t dqx_ctl:4; + } cn70xx; + struct cvmx_lmcx_comp_ctl2_cn70xx cn70xxp1; + struct cvmx_lmcx_comp_ctl2_cn70xx cn73xx; + struct cvmx_lmcx_comp_ctl2_cn70xx cn78xx; + struct cvmx_lmcx_comp_ctl2_cn70xx cn78xxp1; + struct cvmx_lmcx_comp_ctl2_cn61xx cnf71xx; + struct cvmx_lmcx_comp_ctl2_cn70xx cnf75xx; +}; + +/** + * cvmx_lmc#_config + * + * This register controls certain parameters required for memory configuration. + * Note the following: + * * Priority order for hardware write operations to + * LMC()_CONFIG/LMC()_FADR/LMC()_ECC_SYND: DED error > SEC error. + * * The self-refresh entry sequence(s) power the DLL up/down (depending on + * LMC()_MODEREG_PARAMS0[DLL]) when LMC()_CONFIG[SREF_WITH_DLL] is set. + * * Prior to the self-refresh exit sequence, LMC()_MODEREG_PARAMS0 should + * be reprogrammed + * (if needed) to the appropriate values. + * + * See LMC initialization sequence for the LMC bringup sequence. + */ +union cvmx_lmcx_config { + u64 u64; + struct cvmx_lmcx_config_s { + uint64_t lrdimm_ena:1; + uint64_t bg2_enable:1; + uint64_t mode_x4dev:1; + uint64_t mode32b:1; + uint64_t scrz:1; + uint64_t early_unload_d1_r1:1; + uint64_t early_unload_d1_r0:1; + uint64_t early_unload_d0_r1:1; + uint64_t early_unload_d0_r0:1; + uint64_t init_status:4; + uint64_t mirrmask:4; + uint64_t rankmask:4; + uint64_t rank_ena:1; + uint64_t sref_with_dll:1; + uint64_t early_dqx:1; + uint64_t reserved_18_39:22; + uint64_t reset:1; + uint64_t ecc_adr:1; + uint64_t forcewrite:4; + uint64_t idlepower:3; + uint64_t pbank_lsb:4; + uint64_t row_lsb:3; + uint64_t ecc_ena:1; + uint64_t init_start:1; + } s; + struct cvmx_lmcx_config_cn61xx { + uint64_t reserved_61_63:3; + uint64_t mode32b:1; + uint64_t scrz:1; + uint64_t early_unload_d1_r1:1; + uint64_t early_unload_d1_r0:1; + uint64_t early_unload_d0_r1:1; + uint64_t early_unload_d0_r0:1; + uint64_t init_status:4; + uint64_t mirrmask:4; + uint64_t rankmask:4; + uint64_t rank_ena:1; + uint64_t sref_with_dll:1; + uint64_t early_dqx:1; + uint64_t sequence:3; + uint64_t ref_zqcs_int:19; + uint64_t reset:1; + uint64_t ecc_adr:1; + uint64_t forcewrite:4; + uint64_t idlepower:3; + uint64_t pbank_lsb:4; + uint64_t row_lsb:3; + uint64_t ecc_ena:1; + uint64_t init_start:1; + } cn61xx; + struct cvmx_lmcx_config_cn63xx { + uint64_t reserved_59_63:5; + uint64_t early_unload_d1_r1:1; + uint64_t early_unload_d1_r0:1; + uint64_t early_unload_d0_r1:1; + uint64_t early_unload_d0_r0:1; + uint64_t init_status:4; + uint64_t mirrmask:4; + uint64_t rankmask:4; + uint64_t rank_ena:1; + uint64_t sref_with_dll:1; + uint64_t early_dqx:1; + uint64_t sequence:3; + uint64_t ref_zqcs_int:19; + uint64_t reset:1; + uint64_t ecc_adr:1; + uint64_t forcewrite:4; + uint64_t idlepower:3; + uint64_t pbank_lsb:4; + uint64_t row_lsb:3; + uint64_t ecc_ena:1; + uint64_t init_start:1; + } cn63xx; + struct cvmx_lmcx_config_cn63xxp1 { + uint64_t reserved_55_63:9; + uint64_t init_status:4; + uint64_t mirrmask:4; + uint64_t rankmask:4; + uint64_t rank_ena:1; + uint64_t sref_with_dll:1; + uint64_t early_dqx:1; + uint64_t sequence:3; + uint64_t ref_zqcs_int:19; + uint64_t reset:1; + uint64_t ecc_adr:1; + uint64_t forcewrite:4; + uint64_t idlepower:3; + uint64_t pbank_lsb:4; + uint64_t row_lsb:3; + uint64_t ecc_ena:1; + uint64_t init_start:1; + } cn63xxp1; + struct cvmx_lmcx_config_cn66xx { + uint64_t reserved_60_63:4; + uint64_t scrz:1; + uint64_t early_unload_d1_r1:1; + uint64_t early_unload_d1_r0:1; + uint64_t early_unload_d0_r1:1; + uint64_t early_unload_d0_r0:1; + uint64_t init_status:4; + uint64_t mirrmask:4; + uint64_t rankmask:4; + uint64_t rank_ena:1; + uint64_t sref_with_dll:1; + uint64_t early_dqx:1; + uint64_t sequence:3; + uint64_t ref_zqcs_int:19; + uint64_t reset:1; + uint64_t ecc_adr:1; + uint64_t forcewrite:4; + uint64_t idlepower:3; + uint64_t pbank_lsb:4; + uint64_t row_lsb:3; + uint64_t ecc_ena:1; + uint64_t init_start:1; + } cn66xx; + struct cvmx_lmcx_config_cn63xx cn68xx; + struct cvmx_lmcx_config_cn63xx cn68xxp1; + struct cvmx_lmcx_config_cn70xx { + uint64_t reserved_63_63:1; + uint64_t bg2_enable:1; + uint64_t mode_x4dev:1; + uint64_t mode32b:1; + uint64_t scrz:1; + uint64_t early_unload_d1_r1:1; + uint64_t early_unload_d1_r0:1; + uint64_t early_unload_d0_r1:1; + uint64_t early_unload_d0_r0:1; + uint64_t init_status:4; + uint64_t mirrmask:4; + uint64_t rankmask:4; + uint64_t rank_ena:1; + uint64_t sref_with_dll:1; + uint64_t early_dqx:1; + uint64_t ref_zqcs_int:22; + uint64_t reset:1; + uint64_t ecc_adr:1; + uint64_t forcewrite:4; + uint64_t idlepower:3; + uint64_t pbank_lsb:4; + uint64_t row_lsb:3; + uint64_t ecc_ena:1; + uint64_t reserved_0_0:1; + } cn70xx; + struct cvmx_lmcx_config_cn70xx cn70xxp1; + struct cvmx_lmcx_config_cn73xx { + uint64_t lrdimm_ena:1; + uint64_t bg2_enable:1; + uint64_t mode_x4dev:1; + uint64_t mode32b:1; + uint64_t scrz:1; + uint64_t early_unload_d1_r1:1; + uint64_t early_unload_d1_r0:1; + uint64_t early_unload_d0_r1:1; + uint64_t early_unload_d0_r0:1; + uint64_t init_status:4; + uint64_t mirrmask:4; + uint64_t rankmask:4; + uint64_t rank_ena:1; + uint64_t sref_with_dll:1; + uint64_t early_dqx:1; + uint64_t ref_zqcs_int:22; + uint64_t reset:1; + uint64_t ecc_adr:1; + uint64_t forcewrite:4; + uint64_t idlepower:3; + uint64_t pbank_lsb:4; + uint64_t row_lsb:3; + uint64_t ecc_ena:1; + uint64_t reserved_0_0:1; + } cn73xx; + struct cvmx_lmcx_config_cn73xx cn78xx; + struct cvmx_lmcx_config_cn73xx cn78xxp1; + struct cvmx_lmcx_config_cn61xx cnf71xx; + struct cvmx_lmcx_config_cn73xx cnf75xx; +}; + +/** + * cvmx_lmc#_control + * + * LMC_CONTROL = LMC Control + * This register is an assortment of various control fields needed by the + * memory controller + */ +union cvmx_lmcx_control { + u64 u64; + struct cvmx_lmcx_control_s { + uint64_t scramble_ena:1; + uint64_t thrcnt:12; + uint64_t persub:8; + uint64_t thrmax:4; + uint64_t crm_cnt:5; + uint64_t crm_thr:5; + uint64_t crm_max:5; + uint64_t rodt_bprch:1; + uint64_t wodt_bprch:1; + uint64_t bprch:2; + uint64_t ext_zqcs_dis:1; + uint64_t int_zqcs_dis:1; + uint64_t auto_dclkdis:1; + uint64_t xor_bank:1; + uint64_t max_write_batch:4; + uint64_t nxm_write_en:1; + uint64_t elev_prio_dis:1; + uint64_t inorder_wr:1; + uint64_t inorder_rd:1; + uint64_t throttle_wr:1; + uint64_t throttle_rd:1; + uint64_t fprch2:2; + uint64_t pocas:1; + uint64_t ddr2t:1; + uint64_t bwcnt:1; + uint64_t rdimm_ena:1; + } s; + struct cvmx_lmcx_control_s cn61xx; + struct cvmx_lmcx_control_cn63xx { + uint64_t reserved_24_63:40; + uint64_t rodt_bprch:1; + uint64_t wodt_bprch:1; + uint64_t bprch:2; + uint64_t ext_zqcs_dis:1; + uint64_t int_zqcs_dis:1; + uint64_t auto_dclkdis:1; + uint64_t xor_bank:1; + uint64_t max_write_batch:4; + uint64_t nxm_write_en:1; + uint64_t elev_prio_dis:1; + uint64_t inorder_wr:1; + uint64_t inorder_rd:1; + uint64_t throttle_wr:1; + uint64_t throttle_rd:1; + uint64_t fprch2:2; + uint64_t pocas:1; + uint64_t ddr2t:1; + uint64_t bwcnt:1; + uint64_t rdimm_ena:1; + } cn63xx; + struct cvmx_lmcx_control_cn63xx cn63xxp1; + struct cvmx_lmcx_control_cn66xx { + uint64_t scramble_ena:1; + uint64_t reserved_24_62:39; + uint64_t rodt_bprch:1; + uint64_t wodt_bprch:1; + uint64_t bprch:2; + uint64_t ext_zqcs_dis:1; + uint64_t int_zqcs_dis:1; + uint64_t auto_dclkdis:1; + uint64_t xor_bank:1; + uint64_t max_write_batch:4; + uint64_t nxm_write_en:1; + uint64_t elev_prio_dis:1; + uint64_t inorder_wr:1; + uint64_t inorder_rd:1; + uint64_t throttle_wr:1; + uint64_t throttle_rd:1; + uint64_t fprch2:2; + uint64_t pocas:1; + uint64_t ddr2t:1; + uint64_t bwcnt:1; + uint64_t rdimm_ena:1; + } cn66xx; + struct cvmx_lmcx_control_cn68xx { + uint64_t reserved_63_63:1; + uint64_t thrcnt:12; + uint64_t persub:8; + uint64_t thrmax:4; + uint64_t crm_cnt:5; + uint64_t crm_thr:5; + uint64_t crm_max:5; + uint64_t rodt_bprch:1; + uint64_t wodt_bprch:1; + uint64_t bprch:2; + uint64_t ext_zqcs_dis:1; + uint64_t int_zqcs_dis:1; + uint64_t auto_dclkdis:1; + uint64_t xor_bank:1; + uint64_t max_write_batch:4; + uint64_t nxm_write_en:1; + uint64_t elev_prio_dis:1; + uint64_t inorder_wr:1; + uint64_t inorder_rd:1; + uint64_t throttle_wr:1; + uint64_t throttle_rd:1; + uint64_t fprch2:2; + uint64_t pocas:1; + uint64_t ddr2t:1; + uint64_t bwcnt:1; + uint64_t rdimm_ena:1; + } cn68xx; + struct cvmx_lmcx_control_cn68xx cn68xxp1; + struct cvmx_lmcx_control_s cn70xx; + struct cvmx_lmcx_control_s cn70xxp1; + struct cvmx_lmcx_control_s cn73xx; + struct cvmx_lmcx_control_s cn78xx; + struct cvmx_lmcx_control_s cn78xxp1; + struct cvmx_lmcx_control_cn66xx cnf71xx; + struct cvmx_lmcx_control_s cnf75xx; +}; + +/** + * cvmx_lmc#_ctl + * + * LMC_CTL = LMC Control + * This register is an assortment of various control fields needed by the + * memory controller + */ +union cvmx_lmcx_ctl { + u64 u64; + struct cvmx_lmcx_ctl_s { + uint64_t reserved_32_63:32; + uint64_t ddr__nctl:4; + uint64_t ddr__pctl:4; + uint64_t slow_scf:1; + uint64_t xor_bank:1; + uint64_t max_write_batch:4; + uint64_t pll_div2:1; + uint64_t pll_bypass:1; + uint64_t rdimm_ena:1; + uint64_t r2r_slot:1; + uint64_t inorder_mwf:1; + uint64_t inorder_mrf:1; + uint64_t reserved_10_11:2; + uint64_t fprch2:1; + uint64_t bprch:1; + uint64_t sil_lat:2; + uint64_t tskw:2; + uint64_t qs_dic:2; + uint64_t dic:2; + } s; + struct cvmx_lmcx_ctl_cn30xx { + uint64_t reserved_32_63:32; + uint64_t ddr__nctl:4; + uint64_t ddr__pctl:4; + uint64_t slow_scf:1; + uint64_t xor_bank:1; + uint64_t max_write_batch:4; + uint64_t pll_div2:1; + uint64_t pll_bypass:1; + uint64_t rdimm_ena:1; + uint64_t r2r_slot:1; + uint64_t inorder_mwf:1; + uint64_t inorder_mrf:1; + uint64_t dreset:1; + uint64_t mode32b:1; + uint64_t fprch2:1; + uint64_t bprch:1; + uint64_t sil_lat:2; + uint64_t tskw:2; + uint64_t qs_dic:2; + uint64_t dic:2; + } cn30xx; + struct cvmx_lmcx_ctl_cn30xx cn31xx; + struct cvmx_lmcx_ctl_cn38xx { + uint64_t reserved_32_63:32; + uint64_t ddr__nctl:4; + uint64_t ddr__pctl:4; + uint64_t slow_scf:1; + uint64_t xor_bank:1; + uint64_t max_write_batch:4; + uint64_t reserved_16_17:2; + uint64_t rdimm_ena:1; + uint64_t r2r_slot:1; + uint64_t inorder_mwf:1; + uint64_t inorder_mrf:1; + uint64_t set_zero:1; + uint64_t mode128b:1; + uint64_t fprch2:1; + uint64_t bprch:1; + uint64_t sil_lat:2; + uint64_t tskw:2; + uint64_t qs_dic:2; + uint64_t dic:2; + } cn38xx; + struct cvmx_lmcx_ctl_cn38xx cn38xxp2; + struct cvmx_lmcx_ctl_cn50xx { + uint64_t reserved_32_63:32; + uint64_t ddr__nctl:4; + uint64_t ddr__pctl:4; + uint64_t slow_scf:1; + uint64_t xor_bank:1; + uint64_t max_write_batch:4; + uint64_t reserved_17_17:1; + uint64_t pll_bypass:1; + uint64_t rdimm_ena:1; + uint64_t r2r_slot:1; + uint64_t inorder_mwf:1; + uint64_t inorder_mrf:1; + uint64_t dreset:1; + uint64_t mode32b:1; + uint64_t fprch2:1; + uint64_t bprch:1; + uint64_t sil_lat:2; + uint64_t tskw:2; + uint64_t qs_dic:2; + uint64_t dic:2; + } cn50xx; + struct cvmx_lmcx_ctl_cn52xx { + uint64_t reserved_32_63:32; + uint64_t ddr__nctl:4; + uint64_t ddr__pctl:4; + uint64_t slow_scf:1; + uint64_t xor_bank:1; + uint64_t max_write_batch:4; + uint64_t reserved_16_17:2; + uint64_t rdimm_ena:1; + uint64_t r2r_slot:1; + uint64_t inorder_mwf:1; + uint64_t inorder_mrf:1; + uint64_t dreset:1; + uint64_t mode32b:1; + uint64_t fprch2:1; + uint64_t bprch:1; + uint64_t sil_lat:2; + uint64_t tskw:2; + uint64_t qs_dic:2; + uint64_t dic:2; + } cn52xx; + struct cvmx_lmcx_ctl_cn52xx cn52xxp1; + struct cvmx_lmcx_ctl_cn52xx cn56xx; + struct cvmx_lmcx_ctl_cn52xx cn56xxp1; + struct cvmx_lmcx_ctl_cn58xx { + uint64_t reserved_32_63:32; + uint64_t ddr__nctl:4; + uint64_t ddr__pctl:4; + uint64_t slow_scf:1; + uint64_t xor_bank:1; + uint64_t max_write_batch:4; + uint64_t reserved_16_17:2; + uint64_t rdimm_ena:1; + uint64_t r2r_slot:1; + uint64_t inorder_mwf:1; + uint64_t inorder_mrf:1; + uint64_t dreset:1; + uint64_t mode128b:1; + uint64_t fprch2:1; + uint64_t bprch:1; + uint64_t sil_lat:2; + uint64_t tskw:2; + uint64_t qs_dic:2; + uint64_t dic:2; + } cn58xx; + struct cvmx_lmcx_ctl_cn58xx cn58xxp1; +}; + +/** + * cvmx_lmc#_ctl1 + * + * LMC_CTL1 = LMC Control1 + * This register is an assortment of various control fields needed by the + * memory controller + */ +union cvmx_lmcx_ctl1 { + u64 u64; + struct cvmx_lmcx_ctl1_s { + uint64_t reserved_21_63:43; + uint64_t ecc_adr:1; + uint64_t forcewrite:4; + uint64_t idlepower:3; + uint64_t sequence:3; + uint64_t sil_mode:1; + uint64_t dcc_enable:1; + uint64_t reserved_2_7:6; + uint64_t data_layout:2; + } s; + struct cvmx_lmcx_ctl1_cn30xx { + uint64_t reserved_2_63:62; + uint64_t data_layout:2; + } cn30xx; + struct cvmx_lmcx_ctl1_cn50xx { + uint64_t reserved_10_63:54; + uint64_t sil_mode:1; + uint64_t dcc_enable:1; + uint64_t reserved_2_7:6; + uint64_t data_layout:2; + } cn50xx; + struct cvmx_lmcx_ctl1_cn52xx { + uint64_t reserved_21_63:43; + uint64_t ecc_adr:1; + uint64_t forcewrite:4; + uint64_t idlepower:3; + uint64_t sequence:3; + uint64_t sil_mode:1; + uint64_t dcc_enable:1; + uint64_t reserved_0_7:8; + } cn52xx; + struct cvmx_lmcx_ctl1_cn52xx cn52xxp1; + struct cvmx_lmcx_ctl1_cn52xx cn56xx; + struct cvmx_lmcx_ctl1_cn52xx cn56xxp1; + struct cvmx_lmcx_ctl1_cn58xx { + uint64_t reserved_10_63:54; + uint64_t sil_mode:1; + uint64_t dcc_enable:1; + uint64_t reserved_0_7:8; + } cn58xx; + struct cvmx_lmcx_ctl1_cn58xx cn58xxp1; +}; + +/** + * cvmx_lmc#_dbtrain_ctl + * + * Reserved. + * + */ +union cvmx_lmcx_dbtrain_ctl { + u64 u64; + struct cvmx_lmcx_dbtrain_ctl_s { + uint64_t reserved_63_63:1; + uint64_t lfsr_pattern_sel:1; + uint64_t cmd_count_ext:2; + uint64_t db_output_impedance:3; + uint64_t db_sel:1; + uint64_t tccd_sel:1; + uint64_t rw_train:1; + uint64_t read_dq_count:7; + uint64_t read_cmd_count:5; + uint64_t write_ena:1; + uint64_t activate:1; + uint64_t prank:2; + uint64_t lrank:3; + uint64_t row_a:18; + uint64_t bg:2; + uint64_t ba:2; + uint64_t column_a:13; + } s; + struct cvmx_lmcx_dbtrain_ctl_cn73xx { + uint64_t reserved_60_63:4; + uint64_t db_output_impedance:3; + uint64_t db_sel:1; + uint64_t tccd_sel:1; + uint64_t rw_train:1; + uint64_t read_dq_count:7; + uint64_t read_cmd_count:5; + uint64_t write_ena:1; + uint64_t activate:1; + uint64_t prank:2; + uint64_t lrank:3; + uint64_t row_a:18; + uint64_t bg:2; + uint64_t ba:2; + uint64_t column_a:13; + } cn73xx; + struct cvmx_lmcx_dbtrain_ctl_s cn78xx; + struct cvmx_lmcx_dbtrain_ctl_cnf75xx { + uint64_t reserved_62_63:2; + uint64_t cmd_count_ext:2; + uint64_t db_output_impedance:3; + uint64_t db_sel:1; + uint64_t tccd_sel:1; + uint64_t rw_train:1; + uint64_t read_dq_count:7; + uint64_t read_cmd_count:5; + uint64_t write_ena:1; + uint64_t activate:1; + uint64_t prank:2; + uint64_t lrank:3; + uint64_t row_a:18; + uint64_t bg:2; + uint64_t ba:2; + uint64_t column_a:13; + } cnf75xx; +}; + +/** + * cvmx_lmc#_dclk_cnt + * + * LMC_DCLK_CNT = Performance Counters + * + */ +union cvmx_lmcx_dclk_cnt { + u64 u64; + struct cvmx_lmcx_dclk_cnt_s { + uint64_t dclkcnt:64; + } s; + struct cvmx_lmcx_dclk_cnt_s cn61xx; + struct cvmx_lmcx_dclk_cnt_s cn63xx; + struct cvmx_lmcx_dclk_cnt_s cn63xxp1; + struct cvmx_lmcx_dclk_cnt_s cn66xx; + struct cvmx_lmcx_dclk_cnt_s cn68xx; + struct cvmx_lmcx_dclk_cnt_s cn68xxp1; + struct cvmx_lmcx_dclk_cnt_s cn70xx; + struct cvmx_lmcx_dclk_cnt_s cn70xxp1; + struct cvmx_lmcx_dclk_cnt_s cn73xx; + struct cvmx_lmcx_dclk_cnt_s cn78xx; + struct cvmx_lmcx_dclk_cnt_s cn78xxp1; + struct cvmx_lmcx_dclk_cnt_s cnf71xx; + struct cvmx_lmcx_dclk_cnt_s cnf75xx; +}; + +/** + * cvmx_lmc#_dclk_cnt_hi + * + * LMC_DCLK_CNT_HI = Performance Counters + * + */ +union cvmx_lmcx_dclk_cnt_hi { + u64 u64; + struct cvmx_lmcx_dclk_cnt_hi_s { + uint64_t reserved_32_63:32; + uint64_t dclkcnt_hi:32; + } s; + struct cvmx_lmcx_dclk_cnt_hi_s cn30xx; + struct cvmx_lmcx_dclk_cnt_hi_s cn31xx; + struct cvmx_lmcx_dclk_cnt_hi_s cn38xx; + struct cvmx_lmcx_dclk_cnt_hi_s cn38xxp2; + struct cvmx_lmcx_dclk_cnt_hi_s cn50xx; + struct cvmx_lmcx_dclk_cnt_hi_s cn52xx; + struct cvmx_lmcx_dclk_cnt_hi_s cn52xxp1; + struct cvmx_lmcx_dclk_cnt_hi_s cn56xx; + struct cvmx_lmcx_dclk_cnt_hi_s cn56xxp1; + struct cvmx_lmcx_dclk_cnt_hi_s cn58xx; + struct cvmx_lmcx_dclk_cnt_hi_s cn58xxp1; +}; + +/** + * cvmx_lmc#_dclk_cnt_lo + * + * LMC_DCLK_CNT_LO = Performance Counters + * + */ +union cvmx_lmcx_dclk_cnt_lo { + u64 u64; + struct cvmx_lmcx_dclk_cnt_lo_s { + uint64_t reserved_32_63:32; + uint64_t dclkcnt_lo:32; + } s; + struct cvmx_lmcx_dclk_cnt_lo_s cn30xx; + struct cvmx_lmcx_dclk_cnt_lo_s cn31xx; + struct cvmx_lmcx_dclk_cnt_lo_s cn38xx; + struct cvmx_lmcx_dclk_cnt_lo_s cn38xxp2; + struct cvmx_lmcx_dclk_cnt_lo_s cn50xx; + struct cvmx_lmcx_dclk_cnt_lo_s cn52xx; + struct cvmx_lmcx_dclk_cnt_lo_s cn52xxp1; + struct cvmx_lmcx_dclk_cnt_lo_s cn56xx; + struct cvmx_lmcx_dclk_cnt_lo_s cn56xxp1; + struct cvmx_lmcx_dclk_cnt_lo_s cn58xx; + struct cvmx_lmcx_dclk_cnt_lo_s cn58xxp1; +}; + +/** + * cvmx_lmc#_dclk_ctl + * + * LMC_DCLK_CTL = LMC DCLK generation control + * + * + * Notes: + * This CSR is only relevant for LMC1. LMC0_DCLK_CTL is not used. + * + */ +union cvmx_lmcx_dclk_ctl { + u64 u64; + struct cvmx_lmcx_dclk_ctl_s { + uint64_t reserved_8_63:56; + uint64_t off90_ena:1; + uint64_t dclk90_byp:1; + uint64_t dclk90_ld:1; + uint64_t dclk90_vlu:5; + } s; + struct cvmx_lmcx_dclk_ctl_s cn56xx; + struct cvmx_lmcx_dclk_ctl_s cn56xxp1; +}; + +/** + * cvmx_lmc#_ddr2_ctl + * + * LMC_DDR2_CTL = LMC DDR2 & DLL Control Register + * + */ +union cvmx_lmcx_ddr2_ctl { + u64 u64; + struct cvmx_lmcx_ddr2_ctl_s { + uint64_t reserved_32_63:32; + uint64_t bank8:1; + uint64_t burst8:1; + uint64_t addlat:3; + uint64_t pocas:1; + uint64_t bwcnt:1; + uint64_t twr:3; + uint64_t silo_hc:1; + uint64_t ddr_eof:4; + uint64_t tfaw:5; + uint64_t crip_mode:1; + uint64_t ddr2t:1; + uint64_t odt_ena:1; + uint64_t qdll_ena:1; + uint64_t dll90_vlu:5; + uint64_t dll90_byp:1; + uint64_t rdqs:1; + uint64_t ddr2:1; + } s; + struct cvmx_lmcx_ddr2_ctl_cn30xx { + uint64_t reserved_32_63:32; + uint64_t bank8:1; + uint64_t burst8:1; + uint64_t addlat:3; + uint64_t pocas:1; + uint64_t bwcnt:1; + uint64_t twr:3; + uint64_t silo_hc:1; + uint64_t ddr_eof:4; + uint64_t tfaw:5; + uint64_t crip_mode:1; + uint64_t ddr2t:1; + uint64_t odt_ena:1; + uint64_t qdll_ena:1; + uint64_t dll90_vlu:5; + uint64_t dll90_byp:1; + uint64_t reserved_1_1:1; + uint64_t ddr2:1; + } cn30xx; + struct cvmx_lmcx_ddr2_ctl_cn30xx cn31xx; + struct cvmx_lmcx_ddr2_ctl_s cn38xx; + struct cvmx_lmcx_ddr2_ctl_s cn38xxp2; + struct cvmx_lmcx_ddr2_ctl_s cn50xx; + struct cvmx_lmcx_ddr2_ctl_s cn52xx; + struct cvmx_lmcx_ddr2_ctl_s cn52xxp1; + struct cvmx_lmcx_ddr2_ctl_s cn56xx; + struct cvmx_lmcx_ddr2_ctl_s cn56xxp1; + struct cvmx_lmcx_ddr2_ctl_s cn58xx; + struct cvmx_lmcx_ddr2_ctl_s cn58xxp1; +}; + +/** + * cvmx_lmc#_ddr4_dimm_ctl + * + * Bits 0-21 of this register are used only when LMC()_CONTROL[RDIMM_ENA] = 1. + * + * During an RCW initialization sequence, bits 0-21 control LMC's write + * operations to the extended DDR4 control words in the JEDEC standard + * registering clock driver on an RDIMM. + */ +union cvmx_lmcx_ddr4_dimm_ctl { + u64 u64; + struct cvmx_lmcx_ddr4_dimm_ctl_s { + uint64_t reserved_28_63:36; + uint64_t rank_timing_enable:1; + uint64_t bodt_trans_mode:1; + uint64_t trans_mode_ena:1; + uint64_t read_preamble_mode:1; + uint64_t buff_config_da3:1; + uint64_t mpr_over_ena:1; + uint64_t ddr4_dimm1_wmask:11; + uint64_t ddr4_dimm0_wmask:11; + } s; + struct cvmx_lmcx_ddr4_dimm_ctl_cn70xx { + uint64_t reserved_22_63:42; + uint64_t ddr4_dimm1_wmask:11; + uint64_t ddr4_dimm0_wmask:11; + } cn70xx; + struct cvmx_lmcx_ddr4_dimm_ctl_cn70xx cn70xxp1; + struct cvmx_lmcx_ddr4_dimm_ctl_s cn73xx; + struct cvmx_lmcx_ddr4_dimm_ctl_s cn78xx; + struct cvmx_lmcx_ddr4_dimm_ctl_s cn78xxp1; + struct cvmx_lmcx_ddr4_dimm_ctl_s cnf75xx; +}; + +/** + * cvmx_lmc#_ddr_pll_ctl + * + * This register controls the DDR_CK frequency. For details, refer to CK + * speed programming. See LMC initialization sequence for the initialization + * sequence. + * DDR PLL bringup sequence: + * + * 1. Write [CLKF], [CLKR], [DDR_PS_EN]. + * + * 2. Wait 128 ref clock cycles (7680 core-clock cycles). + * + * 3. Write 1 to [RESET_N]. + * + * 4. Wait 1152 ref clocks (1152*16 core-clock cycles). + * + * 5. Write 0 to [DDR_DIV_RESET]. + * + * 6. Wait 10 ref clock cycles (160 core-clock cycles) before bringing up + * the DDR interface. + */ +union cvmx_lmcx_ddr_pll_ctl { + u64 u64; + struct cvmx_lmcx_ddr_pll_ctl_s { + uint64_t reserved_45_63:19; + uint64_t dclk_alt_refclk_sel:1; + uint64_t bwadj:12; + uint64_t dclk_invert:1; + uint64_t phy_dcok:1; + uint64_t ddr4_mode:1; + uint64_t pll_fbslip:1; + uint64_t pll_lock:1; + uint64_t reserved_18_26:9; + uint64_t diffamp:4; + uint64_t cps:3; + uint64_t reserved_8_10:3; + uint64_t reset_n:1; + uint64_t clkf:7; + } s; + struct cvmx_lmcx_ddr_pll_ctl_cn61xx { + uint64_t reserved_27_63:37; + uint64_t jtg_test_mode:1; + uint64_t dfm_div_reset:1; + uint64_t dfm_ps_en:3; + uint64_t ddr_div_reset:1; + uint64_t ddr_ps_en:3; + uint64_t diffamp:4; + uint64_t cps:3; + uint64_t cpb:3; + uint64_t reset_n:1; + uint64_t clkf:7; + } cn61xx; + struct cvmx_lmcx_ddr_pll_ctl_cn61xx cn63xx; + struct cvmx_lmcx_ddr_pll_ctl_cn61xx cn63xxp1; + struct cvmx_lmcx_ddr_pll_ctl_cn61xx cn66xx; + struct cvmx_lmcx_ddr_pll_ctl_cn61xx cn68xx; + struct cvmx_lmcx_ddr_pll_ctl_cn61xx cn68xxp1; + struct cvmx_lmcx_ddr_pll_ctl_cn70xx { + uint64_t reserved_31_63:33; + uint64_t phy_dcok:1; + uint64_t ddr4_mode:1; + uint64_t pll_fbslip:1; + uint64_t pll_lock:1; + uint64_t pll_rfslip:1; + uint64_t clkr:2; + uint64_t jtg_test_mode:1; + uint64_t ddr_div_reset:1; + uint64_t ddr_ps_en:4; + uint64_t reserved_8_17:10; + uint64_t reset_n:1; + uint64_t clkf:7; + } cn70xx; + struct cvmx_lmcx_ddr_pll_ctl_cn70xx cn70xxp1; + struct cvmx_lmcx_ddr_pll_ctl_cn73xx { + uint64_t reserved_45_63:19; + uint64_t dclk_alt_refclk_sel:1; + uint64_t bwadj:12; + uint64_t dclk_invert:1; + uint64_t phy_dcok:1; + uint64_t ddr4_mode:1; + uint64_t pll_fbslip:1; + uint64_t pll_lock:1; + uint64_t pll_rfslip:1; + uint64_t clkr:2; + uint64_t jtg_test_mode:1; + uint64_t ddr_div_reset:1; + uint64_t ddr_ps_en:4; + uint64_t reserved_9_17:9; + uint64_t clkf_ext:1; + uint64_t reset_n:1; + uint64_t clkf:7; + } cn73xx; + struct cvmx_lmcx_ddr_pll_ctl_cn73xx cn78xx; + struct cvmx_lmcx_ddr_pll_ctl_cn73xx cn78xxp1; + struct cvmx_lmcx_ddr_pll_ctl_cn61xx cnf71xx; + struct cvmx_lmcx_ddr_pll_ctl_cn73xx cnf75xx; +}; + +/** + * cvmx_lmc#_delay_cfg + * + * LMC_DELAY_CFG = Open-loop delay line settings + * + * + * Notes: + * The DQ bits add OUTGOING delay only to dq, dqs_[p,n], cb, cbs_[p,n], dqm. + * Delay is approximately 50-80ps per setting depending on process/voltage. + * There is no need to add incoming delay since by default all strobe bits + * are delayed internally by 90 degrees (as was always the case in previous + * passes and past chips. + * + * The CMD add delay to all command bits DDR_RAS, DDR_CAS, DDR_A<15:0>, + * DDR_BA<2:0>, DDR_n_CS<1:0>_L, DDR_WE, DDR_CKE and DDR_ODT_<7:0>. + * Again, delay is 50-80ps per tap. + * + * The CLK bits add delay to all clock signals DDR_CK_<5:0>_P and + * DDR_CK_<5:0>_N. Again, delay is 50-80ps per tap. + * + * The usage scenario is the following: There is too much delay on command + * signals and setup on command is not met. The user can then delay the + * clock until setup is met. + * + * At the same time though, dq/dqs should be delayed because there is also + * a DDR spec tying dqs with clock. If clock is too much delayed with + * respect to dqs, writes will start to fail. + * + * This scheme should eliminate the board need of adding routing delay to + * clock signals to make high frequencies work. + */ +union cvmx_lmcx_delay_cfg { + u64 u64; + struct cvmx_lmcx_delay_cfg_s { + uint64_t reserved_15_63:49; + uint64_t dq:5; + uint64_t cmd:5; + uint64_t clk:5; + } s; + struct cvmx_lmcx_delay_cfg_s cn30xx; + struct cvmx_lmcx_delay_cfg_cn38xx { + uint64_t reserved_14_63:50; + uint64_t dq:4; + uint64_t reserved_9_9:1; + uint64_t cmd:4; + uint64_t reserved_4_4:1; + uint64_t clk:4; + } cn38xx; + struct cvmx_lmcx_delay_cfg_cn38xx cn50xx; + struct cvmx_lmcx_delay_cfg_cn38xx cn52xx; + struct cvmx_lmcx_delay_cfg_cn38xx cn52xxp1; + struct cvmx_lmcx_delay_cfg_cn38xx cn56xx; + struct cvmx_lmcx_delay_cfg_cn38xx cn56xxp1; + struct cvmx_lmcx_delay_cfg_cn38xx cn58xx; + struct cvmx_lmcx_delay_cfg_cn38xx cn58xxp1; +}; + +/** + * cvmx_lmc#_dimm#_ddr4_params0 + * + * This register contains values to be programmed into the extra DDR4 control + * words in the corresponding (registered) DIMM. These are control words + * RC1x through RC8x. + */ +union cvmx_lmcx_dimmx_ddr4_params0 { + u64 u64; + struct cvmx_lmcx_dimmx_ddr4_params0_s { + uint64_t rc8x:8; + uint64_t rc7x:8; + uint64_t rc6x:8; + uint64_t rc5x:8; + uint64_t rc4x:8; + uint64_t rc3x:8; + uint64_t rc2x:8; + uint64_t rc1x:8; + } s; + struct cvmx_lmcx_dimmx_ddr4_params0_s cn70xx; + struct cvmx_lmcx_dimmx_ddr4_params0_s cn70xxp1; + struct cvmx_lmcx_dimmx_ddr4_params0_s cn73xx; + struct cvmx_lmcx_dimmx_ddr4_params0_s cn78xx; + struct cvmx_lmcx_dimmx_ddr4_params0_s cn78xxp1; + struct cvmx_lmcx_dimmx_ddr4_params0_s cnf75xx; +}; + +/** + * cvmx_lmc#_dimm#_ddr4_params1 + * + * This register contains values to be programmed into the extra DDR4 control + * words in the corresponding (registered) DIMM. These are control words + * RC9x through RCBx. + */ +union cvmx_lmcx_dimmx_ddr4_params1 { + u64 u64; + struct cvmx_lmcx_dimmx_ddr4_params1_s { + uint64_t reserved_24_63:40; + uint64_t rcbx:8; + uint64_t rcax:8; + uint64_t rc9x:8; + } s; + struct cvmx_lmcx_dimmx_ddr4_params1_s cn70xx; + struct cvmx_lmcx_dimmx_ddr4_params1_s cn70xxp1; + struct cvmx_lmcx_dimmx_ddr4_params1_s cn73xx; + struct cvmx_lmcx_dimmx_ddr4_params1_s cn78xx; + struct cvmx_lmcx_dimmx_ddr4_params1_s cn78xxp1; + struct cvmx_lmcx_dimmx_ddr4_params1_s cnf75xx; +}; + +/** + * cvmx_lmc#_dimm#_params + * + * This register contains values to be programmed into each control word in + * the corresponding (registered) DIMM. The control words allow optimization + * of the device properties for different raw card designs. Note that LMC + * only uses this CSR when LMC()_CONTROL[RDIMM_ENA]=1. During a power-up/init + * sequence, LMC writes these fields into the control words in the JEDEC + * standard DDR3 SSTE32882 registering clock driver or DDR4 Register + * DDR4RCD01 on an RDIMM when corresponding LMC()_DIMM_CTL[DIMM*_WMASK] + * bits are set. + */ +union cvmx_lmcx_dimmx_params { + u64 u64; + struct cvmx_lmcx_dimmx_params_s { + uint64_t rc15:4; + uint64_t rc14:4; + uint64_t rc13:4; + uint64_t rc12:4; + uint64_t rc11:4; + uint64_t rc10:4; + uint64_t rc9:4; + uint64_t rc8:4; + uint64_t rc7:4; + uint64_t rc6:4; + uint64_t rc5:4; + uint64_t rc4:4; + uint64_t rc3:4; + uint64_t rc2:4; + uint64_t rc1:4; + uint64_t rc0:4; + } s; + struct cvmx_lmcx_dimmx_params_s cn61xx; + struct cvmx_lmcx_dimmx_params_s cn63xx; + struct cvmx_lmcx_dimmx_params_s cn63xxp1; + struct cvmx_lmcx_dimmx_params_s cn66xx; + struct cvmx_lmcx_dimmx_params_s cn68xx; + struct cvmx_lmcx_dimmx_params_s cn68xxp1; + struct cvmx_lmcx_dimmx_params_s cn70xx; + struct cvmx_lmcx_dimmx_params_s cn70xxp1; + struct cvmx_lmcx_dimmx_params_s cn73xx; + struct cvmx_lmcx_dimmx_params_s cn78xx; + struct cvmx_lmcx_dimmx_params_s cn78xxp1; + struct cvmx_lmcx_dimmx_params_s cnf71xx; + struct cvmx_lmcx_dimmx_params_s cnf75xx; +}; + +/** + * cvmx_lmc#_dimm_ctl + * + * Note that this CSR is only used when LMC()_CONTROL[RDIMM_ENA] = 1. During + * a power-up/init sequence, this CSR controls LMC's write operations to the + * control words in the JEDEC standard DDR3 SSTE32882 registering clock + * driver or DDR4 Register DDR4RCD01 on an RDIMM. + */ +union cvmx_lmcx_dimm_ctl { + u64 u64; + struct cvmx_lmcx_dimm_ctl_s { + uint64_t reserved_46_63:18; + uint64_t parity:1; + uint64_t tcws:13; + uint64_t dimm1_wmask:16; + uint64_t dimm0_wmask:16; + } s; + struct cvmx_lmcx_dimm_ctl_s cn61xx; + struct cvmx_lmcx_dimm_ctl_s cn63xx; + struct cvmx_lmcx_dimm_ctl_s cn63xxp1; + struct cvmx_lmcx_dimm_ctl_s cn66xx; + struct cvmx_lmcx_dimm_ctl_s cn68xx; + struct cvmx_lmcx_dimm_ctl_s cn68xxp1; + struct cvmx_lmcx_dimm_ctl_s cn70xx; + struct cvmx_lmcx_dimm_ctl_s cn70xxp1; + struct cvmx_lmcx_dimm_ctl_s cn73xx; + struct cvmx_lmcx_dimm_ctl_s cn78xx; + struct cvmx_lmcx_dimm_ctl_s cn78xxp1; + struct cvmx_lmcx_dimm_ctl_s cnf71xx; + struct cvmx_lmcx_dimm_ctl_s cnf75xx; +}; + +/** + * cvmx_lmc#_dll_ctl + * + * LMC_DLL_CTL = LMC DLL control and DCLK reset + * + */ +union cvmx_lmcx_dll_ctl { + u64 u64; + struct cvmx_lmcx_dll_ctl_s { + uint64_t reserved_8_63:56; + uint64_t dreset:1; + uint64_t dll90_byp:1; + uint64_t dll90_ena:1; + uint64_t dll90_vlu:5; + } s; + struct cvmx_lmcx_dll_ctl_s cn52xx; + struct cvmx_lmcx_dll_ctl_s cn52xxp1; + struct cvmx_lmcx_dll_ctl_s cn56xx; + struct cvmx_lmcx_dll_ctl_s cn56xxp1; +}; + +/** + * cvmx_lmc#_dll_ctl2 + * + * See LMC initialization sequence for the initialization sequence. + * + */ +union cvmx_lmcx_dll_ctl2 { + u64 u64; + struct cvmx_lmcx_dll_ctl2_s { + uint64_t reserved_0_63:64; + } s; + struct cvmx_lmcx_dll_ctl2_cn61xx { + uint64_t reserved_16_63:48; + uint64_t intf_en:1; + uint64_t dll_bringup:1; + uint64_t dreset:1; + uint64_t quad_dll_ena:1; + uint64_t byp_sel:4; + uint64_t byp_setting:8; + } cn61xx; + struct cvmx_lmcx_dll_ctl2_cn63xx { + uint64_t reserved_15_63:49; + uint64_t dll_bringup:1; + uint64_t dreset:1; + uint64_t quad_dll_ena:1; + uint64_t byp_sel:4; + uint64_t byp_setting:8; + } cn63xx; + struct cvmx_lmcx_dll_ctl2_cn63xx cn63xxp1; + struct cvmx_lmcx_dll_ctl2_cn63xx cn66xx; + struct cvmx_lmcx_dll_ctl2_cn61xx cn68xx; + struct cvmx_lmcx_dll_ctl2_cn61xx cn68xxp1; + struct cvmx_lmcx_dll_ctl2_cn70xx { + uint64_t reserved_17_63:47; + uint64_t intf_en:1; + uint64_t dll_bringup:1; + uint64_t dreset:1; + uint64_t quad_dll_ena:1; + uint64_t byp_sel:4; + uint64_t byp_setting:9; + } cn70xx; + struct cvmx_lmcx_dll_ctl2_cn70xx cn70xxp1; + struct cvmx_lmcx_dll_ctl2_cn70xx cn73xx; + struct cvmx_lmcx_dll_ctl2_cn70xx cn78xx; + struct cvmx_lmcx_dll_ctl2_cn70xx cn78xxp1; + struct cvmx_lmcx_dll_ctl2_cn61xx cnf71xx; + struct cvmx_lmcx_dll_ctl2_cn70xx cnf75xx; +}; + +/** + * cvmx_lmc#_dll_ctl3 + * + * LMC_DLL_CTL3 = LMC DLL control and DCLK reset + * + */ +union cvmx_lmcx_dll_ctl3 { + u64 u64; + struct cvmx_lmcx_dll_ctl3_s { + uint64_t reserved_50_63:14; + uint64_t wr_deskew_ena:1; + uint64_t wr_deskew_ld:1; + uint64_t bit_select:4; + uint64_t reserved_0_43:44; + } s; + struct cvmx_lmcx_dll_ctl3_cn61xx { + uint64_t reserved_41_63:23; + uint64_t dclk90_fwd:1; + uint64_t ddr_90_dly_byp:1; + uint64_t dclk90_recal_dis:1; + uint64_t dclk90_byp_sel:1; + uint64_t dclk90_byp_setting:8; + uint64_t dll_fast:1; + uint64_t dll90_setting:8; + uint64_t fine_tune_mode:1; + uint64_t dll_mode:1; + uint64_t dll90_byte_sel:4; + uint64_t offset_ena:1; + uint64_t load_offset:1; + uint64_t mode_sel:2; + uint64_t byte_sel:4; + uint64_t offset:6; + } cn61xx; + struct cvmx_lmcx_dll_ctl3_cn63xx { + uint64_t reserved_29_63:35; + uint64_t dll_fast:1; + uint64_t dll90_setting:8; + uint64_t fine_tune_mode:1; + uint64_t dll_mode:1; + uint64_t dll90_byte_sel:4; + uint64_t offset_ena:1; + uint64_t load_offset:1; + uint64_t mode_sel:2; + uint64_t byte_sel:4; + uint64_t offset:6; + } cn63xx; + struct cvmx_lmcx_dll_ctl3_cn63xx cn63xxp1; + struct cvmx_lmcx_dll_ctl3_cn63xx cn66xx; + struct cvmx_lmcx_dll_ctl3_cn61xx cn68xx; + struct cvmx_lmcx_dll_ctl3_cn61xx cn68xxp1; + struct cvmx_lmcx_dll_ctl3_cn70xx { + uint64_t reserved_44_63:20; + uint64_t dclk90_fwd:1; + uint64_t ddr_90_dly_byp:1; + uint64_t dclk90_recal_dis:1; + uint64_t dclk90_byp_sel:1; + uint64_t dclk90_byp_setting:9; + uint64_t dll_fast:1; + uint64_t dll90_setting:9; + uint64_t fine_tune_mode:1; + uint64_t dll_mode:1; + uint64_t dll90_byte_sel:4; + uint64_t offset_ena:1; + uint64_t load_offset:1; + uint64_t mode_sel:2; + uint64_t byte_sel:4; + uint64_t offset:7; + } cn70xx; + struct cvmx_lmcx_dll_ctl3_cn70xx cn70xxp1; + struct cvmx_lmcx_dll_ctl3_cn73xx { + uint64_t reserved_50_63:14; + uint64_t wr_deskew_ena:1; + uint64_t wr_deskew_ld:1; + uint64_t bit_select:4; + uint64_t dclk90_fwd:1; + uint64_t ddr_90_dly_byp:1; + uint64_t dclk90_recal_dis:1; + uint64_t dclk90_byp_sel:1; + uint64_t dclk90_byp_setting:9; + uint64_t dll_fast:1; + uint64_t dll90_setting:9; + uint64_t fine_tune_mode:1; + uint64_t dll_mode:1; + uint64_t dll90_byte_sel:4; + uint64_t offset_ena:1; + uint64_t load_offset:1; + uint64_t mode_sel:2; + uint64_t byte_sel:4; + uint64_t offset:7; + } cn73xx; + struct cvmx_lmcx_dll_ctl3_cn73xx cn78xx; + struct cvmx_lmcx_dll_ctl3_cn73xx cn78xxp1; + struct cvmx_lmcx_dll_ctl3_cn61xx cnf71xx; + struct cvmx_lmcx_dll_ctl3_cn73xx cnf75xx; +}; + +/** + * cvmx_lmc#_dual_memcfg + * + * This register controls certain parameters of dual-memory configuration. + * + * This register enables the design to have two separate memory + * configurations, selected dynamically by the reference address. Note + * however, that both configurations share LMC()_CONTROL[XOR_BANK], + * LMC()_CONFIG [PBANK_LSB], LMC()_CONFIG[RANK_ENA], and all timing parameters. + * + * In this description: + * * config0 refers to the normal memory configuration that is defined by the + * LMC()_CONFIG[ROW_LSB] parameter + * * config1 refers to the dual (or second) memory configuration that is + * defined by this register. + */ +union cvmx_lmcx_dual_memcfg { + u64 u64; + struct cvmx_lmcx_dual_memcfg_s { + uint64_t reserved_20_63:44; + uint64_t bank8:1; + uint64_t row_lsb:3; + uint64_t reserved_8_15:8; + uint64_t cs_mask:8; + } s; + struct cvmx_lmcx_dual_memcfg_s cn50xx; + struct cvmx_lmcx_dual_memcfg_s cn52xx; + struct cvmx_lmcx_dual_memcfg_s cn52xxp1; + struct cvmx_lmcx_dual_memcfg_s cn56xx; + struct cvmx_lmcx_dual_memcfg_s cn56xxp1; + struct cvmx_lmcx_dual_memcfg_s cn58xx; + struct cvmx_lmcx_dual_memcfg_s cn58xxp1; + struct cvmx_lmcx_dual_memcfg_cn61xx { + uint64_t reserved_19_63:45; + uint64_t row_lsb:3; + uint64_t reserved_8_15:8; + uint64_t cs_mask:8; + } cn61xx; + struct cvmx_lmcx_dual_memcfg_cn61xx cn63xx; + struct cvmx_lmcx_dual_memcfg_cn61xx cn63xxp1; + struct cvmx_lmcx_dual_memcfg_cn61xx cn66xx; + struct cvmx_lmcx_dual_memcfg_cn61xx cn68xx; + struct cvmx_lmcx_dual_memcfg_cn61xx cn68xxp1; + struct cvmx_lmcx_dual_memcfg_cn70xx { + uint64_t reserved_19_63:45; + uint64_t row_lsb:3; + uint64_t reserved_4_15:12; + uint64_t cs_mask:4; + } cn70xx; + struct cvmx_lmcx_dual_memcfg_cn70xx cn70xxp1; + struct cvmx_lmcx_dual_memcfg_cn70xx cn73xx; + struct cvmx_lmcx_dual_memcfg_cn70xx cn78xx; + struct cvmx_lmcx_dual_memcfg_cn70xx cn78xxp1; + struct cvmx_lmcx_dual_memcfg_cn61xx cnf71xx; + struct cvmx_lmcx_dual_memcfg_cn70xx cnf75xx; +}; + +/** + * cvmx_lmc#_ecc_parity_test + * + * This register has bits to control the generation of ECC and command + * address parity errors. ECC error is generated by enabling + * [CA_PARITY_CORRUPT_ENA] and selecting any of the [ECC_CORRUPT_IDX] + * index of the dataword from the cacheline to be corrupted. + * User needs to select which bit of the 128-bit dataword to corrupt by + * asserting any of the CHAR_MASK0 and CHAR_MASK2 bits. (CHAR_MASK0 and + * CHAR_MASK2 corresponds to the lower and upper 64-bit signal that can + * corrupt any individual bit of the data). + * + * Command address parity error is generated by enabling + * [CA_PARITY_CORRUPT_ENA] and selecting the DDR command that the parity + * is to be corrupted with through [CA_PARITY_SEL]. + */ +union cvmx_lmcx_ecc_parity_test { + u64 u64; + struct cvmx_lmcx_ecc_parity_test_s { + uint64_t reserved_12_63:52; + uint64_t ecc_corrupt_ena:1; + uint64_t ecc_corrupt_idx:3; + uint64_t reserved_6_7:2; + uint64_t ca_parity_corrupt_ena:1; + uint64_t ca_parity_sel:5; + } s; + struct cvmx_lmcx_ecc_parity_test_s cn73xx; + struct cvmx_lmcx_ecc_parity_test_s cn78xx; + struct cvmx_lmcx_ecc_parity_test_s cn78xxp1; + struct cvmx_lmcx_ecc_parity_test_s cnf75xx; +}; + +/** + * cvmx_lmc#_ecc_synd + * + * LMC_ECC_SYND = MRD ECC Syndromes + * + */ +union cvmx_lmcx_ecc_synd { + u64 u64; + struct cvmx_lmcx_ecc_synd_s { + uint64_t reserved_32_63:32; + uint64_t mrdsyn3:8; + uint64_t mrdsyn2:8; + uint64_t mrdsyn1:8; + uint64_t mrdsyn0:8; + } s; + struct cvmx_lmcx_ecc_synd_s cn30xx; + struct cvmx_lmcx_ecc_synd_s cn31xx; + struct cvmx_lmcx_ecc_synd_s cn38xx; + struct cvmx_lmcx_ecc_synd_s cn38xxp2; + struct cvmx_lmcx_ecc_synd_s cn50xx; + struct cvmx_lmcx_ecc_synd_s cn52xx; + struct cvmx_lmcx_ecc_synd_s cn52xxp1; + struct cvmx_lmcx_ecc_synd_s cn56xx; + struct cvmx_lmcx_ecc_synd_s cn56xxp1; + struct cvmx_lmcx_ecc_synd_s cn58xx; + struct cvmx_lmcx_ecc_synd_s cn58xxp1; + struct cvmx_lmcx_ecc_synd_s cn61xx; + struct cvmx_lmcx_ecc_synd_s cn63xx; + struct cvmx_lmcx_ecc_synd_s cn63xxp1; + struct cvmx_lmcx_ecc_synd_s cn66xx; + struct cvmx_lmcx_ecc_synd_s cn68xx; + struct cvmx_lmcx_ecc_synd_s cn68xxp1; + struct cvmx_lmcx_ecc_synd_s cn70xx; + struct cvmx_lmcx_ecc_synd_s cn70xxp1; + struct cvmx_lmcx_ecc_synd_s cn73xx; + struct cvmx_lmcx_ecc_synd_s cn78xx; + struct cvmx_lmcx_ecc_synd_s cn78xxp1; + struct cvmx_lmcx_ecc_synd_s cnf71xx; + struct cvmx_lmcx_ecc_synd_s cnf75xx; +}; + +/** + * cvmx_lmc#_ext_config + * + * This register has additional configuration and control bits for the LMC. + * + */ +union cvmx_lmcx_ext_config { + u64 u64; + struct cvmx_lmcx_ext_config_s { + uint64_t reserved_61_63:3; + uint64_t bc4_dqs_ena:1; + uint64_t ref_block:1; + uint64_t mrs_side:1; + uint64_t mrs_one_side:1; + uint64_t mrs_bside_invert_disable:1; + uint64_t dimm_sel_invert_off:1; + uint64_t dimm_sel_force_invert:1; + uint64_t coalesce_address_mode:1; + uint64_t dimm1_cid:2; + uint64_t dimm0_cid:2; + uint64_t rcd_parity_check:1; + uint64_t reserved_46_47:2; + uint64_t error_alert_n_sample:1; + uint64_t ea_int_polarity:1; + uint64_t reserved_43_43:1; + uint64_t par_addr_mask:3; + uint64_t reserved_38_39:2; + uint64_t mrs_cmd_override:1; + uint64_t mrs_cmd_select:1; + uint64_t reserved_33_35:3; + uint64_t invert_data:1; + uint64_t reserved_30_31:2; + uint64_t cmd_rti:1; + uint64_t cal_ena:1; + uint64_t reserved_27_27:1; + uint64_t par_include_a17:1; + uint64_t par_include_bg1:1; + uint64_t gen_par:1; + uint64_t reserved_21_23:3; + uint64_t vrefint_seq_deskew:1; + uint64_t read_ena_bprch:1; + uint64_t read_ena_fprch:1; + uint64_t slot_ctl_reset_force:1; + uint64_t ref_int_lsbs:9; + uint64_t drive_ena_bprch:1; + uint64_t drive_ena_fprch:1; + uint64_t dlcram_flip_synd:2; + uint64_t dlcram_cor_dis:1; + uint64_t dlc_nxm_rd:1; + uint64_t l2c_nxm_rd:1; + uint64_t l2c_nxm_wr:1; + } s; + struct cvmx_lmcx_ext_config_cn70xx { + uint64_t reserved_21_63:43; + uint64_t vrefint_seq_deskew:1; + uint64_t read_ena_bprch:1; + uint64_t read_ena_fprch:1; + uint64_t slot_ctl_reset_force:1; + uint64_t ref_int_lsbs:9; + uint64_t drive_ena_bprch:1; + uint64_t drive_ena_fprch:1; + uint64_t dlcram_flip_synd:2; + uint64_t dlcram_cor_dis:1; + uint64_t dlc_nxm_rd:1; + uint64_t l2c_nxm_rd:1; + uint64_t l2c_nxm_wr:1; + } cn70xx; + struct cvmx_lmcx_ext_config_cn70xx cn70xxp1; + struct cvmx_lmcx_ext_config_cn73xx { + uint64_t reserved_60_63:4; + uint64_t ref_block:1; + uint64_t mrs_side:1; + uint64_t mrs_one_side:1; + uint64_t mrs_bside_invert_disable:1; + uint64_t dimm_sel_invert_off:1; + uint64_t dimm_sel_force_invert:1; + uint64_t coalesce_address_mode:1; + uint64_t dimm1_cid:2; + uint64_t dimm0_cid:2; + uint64_t rcd_parity_check:1; + uint64_t reserved_46_47:2; + uint64_t error_alert_n_sample:1; + uint64_t ea_int_polarity:1; + uint64_t reserved_43_43:1; + uint64_t par_addr_mask:3; + uint64_t reserved_38_39:2; + uint64_t mrs_cmd_override:1; + uint64_t mrs_cmd_select:1; + uint64_t reserved_33_35:3; + uint64_t invert_data:1; + uint64_t reserved_30_31:2; + uint64_t cmd_rti:1; + uint64_t cal_ena:1; + uint64_t reserved_27_27:1; + uint64_t par_include_a17:1; + uint64_t par_include_bg1:1; + uint64_t gen_par:1; + uint64_t reserved_21_23:3; + uint64_t vrefint_seq_deskew:1; + uint64_t read_ena_bprch:1; + uint64_t read_ena_fprch:1; + uint64_t slot_ctl_reset_force:1; + uint64_t ref_int_lsbs:9; + uint64_t drive_ena_bprch:1; + uint64_t drive_ena_fprch:1; + uint64_t dlcram_flip_synd:2; + uint64_t dlcram_cor_dis:1; + uint64_t dlc_nxm_rd:1; + uint64_t l2c_nxm_rd:1; + uint64_t l2c_nxm_wr:1; + } cn73xx; + struct cvmx_lmcx_ext_config_s cn78xx; + struct cvmx_lmcx_ext_config_s cn78xxp1; + struct cvmx_lmcx_ext_config_cn73xx cnf75xx; +}; + +/** + * cvmx_lmc#_ext_config2 + * + * This register has additional configuration and control bits for the LMC. + * + */ +union cvmx_lmcx_ext_config2 { + u64 u64; + struct cvmx_lmcx_ext_config2_s { + uint64_t reserved_27_63:37; + uint64_t sref_auto_idle_thres:5; + uint64_t sref_auto_enable:1; + uint64_t delay_unload_r3:1; + uint64_t delay_unload_r2:1; + uint64_t delay_unload_r1:1; + uint64_t delay_unload_r0:1; + uint64_t early_dqx2:1; + uint64_t xor_bank_sel:4; + uint64_t reserved_10_11:2; + uint64_t row_col_switch:1; + uint64_t trr_on:1; + uint64_t mac:3; + uint64_t macram_scrub_done:1; + uint64_t macram_scrub:1; + uint64_t macram_flip_synd:2; + uint64_t macram_cor_dis:1; + } s; + struct cvmx_lmcx_ext_config2_cn73xx { + uint64_t reserved_10_63:54; + uint64_t row_col_switch:1; + uint64_t trr_on:1; + uint64_t mac:3; + uint64_t macram_scrub_done:1; + uint64_t macram_scrub:1; + uint64_t macram_flip_synd:2; + uint64_t macram_cor_dis:1; + } cn73xx; + struct cvmx_lmcx_ext_config2_s cn78xx; + struct cvmx_lmcx_ext_config2_cnf75xx { + uint64_t reserved_21_63:43; + uint64_t delay_unload_r3:1; + uint64_t delay_unload_r2:1; + uint64_t delay_unload_r1:1; + uint64_t delay_unload_r0:1; + uint64_t early_dqx2:1; + uint64_t xor_bank_sel:4; + uint64_t reserved_10_11:2; + uint64_t row_col_switch:1; + uint64_t trr_on:1; + uint64_t mac:3; + uint64_t macram_scrub_done:1; + uint64_t macram_scrub:1; + uint64_t macram_flip_synd:2; + uint64_t macram_cor_dis:1; + } cnf75xx; +}; + +/** + * cvmx_lmc#_fadr + * + * This register only captures the first transaction with ECC errors. A DED + * error can over-write this register with its failing addresses if the + * first error was a SEC. If you write LMC()_INT -> SEC_ERR/DED_ERR, it + * clears the error bits and captures the next failing address. If FDIMM + * is 1, that means the error is in the high DIMM. LMC()_FADR captures the + * failing pre-scrambled address location (split into DIMM, bunk, bank, etc). + * If scrambling is off, then LMC()_FADR will also capture the failing + * physical location in the DRAM parts. LMC()_SCRAMBLED_FADR captures the + * actual failing address location in the physical DRAM parts, i.e., + * If scrambling is on, LMC()_SCRAMBLED_FADR contains the failing physical + * location in the DRAM parts (split into DIMM, bunk, bank, etc.) + * If scrambling is off, the pre-scramble and post-scramble addresses are + * the same; and so the contents of LMC()_SCRAMBLED_FADR match the contents + * of LMC()_FADR. + */ +union cvmx_lmcx_fadr { + u64 u64; + struct cvmx_lmcx_fadr_s { + uint64_t reserved_43_63:21; + uint64_t fcid:3; + uint64_t fill_order:2; + uint64_t reserved_0_37:38; + } s; + struct cvmx_lmcx_fadr_cn30xx { + uint64_t reserved_32_63:32; + uint64_t fdimm:2; + uint64_t fbunk:1; + uint64_t fbank:3; + uint64_t frow:14; + uint64_t fcol:12; + } cn30xx; + struct cvmx_lmcx_fadr_cn30xx cn31xx; + struct cvmx_lmcx_fadr_cn30xx cn38xx; + struct cvmx_lmcx_fadr_cn30xx cn38xxp2; + struct cvmx_lmcx_fadr_cn30xx cn50xx; + struct cvmx_lmcx_fadr_cn30xx cn52xx; + struct cvmx_lmcx_fadr_cn30xx cn52xxp1; + struct cvmx_lmcx_fadr_cn30xx cn56xx; + struct cvmx_lmcx_fadr_cn30xx cn56xxp1; + struct cvmx_lmcx_fadr_cn30xx cn58xx; + struct cvmx_lmcx_fadr_cn30xx cn58xxp1; + struct cvmx_lmcx_fadr_cn61xx { + uint64_t reserved_36_63:28; + uint64_t fdimm:2; + uint64_t fbunk:1; + uint64_t fbank:3; + uint64_t frow:16; + uint64_t fcol:14; + } cn61xx; + struct cvmx_lmcx_fadr_cn61xx cn63xx; + struct cvmx_lmcx_fadr_cn61xx cn63xxp1; + struct cvmx_lmcx_fadr_cn61xx cn66xx; + struct cvmx_lmcx_fadr_cn61xx cn68xx; + struct cvmx_lmcx_fadr_cn61xx cn68xxp1; + struct cvmx_lmcx_fadr_cn70xx { + uint64_t reserved_40_63:24; + uint64_t fill_order:2; + uint64_t fdimm:1; + uint64_t fbunk:1; + uint64_t fbank:4; + uint64_t frow:18; + uint64_t fcol:14; + } cn70xx; + struct cvmx_lmcx_fadr_cn70xx cn70xxp1; + struct cvmx_lmcx_fadr_cn73xx { + uint64_t reserved_43_63:21; + uint64_t fcid:3; + uint64_t fill_order:2; + uint64_t fdimm:1; + uint64_t fbunk:1; + uint64_t fbank:4; + uint64_t frow:18; + uint64_t fcol:14; + } cn73xx; + struct cvmx_lmcx_fadr_cn73xx cn78xx; + struct cvmx_lmcx_fadr_cn73xx cn78xxp1; + struct cvmx_lmcx_fadr_cn61xx cnf71xx; + struct cvmx_lmcx_fadr_cn73xx cnf75xx; +}; + +/** + * cvmx_lmc#_general_purpose0 + */ +union cvmx_lmcx_general_purpose0 { + u64 u64; + struct cvmx_lmcx_general_purpose0_s { + uint64_t data:64; + } s; + struct cvmx_lmcx_general_purpose0_s cn73xx; + struct cvmx_lmcx_general_purpose0_s cn78xx; + struct cvmx_lmcx_general_purpose0_s cnf75xx; +}; + +/** + * cvmx_lmc#_general_purpose1 + */ +union cvmx_lmcx_general_purpose1 { + u64 u64; + struct cvmx_lmcx_general_purpose1_s { + uint64_t data:64; + } s; + struct cvmx_lmcx_general_purpose1_s cn73xx; + struct cvmx_lmcx_general_purpose1_s cn78xx; + struct cvmx_lmcx_general_purpose1_s cnf75xx; +}; + +/** + * cvmx_lmc#_general_purpose2 + */ +union cvmx_lmcx_general_purpose2 { + u64 u64; + struct cvmx_lmcx_general_purpose2_s { + uint64_t reserved_16_63:48; + uint64_t data:16; + } s; + struct cvmx_lmcx_general_purpose2_s cn73xx; + struct cvmx_lmcx_general_purpose2_s cn78xx; + struct cvmx_lmcx_general_purpose2_s cnf75xx; +}; + +/** + * cvmx_lmc#_ifb_cnt + * + * LMC_IFB_CNT = Performance Counters + * + */ +union cvmx_lmcx_ifb_cnt { + u64 u64; + struct cvmx_lmcx_ifb_cnt_s { + uint64_t ifbcnt:64; + } s; + struct cvmx_lmcx_ifb_cnt_s cn61xx; + struct cvmx_lmcx_ifb_cnt_s cn63xx; + struct cvmx_lmcx_ifb_cnt_s cn63xxp1; + struct cvmx_lmcx_ifb_cnt_s cn66xx; + struct cvmx_lmcx_ifb_cnt_s cn68xx; + struct cvmx_lmcx_ifb_cnt_s cn68xxp1; + struct cvmx_lmcx_ifb_cnt_s cn70xx; + struct cvmx_lmcx_ifb_cnt_s cn70xxp1; + struct cvmx_lmcx_ifb_cnt_s cn73xx; + struct cvmx_lmcx_ifb_cnt_s cn78xx; + struct cvmx_lmcx_ifb_cnt_s cn78xxp1; + struct cvmx_lmcx_ifb_cnt_s cnf71xx; + struct cvmx_lmcx_ifb_cnt_s cnf75xx; +}; + +/** + * cvmx_lmc#_ifb_cnt_hi + * + * LMC_IFB_CNT_HI = Performance Counters + * + */ +union cvmx_lmcx_ifb_cnt_hi { + u64 u64; + struct cvmx_lmcx_ifb_cnt_hi_s { + uint64_t reserved_32_63:32; + uint64_t ifbcnt_hi:32; + } s; + struct cvmx_lmcx_ifb_cnt_hi_s cn30xx; + struct cvmx_lmcx_ifb_cnt_hi_s cn31xx; + struct cvmx_lmcx_ifb_cnt_hi_s cn38xx; + struct cvmx_lmcx_ifb_cnt_hi_s cn38xxp2; + struct cvmx_lmcx_ifb_cnt_hi_s cn50xx; + struct cvmx_lmcx_ifb_cnt_hi_s cn52xx; + struct cvmx_lmcx_ifb_cnt_hi_s cn52xxp1; + struct cvmx_lmcx_ifb_cnt_hi_s cn56xx; + struct cvmx_lmcx_ifb_cnt_hi_s cn56xxp1; + struct cvmx_lmcx_ifb_cnt_hi_s cn58xx; + struct cvmx_lmcx_ifb_cnt_hi_s cn58xxp1; +}; + +/** + * cvmx_lmc#_ifb_cnt_lo + * + * LMC_IFB_CNT_LO = Performance Counters + * + */ +union cvmx_lmcx_ifb_cnt_lo { + u64 u64; + struct cvmx_lmcx_ifb_cnt_lo_s { + uint64_t reserved_32_63:32; + uint64_t ifbcnt_lo:32; + } s; + struct cvmx_lmcx_ifb_cnt_lo_s cn30xx; + struct cvmx_lmcx_ifb_cnt_lo_s cn31xx; + struct cvmx_lmcx_ifb_cnt_lo_s cn38xx; + struct cvmx_lmcx_ifb_cnt_lo_s cn38xxp2; + struct cvmx_lmcx_ifb_cnt_lo_s cn50xx; + struct cvmx_lmcx_ifb_cnt_lo_s cn52xx; + struct cvmx_lmcx_ifb_cnt_lo_s cn52xxp1; + struct cvmx_lmcx_ifb_cnt_lo_s cn56xx; + struct cvmx_lmcx_ifb_cnt_lo_s cn56xxp1; + struct cvmx_lmcx_ifb_cnt_lo_s cn58xx; + struct cvmx_lmcx_ifb_cnt_lo_s cn58xxp1; +}; + +/** + * cvmx_lmc#_int + * + * This register contains the different interrupt-summary bits of the LMC. + * + */ +union cvmx_lmcx_int { + u64 u64; + struct cvmx_lmcx_int_s { + uint64_t reserved_14_63:50; + uint64_t macram_ded_err:1; + uint64_t macram_sec_err:1; + uint64_t ddr_err:1; + uint64_t dlcram_ded_err:1; + uint64_t dlcram_sec_err:1; + uint64_t ded_err:4; + uint64_t sec_err:4; + uint64_t nxm_wr_err:1; + } s; + struct cvmx_lmcx_int_cn61xx { + uint64_t reserved_9_63:55; + uint64_t ded_err:4; + uint64_t sec_err:4; + uint64_t nxm_wr_err:1; + } cn61xx; + struct cvmx_lmcx_int_cn61xx cn63xx; + struct cvmx_lmcx_int_cn61xx cn63xxp1; + struct cvmx_lmcx_int_cn61xx cn66xx; + struct cvmx_lmcx_int_cn61xx cn68xx; + struct cvmx_lmcx_int_cn61xx cn68xxp1; + struct cvmx_lmcx_int_cn70xx { + uint64_t reserved_12_63:52; + uint64_t ddr_err:1; + uint64_t dlcram_ded_err:1; + uint64_t dlcram_sec_err:1; + uint64_t ded_err:4; + uint64_t sec_err:4; + uint64_t nxm_wr_err:1; + } cn70xx; + struct cvmx_lmcx_int_cn70xx cn70xxp1; + struct cvmx_lmcx_int_s cn73xx; + struct cvmx_lmcx_int_s cn78xx; + struct cvmx_lmcx_int_s cn78xxp1; + struct cvmx_lmcx_int_cn61xx cnf71xx; + struct cvmx_lmcx_int_s cnf75xx; +}; + +/** + * cvmx_lmc#_int_en + * + * Unused CSR in O75. + * + */ +union cvmx_lmcx_int_en { + u64 u64; + struct cvmx_lmcx_int_en_s { + uint64_t reserved_6_63:58; + uint64_t ddr_error_alert_ena:1; + uint64_t dlcram_ded_ena:1; + uint64_t dlcram_sec_ena:1; + uint64_t intr_ded_ena:1; + uint64_t intr_sec_ena:1; + uint64_t intr_nxm_wr_ena:1; + } s; + struct cvmx_lmcx_int_en_cn61xx { + uint64_t reserved_3_63:61; + uint64_t intr_ded_ena:1; + uint64_t intr_sec_ena:1; + uint64_t intr_nxm_wr_ena:1; + } cn61xx; + struct cvmx_lmcx_int_en_cn61xx cn63xx; + struct cvmx_lmcx_int_en_cn61xx cn63xxp1; + struct cvmx_lmcx_int_en_cn61xx cn66xx; + struct cvmx_lmcx_int_en_cn61xx cn68xx; + struct cvmx_lmcx_int_en_cn61xx cn68xxp1; + struct cvmx_lmcx_int_en_s cn70xx; + struct cvmx_lmcx_int_en_s cn70xxp1; + struct cvmx_lmcx_int_en_s cn73xx; + struct cvmx_lmcx_int_en_s cn78xx; + struct cvmx_lmcx_int_en_s cn78xxp1; + struct cvmx_lmcx_int_en_cn61xx cnf71xx; + struct cvmx_lmcx_int_en_s cnf75xx; +}; + +/** + * cvmx_lmc#_lane#_crc_swiz + * + * This register contains the CRC bit swizzle for even and odd ranks. + * + */ +union cvmx_lmcx_lanex_crc_swiz { + u64 u64; + struct cvmx_lmcx_lanex_crc_swiz_s { + uint64_t reserved_56_63:8; + uint64_t r1_swiz7:3; + uint64_t r1_swiz6:3; + uint64_t r1_swiz5:3; + uint64_t r1_swiz4:3; + uint64_t r1_swiz3:3; + uint64_t r1_swiz2:3; + uint64_t r1_swiz1:3; + uint64_t r1_swiz0:3; + uint64_t reserved_24_31:8; + uint64_t r0_swiz7:3; + uint64_t r0_swiz6:3; + uint64_t r0_swiz5:3; + uint64_t r0_swiz4:3; + uint64_t r0_swiz3:3; + uint64_t r0_swiz2:3; + uint64_t r0_swiz1:3; + uint64_t r0_swiz0:3; + } s; + struct cvmx_lmcx_lanex_crc_swiz_s cn73xx; + struct cvmx_lmcx_lanex_crc_swiz_s cn78xx; + struct cvmx_lmcx_lanex_crc_swiz_s cn78xxp1; + struct cvmx_lmcx_lanex_crc_swiz_s cnf75xx; +}; + +/** + * cvmx_lmc#_mem_cfg0 + * + * Specify the RSL base addresses for the block + * + * LMC_MEM_CFG0 = LMC Memory Configuration Register0 + * + * This register controls certain parameters of Memory Configuration + */ +union cvmx_lmcx_mem_cfg0 { + u64 u64; + struct cvmx_lmcx_mem_cfg0_s { + uint64_t reserved_32_63:32; + uint64_t reset:1; + uint64_t silo_qc:1; + uint64_t bunk_ena:1; + uint64_t ded_err:4; + uint64_t sec_err:4; + uint64_t intr_ded_ena:1; + uint64_t intr_sec_ena:1; + uint64_t tcl:4; + uint64_t ref_int:6; + uint64_t pbank_lsb:4; + uint64_t row_lsb:3; + uint64_t ecc_ena:1; + uint64_t init_start:1; + } s; + struct cvmx_lmcx_mem_cfg0_s cn30xx; + struct cvmx_lmcx_mem_cfg0_s cn31xx; + struct cvmx_lmcx_mem_cfg0_s cn38xx; + struct cvmx_lmcx_mem_cfg0_s cn38xxp2; + struct cvmx_lmcx_mem_cfg0_s cn50xx; + struct cvmx_lmcx_mem_cfg0_s cn52xx; + struct cvmx_lmcx_mem_cfg0_s cn52xxp1; + struct cvmx_lmcx_mem_cfg0_s cn56xx; + struct cvmx_lmcx_mem_cfg0_s cn56xxp1; + struct cvmx_lmcx_mem_cfg0_s cn58xx; + struct cvmx_lmcx_mem_cfg0_s cn58xxp1; +}; + +/** + * cvmx_lmc#_mem_cfg1 + * + * LMC_MEM_CFG1 = LMC Memory Configuration Register1 + * + * This register controls the External Memory Configuration Timing Parameters. + * Please refer to the appropriate DDR part spec from your memory vendor for + * the various values in this CSR. The details of each of these timing + * parameters can be found in the JEDEC spec or the vendor spec of the + * memory parts. + */ +union cvmx_lmcx_mem_cfg1 { + u64 u64; + struct cvmx_lmcx_mem_cfg1_s { + uint64_t reserved_32_63:32; + uint64_t comp_bypass:1; + uint64_t trrd:3; + uint64_t caslat:3; + uint64_t tmrd:3; + uint64_t trfc:5; + uint64_t trp:4; + uint64_t twtr:4; + uint64_t trcd:4; + uint64_t tras:5; + } s; + struct cvmx_lmcx_mem_cfg1_s cn30xx; + struct cvmx_lmcx_mem_cfg1_s cn31xx; + struct cvmx_lmcx_mem_cfg1_cn38xx { + uint64_t reserved_31_63:33; + uint64_t trrd:3; + uint64_t caslat:3; + uint64_t tmrd:3; + uint64_t trfc:5; + uint64_t trp:4; + uint64_t twtr:4; + uint64_t trcd:4; + uint64_t tras:5; + } cn38xx; + struct cvmx_lmcx_mem_cfg1_cn38xx cn38xxp2; + struct cvmx_lmcx_mem_cfg1_s cn50xx; + struct cvmx_lmcx_mem_cfg1_cn38xx cn52xx; + struct cvmx_lmcx_mem_cfg1_cn38xx cn52xxp1; + struct cvmx_lmcx_mem_cfg1_cn38xx cn56xx; + struct cvmx_lmcx_mem_cfg1_cn38xx cn56xxp1; + struct cvmx_lmcx_mem_cfg1_cn38xx cn58xx; + struct cvmx_lmcx_mem_cfg1_cn38xx cn58xxp1; +}; + +/** + * cvmx_lmc#_modereg_params0 + * + * These parameters are written into the DDR3/DDR4 MR0, MR1, MR2 and MR3 + * registers. + * + */ +union cvmx_lmcx_modereg_params0 { + u64 u64; + struct cvmx_lmcx_modereg_params0_s { + uint64_t reserved_28_63:36; + uint64_t wrp_ext:1; + uint64_t cl_ext:1; + uint64_t al_ext:1; + uint64_t ppd:1; + uint64_t wrp:3; + uint64_t dllr:1; + uint64_t tm:1; + uint64_t rbt:1; + uint64_t cl:4; + uint64_t bl:2; + uint64_t qoff:1; + uint64_t tdqs:1; + uint64_t wlev:1; + uint64_t al:2; + uint64_t dll:1; + uint64_t mpr:1; + uint64_t mprloc:2; + uint64_t cwl:3; + } s; + struct cvmx_lmcx_modereg_params0_cn61xx { + uint64_t reserved_25_63:39; + uint64_t ppd:1; + uint64_t wrp:3; + uint64_t dllr:1; + uint64_t tm:1; + uint64_t rbt:1; + uint64_t cl:4; + uint64_t bl:2; + uint64_t qoff:1; + uint64_t tdqs:1; + uint64_t wlev:1; + uint64_t al:2; + uint64_t dll:1; + uint64_t mpr:1; + uint64_t mprloc:2; + uint64_t cwl:3; + } cn61xx; + struct cvmx_lmcx_modereg_params0_cn61xx cn63xx; + struct cvmx_lmcx_modereg_params0_cn61xx cn63xxp1; + struct cvmx_lmcx_modereg_params0_cn61xx cn66xx; + struct cvmx_lmcx_modereg_params0_cn61xx cn68xx; + struct cvmx_lmcx_modereg_params0_cn61xx cn68xxp1; + struct cvmx_lmcx_modereg_params0_cn61xx cn70xx; + struct cvmx_lmcx_modereg_params0_cn61xx cn70xxp1; + struct cvmx_lmcx_modereg_params0_s cn73xx; + struct cvmx_lmcx_modereg_params0_s cn78xx; + struct cvmx_lmcx_modereg_params0_s cn78xxp1; + struct cvmx_lmcx_modereg_params0_cn61xx cnf71xx; + struct cvmx_lmcx_modereg_params0_s cnf75xx; +}; + +/** + * cvmx_lmc#_modereg_params1 + * + * These parameters are written into the DDR3 MR0, MR1, MR2 and MR3 registers. + * + */ +union cvmx_lmcx_modereg_params1 { + u64 u64; + struct cvmx_lmcx_modereg_params1_s { + uint64_t reserved_55_63:9; + uint64_t rtt_wr_11_ext:1; + uint64_t rtt_wr_10_ext:1; + uint64_t rtt_wr_01_ext:1; + uint64_t rtt_wr_00_ext:1; + uint64_t db_output_impedance:3; + uint64_t rtt_nom_11:3; + uint64_t dic_11:2; + uint64_t rtt_wr_11:2; + uint64_t srt_11:1; + uint64_t asr_11:1; + uint64_t pasr_11:3; + uint64_t rtt_nom_10:3; + uint64_t dic_10:2; + uint64_t rtt_wr_10:2; + uint64_t srt_10:1; + uint64_t asr_10:1; + uint64_t pasr_10:3; + uint64_t rtt_nom_01:3; + uint64_t dic_01:2; + uint64_t rtt_wr_01:2; + uint64_t srt_01:1; + uint64_t asr_01:1; + uint64_t pasr_01:3; + uint64_t rtt_nom_00:3; + uint64_t dic_00:2; + uint64_t rtt_wr_00:2; + uint64_t srt_00:1; + uint64_t asr_00:1; + uint64_t pasr_00:3; + } s; + struct cvmx_lmcx_modereg_params1_cn61xx { + uint64_t reserved_48_63:16; + uint64_t rtt_nom_11:3; + uint64_t dic_11:2; + uint64_t rtt_wr_11:2; + uint64_t srt_11:1; + uint64_t asr_11:1; + uint64_t pasr_11:3; + uint64_t rtt_nom_10:3; + uint64_t dic_10:2; + uint64_t rtt_wr_10:2; + uint64_t srt_10:1; + uint64_t asr_10:1; + uint64_t pasr_10:3; + uint64_t rtt_nom_01:3; + uint64_t dic_01:2; + uint64_t rtt_wr_01:2; + uint64_t srt_01:1; + uint64_t asr_01:1; + uint64_t pasr_01:3; + uint64_t rtt_nom_00:3; + uint64_t dic_00:2; + uint64_t rtt_wr_00:2; + uint64_t srt_00:1; + uint64_t asr_00:1; + uint64_t pasr_00:3; + } cn61xx; + struct cvmx_lmcx_modereg_params1_cn61xx cn63xx; + struct cvmx_lmcx_modereg_params1_cn61xx cn63xxp1; + struct cvmx_lmcx_modereg_params1_cn61xx cn66xx; + struct cvmx_lmcx_modereg_params1_cn61xx cn68xx; + struct cvmx_lmcx_modereg_params1_cn61xx cn68xxp1; + struct cvmx_lmcx_modereg_params1_cn61xx cn70xx; + struct cvmx_lmcx_modereg_params1_cn61xx cn70xxp1; + struct cvmx_lmcx_modereg_params1_s cn73xx; + struct cvmx_lmcx_modereg_params1_s cn78xx; + struct cvmx_lmcx_modereg_params1_s cn78xxp1; + struct cvmx_lmcx_modereg_params1_cn61xx cnf71xx; + struct cvmx_lmcx_modereg_params1_s cnf75xx; +}; + +/** + * cvmx_lmc#_modereg_params2 + * + * These parameters are written into the DDR4 mode registers. + * + */ +union cvmx_lmcx_modereg_params2 { + u64 u64; + struct cvmx_lmcx_modereg_params2_s { + uint64_t reserved_41_63:23; + uint64_t vrefdq_train_en:1; + uint64_t vref_range_11:1; + uint64_t vref_value_11:6; + uint64_t rtt_park_11:3; + uint64_t vref_range_10:1; + uint64_t vref_value_10:6; + uint64_t rtt_park_10:3; + uint64_t vref_range_01:1; + uint64_t vref_value_01:6; + uint64_t rtt_park_01:3; + uint64_t vref_range_00:1; + uint64_t vref_value_00:6; + uint64_t rtt_park_00:3; + } s; + struct cvmx_lmcx_modereg_params2_s cn70xx; + struct cvmx_lmcx_modereg_params2_cn70xxp1 { + uint64_t reserved_40_63:24; + uint64_t vref_range_11:1; + uint64_t vref_value_11:6; + uint64_t rtt_park_11:3; + uint64_t vref_range_10:1; + uint64_t vref_value_10:6; + uint64_t rtt_park_10:3; + uint64_t vref_range_01:1; + uint64_t vref_value_01:6; + uint64_t rtt_park_01:3; + uint64_t vref_range_00:1; + uint64_t vref_value_00:6; + uint64_t rtt_park_00:3; + } cn70xxp1; + struct cvmx_lmcx_modereg_params2_s cn73xx; + struct cvmx_lmcx_modereg_params2_s cn78xx; + struct cvmx_lmcx_modereg_params2_s cn78xxp1; + struct cvmx_lmcx_modereg_params2_s cnf75xx; +}; + +/** + * cvmx_lmc#_modereg_params3 + * + * These parameters are written into the DDR4 mode registers. + * + */ +union cvmx_lmcx_modereg_params3 { + u64 u64; + struct cvmx_lmcx_modereg_params3_s { + uint64_t reserved_39_63:25; + uint64_t xrank_add_tccd_l:3; + uint64_t xrank_add_tccd_s:3; + uint64_t mpr_fmt:2; + uint64_t wr_cmd_lat:2; + uint64_t fgrm:3; + uint64_t temp_sense:1; + uint64_t pda:1; + uint64_t gd:1; + uint64_t crc:1; + uint64_t lpasr:2; + uint64_t tccd_l:3; + uint64_t rd_dbi:1; + uint64_t wr_dbi:1; + uint64_t dm:1; + uint64_t ca_par_pers:1; + uint64_t odt_pd:1; + uint64_t par_lat_mode:3; + uint64_t wr_preamble:1; + uint64_t rd_preamble:1; + uint64_t sre_abort:1; + uint64_t cal:3; + uint64_t vref_mon:1; + uint64_t tc_ref:1; + uint64_t max_pd:1; + } s; + struct cvmx_lmcx_modereg_params3_cn70xx { + uint64_t reserved_33_63:31; + uint64_t mpr_fmt:2; + uint64_t wr_cmd_lat:2; + uint64_t fgrm:3; + uint64_t temp_sense:1; + uint64_t pda:1; + uint64_t gd:1; + uint64_t crc:1; + uint64_t lpasr:2; + uint64_t tccd_l:3; + uint64_t rd_dbi:1; + uint64_t wr_dbi:1; + uint64_t dm:1; + uint64_t ca_par_pers:1; + uint64_t odt_pd:1; + uint64_t par_lat_mode:3; + uint64_t wr_preamble:1; + uint64_t rd_preamble:1; + uint64_t sre_abort:1; + uint64_t cal:3; + uint64_t vref_mon:1; + uint64_t tc_ref:1; + uint64_t max_pd:1; + } cn70xx; + struct cvmx_lmcx_modereg_params3_cn70xx cn70xxp1; + struct cvmx_lmcx_modereg_params3_s cn73xx; + struct cvmx_lmcx_modereg_params3_s cn78xx; + struct cvmx_lmcx_modereg_params3_s cn78xxp1; + struct cvmx_lmcx_modereg_params3_s cnf75xx; +}; + +/** + * cvmx_lmc#_mpr_data0 + * + * This register provides bits <63:0> of MPR data register. + * + */ +union cvmx_lmcx_mpr_data0 { + u64 u64; + struct cvmx_lmcx_mpr_data0_s { + uint64_t mpr_data:64; + } s; + struct cvmx_lmcx_mpr_data0_s cn70xx; + struct cvmx_lmcx_mpr_data0_s cn70xxp1; + struct cvmx_lmcx_mpr_data0_s cn73xx; + struct cvmx_lmcx_mpr_data0_s cn78xx; + struct cvmx_lmcx_mpr_data0_s cn78xxp1; + struct cvmx_lmcx_mpr_data0_s cnf75xx; +}; + +/** + * cvmx_lmc#_mpr_data1 + * + * This register provides bits <127:64> of MPR data register. + * + */ +union cvmx_lmcx_mpr_data1 { + u64 u64; + struct cvmx_lmcx_mpr_data1_s { + uint64_t mpr_data:64; + } s; + struct cvmx_lmcx_mpr_data1_s cn70xx; + struct cvmx_lmcx_mpr_data1_s cn70xxp1; + struct cvmx_lmcx_mpr_data1_s cn73xx; + struct cvmx_lmcx_mpr_data1_s cn78xx; + struct cvmx_lmcx_mpr_data1_s cn78xxp1; + struct cvmx_lmcx_mpr_data1_s cnf75xx; +}; + +/** + * cvmx_lmc#_mpr_data2 + * + * This register provides bits <143:128> of MPR data register. + * + */ +union cvmx_lmcx_mpr_data2 { + u64 u64; + struct cvmx_lmcx_mpr_data2_s { + uint64_t reserved_16_63:48; + uint64_t mpr_data:16; + } s; + struct cvmx_lmcx_mpr_data2_s cn70xx; + struct cvmx_lmcx_mpr_data2_s cn70xxp1; + struct cvmx_lmcx_mpr_data2_s cn73xx; + struct cvmx_lmcx_mpr_data2_s cn78xx; + struct cvmx_lmcx_mpr_data2_s cn78xxp1; + struct cvmx_lmcx_mpr_data2_s cnf75xx; +}; + +/** + * cvmx_lmc#_mr_mpr_ctl + * + * This register provides the control functions when programming the MPR + * of DDR4 DRAMs. + * + */ +union cvmx_lmcx_mr_mpr_ctl { + u64 u64; + struct cvmx_lmcx_mr_mpr_ctl_s { + uint64_t reserved_61_63:3; + uint64_t mr_wr_secure_key_ena:1; + uint64_t pba_func_space:3; + uint64_t mr_wr_bg1:1; + uint64_t mpr_sample_dq_enable:1; + uint64_t pda_early_dqx:1; + uint64_t mr_wr_pba_enable:1; + uint64_t mr_wr_use_default_value:1; + uint64_t mpr_whole_byte_enable:1; + uint64_t mpr_byte_select:4; + uint64_t mpr_bit_select:2; + uint64_t mpr_wr:1; + uint64_t mpr_loc:2; + uint64_t mr_wr_pda_enable:1; + uint64_t mr_wr_pda_mask:18; + uint64_t mr_wr_rank:2; + uint64_t mr_wr_sel:3; + uint64_t mr_wr_addr:18; + } s; + struct cvmx_lmcx_mr_mpr_ctl_cn70xx { + uint64_t reserved_52_63:12; + uint64_t mpr_whole_byte_enable:1; + uint64_t mpr_byte_select:4; + uint64_t mpr_bit_select:2; + uint64_t mpr_wr:1; + uint64_t mpr_loc:2; + uint64_t mr_wr_pda_enable:1; + uint64_t mr_wr_pda_mask:18; + uint64_t mr_wr_rank:2; + uint64_t mr_wr_sel:3; + uint64_t mr_wr_addr:18; + } cn70xx; + struct cvmx_lmcx_mr_mpr_ctl_cn70xx cn70xxp1; + struct cvmx_lmcx_mr_mpr_ctl_s cn73xx; + struct cvmx_lmcx_mr_mpr_ctl_s cn78xx; + struct cvmx_lmcx_mr_mpr_ctl_s cn78xxp1; + struct cvmx_lmcx_mr_mpr_ctl_s cnf75xx; +}; + +/** + * cvmx_lmc#_ns_ctl + * + * This register contains control parameters for handling nonsecure accesses. + * + */ +union cvmx_lmcx_ns_ctl { + u64 u64; + struct cvmx_lmcx_ns_ctl_s { + uint64_t reserved_26_63:38; + uint64_t ns_scramble_dis:1; + uint64_t reserved_18_24:7; + uint64_t adr_offset:18; + } s; + struct cvmx_lmcx_ns_ctl_s cn73xx; + struct cvmx_lmcx_ns_ctl_s cn78xx; + struct cvmx_lmcx_ns_ctl_s cnf75xx; +}; + +/** + * cvmx_lmc#_nxm + * + * Following is the decoding for mem_msb/rank: + * 0x0: mem_msb = mem_adr[25]. + * 0x1: mem_msb = mem_adr[26]. + * 0x2: mem_msb = mem_adr[27]. + * 0x3: mem_msb = mem_adr[28]. + * 0x4: mem_msb = mem_adr[29]. + * 0x5: mem_msb = mem_adr[30]. + * 0x6: mem_msb = mem_adr[31]. + * 0x7: mem_msb = mem_adr[32]. + * 0x8: mem_msb = mem_adr[33]. + * 0x9: mem_msb = mem_adr[34]. + * 0xA: mem_msb = mem_adr[35]. + * 0xB: mem_msb = mem_adr[36]. + * 0xC-0xF = Reserved. + * + * For example, for a DIMM made of Samsung's K4B1G0846C-ZCF7 1Gb + * (16M * 8 bit * 8 bank) parts, the column address width = 10; so with + * 10b of col, 3b of bus, 3b of bank, row_lsb = 16. + * Therefore, row = mem_adr[29:16] and mem_msb = 4. + * + * Note also that addresses greater than the max defined space (pbank_msb) + * are also treated as NXM accesses. + */ +union cvmx_lmcx_nxm { + u64 u64; + struct cvmx_lmcx_nxm_s { + uint64_t reserved_40_63:24; + uint64_t mem_msb_d3_r1:4; + uint64_t mem_msb_d3_r0:4; + uint64_t mem_msb_d2_r1:4; + uint64_t mem_msb_d2_r0:4; + uint64_t mem_msb_d1_r1:4; + uint64_t mem_msb_d1_r0:4; + uint64_t mem_msb_d0_r1:4; + uint64_t mem_msb_d0_r0:4; + uint64_t cs_mask:8; + } s; + struct cvmx_lmcx_nxm_cn52xx { + uint64_t reserved_8_63:56; + uint64_t cs_mask:8; + } cn52xx; + struct cvmx_lmcx_nxm_cn52xx cn56xx; + struct cvmx_lmcx_nxm_cn52xx cn58xx; + struct cvmx_lmcx_nxm_s cn61xx; + struct cvmx_lmcx_nxm_s cn63xx; + struct cvmx_lmcx_nxm_s cn63xxp1; + struct cvmx_lmcx_nxm_s cn66xx; + struct cvmx_lmcx_nxm_s cn68xx; + struct cvmx_lmcx_nxm_s cn68xxp1; + struct cvmx_lmcx_nxm_cn70xx { + uint64_t reserved_24_63:40; + uint64_t mem_msb_d1_r1:4; + uint64_t mem_msb_d1_r0:4; + uint64_t mem_msb_d0_r1:4; + uint64_t mem_msb_d0_r0:4; + uint64_t reserved_4_7:4; + uint64_t cs_mask:4; + } cn70xx; + struct cvmx_lmcx_nxm_cn70xx cn70xxp1; + struct cvmx_lmcx_nxm_cn70xx cn73xx; + struct cvmx_lmcx_nxm_cn70xx cn78xx; + struct cvmx_lmcx_nxm_cn70xx cn78xxp1; + struct cvmx_lmcx_nxm_s cnf71xx; + struct cvmx_lmcx_nxm_cn70xx cnf75xx; +}; + +/** + * cvmx_lmc#_nxm_fadr + * + * This register captures only the first transaction with a NXM error while + * an interrupt is pending, and only captures a subsequent event once the + * interrupt is cleared by writing a one to LMC()_INT[NXM_ERR]. It captures + * the actual L2C-LMC address provided to the LMC that caused the NXM error. + * A read or write NXM error is captured only if enabled using the NXM + * event enables. + */ +union cvmx_lmcx_nxm_fadr { + u64 u64; + struct cvmx_lmcx_nxm_fadr_s { + uint64_t reserved_40_63:24; + uint64_t nxm_faddr_ext:1; + uint64_t nxm_src:1; + uint64_t nxm_type:1; + uint64_t nxm_faddr:37; + } s; + struct cvmx_lmcx_nxm_fadr_cn70xx { + uint64_t reserved_39_63:25; + uint64_t nxm_src:1; + uint64_t nxm_type:1; + uint64_t nxm_faddr:37; + } cn70xx; + struct cvmx_lmcx_nxm_fadr_cn70xx cn70xxp1; + struct cvmx_lmcx_nxm_fadr_s cn73xx; + struct cvmx_lmcx_nxm_fadr_s cn78xx; + struct cvmx_lmcx_nxm_fadr_s cn78xxp1; + struct cvmx_lmcx_nxm_fadr_s cnf75xx; +}; + +/** + * cvmx_lmc#_ops_cnt + * + * LMC_OPS_CNT = Performance Counters + * + */ +union cvmx_lmcx_ops_cnt { + u64 u64; + struct cvmx_lmcx_ops_cnt_s { + uint64_t opscnt:64; + } s; + struct cvmx_lmcx_ops_cnt_s cn61xx; + struct cvmx_lmcx_ops_cnt_s cn63xx; + struct cvmx_lmcx_ops_cnt_s cn63xxp1; + struct cvmx_lmcx_ops_cnt_s cn66xx; + struct cvmx_lmcx_ops_cnt_s cn68xx; + struct cvmx_lmcx_ops_cnt_s cn68xxp1; + struct cvmx_lmcx_ops_cnt_s cn70xx; + struct cvmx_lmcx_ops_cnt_s cn70xxp1; + struct cvmx_lmcx_ops_cnt_s cn73xx; + struct cvmx_lmcx_ops_cnt_s cn78xx; + struct cvmx_lmcx_ops_cnt_s cn78xxp1; + struct cvmx_lmcx_ops_cnt_s cnf71xx; + struct cvmx_lmcx_ops_cnt_s cnf75xx; +}; + +/** + * cvmx_lmc#_ops_cnt_hi + * + * LMC_OPS_CNT_HI = Performance Counters + * + */ +union cvmx_lmcx_ops_cnt_hi { + u64 u64; + struct cvmx_lmcx_ops_cnt_hi_s { + uint64_t reserved_32_63:32; + uint64_t opscnt_hi:32; + } s; + struct cvmx_lmcx_ops_cnt_hi_s cn30xx; + struct cvmx_lmcx_ops_cnt_hi_s cn31xx; + struct cvmx_lmcx_ops_cnt_hi_s cn38xx; + struct cvmx_lmcx_ops_cnt_hi_s cn38xxp2; + struct cvmx_lmcx_ops_cnt_hi_s cn50xx; + struct cvmx_lmcx_ops_cnt_hi_s cn52xx; + struct cvmx_lmcx_ops_cnt_hi_s cn52xxp1; + struct cvmx_lmcx_ops_cnt_hi_s cn56xx; + struct cvmx_lmcx_ops_cnt_hi_s cn56xxp1; + struct cvmx_lmcx_ops_cnt_hi_s cn58xx; + struct cvmx_lmcx_ops_cnt_hi_s cn58xxp1; +}; + +/** + * cvmx_lmc#_ops_cnt_lo + * + * LMC_OPS_CNT_LO = Performance Counters + * + */ +union cvmx_lmcx_ops_cnt_lo { + u64 u64; + struct cvmx_lmcx_ops_cnt_lo_s { + uint64_t reserved_32_63:32; + uint64_t opscnt_lo:32; + } s; + struct cvmx_lmcx_ops_cnt_lo_s cn30xx; + struct cvmx_lmcx_ops_cnt_lo_s cn31xx; + struct cvmx_lmcx_ops_cnt_lo_s cn38xx; + struct cvmx_lmcx_ops_cnt_lo_s cn38xxp2; + struct cvmx_lmcx_ops_cnt_lo_s cn50xx; + struct cvmx_lmcx_ops_cnt_lo_s cn52xx; + struct cvmx_lmcx_ops_cnt_lo_s cn52xxp1; + struct cvmx_lmcx_ops_cnt_lo_s cn56xx; + struct cvmx_lmcx_ops_cnt_lo_s cn56xxp1; + struct cvmx_lmcx_ops_cnt_lo_s cn58xx; + struct cvmx_lmcx_ops_cnt_lo_s cn58xxp1; +}; + +/** + * cvmx_lmc#_phy_ctl + * + * LMC_PHY_CTL = LMC PHY Control + * + */ +union cvmx_lmcx_phy_ctl { + u64 u64; + struct cvmx_lmcx_phy_ctl_s { + uint64_t reserved_61_63:3; + uint64_t dsk_dbg_load_dis:1; + uint64_t dsk_dbg_overwrt_ena:1; + uint64_t dsk_dbg_wr_mode:1; + uint64_t data_rate_loopback:1; + uint64_t dq_shallow_loopback:1; + uint64_t dm_disable:1; + uint64_t c1_sel:2; + uint64_t c0_sel:2; + uint64_t phy_reset:1; + uint64_t dsk_dbg_rd_complete:1; + uint64_t dsk_dbg_rd_data:10; + uint64_t dsk_dbg_rd_start:1; + uint64_t dsk_dbg_clk_scaler:2; + uint64_t dsk_dbg_offset:2; + uint64_t dsk_dbg_num_bits_sel:1; + uint64_t dsk_dbg_byte_sel:4; + uint64_t dsk_dbg_bit_sel:4; + uint64_t dbi_mode_ena:1; + uint64_t ddr_error_n_ena:1; + uint64_t ref_pin_on:1; + uint64_t dac_on:1; + uint64_t int_pad_loopback_ena:1; + uint64_t int_phy_loopback_ena:1; + uint64_t phy_dsk_reset:1; + uint64_t phy_dsk_byp:1; + uint64_t phy_pwr_save_disable:1; + uint64_t ten:1; + uint64_t rx_always_on:1; + uint64_t lv_mode:1; + uint64_t ck_tune1:1; + uint64_t ck_dlyout1:4; + uint64_t ck_tune0:1; + uint64_t ck_dlyout0:4; + uint64_t loopback:1; + uint64_t loopback_pos:1; + uint64_t ts_stagger:1; + } s; + struct cvmx_lmcx_phy_ctl_cn61xx { + uint64_t reserved_15_63:49; + uint64_t rx_always_on:1; + uint64_t lv_mode:1; + uint64_t ck_tune1:1; + uint64_t ck_dlyout1:4; + uint64_t ck_tune0:1; + uint64_t ck_dlyout0:4; + uint64_t loopback:1; + uint64_t loopback_pos:1; + uint64_t ts_stagger:1; + } cn61xx; + struct cvmx_lmcx_phy_ctl_cn61xx cn63xx; + struct cvmx_lmcx_phy_ctl_cn63xxp1 { + uint64_t reserved_14_63:50; + uint64_t lv_mode:1; + uint64_t ck_tune1:1; + uint64_t ck_dlyout1:4; + uint64_t ck_tune0:1; + uint64_t ck_dlyout0:4; + uint64_t loopback:1; + uint64_t loopback_pos:1; + uint64_t ts_stagger:1; + } cn63xxp1; + struct cvmx_lmcx_phy_ctl_cn61xx cn66xx; + struct cvmx_lmcx_phy_ctl_cn61xx cn68xx; + struct cvmx_lmcx_phy_ctl_cn61xx cn68xxp1; + struct cvmx_lmcx_phy_ctl_cn70xx { + uint64_t reserved_51_63:13; + uint64_t phy_reset:1; + uint64_t dsk_dbg_rd_complete:1; + uint64_t dsk_dbg_rd_data:10; + uint64_t dsk_dbg_rd_start:1; + uint64_t dsk_dbg_clk_scaler:2; + uint64_t dsk_dbg_offset:2; + uint64_t dsk_dbg_num_bits_sel:1; + uint64_t dsk_dbg_byte_sel:4; + uint64_t dsk_dbg_bit_sel:4; + uint64_t dbi_mode_ena:1; + uint64_t ddr_error_n_ena:1; + uint64_t ref_pin_on:1; + uint64_t dac_on:1; + uint64_t int_pad_loopback_ena:1; + uint64_t int_phy_loopback_ena:1; + uint64_t phy_dsk_reset:1; + uint64_t phy_dsk_byp:1; + uint64_t phy_pwr_save_disable:1; + uint64_t ten:1; + uint64_t rx_always_on:1; + uint64_t lv_mode:1; + uint64_t ck_tune1:1; + uint64_t ck_dlyout1:4; + uint64_t ck_tune0:1; + uint64_t ck_dlyout0:4; + uint64_t loopback:1; + uint64_t loopback_pos:1; + uint64_t ts_stagger:1; + } cn70xx; + struct cvmx_lmcx_phy_ctl_cn70xx cn70xxp1; + struct cvmx_lmcx_phy_ctl_cn73xx { + uint64_t reserved_58_63:6; + uint64_t data_rate_loopback:1; + uint64_t dq_shallow_loopback:1; + uint64_t dm_disable:1; + uint64_t c1_sel:2; + uint64_t c0_sel:2; + uint64_t phy_reset:1; + uint64_t dsk_dbg_rd_complete:1; + uint64_t dsk_dbg_rd_data:10; + uint64_t dsk_dbg_rd_start:1; + uint64_t dsk_dbg_clk_scaler:2; + uint64_t dsk_dbg_offset:2; + uint64_t dsk_dbg_num_bits_sel:1; + uint64_t dsk_dbg_byte_sel:4; + uint64_t dsk_dbg_bit_sel:4; + uint64_t dbi_mode_ena:1; + uint64_t ddr_error_n_ena:1; + uint64_t ref_pin_on:1; + uint64_t dac_on:1; + uint64_t int_pad_loopback_ena:1; + uint64_t int_phy_loopback_ena:1; + uint64_t phy_dsk_reset:1;
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.28.0
Part of the diff is not shown here. View the raw message.
PATCH v3 4/9 mips: octeon: Add octeon_ddr.h header
In reply to Stefan RoeseFrom: Aaron Williams <[email protected]>
This header will be used by the DDR driver (lmc). Its ported from the 2013 Cavium / Marvell U-Boot repository.
---
Changes in v3:
- Remove "https://spdx.org/licenses" line
- Remove inclusion of "common.h"
- Remove duplicate comment line
- Remove "test-only" comment (leftover after cleanup)
Changes in v2:
- Use readq/writeq in cvmx_read64_uint64/cvmx_write64_uint64 instead of readl/writel
.../mach-octeon/include/mach/octeon_ddr.h | 982 ++++++++++++++++++ 1 file changed, 982 insertions(+) create mode 100644 arch/mips/mach-octeon/include/mach/octeon_ddr.h
arch/mips/mach-octeon/include/mach/octeon_ddr.h new file +982 -0
@@ -0,0 +1,982 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020 Marvell International Ltd. +*/ + +#ifndef __OCTEON_DDR_H_ +#define __OCTEON_DDR_H_ + +#include <env.h> +#include <linux/compat.h> +#include <linux/delay.h> +#include <linux/io.h> +#include <mach/octeon-model.h> +#include <mach/cvmx/cvmx-lmcx-defs.h> + +/* Mapping is done starting from 0x11800.80000000 */ +#define CVMX_L2C_CTL 0x00800000 +#define CVMX_L2C_BIG_CTL 0x00800030 +#define CVMX_L2C_TADX_INT (i) (0x00a00028 + (((i) & 7) * 0x40000)) +#define CVMX_L2C_MCIX_INT (i) (0x00c00028 + (((i) & 3) * 0x40000)) + +/* Some "external" (non-LMC) registers */ +#define CVMX_IPD_CLK_COUNT 0x00014F0000000338 +#define CVMX_FPA_CLK_COUNT 0x00012800000000F0 + +#define CVMX_NODE_MEM_SHIFT 40 + +#define DDR_INTERFACE_MAX 4 + +/* Private data struct */ +struct ddr_priv { +void __iomem *lmc_base; +void __iomem *l2c_base; + +bool ddr_clock_initialized[DDR_INTERFACE_MAX ]; +bool ddr_memory_preserved; +u32 flags; + +struct ram_info info; +}; + +/* Short cut to convert a number to megabytes */ +#define MB (X ) ((u64)(X) * (u64)(1024 * 1024)) + +#define octeon_is_cpuid (x) (__OCTEON_IS_MODEL_COMPILE__(x, read_c0_prid())) + +#define strtoull simple_strtoull + +/* Access LMC registers */ +static inline u64 lmc_rd (struct ddr_priv *priv,u64 addr) +{ +return ioread64 (priv->lmc_base + addr); +} + +static inline void lmc_wr (struct ddr_priv *priv,u64 addr,u64 val) +{ +iowrite64 (val, priv->lmc_base + addr); +} + +/* Access L2C registers */ +static inline u64 l2c_rd (struct ddr_priv *priv,u64 addr) +{ +return ioread64 (priv->l2c_base + addr); +} + +static inline void l2c_wr (struct ddr_priv *priv,u64 addr,u64 val) +{ +iowrite64 (val, priv->l2c_base + addr); +} + +/* Access other CSR registers not located inside the LMC address space */ +static inline u64 csr_rd (u64 addr) +{ +void __iomem *base; + + base =ioremap_nocache (addr,0x100 ); +return ioread64 (base); +} + +static inline void csr_wr (u64 addr,u64 val) +{ +void __iomem *base; + + base =ioremap_nocache (addr,0x100 ); +return iowrite64 (val, base); +} + +/* "Normal" access, without any offsets and/or mapping */ +static inline u64 cvmx_read64_uint64 (u64 addr) +{ +return readq ((void *)addr); +} + +static inline void cvmx_write64_uint64 (u64 addr,u64 val) +{ +writeq (val, (void *)addr); +} + +/* Failsafe mode */ +#define FLAG_FAILSAFE_MODE 0x01000 +/* Note that the DDR clock initialized flags must be contiguous */ +/* Clock for DDR 0 initialized */ +#define FLAG_DDR0_CLK_INITIALIZED 0x02000 +/* Clock for DDR 1 initialized */ +#define FLAG_DDR1_CLK_INITIALIZED 0x04000 +/* Clock for DDR 2 initialized */ +#define FLAG_DDR2_CLK_INITIALIZED 0x08000 +/* Clock for DDR 3 initialized */ +#define FLAG_DDR3_CLK_INITIALIZED 0x10000 +/* Loaded into RAM externally */ +#define FLAG_RAM_RESIDENT 0x20000 +/* Verbose DDR information */ +#define FLAG_DDR_VERBOSE 0x40000 +/* Check env. for DDR variables */ +#define FLAG_DDR_DEBUG 0x80000 +#define FLAG_DDR_TRACE_INIT 0x100000 +#define FLAG_MEMORY_PRESERVED 0x200000 +#define FLAG_DFM_VERBOSE 0x400000 +#define FLAG_DFM_TRACE_INIT 0x800000 +/* DFM memory clock initialized */ +#define FLAG_DFM_CLK_INITIALIZED 0x1000000 +/* EEPROM clock descr. missing */ +#define FLAG_CLOCK_DESC_MISSING 0x2000000 +/* EEPROM board descr. missing */ +#define FLAG_BOARD_DESC_MISSING 0x4000000 +#define FLAG_DDR_PROMPT 0x8000000 + +#ifndef DDR_NO_DEBUG +static inline int ddr_verbose (struct ddr_priv *priv) +{ +return !!(priv->flags &FLAG_DDR_VERBOSE ); +} + +static inline char *ddr_getenv_debug (struct ddr_priv *priv,char *name) +{ +if (priv->flags &FLAG_FAILSAFE_MODE ) +return NULL ; + +if (priv->flags &FLAG_DDR_DEBUG ) +return env_get (name); + +return NULL ; +} +#else +static inline int ddr_verbose (void ) +{ +return 0 ; +} +#endif + +/* turn the variable name into a string */ +#define CVMX_TMP_STR (x) CVMX_TMP_STR2(x) +#define CVMX_TMP_STR2 (x) #x + +#define CVMX_SYNC asm volatile ("sync" : : : "memory") + +#define CVMX_CACHE (op, address, offset) \ + asm volatile ("cache " CVMX_TMP_STR(op) ", " \ + CVMX_TMP_STR(offset) "(%[rbase])" \ + : : [rbase] "d" (address)) + +/* unlock the state */ +#define CVMX_CACHE_WBIL2 (address, offset) \ + CVMX_CACHE(23, address, offset) + +/* complete prefetches, invalidate entire dcache */ +#define CVMX_DCACHE_INVALIDATE \ + { CVMX_SYNC; asm volatile ("cache 9, 0($0)" : : ); } + +/** +* cvmx_l2c_cfg +* +* Specify the RSL base addresses for the block +* +* L2C_CFG = L2C Configuration +* +* Description: +*/ +union cvmx_l2c_cfg { +u64 u64; +struct cvmx_l2c_cfg_s { +uint64_t reserved_20_63:44 ; +uint64_t bstrun:1 ; +uint64_t lbist:1 ; +uint64_t xor_bank:1 ; +uint64_t dpres1:1 ; +uint64_t dpres0:1 ; +uint64_t dfill_dis:1 ; +uint64_t fpexp:4 ; +uint64_t fpempty:1 ; +uint64_t fpen:1 ; +uint64_t idxalias:1 ; +uint64_t mwf_crd:4 ; +uint64_t rsp_arb_mode:1 ; +uint64_t rfb_arb_mode:1 ; +uint64_t lrf_arb_mode:1 ; + } s; +}; + +/** +* cvmx_l2c_ctl +* +* L2C_CTL = L2C Control +* +* +* Notes: +* (1) If MAXVAB is != 0, VAB_THRESH should be less than MAXVAB. +* +* (2) L2DFDBE and L2DFSBE allows software to generate L2DSBE, L2DDBE, VBFSBE, +* and VBFDBE errors for the purposes of testing error handling code. When +* one (or both) of these bits are set a PL2 which misses in the L2 will fill +* with the appropriate error in the first 2 OWs of the fill. Software can +* determine which OW pair gets the error by choosing the desired fill order +* (address<6:5>). A PL2 which hits in the L2 will not inject any errors. +* Therefore sending a WBIL2 prior to the PL2 is recommended to make a miss +* likely (if multiple processors are involved software must be careful to be +* sure no other processor or IO device can bring the block into the L2). +* +* To generate a VBFSBE or VBFDBE, software must first get the cache block +* into the cache with an error using a PL2 which misses the L2. Then a +* store partial to a portion of the cache block without the error must +* change the block to dirty. Then, a subsequent WBL2/WBIL2/victim will +* trigger the VBFSBE/VBFDBE error. +*/ +union cvmx_l2c_ctl { +u64 u64; +struct cvmx_l2c_ctl_s { +uint64_t reserved_29_63:35 ; +uint64_t rdf_fast:1 ; +uint64_t disstgl2i:1 ; +uint64_t l2dfsbe:1 ; +uint64_t l2dfdbe:1 ; +uint64_t discclk:1 ; +uint64_t maxvab:4 ; +uint64_t maxlfb:4 ; +uint64_t rsp_arb_mode:1 ; +uint64_t xmc_arb_mode:1 ; +uint64_t reserved_2_13:12 ; +uint64_t disecc:1 ; +uint64_t disidxalias:1 ; + } s; + +struct cvmx_l2c_ctl_cn73xx { +uint64_t reserved_32_63:32 ; +uint64_t ocla_qos:3 ; +uint64_t reserved_28_28:1 ; +uint64_t disstgl2i:1 ; +uint64_t reserved_25_26:2 ; +uint64_t discclk:1 ; +uint64_t reserved_16_23:8 ; +uint64_t rsp_arb_mode:1 ; +uint64_t xmc_arb_mode:1 ; +uint64_t rdf_cnt:8 ; +uint64_t reserved_4_5:2 ; +uint64_t disldwb:1 ; +uint64_t dissblkdty:1 ; +uint64_t disecc:1 ; +uint64_t disidxalias:1 ; + } cn73xx; + +struct cvmx_l2c_ctl_cn73xx cn78xx; +}; + +/** +* cvmx_l2c_big_ctl +* +* L2C_BIG_CTL = L2C Big memory control register +* +* +* Notes: +* (1) BIGRD interrupts can occur during normal operation as the PP's are +* allowed to prefetch to non-existent memory locations. Therefore, +* BIGRD is for informational purposes only. +* +* (2) When HOLEWR/BIGWR blocks a store L2C_VER_ID, L2C_VER_PP, L2C_VER_IOB, +* and L2C_VER_MSC will be loaded just like a store which is blocked by VRTWR. +* Additionally, L2C_ERR_XMC will be loaded. +*/ +union cvmx_l2c_big_ctl { +u64 u64; +struct cvmx_l2c_big_ctl_s { +uint64_t reserved_8_63:56 ; +uint64_t maxdram:4 ; +uint64_t reserved_0_3:4 ; + } s; +struct cvmx_l2c_big_ctl_cn61xx { +uint64_t reserved_8_63:56 ; +uint64_t maxdram:4 ; +uint64_t reserved_1_3:3 ; +uint64_t disable:1 ; + } cn61xx; +struct cvmx_l2c_big_ctl_cn61xx cn63xx; +struct cvmx_l2c_big_ctl_cn61xx cn66xx; +struct cvmx_l2c_big_ctl_cn61xx cn68xx; +struct cvmx_l2c_big_ctl_cn61xx cn68xxp1; +struct cvmx_l2c_big_ctl_cn70xx { +uint64_t reserved_8_63:56 ; +uint64_t maxdram:4 ; +uint64_t reserved_1_3:3 ; +uint64_t disbig:1 ; + } cn70xx; +struct cvmx_l2c_big_ctl_cn70xx cn70xxp1; +struct cvmx_l2c_big_ctl_cn70xx cn73xx; +struct cvmx_l2c_big_ctl_cn70xx cn78xx; +struct cvmx_l2c_big_ctl_cn70xx cn78xxp1; +struct cvmx_l2c_big_ctl_cn61xx cnf71xx; +struct cvmx_l2c_big_ctl_cn70xx cnf75xx; +}; + +struct rlevel_byte_data { +int delay; +int loop_total; +int loop_count; +int best; +u64 bm; +int bmerrs; +int sqerrs; +int bestsq; +}; + +#define DEBUG_VALIDATE_BITMASK 0 +#if DEBUG_VALIDATE_BITMASK +#define debug_bitmask_print printf +#else +#define debug_bitmask_print (...) +#endif + +#define RLEVEL_BITMASK_TRAILING_BITS_ERROR 5 +// FIXME? now less than TOOLONG +#define RLEVEL_BITMASK_BUBBLE_BITS_ERROR 11 +#define RLEVEL_BITMASK_NARROW_ERROR 6 +#define RLEVEL_BITMASK_BLANK_ERROR 100 +#define RLEVEL_BITMASK_TOOLONG_ERROR 12 +#define RLEVEL_NONSEQUENTIAL_DELAY_ERROR 50 +#define RLEVEL_ADJACENT_DELAY_ERROR 30 + +/* +* Apply a filter to the BITMASK results returned from Octeon +* read-leveling to determine the most likely delay result. This +* computed delay may be used to qualify the delay result returned by +* Octeon. Accumulate an error penalty for invalid characteristics of +* the bitmask so that they can be used to select the most reliable +* results. +* +* The algorithm searches for the largest contiguous MASK within a +* maximum RANGE of bits beginning with the MSB. +* +* 1. a MASK with a WIDTH less than 4 will be penalized +* 2. Bubbles in the bitmask that occur before or after the MASK +* will be penalized +* 3. If there are no trailing bubbles then extra bits that occur +* beyond the maximum RANGE will be penalized. +* +* +++++++++++++++++++++++++++++++++++++++++++++++++++ +* + + +* + e.g. bitmask = 27B00 + +* + + +* + 63 +--- mstart 0 + +* + | | | + +* + | +---------+ +--- fb | + +* + | | range | | | + +* + V V V V V + +* + + +* + 0 0 ... 1 0 0 1 1 1 1 0 1 1 0 0 0 0 0 0 0 0 + +* + + +* + ^ ^ ^ + +* + | | mask| + +* + lb ---+ +-----+ + +* + width + +* + + +* +++++++++++++++++++++++++++++++++++++++++++++++++++ +*/ + +struct rlevel_bitmask { +u64 bm; +u8 mstart; +u8 width; +int errs; +}; + +#define MASKRANGE_BITS 6 +#define MASKRANGE ((1 << MASKRANGE_BITS) - 1) + +/* data field addresses in the DDR2 SPD eeprom */ +enum ddr2_spd_addrs { +DDR2_SPD_BYTES_PROGRAMMED =0 , +DDR2_SPD_TOTAL_BYTES =1 , +DDR2_SPD_MEM_TYPE =2 , +DDR2_SPD_NUM_ROW_BITS =3 , +DDR2_SPD_NUM_COL_BITS =4 , +DDR2_SPD_NUM_RANKS =5 , +DDR2_SPD_CYCLE_CLX =9 , +DDR2_SPD_CONFIG_TYPE =11 , +DDR2_SPD_REFRESH =12 , +DDR2_SPD_SDRAM_WIDTH =13 , +DDR2_SPD_BURST_LENGTH =16 , +DDR2_SPD_NUM_BANKS =17 , +DDR2_SPD_CAS_LATENCY =18 , +DDR2_SPD_DIMM_TYPE =20 , +DDR2_SPD_CYCLE_CLX1 =23 , +DDR2_SPD_CYCLE_CLX2 =25 , +DDR2_SPD_TRP =27 , +DDR2_SPD_TRRD =28 , +DDR2_SPD_TRCD =29 , +DDR2_SPD_TRAS =30 , +DDR2_SPD_TWR =36 , +DDR2_SPD_TWTR =37 , +DDR2_SPD_TRFC_EXT =40 , +DDR2_SPD_TRFC =42 , +DDR2_SPD_CHECKSUM =63 , +DDR2_SPD_MFR_ID =64 +}; + +/* data field addresses in the DDR2 SPD eeprom */ +enum ddr3_spd_addrs { +DDR3_SPD_BYTES_PROGRAMMED =0 , +DDR3_SPD_REVISION =1 , +DDR3_SPD_KEY_BYTE_DEVICE_TYPE =2 , +DDR3_SPD_KEY_BYTE_MODULE_TYPE =3 , +DDR3_SPD_DENSITY_BANKS =4 , +DDR3_SPD_ADDRESSING_ROW_COL_BITS =5 , +DDR3_SPD_NOMINAL_VOLTAGE =6 , +DDR3_SPD_MODULE_ORGANIZATION =7 , +DDR3_SPD_MEMORY_BUS_WIDTH =8 , +DDR3_SPD_FINE_TIMEBASE_DIVIDEND_DIVISOR =9 , +DDR3_SPD_MEDIUM_TIMEBASE_DIVIDEND =10 , +DDR3_SPD_MEDIUM_TIMEBASE_DIVISOR =11 , +DDR3_SPD_MINIMUM_CYCLE_TIME_TCKMIN =12 , +DDR3_SPD_CAS_LATENCIES_LSB =14 , +DDR3_SPD_CAS_LATENCIES_MSB =15 , +DDR3_SPD_MIN_CAS_LATENCY_TAAMIN =16 , +DDR3_SPD_MIN_WRITE_RECOVERY_TWRMIN =17 , +DDR3_SPD_MIN_RAS_CAS_DELAY_TRCDMIN =18 , +DDR3_SPD_MIN_ROW_ACTIVE_DELAY_TRRDMIN =19 , +DDR3_SPD_MIN_ROW_PRECHARGE_DELAY_TRPMIN =20 , +DDR3_SPD_UPPER_NIBBLES_TRAS_TRC =21 , +DDR3_SPD_MIN_ACTIVE_PRECHARGE_LSB_TRASMIN =22 , +DDR3_SPD_MIN_ACTIVE_REFRESH_LSB_TRCMIN =23 , +DDR3_SPD_MIN_REFRESH_RECOVERY_LSB_TRFCMIN =24 , +DDR3_SPD_MIN_REFRESH_RECOVERY_MSB_TRFCMIN =25 , +DDR3_SPD_MIN_INTERNAL_WRITE_READ_CMD_TWTRMIN =26 , +DDR3_SPD_MIN_INTERNAL_READ_PRECHARGE_CMD_TRTPMIN =27 , +DDR3_SPD_UPPER_NIBBLE_TFAW =28 , +DDR3_SPD_MIN_FOUR_ACTIVE_WINDOW_TFAWMIN =29 , +DDR3_SPD_SDRAM_OPTIONAL_FEATURES =30 , +DDR3_SPD_SDRAM_THERMAL_REFRESH_OPTIONS =31 , +DDR3_SPD_MODULE_THERMAL_SENSOR =32 , +DDR3_SPD_SDRAM_DEVICE_TYPE =33 , +DDR3_SPD_MINIMUM_CYCLE_TIME_FINE_TCKMIN =34 , +DDR3_SPD_MIN_CAS_LATENCY_FINE_TAAMIN =35 , +DDR3_SPD_MIN_RAS_CAS_DELAY_FINE_TRCDMIN =36 , +DDR3_SPD_MIN_ROW_PRECHARGE_DELAY_FINE_TRPMIN =37 , +DDR3_SPD_MIN_ACTIVE_REFRESH_LSB_FINE_TRCMIN =38 , +DDR3_SPD_REFERENCE_RAW_CARD =62 , +DDR3_SPD_ADDRESS_MAPPING =63 , +DDR3_SPD_REGISTER_MANUFACTURER_ID_LSB =65 , +DDR3_SPD_REGISTER_MANUFACTURER_ID_MSB =66 , +DDR3_SPD_REGISTER_REVISION_NUMBER =67 , +DDR3_SPD_MODULE_SERIAL_NUMBER =122 , +DDR3_SPD_CYCLICAL_REDUNDANCY_CODE_LOWER_NIBBLE =126 , +DDR3_SPD_CYCLICAL_REDUNDANCY_CODE_UPPER_NIBBLE =127 , +DDR3_SPD_MODULE_PART_NUMBER =128 +}; + +/* data field addresses in the DDR4 SPD eeprom */ +enum ddr4_spd_addrs { +DDR4_SPD_BYTES_PROGRAMMED =0 , +DDR4_SPD_REVISION =1 , +DDR4_SPD_KEY_BYTE_DEVICE_TYPE =2 , +DDR4_SPD_KEY_BYTE_MODULE_TYPE =3 , +DDR4_SPD_DENSITY_BANKS =4 , +DDR4_SPD_ADDRESSING_ROW_COL_BITS =5 , +DDR4_SPD_PACKAGE_TYPE =6 , +DDR4_SPD_OPTIONAL_FEATURES =7 , +DDR4_SPD_THERMAL_REFRESH_OPTIONS =8 , +DDR4_SPD_OTHER_OPTIONAL_FEATURES =9 , +DDR4_SPD_SECONDARY_PACKAGE_TYPE =10 , +DDR4_SPD_MODULE_NOMINAL_VOLTAGE =11 , +DDR4_SPD_MODULE_ORGANIZATION =12 , +DDR4_SPD_MODULE_MEMORY_BUS_WIDTH =13 , +DDR4_SPD_MODULE_THERMAL_SENSOR =14 , +DDR4_SPD_RESERVED_BYTE15 =15 , +DDR4_SPD_RESERVED_BYTE16 =16 , +DDR4_SPD_TIMEBASES =17 , +DDR4_SPD_MINIMUM_CYCLE_TIME_TCKAVGMIN =18 , +DDR4_SPD_MAXIMUM_CYCLE_TIME_TCKAVGMAX =19 , +DDR4_SPD_CAS_LATENCIES_BYTE0 =20 , +DDR4_SPD_CAS_LATENCIES_BYTE1 =21 , +DDR4_SPD_CAS_LATENCIES_BYTE2 =22 , +DDR4_SPD_CAS_LATENCIES_BYTE3 =23 , +DDR4_SPD_MIN_CAS_LATENCY_TAAMIN =24 , +DDR4_SPD_MIN_RAS_CAS_DELAY_TRCDMIN =25 , +DDR4_SPD_MIN_ROW_PRECHARGE_DELAY_TRPMIN =26 , +DDR4_SPD_UPPER_NIBBLES_TRAS_TRC =27 , +DDR4_SPD_MIN_ACTIVE_PRECHARGE_LSB_TRASMIN =28 , +DDR4_SPD_MIN_ACTIVE_REFRESH_LSB_TRCMIN =29 , +DDR4_SPD_MIN_REFRESH_RECOVERY_LSB_TRFC1MIN =30 , +DDR4_SPD_MIN_REFRESH_RECOVERY_MSB_TRFC1MIN =31 , +DDR4_SPD_MIN_REFRESH_RECOVERY_LSB_TRFC2MIN =32 , +DDR4_SPD_MIN_REFRESH_RECOVERY_MSB_TRFC2MIN =33 , +DDR4_SPD_MIN_REFRESH_RECOVERY_LSB_TRFC4MIN =34 , +DDR4_SPD_MIN_REFRESH_RECOVERY_MSB_TRFC4MIN =35 , +DDR4_SPD_MIN_FOUR_ACTIVE_WINDOW_MSN_TFAWMIN =36 , +DDR4_SPD_MIN_FOUR_ACTIVE_WINDOW_LSB_TFAWMIN =37 , +DDR4_SPD_MIN_ROW_ACTIVE_DELAY_SAME_TRRD_SMIN =38 , +DDR4_SPD_MIN_ROW_ACTIVE_DELAY_DIFF_TRRD_LMIN =39 , +DDR4_SPD_MIN_CAS_TO_CAS_DELAY_TCCD_LMIN =40 , +DDR4_SPD_MIN_CAS_TO_CAS_DELAY_FINE_TCCD_LMIN =117 , +DDR4_SPD_MIN_ACT_TO_ACT_DELAY_SAME_FINE_TRRD_LMIN =118 , +DDR4_SPD_MIN_ACT_TO_ACT_DELAY_DIFF_FINE_TRRD_SMIN =119 , +DDR4_SPD_MIN_ACT_TO_ACT_REFRESH_DELAY_FINE_TRCMIN =120 , +DDR4_SPD_MIN_ROW_PRECHARGE_DELAY_FINE_TRPMIN =121 , +DDR4_SPD_MIN_RAS_TO_CAS_DELAY_FINE_TRCDMIN =122 , +DDR4_SPD_MIN_CAS_LATENCY_FINE_TAAMIN =123 , +DDR4_SPD_MAX_CYCLE_TIME_FINE_TCKAVGMAX =124 , +DDR4_SPD_MIN_CYCLE_TIME_FINE_TCKAVGMIN =125 , +DDR4_SPD_CYCLICAL_REDUNDANCY_CODE_LOWER_NIBBLE =126 , +DDR4_SPD_CYCLICAL_REDUNDANCY_CODE_UPPER_NIBBLE =127 , +DDR4_SPD_REFERENCE_RAW_CARD =130 , +DDR4_SPD_UDIMM_ADDR_MAPPING_FROM_EDGE =131 , +DDR4_SPD_REGISTER_MANUFACTURER_ID_LSB =133 , +DDR4_SPD_REGISTER_MANUFACTURER_ID_MSB =134 , +DDR4_SPD_REGISTER_REVISION_NUMBER =135 , +DDR4_SPD_RDIMM_ADDR_MAPPING_FROM_REGISTER_TO_DRAM =136 , +DDR4_SPD_RDIMM_REGISTER_DRIVE_STRENGTH_CTL =137 , +DDR4_SPD_RDIMM_REGISTER_DRIVE_STRENGTH_CK =138 , +}; + +#define SPD_EEPROM_SIZE (DDR4_SPD_RDIMM_REGISTER_DRIVE_STRENGTH_CK + 1) + +struct impedence_values { +unsigned char *rodt_ohms; +unsigned char *rtt_nom_ohms; +unsigned char *rtt_nom_table; +unsigned char *rtt_wr_ohms; +unsigned char *dic_ohms; +short *drive_strength; +short *dqx_strength; +}; + +#define RODT_OHMS_COUNT 8 +#define RTT_NOM_OHMS_COUNT 8 +#define RTT_NOM_TABLE_COUNT 8 +#define RTT_WR_OHMS_COUNT 8 +#define DIC_OHMS_COUNT 3 +#define DRIVE_STRENGTH_COUNT 15 + +/* +* Structure that provides DIMM information, either in the form of an SPD +* TWSI address, or a pointer to an array that contains SPD data. One of +* the two fields must be valid. +*/ +struct dimm_config { +u16 spd_addrs[2 ];/* TWSI address of SPD, 0 if not used */ +u8 *spd_ptrs[2 ];/* pointer to SPD data array, NULL if not used */ +int spd_cached[2 ]; +u8 spd_data[2 ][SPD_EEPROM_SIZE ]; +}; + +struct dimm_odt_config { +u8 odt_ena;/* FIX: dqx_ctl for Octeon 3 DDR4 */ +u64 odt_mask;/* FIX: wodt_mask for Octeon 3 */ +union cvmx_lmcx_modereg_params1 modereg_params1; +union cvmx_lmcx_modereg_params2 modereg_params2; +u8 qs_dic;/* FIX: rodt_ctl for Octeon 3 */ +u64 rodt_ctl;/* FIX: rodt_mask for Octeon 3 */ +u8 dic; +}; + +struct ddr_delay_config { +u32 ddr_board_delay; +u8 lmc_delay_clk; +u8 lmc_delay_cmd; +u8 lmc_delay_dq; +}; + +/* +* The parameters below make up the custom_lmc_config data structure. +* This structure is used to customize the way that the LMC DRAM +* Controller is configured for a particular board design. +* +* The HRM describes LMC Read Leveling which supports automatic +* selection of per byte-lane delays. When measuring the read delays +* the LMC configuration software sweeps through a range of settings +* for LMC0_COMP_CTL2[RODT_CTL], the Octeon II on-die-termination +* resistance and LMC0_MODEREG_PARAMS1[RTT_NOM_XX], the DRAM +* on-die-termination resistance. The minimum and maximum parameters +* for rtt_nom_idx and rodt_ctl listed below determine the ranges of +* ODT settings used for the measurements. Note that for rtt_nom an +* index is used into a sorted table rather than the direct csr setting +* in order to optimize the sweep. +* +* .min_rtt_nom_idx: 1=120ohms, 2=60ohms, 3=40ohms, 4=30ohms, 5=20ohms +* .max_rtt_nom_idx: 1=120ohms, 2=60ohms, 3=40ohms, 4=30ohms, 5=20ohms +* .min_rodt_ctl: 1=20ohms, 2=30ohms, 3=40ohms, 4=60ohms, 5=120ohms +* .max_rodt_ctl: 1=20ohms, 2=30ohms, 3=40ohms, 4=60ohms, 5=120ohms +* +* The settings below control the Octeon II drive strength for the CK, +* ADD/CMD, and DQ/DQS signals. 1=24ohms, 2=26.67ohms, 3=30ohms, +* 4=34.3ohms, 5=40ohms, 6=48ohms, 6=60ohms. +* +* .dqx_ctl: Drive strength control for DDR_DQX/DDR_DQS_X_P/N drivers. +* .ck_ctl: Drive strength control for +* DDR_CK_X_P/DDR_DIMMX_CSX_L/DDR_DIMMX_ODT_X drivers. +* .cmd_ctl: Drive strength control for CMD/A/RESET_L/CKEX drivers. +* +* The LMC controller software selects the most optimal CAS Latency +* that complies with the appropriate SPD values and the frequency +* that the DRAMS are being operated. When operating the DRAMs at +* frequencies substantially lower than their rated frequencies it +* might be necessary to limit the minimum CAS Latency the LMC +* controller software is allowed to select in order to make the DRAM +* work reliably. +* +* .min_cas_latency: Minimum allowed CAS Latency +* +* The value used for LMC0_RLEVEL_CTL[OFFSET_EN] determine how the +* read-leveling information that the Octeon II gathers is interpreted +* to determine the per-byte read delays. +* +* .offset_en: Value used for LMC0_RLEVEL_CTL[OFFSET_EN]. +* .offset_udimm: Value used for LMC0_RLEVEL_CTL[OFFSET] for UDIMMS. +* .offset_rdimm: Value used for LMC0_RLEVEL_CTL[OFFSET] for RDIMMS. +* +* The LMC configuration software sweeps through a range of ODT +* settings while measuring the per-byte read delays. During those +* measurements the software makes an assessment of the quality of the +* measurements in order to determine which measurements provide the +* most accurate delays. The automatic settings provide the option to +* allow that same assessment to determine the most optimal RODT_CTL +* and/or RTT_NOM settings. +* +* The automatic approach might provide the best means to determine +* the settings used for initial poweron of a new design. However, +* the final settings should be determined by board analysis, testing, +* and experience. +* +* .ddr_rtt_nom_auto: 1 means automatically set RTT_NOM value. +* .ddr_rodt_ctl_auto: 1 means automatically set RODT_CTL value. +* +* .rlevel_compute: Enables software interpretation of per-byte read +* delays using the measurements collected by the +* Octeon II rather than completely relying on the +* Octeon II to determine the delays. 1=software +* computation is recomended since a more complete +* analysis is implemented in software. +* +* .rlevel_comp_offset: Set to 2 unless instructed differently by Cavium. +* +* .rlevel_average_loops: Determines the number of times the read-leveling +* sequence is run for each rank. The results is +* then averaged across the number of loops. The +* default setting is 1. +* +* .ddr2t_udimm: +* .ddr2t_rdimm: Turn on the DDR 2T mode. 2-cycle window for CMD and +* address. This mode helps relieve setup time pressure +* on the address and command bus. Please refer to +* Micron's tech note tn_47_01 titled DDR2-533 Memory +* Design Guide for Two Dimm Unbuffered Systems for +* physical details. +* +* .disable_sequential_delay_check: As result of the flyby topology +* prescribed in the JEDEC specifications the byte delays should +* maintain a consistent increasing or decreasing trend across +* the bytes on standard dimms. This setting can be used disable +* that check for unusual circumstances where the check is not +* useful. +* +* .maximum_adjacent_rlevel_delay_increment: An additional sequential +* delay check for the delays that result from the flyby +* topology. This value specifies the maximum difference between +* the delays of adjacent bytes. A value of 0 disables this +* check. +* +* .fprch2 Front Porch Enable: When set, the turn-off +* time for the default DDR_DQ/DQS drivers is FPRCH2 CKs earlier. +* 00 = 0 CKs +* 01 = 1 CKs +* 10 = 2 CKs +* +* .parity: The parity input signal PAR_IN on each dimm must be +* strapped high or low on the board. This bit is programmed +* into LMC0_DIMM_CTL[PARITY] and it must be set to match the +* board strapping. This signal is typically strapped low. +* +* .mode32b: Enable 32-bit datapath mode. Set to 1 if only 32 DQ pins +* are used. (cn61xx, cn71xx) +* +* .measured_vref: Set to 1 to measure VREF; set to 0 to compute VREF. +* +* .dram_connection: Set to 1 if discrete DRAMs; set to 0 if using DIMMs. +* This changes the algorithms used to compute VREF. +* +* .dll_write_offset: FIXME: Add description +* .dll_read_offset: FIXME: Add description +*/ + +struct rlevel_table { +const char part[20 ]; +int speed; +u64 rl_rank[4 ][4 ]; +}; + +struct ddr3_custom_config { +u8 min_rtt_nom_idx; +u8 max_rtt_nom_idx; +u8 min_rodt_ctl; +u8 max_rodt_ctl; +u8 dqx_ctl; +u8 ck_ctl; +u8 cmd_ctl; +u8 ctl_ctl; +u8 min_cas_latency; +u8 offset_en; +u8 offset_udimm; +u8 offset_rdimm; +u8 rlevel_compute; +u8 ddr_rtt_nom_auto; +u8 ddr_rodt_ctl_auto; +u8 rlevel_comp_offset_udimm; +u8 rlevel_comp_offset_rdimm; +int8_t ptune_offset; +int8_t ntune_offset; +u8 rlevel_average_loops; +u8 ddr2t_udimm; +u8 ddr2t_rdimm; +u8 disable_sequential_delay_check; +u8 maximum_adjacent_rlevel_delay_increment; +u8 parity; +u8 fprch2; +u8 mode32b; +u8 measured_vref; +u8 dram_connection; +const int8_t *dll_write_offset; +const int8_t *dll_read_offset; +struct rlevel_table *rl_tbl; +}; + +#define DDR_CFG_T_MAX_DIMMS 5 + +struct ddr_conf { +struct dimm_config dimm_config_table[DDR_CFG_T_MAX_DIMMS ]; +struct dimm_odt_config odt_1rank_config[4 ]; +struct dimm_odt_config odt_2rank_config[4 ]; +struct dimm_odt_config odt_4rank_config[4 ]; +struct ddr_delay_config unbuffered; +struct ddr_delay_config registered; +struct ddr3_custom_config custom_lmc_config; +}; + +/* Divide and round results to the nearest integer. */ +static inline u64 divide_nint (u64 dividend,u64 divisor) +{ +u64 quotent, remainder; + + quotent = dividend / divisor; + remainder = dividend % divisor; +return (quotent + ((remainder *2 ) >= divisor)); +} + +/* Divide and round results up to the next higher integer. */ +static inline u64 divide_roundup (u64 dividend,u64 divisor) +{ +return ((dividend + divisor -1 ) / divisor); +} + +enum ddr_type { +DDR3_DRAM =3 , +DDR4_DRAM =4 , +}; + +#define rttnom_none 0/* Rtt_Nom disabled */ +#define rttnom_60ohm 1/* RZQ/4 = 240/4 = 60 ohms */ +#define rttnom_120ohm 2/* RZQ/2 = 240/2 = 120 ohms */ +#define rttnom_40ohm 3/* RZQ/6 = 240/6 = 40 ohms */ +#define rttnom_20ohm 4/* RZQ/12 = 240/12 = 20 ohms */ +#define rttnom_30ohm 5/* RZQ/8 = 240/8 = 30 ohms */ +#define rttnom_rsrv1 6/* Reserved */ +#define rttnom_rsrv2 7/* Reserved */ + +#define rttwr_none 0/* Dynamic ODT off */ +#define rttwr_60ohm 1/* RZQ/4 = 240/4 = 60 ohms */ +#define rttwr_120ohm 2/* RZQ/2 = 240/2 = 120 ohms */ +#define rttwr_rsrv1 3/* Reserved */ + +#define dic_40ohm 0/* RZQ/6 = 240/6 = 40 ohms */ +#define dic_34ohm 1/* RZQ/7 = 240/7 = 34 ohms */ + +#define driver_24_ohm 1 +#define driver_27_ohm 2 +#define driver_30_ohm 3 +#define driver_34_ohm 4 +#define driver_40_ohm 5 +#define driver_48_ohm 6 +#define driver_60_ohm 7 + +#define rodt_ctl_none 0 +#define rodt_ctl_20_ohm 1 +#define rodt_ctl_30_ohm 2 +#define rodt_ctl_40_ohm 3 +#define rodt_ctl_60_ohm 4 +#define rodt_ctl_120_ohm 5 + +#define ddr4_rttnom_none 0/* Rtt_Nom disabled */ +#define ddr4_rttnom_60ohm 1/* RZQ/4 = 240/4 = 60 ohms */ +#define ddr4_rttnom_120ohm 2/* RZQ/2 = 240/2 = 120 ohms */ +#define ddr4_rttnom_40ohm 3/* RZQ/6 = 240/6 = 40 ohms */ +#define ddr4_rttnom_240ohm 4/* RZQ/1 = 240/1 = 240 ohms */ +#define ddr4_rttnom_48ohm 5/* RZQ/5 = 240/5 = 48 ohms */ +#define ddr4_rttnom_80ohm 6/* RZQ/3 = 240/3 = 80 ohms */ +#define ddr4_rttnom_34ohm 7/* RZQ/7 = 240/7 = 34 ohms */ + +#define ddr4_rttwr_none 0/* Dynamic ODT off */ +#define ddr4_rttwr_120ohm 1/* RZQ/2 = 240/2 = 120 ohms */ +#define ddr4_rttwr_240ohm 2/* RZQ/1 = 240/1 = 240 ohms */ +#define ddr4_rttwr_hiz 3/* HiZ */ +/* This setting is available for cn78xx pass 2, and cn73xx & cnf75xx pass 1 */ +#define ddr4_rttwr_80ohm 4/* RZQ/3 = 240/3 = 80 ohms */ + +#define ddr4_dic_34ohm 0/* RZQ/7 = 240/7 = 34 ohms */ +#define ddr4_dic_48ohm 1/* RZQ/5 = 240/5 = 48 ohms */ + +#define ddr4_rttpark_none 0/* Rtt_Park disabled */ +#define ddr4_rttpark_60ohm 1/* RZQ/4 = 240/4 = 60 ohms */ +#define ddr4_rttpark_120ohm 2/* RZQ/2 = 240/2 = 120 ohms */ +#define ddr4_rttpark_40ohm 3/* RZQ/6 = 240/6 = 40 ohms */ +#define ddr4_rttpark_240ohm 4/* RZQ/1 = 240/1 = 240 ohms */ +#define ddr4_rttpark_48ohm 5/* RZQ/5 = 240/5 = 48 ohms */ +#define ddr4_rttpark_80ohm 6/* RZQ/3 = 240/3 = 80 ohms */ +#define ddr4_rttpark_34ohm 7/* RZQ/7 = 240/7 = 34 ohms */ + +#define ddr4_driver_26_ohm 2 +#define ddr4_driver_30_ohm 3 +#define ddr4_driver_34_ohm 4 +#define ddr4_driver_40_ohm 5 +#define ddr4_driver_48_ohm 6 + +#define ddr4_dqx_driver_24_ohm 1 +#define ddr4_dqx_driver_27_ohm 2 +#define ddr4_dqx_driver_30_ohm 3 +#define ddr4_dqx_driver_34_ohm 4 +#define ddr4_dqx_driver_40_ohm 5 +#define ddr4_dqx_driver_48_ohm 6 +#define ddr4_dqx_driver_60_ohm 7 + +#define ddr4_rodt_ctl_none 0 +#define ddr4_rodt_ctl_40_ohm 1 +#define ddr4_rodt_ctl_60_ohm 2 +#define ddr4_rodt_ctl_80_ohm 3 +#define ddr4_rodt_ctl_120_ohm 4 +#define ddr4_rodt_ctl_240_ohm 5 +#define ddr4_rodt_ctl_34_ohm 6 +#define ddr4_rodt_ctl_48_ohm 7 + +#define DIMM_CONFIG_TERMINATOR { {0, 0}, {NULL, NULL} } + +#define SET_DDR_DLL_CTL3 (field, expr) \ + do { \ + if (octeon_is_cpuid(OCTEON_CN66XX) || \ + octeon_is_cpuid(OCTEON_CN63XX)) \ + ddr_dll_ctl3.cn63xx.field = (expr); \ + else if (octeon_is_cpuid(OCTEON_CN68XX) || \ + octeon_is_cpuid(OCTEON_CN61XX) || \ + octeon_is_cpuid(OCTEON_CNF71XX)) \ + ddr_dll_ctl3.cn61xx.field = (expr); \ + else if (octeon_is_cpuid(OCTEON_CN70XX) || \ + octeon_is_cpuid(OCTEON_CN78XX)) \ + ddr_dll_ctl3.cn70xx.field = (expr); \ + else if (octeon_is_cpuid(OCTEON_CN73XX) || \ + octeon_is_cpuid(OCTEON_CNF75XX)) \ + ddr_dll_ctl3.cn73xx.field = (expr); \ + else \ + debug("%s(): " #field \ + "not set for unknown chip\n", \ + __func__); \ + } while (0) + +#define ENCODE_DLL90_BYTE_SEL (byte_sel) \ + (octeon_is_cpuid(OCTEON_CN70XX) ? ((9 + 7 - (byte_sel)) % 9) : \ + ((byte_sel) + 1)) + +/** +* If debugging is disabled the ddr_print macro is not compatible +* with this macro. +*/ +# define GET_DDR_DLL_CTL3 (field) \ + ((octeon_is_cpuid(OCTEON_CN66XX) || \ + octeon_is_cpuid(OCTEON_CN63XX)) ? \ + ddr_dll_ctl3.cn63xx.field : \ + (octeon_is_cpuid(OCTEON_CN68XX) || \ + octeon_is_cpuid(OCTEON_CN61XX) || \ + octeon_is_cpuid(OCTEON_CNF71XX)) ? \ + ddr_dll_ctl3.cn61xx.field : \ + (octeon_is_cpuid(OCTEON_CN70XX) || \ + octeon_is_cpuid(OCTEON_CN78XX)) ? \ + ddr_dll_ctl3.cn70xx.field : \ + (octeon_is_cpuid(OCTEON_CN73XX) || \ + octeon_is_cpuid(OCTEON_CNF75XX)) ? \ + ddr_dll_ctl3.cn73xx.field : 0) + +extern const char *ddr3_dimm_types[]; +extern const char *ddr4_dimm_types[]; + +extern const struct dimm_odt_config disable_odt_config[]; + +#define RLEVEL_BYTE_BITS 6 +#define RLEVEL_BYTE_MSK ((1ULL << 6) - 1) + +/* Prototypes */ +int get_ddr_type (struct dimm_config *dimm_config,int upper_dimm); +int get_dimm_module_type (struct dimm_config *dimm_config,int upper_dimm, +int ddr_type); +int read_spd (struct dimm_config *dimm_config,int dimm_index,int spd_field); +int read_spd_init (struct dimm_config *dimm_config,int dimm_index); +void report_dimm (struct dimm_config *dimm_config,int upper_dimm, +int dimm,int if_num); +int validate_dimm (struct ddr_priv *priv,struct dimm_config *dimm_config, +int dimm_index); +char *printable_rank_spec (char *buffer,int num_ranks,int dram_width, +int spd_package); + +bool ddr_memory_preserved (struct ddr_priv *priv); + +int get_wl_rank (union cvmx_lmcx_wlevel_rankx *lmc_wlevel_rank,int byte); +int get_rl_rank (union cvmx_lmcx_rlevel_rankx *lmc_rlevel_rank,int byte); +void upd_wl_rank (union cvmx_lmcx_wlevel_rankx *lmc_wlevel_rank,int byte, +int delay); +void upd_rl_rank (union cvmx_lmcx_rlevel_rankx *lmc_rlevel_rank,int byte, +int delay); + +int compute_ddr3_rlevel_delay (u8 mstart,u8 width, +union cvmx_lmcx_rlevel_ctl rlevel_ctl); + +int encode_row_lsb_ddr3 (int row_lsb); +int encode_pbank_lsb_ddr3 (int pbank_lsb); + +int initialize_ddr_clock (struct ddr_priv *priv,struct ddr_conf *ddr_conf, +u32 cpu_hertz,u32 ddr_hertz,u32 ddr_ref_hertz, +int if_num,u32 if_mask); + +void process_custom_dll_offsets (struct ddr_priv *priv,int if_num, +const char *enable_str, +const int8_t *offsets,const char *byte_str, +int mode); +int nonseq_del (struct rlevel_byte_data *rlevel_byte,int start,int end, +int max_adj_delay_inc); +int roundup_ddr3_wlevel_bitmask (int bitmask); + +void oct3_ddr3_seq (struct ddr_priv *priv,int rank_mask,int if_num, +int sequence); +void ddr_init_seq (struct ddr_priv *priv,int rank_mask,int if_num); + +void rlevel_to_wlevel (union cvmx_lmcx_rlevel_rankx *lmc_rlevel_rank, +union cvmx_lmcx_wlevel_rankx *lmc_wlevel_rank,int byte); + +int validate_ddr3_rlevel_bitmask (struct rlevel_bitmask *rlevel_bitmask_p, +int ddr_type); + +void change_dll_offset_enable (struct ddr_priv *priv,int if_num,int change); +unsigned short load_dll_offset (struct ddr_priv *priv,int if_num, +int dll_offset_mode, +int byte_offset,int byte); + +u64 lmc_ddr3_rl_dbg_read (struct ddr_priv *priv,int if_num,int idx); +u64 lmc_ddr3_wl_dbg_read (struct ddr_priv *priv,int if_num,int idx); + +void cvmx_maybe_tune_node (struct ddr_priv *priv,u32 ddr_speed); +void cvmx_dbi_switchover (struct ddr_priv *priv); + +int init_octeon3_ddr3_interface (struct ddr_priv *priv, +struct ddr_conf *ddr_conf, +u32 ddr_hertz,u32 cpu_hertz,u32 ddr_ref_hertz, +int if_num,u32 if_mask); + +char *lookup_env (struct ddr_priv *priv,const char *format, ...); +char *lookup_env_ull (struct ddr_priv *priv,const char *format, ...); + +/* Each board provides a board-specific config table via this function */ +struct ddr_conf *octeon_ddr_conf_table_get (int *count,int *def_ddr_freq); + +#endif /* __OCTEON_DDR_H_ */
Signature · 1 line
2.28.0
PATCH v3 5/9 ram: octeon: Add MIPS Octeon3 DDR4 support (part 1/3)
In reply to Stefan RoeseFrom: Aaron Williams <[email protected]>
This Octeon 3 DDR driver is ported from the 2013 Cavium / Marvell U-Boot repository. It currently supports DDR4 on Octeon 3. It can be later extended to support also DDR3 and Octeon 2 platforms.
Part 1 adds the base U-Boot RAM driver, which will be instantiated by the DT based probing.
---
Changes in v3:
- Remove "https://spdx.org/licenses" line
- Remove inclusion of "common.h"
Changes in v2:
- Don't re-init after relocation
- Some unsupported Octeon families removed (only Octeon 2 & 3 supported in general)
drivers/ram/octeon/octeon_ddr.c | 2728 +++++++++++++++++++++++++++++++ 1 file changed, 2728 insertions(+) create mode 100644 drivers/ram/octeon/octeon_ddr.c
drivers/ram/octeon/octeon_ddr.c new file +2728 -0
@@ -0,0 +1,2728 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2020 Marvell International Ltd. +*/ + +#include <command.h> +#include <config.h> +#include <dm.h> +#include <hang.h> +#include <i2c.h> +#include <ram.h> +#include <time.h> + +#include <asm/sections.h> +#include <linux/io.h> + +#include <mach/octeon_ddr.h> + +#define CONFIG_REF_HERTZ 50000000 + +DECLARE_GLOBAL_DATA_PTR ; + +/* Sign of an integer */ +static s64 _sign (s64 v) +{ +return (v <0 ); +} + +#ifndef DDR_NO_DEBUG +char *lookup_env (struct ddr_priv *priv,const char *format, ...) +{ +char *s; +unsigned long value; +va_list args; +char buffer[64 ]; + +va_start (args, format); +vsnprintf (buffer,sizeof (buffer), format, args); +va_end (args); + + s =ddr_getenv_debug (priv, buffer); +if (s) { + value =simple_strtoul (s,NULL ,0 ); +printf ("Parameter found in environment %s=\"%s\" 0x%lx (%ld)\n" , + buffer, s, value, value); + } + +return s; +} + +char *lookup_env_ull (struct ddr_priv *priv,const char *format, ...) +{ +char *s; +u64 value; +va_list args; +char buffer[64 ]; + +va_start (args, format); +vsnprintf (buffer,sizeof (buffer), format, args); +va_end (args); + + s =ddr_getenv_debug (priv, buffer); +if (s) { + value =simple_strtoull (s,NULL ,0 ); +printf ("Parameter found in environment. %s = 0x%016llx\n" , + buffer, value); + } + +return s; +} +#else +char *lookup_env (struct ddr_priv *priv,const char *format, ...) +{ +return NULL ; +} + +char *lookup_env_ull (struct ddr_priv *priv,const char *format, ...) +{ +return NULL ; +} +#endif + +/* Number of L2C Tag-and-data sections (TADs) that are connected to LMC. */ +#define CVMX_L2C_TADS ((OCTEON_IS_MODEL(OCTEON_CN68XX) || \ + OCTEON_IS_MODEL(OCTEON_CN73XX) || \ + OCTEON_IS_MODEL(OCTEON_CNF75XX)) ? 4 : \ + (OCTEON_IS_MODEL(OCTEON_CN78XX)) ? 8 : 1) + +/* Number of L2C IOBs connected to LMC. */ +#define CVMX_L2C_IOBS ((OCTEON_IS_MODEL(OCTEON_CN68XX) || \ + OCTEON_IS_MODEL(OCTEON_CN78XX) || \ + OCTEON_IS_MODEL(OCTEON_CN73XX) || \ + OCTEON_IS_MODEL(OCTEON_CNF75XX)) ? 2 : 1) + +#define CVMX_L2C_MAX_MEMSZ_ALLOWED (OCTEON_IS_OCTEON2() ? \ + (32 * CVMX_L2C_TADS) : \ + (OCTEON_IS_MODEL(OCTEON_CN70XX) ? \ + 512 : (OCTEON_IS_OCTEON3() ? 1024 : 0))) + +/** +* Initialize the BIG address in L2C+DRAM to generate proper error +* on reading/writing to an non-existent memory location. +* +* @param node OCX CPU node number +* @param mem_size Amount of DRAM configured in MB. +* @param mode Allow/Disallow reporting errors L2C_INT_SUM[BIGRD,BIGWR]. +*/ +static void cvmx_l2c_set_big_size (struct ddr_priv *priv,u64 mem_size,int mode) +{ +if ((OCTEON_IS_OCTEON2 () ||OCTEON_IS_OCTEON3 ()) && + !OCTEON_IS_MODEL (OCTEON_CN63XX_PASS1_X )) { +union cvmx_l2c_big_ctl big_ctl; +int bits =0 , zero_bits =0 ; +u64 mem; + +if (mem_size > (CVMX_L2C_MAX_MEMSZ_ALLOWED *1024ull )) { +printf ("WARNING: Invalid memory size(%lld) requested, should be <= %lld\n" , + mem_size, + (u64 )CVMX_L2C_MAX_MEMSZ_ALLOWED *1024 ); + mem_size =CVMX_L2C_MAX_MEMSZ_ALLOWED *1024 ; + } + + mem = mem_size; +while (mem) { +if ((mem &1 ) ==0 ) + zero_bits++; + bits++; + mem >>=1 ; + } + +if ((bits - zero_bits) !=1 || (bits -9 ) <=0 ) { +printf ("ERROR: Invalid DRAM size (%lld) requested, refer to L2C_BIG_CTL[maxdram] for valid options.\n" , + mem_size); +return ; + } + +/* +* The BIG/HOLE is logic is not supported in pass1 as per +* Errata L2C-17736 +*/ +if (mode ==0 &&OCTEON_IS_MODEL (OCTEON_CN78XX_PASS1_X )) + mode =1 ; + + big_ctl.u64 =0 ; + big_ctl.s.maxdram = bits -9 ; + big_ctl.cn61xx.disable = mode; +l2c_wr (priv,CVMX_L2C_BIG_CTL , big_ctl.u64); + } +} + +static u32 octeon3_refclock (u32 alt_refclk,u32 ddr_hertz, +struct dimm_config *dimm_config) +{ +u32 ddr_ref_hertz =CONFIG_REF_HERTZ ; +int ddr_type; +int spd_dimm_type; + +debug ("%s(%u, %u, %p)\n" , __func__, alt_refclk, ddr_hertz, dimm_config); + +/* Octeon 3 case... */ + +/* we know whether alternate refclk is always wanted +* we also know already if we want 2133 MT/s +* if alt refclk not always wanted, then probe DDR and +* DIMM type if DDR4 and RDIMMs, then set desired refclk +* to 100MHz, otherwise to default (50MHz) +* depend on ddr_initialize() to do the refclk selection +* and validation/ +*/ +if (alt_refclk) { +/* +* If alternate refclk was specified, let it override +* everything +*/ + ddr_ref_hertz = alt_refclk *1000000 ; +printf ("%s: DRAM init: %d MHz refclk is REQUESTED ALWAYS\n" , + __func__, alt_refclk); + }else if (ddr_hertz >1000000000 ) { + ddr_type =get_ddr_type (dimm_config,0 ); + spd_dimm_type =get_dimm_module_type (dimm_config,0 , ddr_type); + +debug ("ddr type: 0x%x, dimm type: 0x%x\n" , ddr_type, + spd_dimm_type); +/* Is DDR4 and RDIMM just to be sure. */ +if (ddr_type ==DDR4_DRAM && + (spd_dimm_type ==1 || spd_dimm_type ==5 || + spd_dimm_type ==8 )) { +/* Yes, we require 100MHz refclk, so set it. */ + ddr_ref_hertz =100000000 ; +puts ("DRAM init: 100 MHz refclk is REQUIRED\n" ); + } + } + +debug ("%s: speed: %u\n" , __func__, ddr_ref_hertz); +return ddr_ref_hertz; +} + +int encode_row_lsb_ddr3 (int row_lsb) +{ +int row_lsb_start =14 ; + +/* Decoding for row_lsb */ +/* 000: row_lsb = mem_adr[14] */ +/* 001: row_lsb = mem_adr[15] */ +/* 010: row_lsb = mem_adr[16] */ +/* 011: row_lsb = mem_adr[17] */ +/* 100: row_lsb = mem_adr[18] */ +/* 101: row_lsb = mem_adr[19] */ +/* 110: row_lsb = mem_adr[20] */ +/* 111: RESERVED */ + +if (octeon_is_cpuid (OCTEON_CN6XXX ) || +octeon_is_cpuid (OCTEON_CNF7XXX ) ||octeon_is_cpuid (OCTEON_CN7XXX )) + row_lsb_start =14 ; +else +printf ("ERROR: Unsupported Octeon model: 0x%x\n" , +read_c0_prid ()); + +return row_lsb - row_lsb_start; +} + +int encode_pbank_lsb_ddr3 (int pbank_lsb) +{ +/* Decoding for pbank_lsb */ +/* 0000:DIMM = mem_adr[28] / rank = mem_adr[27] (if RANK_ENA) */ +/* 0001:DIMM = mem_adr[29] / rank = mem_adr[28] " */ +/* 0010:DIMM = mem_adr[30] / rank = mem_adr[29] " */ +/* 0011:DIMM = mem_adr[31] / rank = mem_adr[30] " */ +/* 0100:DIMM = mem_adr[32] / rank = mem_adr[31] " */ +/* 0101:DIMM = mem_adr[33] / rank = mem_adr[32] " */ +/* 0110:DIMM = mem_adr[34] / rank = mem_adr[33] " */ +/* 0111:DIMM = 0 / rank = mem_adr[34] " */ +/* 1000-1111: RESERVED */ + +int pbank_lsb_start =0 ; + +if (octeon_is_cpuid (OCTEON_CN6XXX ) || +octeon_is_cpuid (OCTEON_CNF7XXX ) ||octeon_is_cpuid (OCTEON_CN7XXX )) + pbank_lsb_start =28 ; +else +printf ("ERROR: Unsupported Octeon model: 0x%x\n" , +read_c0_prid ()); + +return pbank_lsb - pbank_lsb_start; +} + +static void set_ddr_clock_initialized (struct ddr_priv *priv,int if_num, +bool inited_flag) +{ + priv->ddr_clock_initialized[if_num] = inited_flag; +} + +static int ddr_clock_initialized (struct ddr_priv *priv,int if_num) +{ +return priv->ddr_clock_initialized[if_num]; +} + +static void set_ddr_memory_preserved (struct ddr_priv *priv) +{ + priv->ddr_memory_preserved = true; +} + +bool ddr_memory_preserved (struct ddr_priv *priv) +{ +return priv->ddr_memory_preserved; +} + +static void cn78xx_lmc_dreset_init (struct ddr_priv *priv,int if_num) +{ +union cvmx_lmcx_dll_ctl2 dll_ctl2; + +/* +* The remainder of this section describes the sequence for LMCn. +* +* 1. If not done already, write LMC(0..3)_DLL_CTL2 to its reset value +* (except without changing the LMC(0..3)_DLL_CTL2[INTF_EN] value from +* that set in the prior Step 3), including +* LMC(0..3)_DLL_CTL2[DRESET] = 1. +* +* 2. Without changing any other LMC(0..3)_DLL_CTL2 fields, write +* LMC(0..3)_DLL_CTL2[DLL_BRINGUP] = 1. +*/ + + dll_ctl2.u64 =lmc_rd (priv,CVMX_LMCX_DLL_CTL2 (if_num)); + dll_ctl2.cn78xx.dll_bringup =1 ; +lmc_wr (priv,CVMX_LMCX_DLL_CTL2 (if_num), dll_ctl2.u64); + +/* +* 3. Read LMC(0..3)_DLL_CTL2 and wait for the result. +*/ + +lmc_rd (priv,CVMX_LMCX_DLL_CTL2 (if_num)); + +/* +* 4. Wait for a minimum of 10 LMC CK cycles. +*/ + +udelay (1 ); + +/* +* 5. Without changing any other fields in LMC(0..3)_DLL_CTL2, write +* LMC(0..3)_DLL_CTL2[QUAD_DLL_ENA] = 1. +* LMC(0..3)_DLL_CTL2[QUAD_DLL_ENA] must not change after this point +* without restarting the LMCn DRESET initialization sequence. +*/ + + dll_ctl2.u64 =lmc_rd (priv,CVMX_LMCX_DLL_CTL2 (if_num)); + dll_ctl2.cn78xx.quad_dll_ena =1 ; +lmc_wr (priv,CVMX_LMCX_DLL_CTL2 (if_num), dll_ctl2.u64); + +/* +* 6. Read LMC(0..3)_DLL_CTL2 and wait for the result. +*/ + +lmc_rd (priv,CVMX_LMCX_DLL_CTL2 (if_num)); + +/* +* 7. Wait a minimum of 10 us. +*/ + +udelay (10 ); + +/* +* 8. Without changing any other fields in LMC(0..3)_DLL_CTL2, write +* LMC(0..3)_DLL_CTL2[DLL_BRINGUP] = 0. +* LMC(0..3)_DLL_CTL2[DLL_BRINGUP] must not change after this point +* without restarting the LMCn DRESET initialization sequence. +*/ + + dll_ctl2.u64 =lmc_rd (priv,CVMX_LMCX_DLL_CTL2 (if_num)); + dll_ctl2.cn78xx.dll_bringup =0 ; +lmc_wr (priv,CVMX_LMCX_DLL_CTL2 (if_num), dll_ctl2.u64); + +/* +* 9. Read LMC(0..3)_DLL_CTL2 and wait for the result. +*/ + +lmc_rd (priv,CVMX_LMCX_DLL_CTL2 (if_num)); + +/* +* 10. Without changing any other fields in LMC(0..3)_DLL_CTL2, write +* LMC(0..3)_DLL_CTL2[DRESET] = 0. +* LMC(0..3)_DLL_CTL2[DRESET] must not change after this point without +* restarting the LMCn DRESET initialization sequence. +* +* After completing LMCn DRESET initialization, all LMC CSRs may be +* accessed. Prior to completing LMC DRESET initialization, only +* LMC(0..3)_DDR_PLL_CTL, LMC(0..3)_DLL_CTL2, LMC(0..3)_RESET_CTL, and +* LMC(0..3)_COMP_CTL2 LMC CSRs can be accessed. +*/ + + dll_ctl2.u64 =lmc_rd (priv,CVMX_LMCX_DLL_CTL2 (if_num)); + dll_ctl2.cn78xx.dreset =0 ; +lmc_wr (priv,CVMX_LMCX_DLL_CTL2 (if_num), dll_ctl2.u64); +} + +int initialize_ddr_clock (struct ddr_priv *priv,struct ddr_conf *ddr_conf, +u32 cpu_hertz,u32 ddr_hertz,u32 ddr_ref_hertz, +int if_num,u32 if_mask) +{ +char *s; + +if (ddr_clock_initialized (priv, if_num)) +return 0 ; + +if (!ddr_clock_initialized (priv,0 )) {/* Do this once */ +union cvmx_lmcx_reset_ctl reset_ctl; +int i; + +/* +* Check to see if memory is to be preserved and set global +* flag +*/ +for (i =3 ; i >=0 ; --i) { +if ((if_mask & (1 << i)) ==0 ) +continue ; + + reset_ctl.u64 =lmc_rd (priv,CVMX_LMCX_RESET_CTL (i)); +if (reset_ctl.s.ddr3psv ==1 ) { +debug ("LMC%d Preserving memory\n" , i); +set_ddr_memory_preserved (priv); + +/* Re-initialize flags */ + reset_ctl.s.ddr3pwarm =0 ; + reset_ctl.s.ddr3psoft =0 ; + reset_ctl.s.ddr3psv =0 ; +lmc_wr (priv,CVMX_LMCX_RESET_CTL (i), + reset_ctl.u64); + } + } + } + +/* +* ToDo: Add support for these SoCs: +* +* if (octeon_is_cpuid(OCTEON_CN63XX) || +* octeon_is_cpuid(OCTEON_CN66XX) || +* octeon_is_cpuid(OCTEON_CN61XX) || octeon_is_cpuid(OCTEON_CNF71XX)) +* +* and +* +* if (octeon_is_cpuid(OCTEON_CN68XX)) +* +* and +* +* if (octeon_is_cpuid(OCTEON_CN70XX)) +* +*/ + +if (octeon_is_cpuid (OCTEON_CN78XX ) ||octeon_is_cpuid (OCTEON_CN73XX ) || +octeon_is_cpuid (OCTEON_CNF75XX )) { +union cvmx_lmcx_dll_ctl2 dll_ctl2; +union cvmx_lmcx_dll_ctl3 ddr_dll_ctl3; +union cvmx_lmcx_ddr_pll_ctl ddr_pll_ctl; +struct dimm_config *dimm_config_table = + ddr_conf->dimm_config_table; +int en_idx, save_en_idx, best_en_idx =0 ; +u64 clkf, clkr, max_clkf =127 ; +u64 best_clkf =0 , best_clkr =0 ; +u64 best_pll_MHz =0 ; +u64 pll_MHz; +u64 min_pll_MHz =800 ; +u64 max_pll_MHz =5000 ; +u64 error; +u64 best_error; +u64 best_calculated_ddr_hertz =0 ; +u64 calculated_ddr_hertz =0 ; +u64 orig_ddr_hertz = ddr_hertz; +const int _en[] = {1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,10 ,12 }; +int override_pll_settings; +int new_bwadj; +int ddr_type; +int i; + +/* ddr_type only indicates DDR4 or DDR3 */ + ddr_type = (read_spd (&dimm_config_table[0 ],0 , +DDR4_SPD_KEY_BYTE_DEVICE_TYPE ) == +0x0C ) ?DDR4_DRAM :DDR3_DRAM ; + +/* +* 5.9 LMC Initialization Sequence +* +* There are 13 parts to the LMC initialization procedure: +* +* 1. DDR PLL initialization +* +* 2. LMC CK initialization +* +* 3. LMC interface enable initialization +* +* 4. LMC DRESET initialization +* +* 5. LMC CK local initialization +* +* 6. LMC RESET initialization +* +* 7. Early LMC initialization +* +* 8. LMC offset training +* +* 9. LMC internal Vref training +* +* 10. LMC deskew training +* +* 11. LMC write leveling +* +* 12. LMC read leveling +* +* 13. Final LMC initialization +* +* CN78XX supports two modes: +* +* - two-LMC mode: both LMCs 2/3 must not be enabled +* (LMC2/3_DLL_CTL2[DRESET] must be set to 1 and +* LMC2/3_DLL_CTL2[INTF_EN] +* must be set to 0) and both LMCs 0/1 must be enabled). +* +* - four-LMC mode: all four LMCs 0..3 must be enabled. +* +* Steps 4 and 6..13 should each be performed for each +* enabled LMC (either twice or four times). Steps 1..3 and +* 5 are more global in nature and each must be executed +* exactly once (not once per LMC) each time the DDR PLL +* changes or is first brought up. Steps 1..3 and 5 need +* not be performed if the DDR PLL is stable. +* +* Generally, the steps are performed in order. The exception +* is that the CK local initialization (step 5) must be +* performed after some DRESET initializations (step 4) and +* before other DRESET initializations when the DDR PLL is +* brought up or changed. (The CK local initialization uses +* information from some LMCs to bring up the other local +* CKs.) The following text describes these ordering +* requirements in more detail. +* +* Following any chip reset, the DDR PLL must be brought up, +* and all 13 steps should be executed. Subsequently, it is +* possible to execute only steps 4 and 6..13, or to execute +* only steps 8..13. +* +* The remainder of this section covers these initialization +* steps in sequence. +*/ + +/* Do the following init only once */ +if (if_num !=0 ) + goto not_if0; + +/* Only for interface #0 ... */ + +/* +* 5.9.3 LMC Interface-Enable Initialization +* +* LMC interface-enable initialization (Step 3) must be# +* performed after Step 2 for each chip reset and whenever +* the DDR clock speed changes. This step needs to be +* performed only once, not once per LMC. Perform the +* following three substeps for the LMC interface-enable +* initialization: +* +* 1. Without changing any other LMC2_DLL_CTL2 fields +* (LMC(0..3)_DLL_CTL2 should be at their reset values after +* Step 1), write LMC2_DLL_CTL2[INTF_EN] = 1 if four-LMC +* mode is desired. +* +* 2. Without changing any other LMC3_DLL_CTL2 fields, write +* LMC3_DLL_CTL2[INTF_EN] = 1 if four-LMC mode is desired. +* +* 3. Read LMC2_DLL_CTL2 and wait for the result. +* +* The LMC2_DLL_CTL2[INTF_EN] and LMC3_DLL_CTL2[INTF_EN] +* values should not be changed by software from this point. +*/ + +for (i =0 ; i <4 ; ++i) { +if ((if_mask & (1 << i)) ==0 ) +continue ; + + dll_ctl2.u64 =lmc_rd (priv,CVMX_LMCX_DLL_CTL2 (i)); + + dll_ctl2.cn78xx.byp_setting =0 ; + dll_ctl2.cn78xx.byp_sel =0 ; + dll_ctl2.cn78xx.quad_dll_ena =0 ; + dll_ctl2.cn78xx.dreset =1 ; + dll_ctl2.cn78xx.dll_bringup =0 ; + dll_ctl2.cn78xx.intf_en =0 ; + +lmc_wr (priv,CVMX_LMCX_DLL_CTL2 (i), dll_ctl2.u64); + } + +/* +* ###### Interface enable (intf_en) deferred until after +* DDR_DIV_RESET=0 ####### +*/ + +/* +* 5.9.1 DDR PLL Initialization +* +* DDR PLL initialization (Step 1) must be performed for each +* chip reset and whenever the DDR clock speed changes. This +* step needs to be performed only once, not once per LMC. +* +* Perform the following eight substeps to initialize the +* DDR PLL: +* +* 1. If not done already, write all fields in +* LMC(0..3)_DDR_PLL_CTL and +* LMC(0..1)_DLL_CTL2 to their reset values, including: +* +* .. LMC0_DDR_PLL_CTL[DDR_DIV_RESET] = 1 +* .. LMC0_DLL_CTL2[DRESET] = 1 +* +* This substep is not necessary after a chip reset. +* +*/ + + ddr_pll_ctl.u64 =lmc_rd (priv,CVMX_LMCX_DDR_PLL_CTL (0 )); + + ddr_pll_ctl.cn78xx.reset_n =0 ; + ddr_pll_ctl.cn78xx.ddr_div_reset =1 ; + ddr_pll_ctl.cn78xx.phy_dcok =0 ; + +/* +* 73XX pass 1.3 has LMC0 DCLK_INVERT tied to 1; earlier +* 73xx passes are tied to 0 +* +* 75XX needs LMC0 DCLK_INVERT set to 1 to minimize duty +* cycle falling points +* +* and we default all other chips LMC0 to DCLK_INVERT=0 +*/ + ddr_pll_ctl.cn78xx.dclk_invert = + !!(octeon_is_cpuid (OCTEON_CN73XX_PASS1_3 ) || +octeon_is_cpuid (OCTEON_CNF75XX )); + +/* +* allow override of LMC0 desired setting for DCLK_INVERT, +* but not on 73XX; +* we cannot change LMC0 DCLK_INVERT on 73XX any pass +*/ +if (!(octeon_is_cpuid (OCTEON_CN73XX ))) { + s =lookup_env (priv,"ddr0_set_dclk_invert" ); +if (s) { + ddr_pll_ctl.cn78xx.dclk_invert = + !!simple_strtoul (s,NULL ,0 ); +debug ("LMC0: override DDR_PLL_CTL[dclk_invert] to %d\n" , + ddr_pll_ctl.cn78xx.dclk_invert); + } + } + +lmc_wr (priv,CVMX_LMCX_DDR_PLL_CTL (0 ), ddr_pll_ctl.u64); +debug ("%-45s : 0x%016llx\n" ,"LMC0: DDR_PLL_CTL" , + ddr_pll_ctl.u64); + +// only when LMC1 is active +if (if_mask &0x2 ) { +/* +* For CNF75XX, both LMC0 and LMC1 use the same PLL, +* so we use the LMC0 setting of DCLK_INVERT for LMC1. +*/ +if (!octeon_is_cpuid (OCTEON_CNF75XX )) { +int override =0 ; + +/* +* by default, for non-CNF75XX, we want +* LMC1 toggled LMC0 +*/ +int lmc0_dclk_invert = + ddr_pll_ctl.cn78xx.dclk_invert; + +/* +* FIXME: work-around for DDR3 UDIMM problems +* is to use LMC0 setting on LMC1 and if +* 73xx pass 1.3, we want to default LMC1 +* DCLK_INVERT to LMC0, not the invert of LMC0 +*/ +int lmc1_dclk_invert; + + lmc1_dclk_invert = + ((ddr_type ==DDR4_DRAM ) && + !octeon_is_cpuid (OCTEON_CN73XX_PASS1_3 )) + ? lmc0_dclk_invert ^1 : + lmc0_dclk_invert; + +/* +* allow override of LMC1 desired setting for +* DCLK_INVERT +*/ + s =lookup_env (priv,"ddr1_set_dclk_invert" ); +if (s) { + lmc1_dclk_invert = + !!simple_strtoul (s,NULL ,0 ); + override =1 ; + } +debug ("LMC1: %s DDR_PLL_CTL[dclk_invert] to %d (LMC0 %d)\n" , + (override) ?"override" : +"default" , lmc1_dclk_invert, + lmc0_dclk_invert); + + ddr_pll_ctl.cn78xx.dclk_invert = + lmc1_dclk_invert; + } + +// but always write LMC1 CSR if it is active +lmc_wr (priv,CVMX_LMCX_DDR_PLL_CTL (1 ), ddr_pll_ctl.u64); +debug ("%-45s : 0x%016llx\n" , +"LMC1: DDR_PLL_CTL" , ddr_pll_ctl.u64); + } + +/* +* 2. If the current DRAM contents are not preserved (see +* LMC(0..3)_RESET_ CTL[DDR3PSV]), this is also an appropriate +* time to assert the RESET# pin of the DDR3/DDR4 DRAM parts. +* If desired, write +* LMC0_RESET_ CTL[DDR3RST] = 0 without modifying any other +* LMC0_RESET_CTL fields to assert the DDR_RESET_L pin. +* No action is required here to assert DDR_RESET_L +* following a chip reset. Refer to Section 5.9.6. Do this +* for all enabled LMCs. +*/ + +for (i =0 ; (!ddr_memory_preserved (priv)) && i <4 ; ++i) { +union cvmx_lmcx_reset_ctl reset_ctl; + +if ((if_mask & (1 << i)) ==0 ) +continue ; + + reset_ctl.u64 =lmc_rd (priv,CVMX_LMCX_RESET_CTL (i)); + reset_ctl.cn78xx.ddr3rst =0 ;/* Reset asserted */ +debug ("LMC%d Asserting DDR_RESET_L\n" , i); +lmc_wr (priv,CVMX_LMCX_RESET_CTL (i), reset_ctl.u64); +lmc_rd (priv,CVMX_LMCX_RESET_CTL (i)); + } + +/* +* 3. Without changing any other LMC0_DDR_PLL_CTL values, +* write LMC0_DDR_PLL_CTL[CLKF] with a value that gives a +* desired DDR PLL speed. The LMC0_DDR_PLL_CTL[CLKF] value +* should be selected in conjunction with the post-scalar +* divider values for LMC (LMC0_DDR_PLL_CTL[DDR_PS_EN]) so +* that the desired LMC CK speeds are is produced (all +* enabled LMCs must run the same speed). Section 5.14 +* describes LMC0_DDR_PLL_CTL[CLKF] and +* LMC0_DDR_PLL_CTL[DDR_PS_EN] programmings that produce +* the desired LMC CK speed. Section 5.9.2 describes LMC CK +* initialization, which can be done separately from the DDR +* PLL initialization described in this section. +* +* The LMC0_DDR_PLL_CTL[CLKF] value must not change after +* this point without restarting this SDRAM PLL +* initialization sequence. +*/ + +/* Init to max error */ + error = ddr_hertz; + best_error = ddr_hertz; + +debug ("DDR Reference Hertz = %d\n" , ddr_ref_hertz); + +while (best_error == ddr_hertz) { +for (clkr =0 ; clkr <4 ; ++clkr) { +for (en_idx = +sizeof (_en) /sizeof (int ) - +1 ; en_idx >=0 ; --en_idx) { + save_en_idx = en_idx; + clkf = + ((ddr_hertz) * + (clkr +1 ) * (_en[save_en_idx])); + clkf =divide_nint (clkf, ddr_ref_hertz) + -1 ; + pll_MHz = + ddr_ref_hertz * + (clkf +1 ) / (clkr +1 ) /1000000 ; + calculated_ddr_hertz = + ddr_ref_hertz * + (clkf + +1 ) / ((clkr + +1 ) * (_en[save_en_idx])); + error = + ddr_hertz - calculated_ddr_hertz; + +if (pll_MHz < min_pll_MHz || + pll_MHz > max_pll_MHz) +continue ; +if (clkf > max_clkf) { +/* +* PLL requires clkf to be +* limited +*/ +continue ; + } +if (abs (error) >abs (best_error)) +continue ; + +debug ("clkr: %2llu, en[%d]: %2d, clkf: %4llu, pll_MHz: %4llu, ddr_hertz: %8llu, error: %8lld\n" , + clkr, save_en_idx, + _en[save_en_idx], clkf, pll_MHz, + calculated_ddr_hertz, error); + +/* Favor the highest PLL frequency. */ +if (abs (error) <abs (best_error) || + pll_MHz > best_pll_MHz) { + best_pll_MHz = pll_MHz; + best_calculated_ddr_hertz = + calculated_ddr_hertz; + best_error = error; + best_clkr = clkr; + best_clkf = clkf; + best_en_idx = save_en_idx; + } + } + } + + override_pll_settings =0 ; + + s =lookup_env (priv,"ddr_pll_clkr" ); +if (s) { + best_clkr =simple_strtoul (s,NULL ,0 ); + override_pll_settings =1 ; + } + + s =lookup_env (priv,"ddr_pll_clkf" ); +if (s) { + best_clkf =simple_strtoul (s,NULL ,0 ); + override_pll_settings =1 ; + } + + s =lookup_env (priv,"ddr_pll_en_idx" ); +if (s) { + best_en_idx =simple_strtoul (s,NULL ,0 ); + override_pll_settings =1 ; + } + +if (override_pll_settings) { + best_pll_MHz = + ddr_ref_hertz * (best_clkf + +1 ) / + (best_clkr +1 ) /1000000 ; + best_calculated_ddr_hertz = + ddr_ref_hertz * (best_clkf + +1 ) / + ((best_clkr +1 ) * (_en[best_en_idx])); + best_error = + ddr_hertz - best_calculated_ddr_hertz; + } + +debug ("clkr: %2llu, en[%d]: %2d, clkf: %4llu, pll_MHz: %4llu, ddr_hertz: %8llu, error: %8lld <==\n" , + best_clkr, best_en_idx, _en[best_en_idx], + best_clkf, best_pll_MHz, + best_calculated_ddr_hertz, best_error); + +/* +* Try lowering the frequency if we can't get a +* working configuration +*/ +if (best_error == ddr_hertz) { +if (ddr_hertz < orig_ddr_hertz -10000000 ) +break ; + ddr_hertz -=1000000 ; + best_error = ddr_hertz; + } + } + +if (best_error == ddr_hertz) { +printf ("ERROR: Can not compute a legal DDR clock speed configuration.\n" ); +return -1 ; + } + + new_bwadj = (best_clkf +1 ) /10 ; +debug ("bwadj: %2d\n" , new_bwadj); + + s =lookup_env (priv,"ddr_pll_bwadj" ); +if (s) { + new_bwadj =strtoul (s,NULL ,0 ); +debug ("bwadj: %2d\n" , new_bwadj); + } + +for (i =0 ; i <2 ; ++i) { +if ((if_mask & (1 << i)) ==0 ) +continue ; + + ddr_pll_ctl.u64 = +lmc_rd (priv,CVMX_LMCX_DDR_PLL_CTL (i)); +debug ("LMC%d: DDR_PLL_CTL : 0x%016llx\n" , + i, ddr_pll_ctl.u64); + + ddr_pll_ctl.cn78xx.ddr_ps_en = best_en_idx; + ddr_pll_ctl.cn78xx.clkf = best_clkf; + ddr_pll_ctl.cn78xx.clkr = best_clkr; + ddr_pll_ctl.cn78xx.reset_n =0 ; + ddr_pll_ctl.cn78xx.bwadj = new_bwadj; + +lmc_wr (priv,CVMX_LMCX_DDR_PLL_CTL (i), ddr_pll_ctl.u64); +debug ("LMC%d: DDR_PLL_CTL : 0x%016llx\n" , + i, ddr_pll_ctl.u64); + +/* +* For cnf75xx LMC0 and LMC1 use the same PLL so +* only program LMC0 PLL. +*/ +if (octeon_is_cpuid (OCTEON_CNF75XX )) +break ; + } + +for (i =0 ; i <4 ; ++i) { +if ((if_mask & (1 << i)) ==0 ) +continue ; + +/* +* 4. Read LMC0_DDR_PLL_CTL and wait for the result. +*/ + +lmc_rd (priv,CVMX_LMCX_DDR_PLL_CTL (i)); + +/* +* 5. Wait a minimum of 3 us. +*/ + +udelay (3 );/* Wait 3 us */ + +/* +* 6. Write LMC0_DDR_PLL_CTL[RESET_N] = 1 without +* changing any other LMC0_DDR_PLL_CTL values. +*/ + + ddr_pll_ctl.u64 = +lmc_rd (priv,CVMX_LMCX_DDR_PLL_CTL (i)); + ddr_pll_ctl.cn78xx.reset_n =1 ; +lmc_wr (priv,CVMX_LMCX_DDR_PLL_CTL (i), ddr_pll_ctl.u64); + +/* +* 7. Read LMC0_DDR_PLL_CTL and wait for the result. +*/ + +lmc_rd (priv,CVMX_LMCX_DDR_PLL_CTL (i)); + +/* +* 8. Wait a minimum of 25 us. +*/ + +udelay (25 );/* Wait 25 us */ + +/* +* For cnf75xx LMC0 and LMC1 use the same PLL so +* only program LMC0 PLL. +*/ +if (octeon_is_cpuid (OCTEON_CNF75XX )) +break ; + } + +for (i =0 ; i <4 ; ++i) { +if ((if_mask & (1 << i)) ==0 ) +continue ; + +/* +* 5.9.2 LMC CK Initialization +* +* DDR PLL initialization must be completed prior to +* starting LMC CK initialization. +* +* Perform the following substeps to initialize the +* LMC CK: +* +* 1. Without changing any other LMC(0..3)_DDR_PLL_CTL +* values, write +* LMC(0..3)_DDR_PLL_CTL[DDR_DIV_RESET] = 1 and +* LMC(0..3)_DDR_PLL_CTL[DDR_PS_EN] with the +* appropriate value to get the desired LMC CK speed. +* Section 5.14 discusses CLKF and DDR_PS_EN +* programmings. The LMC(0..3)_DDR_PLL_CTL[DDR_PS_EN] +* must not change after this point without restarting +* this LMC CK initialization sequence. +*/ + + ddr_pll_ctl.u64 =lmc_rd (priv, +CVMX_LMCX_DDR_PLL_CTL (i)); + ddr_pll_ctl.cn78xx.ddr_div_reset =1 ; +lmc_wr (priv,CVMX_LMCX_DDR_PLL_CTL (i), ddr_pll_ctl.u64); + +/* +* 2. Without changing any other fields in +* LMC(0..3)_DDR_PLL_CTL, write +* LMC(0..3)_DDR_PLL_CTL[DDR4_MODE] = 0. +*/ + + ddr_pll_ctl.u64 = +lmc_rd (priv,CVMX_LMCX_DDR_PLL_CTL (i)); + ddr_pll_ctl.cn78xx.ddr4_mode = + (ddr_type ==DDR4_DRAM ) ?1 :0 ; +lmc_wr (priv,CVMX_LMCX_DDR_PLL_CTL (i), ddr_pll_ctl.u64); + +/* +* 3. Read LMC(0..3)_DDR_PLL_CTL and wait for the +* result. +*/ + +lmc_rd (priv,CVMX_LMCX_DDR_PLL_CTL (i)); + +/* +* 4. Wait a minimum of 1 us. +*/ + +udelay (1 );/* Wait 1 us */ + +/* +* ###### Steps 5 through 7 deferred until after +* DDR_DIV_RESET=0 ####### +*/ + +/* +* 8. Without changing any other LMC(0..3)_COMP_CTL2 +* values, write +* LMC(0..3)_COMP_CTL2[CK_CTL,CONTROL_CTL,CMD_CTL] +* to the desired DDR*_CK_*_P control and command +* signals drive strength. +*/ + +union cvmx_lmcx_comp_ctl2 comp_ctl2; +const struct ddr3_custom_config *custom_lmc_config = + &ddr_conf->custom_lmc_config; + + comp_ctl2.u64 =lmc_rd (priv,CVMX_LMCX_COMP_CTL2 (i)); + +/* Default 4=34.3 ohm */ + comp_ctl2.cn78xx.dqx_ctl = + (custom_lmc_config->dqx_ctl == +0 ) ?4 : custom_lmc_config->dqx_ctl; +/* Default 4=34.3 ohm */ + comp_ctl2.cn78xx.ck_ctl = + (custom_lmc_config->ck_ctl == +0 ) ?4 : custom_lmc_config->ck_ctl; +/* Default 4=34.3 ohm */ + comp_ctl2.cn78xx.cmd_ctl = + (custom_lmc_config->cmd_ctl == +0 ) ?4 : custom_lmc_config->cmd_ctl; + + comp_ctl2.cn78xx.rodt_ctl =0x4 ;/* 60 ohm */ + + comp_ctl2.cn70xx.ptune_offset = + (abs (custom_lmc_config->ptune_offset) &0x7 ) + | (_sign (custom_lmc_config->ptune_offset) <<3 ); + comp_ctl2.cn70xx.ntune_offset = + (abs (custom_lmc_config->ntune_offset) &0x7 ) + | (_sign (custom_lmc_config->ntune_offset) <<3 ); + + s =lookup_env (priv,"ddr_clk_ctl" ); +if (s) { + comp_ctl2.cn78xx.ck_ctl = +simple_strtoul (s,NULL ,0 ); + } + + s =lookup_env (priv,"ddr_ck_ctl" ); +if (s) { + comp_ctl2.cn78xx.ck_ctl = +simple_strtoul (s,NULL ,0 ); + } + + s =lookup_env (priv,"ddr_cmd_ctl" ); +if (s) { + comp_ctl2.cn78xx.cmd_ctl = +simple_strtoul (s,NULL ,0 ); + } + + s =lookup_env (priv,"ddr_dqx_ctl" ); +if (s) { + comp_ctl2.cn78xx.dqx_ctl = +simple_strtoul (s,NULL ,0 ); + } + + s =lookup_env (priv,"ddr_ptune_offset" ); +if (s) { + comp_ctl2.cn78xx.ptune_offset = +simple_strtoul (s,NULL ,0 ); + } + + s =lookup_env (priv,"ddr_ntune_offset" ); +if (s) { + comp_ctl2.cn78xx.ntune_offset = +simple_strtoul (s,NULL ,0 ); + } + +lmc_wr (priv,CVMX_LMCX_COMP_CTL2 (i), comp_ctl2.u64); + +/* +* 9. Read LMC(0..3)_DDR_PLL_CTL and wait for the +* result. +*/ + +lmc_rd (priv,CVMX_LMCX_DDR_PLL_CTL (i)); + +/* +* 10. Wait a minimum of 200 ns. +*/ + +udelay (1 );/* Wait 1 us */ + +/* +* 11. Without changing any other +* LMC(0..3)_DDR_PLL_CTL values, write +* LMC(0..3)_DDR_PLL_CTL[DDR_DIV_RESET] = 0. +*/ + + ddr_pll_ctl.u64 =lmc_rd (priv, +CVMX_LMCX_DDR_PLL_CTL (i)); + ddr_pll_ctl.cn78xx.ddr_div_reset =0 ; +lmc_wr (priv,CVMX_LMCX_DDR_PLL_CTL (i), ddr_pll_ctl.u64); + +/* +* 12. Read LMC(0..3)_DDR_PLL_CTL and wait for the +* result. +*/ + +lmc_rd (priv,CVMX_LMCX_DDR_PLL_CTL (i)); + +/* +* 13. Wait a minimum of 200 ns. +*/ + +udelay (1 );/* Wait 1 us */ + } + +/* +* Relocated Interface Enable (intf_en) Step +*/ +for (i = (octeon_is_cpuid (OCTEON_CN73XX ) || +octeon_is_cpuid (OCTEON_CNF75XX )) ?1 :2 ; + i <4 ; ++i) { +/* +* This step is only necessary for LMC 2 and 3 in +* 4-LMC mode. The mask will cause the unpopulated +* interfaces to be skipped. +*/ +if ((if_mask & (1 << i)) ==0 ) +continue ; + + dll_ctl2.u64 =lmc_rd (priv,CVMX_LMCX_DLL_CTL2 (i)); + dll_ctl2.cn78xx.intf_en =1 ; +lmc_wr (priv,CVMX_LMCX_DLL_CTL2 (i), dll_ctl2.u64); +lmc_rd (priv,CVMX_LMCX_DLL_CTL2 (i)); + } + +/* +* Relocated PHY_DCOK Step +*/ +for (i =0 ; i <4 ; ++i) { +if ((if_mask & (1 << i)) ==0 ) +continue ; +/* +* 5. Without changing any other fields in +* LMC(0..3)_DDR_PLL_CTL, write +* LMC(0..3)_DDR_PLL_CTL[PHY_DCOK] = 1. +*/ + + ddr_pll_ctl.u64 =lmc_rd (priv, +CVMX_LMCX_DDR_PLL_CTL (i)); + ddr_pll_ctl.cn78xx.phy_dcok =1 ; +lmc_wr (priv,CVMX_LMCX_DDR_PLL_CTL (i), ddr_pll_ctl.u64); +/* +* 6. Read LMC(0..3)_DDR_PLL_CTL and wait for +* the result. +*/ + +lmc_rd (priv,CVMX_LMCX_DDR_PLL_CTL (i)); + +/* +* 7. Wait a minimum of 20 us. +*/ + +udelay (20 );/* Wait 20 us */ + } + +/* +* 5.9.4 LMC DRESET Initialization +* +* All of the DDR PLL, LMC global CK, and LMC interface +* enable initializations must be completed prior to starting +* this LMC DRESET initialization (Step 4). +* +* This LMC DRESET step is done for all enabled LMCs. +* +* There are special constraints on the ordering of DRESET +* initialization (Steps 4) and CK local initialization +* (Step 5) whenever CK local initialization must be executed. +* CK local initialization must be executed whenever the DDR +* PLL is being brought up (for each chip reset* and whenever +* the DDR clock speed changes). +* +* When Step 5 must be executed in the two-LMC mode case: +* - LMC0 DRESET initialization must occur before Step 5. +* - LMC1 DRESET initialization must occur after Step 5. +* +* When Step 5 must be executed in the four-LMC mode case: +* - LMC2 and LMC3 DRESET initialization must occur before +* Step 5. +* - LMC0 and LMC1 DRESET initialization must occur after +* Step 5. +*/ + +if (octeon_is_cpuid (OCTEON_CN73XX )) { +/* ONE-LMC or TWO-LMC MODE BEFORE STEP 5 for cn73xx */ +cn78xx_lmc_dreset_init (priv,0 ); + }else if (octeon_is_cpuid (OCTEON_CNF75XX )) { +if (if_mask ==0x3 ) { +/* +* 2-LMC Mode: LMC1 DRESET must occur +* before Step 5 +*/ +cn78xx_lmc_dreset_init (priv,1 ); + } + }else { +/* TWO-LMC MODE DRESET BEFORE STEP 5 */ +if (if_mask ==0x3 ) +cn78xx_lmc_dreset_init (priv,0 ); + +/* FOUR-LMC MODE BEFORE STEP 5 */ +if (if_mask ==0xf ) { +cn78xx_lmc_dreset_init (priv,2 ); +cn78xx_lmc_dreset_init (priv,3 ); + } + } + +/* +* 5.9.5 LMC CK Local Initialization +* +* All of DDR PLL, LMC global CK, and LMC interface-enable +* initializations must be completed prior to starting this +* LMC CK local initialization (Step 5). +* +* LMC CK Local initialization must be performed for each +* chip reset and whenever the DDR clock speed changes. This +* step needs to be performed only once, not once per LMC. +* +* There are special constraints on the ordering of DRESET +* initialization (Steps 4) and CK local initialization +* (Step 5) whenever CK local initialization must be executed. +* CK local initialization must be executed whenever the +* DDR PLL is being brought up (for each chip reset and +* whenever the DDR clock speed changes). +* +* When Step 5 must be executed in the two-LMC mode case: +* - LMC0 DRESET initialization must occur before Step 5. +* - LMC1 DRESET initialization must occur after Step 5. +* +* When Step 5 must be executed in the four-LMC mode case: +* - LMC2 and LMC3 DRESET initialization must occur before +* Step 5. +* - LMC0 and LMC1 DRESET initialization must occur after +* Step 5. +* +* LMC CK local initialization is different depending on +* whether two-LMC or four-LMC modes are desired. +*/ + +if (if_mask ==0x3 ) { +int temp_lmc_if_num =octeon_is_cpuid (OCTEON_CNF75XX ) ? +1 :0 ; + +/* +* 5.9.5.1 LMC CK Local Initialization for Two-LMC +* Mode +* +* 1. Write LMC0_DLL_CTL3 to its reset value. (Note +* that LMC0_DLL_CTL3[DLL_90_BYTE_SEL] = 0x2 .. 0x8 +* should also work.) +*/ + + ddr_dll_ctl3.u64 =0 ; + ddr_dll_ctl3.cn78xx.dclk90_recal_dis =1 ; + +if (octeon_is_cpuid (OCTEON_CNF75XX )) + ddr_dll_ctl3.cn78xx.dll90_byte_sel =7 ; +else + ddr_dll_ctl3.cn78xx.dll90_byte_sel =1 ; + +lmc_wr (priv, +CVMX_LMCX_DLL_CTL3 (temp_lmc_if_num), + ddr_dll_ctl3.u64); + +/* +* 2. Read LMC0_DLL_CTL3 and wait for the result. +*/ + +lmc_rd (priv,CVMX_LMCX_DLL_CTL3 (temp_lmc_if_num)); + +/* +* 3. Without changing any other fields in +* LMC0_DLL_CTL3, write +* LMC0_DLL_CTL3[DCLK90_FWD] = 1. Writing +* LMC0_DLL_CTL3[DCLK90_FWD] = 1 +* causes clock-delay information to be forwarded +* from LMC0 to LMC1. +*/ + + ddr_dll_ctl3.cn78xx.dclk90_fwd =1 ; +lmc_wr (priv, +CVMX_LMCX_DLL_CTL3 (temp_lmc_if_num), + ddr_dll_ctl3.u64); + +/* +* 4. Read LMC0_DLL_CTL3 and wait for the result. +*/ + +lmc_rd (priv,CVMX_LMCX_DLL_CTL3 (temp_lmc_if_num)); + } + +if (if_mask ==0xf ) { +/* +* 5.9.5.2 LMC CK Local Initialization for Four-LMC +* Mode +* +* 1. Write LMC2_DLL_CTL3 to its reset value except +* LMC2_DLL_CTL3[DLL90_BYTE_SEL] = 0x7. +*/ + + ddr_dll_ctl3.u64 =0 ; + ddr_dll_ctl3.cn78xx.dclk90_recal_dis =1 ; + ddr_dll_ctl3.cn78xx.dll90_byte_sel =7 ; +lmc_wr (priv,CVMX_LMCX_DLL_CTL3 (2 ), ddr_dll_ctl3.u64); + +/* +* 2. Write LMC3_DLL_CTL3 to its reset value except +* LMC3_DLL_CTL3[DLL90_BYTE_SEL] = 0x2. +*/ + + ddr_dll_ctl3.u64 =0 ; + ddr_dll_ctl3.cn78xx.dclk90_recal_dis =1 ; + ddr_dll_ctl3.cn78xx.dll90_byte_sel =2 ; +lmc_wr (priv,CVMX_LMCX_DLL_CTL3 (3 ), ddr_dll_ctl3.u64); + +/* +* 3. Read LMC3_DLL_CTL3 and wait for the result. +*/ + +lmc_rd (priv,CVMX_LMCX_DLL_CTL3 (3 )); + +/* +* 4. Without changing any other fields in +* LMC2_DLL_CTL3, write LMC2_DLL_CTL3[DCLK90_FWD] = 1 +* and LMC2_DLL_CTL3[DCLK90_RECAL_ DIS] = 1. +* Writing LMC2_DLL_CTL3[DCLK90_FWD] = 1 causes LMC 2 +* to forward clockdelay information to LMC0. Setting +* LMC2_DLL_CTL3[DCLK90_RECAL_DIS] to 1 prevents LMC2 +* from periodically recalibrating this delay +* information. +*/ + + ddr_dll_ctl3.u64 =lmc_rd (priv,CVMX_LMCX_DLL_CTL3 (2 )); + ddr_dll_ctl3.cn78xx.dclk90_fwd =1 ; + ddr_dll_ctl3.cn78xx.dclk90_recal_dis =1 ; +lmc_wr (priv,CVMX_LMCX_DLL_CTL3 (2 ), ddr_dll_ctl3.u64); + +/* +* 5. Without changing any other fields in +* LMC3_DLL_CTL3, write LMC3_DLL_CTL3[DCLK90_FWD] = 1 +* and LMC3_DLL_CTL3[DCLK90_RECAL_ DIS] = 1. +* Writing LMC3_DLL_CTL3[DCLK90_FWD] = 1 causes LMC3 +* to forward clockdelay information to LMC1. Setting +* LMC3_DLL_CTL3[DCLK90_RECAL_DIS] to 1 prevents LMC3 +* from periodically recalibrating this delay +* information. +*/ + + ddr_dll_ctl3.u64 =lmc_rd (priv,CVMX_LMCX_DLL_CTL3 (3 )); + ddr_dll_ctl3.cn78xx.dclk90_fwd =1 ; + ddr_dll_ctl3.cn78xx.dclk90_recal_dis =1 ; +lmc_wr (priv,CVMX_LMCX_DLL_CTL3 (3 ), ddr_dll_ctl3.u64); + +/* +* 6. Read LMC3_DLL_CTL3 and wait for the result. +*/ + +lmc_rd (priv,CVMX_LMCX_DLL_CTL3 (3 )); + } + +if (octeon_is_cpuid (OCTEON_CNF75XX )) { +/* +* cnf75xx 2-LMC Mode: LMC0 DRESET must occur after +* Step 5, Do LMC0 for 1-LMC Mode here too +*/ +cn78xx_lmc_dreset_init (priv,0 ); + } + +/* TWO-LMC MODE AFTER STEP 5 */ +if (if_mask ==0x3 ) { +if (octeon_is_cpuid (OCTEON_CNF75XX )) { +/* +* cnf75xx 2-LMC Mode: LMC0 DRESET must +* occur after Step 5 +*/ +cn78xx_lmc_dreset_init (priv,0 ); + }else { +cn78xx_lmc_dreset_init (priv,1 ); + } + } + +/* FOUR-LMC MODE AFTER STEP 5 */ +if (if_mask ==0xf ) { +cn78xx_lmc_dreset_init (priv,0 ); +cn78xx_lmc_dreset_init (priv,1 ); + +/* +* Enable periodic recalibration of DDR90 delay +* line in. +*/ + ddr_dll_ctl3.u64 =lmc_rd (priv,CVMX_LMCX_DLL_CTL3 (0 )); + ddr_dll_ctl3.cn78xx.dclk90_recal_dis =0 ; +lmc_wr (priv,CVMX_LMCX_DLL_CTL3 (0 ), ddr_dll_ctl3.u64); + ddr_dll_ctl3.u64 =lmc_rd (priv,CVMX_LMCX_DLL_CTL3 (1 )); + ddr_dll_ctl3.cn78xx.dclk90_recal_dis =0 ; +lmc_wr (priv,CVMX_LMCX_DLL_CTL3 (1 ), ddr_dll_ctl3.u64); + } + +/* Enable fine tune mode for all LMCs */ +for (i =0 ; i <4 ; ++i) { +if ((if_mask & (1 << i)) ==0 ) +continue ; + ddr_dll_ctl3.u64 =lmc_rd (priv,CVMX_LMCX_DLL_CTL3 (i)); + ddr_dll_ctl3.cn78xx.fine_tune_mode =1 ; +lmc_wr (priv,CVMX_LMCX_DLL_CTL3 (i), ddr_dll_ctl3.u64); + } + +/* +* Enable the trim circuit on the appropriate channels to +* adjust the DDR clock duty cycle for chips that support +* it +*/ +if (octeon_is_cpuid (OCTEON_CN78XX_PASS2_X ) || +octeon_is_cpuid (OCTEON_CN73XX ) || +octeon_is_cpuid (OCTEON_CNF75XX )) { +union cvmx_lmcx_phy_ctl lmc_phy_ctl; +int i; + +for (i =0 ; i <4 ; ++i) { +if ((if_mask & (1 << i)) ==0 ) +continue ; + + lmc_phy_ctl.u64 = +lmc_rd (priv,CVMX_LMCX_PHY_CTL (i)); + +if (octeon_is_cpuid (OCTEON_CNF75XX ) || +octeon_is_cpuid (OCTEON_CN73XX_PASS1_3 )) { +/* Both LMCs */ + lmc_phy_ctl.s.lv_mode =0 ; + }else { +/* Odd LMCs = 0, Even LMCs = 1 */ + lmc_phy_ctl.s.lv_mode = (~i) &1 ; + } + +debug ("LMC%d: PHY_CTL : 0x%016llx\n" , + i, lmc_phy_ctl.u64); +lmc_wr (priv,CVMX_LMCX_PHY_CTL (i), + lmc_phy_ctl.u64); + } + } + } + +/* +* 5.9.6 LMC RESET Initialization +* +* NOTE: this is now done as the first step in +* init_octeon3_ddr3_interface, rather than the last step in clock +* init. This reorg allows restarting per-LMC initialization should +* problems be encountered, rather than being forced to resort to +* resetting the chip and starting all over. +* +* Look for the code in octeon3_lmc.c: perform_lmc_reset(). +*/ + +/* Fallthrough for all interfaces... */ +not_if0: + +/* +* Start the DDR clock so that its frequency can be measured. +* For some chips we must activate the memory controller with +* init_start to make the DDR clock start to run. +*/ +if ((!octeon_is_cpuid (OCTEON_CN6XXX )) && + (!octeon_is_cpuid (OCTEON_CNF7XXX )) && + (!octeon_is_cpuid (OCTEON_CN7XXX ))) { +union cvmx_lmcx_mem_cfg0 mem_cfg0; + + mem_cfg0.u64 =0 ; + mem_cfg0.s.init_start =1 ; +lmc_wr (priv,CVMX_LMCX_MEM_CFG0 (if_num), mem_cfg0.u64); +lmc_rd (priv,CVMX_LMCX_MEM_CFG0 (if_num)); + } + +set_ddr_clock_initialized (priv, if_num,1 ); + +return 0 ; +} + +static void octeon_ipd_delay_cycles (u64 cycles) +{ +u64 start =csr_rd (CVMX_IPD_CLK_COUNT ); + +while (start + cycles >csr_rd (CVMX_IPD_CLK_COUNT )) + ; +} + +static void octeon_ipd_delay_cycles_o3 (u64 cycles) +{ +u64 start =csr_rd (CVMX_FPA_CLK_COUNT ); + +while (start + cycles >csr_rd (CVMX_FPA_CLK_COUNT )) + ; +} + +static u32 measure_octeon_ddr_clock (struct ddr_priv *priv, +struct ddr_conf *ddr_conf,u32 cpu_hertz, +u32 ddr_hertz,u32 ddr_ref_hertz, +int if_num,u32 if_mask) +{ +u64 core_clocks; +u64 ddr_clocks; +u64 calc_ddr_hertz; + +if (ddr_conf) { +if (initialize_ddr_clock (priv, ddr_conf, cpu_hertz, + ddr_hertz, ddr_ref_hertz, if_num, + if_mask) !=0 ) +return 0 ; + } + +/* Dynamically determine the DDR clock speed */ +if (OCTEON_IS_OCTEON2 () ||octeon_is_cpuid (OCTEON_CN70XX )) { + core_clocks =csr_rd (CVMX_IPD_CLK_COUNT ); + ddr_clocks =lmc_rd (priv,CVMX_LMCX_DCLK_CNT (if_num)); +/* How many cpu cycles to measure over */ +octeon_ipd_delay_cycles (100000000 ); + core_clocks =csr_rd (CVMX_IPD_CLK_COUNT ) - core_clocks; + ddr_clocks = +lmc_rd (priv,CVMX_LMCX_DCLK_CNT (if_num)) - ddr_clocks; + calc_ddr_hertz = ddr_clocks * gd->bus_clk / core_clocks; + }else if (octeon_is_cpuid (OCTEON_CN7XXX )) { + core_clocks =csr_rd (CVMX_FPA_CLK_COUNT ); + ddr_clocks =lmc_rd (priv,CVMX_LMCX_DCLK_CNT (if_num)); +/* How many cpu cycles to measure over */ +octeon_ipd_delay_cycles_o3 (100000000 ); + core_clocks =csr_rd (CVMX_FPA_CLK_COUNT ) - core_clocks; + ddr_clocks = +lmc_rd (priv,CVMX_LMCX_DCLK_CNT (if_num)) - ddr_clocks; + calc_ddr_hertz = ddr_clocks * gd->bus_clk / core_clocks; + }else { + core_clocks =csr_rd (CVMX_IPD_CLK_COUNT ); +/* +* ignore overflow, starts counting when we enable the +* controller +*/ + ddr_clocks =lmc_rd (priv,CVMX_LMCX_DCLK_CNT_LO (if_num)); +/* How many cpu cycles to measure over */ +octeon_ipd_delay_cycles (100000000 ); + core_clocks =csr_rd (CVMX_IPD_CLK_COUNT ) - core_clocks; + ddr_clocks = +lmc_rd (priv,CVMX_LMCX_DCLK_CNT_LO (if_num)) - ddr_clocks; + calc_ddr_hertz = ddr_clocks * cpu_hertz / core_clocks; + } + +debug ("core clocks: %llu, ddr clocks: %llu, calc rate: %llu\n" , + core_clocks, ddr_clocks, calc_ddr_hertz); +debug ("LMC%d: Measured DDR clock: %lld, cpu clock: %u, ddr clocks: %llu\n" , + if_num, calc_ddr_hertz, cpu_hertz, ddr_clocks); + +/* Check for unreasonable settings. */ +if (calc_ddr_hertz <10000 ) { +udelay (8000000 *100 ); +printf ("DDR clock misconfigured on interface %d. Resetting...\n" , + if_num); +do_reset (NULL ,0 ,0 ,NULL ); + } + +return calc_ddr_hertz; +} + +u64 lmc_ddr3_rl_dbg_read (struct ddr_priv *priv,int if_num,int idx) +{ +union cvmx_lmcx_rlevel_dbg rlevel_dbg; +union cvmx_lmcx_rlevel_ctl rlevel_ctl; + + rlevel_ctl.u64 =lmc_rd (priv,CVMX_LMCX_RLEVEL_CTL (if_num)); + rlevel_ctl.s.byte = idx; + +lmc_wr (priv,CVMX_LMCX_RLEVEL_CTL (if_num), rlevel_ctl.u64); +lmc_rd (priv,CVMX_LMCX_RLEVEL_CTL (if_num)); + + rlevel_dbg.u64 =lmc_rd (priv,CVMX_LMCX_RLEVEL_DBG (if_num)); +return rlevel_dbg.s.bitmask; +} + +u64 lmc_ddr3_wl_dbg_read (struct ddr_priv *priv,int if_num,int idx) +{ +union cvmx_lmcx_wlevel_dbg wlevel_dbg; + + wlevel_dbg.u64 =0 ; + wlevel_dbg.s.byte = idx; + +lmc_wr (priv,CVMX_LMCX_WLEVEL_DBG (if_num), wlevel_dbg.u64); +lmc_rd (priv,CVMX_LMCX_WLEVEL_DBG (if_num)); + + wlevel_dbg.u64 =lmc_rd (priv,CVMX_LMCX_WLEVEL_DBG (if_num)); +return wlevel_dbg.s.bitmask; +} + +int validate_ddr3_rlevel_bitmask (struct rlevel_bitmask *rlevel_bitmask_p, +int ddr_type) +{ +int i; +int errors =0 ; +u64 mask =0 ;/* Used in 64-bit comparisons */ +u8 mstart =0 ; +u8 width =0 ; +u8 firstbit =0 ; +u8 lastbit =0 ; +u8 bubble =0 ; +u8 tbubble =0 ; +u8 blank =0 ; +u8 narrow =0 ; +u8 trailing =0 ; +u64 bitmask = rlevel_bitmask_p->bm; +u8 extras =0 ; +u8 toolong =0 ; +u64 temp; + +if (bitmask ==0 ) { + blank +=RLEVEL_BITMASK_BLANK_ERROR ; + }else { +/* Look for fb, the first bit */ + temp = bitmask; +while (!(temp &1 )) { + firstbit++; + temp >>=1 ; + } + +/* Look for lb, the last bit */ + lastbit = firstbit; +while ((temp >>=1 )) + lastbit++; + +/* +* Start with the max range to try to find the largest mask +* within the bitmask data +*/ + width =MASKRANGE_BITS ; +for (mask =MASKRANGE ; mask >0 ; mask >>=1 , --width) { +for (mstart = lastbit - width +1 ; mstart >= firstbit; + --mstart) { + temp = mask << mstart; +if ((bitmask & temp) == temp) + goto done_now; + } + } +done_now: +/* look for any more contiguous 1's to the right of mstart */ +if (width ==MASKRANGE_BITS ) {// only when maximum mask +while ((bitmask >> (mstart -1 )) &1 ) { +// slide right over more 1's + --mstart; +// count the number of extra bits only for DDR4 +if (ddr_type ==DDR4_DRAM ) + extras++; + } + } + +/* Penalize any extra 1's beyond the maximum desired mask */ +if (extras >0 ) + toolong = +RLEVEL_BITMASK_TOOLONG_ERROR * ((1 << extras) -1 ); + +/* Detect if bitmask is too narrow. */ +if (width <4 ) + narrow = (4 - width) *RLEVEL_BITMASK_NARROW_ERROR ; + +/* +* detect leading bubble bits, that is, any 0's between first +* and mstart +*/ + temp = bitmask >> (firstbit +1 ); + i = mstart - firstbit -1 ; +while (--i >=0 ) { +if ((temp &1 ) ==0 ) + bubble +=RLEVEL_BITMASK_BUBBLE_BITS_ERROR ; + temp >>=1 ; + } + + temp = bitmask >> (mstart + width + extras); + i = lastbit - (mstart + width + extras -1 ); +while (--i >=0 ) { +if (temp &1 ) { +/* +* Detect 1 bits after the trailing end of +* the mask, including last. +*/ + trailing +=RLEVEL_BITMASK_TRAILING_BITS_ERROR ; + }else { +/* +* Detect trailing bubble bits, that is, +* any 0's between end-of-mask and last +*/ + tbubble +=RLEVEL_BITMASK_BUBBLE_BITS_ERROR ; + } + temp >>=1 ; + } + } + + errors = bubble + tbubble + blank + narrow + trailing + toolong; + +/* Pass out useful statistics */ + rlevel_bitmask_p->mstart = mstart; + rlevel_bitmask_p->width = width; + +debug_bitmask_print ("bm:%08lx mask:%02lx, width:%2u, mstart:%2d, fb:%2u, lb:%2u (bu:%2d, tb:%2d, bl:%2d, n:%2d, t:%2d, x:%2d) errors:%3d %s\n" , + (unsigned long )bitmask, mask, width, mstart, + firstbit, lastbit, bubble, tbubble, blank, + narrow, trailing, toolong, errors, + (errors) ?"=> invalid" :"" ); + +return errors; +} + +int compute_ddr3_rlevel_delay (u8 mstart,u8 width, +union cvmx_lmcx_rlevel_ctl rlevel_ctl) +{ +int delay; + +debug_bitmask_print (" offset_en:%d" , rlevel_ctl.s.offset_en); + +if (rlevel_ctl.s.offset_en) { + delay =max ((int )mstart, + (int )(mstart + width -1 - rlevel_ctl.s.offset)); + }else { +/* if (rlevel_ctl.s.offset) { *//* Experimental */ +if (0 ) { + delay =max (mstart + rlevel_ctl.s.offset, mstart +1 ); +/* +* Insure that the offset delay falls within the +* bitmask +*/ + delay =min (delay, mstart + width -1 ); + }else { +/* Round down */ + delay = (width -1 ) /2 + mstart; + } + } + +return delay; +} + +/* Default ODT config must disable ODT */ +/* Must be const (read only) so that the structure is in flash */ +const struct dimm_odt_config disable_odt_config[] = { +/* 1 */ {0 ,0x0000 , {.u64 =0x0000 }, {.u64 =0x0000 },0 ,0x0000 ,0 }, +/* 2 */ {0 ,0x0000 , {.u64 =0x0000 }, {.u64 =0x0000 },0 ,0x0000 ,0 }, +/* 3 */ {0 ,0x0000 , {.u64 =0x0000 }, {.u64 =0x0000 },0 ,0x0000 ,0 }, +/* 4 */ {0 ,0x0000 , {.u64 =0x0000 }, {.u64 =0x0000 },0 ,0x0000 ,0 }, +}; + +/* Memory controller setup function */ +static int init_octeon_dram_interface (struct ddr_priv *priv, +struct ddr_conf *ddr_conf, +u32 ddr_hertz,u32 cpu_hertz, +u32 ddr_ref_hertz,int if_num, +u32 if_mask) +{ +u32 mem_size_mbytes =0 ; +char *s; + + s =lookup_env (priv,"ddr_timing_hertz" ); +if (s) + ddr_hertz =simple_strtoul (s,NULL ,0 ); + +if (OCTEON_IS_OCTEON3 ()) { +int lmc_restart_retries =0 ; +#define DEFAULT_RESTART_RETRIES 3 +int lmc_restart_retries_limit =DEFAULT_RESTART_RETRIES ; + + s =lookup_env (priv,"ddr_restart_retries_limit" ); +if (s) + lmc_restart_retries_limit =simple_strtoul (s,NULL ,0 ); + +restart_lmc_init: + mem_size_mbytes =init_octeon3_ddr3_interface (priv, ddr_conf, + ddr_hertz, + cpu_hertz, + ddr_ref_hertz, + if_num, if_mask); +if (mem_size_mbytes ==0 ) {// 0 means restart is possible +if (lmc_restart_retries < lmc_restart_retries_limit) { + lmc_restart_retries++; +printf ("N0.LMC%d Configuration problem: attempting LMC reset and init restart %d\n" , + if_num, lmc_restart_retries); + goto restart_lmc_init; + }else { +if (lmc_restart_retries_limit >0 ) { +printf ("INFO: N0.LMC%d Configuration: fatal problem remains after %d LMC init retries - Resetting node...\n" , + if_num, lmc_restart_retries); +mdelay (500 ); +do_reset (NULL ,0 ,0 ,NULL ); + }else { +// return an error, no restart + mem_size_mbytes =-1 ; + } + } + } + } + +debug ("N0.LMC%d Configuration Completed: %d MB\n" , + if_num, mem_size_mbytes); + +return mem_size_mbytes; +} + +#define WLEVEL_BYTE_BITS 5 +#define WLEVEL_BYTE_MSK ((1ULL << 5) - 1) + +void upd_wl_rank (union cvmx_lmcx_wlevel_rankx *lmc_wlevel_rank, +int byte,int delay) +{ +union cvmx_lmcx_wlevel_rankx temp_wlevel_rank; + +if (byte >=0 && byte <=8 ) { + temp_wlevel_rank.u64 = lmc_wlevel_rank->u64; + temp_wlevel_rank.u64 &= + ~(WLEVEL_BYTE_MSK << (WLEVEL_BYTE_BITS * byte)); + temp_wlevel_rank.u64 |= + ((delay &WLEVEL_BYTE_MSK ) << (WLEVEL_BYTE_BITS * byte)); + lmc_wlevel_rank->u64 = temp_wlevel_rank.u64; + } +} + +int get_wl_rank (union cvmx_lmcx_wlevel_rankx *lmc_wlevel_rank,int byte) +{ +int delay =0 ; + +if (byte >=0 && byte <=8 ) + delay = + ((lmc_wlevel_rank->u64) >> (WLEVEL_BYTE_BITS * + byte)) &WLEVEL_BYTE_MSK ; + +return delay; +} + +void upd_rl_rank (union cvmx_lmcx_rlevel_rankx *lmc_rlevel_rank, +int byte,int delay) +{ +union cvmx_lmcx_rlevel_rankx temp_rlevel_rank; + +if (byte >=0 && byte <=8 ) { + temp_rlevel_rank.u64 = + lmc_rlevel_rank->u64 & ~(RLEVEL_BYTE_MSK << + (RLEVEL_BYTE_BITS * byte)); + temp_rlevel_rank.u64 |= + ((delay &RLEVEL_BYTE_MSK ) << (RLEVEL_BYTE_BITS * byte)); + lmc_rlevel_rank->u64 = temp_rlevel_rank.u64; + } +} + +int get_rl_rank (union cvmx_lmcx_rlevel_rankx *lmc_rlevel_rank,int byte) +{ +int delay =0 ; + +if (byte >=0 && byte <=8 ) + delay = + ((lmc_rlevel_rank->u64) >> (RLEVEL_BYTE_BITS * + byte)) &RLEVEL_BYTE_MSK ; + +return delay; +} + +void rlevel_to_wlevel (union cvmx_lmcx_rlevel_rankx *lmc_rlevel_rank, +union cvmx_lmcx_wlevel_rankx *lmc_wlevel_rank,int byte) +{ +int byte_delay =get_rl_rank (lmc_rlevel_rank, byte); + +debug ("Estimating Wlevel delay byte %d: " , byte); +debug ("Rlevel=%d => " , byte_delay); + byte_delay =divide_roundup (byte_delay,2 ) &0x1e ; +debug ("Wlevel=%d\n" , byte_delay); +upd_wl_rank (lmc_wlevel_rank, byte, byte_delay); +} + +/* Delay trend: constant=0, decreasing=-1, increasing=1 */ +static s64 calc_delay_trend (s64 v) +{ +if (v ==0 ) +return 0 ; +if (v <0 ) +return -1 ; + +return 1 ; +} + +/* +* Evaluate delay sequence across the whole range of byte delays while +* keeping track of the overall delay trend, increasing or decreasing. +* If the trend changes charge an error amount to the score. +*/ + +// NOTE: "max_adj_delay_inc" argument is, by default, 1 for DDR3 and 2 for DDR4 + +int nonseq_del (struct rlevel_byte_data *rlevel_byte,int start,int end, +int max_adj_delay_inc) +{ +s64 error =0 ; +s64 delay_trend, prev_trend =0 ; +int byte_idx; +s64 seq_err; +s64 adj_err; +s64 delay_inc; +s64 delay_diff; + +for (byte_idx = start; byte_idx < end; ++byte_idx) { + delay_diff = rlevel_byte[byte_idx +1 ].delay - + rlevel_byte[byte_idx].delay; + delay_trend =calc_delay_trend (delay_diff); + +/* +* Increment error each time the trend changes to the +* opposite direction. +*/ +if (prev_trend !=0 && delay_trend !=0 && + prev_trend != delay_trend) { + seq_err =RLEVEL_NONSEQUENTIAL_DELAY_ERROR ; + }else { + seq_err =0 ; + } + +// how big was the delay change, if any + delay_inc =abs (delay_diff); + +/* +* Even if the trend did not change to the opposite direction, +* check for the magnitude of the change, and scale the +* penalty by the amount that the size is larger than the +* provided limit. +*/ +if (max_adj_delay_inc !=0 && delay_inc > max_adj_delay_inc) { + adj_err = (delay_inc - max_adj_delay_inc) * +RLEVEL_ADJACENT_DELAY_ERROR ; + }else { + adj_err =0 ; + } + + rlevel_byte[byte_idx +1 ].sqerrs = seq_err + adj_err; + error += seq_err + adj_err; + +debug_bitmask_print ("Byte %d: %d, Byte %d: %d, delay_trend: %ld, prev_trend: %ld, [%ld/%ld]%s%s\n" , + byte_idx +0 , + rlevel_byte[byte_idx +0 ].delay, + byte_idx +1 , + rlevel_byte[byte_idx +1 ].delay, + delay_trend, + prev_trend, seq_err, adj_err, + (seq_err) ? +" => Nonsequential byte delay" :"" , + (adj_err) ? +" => Adjacent delay error" :"" ); + +if (delay_trend !=0 ) + prev_trend = delay_trend; + } + +return (int )error; +} + +int roundup_ddr3_wlevel_bitmask (int bitmask) +{ +int shifted_bitmask; +int leader; +int delay; + +for (leader =0 ; leader <8 ; ++leader) { + shifted_bitmask = (bitmask >> leader); +if ((shifted_bitmask &1 ) ==0 ) +break ; + } + +for (leader = leader; leader <16 ; ++leader) { + shifted_bitmask = (bitmask >> (leader %8 )); +if (shifted_bitmask &1 ) +break ; + } + + delay = (leader &1 ) ? leader +1 : leader; + delay = delay %8 ; + +return delay; +} + +/* Octeon 2 */ +static void oct2_ddr3_seq (struct ddr_priv *priv,int rank_mask,int if_num, +int sequence) +{ +char *s; + +#ifdef DEBUG_PERFORM_DDR3_SEQUENCE +static const char *const sequence_str[] = { +"power-up/init" , +"read-leveling" , +"self-refresh entry" , +"self-refresh exit" , +"precharge power-down entry" , +"precharge power-down exit" , +"write-leveling" , +"illegal" + }; +#endif + +union cvmx_lmcx_control lmc_control; +union cvmx_lmcx_config lmc_config; +int save_ddr2t; + + lmc_control.u64 =lmc_rd (priv,CVMX_LMCX_CONTROL (if_num)); + save_ddr2t = lmc_control.s.ddr2t; + +if (save_ddr2t ==0 &&octeon_is_cpuid (OCTEON_CN63XX_PASS1_X )) { +/* Some register parts (IDT and TI included) do not like +* the sequence that LMC generates for an MRS register +* write in 1T mode. In this case, the register part does +* not properly forward the MRS register write to the DRAM +* parts. See errata (LMC-14548) Issues with registered +* DIMMs. +*/ +debug ("Forcing DDR 2T during init seq. Re: Pass 1 LMC-14548\n" ); + lmc_control.s.ddr2t =1 ; + } + + s =lookup_env (priv,"ddr_init_2t" ); +if (s) + lmc_control.s.ddr2t =simple_strtoul (s,NULL ,0 ); + +lmc_wr (priv,CVMX_LMCX_CONTROL (if_num), lmc_control.u64); + + lmc_config.u64 =lmc_rd (priv,CVMX_LMCX_CONFIG (if_num)); + + lmc_config.s.init_start =1 ; +if (OCTEON_IS_OCTEON2 ()) + lmc_config.cn63xx.sequence = sequence; + lmc_config.s.rankmask = rank_mask; + +#ifdef DEBUG_PERFORM_DDR3_SEQUENCE +debug ("Performing LMC sequence: rank_mask=0x%02x, sequence=%d, %s\n" , + rank_mask, sequence, sequence_str[sequence]); +#endif + +lmc_wr (priv,CVMX_LMCX_CONFIG (if_num), lmc_config.u64); +lmc_rd (priv,CVMX_LMCX_CONFIG (if_num)); +udelay (600 );/* Wait a while */ + + lmc_control.s.ddr2t = save_ddr2t; +lmc_wr (priv,CVMX_LMCX_CONTROL (if_num), lmc_control.u64); +lmc_rd (priv,CVMX_LMCX_CONTROL (if_num)); +} + +/* Check to see if any custom offset values are used */ +static int is_dll_offset_provided (const int8_t *dll_offset_table) +{ +int i; + +if (!dll_offset_table)/* Check for pointer to table. */ +return 0 ; + +for (i =0 ; i <9 ; ++i) { +if (dll_offset_table[i] !=0 ) +return 1 ; + } + +return 0 ; +} + +void change_dll_offset_enable (struct ddr_priv *priv,int if_num,int change) +{ +union cvmx_lmcx_dll_ctl3 ddr_dll_ctl3; + + ddr_dll_ctl3.u64 =lmc_rd (priv,CVMX_LMCX_DLL_CTL3 (if_num)); +SET_DDR_DLL_CTL3 (offset_ena, !!change); +lmc_wr (priv,CVMX_LMCX_DLL_CTL3 (if_num), ddr_dll_ctl3.u64); + ddr_dll_ctl3.u64 =lmc_rd (priv,CVMX_LMCX_DLL_CTL3 (if_num)); +} + +unsigned short load_dll_offset (struct ddr_priv *priv,int if_num, +int dll_offset_mode,int byte_offset,int byte) +{ +union cvmx_lmcx_dll_ctl3 ddr_dll_ctl3; +int field_width =6 ; +/* +* byte_sel: +* 0x1 = byte 0, ..., 0x9 = byte 8 +* 0xA = all bytes +*/ +int byte_sel = (byte ==10 ) ? byte : byte +1 ; + +if (octeon_is_cpuid (OCTEON_CN6XXX )) + field_width =5 ; + + ddr_dll_ctl3.u64 =lmc_rd (priv,CVMX_LMCX_DLL_CTL3 (if_num)); +SET_DDR_DLL_CTL3 (load_offset,0 ); +lmc_wr (priv,CVMX_LMCX_DLL_CTL3 (if_num), ddr_dll_ctl3.u64); + ddr_dll_ctl3.u64 =lmc_rd (priv,CVMX_LMCX_DLL_CTL3 (if_num)); + +SET_DDR_DLL_CTL3 (mode_sel, dll_offset_mode); +SET_DDR_DLL_CTL3 (offset, + (abs (byte_offset) & (~(-1 << field_width))) | + (_sign (byte_offset) << field_width)); +SET_DDR_DLL_CTL3 (byte_sel, byte_sel); +lmc_wr (priv,CVMX_LMCX_DLL_CTL3 (if_num), ddr_dll_ctl3.u64); + ddr_dll_ctl3.u64 =lmc_rd (priv,CVMX_LMCX_DLL_CTL3 (if_num)); + +SET_DDR_DLL_CTL3 (load_offset,1 ); +lmc_wr (priv,CVMX_LMCX_DLL_CTL3 (if_num), ddr_dll_ctl3.u64); + ddr_dll_ctl3.u64 =lmc_rd (priv,CVMX_LMCX_DLL_CTL3 (if_num)); + +return (unsigned short )GET_DDR_DLL_CTL3 (offset); +} + +void process_custom_dll_offsets (struct ddr_priv *priv,int if_num, +const char *enable_str, +const int8_t *offsets,const char *byte_str, +int mode) +{ +const char *s; +int enabled; +int provided; +int byte_offset; +unsigned short offset[9 ] = {0 }; +int byte; + + s =lookup_env (priv, enable_str); +if (s) + enabled = !!simple_strtol (s,NULL ,0 ); +else + enabled =-1 ; + +/* +* enabled == -1: no override, do only configured offsets if provided +* enabled == 0: override OFF, do NOT do it even if configured +* offsets provided +* enabled == 1: override ON, do it for overrides plus configured +* offsets +*/ + +if (enabled ==0 ) +return ; + + provided =is_dll_offset_provided (offsets); + +if (enabled <0 && !provided) +return ; + +change_dll_offset_enable (priv, if_num,0 ); + +for (byte =0 ; byte <9 ; ++byte) { +// always take the provided, if available + byte_offset = (provided) ? offsets[byte] :0 ; + +// then, if enabled, use any overrides present +if (enabled >0 ) { + s =lookup_env (priv, byte_str, if_num, byte); +if (s) + byte_offset =simple_strtol (s,NULL ,0 ); + } + + offset[byte] = +load_dll_offset (priv, if_num, mode, byte_offset, byte); + } + +change_dll_offset_enable (priv, if_num,1 ); + +debug ("N0.LMC%d: DLL %s Offset 8:0 : 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n" , + if_num, (mode ==2 ) ?"Read " :"Write" , + offset[8 ], offset[7 ], offset[6 ], offset[5 ], offset[4 ], + offset[3 ], offset[2 ], offset[1 ], offset[0 ]); +} + +void ddr_init_seq (struct ddr_priv *priv,int rank_mask,int if_num) +{ +char *s; +int ddr_init_loops =1 ; +int rankx; + + s =lookup_env (priv,"ddr%d_init_loops" , if_num); +if (s) + ddr_init_loops =simple_strtoul (s,NULL ,0 ); + +while (ddr_init_loops--) { +for (rankx =0 ; rankx <8 ; rankx++) { +if (!(rank_mask & (1 << rankx))) +continue ; + +if (OCTEON_IS_OCTEON3 ()) { +/* power-up/init */ +oct3_ddr3_seq (priv,1 << rankx, if_num,0 ); + }else { +/* power-up/init */ +oct2_ddr3_seq (priv,1 << rankx, if_num,0 ); + } + +udelay (1000 );/* Wait a while. */ + + s =lookup_env (priv,"ddr_sequence1" ); +if (s) { +int sequence1; + + sequence1 =simple_strtoul (s,NULL ,0 ); + +if (OCTEON_IS_OCTEON3 ()) { +oct3_ddr3_seq (priv,1 << rankx, + if_num, sequence1); + }else { +oct2_ddr3_seq (priv,1 << rankx, + if_num, sequence1); + } + } + + s =lookup_env (priv,"ddr_sequence2" ); +if (s) { +int sequence2; + + sequence2 =simple_strtoul (s,NULL ,0 ); + +if (OCTEON_IS_OCTEON3 ()) +oct3_ddr3_seq (priv,1 << rankx, + if_num, sequence2); +else +oct2_ddr3_seq (priv,1 << rankx, + if_num, sequence2); + } + } + } +} + +static int octeon_ddr_initialize (struct ddr_priv *priv,u32 cpu_hertz, +u32 ddr_hertz,u32 ddr_ref_hertz, +u32 if_mask, +struct ddr_conf *ddr_conf, +u32 *measured_ddr_hertz) +{ +u32 ddr_conf_valid_mask =0 ; +int memsize_mbytes =0 ; +char *eptr; +int if_idx; +u32 ddr_max_speed =667000000 ; +u32 calc_ddr_hertz =-1 ; +int val; +int ret; + +if (env_get ("ddr_verbose" ) ||env_get ("ddr_prompt" )) + priv->flags |=FLAG_DDR_VERBOSE ; + +#ifdef DDR_VERBOSE + priv->flags |=FLAG_DDR_VERBOSE ; +#endif + +if (env_get ("ddr_trace_init" )) { +printf ("Parameter ddr_trace_init found in environment.\n" ); + priv->flags |=FLAG_DDR_TRACE_INIT ; + priv->flags |=FLAG_DDR_VERBOSE ; + } + + priv->flags |=FLAG_DDR_DEBUG ; + + val =env_get_ulong ("ddr_debug" ,10 , (u32)-1 ); +switch (val) { +case 0 : + priv->flags &= ~FLAG_DDR_DEBUG ; +printf ("Parameter ddr_debug clear in environment\n" ); +break ; +case (u32)-1 : +break ; +default : +printf ("Parameter ddr_debug set in environment\n" ); + priv->flags |=FLAG_DDR_DEBUG ; + priv->flags |=FLAG_DDR_VERBOSE ; +break ; + } +if (env_get ("ddr_prompt" )) + priv->flags |=FLAG_DDR_PROMPT ; + +/* Force ddr_verbose for failsafe debugger */ +if (priv->flags &FLAG_FAILSAFE_MODE ) + priv->flags |=FLAG_DDR_VERBOSE ; + +#ifdef DDR_DEBUG + priv->flags |=FLAG_DDR_DEBUG ; +/* Keep verbose on while we are still debugging. */ + priv->flags |=FLAG_DDR_VERBOSE ; +#endif + +if ((octeon_is_cpuid (OCTEON_CN61XX ) || +octeon_is_cpuid (OCTEON_CNF71XX )) && ddr_max_speed >533333333 ) { + ddr_max_speed =533333333 ; + }else if (octeon_is_cpuid (OCTEON_CN7XXX )) { +/* Override speed restrictions to support internal testing. */ + ddr_max_speed =1210000000 ; + } + +if (ddr_hertz > ddr_max_speed) { +printf ("DDR clock speed %u exceeds maximum supported DDR speed, reducing to %uHz\n" , + ddr_hertz, ddr_max_speed); + ddr_hertz = ddr_max_speed; + } + +if (OCTEON_IS_OCTEON3 ()) {// restrict check +if (ddr_hertz > cpu_hertz) { +printf ("\nFATAL ERROR: DDR speed %u exceeds CPU speed %u, exiting...\n\n" , + ddr_hertz, cpu_hertz); +return -1 ; + } + } + +/* Enable L2 ECC */ + eptr =env_get ("disable_l2_ecc" ); +if (eptr) { +printf ("Disabling L2 ECC based on disable_l2_ecc environment variable\n" ); +union cvmx_l2c_ctl l2c_val; + + l2c_val.u64 =l2c_rd (priv,CVMX_L2C_CTL ); + l2c_val.s.disecc =1 ; +l2c_wr (priv,CVMX_L2C_CTL , l2c_val.u64); + }else { +union cvmx_l2c_ctl l2c_val; + + l2c_val.u64 =l2c_rd (priv,CVMX_L2C_CTL ); + l2c_val.s.disecc =0 ; +l2c_wr (priv,CVMX_L2C_CTL , l2c_val.u64); + } + +/* +* Init the L2C, must be done before DRAM access so that we +* know L2 is empty +*/ + eptr =env_get ("disable_l2_index_aliasing" ); +if (eptr) { +union cvmx_l2c_ctl l2c_val; + +puts ("L2 index aliasing disabled.\n" ); + + l2c_val.u64 =l2c_rd (priv,CVMX_L2C_CTL ); + l2c_val.s.disidxalias =1 ; +l2c_wr (priv,CVMX_L2C_CTL , l2c_val.u64); + }else { +union cvmx_l2c_ctl l2c_val; + +/* Enable L2C index aliasing */ + + l2c_val.u64 =l2c_rd (priv,CVMX_L2C_CTL ); + l2c_val.s.disidxalias =0 ; +l2c_wr (priv,CVMX_L2C_CTL , l2c_val.u64); + } + +if (OCTEON_IS_OCTEON3 ()) { +/* +* rdf_cnt: Defines the sample point of the LMC response data in +* the DDR-clock/core-clock crossing. For optimal +* performance set to 10 * (DDR-clock period/core-clock +* period) - 1. To disable set to 0. All other values +* are reserved. +*/ + +union cvmx_l2c_ctl l2c_ctl; +u64 rdf_cnt; +char *s; + + l2c_ctl.u64 =l2c_rd (priv,CVMX_L2C_CTL ); + +/* +* It is more convenient to compute the ratio using clock +* frequencies rather than clock periods. +*/ + rdf_cnt = (((u64 )10 * cpu_hertz) / ddr_hertz) -1 ; + rdf_cnt = rdf_cnt <256 ? rdf_cnt :255 ; + l2c_ctl.cn78xx.rdf_cnt = rdf_cnt; + + s =lookup_env (priv,"early_fill_count" ); +if (s) + l2c_ctl.cn78xx.rdf_cnt =simple_strtoul (s,NULL ,0 ); + +debug ("%-45s : %d, cpu_hertz:%d, ddr_hertz:%d\n" , +"EARLY FILL COUNT " , l2c_ctl.cn78xx.rdf_cnt, cpu_hertz, + ddr_hertz); +l2c_wr (priv,CVMX_L2C_CTL , l2c_ctl.u64); + } + +/* Check for lower DIMM socket populated */ +for (if_idx =0 ; if_idx <4 ; ++if_idx) { +if ((if_mask & (1 << if_idx)) && +validate_dimm (priv, + &ddr_conf[(int )if_idx].dimm_config_table[0 ], +0 )) + ddr_conf_valid_mask |= (1 << if_idx); + } + +if (octeon_is_cpuid (OCTEON_CN68XX ) ||octeon_is_cpuid (OCTEON_CN78XX )) { +int four_lmc_mode =1 ; +char *s; + +if (priv->flags &FLAG_FAILSAFE_MODE ) + four_lmc_mode =0 ; + +/* Pass 1.0 disable four LMC mode. +* See errata (LMC-15811) +*/ +if (octeon_is_cpuid (OCTEON_CN68XX_PASS1_0 )) + four_lmc_mode =0 ; + + s =env_get ("ddr_four_lmc" ); +if (s) { + four_lmc_mode =simple_strtoul (s,NULL ,0 ); +printf ("Parameter found in environment. ddr_four_lmc = %d\n" , + four_lmc_mode); + } + +if (!four_lmc_mode) { +puts ("Forcing two-LMC Mode.\n" ); +/* Invalidate LMC[2:3] */ + ddr_conf_valid_mask &= ~(3 <<2 ); + } + }else if (octeon_is_cpuid (OCTEON_CN73XX )) { +int one_lmc_mode =0 ; +char *s; + + s =env_get ("ddr_one_lmc" ); +if (s) { + one_lmc_mode =simple_strtoul (s,NULL ,0 ); +printf ("Parameter found in environment. ddr_one_lmc = %d\n" , + one_lmc_mode); + } + +if (one_lmc_mode) { +puts ("Forcing one-LMC Mode.\n" ); +/* Invalidate LMC[1:3] */ + ddr_conf_valid_mask &= ~(1 <<1 ); + } + } + +if (!ddr_conf_valid_mask) { +printf + ("ERROR: No valid DIMMs detected on any DDR interface.\n" ); +hang (); +return -1 ;// testr-only: no ret negativ!!! + } + +/* +* We measure the DDR frequency by counting DDR clocks. We can +* confirm or adjust the expected frequency as necessary. We use +* the measured frequency to make accurate timing calculations +* used to configure the controller. +*/ +for (if_idx =0 ; if_idx <4 ; ++if_idx) { +u32 tmp_hertz; + +if (!(ddr_conf_valid_mask & (1 << if_idx))) +continue ; + +try_again: +/* +* only check for alternate refclk wanted on chips that +* support it +*/ +if ((octeon_is_cpuid (OCTEON_CN73XX )) || + (octeon_is_cpuid (OCTEON_CNF75XX )) || + (octeon_is_cpuid (OCTEON_CN78XX_PASS2_X ))) { +// only need do this if we are LMC0 +if (if_idx ==0 ) { +union cvmx_lmcx_ddr_pll_ctl ddr_pll_ctl; + + ddr_pll_ctl.u64 = +lmc_rd (priv,CVMX_LMCX_DDR_PLL_CTL (0 )); + +/* +* If we are asking for 100 MHz refclk, we can +* only get it via alternate, so switch to it +*/ +if (ddr_ref_hertz ==100000000 ) { + ddr_pll_ctl.cn78xx.dclk_alt_refclk_sel = +1 ; +lmc_wr (priv,CVMX_LMCX_DDR_PLL_CTL (0 ), + ddr_pll_ctl.u64); +udelay (1000 );// wait 1 msec + }else { +/* +* If we are NOT asking for 100MHz, +* then reset to (assumed) 50MHz and go +* on +*/ + ddr_pll_ctl.cn78xx.dclk_alt_refclk_sel = +0 ; +lmc_wr (priv,CVMX_LMCX_DDR_PLL_CTL (0 ), + ddr_pll_ctl.u64); +udelay (1000 );// wait 1 msec + } + } + }else { +if (ddr_ref_hertz ==100000000 ) { +debug ("N0: DRAM init: requested 100 MHz refclk NOT SUPPORTED\n" ); + ddr_ref_hertz =CONFIG_REF_HERTZ ; + } + } + + tmp_hertz =measure_octeon_ddr_clock (priv, &ddr_conf[if_idx], + cpu_hertz, ddr_hertz, + ddr_ref_hertz, if_idx, + ddr_conf_valid_mask); + +/* +* only check for alternate refclk acquired on chips that +* support it +*/ +if ((octeon_is_cpuid (OCTEON_CN73XX )) || + (octeon_is_cpuid (OCTEON_CNF75XX )) || + (octeon_is_cpuid (OCTEON_CN78XX_PASS2_X ))) { +/* +* if we are LMC0 and we are asked for 100 MHz refclk, +* we must be sure it is available +* If not, we print an error message, set to 50MHz, +* and go on... +*/ +if (if_idx ==0 && ddr_ref_hertz ==100000000 ) { +/* +* Validate that the clock returned is close +* enough to the clock desired +*/ +// FIXME: is 5% close enough? +int hertz_diff = +abs ((int )tmp_hertz - (int )ddr_hertz); +if (hertz_diff > ((int )ddr_hertz *5 /100 )) { +// nope, diff is greater than than 5% +debug ("N0: DRAM init: requested 100 MHz refclk NOT FOUND\n" ); + ddr_ref_hertz =CONFIG_REF_HERTZ ; +// clear the flag before trying again!! +set_ddr_clock_initialized (priv,0 ,0 ); + goto try_again; + }else { +debug ("N0: DRAM Init: requested 100 MHz refclk FOUND and SELECTED\n" ); + } + } + } + +if (tmp_hertz >0 ) + calc_ddr_hertz = tmp_hertz; +debug ("LMC%d: measured speed: %u hz\n" , if_idx, tmp_hertz); + } + +if (measured_ddr_hertz) + *measured_ddr_hertz = calc_ddr_hertz; + + memsize_mbytes =0 ; +for (if_idx =0 ; if_idx <4 ; ++if_idx) { +if (!(ddr_conf_valid_mask & (1 << if_idx))) +continue ; + + ret =init_octeon_dram_interface (priv, &ddr_conf[if_idx], + calc_ddr_hertz, + cpu_hertz, ddr_ref_hertz, + if_idx, ddr_conf_valid_mask); +if (ret >0 ) + memsize_mbytes += ret; + } + +if (memsize_mbytes ==0 ) +/* All interfaces failed to initialize, so return error */ +return -1 ; + +/* +* switch over to DBI mode only for chips that support it, and +* enabled by envvar +*/ +if ((octeon_is_cpuid (OCTEON_CN73XX )) || + (octeon_is_cpuid (OCTEON_CNF75XX )) || + (octeon_is_cpuid (OCTEON_CN78XX_PASS2_X ))) { + eptr =env_get ("ddr_dbi_switchover" ); +if (eptr) { +printf ("DBI Switchover starting...\n" ); +cvmx_dbi_switchover (priv); +printf ("DBI Switchover finished.\n" ); + } + } + +/* call HW-assist tuning here on chips that support it */ +if ((octeon_is_cpuid (OCTEON_CN73XX )) || + (octeon_is_cpuid (OCTEON_CNF75XX )) || + (octeon_is_cpuid (OCTEON_CN78XX_PASS2_X ))) +cvmx_maybe_tune_node (priv, calc_ddr_hertz); + + eptr =env_get ("limit_dram_mbytes" ); +if (eptr) { +unsigned int mbytes =simple_strtoul (eptr,NULL ,10 ); + +if (mbytes >0 ) { + memsize_mbytes = mbytes; +printf ("Limiting DRAM size to %d MBytes based on limit_dram_mbytes env. variable\n" , + mbytes); + } + } + +debug ("LMC Initialization complete. Total DRAM %d MB\n" , + memsize_mbytes); + +return memsize_mbytes; +} + +static int octeon_ddr_probe (struct udevice *dev) +{ +struct ddr_priv *priv =dev_get_priv (dev); +struct ofnode_phandle_args l2c_node; +struct ddr_conf *ddr_conf_ptr; +u32 ddr_conf_valid_mask =0 ; +u32 measured_ddr_hertz =0 ; +int conf_table_count; +int def_ddr_freq; +u32 mem_mbytes =0 ; +u32 ddr_hertz; +u32 ddr_ref_hertz; +int alt_refclk; +const char *eptr; +fdt_addr_t addr; +u64 *ptr; +u64 val; +int ret; +int i; + +/* Don't try to re-init the DDR controller after relocation */ +if (gd->flags &GD_FLG_RELOC ) +return 0 ; + +/* +* Dummy read all local variables into cache, so that they are +* locked in cache when the DDR code runs with flushes etc enabled +*/ + ptr = (u64 *)_end; +for (i =0 ; i < (0x100000 /sizeof (u64)); i++) + val =readq (ptr++); + +/* +* The base addresses of LMC and L2C are read from the DT. This +* makes it possible to use the DDR init code without the need +* of the "node" variable, describing on which node to access. The +* node number is already included implicitly in the base addresses +* read from the DT this way. +*/ + +/* Get LMC base address */ + priv->lmc_base =dev_remap_addr (dev); +debug ("%s: lmc_base=%p\n" , __func__, priv->lmc_base); + +/* Get L2C base address */ + ret =dev_read_phandle_with_args (dev,"l2c-handle" ,NULL ,0 ,0 , + &l2c_node); +if (ret) { +printf ("Can't access L2C node!\n" ); +return -ENODEV ; + } + + addr =ofnode_get_addr (l2c_node.node); +if (addr ==FDT_ADDR_T_NONE ) { +printf ("Can't access L2C node!\n" ); +return -ENODEV ; + } + + priv->l2c_base =map_physmem (addr,0 ,MAP_NOCACHE ); +debug ("%s: l2c_base=%p\n" , __func__, priv->l2c_base); + + ddr_conf_ptr =octeon_ddr_conf_table_get (&conf_table_count, + &def_ddr_freq); +if (!ddr_conf_ptr) { +printf ("ERROR: unable to determine DDR configuration\n" ); +return -ENODEV ; + } + +for (i =0 ; i < conf_table_count; i++) { +if (ddr_conf_ptr[i].dimm_config_table[0 ].spd_addrs[0 ] || + ddr_conf_ptr[i].dimm_config_table[0 ].spd_ptrs[0 ]) + ddr_conf_valid_mask |=1 << i; + } + +/* +* Check for special case of mismarked 3005 samples, +* and adjust cpuid +*/ + alt_refclk =0 ; + ddr_hertz = def_ddr_freq *1000000 ; + + eptr =env_get ("ddr_clock_hertz" ); +if (eptr) { + ddr_hertz =simple_strtoul (eptr,NULL ,0 ); + gd->mem_clk =divide_nint (ddr_hertz,1000000 ); +printf ("Parameter found in environment. ddr_clock_hertz = %d\n" , + ddr_hertz); + } + + ddr_ref_hertz =octeon3_refclock (alt_refclk, + ddr_hertz, + &ddr_conf_ptr[0 ].dimm_config_table[0 ]); + +debug ("Initializing DDR, clock = %uhz, reference = %uhz\n" , + ddr_hertz, ddr_ref_hertz); + + mem_mbytes =octeon_ddr_initialize (priv, gd->cpu_clk, + ddr_hertz, ddr_ref_hertz, + ddr_conf_valid_mask, + ddr_conf_ptr, &measured_ddr_hertz); +debug ("Mem size in MBYTES: %u\n" , mem_mbytes); + + gd->mem_clk =divide_nint (measured_ddr_hertz,1000000 ); + +debug ("Measured DDR clock %d Hz\n" , measured_ddr_hertz); + +if (measured_ddr_hertz !=0 ) { +if (!gd->mem_clk) { +/* +* If ddr_clock not set, use measured clock +* and don't warn +*/ + gd->mem_clk =divide_nint (measured_ddr_hertz,1000000 ); + }else if ((measured_ddr_hertz > ddr_hertz +3000000 ) || + (measured_ddr_hertz < ddr_hertz -3000000 )) { +printf ("\nWARNING:\n" ); +printf ("WARNING: Measured DDR clock mismatch! expected: %lld MHz, measured: %lldMHz, cpu clock: %lu MHz\n" , +divide_nint (ddr_hertz,1000000 ), +divide_nint (measured_ddr_hertz,1000000 ), + gd->cpu_clk); +printf ("WARNING:\n\n" ); + gd->mem_clk =divide_nint (measured_ddr_hertz,1000000 ); + } + } + +if (!mem_mbytes) +return -ENODEV ; + + priv->info.base =CONFIG_SYS_SDRAM_BASE ; + priv->info.size =MB (mem_mbytes); + +/* +* For 6XXX generate a proper error when reading/writing +* non-existent memory locations. +*/ +cvmx_l2c_set_big_size (priv, mem_mbytes,0 ); + +debug ("Ram size %uMiB\n" , mem_mbytes); + +return 0 ; +} + +static int octeon_get_info (struct udevice *dev,struct ram_info *info) +{ +struct ddr_priv *priv =dev_get_priv (dev); + + *info = priv->info; + +return 0 ; +} + +static struct ram_ops octeon_ops = { + .get_info = octeon_get_info, +}; + +static const struct udevice_id octeon_ids[] = { + {.compatible ="cavium,octeon-7xxx-ddr4" }, + { } +}; + +U_BOOT_DRIVER (octeon_ddr) = { + .name ="octeon_ddr" , + .id =UCLASS_RAM , + .of_match = octeon_ids, + .ops = &octeon_ops, + .probe = octeon_ddr_probe, + .platdata_auto_alloc_size =sizeof (struct ddr_priv ), +};
Signature · 1 line
2.28.0
PATCH v3 6/9 ram: octeon: Add MIPS Octeon3 DDR4 support (part 2/3)
In reply to Stefan RoeseFrom: Aaron Williams <[email protected]>
This Octeon 3 DDR driver is ported from the 2013 Cavium / Marvell U-Boot repository. It currently supports DDR4 on Octeon 3. It can be later extended to support also DDR3 and Octeon 2 platforms.
Part 2 includes the very complex Octeon 3 DDR4 configuration
---
Changes in v3:
- Remove all internal defines that resulted in dead code, as they have never been changed via external config files or Kconfig. This results in a smaller (~13KiB of source code saved, > 450 lines removed) and much cleaner code base.
- Remove "https://spdx.org/licenses" line
drivers/ram/octeon/octeon3_lmc.c | 11030 +++++++++++++++++++++++++++++ 1 file changed, 11030 insertions(+) create mode 100644 drivers/ram/octeon/octeon3_lmc.c
drivers/ram/octeon/octeon3_lmc.c new file +11030 -0
@@ -0,0 +1,11030 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2020 Marvell International Ltd. +*/ + +#include <command.h> +#include <dm.h> +#include <hang.h> +#include <i2c.h> +#include <ram.h> +#include <time.h> + +#include <linux/bitops.h> +#include <linux/io.h> + +#include <mach/octeon_ddr.h> + +/* Random number generator stuff */ + +#define CVMX_RNM_CTL_STATUS 0x0001180040000000 +#define CVMX_OCT_DID_RNG 8ULL + +static u64 cvmx_build_io_address (u64 major_did,u64 sub_did) +{ +return ((0x1ull <<48 ) | (major_did <<43 ) | (sub_did <<40 )); +} + +static u64 cvmx_rng_get_random64 (void ) +{ +return csr_rd (cvmx_build_io_address (CVMX_OCT_DID_RNG ,0 )); +} + +static void cvmx_rng_enable (void ) +{ +u64 val; + + val =csr_rd (CVMX_RNM_CTL_STATUS ); + val |=BIT (0 ) |BIT (1 ); +csr_wr (CVMX_RNM_CTL_STATUS , val); +} + +#define RLEVEL_PRINTALL_DEFAULT 1 +#define WLEVEL_PRINTALL_DEFAULT 1 + +/* +* Define how many HW WL samples to take for majority voting. +* MUST BE odd!! +* Assume there should only be 2 possible values that will show up, +* so treat ties as a problem!!! +* NOTE: Do not change this without checking the code!!! +*/ +#define WLEVEL_LOOPS_DEFAULT 5 + +#define ENABLE_COMPUTED_VREF_ADJUSTMENT 1 +#define SW_WLEVEL_HW_DEFAULT 1 +#define DEFAULT_BEST_RANK_SCORE 9999999 +#define MAX_RANK_SCORE_LIMIT 99 + +/* +* Define how many HW RL samples per rank to take multiple samples will +* allow looking for the best sample score +*/ +#define RLEVEL_SAMPLES_DEFAULT 3 + +#define ddr_seq_print (format, ...) do {} while (0) + +struct wlevel_bitcnt { +int bitcnt[4 ]; +}; + +static void display_dac_dbi_settings (int lmc,int dac_or_dbi, +int ecc_ena,int *settings,char *title); + +static unsigned short load_dac_override (struct ddr_priv *priv,int if_num, +int dac_value,int byte); + +/* "mode" arg */ +#define DBTRAIN_TEST 0 +#define DBTRAIN_DBI 1 +#define DBTRAIN_LFSR 2 + +static int run_best_hw_patterns (struct ddr_priv *priv,int lmc,u64 phys_addr, +int mode,u64 *xor_data); + +#define LMC_DDR3_RESET_ASSERT 0 +#define LMC_DDR3_RESET_DEASSERT 1 + +static void cn7xxx_lmc_ddr3_reset (struct ddr_priv *priv,int if_num,int reset) +{ +union cvmx_lmcx_reset_ctl reset_ctl; + +/* +* 4. Deassert DDRn_RESET_L pin by writing +* LMC(0..3)_RESET_CTL[DDR3RST] = 1 +* without modifying any other LMC(0..3)_RESET_CTL fields. +* 5. Read LMC(0..3)_RESET_CTL and wait for the result. +* 6. Wait a minimum of 500us. This guarantees the necessary T = 500us +* delay between DDRn_RESET_L deassertion and DDRn_DIMM*_CKE* +* assertion. +*/ +debug ("LMC%d %s DDR_RESET_L\n" , if_num, + (reset == +LMC_DDR3_RESET_DEASSERT ) ?"De-asserting" :"Asserting" ); + + reset_ctl.u64 =lmc_rd (priv,CVMX_LMCX_RESET_CTL (if_num)); + reset_ctl.cn78xx.ddr3rst = reset; +lmc_wr (priv,CVMX_LMCX_RESET_CTL (if_num), reset_ctl.u64); + +lmc_rd (priv,CVMX_LMCX_RESET_CTL (if_num)); + +udelay (500 ); +} + +static void perform_lmc_reset (struct ddr_priv *priv,int node,int if_num) +{ +/* +* 5.9.6 LMC RESET Initialization +* +* The purpose of this step is to assert/deassert the RESET# pin at the +* DDR3/DDR4 parts. +* +* This LMC RESET step is done for all enabled LMCs. +* +* It may be appropriate to skip this step if the DDR3/DDR4 DRAM parts +* are in self refresh and are currently preserving their +* contents. (Software can determine this via +* LMC(0..3)_RESET_CTL[DDR3PSV] in some circumstances.) The remainder of +* this section assumes that the DRAM contents need not be preserved. +* +* The remainder of this section assumes that the CN78XX DDRn_RESET_L +* pin is attached to the RESET# pin of the attached DDR3/DDR4 parts, +* as will be appropriate in many systems. +* +* (In other systems, such as ones that can preserve DDR3/DDR4 part +* contents while CN78XX is powered down, it will not be appropriate to +* directly attach the CN78XX DDRn_RESET_L pin to DRESET# of the +* DDR3/DDR4 parts, and this section may not apply.) +* +* The remainder of this section describes the sequence for LMCn. +* +* Perform the following six substeps for LMC reset initialization: +* +* 1. If not done already, assert DDRn_RESET_L pin by writing +* LMC(0..3)_RESET_ CTL[DDR3RST] = 0 without modifying any other +* LMC(0..3)_RESET_CTL fields. +*/ + +if (!ddr_memory_preserved (priv)) { +/* +* 2. Read LMC(0..3)_RESET_CTL and wait for the result. +*/ + +lmc_rd (priv,CVMX_LMCX_RESET_CTL (if_num)); + +/* +* 3. Wait until RESET# assertion-time requirement from JEDEC +* DDR3/DDR4 specification is satisfied (200 us during a +* power-on ramp, 100ns when power is already stable). +*/ + +udelay (200 ); + +/* +* 4. Deassert DDRn_RESET_L pin by writing +* LMC(0..3)_RESET_CTL[DDR3RST] = 1 +* without modifying any other LMC(0..3)_RESET_CTL fields. +* 5. Read LMC(0..3)_RESET_CTL and wait for the result. +* 6. Wait a minimum of 500us. This guarantees the necessary +* T = 500us delay between DDRn_RESET_L deassertion and +* DDRn_DIMM*_CKE* assertion. +*/ +cn7xxx_lmc_ddr3_reset (priv, if_num,LMC_DDR3_RESET_DEASSERT ); + +/* Toggle Reset Again */ +/* That is, assert, then de-assert, one more time */ +cn7xxx_lmc_ddr3_reset (priv, if_num,LMC_DDR3_RESET_ASSERT ); +cn7xxx_lmc_ddr3_reset (priv, if_num,LMC_DDR3_RESET_DEASSERT ); + } +} + +void oct3_ddr3_seq (struct ddr_priv *priv,int rank_mask,int if_num, +int sequence) +{ +/* +* 3. Without changing any other fields in LMC(0)_CONFIG, write +* LMC(0)_CONFIG[RANKMASK] then write both +* LMC(0)_SEQ_CTL[SEQ_SEL,INIT_START] = 1 with a single CSR write +* operation. LMC(0)_CONFIG[RANKMASK] bits should be set to indicate +* the ranks that will participate in the sequence. +* +* The LMC(0)_SEQ_CTL[SEQ_SEL] value should select power-up/init or +* selfrefresh exit, depending on whether the DRAM parts are in +* self-refresh and whether their contents should be preserved. While +* LMC performs these sequences, it will not perform any other DDR3 +* transactions. When the sequence is complete, hardware sets the +* LMC(0)_CONFIG[INIT_STATUS] bits for the ranks that have been +* initialized. +* +* If power-up/init is selected immediately following a DRESET +* assertion, LMC executes the sequence described in the "Reset and +* Initialization Procedure" section of the JEDEC DDR3 +* specification. This includes activating CKE, writing all four DDR3 +* mode registers on all selected ranks, and issuing the required +* ZQCL +* command. The LMC(0)_CONFIG[RANKMASK] value should select all ranks +* with attached DRAM in this case. If LMC(0)_CONTROL[RDIMM_ENA] = 1, +* LMC writes the JEDEC standard SSTE32882 control words selected by +* LMC(0)_DIMM_CTL[DIMM*_WMASK] between DDR_CKE* signal assertion and +* the first DDR3 mode register write operation. +* LMC(0)_DIMM_CTL[DIMM*_WMASK] should be cleared to 0 if the +* corresponding DIMM is not present. +* +* If self-refresh exit is selected, LMC executes the required SRX +* command followed by a refresh and ZQ calibration. Section 4.5 +* describes behavior of a REF + ZQCS. LMC does not write the DDR3 +* mode registers as part of this sequence, and the mode register +* parameters must match at self-refresh entry and exit times. +* +* 4. Read LMC(0)_SEQ_CTL and wait for LMC(0)_SEQ_CTL[SEQ_COMPLETE] +* to be set. +* +* 5. Read LMC(0)_CONFIG[INIT_STATUS] and confirm that all ranks have +* been initialized. +*/ + +union cvmx_lmcx_seq_ctl seq_ctl; +union cvmx_lmcx_config lmc_config; +int timeout; + + lmc_config.u64 =lmc_rd (priv,CVMX_LMCX_CONFIG (if_num)); + lmc_config.s.rankmask = rank_mask; +lmc_wr (priv,CVMX_LMCX_CONFIG (if_num), lmc_config.u64); + + seq_ctl.u64 =0 ; + + seq_ctl.s.init_start =1 ; + seq_ctl.s.seq_sel = sequence; + +ddr_seq_print + ("Performing LMC sequence: rank_mask=0x%02x, sequence=0x%x, %s\n" , + rank_mask, sequence, sequence_str[sequence]); + +if (seq_ctl.s.seq_sel ==3 ) +debug ("LMC%d: Exiting Self-refresh Rank_mask:%x\n" , if_num, + rank_mask); + +lmc_wr (priv,CVMX_LMCX_SEQ_CTL (if_num), seq_ctl.u64); +lmc_rd (priv,CVMX_LMCX_SEQ_CTL (if_num)); + + timeout =100 ; +do { +udelay (100 );/* Wait a while */ + seq_ctl.u64 =lmc_rd (priv,CVMX_LMCX_SEQ_CTL (if_num)); +if (--timeout ==0 ) { +printf ("Sequence %d timed out\n" , sequence); +break ; + } + }while (seq_ctl.s.seq_complete !=1 ); + +ddr_seq_print (" LMC sequence=%x: Completed.\n" , sequence); +} + +#define bdk_numa_get_address (n, p) ((p) | ((u64)n) << CVMX_NODE_MEM_SHIFT) +#define AREA_BASE_OFFSET BIT_ULL(26) + +static int test_dram_byte64 (struct ddr_priv *priv,int lmc,u64 p, +u64 bitmask,u64 *xor_data) +{ +u64 p1, p2, d1, d2; +u64 v, v1; +u64 p2offset = (1ULL <<26 );// offset to area 2 +u64 datamask; +u64 xor; +u64 i, j, k; +u64 ii; +int errors =0 ; +//u64 index; +u64 pattern1 =cvmx_rng_get_random64 (); +u64 pattern2 =0 ; +u64 bad_bits[2 ] = {0 ,0 }; +int kbitno = (octeon_is_cpuid (OCTEON_CN7XXX )) ?20 :18 ; +union cvmx_l2c_ctl l2c_ctl; +int burst; +int saved_dissblkdty; +int node =0 ; + +// Force full cacheline write-backs to boost traffic + l2c_ctl.u64 =l2c_rd (priv,CVMX_L2C_CTL ); + saved_dissblkdty = l2c_ctl.cn78xx.dissblkdty; + l2c_ctl.cn78xx.dissblkdty =1 ; +l2c_wr (priv,CVMX_L2C_CTL , l2c_ctl.u64); + +if (octeon_is_cpuid (OCTEON_CN73XX ) ||octeon_is_cpuid (OCTEON_CNF75XX )) + kbitno =18 ; + +// Byte lanes may be clear in the mask to indicate no testing on that +//lane. + datamask = bitmask; + +/* +* Add offset to both test regions to not clobber boot stuff +* when running from L2 for NAND boot. +*/ + p +=AREA_BASE_OFFSET ;// make sure base is out of the way of boot + +// final address must include LMC and node + p |= (lmc <<7 );/* Map address into proper interface */ + p =bdk_numa_get_address (node, p);/* Map to node */ + p |=1ull <<63 ; + +#define II_INC BIT_ULL(22) +#define II_MAX BIT_ULL(22) +#define K_INC BIT_ULL(14) +#define K_MAX BIT_ULL(kbitno) +#define J_INC BIT_ULL(9) +#define J_MAX BIT_ULL(12) +#define I_INC BIT_ULL(3) +#define I_MAX BIT_ULL(7) + +debug ("N%d.LMC%d: %s: phys_addr=0x%llx/0x%llx (0x%llx)\n" , + node, lmc, __func__, p, p + p2offset,1ULL << kbitno); + +// loops are ordered so that only a single 64-bit slot is written to +// each cacheline at one time, then the cachelines are forced out; +// this should maximize read/write traffic + +// FIXME? extend the range of memory tested!! +for (ii =0 ; ii <II_MAX ; ii +=II_INC ) { +for (i =0 ; i <I_MAX ; i +=I_INC ) { +for (k =0 ; k <K_MAX ; k +=K_INC ) { +for (j =0 ; j <J_MAX ; j +=J_INC ) { + p1 = p + ii + k + j; + p2 = p1 + p2offset; + + v = pattern1 * (p1 + i); +// write the same thing to both areas + v1 = v; + +cvmx_write64_uint64 (p1 + i, v); +cvmx_write64_uint64 (p2 + i, v1); + +CVMX_CACHE_WBIL2 (p1,0 ); +CVMX_CACHE_WBIL2 (p2,0 ); + } + } + } + } + +CVMX_DCACHE_INVALIDATE ; + +debug ("N%d.LMC%d: dram_tuning_mem_xor: done INIT loop\n" , node, lmc); + +/* Make a series of passes over the memory areas. */ + +for (burst =0 ; burst <1 /* was: dram_tune_use_bursts */ ; burst++) { +u64 this_pattern =cvmx_rng_get_random64 (); + + pattern2 ^= this_pattern; + +/* +* XOR the data with a random value, applying the change to both +* memory areas. +*/ + +// FIXME? extend the range of memory tested!! +for (ii =0 ; ii <II_MAX ; ii +=II_INC ) { +// FIXME: rearranged, did not make much difference? +for (i =0 ; i <I_MAX ; i +=I_INC ) { +for (k =0 ; k <K_MAX ; k +=K_INC ) { +for (j =0 ; j <J_MAX ; j +=J_INC ) { + p1 = p + ii + k + j; + p2 = p1 + p2offset; + + v =cvmx_read64_uint64 (p1 + + i) ^ + this_pattern; + v1 =cvmx_read64_uint64 (p2 + + i) ^ + this_pattern; + +cvmx_write64_uint64 (p1 + i, v); +cvmx_write64_uint64 (p2 + i, v1); + +CVMX_CACHE_WBIL2 (p1,0 ); +CVMX_CACHE_WBIL2 (p2,0 ); + } + } + } + } + +CVMX_DCACHE_INVALIDATE ; + +debug ("N%d.LMC%d: dram_tuning_mem_xor: done MODIFY loop\n" , + node, lmc); + +/* +* Look for differences in the areas. If there is a mismatch, +* reset both memory locations with the same pattern. Failing +* to do so means that on all subsequent passes the pair of +* locations remain out of sync giving spurious errors. +*/ + +// FIXME: Change the loop order so that an entire cache line +// is compared at one time. This is so that a read +// error that occurs *anywhere* on the cacheline will +// be caught, rather than comparing only 1 cacheline +// slot@a time, where an error on a different +// slot will be missed that time around +// Does the above make sense? + +// FIXME? extend the range of memory tested!! +for (ii =0 ; ii <II_MAX ; ii +=II_INC ) { +for (k =0 ; k <K_MAX ; k +=K_INC ) { +for (j =0 ; j <J_MAX ; j +=J_INC ) { + p1 = p + ii + k + j; + p2 = p1 + p2offset; + +// process entire cachelines in the +//innermost loop +for (i =0 ; i <I_MAX ; i +=I_INC ) { +int bybit =1 ; +// start in byte lane 0 +u64 bymsk =0xffULL ; + +// FIXME: this should predict +// what we find...??? + v = ((p1 + i) * pattern1) ^ + pattern2; + d1 =cvmx_read64_uint64 (p1 + i); + d2 =cvmx_read64_uint64 (p2 + i); + +// union of error bits only in +// active byte lanes + xor = ((d1 ^ v) | (d2 ^ v)) & + datamask; + +if (!xor) +continue ; + +// accumulate bad bits + bad_bits[0 ] |= xor; + +while (xor !=0 ) { +debug ("ERROR(%03d): [0x%016llX] [0x%016llX] expected 0x%016llX d1 %016llX d2 %016llX\n" , + burst, p1, p2, v, + d1, d2); +// error(s) in this lane +if (xor & bymsk) { +// set the byte +// error bit + errors |= bybit; +// clear byte +// lane in +// error bits + xor &= ~bymsk; +// clear the +// byte lane in +// the mask + datamask &= ~bymsk; +#if EXIT_WHEN_ALL_LANES_HAVE_ERRORS +// nothing +// left to do +if (datamask ==0 ) { +return errors; + } +#endif /* EXIT_WHEN_ALL_LANES_HAVE_ERRORS */ + } +// move mask into +// next byte lane + bymsk <<=8 ; +// move bit into next +// byte position + bybit <<=1 ; + } + } +CVMX_CACHE_WBIL2 (p1,0 ); +CVMX_CACHE_WBIL2 (p2,0 ); + } + } + } + +debug ("N%d.LMC%d: dram_tuning_mem_xor: done TEST loop\n" , + node, lmc); + } + +if (xor_data) {// send the bad bits back... + xor_data[0 ] = bad_bits[0 ]; + xor_data[1 ] = bad_bits[1 ];// let it be zeroed + } + +// Restore original setting that could enable partial cacheline writes + l2c_ctl.u64 =l2c_rd (priv,CVMX_L2C_CTL ); + l2c_ctl.cn78xx.dissblkdty = saved_dissblkdty; +l2c_wr (priv,CVMX_L2C_CTL , l2c_ctl.u64); + +return errors; +} + +static void ddr4_mrw (struct ddr_priv *priv,int if_num,int rank, +int mr_wr_addr,int mr_wr_sel,int mr_wr_bg1) +{ +union cvmx_lmcx_mr_mpr_ctl lmc_mr_mpr_ctl; + + lmc_mr_mpr_ctl.u64 =0 ; + lmc_mr_mpr_ctl.cn78xx.mr_wr_addr = (mr_wr_addr ==-1 ) ?0 : mr_wr_addr; + lmc_mr_mpr_ctl.cn78xx.mr_wr_sel = mr_wr_sel; + lmc_mr_mpr_ctl.cn78xx.mr_wr_rank = rank; + lmc_mr_mpr_ctl.cn78xx.mr_wr_use_default_value = + (mr_wr_addr ==-1 ) ?1 :0 ; + lmc_mr_mpr_ctl.cn78xx.mr_wr_bg1 = mr_wr_bg1; +lmc_wr (priv,CVMX_LMCX_MR_MPR_CTL (if_num), lmc_mr_mpr_ctl.u64); + +/* Mode Register Write */ +oct3_ddr3_seq (priv,1 << rank, if_num,0x8 ); +} + +#define INV_A0_17 (x) ((x) ^ 0x22bf8) + +static void set_mpr_mode (struct ddr_priv *priv,int rank_mask, +int if_num,int dimm_count,int mpr,int bg1) +{ +int rankx; + +debug ("All Ranks: Set mpr mode = %x %c-side\n" , + mpr, (bg1 ==0 ) ?'A' :'B' ); + +for (rankx =0 ; rankx < dimm_count *4 ; rankx++) { +if (!(rank_mask & (1 << rankx))) +continue ; +if (bg1 ==0 ) { +/* MR3 A-side */ +ddr4_mrw (priv, if_num, rankx, mpr <<2 ,3 , bg1); + }else { +/* MR3 B-side */ +ddr4_mrw (priv, if_num, rankx,INV_A0_17 (mpr <<2 ), ~3 , + bg1); + } + } +} + +static void do_ddr4_mpr_read (struct ddr_priv *priv,int if_num, +int rank,int page,int location) +{ +union cvmx_lmcx_mr_mpr_ctl lmc_mr_mpr_ctl; + + lmc_mr_mpr_ctl.u64 =lmc_rd (priv,CVMX_LMCX_MR_MPR_CTL (if_num)); + lmc_mr_mpr_ctl.cn70xx.mr_wr_addr =0 ; + lmc_mr_mpr_ctl.cn70xx.mr_wr_sel = page;/* Page */ + lmc_mr_mpr_ctl.cn70xx.mr_wr_rank = rank; + lmc_mr_mpr_ctl.cn70xx.mpr_loc = location; + lmc_mr_mpr_ctl.cn70xx.mpr_wr =0 ;/* Read=0, Write=1 */ +lmc_wr (priv,CVMX_LMCX_MR_MPR_CTL (if_num), lmc_mr_mpr_ctl.u64); + +/* MPR register access sequence */ +oct3_ddr3_seq (priv,1 << rank, if_num,0x9 ); + +debug ("LMC_MR_MPR_CTL : 0x%016llx\n" , + lmc_mr_mpr_ctl.u64); +debug ("lmc_mr_mpr_ctl.cn70xx.mr_wr_addr: 0x%02x\n" , + lmc_mr_mpr_ctl.cn70xx.mr_wr_addr); +debug ("lmc_mr_mpr_ctl.cn70xx.mr_wr_sel : 0x%02x\n" , + lmc_mr_mpr_ctl.cn70xx.mr_wr_sel); +debug ("lmc_mr_mpr_ctl.cn70xx.mpr_loc : 0x%02x\n" , + lmc_mr_mpr_ctl.cn70xx.mpr_loc); +debug ("lmc_mr_mpr_ctl.cn70xx.mpr_wr : 0x%02x\n" , + lmc_mr_mpr_ctl.cn70xx.mpr_wr); +} + +static int set_rdimm_mode (struct ddr_priv *priv,int if_num,int enable) +{ +union cvmx_lmcx_control lmc_control; +int save_rdimm_mode; + + lmc_control.u64 =lmc_rd (priv,CVMX_LMCX_CONTROL (if_num)); + save_rdimm_mode = lmc_control.s.rdimm_ena; + lmc_control.s.rdimm_ena = enable; +debug ("Setting RDIMM_ENA = %x\n" , enable); +lmc_wr (priv,CVMX_LMCX_CONTROL (if_num), lmc_control.u64); + +return save_rdimm_mode; +} + +static void ddr4_mpr_read (struct ddr_priv *priv,int if_num,int rank, +int page,int location,u64 *mpr_data) +{ +do_ddr4_mpr_read (priv, if_num, rank, page, location); + + mpr_data[0 ] =lmc_rd (priv,CVMX_LMCX_MPR_DATA0 (if_num)); +} + +/* Display MPR values for Page */ +static void display_mpr_page (struct ddr_priv *priv,int rank_mask, +int if_num,int page) +{ +int rankx, location; +u64 mpr_data[3 ]; + +for (rankx =0 ; rankx <4 ; rankx++) { +if (!(rank_mask & (1 << rankx))) +continue ; + +debug ("N0.LMC%d.R%d: MPR Page %d loc [0:3]: " , + if_num, rankx, page); +for (location =0 ; location <4 ; location++) { +ddr4_mpr_read (priv, if_num, rankx, page, location, + mpr_data); +debug ("0x%02llx " , mpr_data[0 ] &0xFF ); + } +debug ("\n" ); + + }/* for (rankx = 0; rankx < 4; rankx++) */ +} + +static void ddr4_mpr_write (struct ddr_priv *priv,int if_num,int rank, +int page,int location,u8 mpr_data) +{ +union cvmx_lmcx_mr_mpr_ctl lmc_mr_mpr_ctl; + + lmc_mr_mpr_ctl.u64 =0 ; + lmc_mr_mpr_ctl.cn70xx.mr_wr_addr = mpr_data; + lmc_mr_mpr_ctl.cn70xx.mr_wr_sel = page;/* Page */ + lmc_mr_mpr_ctl.cn70xx.mr_wr_rank = rank; + lmc_mr_mpr_ctl.cn70xx.mpr_loc = location; + lmc_mr_mpr_ctl.cn70xx.mpr_wr =1 ;/* Read=0, Write=1 */ +lmc_wr (priv,CVMX_LMCX_MR_MPR_CTL (if_num), lmc_mr_mpr_ctl.u64); + +/* MPR register access sequence */ +oct3_ddr3_seq (priv,1 << rank, if_num,0x9 ); + +debug ("LMC_MR_MPR_CTL : 0x%016llx\n" , + lmc_mr_mpr_ctl.u64); +debug ("lmc_mr_mpr_ctl.cn70xx.mr_wr_addr: 0x%02x\n" , + lmc_mr_mpr_ctl.cn70xx.mr_wr_addr); +debug ("lmc_mr_mpr_ctl.cn70xx.mr_wr_sel : 0x%02x\n" , + lmc_mr_mpr_ctl.cn70xx.mr_wr_sel); +debug ("lmc_mr_mpr_ctl.cn70xx.mpr_loc : 0x%02x\n" , + lmc_mr_mpr_ctl.cn70xx.mpr_loc); +debug ("lmc_mr_mpr_ctl.cn70xx.mpr_wr : 0x%02x\n" , + lmc_mr_mpr_ctl.cn70xx.mpr_wr); +} + +static void set_vref (struct ddr_priv *priv,int if_num,int rank, +int range,int value) +{ +union cvmx_lmcx_mr_mpr_ctl lmc_mr_mpr_ctl; +union cvmx_lmcx_modereg_params3 lmc_modereg_params3; +int mr_wr_addr =0 ; + + lmc_mr_mpr_ctl.u64 =0 ; + lmc_modereg_params3.u64 =lmc_rd (priv, +CVMX_LMCX_MODEREG_PARAMS3 (if_num)); + +/* A12:A10 tCCD_L */ + mr_wr_addr |= lmc_modereg_params3.s.tccd_l <<10 ; + mr_wr_addr |=1 <<7 ;/* A7 1 = Enable(Training Mode) */ + mr_wr_addr |= range <<6 ;/* A6 vrefDQ Training Range */ + mr_wr_addr |= value <<0 ;/* A5:A0 vrefDQ Training Value */ + + lmc_mr_mpr_ctl.cn70xx.mr_wr_addr = mr_wr_addr; + lmc_mr_mpr_ctl.cn70xx.mr_wr_sel =6 ;/* Write MR6 */ + lmc_mr_mpr_ctl.cn70xx.mr_wr_rank = rank; +lmc_wr (priv,CVMX_LMCX_MR_MPR_CTL (if_num), lmc_mr_mpr_ctl.u64); + +/* 0x8 = Mode Register Write */ +oct3_ddr3_seq (priv,1 << rank, if_num,0x8 ); + +/* +* It is vendor specific whether vref_value is captured with A7=1. +* A subsequent MRS might be necessary. +*/ +oct3_ddr3_seq (priv,1 << rank, if_num,0x8 ); + + mr_wr_addr &= ~(1 <<7 );/* A7 0 = Disable(Training Mode) */ + lmc_mr_mpr_ctl.cn70xx.mr_wr_addr = mr_wr_addr; +lmc_wr (priv,CVMX_LMCX_MR_MPR_CTL (if_num), lmc_mr_mpr_ctl.u64); +} + +static void set_dram_output_inversion (struct ddr_priv *priv,int if_num, +int dimm_count,int rank_mask, +int inversion) +{ +union cvmx_lmcx_ddr4_dimm_ctl lmc_ddr4_dimm_ctl; +union cvmx_lmcx_dimmx_params lmc_dimmx_params; +union cvmx_lmcx_dimm_ctl lmc_dimm_ctl; +int dimm_no; + +/* Don't touch extenced register control words */ + lmc_ddr4_dimm_ctl.u64 =0 ; +lmc_wr (priv,CVMX_LMCX_DDR4_DIMM_CTL (if_num), lmc_ddr4_dimm_ctl.u64); + +debug ("All DIMMs: Register Control Word RC0 : %x\n" , + (inversion &1 )); + +for (dimm_no =0 ; dimm_no < dimm_count; ++dimm_no) { + lmc_dimmx_params.u64 = +lmc_rd (priv,CVMX_LMCX_DIMMX_PARAMS (dimm_no, if_num)); + lmc_dimmx_params.s.rc0 = + (lmc_dimmx_params.s.rc0 & ~1 ) | (inversion &1 ); + +lmc_wr (priv, +CVMX_LMCX_DIMMX_PARAMS (dimm_no, if_num), + lmc_dimmx_params.u64); + } + +/* LMC0_DIMM_CTL */ + lmc_dimm_ctl.u64 =lmc_rd (priv,CVMX_LMCX_DIMM_CTL (if_num)); + lmc_dimm_ctl.s.dimm0_wmask =0x1 ; + lmc_dimm_ctl.s.dimm1_wmask = (dimm_count >1 ) ?0x0001 :0x0000 ; + +debug ("LMC DIMM_CTL : 0x%016llx\n" , + lmc_dimm_ctl.u64); +lmc_wr (priv,CVMX_LMCX_DIMM_CTL (if_num), lmc_dimm_ctl.u64); + +oct3_ddr3_seq (priv, rank_mask, if_num,0x7 );/* Init RCW */ +} + +static void write_mpr_page0_pattern (struct ddr_priv *priv,int rank_mask, +int if_num,int dimm_count,int pattern, +int location_mask) +{ +int rankx; +int location; + +for (rankx =0 ; rankx < dimm_count *4 ; rankx++) { +if (!(rank_mask & (1 << rankx))) +continue ; +for (location =0 ; location <4 ; ++location) { +if (!(location_mask & (1 << location))) +continue ; + +ddr4_mpr_write (priv, if_num, rankx, +/* page */ 0 ,/* location */ location, + pattern); + } + } +} + +static void change_rdimm_mpr_pattern (struct ddr_priv *priv,int rank_mask, +int if_num,int dimm_count) +{ +int save_ref_zqcs_int; +union cvmx_lmcx_config lmc_config; + +/* +* Okay, here is the latest sequence. This should work for all +* chips and passes (78,88,73,etc). This sequence should be run +* immediately after DRAM INIT. The basic idea is to write the +* same pattern into each of the 4 MPR locations in the DRAM, so +* that the same value is returned when doing MPR reads regardless +* of the inversion state. My advice is to put this into a +* function, change_rdimm_mpr_pattern or something like that, so +* that it can be called multiple times, as I think David wants a +* clock-like pattern for OFFSET training, but does not want a +* clock pattern for Bit-Deskew. You should then be able to call +* this at any point in the init sequence (after DRAM init) to +* change the pattern to a new value. +* Mike +* +* A correction: PHY doesn't need any pattern during offset +* training, but needs clock like pattern for internal vref and +* bit-dskew training. So for that reason, these steps below have +* to be conducted before those trainings to pre-condition +* the pattern. David +* +* Note: Step 3, 4, 8 and 9 have to be done through RDIMM +* sequence. If you issue MRW sequence to do RCW write (in o78 pass +* 1@least), LMC will still do two commands because +* CONTROL[RDIMM_ENA] is still set high. We don't want it to have +* any unintentional mode register write so it's best to do what +* Mike is doing here. +* Andrew +*/ + +/* 1) Disable refresh (REF_ZQCS_INT = 0) */ + +debug ("1) Disable refresh (REF_ZQCS_INT = 0)\n" ); + + lmc_config.u64 =lmc_rd (priv,CVMX_LMCX_CONFIG (if_num)); + save_ref_zqcs_int = lmc_config.cn78xx.ref_zqcs_int; + lmc_config.cn78xx.ref_zqcs_int =0 ; +lmc_wr (priv,CVMX_LMCX_CONFIG (if_num), lmc_config.u64); + +/* +* 2) Put all devices in MPR mode (Run MRW sequence (sequence=8) +* with MODEREG_PARAMS0[MPRLOC]=0, +* MODEREG_PARAMS0[MPR]=1, MR_MPR_CTL[MR_WR_SEL]=3, and +* MR_MPR_CTL[MR_WR_USE_DEFAULT_VALUE]=1) +*/ + +debug ("2) Put all devices in MPR mode (Run MRW sequence (sequence=8)\n" ); + +/* A-side */ +set_mpr_mode (priv, rank_mask, if_num, dimm_count,1 ,0 ); +/* B-side */ +set_mpr_mode (priv, rank_mask, if_num, dimm_count,1 ,1 ); + +/* +* a. Or you can set MR_MPR_CTL[MR_WR_USE_DEFAULT_VALUE]=0 and set +* the value you would like directly into +* MR_MPR_CTL[MR_WR_ADDR] +*/ + +/* +* 3) Disable RCD Parity (if previously enabled) - parity does not +* work if inversion disabled +*/ + +debug ("3) Disable RCD Parity\n" ); + +/* +* 4) Disable Inversion in the RCD. +* a. I did (3&4) via the RDIMM sequence (seq_sel=7), but it +* may be easier to use the MRW sequence (seq_sel=8). Just set +* MR_MPR_CTL[MR_WR_SEL]=7, MR_MPR_CTL[MR_WR_ADDR][3:0]=data, +* MR_MPR_CTL[MR_WR_ADDR][7:4]=RCD reg +*/ + +debug ("4) Disable Inversion in the RCD.\n" ); + +set_dram_output_inversion (priv, if_num, dimm_count, rank_mask,1 ); + +/* +* 5) Disable CONTROL[RDIMM_ENA] so that MR sequence goes out +* non-inverted. +*/ + +debug ("5) Disable CONTROL[RDIMM_ENA]\n" ); + +set_rdimm_mode (priv, if_num,0 ); + +/* +* 6) Write all 4 MPR registers with the desired pattern (have to +* do this for all enabled ranks) +* a. MR_MPR_CTL.MPR_WR=1, MR_MPR_CTL.MPR_LOC=0..3, +* MR_MPR_CTL.MR_WR_SEL=0, MR_MPR_CTL.MR_WR_ADDR[7:0]=pattern +*/ + +debug ("6) Write all 4 MPR page 0 Training Patterns\n" ); + +write_mpr_page0_pattern (priv, rank_mask, if_num, dimm_count,0x55 ,0x8 ); + +/* 7) Re-enable RDIMM_ENA */ + +debug ("7) Re-enable RDIMM_ENA\n" ); + +set_rdimm_mode (priv, if_num,1 ); + +/* 8) Re-enable RDIMM inversion */ + +debug ("8) Re-enable RDIMM inversion\n" ); + +set_dram_output_inversion (priv, if_num, dimm_count, rank_mask,0 ); + +/* 9) Re-enable RDIMM parity (if desired) */ + +debug ("9) Re-enable RDIMM parity (if desired)\n" ); + +/* +* 10)Take B-side devices out of MPR mode (Run MRW sequence +* (sequence=8) with MODEREG_PARAMS0[MPRLOC]=0, +* MODEREG_PARAMS0[MPR]=0, MR_MPR_CTL[MR_WR_SEL]=3, and +* MR_MPR_CTL[MR_WR_USE_DEFAULT_VALUE]=1) +*/ + +debug ("10)Take B-side devices out of MPR mode\n" ); + +set_mpr_mode (priv, rank_mask, if_num, dimm_count, +/* mpr */ 0 ,/* bg1 */ 1 ); + +/* +* a. Or you can set MR_MPR_CTL[MR_WR_USE_DEFAULT_VALUE]=0 and +* set the value you would like directly into MR_MPR_CTL[MR_WR_ADDR] +*/ + +/* 11)Re-enable refresh (REF_ZQCS_INT=previous value) */ + +debug ("11)Re-enable refresh (REF_ZQCS_INT=previous value)\n" ); + + lmc_config.u64 =lmc_rd (priv,CVMX_LMCX_CONFIG (if_num)); + lmc_config.cn78xx.ref_zqcs_int = save_ref_zqcs_int; +lmc_wr (priv,CVMX_LMCX_CONFIG (if_num), lmc_config.u64); +} + +static int validate_hwl_seq (int *wl,int *seq) +{ +// sequence index, step through the sequence array +int seqx; +int bitnum; + + seqx =0 ; + +while (seq[seqx +1 ] >=0 ) {// stop on next seq entry == -1 +// but now, check current versus next + bitnum = (wl[seq[seqx]] <<2 ) | wl[seq[seqx +1 ]]; +// magic validity number (see matrix above) +if (!((1 << bitnum) &0xBDE7 )) +return 1 ; + seqx++; + } + +return 0 ; +} + +static int validate_hw_wl_settings (int if_num, +union cvmx_lmcx_wlevel_rankx + *lmc_wlevel_rank,int is_rdimm,int ecc_ena) +{ +int wl[9 ], byte, errors; + +// arrange the sequences so +// index 0 has byte 0, etc, ECC in middle +int useq[] = {0 ,1 ,2 ,3 ,8 ,4 ,5 ,6 ,7 ,-1 }; +// index 0 is ECC, then go down +int rseq1[] = {8 ,3 ,2 ,1 ,0 ,-1 }; +// index 0 has byte 4, then go up +int rseq2[] = {4 ,5 ,6 ,7 ,-1 }; +// index 0 has byte 0, etc, no ECC +int useqno[] = {0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,-1 }; +// index 0 is byte 3, then go down, no ECC +int rseq1no[] = {3 ,2 ,1 ,0 ,-1 }; + +// in the CSR, bytes 0-7 are always data, byte 8 is ECC +for (byte =0 ; byte < (8 + ecc_ena); byte++) { +// preprocess :-) + wl[byte] = (get_wl_rank (lmc_wlevel_rank, byte) >> +1 ) &3 ; + } + + errors =0 ; +if (is_rdimm) {// RDIMM order + errors =validate_hwl_seq (wl, (ecc_ena) ? rseq1 : rseq1no); + errors +=validate_hwl_seq (wl, rseq2); + }else {// UDIMM order + errors =validate_hwl_seq (wl, (ecc_ena) ? useq : useqno); + } + +return errors; +} + +static unsigned int extr_wr (u64 u,int x) +{ +return (unsigned int )(((u >> (x *12 +5 )) &0x3ULL ) | + ((u >> (51 + x -2 )) &0x4ULL )); +} + +static void insrt_wr (u64 *up,int x,int v) +{ +u64 u = *up; + + u &= ~(((0x3ULL ) << (x *12 +5 )) | ((0x1ULL ) << (51 + x))); + *up = (u | ((v &0x3ULL ) << (x *12 +5 )) | + ((v &0x4ULL ) << (51 + x -2 ))); +} + +/* Read out Deskew Settings for DDR */ + +struct deskew_bytes { +u16 bits[8 ]; +}; + +struct deskew_data { +struct deskew_bytes bytes[9 ]; +}; + +struct dac_data { +int bytes[9 ]; +}; + +// T88 pass 1, skip 4=DAC +static const u8 dsk_bit_seq_p1[8 ] = {0 ,1 ,2 ,3 ,5 ,6 ,7 ,8 }; +// T88 Pass 2, skip 4=DAC and 5=DBI +static const u8 dsk_bit_seq_p2[8 ] = {0 ,1 ,2 ,3 ,6 ,7 ,8 ,9 }; + +static void get_deskew_settings (struct ddr_priv *priv,int if_num, +struct deskew_data *dskdat) +{ +union cvmx_lmcx_phy_ctl phy_ctl; +union cvmx_lmcx_config lmc_config; +int bit_index; +int byte_lane, byte_limit; +// NOTE: these are for pass 2.x +int is_o78p2 = !octeon_is_cpuid (OCTEON_CN78XX_PASS1_X ); +const u8 *bit_seq = (is_o78p2) ? dsk_bit_seq_p2 : dsk_bit_seq_p1; + + lmc_config.u64 =lmc_rd (priv,CVMX_LMCX_CONFIG (if_num)); + byte_limit = ((!lmc_config.s.mode32b) ?8 :4 ) + lmc_config.s.ecc_ena; + +memset (dskdat,0 ,sizeof (*dskdat)); + + phy_ctl.u64 =lmc_rd (priv,CVMX_LMCX_PHY_CTL (if_num)); + phy_ctl.s.dsk_dbg_clk_scaler =3 ; + +for (byte_lane =0 ; byte_lane < byte_limit; byte_lane++) { + phy_ctl.s.dsk_dbg_byte_sel = byte_lane;// set byte lane + +for (bit_index =0 ; bit_index <8 ; ++bit_index) { +// set bit number and start read sequence + phy_ctl.s.dsk_dbg_bit_sel = bit_seq[bit_index]; + phy_ctl.s.dsk_dbg_rd_start =1 ; +lmc_wr (priv,CVMX_LMCX_PHY_CTL (if_num), phy_ctl.u64); + +// poll for read sequence to complete +do { + phy_ctl.u64 = +lmc_rd (priv,CVMX_LMCX_PHY_CTL (if_num)); + }while (phy_ctl.s.dsk_dbg_rd_complete !=1 ); + +// record the data + dskdat->bytes[byte_lane].bits[bit_index] = + phy_ctl.s.dsk_dbg_rd_data &0x3ff ; + } + } +} + +static void display_deskew_settings (struct ddr_priv *priv,int if_num, +struct deskew_data *dskdat, +int print_enable) +{ +int byte_lane; +int bit_num; +u16 flags, deskew; +union cvmx_lmcx_config lmc_config; +int byte_limit; +const char *fc =" ?-=+*#&" ; + + lmc_config.u64 =lmc_rd (priv,CVMX_LMCX_CONFIG (if_num)); + byte_limit = ((lmc_config.s.mode32b) ?4 :8 ) + lmc_config.s.ecc_ena; + +if (print_enable) { +debug ("N0.LMC%d: Deskew Data: Bit => :" , + if_num); +for (bit_num =7 ; bit_num >=0 ; --bit_num) +debug (" %3d " , bit_num); +debug ("\n" ); + } + +for (byte_lane =0 ; byte_lane < byte_limit; byte_lane++) { +if (print_enable) +debug ("N0.LMC%d: Bit Deskew Byte %d %s :" , + if_num, byte_lane, + (print_enable >=3 ) ?"FINAL" :" " ); + +for (bit_num =7 ; bit_num >=0 ; --bit_num) { + flags = dskdat->bytes[byte_lane].bits[bit_num] &7 ; + deskew = dskdat->bytes[byte_lane].bits[bit_num] >>3 ; + +if (print_enable) +debug (" %3d %c" , deskew, fc[flags ^1 ]); + + }/* for (bit_num = 7; bit_num >= 0; --bit_num) */ + +if (print_enable) +debug ("\n" ); + } +} + +static void override_deskew_settings (struct ddr_priv *priv,int if_num, +struct deskew_data *dskdat) +{ +union cvmx_lmcx_phy_ctl phy_ctl; +union cvmx_lmcx_config lmc_config; + +int bit, byte_lane, byte_limit; +u64 csr_data; + + lmc_config.u64 =lmc_rd (priv,CVMX_LMCX_CONFIG (if_num)); + byte_limit = ((lmc_config.s.mode32b) ?4 :8 ) + lmc_config.s.ecc_ena; + + phy_ctl.u64 =lmc_rd (priv,CVMX_LMCX_PHY_CTL (if_num)); + + phy_ctl.s.phy_reset =0 ; + phy_ctl.s.dsk_dbg_num_bits_sel =1 ; + phy_ctl.s.dsk_dbg_offset =0 ; + phy_ctl.s.dsk_dbg_clk_scaler =3 ; + + phy_ctl.s.dsk_dbg_wr_mode =1 ; + phy_ctl.s.dsk_dbg_load_dis =0 ; + phy_ctl.s.dsk_dbg_overwrt_ena =0 ; + + phy_ctl.s.phy_dsk_reset =0 ; + +lmc_wr (priv,CVMX_LMCX_PHY_CTL (if_num), phy_ctl.u64); +lmc_rd (priv,CVMX_LMCX_PHY_CTL (if_num)); + +for (byte_lane =0 ; byte_lane < byte_limit; byte_lane++) { + csr_data =0 ; +// FIXME: can we ignore DBI? +for (bit =0 ; bit <8 ; ++bit) { +// fetch input and adjust +u64 bits = (dskdat->bytes[byte_lane].bits[bit] >>3 ) & +0x7F ; + +/* +* lmc_general_purpose0.data[6:0] // DQ0 +* lmc_general_purpose0.data[13:7] // DQ1 +* lmc_general_purpose0.data[20:14] // DQ2 +* lmc_general_purpose0.data[27:21] // DQ3 +* lmc_general_purpose0.data[34:28] // DQ4 +* lmc_general_purpose0.data[41:35] // DQ5 +* lmc_general_purpose0.data[48:42] // DQ6 +* lmc_general_purpose0.data[55:49] // DQ7 +* lmc_general_purpose0.data[62:56] // DBI +*/ + csr_data |= (bits << (7 * bit)); + + }/* for (bit = 0; bit < 8; ++bit) */ + +// update GP0 with the bit data for this byte lane +lmc_wr (priv,CVMX_LMCX_GENERAL_PURPOSE0 (if_num), csr_data); +lmc_rd (priv,CVMX_LMCX_GENERAL_PURPOSE0 (if_num)); + +// start the deskew load sequence + phy_ctl.s.dsk_dbg_byte_sel = byte_lane; + phy_ctl.s.dsk_dbg_rd_start =1 ; +lmc_wr (priv,CVMX_LMCX_PHY_CTL (if_num), phy_ctl.u64); + +// poll for read sequence to complete +do { +udelay (100 ); + phy_ctl.u64 =lmc_rd (priv,CVMX_LMCX_PHY_CTL (if_num)); + }while (phy_ctl.s.dsk_dbg_rd_complete !=1 ); + } + +// tell phy to use the new settings + phy_ctl.s.dsk_dbg_overwrt_ena =1 ; + phy_ctl.s.dsk_dbg_rd_start =0 ; +lmc_wr (priv,CVMX_LMCX_PHY_CTL (if_num), phy_ctl.u64); + + phy_ctl.s.dsk_dbg_wr_mode =0 ; +lmc_wr (priv,CVMX_LMCX_PHY_CTL (if_num), phy_ctl.u64); +} + +static void process_by_rank_dac (struct ddr_priv *priv,int if_num, +int rank_mask,struct dac_data *dacdat) +{ +union cvmx_lmcx_config lmc_config; +int rankx, byte_lane; +int byte_limit; +int rank_count; +struct dac_data dacsum; +int lane_probs; + + lmc_config.u64 =lmc_rd (priv,CVMX_LMCX_CONFIG (if_num)); + byte_limit = ((lmc_config.s.mode32b) ?4 :8 ) + lmc_config.s.ecc_ena; + +memset ((void *)&dacsum,0 ,sizeof (dacsum)); + rank_count =0 ; + lane_probs =0 ; + +for (rankx =0 ; rankx <4 ; rankx++) { +if (!(rank_mask & (1 << rankx))) +continue ; + rank_count++; + +display_dac_dbi_settings (if_num,/*dac */ 1 , + lmc_config.s.ecc_ena, + &dacdat[rankx].bytes[0 ], +"By-Ranks VREF" ); +// sum +for (byte_lane =0 ; byte_lane < byte_limit; byte_lane++) { +if (rank_count ==2 ) { +int ranks_diff = +abs ((dacsum.bytes[byte_lane] - + dacdat[rankx].bytes[byte_lane])); + +// FIXME: is 19 a good number? +if (ranks_diff >19 ) + lane_probs |= (1 << byte_lane); + } + dacsum.bytes[byte_lane] += + dacdat[rankx].bytes[byte_lane]; + } + } + +// average +for (byte_lane =0 ; byte_lane < byte_limit; byte_lane++) + dacsum.bytes[byte_lane] /= rank_count;// FIXME: nint? + +display_dac_dbi_settings (if_num,/*dac */ 1 , lmc_config.s.ecc_ena, + &dacsum.bytes[0 ],"All-Rank VREF" ); + +if (lane_probs) { +debug ("N0.LMC%d: All-Rank VREF DAC Problem Bytelane(s): 0x%03x\n" , + if_num, lane_probs); + } + +// finally, write the averaged DAC values +for (byte_lane =0 ; byte_lane < byte_limit; byte_lane++) { +load_dac_override (priv, if_num, dacsum.bytes[byte_lane], + byte_lane); + } +} + +static void process_by_rank_dsk (struct ddr_priv *priv,int if_num, +int rank_mask,struct deskew_data *dskdat) +{ +union cvmx_lmcx_config lmc_config; +int rankx, lane, bit; +int byte_limit; +struct deskew_data dsksum, dskcnt; +u16 deskew; + + lmc_config.u64 =lmc_rd (priv,CVMX_LMCX_CONFIG (if_num)); + byte_limit = ((lmc_config.s.mode32b) ?4 :8 ) + lmc_config.s.ecc_ena; + +memset ((void *)&dsksum,0 ,sizeof (dsksum)); +memset ((void *)&dskcnt,0 ,sizeof (dskcnt)); + +for (rankx =0 ; rankx <4 ; rankx++) { +if (!(rank_mask & (1 << rankx))) +continue ; + +// sum ranks +for (lane =0 ; lane < byte_limit; lane++) { +for (bit =0 ; bit <8 ; ++bit) { + deskew = dskdat[rankx].bytes[lane].bits[bit]; +// if flags indicate sat hi or lo, skip it +if (deskew &6 ) +continue ; + +// clear flags + dsksum.bytes[lane].bits[bit] += + deskew & ~7 ; +// count entries + dskcnt.bytes[lane].bits[bit] +=1 ; + } + } + } + +// average ranks +for (lane =0 ; lane < byte_limit; lane++) { +for (bit =0 ; bit <8 ; ++bit) { +int div = dskcnt.bytes[lane].bits[bit]; + +if (div >0 ) { + dsksum.bytes[lane].bits[bit] /= div; +// clear flags + dsksum.bytes[lane].bits[bit] &= ~7 ; +// set LOCK + dsksum.bytes[lane].bits[bit] |=1 ; + }else { +// FIXME? use reset value? + dsksum.bytes[lane].bits[bit] = + (64 <<3 ) |1 ; + } + } + } + +// TME for FINAL version +display_deskew_settings (priv, if_num, &dsksum,/*VBL_TME */ 3 ); + +// finally, write the averaged DESKEW values +override_deskew_settings (priv, if_num, &dsksum); +} + +struct deskew_counts { +int saturated;// number saturated +int unlocked;// number unlocked +int nibrng_errs;// nibble range errors +int nibunl_errs;// nibble unlocked errors +int bitval_errs;// bit value errors +}; + +#define MIN_BITVAL 17 +#define MAX_BITVAL 110 + +static void validate_deskew_training (struct ddr_priv *priv,int rank_mask, +int if_num,struct deskew_counts *counts, +int print_flags) +{ +int byte_lane, bit_index, nib_num; +int nibrng_errs, nibunl_errs, bitval_errs; +union cvmx_lmcx_config lmc_config; +s16 nib_min[2 ], nib_max[2 ], nib_unl[2 ]; +int byte_limit; +int print_enable = print_flags &1 ; +struct deskew_data dskdat; +s16 flags, deskew; +const char *fc =" ?-=+*#&" ; +int bit_last; + + lmc_config.u64 =lmc_rd (priv,CVMX_LMCX_CONFIG (if_num)); + byte_limit = ((!lmc_config.s.mode32b) ?8 :4 ) + lmc_config.s.ecc_ena; + +memset (counts,0 ,sizeof (struct deskew_counts )); + +get_deskew_settings (priv, if_num, &dskdat); + +if (print_enable) { +debug ("N0.LMC%d: Deskew Settings: Bit => :" , + if_num); +for (bit_index =7 ; bit_index >=0 ; --bit_index) +debug (" %3d " , bit_index); +debug ("\n" ); + } + +for (byte_lane =0 ; byte_lane < byte_limit; byte_lane++) { +if (print_enable) +debug ("N0.LMC%d: Bit Deskew Byte %d %s :" , + if_num, byte_lane, + (print_flags &2 ) ?"FINAL" :" " ); + + nib_min[0 ] =127 ; + nib_min[1 ] =127 ; + nib_max[0 ] =0 ; + nib_max[1 ] =0 ; + nib_unl[0 ] =0 ; + nib_unl[1 ] =0 ; + +if (lmc_config.s.mode32b ==1 && byte_lane ==4 ) { + bit_last =3 ; +if (print_enable) +debug (" " ); + }else { + bit_last =7 ; + } + +for (bit_index = bit_last; bit_index >=0 ; --bit_index) { + nib_num = (bit_index >3 ) ?1 :0 ; + + flags = dskdat.bytes[byte_lane].bits[bit_index] &7 ; + deskew = dskdat.bytes[byte_lane].bits[bit_index] >>3 ; + + counts->saturated += !!(flags &6 ); + +// Do range calc even when locked; it could happen +// that a bit is still unlocked after final retry, +// and we want to have an external retry if a RANGE +// error is present at exit... + nib_min[nib_num] =min (nib_min[nib_num], deskew); + nib_max[nib_num] =max (nib_max[nib_num], deskew); + +if (!(flags &1 )) {// only when not locked + counts->unlocked +=1 ; + nib_unl[nib_num] +=1 ; + } + +if (print_enable) +debug (" %3d %c" , deskew, fc[flags ^1 ]); + } + +/* +* Now look for nibble errors +* +* For bit 55, it looks like a bit deskew problem. When the +* upper nibble of byte 6 needs to go to saturation, bit 7 +* of byte 6 locks prematurely at 64. For DIMMs with raw +* card A and B, can we reset the deskew training when we +* encounter this case? The reset criteria should be looking +* at one nibble at a time for raw card A and B; if the +* bit-deskew setting within a nibble is different by > 33, +* we'll issue a reset to the bit deskew training. +* +* LMC0 Bit Deskew Byte(6): 64 0 - 0 - 0 - 26 61 35 64 +*/ +// upper nibble range, then lower nibble range + nibrng_errs = ((nib_max[1 ] - nib_min[1 ]) >33 ) ?1 :0 ; + nibrng_errs |= ((nib_max[0 ] - nib_min[0 ]) >33 ) ?1 :0 ; + +// check for nibble all unlocked + nibunl_errs = ((nib_unl[0 ] ==4 ) || (nib_unl[1 ] ==4 )) ?1 :0 ; + +// check for bit value errors, ie < 17 or > 110 +// FIXME? assume max always > MIN_BITVAL and min < MAX_BITVAL + bitval_errs = ((nib_max[1 ] >MAX_BITVAL ) || + (nib_max[0 ] >MAX_BITVAL )) ?1 :0 ; + bitval_errs |= ((nib_min[1 ] <MIN_BITVAL ) || + (nib_min[0 ] <MIN_BITVAL )) ?1 :0 ; + +if ((nibrng_errs !=0 || nibunl_errs !=0 || + bitval_errs !=0 ) && print_enable) { +debug (" %c%c%c" , + (nibrng_errs) ?'R' :' ' , + (nibunl_errs) ?'U' :' ' , + (bitval_errs) ?'V' :' ' ); + } + +if (print_enable) +debug ("\n" ); + + counts->nibrng_errs |= (nibrng_errs << byte_lane); + counts->nibunl_errs |= (nibunl_errs << byte_lane); + counts->bitval_errs |= (bitval_errs << byte_lane); + } +} + +static unsigned short load_dac_override (struct ddr_priv *priv,int if_num, +int dac_value,int byte) +{ +union cvmx_lmcx_dll_ctl3 ddr_dll_ctl3; +// single bytelanes incr by 1; A is for ALL +int bytex = (byte ==0x0A ) ? byte : byte +1 ; + + ddr_dll_ctl3.u64 =lmc_rd (priv,CVMX_LMCX_DLL_CTL3 (if_num)); + +SET_DDR_DLL_CTL3 (byte_sel, bytex); +SET_DDR_DLL_CTL3 (offset, dac_value >>1 ); + + ddr_dll_ctl3.cn73xx.bit_select =0x9 ;/* No-op */ +lmc_wr (priv,CVMX_LMCX_DLL_CTL3 (if_num), ddr_dll_ctl3.u64); + + ddr_dll_ctl3.cn73xx.bit_select =0xC ;/* vref bypass setting load */ +lmc_wr (priv,CVMX_LMCX_DLL_CTL3 (if_num), ddr_dll_ctl3.u64); + + ddr_dll_ctl3.cn73xx.bit_select =0xD ;/* vref bypass on. */ +lmc_wr (priv,CVMX_LMCX_DLL_CTL3 (if_num), ddr_dll_ctl3.u64); + + ddr_dll_ctl3.cn73xx.bit_select =0x9 ;/* No-op */ +lmc_wr (priv,CVMX_LMCX_DLL_CTL3 (if_num), ddr_dll_ctl3.u64); + +lmc_rd (priv,CVMX_LMCX_DLL_CTL3 (if_num));// flush writes + +return (unsigned short )GET_DDR_DLL_CTL3 (offset); +} + +// arg dac_or_dbi is 1 for DAC, 0 for DBI +// returns 9 entries (bytelanes 0 through 8) in settings[] +// returns 0 if OK, -1 if a problem +static int read_dac_dbi_settings (struct ddr_priv *priv,int if_num, +int dac_or_dbi,int *settings) +{ +union cvmx_lmcx_phy_ctl phy_ctl; +int byte_lane, bit_num; +int deskew; +int dac_value; +int new_deskew_layout =0 ; + + new_deskew_layout =octeon_is_cpuid (OCTEON_CN73XX ) || +octeon_is_cpuid (OCTEON_CNF75XX ); + new_deskew_layout |= (octeon_is_cpuid (OCTEON_CN78XX ) && + !octeon_is_cpuid (OCTEON_CN78XX_PASS1_X )); + + phy_ctl.u64 =lmc_rd (priv,CVMX_LMCX_PHY_CTL (if_num)); + phy_ctl.s.dsk_dbg_clk_scaler =3 ; +lmc_wr (priv,CVMX_LMCX_PHY_CTL (if_num), phy_ctl.u64); + + bit_num = (dac_or_dbi) ?4 :5 ; +// DBI not available +if (bit_num ==5 && !new_deskew_layout) +return -1 ; + +// FIXME: always assume ECC is available +for (byte_lane =8 ; byte_lane >=0 ; --byte_lane) { +//set byte lane and bit to read + phy_ctl.s.dsk_dbg_bit_sel = bit_num; + phy_ctl.s.dsk_dbg_byte_sel = byte_lane; +lmc_wr (priv,CVMX_LMCX_PHY_CTL (if_num), phy_ctl.u64); + +//start read sequence + phy_ctl.u64 =lmc_rd (priv,CVMX_LMCX_PHY_CTL (if_num)); + phy_ctl.s.dsk_dbg_rd_start =1 ; +lmc_wr (priv,CVMX_LMCX_PHY_CTL (if_num), phy_ctl.u64); + +//poll for read sequence to complete +do { + phy_ctl.u64 =lmc_rd (priv,CVMX_LMCX_PHY_CTL (if_num)); + }while (phy_ctl.s.dsk_dbg_rd_complete !=1 ); + +// keep the flag bits where they are for DBI + deskew = phy_ctl.s.dsk_dbg_rd_data;/* >> 3 */ + dac_value = phy_ctl.s.dsk_dbg_rd_data &0xff ; + + settings[byte_lane] = (dac_or_dbi) ? dac_value : deskew; + } + +return 0 ; +} + +// print out the DBI settings array +// arg dac_or_dbi is 1 for DAC, 0 for DBI +static void display_dac_dbi_settings (int lmc,int dac_or_dbi, +int ecc_ena,int *settings,char *title) +{ +int byte; +int flags; +int deskew; +const char *fc =" ?-=+*#&" ; + +debug ("N0.LMC%d: %s %s Settings %d:0 :" , + lmc, title, (dac_or_dbi) ?"DAC" :"DBI" ,7 + ecc_ena); +// FIXME: what about 32-bit mode? +for (byte = (7 + ecc_ena); byte >=0 ; --byte) { +if (dac_or_dbi) {// DAC + flags =1 ;// say its locked to get blank + deskew = settings[byte] &0xff ; + }else {// DBI + flags = settings[byte] &7 ; + deskew = (settings[byte] >>3 ) &0x7f ; + } +debug (" %3d %c" , deskew, fc[flags ^1 ]); + } +debug ("\n" ); +} + +// Find a HWL majority +static int find_wl_majority (struct wlevel_bitcnt *bc,int *mx,int *mc, +int *xc,int *cc) +{ +int ix, ic; + + *mx =-1 ; + *mc =0 ; + *xc =0 ; + *cc =0 ; + +for (ix =0 ; ix <4 ; ix++) { + ic = bc->bitcnt[ix]; + +// make a bitmask of the ones with a count +if (ic >0 ) { + *mc |= (1 << ix); + *cc +=1 ;// count how many had non-zero counts + } + +// find the majority +if (ic > *xc) {// new max? + *xc = ic;// yes + *mx = ix;// set its index + } + } + +return (*mx <<1 ); +} + +// Evaluate the DAC settings array +static int evaluate_dac_settings (int if_64b,int ecc_ena,int *settings) +{ +int byte, lane, dac, comp; +int last = (if_64b) ?7 :3 ; + +// FIXME: change the check...??? +// this looks only for sets of DAC values whose max/min differ by a lot +// let any EVEN go so long as it is within range... +for (byte = (last + ecc_ena); byte >=0 ; --byte) { + dac = settings[byte] &0xff ; + +for (lane = (last + ecc_ena); lane >=0 ; --lane) { + comp = settings[lane] &0xff ; +if (abs ((dac - comp)) >25 ) +return 1 ; + } + } + +return 0 ; +} + +static void perform_offset_training (struct ddr_priv *priv,int rank_mask, +int if_num) +{ +union cvmx_lmcx_phy_ctl lmc_phy_ctl; +u64 orig_phy_ctl; +const char *s; + +/* +* 4.8.6 LMC Offset Training +* +* LMC requires input-receiver offset training. +* +* 1. Write LMC(0)_PHY_CTL[DAC_ON] = 1 +*/ + lmc_phy_ctl.u64 =lmc_rd (priv,CVMX_LMCX_PHY_CTL (if_num)); + orig_phy_ctl = lmc_phy_ctl.u64; + lmc_phy_ctl.s.dac_on =1 ; + +// allow full CSR override + s =lookup_env_ull (priv,"ddr_phy_ctl" ); +if (s) + lmc_phy_ctl.u64 =strtoull (s,NULL ,0 ); + +// do not print or write if CSR does not change... +if (lmc_phy_ctl.u64 != orig_phy_ctl) { +debug ("PHY_CTL : 0x%016llx\n" , + lmc_phy_ctl.u64); +lmc_wr (priv,CVMX_LMCX_PHY_CTL (if_num), lmc_phy_ctl.u64); + } + +/* +* 2. Write LMC(0)_SEQ_CTL[SEQ_SEL] = 0x0B and +* LMC(0)_SEQ_CTL[INIT_START] = 1. +* +* 3. Wait for LMC(0)_SEQ_CTL[SEQ_COMPLETE] to be set to 1. +*/ +/* Start Offset training sequence */ +oct3_ddr3_seq (priv, rank_mask, if_num,0x0B ); +} + +static void perform_internal_vref_training (struct ddr_priv *priv, +int rank_mask,int if_num) +{ +union cvmx_lmcx_ext_config ext_config; +union cvmx_lmcx_dll_ctl3 ddr_dll_ctl3; + +// First, make sure all byte-lanes are out of VREF bypass mode + ddr_dll_ctl3.u64 =lmc_rd (priv,CVMX_LMCX_DLL_CTL3 (if_num)); + + ddr_dll_ctl3.cn78xx.byte_sel =0x0A ;/* all byte-lanes */ + ddr_dll_ctl3.cn78xx.bit_select =0x09 ;/* No-op */ +lmc_wr (priv,CVMX_LMCX_DLL_CTL3 (if_num), ddr_dll_ctl3.u64); + + ddr_dll_ctl3.cn78xx.bit_select =0x0E ;/* vref bypass off. */ +lmc_wr (priv,CVMX_LMCX_DLL_CTL3 (if_num), ddr_dll_ctl3.u64); + + ddr_dll_ctl3.cn78xx.bit_select =0x09 ;/* No-op */ +lmc_wr (priv,CVMX_LMCX_DLL_CTL3 (if_num), ddr_dll_ctl3.u64); + +/* +* 4.8.7 LMC Internal vref Training +* +* LMC requires input-reference-voltage training. +* +* 1. Write LMC(0)_EXT_CONFIG[VREFINT_SEQ_DESKEW] = 0. +*/ + ext_config.u64 =lmc_rd (priv,CVMX_LMCX_EXT_CONFIG (if_num)); + ext_config.s.vrefint_seq_deskew =0 ; + +ddr_seq_print ("Performing LMC sequence: vrefint_seq_deskew = %d\n" , + ext_config.s.vrefint_seq_deskew); + +lmc_wr (priv,CVMX_LMCX_EXT_CONFIG (if_num), ext_config.u64); + +/* +* 2. Write LMC(0)_SEQ_CTL[SEQ_SEL] = 0x0a and +* LMC(0)_SEQ_CTL[INIT_START] = 1. +* +* 3. Wait for LMC(0)_SEQ_CTL[SEQ_COMPLETE] to be set to 1. +*/ +/* Start LMC Internal vref Training */ +oct3_ddr3_seq (priv, rank_mask, if_num,0x0A ); +} + +#define dbg_avg (format, ...)// debug(format, ##__VA_ARGS__) + +static int process_samples_average (s16 *bytes,int num_samples, +int lmc,int lane_no) +{ +int i, sadj, sum =0 , ret, asum, trunc; +s16 smin =32767 , smax =-32768 ; +int nmin, nmax; +//int rng; + +dbg_avg ("DBG_AVG%d.%d: " , lmc, lane_no); + +for (i =0 ; i < num_samples; i++) { + sum += bytes[i]; +if (bytes[i] < smin) + smin = bytes[i]; +if (bytes[i] > smax) + smax = bytes[i]; +dbg_avg (" %3d" , bytes[i]); + } + + nmin =0 ; + nmax =0 ; +for (i =0 ; i < num_samples; i++) { +if (bytes[i] == smin) + nmin +=1 ; +if (bytes[i] == smax) + nmax +=1 ; + } +dbg_avg (" (min=%3d/%d, max=%3d/%d, range=%2d, samples=%2d)" , + smin, nmin, smax, nmax, rng, num_samples); + + asum = sum - smin - smax; + + sadj =divide_nint (asum *10 , (num_samples -2 )); + + trunc = asum / (num_samples -2 ); + +dbg_avg (" [%3d.%d, %3d]" , sadj /10 , sadj %10 , trunc); + + sadj =divide_nint (sadj,10 ); +if (trunc &1 ) + ret = trunc; +else if (sadj &1 ) + ret = sadj; +else + ret = trunc +1 ; + +dbg_avg (" -> %3d\n" , ret); + +return ret; +} + +#define DEFAULT_SAT_RETRY_LIMIT 11 // 1 + 10 retries + +#define default_lock_retry_limit 20 // 20 retries +#define deskew_validation_delay 10000 // 10 millisecs + +static int perform_deskew_training (struct ddr_priv *priv,int rank_mask, +int if_num,int spd_rawcard_aorb) +{ +int unsaturated, locked; +int sat_retries, sat_retries_limit; +int lock_retries, lock_retries_total, lock_retries_limit; +int print_first; +int print_them_all; +struct deskew_counts dsk_counts; +union cvmx_lmcx_phy_ctl phy_ctl; +char *s; +int has_no_sat =octeon_is_cpuid (OCTEON_CN78XX_PASS2_X ) || +octeon_is_cpuid (OCTEON_CNF75XX ); +int disable_bitval_retries =1 ;// default to disabled + +debug ("N0.LMC%d: Performing Deskew Training.\n" , if_num); + + sat_retries =0 ; + sat_retries_limit = (has_no_sat) ?5 :DEFAULT_SAT_RETRY_LIMIT ; + + lock_retries_total =0 ; + unsaturated =0 ; + print_first =1 ;// print the first one +// set to true for printing all normal deskew attempts + print_them_all =0 ; + +// provide override for bitval_errs causing internal VREF retries + s =env_get ("ddr_disable_bitval_retries" ); +if (s) + disable_bitval_retries = !!simple_strtoul (s,NULL ,0 ); + + lock_retries_limit = default_lock_retry_limit; +if ((octeon_is_cpuid (OCTEON_CN78XX_PASS2_X )) || + (octeon_is_cpuid (OCTEON_CN73XX )) || + (octeon_is_cpuid (OCTEON_CNF75XX ))) + lock_retries_limit *=2 ;// give new chips twice as many + +do {/* while (sat_retries < sat_retry_limit) */ +/* +* 4.8.8 LMC Deskew Training +* +* LMC requires input-read-data deskew training. +* +* 1. Write LMC(0)_EXT_CONFIG[VREFINT_SEQ_DESKEW] = 1. +*/ + +union cvmx_lmcx_ext_config ext_config; + + ext_config.u64 =lmc_rd (priv,CVMX_LMCX_EXT_CONFIG (if_num)); + ext_config.s.vrefint_seq_deskew =1 ; + +ddr_seq_print + ("Performing LMC sequence: vrefint_seq_deskew = %d\n" , + ext_config.s.vrefint_seq_deskew); + +lmc_wr (priv,CVMX_LMCX_EXT_CONFIG (if_num), ext_config.u64); + +/* +* 2. Write LMC(0)_SEQ_CTL[SEQ_SEL] = 0x0A and +* LMC(0)_SEQ_CTL[INIT_START] = 1. +* +* 3. Wait for LMC(0)_SEQ_CTL[SEQ_COMPLETE] to be set to 1. +*/ + + phy_ctl.u64 =lmc_rd (priv,CVMX_LMCX_PHY_CTL (if_num)); + phy_ctl.s.phy_dsk_reset =1 ;/* RESET Deskew sequence */ +lmc_wr (priv,CVMX_LMCX_PHY_CTL (if_num), phy_ctl.u64); + +/* LMC Deskew Training */ +oct3_ddr3_seq (priv, rank_mask, if_num,0x0A ); + + lock_retries =0 ; + +perform_deskew_training: + + phy_ctl.u64 =lmc_rd (priv,CVMX_LMCX_PHY_CTL (if_num)); + phy_ctl.s.phy_dsk_reset =0 ;/* Normal Deskew sequence */ +lmc_wr (priv,CVMX_LMCX_PHY_CTL (if_num), phy_ctl.u64); + +/* LMC Deskew Training */ +oct3_ddr3_seq (priv, rank_mask, if_num,0x0A ); + +// Moved this from validate_deskew_training +/* Allow deskew results to stabilize before evaluating them. */ +udelay (deskew_validation_delay); + +// Now go look@lock and saturation status... +validate_deskew_training (priv, rank_mask, if_num, &dsk_counts, + print_first); +// after printing the first and not doing them all, no more +if (print_first && !print_them_all) + print_first =0 ; + + unsaturated = (dsk_counts.saturated ==0 ); + locked = (dsk_counts.unlocked ==0 ); + +// only do locking retries if unsaturated or rawcard A or B, +// otherwise full SAT retry +if (unsaturated || (spd_rawcard_aorb && !has_no_sat)) { +if (!locked) {// and not locked + lock_retries++; + lock_retries_total++; +if (lock_retries <= lock_retries_limit) { + goto perform_deskew_training; + }else { +debug ("N0.LMC%d: LOCK RETRIES failed after %d retries\n" , + if_num, lock_retries_limit); + } + }else { +// only print if we did try +if (lock_retries_total >0 ) +debug ("N0.LMC%d: LOCK RETRIES successful after %d retries\n" , + if_num, lock_retries); + } + }/* if (unsaturated || spd_rawcard_aorb) */ + + ++sat_retries; + +/* +* At this point, check for a DDR4 RDIMM that will not +* benefit from SAT retries; if so, exit +*/ +if (spd_rawcard_aorb && !has_no_sat) { +debug ("N0.LMC%d: Deskew Training Loop: Exiting for RAWCARD == A or B.\n" , + if_num); +break ;// no sat or lock retries + } + + }while (!unsaturated && (sat_retries < sat_retries_limit)); + +debug ("N0.LMC%d: Deskew Training %s. %d sat-retries, %d lock-retries\n" , + if_num, (sat_retries >=DEFAULT_SAT_RETRY_LIMIT ) ? +"Timed Out" :"Completed" , sat_retries -1 , lock_retries_total); + +// FIXME? add saturation to reasons for fault return - give it a +// chance via Internal VREF +// FIXME? add OPTIONAL bit value to reasons for fault return - +// give it a chance via Internal VREF +if (dsk_counts.nibrng_errs !=0 || dsk_counts.nibunl_errs !=0 || + (dsk_counts.bitval_errs !=0 && !disable_bitval_retries) || + !unsaturated) { +debug ("N0.LMC%d: Nibble or Saturation Error(s) found, returning FAULT\n" , + if_num); +// FIXME: do we want this output always for errors? +validate_deskew_training (priv, rank_mask, if_num, + &dsk_counts,1 ); +return -1 ;// we did retry locally, they did not help + } + +// NOTE: we (currently) always print one last training validation +// before starting Read Leveling... + +return 0 ; +} + +#define SCALING_FACTOR (1000) + +// NOTE: this gets called for 1-rank and 2-rank DIMMs in single-slot config +static int compute_vref_1slot_2rank (int rtt_wr,int rtt_park,int dqx_ctl, +int rank_count,int dram_connection) +{ +u64 reff_s; +u64 rser_s = (dram_connection) ?0 :15 ; +u64 vdd =1200 ; +u64 vref; +// 99 == HiZ +u64 rtt_wr_s = (((rtt_wr ==0 ) || rtt_wr ==99 ) ? +1 *1024 *1024 : rtt_wr); +u64 rtt_park_s = (((rtt_park ==0 ) || ((rank_count ==1 ) && + (rtt_wr !=0 ))) ? +1 *1024 *1024 : rtt_park); +u64 dqx_ctl_s = (dqx_ctl ==0 ?1 *1024 *1024 : dqx_ctl); +int vref_value; +u64 rangepc =6000 ;// range1 base +u64 vrefpc; +int vref_range =0 ; + + reff_s =divide_nint ((rtt_wr_s * rtt_park_s), (rtt_wr_s + rtt_park_s)); + + vref = (((rser_s + dqx_ctl_s) *SCALING_FACTOR ) / + (rser_s + dqx_ctl_s + reff_s)) +SCALING_FACTOR ; + + vref = (vref * vdd) /2 /SCALING_FACTOR ; + + vrefpc = (vref *100 *100 ) / vdd; + +if (vrefpc < rangepc) {// < range1 base, use range2 + vref_range =1 <<6 ;// set bit A6 for range2 + rangepc =4500 ;// range2 base is 45% + } + + vref_value =divide_nint (vrefpc - rangepc,65 ); +if (vref_value <0 ) + vref_value = vref_range;// set to base of range +else + vref_value |= vref_range; + +debug ("rtt_wr: %d, rtt_park: %d, dqx_ctl: %d, rank_count: %d\n" , + rtt_wr, rtt_park, dqx_ctl, rank_count); +debug ("rtt_wr_s: %lld, rtt_park_s: %lld, dqx_ctl_s: %lld, vref_value: 0x%x, range: %d\n" , + rtt_wr_s, rtt_park_s, dqx_ctl_s, vref_value ^ vref_range, + vref_range ?2 :1 ); + +return vref_value; +} + +// NOTE: this gets called for 1-rank and 2-rank DIMMs in two-slot configs +static int compute_vref_2slot_2rank (int rtt_wr,int rtt_park_00, +int rtt_park_01, +int dqx_ctl,int rtt_nom, +int dram_connection) +{ +u64 rser = (dram_connection) ?0 :15 ; +u64 vdd =1200 ; +u64 vl, vlp, vcm; +u64 rd0, rd1, rpullup; +// 99 == HiZ +u64 rtt_wr_s = (((rtt_wr ==0 ) || rtt_wr ==99 ) ? +1 *1024 *1024 : rtt_wr); +u64 rtt_park_00_s = (rtt_park_00 ==0 ?1 *1024 *1024 : rtt_park_00); +u64 rtt_park_01_s = (rtt_park_01 ==0 ?1 *1024 *1024 : rtt_park_01); +u64 dqx_ctl_s = (dqx_ctl ==0 ?1 *1024 *1024 : dqx_ctl); +u64 rtt_nom_s = (rtt_nom ==0 ?1 *1024 *1024 : rtt_nom); +int vref_value; +u64 rangepc =6000 ;// range1 base +u64 vrefpc; +int vref_range =0 ; + +// rd0 = (RTT_NOM (parallel) RTT_WR) + = +// ((RTT_NOM * RTT_WR) / (RTT_NOM + RTT_WR)) + RSER + rd0 =divide_nint ((rtt_nom_s * rtt_wr_s), + (rtt_nom_s + rtt_wr_s)) + rser; + +// rd1 = (RTT_PARK_00 (parallel) RTT_PARK_01) + RSER = +// ((RTT_PARK_00 * RTT_PARK_01) / (RTT_PARK_00 + RTT_PARK_01)) + RSER + rd1 =divide_nint ((rtt_park_00_s * rtt_park_01_s), + (rtt_park_00_s + rtt_park_01_s)) + rser; + +// rpullup = rd0 (parallel) rd1 = (rd0 * rd1) / (rd0 + rd1) + rpullup =divide_nint ((rd0 * rd1), (rd0 + rd1)); + +// vl = (DQX_CTL / (DQX_CTL + rpullup)) * 1.2 + vl =divide_nint ((dqx_ctl_s * vdd), (dqx_ctl_s + rpullup)); + +// vlp = ((RSER / rd0) * (1.2 - vl)) + vl + vlp =divide_nint ((rser * (vdd - vl)), rd0) + vl; + +// vcm = (vlp + 1.2) / 2 + vcm =divide_nint ((vlp + vdd),2 ); + +// vrefpc = (vcm / 1.2) * 100 + vrefpc =divide_nint ((vcm *100 *100 ), vdd); + +if (vrefpc < rangepc) {// < range1 base, use range2 + vref_range =1 <<6 ;// set bit A6 for range2 + rangepc =4500 ;// range2 base is 45% + } + + vref_value =divide_nint (vrefpc - rangepc,65 ); +if (vref_value <0 ) + vref_value = vref_range;// set to base of range +else + vref_value |= vref_range; + +debug ("rtt_wr:%d, rtt_park_00:%d, rtt_park_01:%d, dqx_ctl:%d, rtt_nom:%d, vref_value:%d (0x%x)\n" , + rtt_wr, rtt_park_00, rtt_park_01, dqx_ctl, rtt_nom, vref_value, + vref_value); + +return vref_value; +} + +// NOTE: only call this for DIMMs with 1 or 2 ranks, not 4. +static int compute_vref_val (struct ddr_priv *priv,int if_num,int rankx, +int dimm_count,int rank_count, +struct impedence_values *imp_values, +int is_stacked_die,int dram_connection) +{ +int computed_final_vref_value =0 ; +int enable_adjust =ENABLE_COMPUTED_VREF_ADJUSTMENT ; +const char *s; +int rtt_wr, dqx_ctl, rtt_nom, index; +union cvmx_lmcx_modereg_params1 lmc_modereg_params1; +union cvmx_lmcx_modereg_params2 lmc_modereg_params2; +union cvmx_lmcx_comp_ctl2 comp_ctl2; +int rtt_park; +int rtt_park_00; +int rtt_park_01; + +debug ("N0.LMC%d.R%d: %s(...dram_connection = %d)\n" , + if_num, rankx, __func__, dram_connection); + +// allow some overrides... + s =env_get ("ddr_adjust_computed_vref" ); +if (s) { + enable_adjust = !!simple_strtoul (s,NULL ,0 ); +if (!enable_adjust) { +debug ("N0.LMC%d.R%d: DISABLE adjustment of computed VREF\n" , + if_num, rankx); + } + } + + s =env_get ("ddr_set_computed_vref" ); +if (s) { +int new_vref =simple_strtoul (s,NULL ,0 ); + +debug ("N0.LMC%d.R%d: OVERRIDE computed VREF to 0x%x (%d)\n" , + if_num, rankx, new_vref, new_vref); +return new_vref; + } + +/* +* Calculate an alternative to the measured vref value +* but only for configurations we know how to... +*/ +// We have code for 2-rank DIMMs in both 1-slot or 2-slot configs, +// and can use the 2-rank 1-slot code for 1-rank DIMMs in 1-slot +// configs, and can use the 2-rank 2-slot code for 1-rank DIMMs +// in 2-slot configs. + + lmc_modereg_params1.u64 = +lmc_rd (priv,CVMX_LMCX_MODEREG_PARAMS1 (if_num)); + lmc_modereg_params2.u64 = +lmc_rd (priv,CVMX_LMCX_MODEREG_PARAMS2 (if_num)); + comp_ctl2.u64 =lmc_rd (priv,CVMX_LMCX_COMP_CTL2 (if_num)); + dqx_ctl = imp_values->dqx_strength[comp_ctl2.s.dqx_ctl]; + +// WR always comes from the current rank + index = (lmc_modereg_params1.u64 >> (rankx *12 +5 )) &0x03 ; +if (!octeon_is_cpuid (OCTEON_CN78XX_PASS1_X )) + index |= lmc_modereg_params1.u64 >> (51 + rankx -2 ) &0x04 ; + rtt_wr = imp_values->rtt_wr_ohms[index]; + +// separate calculations for 1 vs 2 DIMMs per LMC +if (dimm_count ==1 ) { +// PARK comes from this rank if 1-rank, otherwise other rank + index = + (lmc_modereg_params2.u64 >> + ((rankx ^ (rank_count -1 )) *10 +0 )) &0x07 ; + rtt_park = imp_values->rtt_nom_ohms[index]; + computed_final_vref_value = +compute_vref_1slot_2rank (rtt_wr, rtt_park, dqx_ctl, + rank_count, dram_connection); + }else { +// get both PARK values from the other DIMM + index = + (lmc_modereg_params2.u64 >> ((rankx ^0x02 ) *10 +0 )) & +0x07 ; + rtt_park_00 = imp_values->rtt_nom_ohms[index]; + index = + (lmc_modereg_params2.u64 >> ((rankx ^0x03 ) *10 +0 )) & +0x07 ; + rtt_park_01 = imp_values->rtt_nom_ohms[index]; +// NOM comes from this rank if 1-rank, otherwise other rank + index = + (lmc_modereg_params1.u64 >> + ((rankx ^ (rank_count -1 )) *12 +9 )) &0x07 ; + rtt_nom = imp_values->rtt_nom_ohms[index]; + computed_final_vref_value = +compute_vref_2slot_2rank (rtt_wr, rtt_park_00, rtt_park_01, + dqx_ctl, rtt_nom, dram_connection); + } + +if (enable_adjust) { +union cvmx_lmcx_config lmc_config; +union cvmx_lmcx_control lmc_control; + + lmc_config.u64 =lmc_rd (priv,CVMX_LMCX_CONFIG (if_num)); + lmc_control.u64 =lmc_rd (priv,CVMX_LMCX_CONTROL (if_num)); + +/* +* New computed vref = existing computed vref ? X +* +* The value of X is depending on different conditions. +* Both #122 and #139 are 2Rx4 RDIMM, while #124 is stacked +* die 2Rx4, so I conclude the results into two conditions: +* +* 1. Stacked Die: 2Rx4 +* 1-slot: offset = 7. i, e New computed vref = existing +* computed vref ? 7 +* 2-slot: offset = 6 +* +* 2. Regular: 2Rx4 +* 1-slot: offset = 3 +* 2-slot: offset = 2 +*/ +// we know we never get called unless DDR4, so test just +// the other conditions +if (lmc_control.s.rdimm_ena ==1 && + rank_count ==2 && lmc_config.s.mode_x4dev) { +// it must first be RDIMM and 2-rank and x4 +int adj; + +// now do according to stacked die or not... +if (is_stacked_die) + adj = (dimm_count ==1 ) ?-7 :-6 ; +else + adj = (dimm_count ==1 ) ?-3 :-2 ; + +// we must have adjusted it, so print it out if +// verbosity is right +debug ("N0.LMC%d.R%d: adjusting computed vref from %2d (0x%02x) to %2d (0x%02x)\n" , + if_num, rankx, computed_final_vref_value, + computed_final_vref_value, + computed_final_vref_value + adj, + computed_final_vref_value + adj); + computed_final_vref_value += adj; + } + } + +return computed_final_vref_value; +} + +static void unpack_rlevel_settings (int if_bytemask,int ecc_ena, +struct rlevel_byte_data *rlevel_byte, +union cvmx_lmcx_rlevel_rankx lmc_rlevel_rank) +{ +if ((if_bytemask &0xff ) ==0xff ) { +if (ecc_ena) { + rlevel_byte[8 ].delay = lmc_rlevel_rank.s.byte7; + rlevel_byte[7 ].delay = lmc_rlevel_rank.s.byte6; + rlevel_byte[6 ].delay = lmc_rlevel_rank.s.byte5; + rlevel_byte[5 ].delay = lmc_rlevel_rank.s.byte4; +/* ECC */ + rlevel_byte[4 ].delay = lmc_rlevel_rank.s.byte8; + }else { + rlevel_byte[7 ].delay = lmc_rlevel_rank.s.byte7; + rlevel_byte[6 ].delay = lmc_rlevel_rank.s.byte6; + rlevel_byte[5 ].delay = lmc_rlevel_rank.s.byte5; + rlevel_byte[4 ].delay = lmc_rlevel_rank.s.byte4; + } + }else { + rlevel_byte[8 ].delay = lmc_rlevel_rank.s.byte8;/* unused */ + rlevel_byte[7 ].delay = lmc_rlevel_rank.s.byte7;/* unused */ + rlevel_byte[6 ].delay = lmc_rlevel_rank.s.byte6;/* unused */ + rlevel_byte[5 ].delay = lmc_rlevel_rank.s.byte5;/* unused */ + rlevel_byte[4 ].delay = lmc_rlevel_rank.s.byte4;/* ECC */ + } + + rlevel_byte[3 ].delay = lmc_rlevel_rank.s.byte3; + rlevel_byte[2 ].delay = lmc_rlevel_rank.s.byte2; + rlevel_byte[1 ].delay = lmc_rlevel_rank.s.byte1; + rlevel_byte[0 ].delay = lmc_rlevel_rank.s.byte0; +} + +static void pack_rlevel_settings (int if_bytemask,int ecc_ena, +struct rlevel_byte_data *rlevel_byte, +union cvmx_lmcx_rlevel_rankx + *final_rlevel_rank) +{ +union cvmx_lmcx_rlevel_rankx lmc_rlevel_rank = *final_rlevel_rank; + +if ((if_bytemask &0xff ) ==0xff ) { +if (ecc_ena) { + lmc_rlevel_rank.s.byte7 = rlevel_byte[8 ].delay; + lmc_rlevel_rank.s.byte6 = rlevel_byte[7 ].delay; + lmc_rlevel_rank.s.byte5 = rlevel_byte[6 ].delay; + lmc_rlevel_rank.s.byte4 = rlevel_byte[5 ].delay; +/* ECC */ + lmc_rlevel_rank.s.byte8 = rlevel_byte[4 ].delay; + }else { + lmc_rlevel_rank.s.byte7 = rlevel_byte[7 ].delay; + lmc_rlevel_rank.s.byte6 = rlevel_byte[6 ].delay; + lmc_rlevel_rank.s.byte5 = rlevel_byte[5 ].delay; + lmc_rlevel_rank.s.byte4 = rlevel_byte[4 ].delay; + } + }else { + lmc_rlevel_rank.s.byte8 = rlevel_byte[8 ].delay; + lmc_rlevel_rank.s.byte7 = rlevel_byte[7 ].delay; + lmc_rlevel_rank.s.byte6 = rlevel_byte[6 ].delay; + lmc_rlevel_rank.s.byte5 = rlevel_byte[5 ].delay; + lmc_rlevel_rank.s.byte4 = rlevel_byte[4 ].delay; + } + + lmc_rlevel_rank.s.byte3 = rlevel_byte[3 ].delay; + lmc_rlevel_rank.s.byte2 = rlevel_byte[2 ].delay; + lmc_rlevel_rank.s.byte1 = rlevel_byte[1 ].delay; + lmc_rlevel_rank.s.byte0 = rlevel_byte[0 ].delay; + + *final_rlevel_rank = lmc_rlevel_rank; +} + +/////////////////// These are the RLEVEL settings display routines + +// flags +#define WITH_NOTHING 0 +#define WITH_SCORE 1 +#define WITH_AVERAGE 2 +#define WITH_FINAL 4 +#define WITH_COMPUTE 8 + +static void do_display_rl (int if_num, +union cvmx_lmcx_rlevel_rankx lmc_rlevel_rank, +int rank,int flags,int score) +{ +char score_buf[16 ]; +char *msg_buf; +char hex_buf[20 ]; + +if (flags &WITH_SCORE ) { +snprintf (score_buf,sizeof (score_buf),"(%d)" , score); + }else { + score_buf[0 ] =' ' ; + score_buf[1 ] =0 ; + } + +if (flags &WITH_AVERAGE ) { + msg_buf =" DELAY AVERAGES " ; + }else if (flags &WITH_FINAL ) { + msg_buf =" FINAL SETTINGS " ; + }else if (flags &WITH_COMPUTE ) { + msg_buf =" COMPUTED DELAYS " ; + }else { +snprintf (hex_buf,sizeof (hex_buf),"0x%016llX" , + (unsigned long long )lmc_rlevel_rank.u64); + msg_buf = hex_buf; + } + +debug ("N0.LMC%d.R%d: Rlevel Rank %#4x, %s : %5d %5d %5d %5d %5d %5d %5d %5d %5d %s\n" , + if_num, rank, lmc_rlevel_rank.s.status, msg_buf, + lmc_rlevel_rank.s.byte8, lmc_rlevel_rank.s.byte7, + lmc_rlevel_rank.s.byte6, lmc_rlevel_rank.s.byte5, + lmc_rlevel_rank.s.byte4, lmc_rlevel_rank.s.byte3, + lmc_rlevel_rank.s.byte2, lmc_rlevel_rank.s.byte1, + lmc_rlevel_rank.s.byte0, score_buf); +} + +static void display_rl (int if_num, +union cvmx_lmcx_rlevel_rankx lmc_rlevel_rank,int rank) +{ +do_display_rl (if_num, lmc_rlevel_rank, rank,0 ,0 ); +} + +static void display_rl_with_score (int if_num, +union cvmx_lmcx_rlevel_rankx lmc_rlevel_rank, +int rank,int score) +{ +do_display_rl (if_num, lmc_rlevel_rank, rank,1 , score); +} + +static void display_rl_with_final (int if_num, +union cvmx_lmcx_rlevel_rankx lmc_rlevel_rank, +int rank) +{ +do_display_rl (if_num, lmc_rlevel_rank, rank,4 ,0 ); +} + +static void display_rl_with_computed (int if_num, +union cvmx_lmcx_rlevel_rankx + lmc_rlevel_rank,int rank,int score) +{ +do_display_rl (if_num, lmc_rlevel_rank, rank,9 , score); +} + +// flag values +#define WITH_RODT_BLANK 0 +#define WITH_RODT_SKIPPING 1 +#define WITH_RODT_BESTROW 2 +#define WITH_RODT_BESTSCORE 3 +// control +#define SKIP_SKIPPING 1 + +static const char *with_rodt_canned_msgs[4 ] = { +" " ,"SKIPPING " ,"BEST ROW " ,"BEST SCORE" +}; + +static void display_rl_with_rodt (int if_num, +union cvmx_lmcx_rlevel_rankx lmc_rlevel_rank, +int rank,int score, +int nom_ohms,int rodt_ohms,int flag) +{ +const char *msg_buf; +char set_buf[20 ]; + +#if SKIP_SKIPPING +if (flag ==WITH_RODT_SKIPPING ) +return ; +#endif + + msg_buf = with_rodt_canned_msgs[flag]; +if (nom_ohms <0 ) { +snprintf (set_buf,sizeof (set_buf)," RODT %3d " , + rodt_ohms); + }else { +snprintf (set_buf,sizeof (set_buf),"NOM %3d RODT %3d" , nom_ohms, + rodt_ohms); + } + +debug ("N0.LMC%d.R%d: Rlevel %s %s : %5d %5d %5d %5d %5d %5d %5d %5d %5d (%d)\n" , + if_num, rank, set_buf, msg_buf, lmc_rlevel_rank.s.byte8, + lmc_rlevel_rank.s.byte7, lmc_rlevel_rank.s.byte6, + lmc_rlevel_rank.s.byte5, lmc_rlevel_rank.s.byte4, + lmc_rlevel_rank.s.byte3, lmc_rlevel_rank.s.byte2, + lmc_rlevel_rank.s.byte1, lmc_rlevel_rank.s.byte0, score); +} + +static void do_display_wl (int if_num, +union cvmx_lmcx_wlevel_rankx lmc_wlevel_rank, +int rank,int flags) +{ +char *msg_buf; +char hex_buf[20 ]; + +if (flags &WITH_FINAL ) { + msg_buf =" FINAL SETTINGS " ; + }else { +snprintf (hex_buf,sizeof (hex_buf),"0x%016llX" , + (unsigned long long )lmc_wlevel_rank.u64); + msg_buf = hex_buf; + } + +debug ("N0.LMC%d.R%d: Wlevel Rank %#4x, %s : %5d %5d %5d %5d %5d %5d %5d %5d %5d\n" , + if_num, rank, lmc_wlevel_rank.s.status, msg_buf, + lmc_wlevel_rank.s.byte8, lmc_wlevel_rank.s.byte7, + lmc_wlevel_rank.s.byte6, lmc_wlevel_rank.s.byte5, + lmc_wlevel_rank.s.byte4, lmc_wlevel_rank.s.byte3, + lmc_wlevel_rank.s.byte2, lmc_wlevel_rank.s.byte1, + lmc_wlevel_rank.s.byte0); +} + +static void display_wl (int if_num, +union cvmx_lmcx_wlevel_rankx lmc_wlevel_rank,int rank) +{ +do_display_wl (if_num, lmc_wlevel_rank, rank,WITH_NOTHING ); +} + +static void display_wl_with_final (int if_num, +union cvmx_lmcx_wlevel_rankx lmc_wlevel_rank, +int rank) +{ +do_display_wl (if_num, lmc_wlevel_rank, rank,WITH_FINAL ); +} + +// pretty-print bitmask adjuster +static u64 ppbm (u64 bm) +{ +if (bm !=0ul ) { +while ((bm &0x0fful ) ==0ul ) + bm >>=4 ; + } + +return bm; +} + +// xlate PACKED index to UNPACKED index to use with rlevel_byte +#define XPU (i, e) (((i) < 4) ? (i) : (((i) < 8) ? (i) + (e) : 4)) +// xlate UNPACKED index to PACKED index to use with rlevel_bitmask +#define XUP (i, e) (((i) < 4) ? (i) : (e) ? (((i) > 4) ? (i) - 1 : 8) : (i)) + +// flag values +#define WITH_WL_BITMASKS 0 +#define WITH_RL_BITMASKS 1 +#define WITH_RL_MASK_SCORES 2 +#define WITH_RL_SEQ_SCORES 3 + +static void do_display_bm (int if_num,int rank,void *bm, +int flags,int ecc) +{ +if (flags ==WITH_WL_BITMASKS ) { +// wlevel_bitmask array in PACKED index order, so just +// print them +int *bitmasks = (int *)bm; + +debug ("N0.LMC%d.R%d: Wlevel Debug Bitmasks : %05x %05x %05x %05x %05x %05x %05x %05x %05x\n" , + if_num, rank, bitmasks[8 ], bitmasks[7 ], bitmasks[6 ], + bitmasks[5 ], bitmasks[4 ], bitmasks[3 ], bitmasks[2 ], + bitmasks[1 ], bitmasks[0 ] + ); + }else if (flags ==WITH_RL_BITMASKS ) { +// rlevel_bitmask array in PACKED index order, so just +// print them +struct rlevel_bitmask *rlevel_bitmask = + (struct rlevel_bitmask *)bm; + +debug ("N0.LMC%d.R%d: Rlevel Debug Bitmasks 8:0 : %05llx %05llx %05llx %05llx %05llx %05llx %05llx %05llx %05llx\n" , + if_num, rank,ppbm (rlevel_bitmask[8 ].bm), +ppbm (rlevel_bitmask[7 ].bm),ppbm (rlevel_bitmask[6 ].bm), +ppbm (rlevel_bitmask[5 ].bm),ppbm (rlevel_bitmask[4 ].bm), +ppbm (rlevel_bitmask[3 ].bm),ppbm (rlevel_bitmask[2 ].bm), +ppbm (rlevel_bitmask[1 ].bm),ppbm (rlevel_bitmask[0 ].bm) + ); + }else if (flags ==WITH_RL_MASK_SCORES ) { +// rlevel_bitmask array in PACKED index order, so just +// print them +struct rlevel_bitmask *rlevel_bitmask = + (struct rlevel_bitmask *)bm; + +debug ("N0.LMC%d.R%d: Rlevel Debug Bitmask Scores 8:0 : %5d %5d %5d %5d %5d %5d %5d %5d %5d\n" , + if_num, rank, rlevel_bitmask[8 ].errs, + rlevel_bitmask[7 ].errs, rlevel_bitmask[6 ].errs, + rlevel_bitmask[5 ].errs, rlevel_bitmask[4 ].errs, + rlevel_bitmask[3 ].errs, rlevel_bitmask[2 ].errs, + rlevel_bitmask[1 ].errs, rlevel_bitmask[0 ].errs); + }else if (flags ==WITH_RL_SEQ_SCORES ) { +// rlevel_byte array in UNPACKED index order, so xlate +// and print them +struct rlevel_byte_data *rlevel_byte = + (struct rlevel_byte_data *)bm; + +debug ("N0.LMC%d.R%d: Rlevel Debug Non-seq Scores 8:0 : %5d %5d %5d %5d %5d %5d %5d %5d %5d\n" , + if_num, rank, rlevel_byte[XPU (8 , ecc)].sqerrs, + rlevel_byte[XPU (7 , ecc)].sqerrs, + rlevel_byte[XPU (6 , ecc)].sqerrs, + rlevel_byte[XPU (5 , ecc)].sqerrs, + rlevel_byte[XPU (4 , ecc)].sqerrs, + rlevel_byte[XPU (3 , ecc)].sqerrs, + rlevel_byte[XPU (2 , ecc)].sqerrs, + rlevel_byte[XPU (1 , ecc)].sqerrs, + rlevel_byte[XPU (0 , ecc)].sqerrs); + } +} + +static void display_wl_bm (int if_num,int rank,int *bitmasks) +{ +do_display_bm (if_num, rank, (void *)bitmasks,WITH_WL_BITMASKS ,0 ); +} + +static void display_rl_bm (int if_num,int rank, +struct rlevel_bitmask *bitmasks,int ecc_ena) +{ +do_display_bm (if_num, rank, (void *)bitmasks,WITH_RL_BITMASKS , + ecc_ena); +} + +static void display_rl_bm_scores (int if_num,int rank, +struct rlevel_bitmask *bitmasks,int ecc_ena) +{ +do_display_bm (if_num, rank, (void *)bitmasks,WITH_RL_MASK_SCORES , + ecc_ena); +} + +static void display_rl_seq_scores (int if_num,int rank, +struct rlevel_byte_data *bytes,int ecc_ena) +{ +do_display_bm (if_num, rank, (void *)bytes,WITH_RL_SEQ_SCORES , ecc_ena); +} + +#define RODT_OHMS_COUNT 8 +#define RTT_NOM_OHMS_COUNT 8 +#define RTT_NOM_TABLE_COUNT 8 +#define RTT_WR_OHMS_COUNT 8 +#define DIC_OHMS_COUNT 3 +#define DRIVE_STRENGTH_COUNT 15 + +static unsigned char ddr4_rodt_ohms[RODT_OHMS_COUNT ] = { +0 ,40 ,60 ,80 ,120 ,240 ,34 ,48 }; +static unsigned char ddr4_rtt_nom_ohms[RTT_NOM_OHMS_COUNT ] = { +0 ,60 ,120 ,40 ,240 ,48 ,80 ,34 }; +static unsigned char ddr4_rtt_nom_table[RTT_NOM_TABLE_COUNT ] = { +0 ,4 ,2 ,6 ,1 ,5 ,3 ,7 }; +// setting HiZ ohms to 99 for computed vref +static unsigned char ddr4_rtt_wr_ohms[RTT_WR_OHMS_COUNT ] = { +0 ,120 ,240 ,99 ,80 }; +static unsigned char ddr4_dic_ohms[DIC_OHMS_COUNT ] = {34 ,48 }; +static short ddr4_drive_strength[DRIVE_STRENGTH_COUNT ] = { +0 ,0 ,26 ,30 ,34 ,40 ,48 ,68 ,0 ,0 ,0 ,0 ,0 ,0 ,0 }; +static short ddr4_dqx_strength[DRIVE_STRENGTH_COUNT ] = { +0 ,24 ,27 ,30 ,34 ,40 ,48 ,60 ,0 ,0 ,0 ,0 ,0 ,0 ,0 }; +struct impedence_values ddr4_impedence_val = { + .rodt_ohms = ddr4_rodt_ohms, + .rtt_nom_ohms = ddr4_rtt_nom_ohms, + .rtt_nom_table = ddr4_rtt_nom_table, + .rtt_wr_ohms = ddr4_rtt_wr_ohms, + .dic_ohms = ddr4_dic_ohms, + .drive_strength = ddr4_drive_strength, + .dqx_strength = ddr4_dqx_strength, +}; + +static unsigned char ddr3_rodt_ohms[RODT_OHMS_COUNT ] = { +0 ,20 ,30 ,40 ,60 ,120 ,0 ,0 }; +static unsigned char ddr3_rtt_nom_ohms[RTT_NOM_OHMS_COUNT ] = { +0 ,60 ,120 ,40 ,20 ,30 ,0 ,0 }; +static unsigned char ddr3_rtt_nom_table[RTT_NOM_TABLE_COUNT ] = { +0 ,2 ,1 ,3 ,5 ,4 ,0 ,0 }; +static unsigned char ddr3_rtt_wr_ohms[RTT_WR_OHMS_COUNT ] = {0 ,60 ,120 }; +static unsigned char ddr3_dic_ohms[DIC_OHMS_COUNT ] = {40 ,34 }; +static short ddr3_drive_strength[DRIVE_STRENGTH_COUNT ] = { +0 ,24 ,27 ,30 ,34 ,40 ,48 ,60 ,0 ,0 ,0 ,0 ,0 ,0 ,0 }; +static struct impedence_values ddr3_impedence_val = { + .rodt_ohms = ddr3_rodt_ohms, + .rtt_nom_ohms = ddr3_rtt_nom_ohms, + .rtt_nom_table = ddr3_rtt_nom_table, + .rtt_wr_ohms = ddr3_rtt_wr_ohms, + .dic_ohms = ddr3_dic_ohms, + .drive_strength = ddr3_drive_strength, + .dqx_strength = ddr3_drive_strength, +}; + +static u64 hertz_to_psecs (u64 hertz) +{ +/* Clock in psecs */ +return divide_nint ((u64 )1000 *1000 *1000 *1000 , hertz); +} + +#define DIVIDEND_SCALE 1000/* Scale to avoid rounding error. */ + +static u64 psecs_to_mts (u64 psecs) +{ +return divide_nint (divide_nint ((u64)(2 *1000000 *DIVIDEND_SCALE ), + psecs),DIVIDEND_SCALE ); +} + +#define WITHIN (v, b, m) (((v) >= ((b) - (m))) && ((v) <= ((b) + (m)))) + +static unsigned long pretty_psecs_to_mts (u64 psecs) +{ +u64 ret =0 ;// default to error + +if (WITHIN (psecs,2500 ,1 )) + ret =800 ; +else if (WITHIN (psecs,1875 ,1 )) + ret =1066 ; +else if (WITHIN (psecs,1500 ,1 )) + ret =1333 ; +else if (WITHIN (psecs,1250 ,1 )) + ret =1600 ; +else if (WITHIN (psecs,1071 ,1 )) + ret =1866 ; +else if (WITHIN (psecs,937 ,1 )) + ret =2133 ; +else if (WITHIN (psecs,833 ,1 )) + ret =2400 ; +else if (WITHIN (psecs,750 ,1 )) + ret =2666 ; +return ret; +} + +static u64 mts_to_hertz (u64 mts) +{ +return ((mts *1000 *1000 ) /2 ); +} + +static int compute_rc3x (int64_t tclk_psecs) +{ +long speed; +long tclk_psecs_min, tclk_psecs_max; +long data_rate_mhz, data_rate_mhz_min, data_rate_mhz_max; +int rc3x; + +#define ENCODING_BASE 1240 + + data_rate_mhz =psecs_to_mts (tclk_psecs); + +/* +* 2400 MT/s is a special case. Using integer arithmetic it rounds +* from 833 psecs to 2401 MT/s. Force it to 2400 to pick the +* proper setting from the table. +*/ +if (tclk_psecs ==833 ) + data_rate_mhz =2400 ; + +for (speed =ENCODING_BASE ; speed <3200 ; speed +=20 ) { +int error =0 ; + +/* Clock in psecs */ + tclk_psecs_min =hertz_to_psecs (mts_to_hertz (speed +00 )); +/* Clock in psecs */ + tclk_psecs_max =hertz_to_psecs (mts_to_hertz (speed +18 )); + + data_rate_mhz_min =psecs_to_mts (tclk_psecs_min); + data_rate_mhz_max =psecs_to_mts (tclk_psecs_max); + +/* Force alingment to multiple to avound rounding errors. */ + data_rate_mhz_min = ((data_rate_mhz_min +18 ) /20 ) *20 ; + data_rate_mhz_max = ((data_rate_mhz_max +18 ) /20 ) *20 ; + + error += (speed +00 != data_rate_mhz_min); + error += (speed +20 != data_rate_mhz_max); + + rc3x = (speed -ENCODING_BASE ) /20 ; + +if (data_rate_mhz <= (speed +20 )) +break ; + } + +return rc3x; +} + +/* +* static global variables needed, so that functions (loops) can be +* restructured from the main huge function. Its not elegant, but the +* only way to break the original functions like init_octeon3_ddr3_interface() +* into separate logical smaller functions with less indentation levels. +*/ +static int if_num __section(".data"); +static u32 if_mask __section(".data"); +static int ddr_hertz __section(".data"); + +static struct ddr_conf *ddr_conf __section(".data"); +static const struct dimm_odt_config *odt_1rank_config __section(".data"); +static const struct dimm_odt_config *odt_2rank_config __section(".data"); +static const struct dimm_odt_config *odt_4rank_config __section(".data"); +static struct dimm_config *dimm_config_table __section(".data"); +static const struct dimm_odt_config *odt_config __section(".data"); +static const struct ddr3_custom_config *c_cfg __section(".data"); + +static int odt_idx __section(".data"); + +static ulong tclk_psecs __section(".data"); +static ulong eclk_psecs __section(".data"); + +static int row_bits __section(".data"); +static int col_bits __section(".data"); +static int num_banks __section(".data"); +static int num_ranks __section(".data"); +static int dram_width __section(".data"); +static int dimm_count __section(".data"); +/* Accumulate and report all the errors before giving up */ +static int fatal_error __section(".data"); +/* Flag that indicates safe DDR settings should be used */ +static int safe_ddr_flag __section(".data"); +/* Octeon II Default: 64bit interface width */ +static int if_64b __section(".data"); +static int if_bytemask __section(".data"); +static u32 mem_size_mbytes __section(".data"); +static unsigned int didx __section(".data"); +static int bank_bits __section(".data"); +static int bunk_enable __section(".data"); +static int rank_mask __section(".data"); +static int column_bits_start __section(".data"); +static int row_lsb __section(".data"); +static int pbank_lsb __section(".data"); +static int use_ecc __section(".data"); +static int mtb_psec __section(".data"); +static short ftb_dividend __section(".data"); +static short ftb_divisor __section(".data"); +static int taamin __section(".data"); +static int tckmin __section(".data"); +static int cl __section(".data"); +static int min_cas_latency __section(".data"); +static int max_cas_latency __section(".data"); +static int override_cas_latency __section(".data"); +static int ddr_rtt_nom_auto __section(".data"); +static int ddr_rodt_ctl_auto __section(".data"); + +static int spd_addr __section(".data"); +static int spd_org __section(".data"); +static int spd_banks __section(".data"); +static int spd_rdimm __section(".data"); +static int spd_dimm_type __section(".data"); +static int spd_ecc __section(".data"); +static u32 spd_cas_latency __section(".data"); +static int spd_mtb_dividend __section(".data"); +static int spd_mtb_divisor __section(".data"); +static int spd_tck_min __section(".data"); +static int spd_taa_min __section(".data"); +static int spd_twr __section(".data"); +static int spd_trcd __section(".data"); +static int spd_trrd __section(".data"); +static int spd_trp __section(".data"); +static int spd_tras __section(".data"); +static int spd_trc __section(".data"); +static int spd_trfc __section(".data"); +static int spd_twtr __section(".data"); +static int spd_trtp __section(".data"); +static int spd_tfaw __section(".data"); +static int spd_addr_mirror __section(".data"); +static int spd_package __section(".data"); +static int spd_rawcard __section(".data"); +static int spd_rawcard_aorb __section(".data"); +static int spd_rdimm_registers __section(".data"); +static int spd_thermal_sensor __section(".data"); + +static int is_stacked_die __section(".data"); +static int is_3ds_dimm __section(".data"); +// 3DS: logical ranks per package rank +static int lranks_per_prank __section(".data"); +// 3DS: logical ranks bits +static int lranks_bits __section(".data"); +// in Mbits; only used for 3DS +static int die_capacity __section(".data"); + +static enum ddr_type ddr_type __section(".data"); + +static int twr __section(".data"); +static int trcd __section(".data"); +static int trrd __section(".data"); +static int trp __section(".data"); +static int tras __section(".data"); +static int trc __section(".data"); +static int trfc __section(".data"); +static int twtr __section(".data"); +static int trtp __section(".data"); +static int tfaw __section(".data"); + +static int ddr4_tckavgmin __section(".data"); +static int ddr4_tckavgmax __section(".data"); +static int ddr4_trdcmin __section(".data"); +static int ddr4_trpmin __section(".data"); +static int ddr4_trasmin __section(".data"); +static int ddr4_trcmin __section(".data"); +static int ddr4_trfc1min __section(".data"); +static int ddr4_trfc2min __section(".data"); +static int ddr4_trfc4min __section(".data"); +static int ddr4_tfawmin __section(".data"); +static int ddr4_trrd_smin __section(".data"); +static int ddr4_trrd_lmin __section(".data"); +static int ddr4_tccd_lmin __section(".data"); + +static int wl_mask_err __section(".data"); +static int wl_loops __section(".data"); +static int default_rtt_nom[4] __section(".data"); +static int dyn_rtt_nom_mask __section(".data"); +static struct impedence_values *imp_val __section(".data"); +static char default_rodt_ctl __section(".data"); +// default to disabled (ie, try LMC restart, not chip reset) +static int ddr_disable_chip_reset __section(".data"); +static const char *dimm_type_name __section(".data"); +static int match_wl_rtt_nom __section(".data"); + +struct hwl_alt_by_rank { +u16 hwl_alt_mask;// mask of bytelanes with alternate +u16 hwl_alt_delay[9 ];// bytelane alternate avail if mask=1 +}; + +static struct hwl_alt_by_rank hwl_alts[4] __section(".data"); + +#define DEFAULT_INTERNAL_VREF_TRAINING_LIMIT 3 // was: 5 +static int internal_retries __section(".data"); + +static int deskew_training_errors __section(".data"); +static struct deskew_counts deskew_training_results __section(".data"); +static int disable_deskew_training __section(".data"); +static int restart_if_dsk_incomplete __section(".data"); +static int dac_eval_retries __section(".data"); +static int dac_settings[9] __section(".data"); +static int num_samples __section(".data"); +static int sample __section(".data"); +static int lane __section(".data"); +static int last_lane __section(".data"); +static int total_dac_eval_retries __section(".data"); +static int dac_eval_exhausted __section(".data"); + +#define DEFAULT_DAC_SAMPLES 7 // originally was 5 +#define DAC_RETRIES_LIMIT 2 + +struct bytelane_sample { +s16 bytes[DEFAULT_DAC_SAMPLES ]; +}; + +static struct bytelane_sample lanes[9] __section(".data"); + +static char disable_sequential_delay_check __section(".data"); +static int wl_print __section(".data"); + +static int enable_by_rank_init __section(".data"); +static int saved_rank_mask __section(".data"); +static int by_rank __section(".data"); +static struct deskew_data rank_dsk[4] __section(".data"); +static struct dac_data rank_dac[4] __section(".data"); + +// todo: perhaps remove node@some time completely? +static int node __section(".data"); +static int base_cl __section(".data"); + +/* Parameters from DDR3 Specifications */ +#define DDR3_TREFI 7800000/* 7.8 us */ +#define DDR3_ZQCS 80000ull/* 80 ns */ +#define DDR3_ZQCS_INTERNAL 1280000000ull/* 128ms/100 */ +#define DDR3_TCKE 5000/* 5 ns */ +#define DDR3_TMRD 4/* 4 nCK */ +#define DDR3_TDLLK 512/* 512 nCK */ +#define DDR3_TMPRR 1/* 1 nCK */ +#define DDR3_TWLMRD 40/* 40 nCK */ +#define DDR3_TWLDQSEN 25/* 25 nCK */ + +/* Parameters from DDR4 Specifications */ +#define DDR4_TMRD 8/* 8 nCK */ +#define DDR4_TDLLK 768/* 768 nCK */ + +static void lmc_config (struct ddr_priv *priv) +{ +union cvmx_lmcx_config cfg; +char *s; + + cfg.u64 =0 ; + + cfg.cn78xx.ecc_ena = use_ecc; + cfg.cn78xx.row_lsb =encode_row_lsb_ddr3 (row_lsb); + cfg.cn78xx.pbank_lsb =encode_pbank_lsb_ddr3 (pbank_lsb); + + cfg.cn78xx.idlepower =0 ;/* Disabled */ + + s =lookup_env (priv,"ddr_idlepower" ); +if (s) + cfg.cn78xx.idlepower =simple_strtoul (s,NULL ,0 ); + + cfg.cn78xx.forcewrite =0 ;/* Disabled */ +/* Include memory reference address in the ECC */ + cfg.cn78xx.ecc_adr =1 ; + + s =lookup_env (priv,"ddr_ecc_adr" ); +if (s) + cfg.cn78xx.ecc_adr =simple_strtoul (s,NULL ,0 ); + + cfg.cn78xx.reset =0 ; + +/* +* Program LMC0_CONFIG[24:18], ref_zqcs_int(6:0) to +* RND-DN(tREFI/clkPeriod/512) Program LMC0_CONFIG[36:25], +* ref_zqcs_int(18:7) to +* RND-DN(ZQCS_Interval/clkPeriod/(512*128)). Note that this +* value should always be greater than 32, to account for +* resistor calibration delays. +*/ + + cfg.cn78xx.ref_zqcs_int = ((DDR3_TREFI / tclk_psecs /512 ) &0x7f ); + cfg.cn78xx.ref_zqcs_int |= + ((max (33ull , (DDR3_ZQCS_INTERNAL / (tclk_psecs /100 ) / + (512 *128 ))) &0xfff ) <<7 ); + + cfg.cn78xx.early_dqx =1 ;/* Default to enabled */ + + s =lookup_env (priv,"ddr_early_dqx" ); +if (!s) + s =lookup_env (priv,"ddr%d_early_dqx" , if_num); + +if (s) + cfg.cn78xx.early_dqx =simple_strtoul (s,NULL ,0 ); + + cfg.cn78xx.sref_with_dll =0 ; + + cfg.cn78xx.rank_ena = bunk_enable; + cfg.cn78xx.rankmask = rank_mask;/* Set later */ + cfg.cn78xx.mirrmask = (spd_addr_mirror <<1 | spd_addr_mirror <<3 ) & + rank_mask; +/* Set once and don't change it. */ + cfg.cn78xx.init_status = rank_mask; + cfg.cn78xx.early_unload_d0_r0 =0 ; + cfg.cn78xx.early_unload_d0_r1 =0 ; + cfg.cn78xx.early_unload_d1_r0 =0 ; + cfg.cn78xx.early_unload_d1_r1 =0 ; + cfg.cn78xx.scrz =0 ; +if (octeon_is_cpuid (OCTEON_CN70XX )) + cfg.cn78xx.mode32b =1 ;/* Read-only. Always 1. */ + cfg.cn78xx.mode_x4dev = (dram_width ==4 ) ?1 :0 ; + cfg.cn78xx.bg2_enable = ((ddr_type ==DDR4_DRAM ) && + (dram_width ==16 )) ?0 :1 ; + + s =lookup_env_ull (priv,"ddr_config" ); +if (s) + cfg.u64 =simple_strtoull (s,NULL ,0 ); +debug ("LMC_CONFIG : 0x%016llx\n" , + cfg.u64); +lmc_wr (priv,CVMX_LMCX_CONFIG (if_num), cfg.u64); +} + +static void lmc_control (struct ddr_priv *priv) +{ +union cvmx_lmcx_control ctrl; +char *s; + + ctrl.u64 =lmc_rd (priv,CVMX_LMCX_CONTROL (if_num)); + ctrl.s.rdimm_ena = spd_rdimm; + ctrl.s.bwcnt =0 ;/* Clear counter later */ +if (spd_rdimm) + ctrl.s.ddr2t = (safe_ddr_flag ?1 : c_cfg->ddr2t_rdimm); +else + ctrl.s.ddr2t = (safe_ddr_flag ?1 : c_cfg->ddr2t_udimm); + ctrl.s.pocas =0 ; + ctrl.s.fprch2 = (safe_ddr_flag ?2 : c_cfg->fprch2); + ctrl.s.throttle_rd = safe_ddr_flag ?1 :0 ; + ctrl.s.throttle_wr = safe_ddr_flag ?1 :0 ; + ctrl.s.inorder_rd = safe_ddr_flag ?1 :0 ; + ctrl.s.inorder_wr = safe_ddr_flag ?1 :0 ; + ctrl.s.elev_prio_dis = safe_ddr_flag ?1 :0 ; +/* discards writes to addresses that don't exist in the DRAM */ + ctrl.s.nxm_write_en =0 ; + ctrl.s.max_write_batch =8 ; + ctrl.s.xor_bank =1 ; + ctrl.s.auto_dclkdis =1 ; + ctrl.s.int_zqcs_dis =0 ; + ctrl.s.ext_zqcs_dis =0 ; + ctrl.s.bprch =1 ; + ctrl.s.wodt_bprch =1 ; + ctrl.s.rodt_bprch =1 ; + + s =lookup_env (priv,"ddr_xor_bank" ); +if (s) + ctrl.s.xor_bank =simple_strtoul (s,NULL ,0 ); + + s =lookup_env (priv,"ddr_2t" ); +if (s) + ctrl.s.ddr2t =simple_strtoul (s,NULL ,0 ); + + s =lookup_env (priv,"ddr_fprch2" ); +if (s) + ctrl.s.fprch2 =simple_strtoul (s,NULL ,0 ); + + s =lookup_env (priv,"ddr_bprch" ); +if (s) + ctrl.s.bprch =simple_strtoul (s,NULL ,0 ); + + s =lookup_env (priv,"ddr_wodt_bprch" ); +if (s) + ctrl.s.wodt_bprch =simple_strtoul (s,NULL ,0 ); + + s =lookup_env (priv,"ddr_rodt_bprch" ); +if (s) + ctrl.s.rodt_bprch =simple_strtoul (s,NULL ,0 ); + + s =lookup_env (priv,"ddr_int_zqcs_dis" ); +if (s) + ctrl.s.int_zqcs_dis =simple_strtoul (s,NULL ,0 ); + + s =lookup_env (priv,"ddr_ext_zqcs_dis" ); +if (s) + ctrl.s.ext_zqcs_dis =simple_strtoul (s,NULL ,0 ); + + s =lookup_env_ull (priv,"ddr_control" ); +if (s) + ctrl.u64 =simple_strtoull (s,NULL ,0 ); + +debug ("LMC_CONTROL : 0x%016llx\n" , + ctrl.u64); +lmc_wr (priv,CVMX_LMCX_CONTROL (if_num), ctrl.u64); +} + +static void lmc_timing_params0 (struct ddr_priv *priv) +{ +union cvmx_lmcx_timing_params0 tp0; +unsigned int trp_value; +char *s; + + tp0.u64 =lmc_rd (priv,CVMX_LMCX_TIMING_PARAMS0 (if_num)); + + trp_value =divide_roundup (trp, tclk_psecs) -1 ; +debug ("TIMING_PARAMS0[TRP]: NEW 0x%x, OLD 0x%x\n" , trp_value, + trp_value + + (unsigned int )(divide_roundup (max (4ull * tclk_psecs,7500ull ), + tclk_psecs)) -4 ); + s =lookup_env_ull (priv,"ddr_use_old_trp" ); +if (s) { +if (!!simple_strtoull (s,NULL ,0 )) { + trp_value += +divide_roundup (max (4ull * tclk_psecs,7500ull ), + tclk_psecs) -4 ; +debug ("TIMING_PARAMS0[trp]: USING OLD 0x%x\n" , + trp_value); + } + } + + tp0.cn78xx.txpr = +divide_roundup (max (5ull * tclk_psecs, trfc +10000ull ), +16 * tclk_psecs); + tp0.cn78xx.trp = trp_value &0x1f ; + tp0.cn78xx.tcksre = +divide_roundup (max (5ull * tclk_psecs,10000ull ), tclk_psecs) -1 ; + +if (ddr_type ==DDR4_DRAM ) { +int tzqinit =4 ;// Default to 4, for all DDR4 speed bins + + s =lookup_env (priv,"ddr_tzqinit" ); +if (s) + tzqinit =simple_strtoul (s,NULL ,0 ); + + tp0.cn78xx.tzqinit = tzqinit; +/* Always 8. */ + tp0.cn78xx.tzqcs =divide_roundup (128 * tclk_psecs, + (16 * tclk_psecs)); + tp0.cn78xx.tcke = +divide_roundup (max (3 * tclk_psecs, (ulong )DDR3_TCKE ), + tclk_psecs) -1 ; + tp0.cn78xx.tmrd = +divide_roundup ((DDR4_TMRD * tclk_psecs), tclk_psecs) -1 ; + tp0.cn78xx.tmod =25 ;/* 25 is the max allowed */ + tp0.cn78xx.tdllk =divide_roundup (DDR4_TDLLK ,256 ); + }else { + tp0.cn78xx.tzqinit = +divide_roundup (max (512ull * tclk_psecs,640000ull ), + (256 * tclk_psecs)); + tp0.cn78xx.tzqcs = +divide_roundup (max (64ull * tclk_psecs,DDR3_ZQCS ), + (16 * tclk_psecs)); + tp0.cn78xx.tcke =divide_roundup (DDR3_TCKE , tclk_psecs) -1 ; + tp0.cn78xx.tmrd = +divide_roundup ((DDR3_TMRD * tclk_psecs), tclk_psecs) -1 ; + tp0.cn78xx.tmod = +divide_roundup (max (12ull * tclk_psecs,15000ull ), + tclk_psecs) -1 ; + tp0.cn78xx.tdllk =divide_roundup (DDR3_TDLLK ,256 ); + } + + s =lookup_env_ull (priv,"ddr_timing_params0" ); +if (s) + tp0.u64 =simple_strtoull (s,NULL ,0 ); +debug ("TIMING_PARAMS0 : 0x%016llx\n" , + tp0.u64); +lmc_wr (priv,CVMX_LMCX_TIMING_PARAMS0 (if_num), tp0.u64); +} + +static void lmc_timing_params1 (struct ddr_priv *priv) +{ +union cvmx_lmcx_timing_params1 tp1; +unsigned int txp, temp_trcd, trfc_dlr; +char *s; + + tp1.u64 =lmc_rd (priv,CVMX_LMCX_TIMING_PARAMS1 (if_num)); + +/* .cn70xx. */ + tp1.s.tmprr =divide_roundup (DDR3_TMPRR * tclk_psecs, tclk_psecs) -1 ; + + tp1.cn78xx.tras =divide_roundup (tras, tclk_psecs) -1 ; + + temp_trcd =divide_roundup (trcd, tclk_psecs); +if (temp_trcd >15 ) { +debug ("TIMING_PARAMS1[trcd]: need extension bit for 0x%x\n" , + temp_trcd); + } +if (octeon_is_cpuid (OCTEON_CN78XX_PASS1_X ) && temp_trcd >15 ) { +/* +* Let .trcd=0 serve as a flag that the field has +* overflowed. Must use Additive Latency mode as a
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.28.0
Part of the diff is not shown here. View the raw message.
PATCH v3 7/9 ram: octeon: Add MIPS Octeon3 DDR4 support (part 3/3)
In reply to Stefan RoeseFrom: Aaron Williams <[email protected]>
This Octeon 3 DDR driver is ported from the 2013 Cavium / Marvell U-Boot repository. It currently supports DDR4 on Octeon 3. It can be later extended to support also DDR3 and Octeon 2 platforms.
Part 3 includes the DIMM SPD handling code and the Kconfig / Makefile integration.
---
Changes in v3:
- Remove "https://spdx.org/licenses" line
- Remove inclusion of "common.h"
drivers/ram/Kconfig | 1 + drivers/ram/Makefile | 2 + drivers/ram/octeon/Kconfig | 17 ++ drivers/ram/octeon/Makefile | 8 + drivers/ram/octeon/dimm_spd_eeprom.c | 407 +++++++++++++++++++++++++++ 5 files changed, 435 insertions(+) create mode 100644 drivers/ram/octeon/Kconfig create mode 100644 drivers/ram/octeon/Makefile create mode 100644 drivers/ram/octeon/dimm_spd_eeprom.c
drivers/ram/Kconfig +1 -0
@@ -76,3 +76,4 @@ config IMXRT_SDRAM source "drivers/ram/rockchip/Kconfig" source "drivers/ram/sifive/Kconfig" source "drivers/ram/stm32mp1/Kconfig" +source "drivers/ram/octeon/Kconfig"
drivers/ram/Makefile +2 -0
@@ -19,3 +19,5 @@ obj-$(CONFIG_K3_J721E_DDRSS) += k3-j721e/ obj-$(CONFIG_IMXRT_SDRAM) += imxrt_sdram.o obj-$(CONFIG_RAM_SIFIVE) += sifive/ + +obj-$(CONFIG_ARCH_OCTEON) += octeon/
drivers/ram/octeon/Kconfig new file +17 -0
@@ -0,0 +1,17 @@ +config RAM_OCTEON + bool "Ram drivers for Octeon SoCs" + depends on RAM && ARCH_OCTEON + default n + help + This enables support for RAM drivers for Octeon SoCs. + +if RAM_OCTEON + +config RAM_OCTEON_DDR4 + bool "Octeon III DDR4 RAM support" + default n + help + This enables support for DDR4 RAM suppoort for Octeon III. This does + not include support for Octeon CN70XX. + +endif # RAM_OCTEON
drivers/ram/octeon/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (c) 2020 Marvell, Inc. +# + +obj-$(CONFIG_RAM_OCTEON_DDR4) += octeon_ddr.o +obj-$(CONFIG_RAM_OCTEON_DDR4) += octeon3_lmc.o +obj-y += dimm_spd_eeprom.o
drivers/ram/octeon/dimm_spd_eeprom.c new file +407 -0
407 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH v3 8/9 mips: octeon: dram.c: Add RAM driver support
In reply to Stefan RoeseThis patch adds the initialization call for the Octeon RAM driver to the Octeon platforms code. So if enabled via Kconfig, the DDR driver will be called and the RAM will be configured and used. If the RAM driver is not enabled, the L2 cache is still used as RAM.
---
(no changes since v2)
Changes in v2:
- Only map 256MiB of RAM in U-Boot and print total size as well
- Add year to copyright line
arch/mips/mach-octeon/dram.c | 72 ++++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 8 deletions(-)
arch/mips/mach-octeon/dram.c +64 -8
@@ -1,28 +1,84 @@// SPDX-License-Identifier: GPL-2.0+ /* -* Copyright (C) Stefan Roese <[email protected]> +* Copyright (C) 2020 Stefan Roese <[email protected]> */ +#include <config.h> #include <dm.h> #include <ram.h> #include <asm/global_data.h> #include <linux/compat.h> +#include <display_options.h> DECLARE_GLOBAL_DATA_PTR ; +#define UBOOT_RAM_SIZE_MAX 0x10000000ULL +int dram_init (void ) { -/* -* No DDR init yet -> run in L2 cache -*/ - gd->ram_size = (4 <<20 ); - gd->bd->bi_dram[0 ].size = gd->ram_size; - gd->bd->bi_dram[1 ].size =0 ; +if (IS_ENABLED (CONFIG_RAM_OCTEON )) { +struct ram_info ram; +struct udevice *dev; +int ret; + + ret =uclass_get_device (UCLASS_RAM ,0 , &dev); +if (ret) { +debug ("DRAM init failed: %d\n" , ret); +return ret; + } + + ret =ram_get_info (dev, &ram); +if (ret) { +debug ("Cannot get DRAM size: %d\n" , ret); +return ret; + } + + gd->ram_size =min_t (size_t, ram.size,UBOOT_RAM_SIZE_MAX ); +debug ("SDRAM base=%lx, size=%lx\n" , + (unsigned long )ram.base, (unsigned long )ram.size); + }else { +/* +* No DDR init yet -> run in L2 cache +*/ + gd->ram_size = (4 <<20 ); + gd->bd->bi_dram[0 ].size = gd->ram_size; + gd->bd->bi_dram[1 ].size =0 ; + }return 0 ; } +void board_add_ram_info (int use_default) +{ +if (IS_ENABLED (CONFIG_RAM_OCTEON )) { +struct ram_info ram; +struct udevice *dev; +int ret; + + ret =uclass_get_device (UCLASS_RAM ,0 , &dev); +if (ret) { +debug ("DRAM init failed: %d\n" , ret); +return ; + } + + ret =ram_get_info (dev, &ram); +if (ret) { +debug ("Cannot get DRAM size: %d\n" , ret); +return ; + } + +printf (" (" ); +print_size (ram.size," total)" ); + } +} +ulong board_get_usable_ram_top (ulong total_size) { -return gd->ram_top; +if (IS_ENABLED (CONFIG_RAM_OCTEON )) { +/* Map a maximum of 256MiB - return not size but address */ +return CONFIG_SYS_SDRAM_BASE +min (gd->ram_size, +UBOOT_RAM_SIZE_MAX ); + }else { +return gd->ram_top; + } }
Signature · 1 line
2.28.0
PATCH v3 9/9 mips: octeon: octeon_ebb7304: Add DDR4 support
In reply to Stefan RoeseThis patch adds the board specific configuration (struct) for the Octeon 3 EBB7304 EVK. This struct is ported from the 2013er Cavium / Marvell U-Boot repository. Also, the Octeon RAM driver is enabled in the board defconfig for its usage.
Tested with one and two DIMMs on the EBB7304 EVK (8 & 16 GiB).
---
(no changes since v1)
board/Marvell/octeon_ebb7304/board.c | 25 +- board/Marvell/octeon_ebb7304/board_ddr.h | 447 +++++++++++++++++++++++ configs/octeon_ebb7304_defconfig | 3 + include/configs/octeon_common.h | 11 +- 4 files changed, 479 insertions(+), 7 deletions(-) create mode 100644 board/Marvell/octeon_ebb7304/board_ddr.h
board/Marvell/octeon_ebb7304/board.c +21 -4
@@ -3,7 +3,24 @@* Copyright (C) 2020 Stefan Roese <[email protected]> */ -/* -* Nothing included right now. Code will be added in follow-up -* patches. -*/ +#include <common.h> +#include <dm.h> +#include <ram.h> + +#include <mach/octeon_ddr.h> + +#include "board_ddr.h" + +#define EBB7304_DEF_DRAM_FREQ 800 + +static struct ddr_conf board_ddr_conf[] = { +OCTEON_EBB7304_DDR_CONFIGURATION +}; + +struct ddr_conf *octeon_ddr_conf_table_get (int *count,int *def_ddr_freq) +{ + *count =ARRAY_SIZE (board_ddr_conf); + *def_ddr_freq =EBB7304_DEF_DRAM_FREQ ; + +return board_ddr_conf; +}
board/Marvell/octeon_ebb7304/board_ddr.h new file +447 -0
447 lines not on this page · raw message
configs/octeon_ebb7304_defconfig +3 -0
@@ -38,6 +38,9 @@ CONFIG_SPI_FLASH_STMICRO=y # CONFIG_NETDEVICES is not set CONFIG_PCI=y CONFIG_DM_PCI=y +CONFIG_RAM=y +CONFIG_RAM_OCTEON=y +CONFIG_RAM_OCTEON_DDR4=y CONFIG_DEBUG_UART_SHIFT=3 CONFIG_DEBUG_UART_ANNOUNCE=y CONFIG_SYS_NS16550=y
include/configs/octeon_common.h +8 -3
@@ -7,13 +7,18 @@#ifndef __OCTEON_COMMON_H__#define __OCTEON_COMMON_H__ -/* No DDR init yet -> run in L2 cache with limited resources */ +#if defined(CONFIG_RAM_OCTEON ) +#define CONFIG_SYS_MALLOC_LEN (16 << 20) +#define CONFIG_SYS_INIT_SP_OFFSET 0x20100000 +#else +/* No DDR init -> run in L2 cache with limited resources */ #define CONFIG_SYS_MALLOC_LEN (256 << 10) +#define CONFIG_SYS_INIT_SP_OFFSET 0x00180000 +#endif +#define CONFIG_SYS_SDRAM_BASE 0xffffffff80000000#define CONFIG_SYS_MONITOR_BASE CONFIG_SYS_TEXT_BASE#define CONFIG_SYS_LOAD_ADDR (CONFIG_SYS_SDRAM_BASE + (1 << 20)) -#define CONFIG_SYS_INIT_SP_OFFSET 0x180000 -#endif /* __OCTEON_COMMON_H__ */
Signature · 1 line
2.28.0
v3 cover mips: Add Octeon DDR4 init code
In reply to Stefan RoeseAm Mittwoch, den 02.09.2020, 08:29 +0200 schrieb Stefan Roese:
Quoted 98 lines
This patch adds the DDR4 init code. It is ported from the 2013 Cavium / Marvell U-Boot version with no functional change. This was done intentionally, as this code is very large and complex and is known to work on many boards "as-is". So any functional change might have introduced (hidden) incompatibilities.
Please note that the code has undergone many hours (read many days) of code cleanup and restructuring. Unfortunately its still not 100% checkpatch clean, as some warnings and checks can practically not be removed / addresses, like these here:
CHECK: Prefer kernel type 's8' over '
int8_t'
-> 's8' can't be used on MIPS platforms, as its a register macroor:
WARNING: Too many leading tabs - consider code refactoring
+ while (xor != 0) {
-> I've restructured the code already and its very hard to remove all
these "Too many leading tabs" warnings.or other warnings / checks.
But compared to the original code in much better shape (checkpatch wise). I would have liked to include a checkpatch summary in this cover- letter, showing the "before" (original code) and "after" (this code) numbers, but unfortunately currently running checkpatch on the really big file (
octeon3_lmc.c) leads to many false errors. I can only suspect that checkpatch has an issue handling this big file because of its size.This code is tested on the Octeon3 EBB7304 EVK and works without any known issues with 1 or 2 DDR4 DIMM configurations (8 & 16 GiB).
Thanks,
StefanChanges in v3:
- Remove "https://spdx.org/licenses" line
- Move multiple comment blocks into one
- Remove "https://spdx.org/licenses" line
- Remove "https://spdx.org/licenses" line
- Remove inclusion of "common.h"
- Remove duplicate comment line
- Remove "test-only" comment (leftover after cleanup)
- Remove "https://spdx.org/licenses" line
- Remove inclusion of "common.h"
- Remove all internal defines that resulted in dead code, as they have never been changed via external config files orKconfig. This results in a smaller (~13KiB of source code saved, > 450 lines removed) and much cleaner code base.
- Remove "https://spdx.org/licenses" line
- Remove "https://spdx.org/licenses" line
- Remove inclusion of "common.h"Changes in v2:
- Some unsupported Octeon families removed (only Octeon 2 & 3 supported in general)
- Some unsupported Octeon families removed (only Octeon 2 & 3 supported in general)
- Use readq/writeq in cvmx_read64_uint64/cvmx_write64_uint64 instead of readl/writel
- Don't re-init after relocation
- Some unsupported Octeon families removed (only Octeon 2 & 3 supported in general)
- Only map 256MiB of RAM in U-Boot and print total size as well
- Add year to copyright lineAaron Williams (6):
mips: octeon: Addocteon-model.hheader
mips: octeon Addcvmx/cvmx-lmcx-defs.hheader
mips: octeon: Addocteon_ddr.hheader
ram: octeon: Add MIPS Octeon3 DDR4 support (part 1/3)
ram: octeon: Add MIPS Octeon3 DDR4 support (part 2/3)
ram: octeon: Add MIPS Octeon3 DDR4 support (part 3/3)Stefan Roese (3):
mips: octeon: dts: mrvl,cn73xx.dtsi: Add memory controller DT node
mips: octeon:dram.c: Add RAM driver support
mips: octeon:octeon_ebb7304: Add DDR4 supportarch/mips/dts/mrvl,cn73xx.dtsi | 17 + arch/mips/mach-octeon/dram.c | 72 +- .../include/mach/cvmx/cvmx-lmcx-defs.h | 4574 +++++++ .../mach-octeon/include/mach/octeon-model.h | 313 + .../mach-octeon/include/mach/octeon_ddr.h | 982 ++ board/Marvell/octeon_ebb7304/board.c | 25 +- board/Marvell/octeon_ebb7304/board_ddr.h | 447 + configs/octeon_ebb7304_defconfig | 3 + drivers/ram/Kconfig | 1 + drivers/ram/Makefile | 2 + drivers/ram/octeon/Kconfig | 17 + drivers/ram/octeon/Makefile | 8 + drivers/ram/octeon/dimm_spd_eeprom.c | 407 + drivers/ram/octeon/octeon3_lmc.c | 11030 ++++++++++++++++ drivers/ram/octeon/octeon_ddr.c | 2728 ++++ include/configs/octeon_common.h | 11 +- 16 files changed, 20622 insertions(+), 15 deletions(-) create mode 100644 arch/mips/mach-octeon/include/mach/cvmx/cvmx-lmcx-defs.h
Quoted 9 lines
create mode 100644 arch/mips/mach-octeon/include/mach/octeon-model.h create mode 100644 arch/mips/mach-octeon/include/mach/octeon_ddr.h create mode 100644 board/Marvell/octeon_ebb7304/board_ddr.h create mode 100644 drivers/ram/octeon/Kconfig create mode 100644 drivers/ram/octeon/Makefile create mode 100644 drivers/ram/octeon/dimm_spd_eeprom.c create mode 100644 drivers/ram/octeon/octeon3_lmc.c create mode 100644 drivers/ram/octeon/octeon_ddr.c
series applied to u-boot-mips/next, thanks.
Signature · 1 line
- Daniel