Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1 | /* Intel Sandy Bridge -EN/-EP/-EX Memory Controller kernel module |
| 2 | * |
| 3 | * This driver supports the memory controllers found on the Intel |
| 4 | * processor family Sandy Bridge. |
| 5 | * |
| 6 | * This file may be distributed under the terms of the |
| 7 | * GNU General Public License version 2 only. |
| 8 | * |
| 9 | * Copyright (c) 2011 by: |
Mauro Carvalho Chehab | 37e59f8 | 2014-02-07 08:03:07 -0200 | [diff] [blame] | 10 | * Mauro Carvalho Chehab |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/pci.h> |
| 16 | #include <linux/pci_ids.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/delay.h> |
| 19 | #include <linux/edac.h> |
| 20 | #include <linux/mmzone.h> |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 21 | #include <linux/smp.h> |
| 22 | #include <linux/bitmap.h> |
Mauro Carvalho Chehab | 5b889e3 | 2011-11-07 18:26:53 -0300 | [diff] [blame] | 23 | #include <linux/math64.h> |
Tony Luck | 2c1ea4c | 2016-04-28 15:40:00 -0700 | [diff] [blame] | 24 | #include <linux/mod_devicetable.h> |
| 25 | #include <asm/cpu_device_id.h> |
Dave Hansen | 20f4d69 | 2016-09-29 13:43:21 -0700 | [diff] [blame] | 26 | #include <asm/intel-family.h> |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 27 | #include <asm/processor.h> |
Mauro Carvalho Chehab | 3d78c9a | 2011-10-20 19:33:46 -0200 | [diff] [blame] | 28 | #include <asm/mce.h> |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 29 | |
Mauro Carvalho Chehab | 78d88e8 | 2016-10-29 15:16:34 -0200 | [diff] [blame] | 30 | #include "edac_module.h" |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 31 | |
| 32 | /* Static vars */ |
| 33 | static LIST_HEAD(sbridge_edac_list); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 34 | |
| 35 | /* |
| 36 | * Alter this version for the module when modifications are made |
| 37 | */ |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 38 | #define SBRIDGE_REVISION " Ver: 1.1.1 " |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 39 | #define EDAC_MOD_STR "sbridge_edac" |
| 40 | |
| 41 | /* |
| 42 | * Debug macros |
| 43 | */ |
| 44 | #define sbridge_printk(level, fmt, arg...) \ |
| 45 | edac_printk(level, "sbridge", fmt, ##arg) |
| 46 | |
| 47 | #define sbridge_mc_printk(mci, level, fmt, arg...) \ |
| 48 | edac_mc_chipset_printk(mci, level, "sbridge", fmt, ##arg) |
| 49 | |
| 50 | /* |
| 51 | * Get a bit field at register value <v>, from bit <lo> to bit <hi> |
| 52 | */ |
| 53 | #define GET_BITFIELD(v, lo, hi) \ |
Chen, Gong | 10ef6b0 | 2013-10-18 14:29:07 -0700 | [diff] [blame] | 54 | (((v) & GENMASK_ULL(hi, lo)) >> (lo)) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 55 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 56 | /* Devices 12 Function 6, Offsets 0x80 to 0xcc */ |
Aristeu Rozanski | 464f1d8 | 2013-10-30 13:27:00 -0300 | [diff] [blame] | 57 | static const u32 sbridge_dram_rule[] = { |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 58 | 0x80, 0x88, 0x90, 0x98, 0xa0, |
| 59 | 0xa8, 0xb0, 0xb8, 0xc0, 0xc8, |
| 60 | }; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 61 | |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 62 | static const u32 ibridge_dram_rule[] = { |
| 63 | 0x60, 0x68, 0x70, 0x78, 0x80, |
| 64 | 0x88, 0x90, 0x98, 0xa0, 0xa8, |
| 65 | 0xb0, 0xb8, 0xc0, 0xc8, 0xd0, |
| 66 | 0xd8, 0xe0, 0xe8, 0xf0, 0xf8, |
| 67 | }; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 68 | |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 69 | static const u32 knl_dram_rule[] = { |
| 70 | 0x60, 0x68, 0x70, 0x78, 0x80, /* 0-4 */ |
| 71 | 0x88, 0x90, 0x98, 0xa0, 0xa8, /* 5-9 */ |
| 72 | 0xb0, 0xb8, 0xc0, 0xc8, 0xd0, /* 10-14 */ |
| 73 | 0xd8, 0xe0, 0xe8, 0xf0, 0xf8, /* 15-19 */ |
| 74 | 0x100, 0x108, 0x110, 0x118, /* 20-23 */ |
| 75 | }; |
| 76 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 77 | #define DRAM_RULE_ENABLE(reg) GET_BITFIELD(reg, 0, 0) |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 78 | #define A7MODE(reg) GET_BITFIELD(reg, 26, 26) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 79 | |
Jim Snow | c59f9c0 | 2015-12-03 10:48:52 +0100 | [diff] [blame] | 80 | static char *show_dram_attr(u32 attr) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 81 | { |
Jim Snow | c59f9c0 | 2015-12-03 10:48:52 +0100 | [diff] [blame] | 82 | switch (attr) { |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 83 | case 0: |
| 84 | return "DRAM"; |
| 85 | case 1: |
| 86 | return "MMCFG"; |
| 87 | case 2: |
| 88 | return "NXM"; |
| 89 | default: |
| 90 | return "unknown"; |
| 91 | } |
| 92 | } |
| 93 | |
Aristeu Rozanski | ef1ce51 | 2013-10-30 13:27:01 -0300 | [diff] [blame] | 94 | static const u32 sbridge_interleave_list[] = { |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 95 | 0x84, 0x8c, 0x94, 0x9c, 0xa4, |
| 96 | 0xac, 0xb4, 0xbc, 0xc4, 0xcc, |
| 97 | }; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 98 | |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 99 | static const u32 ibridge_interleave_list[] = { |
| 100 | 0x64, 0x6c, 0x74, 0x7c, 0x84, |
| 101 | 0x8c, 0x94, 0x9c, 0xa4, 0xac, |
| 102 | 0xb4, 0xbc, 0xc4, 0xcc, 0xd4, |
| 103 | 0xdc, 0xe4, 0xec, 0xf4, 0xfc, |
| 104 | }; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 105 | |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 106 | static const u32 knl_interleave_list[] = { |
| 107 | 0x64, 0x6c, 0x74, 0x7c, 0x84, /* 0-4 */ |
| 108 | 0x8c, 0x94, 0x9c, 0xa4, 0xac, /* 5-9 */ |
| 109 | 0xb4, 0xbc, 0xc4, 0xcc, 0xd4, /* 10-14 */ |
| 110 | 0xdc, 0xe4, 0xec, 0xf4, 0xfc, /* 15-19 */ |
| 111 | 0x104, 0x10c, 0x114, 0x11c, /* 20-23 */ |
| 112 | }; |
| 113 | |
Aristeu Rozanski | cc31199 | 2013-10-30 13:27:02 -0300 | [diff] [blame] | 114 | struct interleave_pkg { |
| 115 | unsigned char start; |
| 116 | unsigned char end; |
| 117 | }; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 118 | |
Aristeu Rozanski | cc31199 | 2013-10-30 13:27:02 -0300 | [diff] [blame] | 119 | static const struct interleave_pkg sbridge_interleave_pkg[] = { |
| 120 | { 0, 2 }, |
| 121 | { 3, 5 }, |
| 122 | { 8, 10 }, |
| 123 | { 11, 13 }, |
| 124 | { 16, 18 }, |
| 125 | { 19, 21 }, |
| 126 | { 24, 26 }, |
| 127 | { 27, 29 }, |
| 128 | }; |
| 129 | |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 130 | static const struct interleave_pkg ibridge_interleave_pkg[] = { |
| 131 | { 0, 3 }, |
| 132 | { 4, 7 }, |
| 133 | { 8, 11 }, |
| 134 | { 12, 15 }, |
| 135 | { 16, 19 }, |
| 136 | { 20, 23 }, |
| 137 | { 24, 27 }, |
| 138 | { 28, 31 }, |
| 139 | }; |
| 140 | |
Aristeu Rozanski | cc31199 | 2013-10-30 13:27:02 -0300 | [diff] [blame] | 141 | static inline int sad_pkg(const struct interleave_pkg *table, u32 reg, |
| 142 | int interleave) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 143 | { |
Aristeu Rozanski | cc31199 | 2013-10-30 13:27:02 -0300 | [diff] [blame] | 144 | return GET_BITFIELD(reg, table[interleave].start, |
| 145 | table[interleave].end); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | /* Devices 12 Function 7 */ |
| 149 | |
| 150 | #define TOLM 0x80 |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 151 | #define TOHM 0x84 |
Tony Luck | f7cf2a2 | 2014-10-29 10:36:50 -0700 | [diff] [blame] | 152 | #define HASWELL_TOLM 0xd0 |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 153 | #define HASWELL_TOHM_0 0xd4 |
| 154 | #define HASWELL_TOHM_1 0xd8 |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 155 | #define KNL_TOLM 0xd0 |
| 156 | #define KNL_TOHM_0 0xd4 |
| 157 | #define KNL_TOHM_1 0xd8 |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 158 | |
| 159 | #define GET_TOLM(reg) ((GET_BITFIELD(reg, 0, 3) << 28) | 0x3ffffff) |
| 160 | #define GET_TOHM(reg) ((GET_BITFIELD(reg, 0, 20) << 25) | 0x3ffffff) |
| 161 | |
| 162 | /* Device 13 Function 6 */ |
| 163 | |
| 164 | #define SAD_TARGET 0xf0 |
| 165 | |
| 166 | #define SOURCE_ID(reg) GET_BITFIELD(reg, 9, 11) |
| 167 | |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 168 | #define SOURCE_ID_KNL(reg) GET_BITFIELD(reg, 12, 14) |
| 169 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 170 | #define SAD_CONTROL 0xf4 |
| 171 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 172 | /* Device 14 function 0 */ |
| 173 | |
| 174 | static const u32 tad_dram_rule[] = { |
| 175 | 0x40, 0x44, 0x48, 0x4c, |
| 176 | 0x50, 0x54, 0x58, 0x5c, |
| 177 | 0x60, 0x64, 0x68, 0x6c, |
| 178 | }; |
| 179 | #define MAX_TAD ARRAY_SIZE(tad_dram_rule) |
| 180 | |
| 181 | #define TAD_LIMIT(reg) ((GET_BITFIELD(reg, 12, 31) << 26) | 0x3ffffff) |
| 182 | #define TAD_SOCK(reg) GET_BITFIELD(reg, 10, 11) |
| 183 | #define TAD_CH(reg) GET_BITFIELD(reg, 8, 9) |
| 184 | #define TAD_TGT3(reg) GET_BITFIELD(reg, 6, 7) |
| 185 | #define TAD_TGT2(reg) GET_BITFIELD(reg, 4, 5) |
| 186 | #define TAD_TGT1(reg) GET_BITFIELD(reg, 2, 3) |
| 187 | #define TAD_TGT0(reg) GET_BITFIELD(reg, 0, 1) |
| 188 | |
| 189 | /* Device 15, function 0 */ |
| 190 | |
| 191 | #define MCMTR 0x7c |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 192 | #define KNL_MCMTR 0x624 |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 193 | |
| 194 | #define IS_ECC_ENABLED(mcmtr) GET_BITFIELD(mcmtr, 2, 2) |
| 195 | #define IS_LOCKSTEP_ENABLED(mcmtr) GET_BITFIELD(mcmtr, 1, 1) |
| 196 | #define IS_CLOSE_PG(mcmtr) GET_BITFIELD(mcmtr, 0, 0) |
| 197 | |
| 198 | /* Device 15, function 1 */ |
| 199 | |
| 200 | #define RASENABLES 0xac |
| 201 | #define IS_MIRROR_ENABLED(reg) GET_BITFIELD(reg, 0, 0) |
| 202 | |
| 203 | /* Device 15, functions 2-5 */ |
| 204 | |
| 205 | static const int mtr_regs[] = { |
| 206 | 0x80, 0x84, 0x88, |
| 207 | }; |
| 208 | |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 209 | static const int knl_mtr_reg = 0xb60; |
| 210 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 211 | #define RANK_DISABLE(mtr) GET_BITFIELD(mtr, 16, 19) |
| 212 | #define IS_DIMM_PRESENT(mtr) GET_BITFIELD(mtr, 14, 14) |
| 213 | #define RANK_CNT_BITS(mtr) GET_BITFIELD(mtr, 12, 13) |
| 214 | #define RANK_WIDTH_BITS(mtr) GET_BITFIELD(mtr, 2, 4) |
| 215 | #define COL_WIDTH_BITS(mtr) GET_BITFIELD(mtr, 0, 1) |
| 216 | |
| 217 | static const u32 tad_ch_nilv_offset[] = { |
| 218 | 0x90, 0x94, 0x98, 0x9c, |
| 219 | 0xa0, 0xa4, 0xa8, 0xac, |
| 220 | 0xb0, 0xb4, 0xb8, 0xbc, |
| 221 | }; |
| 222 | #define CHN_IDX_OFFSET(reg) GET_BITFIELD(reg, 28, 29) |
| 223 | #define TAD_OFFSET(reg) (GET_BITFIELD(reg, 6, 25) << 26) |
| 224 | |
| 225 | static const u32 rir_way_limit[] = { |
| 226 | 0x108, 0x10c, 0x110, 0x114, 0x118, |
| 227 | }; |
| 228 | #define MAX_RIR_RANGES ARRAY_SIZE(rir_way_limit) |
| 229 | |
| 230 | #define IS_RIR_VALID(reg) GET_BITFIELD(reg, 31, 31) |
| 231 | #define RIR_WAY(reg) GET_BITFIELD(reg, 28, 29) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 232 | |
| 233 | #define MAX_RIR_WAY 8 |
| 234 | |
| 235 | static const u32 rir_offset[MAX_RIR_RANGES][MAX_RIR_WAY] = { |
| 236 | { 0x120, 0x124, 0x128, 0x12c, 0x130, 0x134, 0x138, 0x13c }, |
| 237 | { 0x140, 0x144, 0x148, 0x14c, 0x150, 0x154, 0x158, 0x15c }, |
| 238 | { 0x160, 0x164, 0x168, 0x16c, 0x170, 0x174, 0x178, 0x17c }, |
| 239 | { 0x180, 0x184, 0x188, 0x18c, 0x190, 0x194, 0x198, 0x19c }, |
| 240 | { 0x1a0, 0x1a4, 0x1a8, 0x1ac, 0x1b0, 0x1b4, 0x1b8, 0x1bc }, |
| 241 | }; |
| 242 | |
Tony Luck | c7103f6 | 2016-05-31 11:50:28 -0700 | [diff] [blame] | 243 | #define RIR_RNK_TGT(type, reg) (((type) == BROADWELL) ? \ |
| 244 | GET_BITFIELD(reg, 20, 23) : GET_BITFIELD(reg, 16, 19)) |
| 245 | |
| 246 | #define RIR_OFFSET(type, reg) (((type) == HASWELL || (type) == BROADWELL) ? \ |
| 247 | GET_BITFIELD(reg, 2, 15) : GET_BITFIELD(reg, 2, 14)) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 248 | |
| 249 | /* Device 16, functions 2-7 */ |
| 250 | |
| 251 | /* |
| 252 | * FIXME: Implement the error count reads directly |
| 253 | */ |
| 254 | |
| 255 | static const u32 correrrcnt[] = { |
| 256 | 0x104, 0x108, 0x10c, 0x110, |
| 257 | }; |
| 258 | |
| 259 | #define RANK_ODD_OV(reg) GET_BITFIELD(reg, 31, 31) |
| 260 | #define RANK_ODD_ERR_CNT(reg) GET_BITFIELD(reg, 16, 30) |
| 261 | #define RANK_EVEN_OV(reg) GET_BITFIELD(reg, 15, 15) |
| 262 | #define RANK_EVEN_ERR_CNT(reg) GET_BITFIELD(reg, 0, 14) |
| 263 | |
| 264 | static const u32 correrrthrsld[] = { |
| 265 | 0x11c, 0x120, 0x124, 0x128, |
| 266 | }; |
| 267 | |
| 268 | #define RANK_ODD_ERR_THRSLD(reg) GET_BITFIELD(reg, 16, 30) |
| 269 | #define RANK_EVEN_ERR_THRSLD(reg) GET_BITFIELD(reg, 0, 14) |
| 270 | |
| 271 | |
| 272 | /* Device 17, function 0 */ |
| 273 | |
Aristeu Rozanski | ef1e8d0 | 2013-10-30 13:26:56 -0300 | [diff] [blame] | 274 | #define SB_RANK_CFG_A 0x0328 |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 275 | |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 276 | #define IB_RANK_CFG_A 0x0320 |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 277 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 278 | /* |
| 279 | * sbridge structs |
| 280 | */ |
| 281 | |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 282 | #define NUM_CHANNELS 8 /* 2MC per socket, four chan per MC */ |
Seth Jennings | 351fc4a | 2014-09-05 14:28:47 -0500 | [diff] [blame] | 283 | #define MAX_DIMMS 3 /* Max DIMMS per channel */ |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 284 | #define KNL_MAX_CHAS 38 /* KNL max num. of Cache Home Agents */ |
| 285 | #define KNL_MAX_CHANNELS 6 /* KNL max num. of PCI channels */ |
| 286 | #define KNL_MAX_EDCS 8 /* Embedded DRAM controllers */ |
Seth Jennings | 351fc4a | 2014-09-05 14:28:47 -0500 | [diff] [blame] | 287 | #define CHANNEL_UNSPECIFIED 0xf /* Intel IA32 SDM 15-14 */ |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 288 | |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 289 | enum type { |
| 290 | SANDY_BRIDGE, |
| 291 | IVY_BRIDGE, |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 292 | HASWELL, |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 293 | BROADWELL, |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 294 | KNIGHTS_LANDING, |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 295 | }; |
| 296 | |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 297 | enum domain { |
| 298 | IMC0 = 0, |
| 299 | IMC1, |
| 300 | SOCK, |
| 301 | }; |
| 302 | |
Aristeu Rozanski | fb79a50 | 2013-10-30 13:26:57 -0300 | [diff] [blame] | 303 | struct sbridge_pvt; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 304 | struct sbridge_info { |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 305 | enum type type; |
Aristeu Rozanski | 464f1d8 | 2013-10-30 13:27:00 -0300 | [diff] [blame] | 306 | u32 mcmtr; |
| 307 | u32 rankcfgr; |
| 308 | u64 (*get_tolm)(struct sbridge_pvt *pvt); |
| 309 | u64 (*get_tohm)(struct sbridge_pvt *pvt); |
Aristeu Rozanski | b976bcf | 2014-06-02 15:15:24 -0300 | [diff] [blame] | 310 | u64 (*rir_limit)(u32 reg); |
Jim Snow | c59f9c0 | 2015-12-03 10:48:52 +0100 | [diff] [blame] | 311 | u64 (*sad_limit)(u32 reg); |
| 312 | u32 (*interleave_mode)(u32 reg); |
Jim Snow | c59f9c0 | 2015-12-03 10:48:52 +0100 | [diff] [blame] | 313 | u32 (*dram_attr)(u32 reg); |
Aristeu Rozanski | 464f1d8 | 2013-10-30 13:27:00 -0300 | [diff] [blame] | 314 | const u32 *dram_rule; |
Aristeu Rozanski | ef1ce51 | 2013-10-30 13:27:01 -0300 | [diff] [blame] | 315 | const u32 *interleave_list; |
Aristeu Rozanski | cc31199 | 2013-10-30 13:27:02 -0300 | [diff] [blame] | 316 | const struct interleave_pkg *interleave_pkg; |
Aristeu Rozanski | 464f1d8 | 2013-10-30 13:27:00 -0300 | [diff] [blame] | 317 | u8 max_sad; |
Aristeu Rozanski | ef1ce51 | 2013-10-30 13:27:01 -0300 | [diff] [blame] | 318 | u8 max_interleave; |
Aristeu Rozanski | f14d689 | 2014-06-02 15:15:23 -0300 | [diff] [blame] | 319 | u8 (*get_node_id)(struct sbridge_pvt *pvt); |
Aristeu Rozanski | 9e37544 | 2014-06-02 15:15:22 -0300 | [diff] [blame] | 320 | enum mem_type (*get_memory_type)(struct sbridge_pvt *pvt); |
Aristeu Rozanski | 12f0721 | 2015-06-12 15:08:17 -0400 | [diff] [blame] | 321 | enum dev_type (*get_width)(struct sbridge_pvt *pvt, u32 mtr); |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 322 | struct pci_dev *pci_vtd; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 323 | }; |
| 324 | |
| 325 | struct sbridge_channel { |
| 326 | u32 ranks; |
| 327 | u32 dimms; |
| 328 | }; |
| 329 | |
| 330 | struct pci_id_descr { |
Mauro Carvalho Chehab | c41afdc | 2014-06-26 15:35:14 -0300 | [diff] [blame] | 331 | int dev_id; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 332 | int optional; |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 333 | enum domain dom; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 334 | }; |
| 335 | |
| 336 | struct pci_id_table { |
| 337 | const struct pci_id_descr *descr; |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 338 | int n_devs_per_imc; |
| 339 | int n_devs_per_sock; |
| 340 | int n_imcs_per_sock; |
Tony Luck | 665f05e0 | 2016-06-02 10:58:08 -0700 | [diff] [blame] | 341 | enum type type; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 342 | }; |
| 343 | |
| 344 | struct sbridge_dev { |
| 345 | struct list_head list; |
| 346 | u8 bus, mc; |
| 347 | u8 node_id, source_id; |
| 348 | struct pci_dev **pdev; |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 349 | enum domain dom; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 350 | int n_devs; |
| 351 | struct mem_ctl_info *mci; |
| 352 | }; |
| 353 | |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 354 | struct knl_pvt { |
| 355 | struct pci_dev *pci_cha[KNL_MAX_CHAS]; |
| 356 | struct pci_dev *pci_channel[KNL_MAX_CHANNELS]; |
| 357 | struct pci_dev *pci_mc0; |
| 358 | struct pci_dev *pci_mc1; |
| 359 | struct pci_dev *pci_mc0_misc; |
| 360 | struct pci_dev *pci_mc1_misc; |
| 361 | struct pci_dev *pci_mc_info; /* tolm, tohm */ |
| 362 | }; |
| 363 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 364 | struct sbridge_pvt { |
| 365 | struct pci_dev *pci_ta, *pci_ddrio, *pci_ras; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 366 | struct pci_dev *pci_sad0, *pci_sad1; |
| 367 | struct pci_dev *pci_ha0, *pci_ha1; |
| 368 | struct pci_dev *pci_br0, *pci_br1; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 369 | struct pci_dev *pci_ha1_ta; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 370 | struct pci_dev *pci_tad[NUM_CHANNELS]; |
| 371 | |
| 372 | struct sbridge_dev *sbridge_dev; |
| 373 | |
| 374 | struct sbridge_info info; |
| 375 | struct sbridge_channel channel[NUM_CHANNELS]; |
| 376 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 377 | /* Memory type detection */ |
| 378 | bool is_mirrored, is_lockstep, is_close_pg; |
Tony Luck | ea5dfb5 | 2016-04-14 10:22:02 -0700 | [diff] [blame] | 379 | bool is_chan_hash; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 380 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 381 | /* Memory description */ |
| 382 | u64 tolm, tohm; |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 383 | struct knl_pvt knl; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 384 | }; |
| 385 | |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 386 | #define PCI_DESCR(device_id, opt, domain) \ |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 387 | .dev_id = (device_id), \ |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 388 | .optional = opt, \ |
| 389 | .dom = domain |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 390 | |
| 391 | static const struct pci_id_descr pci_dev_descr_sbridge[] = { |
| 392 | /* Processor Home Agent */ |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 393 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_HA0, 0, IMC0) }, |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 394 | |
| 395 | /* Memory controller */ |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 396 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA, 0, IMC0) }, |
| 397 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_RAS, 0, IMC0) }, |
| 398 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD0, 0, IMC0) }, |
| 399 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD1, 0, IMC0) }, |
| 400 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD2, 0, IMC0) }, |
| 401 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD3, 0, IMC0) }, |
| 402 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_DDRIO, 1, SOCK) }, |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 403 | |
| 404 | /* System Address Decoder */ |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 405 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_SAD0, 0, SOCK) }, |
| 406 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_SAD1, 0, SOCK) }, |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 407 | |
| 408 | /* Broadcast Registers */ |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 409 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_BR, 0, SOCK) }, |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 410 | }; |
| 411 | |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 412 | #define PCI_ID_TABLE_ENTRY(A, N, M, T) { \ |
Tony Luck | 665f05e0 | 2016-06-02 10:58:08 -0700 | [diff] [blame] | 413 | .descr = A, \ |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 414 | .n_devs_per_imc = N, \ |
| 415 | .n_devs_per_sock = ARRAY_SIZE(A), \ |
| 416 | .n_imcs_per_sock = M, \ |
Tony Luck | 665f05e0 | 2016-06-02 10:58:08 -0700 | [diff] [blame] | 417 | .type = T \ |
| 418 | } |
| 419 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 420 | static const struct pci_id_table pci_dev_descr_sbridge_table[] = { |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 421 | PCI_ID_TABLE_ENTRY(pci_dev_descr_sbridge, ARRAY_SIZE(pci_dev_descr_sbridge), 1, SANDY_BRIDGE), |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 422 | {0,} /* 0 terminated list. */ |
| 423 | }; |
| 424 | |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 425 | /* This changes depending if 1HA or 2HA: |
| 426 | * 1HA: |
| 427 | * 0x0eb8 (17.0) is DDRIO0 |
| 428 | * 2HA: |
| 429 | * 0x0ebc (17.4) is DDRIO0 |
| 430 | */ |
| 431 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_1HA_DDRIO0 0x0eb8 |
| 432 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_2HA_DDRIO0 0x0ebc |
| 433 | |
| 434 | /* pci ids */ |
| 435 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0 0x0ea0 |
| 436 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA 0x0ea8 |
| 437 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_RAS 0x0e71 |
| 438 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD0 0x0eaa |
| 439 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD1 0x0eab |
| 440 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD2 0x0eac |
| 441 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD3 0x0ead |
| 442 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_SAD 0x0ec8 |
| 443 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_BR0 0x0ec9 |
| 444 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_BR1 0x0eca |
| 445 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1 0x0e60 |
| 446 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TA 0x0e68 |
| 447 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_RAS 0x0e79 |
| 448 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD0 0x0e6a |
| 449 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD1 0x0e6b |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 450 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD2 0x0e6c |
| 451 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD3 0x0e6d |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 452 | |
| 453 | static const struct pci_id_descr pci_dev_descr_ibridge[] = { |
| 454 | /* Processor Home Agent */ |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 455 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0, 0, IMC0) }, |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 456 | |
| 457 | /* Memory controller */ |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 458 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA, 0, IMC0) }, |
| 459 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_RAS, 0, IMC0) }, |
| 460 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD0, 0, IMC0) }, |
| 461 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD1, 0, IMC0) }, |
| 462 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD2, 0, IMC0) }, |
| 463 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD3, 0, IMC0) }, |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 464 | |
| 465 | /* Optional, mode 2HA */ |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 466 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1, 1, IMC1) }, |
| 467 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TA, 1, IMC1) }, |
| 468 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_RAS, 1, IMC1) }, |
| 469 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD0, 1, IMC1) }, |
| 470 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD1, 1, IMC1) }, |
| 471 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD2, 1, IMC1) }, |
| 472 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD3, 1, IMC1) }, |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 473 | |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 474 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_1HA_DDRIO0, 1, SOCK) }, |
| 475 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_2HA_DDRIO0, 1, SOCK) }, |
| 476 | |
| 477 | /* System Address Decoder */ |
| 478 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_SAD, 0, SOCK) }, |
| 479 | |
| 480 | /* Broadcast Registers */ |
| 481 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_BR0, 1, SOCK) }, |
| 482 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_BR1, 0, SOCK) }, |
| 483 | |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 484 | }; |
| 485 | |
| 486 | static const struct pci_id_table pci_dev_descr_ibridge_table[] = { |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 487 | PCI_ID_TABLE_ENTRY(pci_dev_descr_ibridge, 12, 2, IVY_BRIDGE), |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 488 | {0,} /* 0 terminated list. */ |
| 489 | }; |
| 490 | |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 491 | /* Haswell support */ |
| 492 | /* EN processor: |
| 493 | * - 1 IMC |
| 494 | * - 3 DDR3 channels, 2 DPC per channel |
| 495 | * EP processor: |
| 496 | * - 1 or 2 IMC |
| 497 | * - 4 DDR4 channels, 3 DPC per channel |
| 498 | * EP 4S processor: |
| 499 | * - 2 IMC |
| 500 | * - 4 DDR4 channels, 3 DPC per channel |
| 501 | * EX processor: |
| 502 | * - 2 IMC |
| 503 | * - each IMC interfaces with a SMI 2 channel |
| 504 | * - each SMI channel interfaces with a scalable memory buffer |
| 505 | * - each scalable memory buffer supports 4 DDR3/DDR4 channels, 3 DPC |
| 506 | */ |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 507 | #define HASWELL_DDRCRCLKCONTROLS 0xa10 /* Ditto on Broadwell */ |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 508 | #define HASWELL_HASYSDEFEATURE2 0x84 |
| 509 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_VTD_MISC 0x2f28 |
| 510 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0 0x2fa0 |
| 511 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1 0x2f60 |
| 512 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TA 0x2fa8 |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 513 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TM 0x2f71 |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 514 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TA 0x2f68 |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 515 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TM 0x2f79 |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 516 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_CBO_SAD0 0x2ffc |
| 517 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_CBO_SAD1 0x2ffd |
| 518 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD0 0x2faa |
| 519 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD1 0x2fab |
| 520 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD2 0x2fac |
| 521 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD3 0x2fad |
| 522 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD0 0x2f6a |
| 523 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD1 0x2f6b |
| 524 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD2 0x2f6c |
| 525 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD3 0x2f6d |
| 526 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO0 0x2fbd |
Aristeu Rozanski | 7179385 | 2015-06-12 09:44:52 -0400 | [diff] [blame] | 527 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO1 0x2fbf |
| 528 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO2 0x2fb9 |
| 529 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO3 0x2fbb |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 530 | static const struct pci_id_descr pci_dev_descr_haswell[] = { |
| 531 | /* first item must be the HA */ |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 532 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0, 0, IMC0) }, |
| 533 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1, 1, IMC1) }, |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 534 | |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 535 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TA, 0, IMC0) }, |
| 536 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TM, 0, IMC0) }, |
| 537 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD0, 0, IMC0) }, |
| 538 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD1, 0, IMC0) }, |
| 539 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD2, 1, IMC0) }, |
| 540 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD3, 1, IMC0) }, |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 541 | |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 542 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TA, 1, IMC1) }, |
| 543 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TM, 1, IMC1) }, |
| 544 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD0, 1, IMC1) }, |
| 545 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD1, 1, IMC1) }, |
| 546 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD2, 1, IMC1) }, |
| 547 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD3, 1, IMC1) }, |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 548 | |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 549 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_CBO_SAD0, 0, SOCK) }, |
| 550 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_CBO_SAD1, 0, SOCK) }, |
| 551 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO0, 1, SOCK) }, |
| 552 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO1, 1, SOCK) }, |
| 553 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO2, 1, SOCK) }, |
| 554 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO3, 1, SOCK) }, |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 555 | }; |
| 556 | |
| 557 | static const struct pci_id_table pci_dev_descr_haswell_table[] = { |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 558 | PCI_ID_TABLE_ENTRY(pci_dev_descr_haswell, 13, 2, HASWELL), |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 559 | {0,} /* 0 terminated list. */ |
| 560 | }; |
| 561 | |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 562 | /* Knight's Landing Support */ |
| 563 | /* |
| 564 | * KNL's memory channels are swizzled between memory controllers. |
Lukasz Odzioba | c5b48fa | 2016-07-23 01:44:49 +0200 | [diff] [blame] | 565 | * MC0 is mapped to CH3,4,5 and MC1 is mapped to CH0,1,2 |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 566 | */ |
Lukasz Odzioba | c5b48fa | 2016-07-23 01:44:49 +0200 | [diff] [blame] | 567 | #define knl_channel_remap(mc, chan) ((mc) ? (chan) : (chan) + 3) |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 568 | |
| 569 | /* Memory controller, TAD tables, error injection - 2-8-0, 2-9-0 (2 of these) */ |
| 570 | #define PCI_DEVICE_ID_INTEL_KNL_IMC_MC 0x7840 |
| 571 | /* DRAM channel stuff; bank addrs, dimmmtr, etc.. 2-8-2 - 2-9-4 (6 of these) */ |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 572 | #define PCI_DEVICE_ID_INTEL_KNL_IMC_CHAN 0x7843 |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 573 | /* kdrwdbu TAD limits/offsets, MCMTR - 2-10-1, 2-11-1 (2 of these) */ |
| 574 | #define PCI_DEVICE_ID_INTEL_KNL_IMC_TA 0x7844 |
| 575 | /* CHA broadcast registers, dram rules - 1-29-0 (1 of these) */ |
| 576 | #define PCI_DEVICE_ID_INTEL_KNL_IMC_SAD0 0x782a |
| 577 | /* SAD target - 1-29-1 (1 of these) */ |
| 578 | #define PCI_DEVICE_ID_INTEL_KNL_IMC_SAD1 0x782b |
| 579 | /* Caching / Home Agent */ |
| 580 | #define PCI_DEVICE_ID_INTEL_KNL_IMC_CHA 0x782c |
| 581 | /* Device with TOLM and TOHM, 0-5-0 (1 of these) */ |
| 582 | #define PCI_DEVICE_ID_INTEL_KNL_IMC_TOLHM 0x7810 |
| 583 | |
| 584 | /* |
| 585 | * KNL differs from SB, IB, and Haswell in that it has multiple |
| 586 | * instances of the same device with the same device ID, so we handle that |
| 587 | * by creating as many copies in the table as we expect to find. |
| 588 | * (Like device ID must be grouped together.) |
| 589 | */ |
| 590 | |
| 591 | static const struct pci_id_descr pci_dev_descr_knl[] = { |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 592 | [0 ... 1] = { PCI_DESCR(PCI_DEVICE_ID_INTEL_KNL_IMC_MC, 0, IMC0)}, |
| 593 | [2 ... 7] = { PCI_DESCR(PCI_DEVICE_ID_INTEL_KNL_IMC_CHAN, 0, IMC0) }, |
| 594 | [8] = { PCI_DESCR(PCI_DEVICE_ID_INTEL_KNL_IMC_TA, 0, IMC0) }, |
| 595 | [9] = { PCI_DESCR(PCI_DEVICE_ID_INTEL_KNL_IMC_TOLHM, 0, IMC0) }, |
| 596 | [10] = { PCI_DESCR(PCI_DEVICE_ID_INTEL_KNL_IMC_SAD0, 0, SOCK) }, |
| 597 | [11] = { PCI_DESCR(PCI_DEVICE_ID_INTEL_KNL_IMC_SAD1, 0, SOCK) }, |
| 598 | [12 ... 49] = { PCI_DESCR(PCI_DEVICE_ID_INTEL_KNL_IMC_CHA, 0, SOCK) }, |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 599 | }; |
| 600 | |
| 601 | static const struct pci_id_table pci_dev_descr_knl_table[] = { |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 602 | PCI_ID_TABLE_ENTRY(pci_dev_descr_knl, ARRAY_SIZE(pci_dev_descr_knl), 1, KNIGHTS_LANDING), |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 603 | {0,} |
| 604 | }; |
| 605 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 606 | /* |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 607 | * Broadwell support |
| 608 | * |
| 609 | * DE processor: |
| 610 | * - 1 IMC |
| 611 | * - 2 DDR3 channels, 2 DPC per channel |
Tony Luck | fa2ce64 | 2015-05-20 19:10:35 -0300 | [diff] [blame] | 612 | * EP processor: |
| 613 | * - 1 or 2 IMC |
| 614 | * - 4 DDR4 channels, 3 DPC per channel |
| 615 | * EP 4S processor: |
| 616 | * - 2 IMC |
| 617 | * - 4 DDR4 channels, 3 DPC per channel |
| 618 | * EX processor: |
| 619 | * - 2 IMC |
| 620 | * - each IMC interfaces with a SMI 2 channel |
| 621 | * - each SMI channel interfaces with a scalable memory buffer |
| 622 | * - each scalable memory buffer supports 4 DDR3/DDR4 channels, 3 DPC |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 623 | */ |
| 624 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_VTD_MISC 0x6f28 |
| 625 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0 0x6fa0 |
Tony Luck | fa2ce64 | 2015-05-20 19:10:35 -0300 | [diff] [blame] | 626 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1 0x6f60 |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 627 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TA 0x6fa8 |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 628 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TM 0x6f71 |
Tony Luck | fa2ce64 | 2015-05-20 19:10:35 -0300 | [diff] [blame] | 629 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TA 0x6f68 |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 630 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TM 0x6f79 |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 631 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_CBO_SAD0 0x6ffc |
| 632 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_CBO_SAD1 0x6ffd |
| 633 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD0 0x6faa |
| 634 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD1 0x6fab |
| 635 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD2 0x6fac |
| 636 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD3 0x6fad |
Tony Luck | fa2ce64 | 2015-05-20 19:10:35 -0300 | [diff] [blame] | 637 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD0 0x6f6a |
| 638 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD1 0x6f6b |
| 639 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD2 0x6f6c |
| 640 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD3 0x6f6d |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 641 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_DDRIO0 0x6faf |
| 642 | |
| 643 | static const struct pci_id_descr pci_dev_descr_broadwell[] = { |
| 644 | /* first item must be the HA */ |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 645 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0, 0, IMC0) }, |
| 646 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1, 1, IMC1) }, |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 647 | |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 648 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TA, 0, IMC0) }, |
| 649 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TM, 0, IMC0) }, |
| 650 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD0, 0, IMC0) }, |
| 651 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD1, 0, IMC0) }, |
| 652 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD2, 1, IMC0) }, |
| 653 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD3, 1, IMC0) }, |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 654 | |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 655 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TA, 1, IMC1) }, |
| 656 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TM, 1, IMC1) }, |
| 657 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD0, 1, IMC1) }, |
| 658 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD1, 1, IMC1) }, |
| 659 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD2, 1, IMC1) }, |
| 660 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD3, 1, IMC1) }, |
Tony Luck | fa2ce64 | 2015-05-20 19:10:35 -0300 | [diff] [blame] | 661 | |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 662 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_CBO_SAD0, 0, SOCK) }, |
| 663 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_CBO_SAD1, 0, SOCK) }, |
| 664 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_DDRIO0, 1, SOCK) }, |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 665 | }; |
| 666 | |
| 667 | static const struct pci_id_table pci_dev_descr_broadwell_table[] = { |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 668 | PCI_ID_TABLE_ENTRY(pci_dev_descr_broadwell, 10, 2, BROADWELL), |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 669 | {0,} /* 0 terminated list. */ |
| 670 | }; |
| 671 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 672 | |
| 673 | /**************************************************************************** |
David Mackey | 15ed103 | 2012-04-17 11:30:52 -0700 | [diff] [blame] | 674 | Ancillary status routines |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 675 | ****************************************************************************/ |
| 676 | |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 677 | static inline int numrank(enum type type, u32 mtr) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 678 | { |
| 679 | int ranks = (1 << RANK_CNT_BITS(mtr)); |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 680 | int max = 4; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 681 | |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 682 | if (type == HASWELL || type == BROADWELL || type == KNIGHTS_LANDING) |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 683 | max = 8; |
| 684 | |
| 685 | if (ranks > max) { |
| 686 | edac_dbg(0, "Invalid number of ranks: %d (max = %i) raw value = %x (%04x)\n", |
| 687 | ranks, max, (unsigned int)RANK_CNT_BITS(mtr), mtr); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 688 | return -EINVAL; |
| 689 | } |
| 690 | |
| 691 | return ranks; |
| 692 | } |
| 693 | |
| 694 | static inline int numrow(u32 mtr) |
| 695 | { |
| 696 | int rows = (RANK_WIDTH_BITS(mtr) + 12); |
| 697 | |
| 698 | if (rows < 13 || rows > 18) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 699 | edac_dbg(0, "Invalid number of rows: %d (should be between 14 and 17) raw value = %x (%04x)\n", |
| 700 | rows, (unsigned int)RANK_WIDTH_BITS(mtr), mtr); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 701 | return -EINVAL; |
| 702 | } |
| 703 | |
| 704 | return 1 << rows; |
| 705 | } |
| 706 | |
| 707 | static inline int numcol(u32 mtr) |
| 708 | { |
| 709 | int cols = (COL_WIDTH_BITS(mtr) + 10); |
| 710 | |
| 711 | if (cols > 12) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 712 | edac_dbg(0, "Invalid number of cols: %d (max = 4) raw value = %x (%04x)\n", |
| 713 | cols, (unsigned int)COL_WIDTH_BITS(mtr), mtr); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 714 | return -EINVAL; |
| 715 | } |
| 716 | |
| 717 | return 1 << cols; |
| 718 | } |
| 719 | |
Jim Snow | c1979ba | 2015-12-03 10:48:53 +0100 | [diff] [blame] | 720 | static struct sbridge_dev *get_sbridge_dev(u8 bus, int multi_bus) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 721 | { |
| 722 | struct sbridge_dev *sbridge_dev; |
| 723 | |
Jim Snow | c1979ba | 2015-12-03 10:48:53 +0100 | [diff] [blame] | 724 | /* |
| 725 | * If we have devices scattered across several busses that pertain |
| 726 | * to the same memory controller, we'll lump them all together. |
| 727 | */ |
| 728 | if (multi_bus) { |
| 729 | return list_first_entry_or_null(&sbridge_edac_list, |
| 730 | struct sbridge_dev, list); |
| 731 | } |
| 732 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 733 | list_for_each_entry(sbridge_dev, &sbridge_edac_list, list) { |
| 734 | if (sbridge_dev->bus == bus) |
| 735 | return sbridge_dev; |
| 736 | } |
| 737 | |
| 738 | return NULL; |
| 739 | } |
| 740 | |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 741 | static struct sbridge_dev *alloc_sbridge_dev(u8 bus, enum domain dom, const struct pci_id_table *table) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 742 | { |
| 743 | struct sbridge_dev *sbridge_dev; |
| 744 | |
| 745 | sbridge_dev = kzalloc(sizeof(*sbridge_dev), GFP_KERNEL); |
| 746 | if (!sbridge_dev) |
| 747 | return NULL; |
| 748 | |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 749 | sbridge_dev->pdev = kcalloc(table->n_devs_per_sock, sizeof(*sbridge_dev->pdev), GFP_KERNEL); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 750 | if (!sbridge_dev->pdev) { |
| 751 | kfree(sbridge_dev); |
| 752 | return NULL; |
| 753 | } |
| 754 | |
| 755 | sbridge_dev->bus = bus; |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 756 | sbridge_dev->dom = dom; |
| 757 | sbridge_dev->n_devs = table->n_devs_per_sock; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 758 | list_add_tail(&sbridge_dev->list, &sbridge_edac_list); |
| 759 | |
| 760 | return sbridge_dev; |
| 761 | } |
| 762 | |
| 763 | static void free_sbridge_dev(struct sbridge_dev *sbridge_dev) |
| 764 | { |
| 765 | list_del(&sbridge_dev->list); |
| 766 | kfree(sbridge_dev->pdev); |
| 767 | kfree(sbridge_dev); |
| 768 | } |
| 769 | |
Aristeu Rozanski | fb79a50 | 2013-10-30 13:26:57 -0300 | [diff] [blame] | 770 | static u64 sbridge_get_tolm(struct sbridge_pvt *pvt) |
| 771 | { |
| 772 | u32 reg; |
| 773 | |
| 774 | /* Address range is 32:28 */ |
| 775 | pci_read_config_dword(pvt->pci_sad1, TOLM, ®); |
| 776 | return GET_TOLM(reg); |
| 777 | } |
| 778 | |
Aristeu Rozanski | 8fd6a43 | 2013-10-30 13:26:59 -0300 | [diff] [blame] | 779 | static u64 sbridge_get_tohm(struct sbridge_pvt *pvt) |
| 780 | { |
| 781 | u32 reg; |
| 782 | |
| 783 | pci_read_config_dword(pvt->pci_sad1, TOHM, ®); |
| 784 | return GET_TOHM(reg); |
| 785 | } |
| 786 | |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 787 | static u64 ibridge_get_tolm(struct sbridge_pvt *pvt) |
| 788 | { |
| 789 | u32 reg; |
| 790 | |
| 791 | pci_read_config_dword(pvt->pci_br1, TOLM, ®); |
| 792 | |
| 793 | return GET_TOLM(reg); |
| 794 | } |
| 795 | |
| 796 | static u64 ibridge_get_tohm(struct sbridge_pvt *pvt) |
| 797 | { |
| 798 | u32 reg; |
| 799 | |
| 800 | pci_read_config_dword(pvt->pci_br1, TOHM, ®); |
| 801 | |
| 802 | return GET_TOHM(reg); |
| 803 | } |
| 804 | |
Aristeu Rozanski | b976bcf | 2014-06-02 15:15:24 -0300 | [diff] [blame] | 805 | static u64 rir_limit(u32 reg) |
| 806 | { |
| 807 | return ((u64)GET_BITFIELD(reg, 1, 10) << 29) | 0x1fffffff; |
| 808 | } |
| 809 | |
Jim Snow | c59f9c0 | 2015-12-03 10:48:52 +0100 | [diff] [blame] | 810 | static u64 sad_limit(u32 reg) |
| 811 | { |
| 812 | return (GET_BITFIELD(reg, 6, 25) << 26) | 0x3ffffff; |
| 813 | } |
| 814 | |
| 815 | static u32 interleave_mode(u32 reg) |
| 816 | { |
| 817 | return GET_BITFIELD(reg, 1, 1); |
| 818 | } |
| 819 | |
Jim Snow | c59f9c0 | 2015-12-03 10:48:52 +0100 | [diff] [blame] | 820 | static u32 dram_attr(u32 reg) |
| 821 | { |
| 822 | return GET_BITFIELD(reg, 2, 3); |
| 823 | } |
| 824 | |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 825 | static u64 knl_sad_limit(u32 reg) |
| 826 | { |
| 827 | return (GET_BITFIELD(reg, 7, 26) << 26) | 0x3ffffff; |
| 828 | } |
| 829 | |
| 830 | static u32 knl_interleave_mode(u32 reg) |
| 831 | { |
| 832 | return GET_BITFIELD(reg, 1, 2); |
| 833 | } |
| 834 | |
Nicolas Iooss | 127c122 | 2017-01-22 18:28:06 +0100 | [diff] [blame] | 835 | static const char * const knl_intlv_mode[] = { |
| 836 | "[8:6]", "[10:8]", "[14:12]", "[32:30]" |
| 837 | }; |
| 838 | |
| 839 | static const char *get_intlv_mode_str(u32 reg, enum type t) |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 840 | { |
Nicolas Iooss | 127c122 | 2017-01-22 18:28:06 +0100 | [diff] [blame] | 841 | if (t == KNIGHTS_LANDING) |
| 842 | return knl_intlv_mode[knl_interleave_mode(reg)]; |
| 843 | else |
| 844 | return interleave_mode(reg) ? "[8:6]" : "[8:6]XOR[18:16]"; |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | static u32 dram_attr_knl(u32 reg) |
| 848 | { |
| 849 | return GET_BITFIELD(reg, 3, 4); |
| 850 | } |
| 851 | |
| 852 | |
Aristeu Rozanski | 9e37544 | 2014-06-02 15:15:22 -0300 | [diff] [blame] | 853 | static enum mem_type get_memory_type(struct sbridge_pvt *pvt) |
| 854 | { |
| 855 | u32 reg; |
| 856 | enum mem_type mtype; |
| 857 | |
| 858 | if (pvt->pci_ddrio) { |
| 859 | pci_read_config_dword(pvt->pci_ddrio, pvt->info.rankcfgr, |
| 860 | ®); |
| 861 | if (GET_BITFIELD(reg, 11, 11)) |
| 862 | /* FIXME: Can also be LRDIMM */ |
| 863 | mtype = MEM_RDDR3; |
| 864 | else |
| 865 | mtype = MEM_DDR3; |
| 866 | } else |
| 867 | mtype = MEM_UNKNOWN; |
| 868 | |
| 869 | return mtype; |
| 870 | } |
| 871 | |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 872 | static enum mem_type haswell_get_memory_type(struct sbridge_pvt *pvt) |
| 873 | { |
| 874 | u32 reg; |
| 875 | bool registered = false; |
| 876 | enum mem_type mtype = MEM_UNKNOWN; |
| 877 | |
| 878 | if (!pvt->pci_ddrio) |
| 879 | goto out; |
| 880 | |
| 881 | pci_read_config_dword(pvt->pci_ddrio, |
| 882 | HASWELL_DDRCRCLKCONTROLS, ®); |
| 883 | /* Is_Rdimm */ |
| 884 | if (GET_BITFIELD(reg, 16, 16)) |
| 885 | registered = true; |
| 886 | |
| 887 | pci_read_config_dword(pvt->pci_ta, MCMTR, ®); |
| 888 | if (GET_BITFIELD(reg, 14, 14)) { |
| 889 | if (registered) |
| 890 | mtype = MEM_RDDR4; |
| 891 | else |
| 892 | mtype = MEM_DDR4; |
| 893 | } else { |
| 894 | if (registered) |
| 895 | mtype = MEM_RDDR3; |
| 896 | else |
| 897 | mtype = MEM_DDR3; |
| 898 | } |
| 899 | |
| 900 | out: |
| 901 | return mtype; |
| 902 | } |
| 903 | |
Hubert Chrzaniuk | 45f4d3a | 2015-12-11 14:21:22 +0100 | [diff] [blame] | 904 | static enum dev_type knl_get_width(struct sbridge_pvt *pvt, u32 mtr) |
| 905 | { |
| 906 | /* for KNL value is fixed */ |
| 907 | return DEV_X16; |
| 908 | } |
| 909 | |
Aristeu Rozanski | 12f0721 | 2015-06-12 15:08:17 -0400 | [diff] [blame] | 910 | static enum dev_type sbridge_get_width(struct sbridge_pvt *pvt, u32 mtr) |
| 911 | { |
| 912 | /* there's no way to figure out */ |
| 913 | return DEV_UNKNOWN; |
| 914 | } |
| 915 | |
| 916 | static enum dev_type __ibridge_get_width(u32 mtr) |
| 917 | { |
| 918 | enum dev_type type; |
| 919 | |
| 920 | switch (mtr) { |
| 921 | case 3: |
| 922 | type = DEV_UNKNOWN; |
| 923 | break; |
| 924 | case 2: |
| 925 | type = DEV_X16; |
| 926 | break; |
| 927 | case 1: |
| 928 | type = DEV_X8; |
| 929 | break; |
| 930 | case 0: |
| 931 | type = DEV_X4; |
| 932 | break; |
| 933 | } |
| 934 | |
| 935 | return type; |
| 936 | } |
| 937 | |
| 938 | static enum dev_type ibridge_get_width(struct sbridge_pvt *pvt, u32 mtr) |
| 939 | { |
| 940 | /* |
| 941 | * ddr3_width on the documentation but also valid for DDR4 on |
| 942 | * Haswell |
| 943 | */ |
| 944 | return __ibridge_get_width(GET_BITFIELD(mtr, 7, 8)); |
| 945 | } |
| 946 | |
| 947 | static enum dev_type broadwell_get_width(struct sbridge_pvt *pvt, u32 mtr) |
| 948 | { |
| 949 | /* ddr3_width on the documentation but also valid for DDR4 */ |
| 950 | return __ibridge_get_width(GET_BITFIELD(mtr, 8, 9)); |
| 951 | } |
| 952 | |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 953 | static enum mem_type knl_get_memory_type(struct sbridge_pvt *pvt) |
| 954 | { |
| 955 | /* DDR4 RDIMMS and LRDIMMS are supported */ |
| 956 | return MEM_RDDR4; |
| 957 | } |
| 958 | |
Aristeu Rozanski | f14d689 | 2014-06-02 15:15:23 -0300 | [diff] [blame] | 959 | static u8 get_node_id(struct sbridge_pvt *pvt) |
| 960 | { |
| 961 | u32 reg; |
| 962 | pci_read_config_dword(pvt->pci_br0, SAD_CONTROL, ®); |
| 963 | return GET_BITFIELD(reg, 0, 2); |
| 964 | } |
| 965 | |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 966 | static u8 haswell_get_node_id(struct sbridge_pvt *pvt) |
| 967 | { |
| 968 | u32 reg; |
| 969 | |
| 970 | pci_read_config_dword(pvt->pci_sad1, SAD_CONTROL, ®); |
| 971 | return GET_BITFIELD(reg, 0, 3); |
| 972 | } |
| 973 | |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 974 | static u8 knl_get_node_id(struct sbridge_pvt *pvt) |
| 975 | { |
| 976 | u32 reg; |
| 977 | |
| 978 | pci_read_config_dword(pvt->pci_sad1, SAD_CONTROL, ®); |
| 979 | return GET_BITFIELD(reg, 0, 2); |
| 980 | } |
| 981 | |
| 982 | |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 983 | static u64 haswell_get_tolm(struct sbridge_pvt *pvt) |
| 984 | { |
| 985 | u32 reg; |
| 986 | |
Tony Luck | f7cf2a2 | 2014-10-29 10:36:50 -0700 | [diff] [blame] | 987 | pci_read_config_dword(pvt->info.pci_vtd, HASWELL_TOLM, ®); |
| 988 | return (GET_BITFIELD(reg, 26, 31) << 26) | 0x3ffffff; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | static u64 haswell_get_tohm(struct sbridge_pvt *pvt) |
| 992 | { |
| 993 | u64 rc; |
| 994 | u32 reg; |
| 995 | |
| 996 | pci_read_config_dword(pvt->info.pci_vtd, HASWELL_TOHM_0, ®); |
| 997 | rc = GET_BITFIELD(reg, 26, 31); |
| 998 | pci_read_config_dword(pvt->info.pci_vtd, HASWELL_TOHM_1, ®); |
| 999 | rc = ((reg << 6) | rc) << 26; |
| 1000 | |
| 1001 | return rc | 0x1ffffff; |
| 1002 | } |
| 1003 | |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 1004 | static u64 knl_get_tolm(struct sbridge_pvt *pvt) |
| 1005 | { |
| 1006 | u32 reg; |
| 1007 | |
| 1008 | pci_read_config_dword(pvt->knl.pci_mc_info, KNL_TOLM, ®); |
| 1009 | return (GET_BITFIELD(reg, 26, 31) << 26) | 0x3ffffff; |
| 1010 | } |
| 1011 | |
| 1012 | static u64 knl_get_tohm(struct sbridge_pvt *pvt) |
| 1013 | { |
| 1014 | u64 rc; |
| 1015 | u32 reg_lo, reg_hi; |
| 1016 | |
| 1017 | pci_read_config_dword(pvt->knl.pci_mc_info, KNL_TOHM_0, ®_lo); |
| 1018 | pci_read_config_dword(pvt->knl.pci_mc_info, KNL_TOHM_1, ®_hi); |
| 1019 | rc = ((u64)reg_hi << 32) | reg_lo; |
| 1020 | return rc | 0x3ffffff; |
| 1021 | } |
| 1022 | |
| 1023 | |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 1024 | static u64 haswell_rir_limit(u32 reg) |
| 1025 | { |
| 1026 | return (((u64)GET_BITFIELD(reg, 1, 11) + 1) << 29) - 1; |
| 1027 | } |
| 1028 | |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 1029 | static inline u8 sad_pkg_socket(u8 pkg) |
| 1030 | { |
| 1031 | /* on Ivy Bridge, nodeID is SASS, where A is HA and S is node id */ |
Aristeu Rozanski | 2ff3a30 | 2014-06-02 15:15:27 -0300 | [diff] [blame] | 1032 | return ((pkg >> 3) << 2) | (pkg & 0x3); |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | static inline u8 sad_pkg_ha(u8 pkg) |
| 1036 | { |
| 1037 | return (pkg >> 2) & 0x1; |
| 1038 | } |
| 1039 | |
Tony Luck | ea5dfb5 | 2016-04-14 10:22:02 -0700 | [diff] [blame] | 1040 | static int haswell_chan_hash(int idx, u64 addr) |
| 1041 | { |
| 1042 | int i; |
| 1043 | |
| 1044 | /* |
| 1045 | * XOR even bits from 12:26 to bit0 of idx, |
| 1046 | * odd bits from 13:27 to bit1 |
| 1047 | */ |
| 1048 | for (i = 12; i < 28; i += 2) |
| 1049 | idx ^= (addr >> i) & 3; |
| 1050 | |
| 1051 | return idx; |
| 1052 | } |
| 1053 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1054 | /**************************************************************************** |
| 1055 | Memory check routines |
| 1056 | ****************************************************************************/ |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1057 | static struct pci_dev *get_pdev_same_bus(u8 bus, u32 id) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1058 | { |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1059 | struct pci_dev *pdev = NULL; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1060 | |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1061 | do { |
| 1062 | pdev = pci_get_device(PCI_VENDOR_ID_INTEL, id, pdev); |
| 1063 | if (pdev && pdev->bus->number == bus) |
| 1064 | break; |
| 1065 | } while (pdev); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1066 | |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1067 | return pdev; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | /** |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 1071 | * check_if_ecc_is_active() - Checks if ECC is active |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 1072 | * @bus: Device bus |
| 1073 | * @type: Memory controller type |
| 1074 | * returns: 0 in case ECC is active, -ENODEV if it can't be determined or |
| 1075 | * disabled |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1076 | */ |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1077 | static int check_if_ecc_is_active(const u8 bus, enum type type) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1078 | { |
| 1079 | struct pci_dev *pdev = NULL; |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1080 | u32 mcmtr, id; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1081 | |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 1082 | switch (type) { |
| 1083 | case IVY_BRIDGE: |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1084 | id = PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA; |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 1085 | break; |
| 1086 | case HASWELL: |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 1087 | id = PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TA; |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 1088 | break; |
| 1089 | case SANDY_BRIDGE: |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1090 | id = PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA; |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 1091 | break; |
| 1092 | case BROADWELL: |
| 1093 | id = PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TA; |
| 1094 | break; |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 1095 | case KNIGHTS_LANDING: |
| 1096 | /* |
| 1097 | * KNL doesn't group things by bus the same way |
| 1098 | * SB/IB/Haswell does. |
| 1099 | */ |
| 1100 | id = PCI_DEVICE_ID_INTEL_KNL_IMC_TA; |
| 1101 | break; |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 1102 | default: |
| 1103 | return -ENODEV; |
| 1104 | } |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1105 | |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 1106 | if (type != KNIGHTS_LANDING) |
| 1107 | pdev = get_pdev_same_bus(bus, id); |
| 1108 | else |
| 1109 | pdev = pci_get_device(PCI_VENDOR_ID_INTEL, id, 0); |
| 1110 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1111 | if (!pdev) { |
| 1112 | sbridge_printk(KERN_ERR, "Couldn't find PCI device " |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1113 | "%04x:%04x! on bus %02d\n", |
| 1114 | PCI_VENDOR_ID_INTEL, id, bus); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1115 | return -ENODEV; |
| 1116 | } |
| 1117 | |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 1118 | pci_read_config_dword(pdev, |
| 1119 | type == KNIGHTS_LANDING ? KNL_MCMTR : MCMTR, &mcmtr); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1120 | if (!IS_ECC_ENABLED(mcmtr)) { |
| 1121 | sbridge_printk(KERN_ERR, "ECC is disabled. Aborting\n"); |
| 1122 | return -ENODEV; |
| 1123 | } |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1124 | return 0; |
| 1125 | } |
| 1126 | |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 1127 | /* Low bits of TAD limit, and some metadata. */ |
| 1128 | static const u32 knl_tad_dram_limit_lo[] = { |
| 1129 | 0x400, 0x500, 0x600, 0x700, |
| 1130 | 0x800, 0x900, 0xa00, 0xb00, |
| 1131 | }; |
| 1132 | |
| 1133 | /* Low bits of TAD offset. */ |
| 1134 | static const u32 knl_tad_dram_offset_lo[] = { |
| 1135 | 0x404, 0x504, 0x604, 0x704, |
| 1136 | 0x804, 0x904, 0xa04, 0xb04, |
| 1137 | }; |
| 1138 | |
| 1139 | /* High 16 bits of TAD limit and offset. */ |
| 1140 | static const u32 knl_tad_dram_hi[] = { |
| 1141 | 0x408, 0x508, 0x608, 0x708, |
| 1142 | 0x808, 0x908, 0xa08, 0xb08, |
| 1143 | }; |
| 1144 | |
| 1145 | /* Number of ways a tad entry is interleaved. */ |
| 1146 | static const u32 knl_tad_ways[] = { |
| 1147 | 8, 6, 4, 3, 2, 1, |
| 1148 | }; |
| 1149 | |
| 1150 | /* |
| 1151 | * Retrieve the n'th Target Address Decode table entry |
| 1152 | * from the memory controller's TAD table. |
| 1153 | * |
| 1154 | * @pvt: driver private data |
| 1155 | * @entry: which entry you want to retrieve |
| 1156 | * @mc: which memory controller (0 or 1) |
| 1157 | * @offset: output tad range offset |
| 1158 | * @limit: output address of first byte above tad range |
| 1159 | * @ways: output number of interleave ways |
| 1160 | * |
| 1161 | * The offset value has curious semantics. It's a sort of running total |
| 1162 | * of the sizes of all the memory regions that aren't mapped in this |
| 1163 | * tad table. |
| 1164 | */ |
| 1165 | static int knl_get_tad(const struct sbridge_pvt *pvt, |
| 1166 | const int entry, |
| 1167 | const int mc, |
| 1168 | u64 *offset, |
| 1169 | u64 *limit, |
| 1170 | int *ways) |
| 1171 | { |
| 1172 | u32 reg_limit_lo, reg_offset_lo, reg_hi; |
| 1173 | struct pci_dev *pci_mc; |
| 1174 | int way_id; |
| 1175 | |
| 1176 | switch (mc) { |
| 1177 | case 0: |
| 1178 | pci_mc = pvt->knl.pci_mc0; |
| 1179 | break; |
| 1180 | case 1: |
| 1181 | pci_mc = pvt->knl.pci_mc1; |
| 1182 | break; |
| 1183 | default: |
| 1184 | WARN_ON(1); |
| 1185 | return -EINVAL; |
| 1186 | } |
| 1187 | |
| 1188 | pci_read_config_dword(pci_mc, |
| 1189 | knl_tad_dram_limit_lo[entry], ®_limit_lo); |
| 1190 | pci_read_config_dword(pci_mc, |
| 1191 | knl_tad_dram_offset_lo[entry], ®_offset_lo); |
| 1192 | pci_read_config_dword(pci_mc, |
| 1193 | knl_tad_dram_hi[entry], ®_hi); |
| 1194 | |
| 1195 | /* Is this TAD entry enabled? */ |
| 1196 | if (!GET_BITFIELD(reg_limit_lo, 0, 0)) |
| 1197 | return -ENODEV; |
| 1198 | |
| 1199 | way_id = GET_BITFIELD(reg_limit_lo, 3, 5); |
| 1200 | |
| 1201 | if (way_id < ARRAY_SIZE(knl_tad_ways)) { |
| 1202 | *ways = knl_tad_ways[way_id]; |
| 1203 | } else { |
| 1204 | *ways = 0; |
| 1205 | sbridge_printk(KERN_ERR, |
| 1206 | "Unexpected value %d in mc_tad_limit_lo wayness field\n", |
| 1207 | way_id); |
| 1208 | return -ENODEV; |
| 1209 | } |
| 1210 | |
| 1211 | /* |
| 1212 | * The least significant 6 bits of base and limit are truncated. |
| 1213 | * For limit, we fill the missing bits with 1s. |
| 1214 | */ |
| 1215 | *offset = ((u64) GET_BITFIELD(reg_offset_lo, 6, 31) << 6) | |
| 1216 | ((u64) GET_BITFIELD(reg_hi, 0, 15) << 32); |
| 1217 | *limit = ((u64) GET_BITFIELD(reg_limit_lo, 6, 31) << 6) | 63 | |
| 1218 | ((u64) GET_BITFIELD(reg_hi, 16, 31) << 32); |
| 1219 | |
| 1220 | return 0; |
| 1221 | } |
| 1222 | |
| 1223 | /* Determine which memory controller is responsible for a given channel. */ |
| 1224 | static int knl_channel_mc(int channel) |
| 1225 | { |
| 1226 | WARN_ON(channel < 0 || channel >= 6); |
| 1227 | |
| 1228 | return channel < 3 ? 1 : 0; |
| 1229 | } |
| 1230 | |
| 1231 | /* |
| 1232 | * Get the Nth entry from EDC_ROUTE_TABLE register. |
| 1233 | * (This is the per-tile mapping of logical interleave targets to |
| 1234 | * physical EDC modules.) |
| 1235 | * |
| 1236 | * entry 0: 0:2 |
| 1237 | * 1: 3:5 |
| 1238 | * 2: 6:8 |
| 1239 | * 3: 9:11 |
| 1240 | * 4: 12:14 |
| 1241 | * 5: 15:17 |
| 1242 | * 6: 18:20 |
| 1243 | * 7: 21:23 |
| 1244 | * reserved: 24:31 |
| 1245 | */ |
| 1246 | static u32 knl_get_edc_route(int entry, u32 reg) |
| 1247 | { |
| 1248 | WARN_ON(entry >= KNL_MAX_EDCS); |
| 1249 | return GET_BITFIELD(reg, entry*3, (entry*3)+2); |
| 1250 | } |
| 1251 | |
| 1252 | /* |
| 1253 | * Get the Nth entry from MC_ROUTE_TABLE register. |
| 1254 | * (This is the per-tile mapping of logical interleave targets to |
| 1255 | * physical DRAM channels modules.) |
| 1256 | * |
| 1257 | * entry 0: mc 0:2 channel 18:19 |
| 1258 | * 1: mc 3:5 channel 20:21 |
| 1259 | * 2: mc 6:8 channel 22:23 |
| 1260 | * 3: mc 9:11 channel 24:25 |
| 1261 | * 4: mc 12:14 channel 26:27 |
| 1262 | * 5: mc 15:17 channel 28:29 |
| 1263 | * reserved: 30:31 |
| 1264 | * |
| 1265 | * Though we have 3 bits to identify the MC, we should only see |
| 1266 | * the values 0 or 1. |
| 1267 | */ |
| 1268 | |
| 1269 | static u32 knl_get_mc_route(int entry, u32 reg) |
| 1270 | { |
| 1271 | int mc, chan; |
| 1272 | |
| 1273 | WARN_ON(entry >= KNL_MAX_CHANNELS); |
| 1274 | |
| 1275 | mc = GET_BITFIELD(reg, entry*3, (entry*3)+2); |
| 1276 | chan = GET_BITFIELD(reg, (entry*2) + 18, (entry*2) + 18 + 1); |
| 1277 | |
Lukasz Odzioba | c5b48fa | 2016-07-23 01:44:49 +0200 | [diff] [blame] | 1278 | return knl_channel_remap(mc, chan); |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | /* |
| 1282 | * Render the EDC_ROUTE register in human-readable form. |
| 1283 | * Output string s should be at least KNL_MAX_EDCS*2 bytes. |
| 1284 | */ |
| 1285 | static void knl_show_edc_route(u32 reg, char *s) |
| 1286 | { |
| 1287 | int i; |
| 1288 | |
| 1289 | for (i = 0; i < KNL_MAX_EDCS; i++) { |
| 1290 | s[i*2] = knl_get_edc_route(i, reg) + '0'; |
| 1291 | s[i*2+1] = '-'; |
| 1292 | } |
| 1293 | |
| 1294 | s[KNL_MAX_EDCS*2 - 1] = '\0'; |
| 1295 | } |
| 1296 | |
| 1297 | /* |
| 1298 | * Render the MC_ROUTE register in human-readable form. |
| 1299 | * Output string s should be at least KNL_MAX_CHANNELS*2 bytes. |
| 1300 | */ |
| 1301 | static void knl_show_mc_route(u32 reg, char *s) |
| 1302 | { |
| 1303 | int i; |
| 1304 | |
| 1305 | for (i = 0; i < KNL_MAX_CHANNELS; i++) { |
| 1306 | s[i*2] = knl_get_mc_route(i, reg) + '0'; |
| 1307 | s[i*2+1] = '-'; |
| 1308 | } |
| 1309 | |
| 1310 | s[KNL_MAX_CHANNELS*2 - 1] = '\0'; |
| 1311 | } |
| 1312 | |
| 1313 | #define KNL_EDC_ROUTE 0xb8 |
| 1314 | #define KNL_MC_ROUTE 0xb4 |
| 1315 | |
| 1316 | /* Is this dram rule backed by regular DRAM in flat mode? */ |
| 1317 | #define KNL_EDRAM(reg) GET_BITFIELD(reg, 29, 29) |
| 1318 | |
| 1319 | /* Is this dram rule cached? */ |
| 1320 | #define KNL_CACHEABLE(reg) GET_BITFIELD(reg, 28, 28) |
| 1321 | |
| 1322 | /* Is this rule backed by edc ? */ |
| 1323 | #define KNL_EDRAM_ONLY(reg) GET_BITFIELD(reg, 29, 29) |
| 1324 | |
| 1325 | /* Is this rule backed by DRAM, cacheable in EDRAM? */ |
| 1326 | #define KNL_CACHEABLE(reg) GET_BITFIELD(reg, 28, 28) |
| 1327 | |
| 1328 | /* Is this rule mod3? */ |
| 1329 | #define KNL_MOD3(reg) GET_BITFIELD(reg, 27, 27) |
| 1330 | |
| 1331 | /* |
| 1332 | * Figure out how big our RAM modules are. |
| 1333 | * |
| 1334 | * The DIMMMTR register in KNL doesn't tell us the size of the DIMMs, so we |
| 1335 | * have to figure this out from the SAD rules, interleave lists, route tables, |
| 1336 | * and TAD rules. |
| 1337 | * |
| 1338 | * SAD rules can have holes in them (e.g. the 3G-4G hole), so we have to |
| 1339 | * inspect the TAD rules to figure out how large the SAD regions really are. |
| 1340 | * |
| 1341 | * When we know the real size of a SAD region and how many ways it's |
| 1342 | * interleaved, we know the individual contribution of each channel to |
| 1343 | * TAD is size/ways. |
| 1344 | * |
| 1345 | * Finally, we have to check whether each channel participates in each SAD |
| 1346 | * region. |
| 1347 | * |
| 1348 | * Fortunately, KNL only supports one DIMM per channel, so once we know how |
| 1349 | * much memory the channel uses, we know the DIMM is at least that large. |
| 1350 | * (The BIOS might possibly choose not to map all available memory, in which |
| 1351 | * case we will underreport the size of the DIMM.) |
| 1352 | * |
| 1353 | * In theory, we could try to determine the EDC sizes as well, but that would |
| 1354 | * only work in flat mode, not in cache mode. |
| 1355 | * |
| 1356 | * @mc_sizes: Output sizes of channels (must have space for KNL_MAX_CHANNELS |
| 1357 | * elements) |
| 1358 | */ |
| 1359 | static int knl_get_dimm_capacity(struct sbridge_pvt *pvt, u64 *mc_sizes) |
| 1360 | { |
| 1361 | u64 sad_base, sad_size, sad_limit = 0; |
| 1362 | u64 tad_base, tad_size, tad_limit, tad_deadspace, tad_livespace; |
| 1363 | int sad_rule = 0; |
| 1364 | int tad_rule = 0; |
| 1365 | int intrlv_ways, tad_ways; |
| 1366 | u32 first_pkg, pkg; |
| 1367 | int i; |
| 1368 | u64 sad_actual_size[2]; /* sad size accounting for holes, per mc */ |
| 1369 | u32 dram_rule, interleave_reg; |
| 1370 | u32 mc_route_reg[KNL_MAX_CHAS]; |
| 1371 | u32 edc_route_reg[KNL_MAX_CHAS]; |
| 1372 | int edram_only; |
| 1373 | char edc_route_string[KNL_MAX_EDCS*2]; |
| 1374 | char mc_route_string[KNL_MAX_CHANNELS*2]; |
| 1375 | int cur_reg_start; |
| 1376 | int mc; |
| 1377 | int channel; |
| 1378 | int way; |
| 1379 | int participants[KNL_MAX_CHANNELS]; |
| 1380 | int participant_count = 0; |
| 1381 | |
| 1382 | for (i = 0; i < KNL_MAX_CHANNELS; i++) |
| 1383 | mc_sizes[i] = 0; |
| 1384 | |
| 1385 | /* Read the EDC route table in each CHA. */ |
| 1386 | cur_reg_start = 0; |
| 1387 | for (i = 0; i < KNL_MAX_CHAS; i++) { |
| 1388 | pci_read_config_dword(pvt->knl.pci_cha[i], |
| 1389 | KNL_EDC_ROUTE, &edc_route_reg[i]); |
| 1390 | |
| 1391 | if (i > 0 && edc_route_reg[i] != edc_route_reg[i-1]) { |
| 1392 | knl_show_edc_route(edc_route_reg[i-1], |
| 1393 | edc_route_string); |
| 1394 | if (cur_reg_start == i-1) |
| 1395 | edac_dbg(0, "edc route table for CHA %d: %s\n", |
| 1396 | cur_reg_start, edc_route_string); |
| 1397 | else |
| 1398 | edac_dbg(0, "edc route table for CHA %d-%d: %s\n", |
| 1399 | cur_reg_start, i-1, edc_route_string); |
| 1400 | cur_reg_start = i; |
| 1401 | } |
| 1402 | } |
| 1403 | knl_show_edc_route(edc_route_reg[i-1], edc_route_string); |
| 1404 | if (cur_reg_start == i-1) |
| 1405 | edac_dbg(0, "edc route table for CHA %d: %s\n", |
| 1406 | cur_reg_start, edc_route_string); |
| 1407 | else |
| 1408 | edac_dbg(0, "edc route table for CHA %d-%d: %s\n", |
| 1409 | cur_reg_start, i-1, edc_route_string); |
| 1410 | |
| 1411 | /* Read the MC route table in each CHA. */ |
| 1412 | cur_reg_start = 0; |
| 1413 | for (i = 0; i < KNL_MAX_CHAS; i++) { |
| 1414 | pci_read_config_dword(pvt->knl.pci_cha[i], |
| 1415 | KNL_MC_ROUTE, &mc_route_reg[i]); |
| 1416 | |
| 1417 | if (i > 0 && mc_route_reg[i] != mc_route_reg[i-1]) { |
| 1418 | knl_show_mc_route(mc_route_reg[i-1], mc_route_string); |
| 1419 | if (cur_reg_start == i-1) |
| 1420 | edac_dbg(0, "mc route table for CHA %d: %s\n", |
| 1421 | cur_reg_start, mc_route_string); |
| 1422 | else |
| 1423 | edac_dbg(0, "mc route table for CHA %d-%d: %s\n", |
| 1424 | cur_reg_start, i-1, mc_route_string); |
| 1425 | cur_reg_start = i; |
| 1426 | } |
| 1427 | } |
| 1428 | knl_show_mc_route(mc_route_reg[i-1], mc_route_string); |
| 1429 | if (cur_reg_start == i-1) |
| 1430 | edac_dbg(0, "mc route table for CHA %d: %s\n", |
| 1431 | cur_reg_start, mc_route_string); |
| 1432 | else |
| 1433 | edac_dbg(0, "mc route table for CHA %d-%d: %s\n", |
| 1434 | cur_reg_start, i-1, mc_route_string); |
| 1435 | |
| 1436 | /* Process DRAM rules */ |
| 1437 | for (sad_rule = 0; sad_rule < pvt->info.max_sad; sad_rule++) { |
| 1438 | /* previous limit becomes the new base */ |
| 1439 | sad_base = sad_limit; |
| 1440 | |
| 1441 | pci_read_config_dword(pvt->pci_sad0, |
| 1442 | pvt->info.dram_rule[sad_rule], &dram_rule); |
| 1443 | |
| 1444 | if (!DRAM_RULE_ENABLE(dram_rule)) |
| 1445 | break; |
| 1446 | |
| 1447 | edram_only = KNL_EDRAM_ONLY(dram_rule); |
| 1448 | |
| 1449 | sad_limit = pvt->info.sad_limit(dram_rule)+1; |
| 1450 | sad_size = sad_limit - sad_base; |
| 1451 | |
| 1452 | pci_read_config_dword(pvt->pci_sad0, |
| 1453 | pvt->info.interleave_list[sad_rule], &interleave_reg); |
| 1454 | |
| 1455 | /* |
| 1456 | * Find out how many ways this dram rule is interleaved. |
| 1457 | * We stop when we see the first channel again. |
| 1458 | */ |
| 1459 | first_pkg = sad_pkg(pvt->info.interleave_pkg, |
| 1460 | interleave_reg, 0); |
| 1461 | for (intrlv_ways = 1; intrlv_ways < 8; intrlv_ways++) { |
| 1462 | pkg = sad_pkg(pvt->info.interleave_pkg, |
| 1463 | interleave_reg, intrlv_ways); |
| 1464 | |
| 1465 | if ((pkg & 0x8) == 0) { |
| 1466 | /* |
| 1467 | * 0 bit means memory is non-local, |
| 1468 | * which KNL doesn't support |
| 1469 | */ |
| 1470 | edac_dbg(0, "Unexpected interleave target %d\n", |
| 1471 | pkg); |
| 1472 | return -1; |
| 1473 | } |
| 1474 | |
| 1475 | if (pkg == first_pkg) |
| 1476 | break; |
| 1477 | } |
| 1478 | if (KNL_MOD3(dram_rule)) |
| 1479 | intrlv_ways *= 3; |
| 1480 | |
| 1481 | edac_dbg(3, "dram rule %d (base 0x%llx, limit 0x%llx), %d way interleave%s\n", |
| 1482 | sad_rule, |
| 1483 | sad_base, |
| 1484 | sad_limit, |
| 1485 | intrlv_ways, |
| 1486 | edram_only ? ", EDRAM" : ""); |
| 1487 | |
| 1488 | /* |
| 1489 | * Find out how big the SAD region really is by iterating |
| 1490 | * over TAD tables (SAD regions may contain holes). |
| 1491 | * Each memory controller might have a different TAD table, so |
| 1492 | * we have to look at both. |
| 1493 | * |
| 1494 | * Livespace is the memory that's mapped in this TAD table, |
| 1495 | * deadspace is the holes (this could be the MMIO hole, or it |
| 1496 | * could be memory that's mapped by the other TAD table but |
| 1497 | * not this one). |
| 1498 | */ |
| 1499 | for (mc = 0; mc < 2; mc++) { |
| 1500 | sad_actual_size[mc] = 0; |
| 1501 | tad_livespace = 0; |
| 1502 | for (tad_rule = 0; |
| 1503 | tad_rule < ARRAY_SIZE( |
| 1504 | knl_tad_dram_limit_lo); |
| 1505 | tad_rule++) { |
| 1506 | if (knl_get_tad(pvt, |
| 1507 | tad_rule, |
| 1508 | mc, |
| 1509 | &tad_deadspace, |
| 1510 | &tad_limit, |
| 1511 | &tad_ways)) |
| 1512 | break; |
| 1513 | |
| 1514 | tad_size = (tad_limit+1) - |
| 1515 | (tad_livespace + tad_deadspace); |
| 1516 | tad_livespace += tad_size; |
| 1517 | tad_base = (tad_limit+1) - tad_size; |
| 1518 | |
| 1519 | if (tad_base < sad_base) { |
| 1520 | if (tad_limit > sad_base) |
| 1521 | edac_dbg(0, "TAD region overlaps lower SAD boundary -- TAD tables may be configured incorrectly.\n"); |
| 1522 | } else if (tad_base < sad_limit) { |
| 1523 | if (tad_limit+1 > sad_limit) { |
| 1524 | edac_dbg(0, "TAD region overlaps upper SAD boundary -- TAD tables may be configured incorrectly.\n"); |
| 1525 | } else { |
| 1526 | /* TAD region is completely inside SAD region */ |
| 1527 | edac_dbg(3, "TAD region %d 0x%llx - 0x%llx (%lld bytes) table%d\n", |
| 1528 | tad_rule, tad_base, |
| 1529 | tad_limit, tad_size, |
| 1530 | mc); |
| 1531 | sad_actual_size[mc] += tad_size; |
| 1532 | } |
| 1533 | } |
| 1534 | tad_base = tad_limit+1; |
| 1535 | } |
| 1536 | } |
| 1537 | |
| 1538 | for (mc = 0; mc < 2; mc++) { |
| 1539 | edac_dbg(3, " total TAD DRAM footprint in table%d : 0x%llx (%lld bytes)\n", |
| 1540 | mc, sad_actual_size[mc], sad_actual_size[mc]); |
| 1541 | } |
| 1542 | |
| 1543 | /* Ignore EDRAM rule */ |
| 1544 | if (edram_only) |
| 1545 | continue; |
| 1546 | |
| 1547 | /* Figure out which channels participate in interleave. */ |
| 1548 | for (channel = 0; channel < KNL_MAX_CHANNELS; channel++) |
| 1549 | participants[channel] = 0; |
| 1550 | |
| 1551 | /* For each channel, does at least one CHA have |
| 1552 | * this channel mapped to the given target? |
| 1553 | */ |
| 1554 | for (channel = 0; channel < KNL_MAX_CHANNELS; channel++) { |
| 1555 | for (way = 0; way < intrlv_ways; way++) { |
| 1556 | int target; |
| 1557 | int cha; |
| 1558 | |
| 1559 | if (KNL_MOD3(dram_rule)) |
| 1560 | target = way; |
| 1561 | else |
| 1562 | target = 0x7 & sad_pkg( |
| 1563 | pvt->info.interleave_pkg, interleave_reg, way); |
| 1564 | |
| 1565 | for (cha = 0; cha < KNL_MAX_CHAS; cha++) { |
| 1566 | if (knl_get_mc_route(target, |
| 1567 | mc_route_reg[cha]) == channel |
Hubert Chrzaniuk | 83bdaad | 2016-03-07 15:30:45 +0100 | [diff] [blame] | 1568 | && !participants[channel]) { |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 1569 | participant_count++; |
| 1570 | participants[channel] = 1; |
| 1571 | break; |
| 1572 | } |
| 1573 | } |
| 1574 | } |
| 1575 | } |
| 1576 | |
| 1577 | if (participant_count != intrlv_ways) |
| 1578 | edac_dbg(0, "participant_count (%d) != interleave_ways (%d): DIMM size may be incorrect\n", |
| 1579 | participant_count, intrlv_ways); |
| 1580 | |
| 1581 | for (channel = 0; channel < KNL_MAX_CHANNELS; channel++) { |
| 1582 | mc = knl_channel_mc(channel); |
| 1583 | if (participants[channel]) { |
| 1584 | edac_dbg(4, "mc channel %d contributes %lld bytes via sad entry %d\n", |
| 1585 | channel, |
| 1586 | sad_actual_size[mc]/intrlv_ways, |
| 1587 | sad_rule); |
| 1588 | mc_sizes[channel] += |
| 1589 | sad_actual_size[mc]/intrlv_ways; |
| 1590 | } |
| 1591 | } |
| 1592 | } |
| 1593 | |
| 1594 | return 0; |
| 1595 | } |
| 1596 | |
Mauro Carvalho Chehab | 084a4fc | 2012-01-27 18:38:08 -0300 | [diff] [blame] | 1597 | static int get_dimm_config(struct mem_ctl_info *mci) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1598 | { |
| 1599 | struct sbridge_pvt *pvt = mci->pvt_info; |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 1600 | struct dimm_info *dimm; |
Mauro Carvalho Chehab | deb09dd | 2012-09-20 12:09:30 -0300 | [diff] [blame] | 1601 | unsigned i, j, banks, ranks, rows, cols, npages; |
| 1602 | u64 size; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1603 | u32 reg; |
| 1604 | enum edac_type mode; |
Mark A. Grondona | c6e13b5 | 2011-10-18 11:02:58 -0200 | [diff] [blame] | 1605 | enum mem_type mtype; |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 1606 | int channels = pvt->info.type == KNIGHTS_LANDING ? |
| 1607 | KNL_MAX_CHANNELS : NUM_CHANNELS; |
| 1608 | u64 knl_mc_sizes[KNL_MAX_CHANNELS]; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1609 | |
Tony Luck | ea5dfb5 | 2016-04-14 10:22:02 -0700 | [diff] [blame] | 1610 | if (pvt->info.type == HASWELL || pvt->info.type == BROADWELL) { |
| 1611 | pci_read_config_dword(pvt->pci_ha0, HASWELL_HASYSDEFEATURE2, ®); |
| 1612 | pvt->is_chan_hash = GET_BITFIELD(reg, 21, 21); |
| 1613 | } |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 1614 | if (pvt->info.type == HASWELL || pvt->info.type == BROADWELL || |
| 1615 | pvt->info.type == KNIGHTS_LANDING) |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 1616 | pci_read_config_dword(pvt->pci_sad1, SAD_TARGET, ®); |
| 1617 | else |
| 1618 | pci_read_config_dword(pvt->pci_br0, SAD_TARGET, ®); |
| 1619 | |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 1620 | if (pvt->info.type == KNIGHTS_LANDING) |
| 1621 | pvt->sbridge_dev->source_id = SOURCE_ID_KNL(reg); |
| 1622 | else |
| 1623 | pvt->sbridge_dev->source_id = SOURCE_ID(reg); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1624 | |
Aristeu Rozanski | f14d689 | 2014-06-02 15:15:23 -0300 | [diff] [blame] | 1625 | pvt->sbridge_dev->node_id = pvt->info.get_node_id(pvt); |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1626 | edac_dbg(0, "mc#%d: Node ID: %d, source ID: %d\n", |
| 1627 | pvt->sbridge_dev->mc, |
| 1628 | pvt->sbridge_dev->node_id, |
| 1629 | pvt->sbridge_dev->source_id); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1630 | |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 1631 | /* KNL doesn't support mirroring or lockstep, |
| 1632 | * and is always closed page |
| 1633 | */ |
| 1634 | if (pvt->info.type == KNIGHTS_LANDING) { |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1635 | mode = EDAC_S4ECD4ED; |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 1636 | pvt->is_mirrored = false; |
| 1637 | |
| 1638 | if (knl_get_dimm_capacity(pvt, knl_mc_sizes) != 0) |
| 1639 | return -1; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1640 | } else { |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 1641 | pci_read_config_dword(pvt->pci_ras, RASENABLES, ®); |
| 1642 | if (IS_MIRROR_ENABLED(reg)) { |
| 1643 | edac_dbg(0, "Memory mirror is enabled\n"); |
| 1644 | pvt->is_mirrored = true; |
| 1645 | } else { |
| 1646 | edac_dbg(0, "Memory mirror is disabled\n"); |
| 1647 | pvt->is_mirrored = false; |
| 1648 | } |
| 1649 | |
| 1650 | pci_read_config_dword(pvt->pci_ta, MCMTR, &pvt->info.mcmtr); |
| 1651 | if (IS_LOCKSTEP_ENABLED(pvt->info.mcmtr)) { |
| 1652 | edac_dbg(0, "Lockstep is enabled\n"); |
| 1653 | mode = EDAC_S8ECD8ED; |
| 1654 | pvt->is_lockstep = true; |
| 1655 | } else { |
| 1656 | edac_dbg(0, "Lockstep is disabled\n"); |
| 1657 | mode = EDAC_S4ECD4ED; |
| 1658 | pvt->is_lockstep = false; |
| 1659 | } |
| 1660 | if (IS_CLOSE_PG(pvt->info.mcmtr)) { |
| 1661 | edac_dbg(0, "address map is on closed page mode\n"); |
| 1662 | pvt->is_close_pg = true; |
| 1663 | } else { |
| 1664 | edac_dbg(0, "address map is on open page mode\n"); |
| 1665 | pvt->is_close_pg = false; |
| 1666 | } |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1667 | } |
| 1668 | |
Aristeu Rozanski | 9e37544 | 2014-06-02 15:15:22 -0300 | [diff] [blame] | 1669 | mtype = pvt->info.get_memory_type(pvt); |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 1670 | if (mtype == MEM_RDDR3 || mtype == MEM_RDDR4) |
Aristeu Rozanski | 9e37544 | 2014-06-02 15:15:22 -0300 | [diff] [blame] | 1671 | edac_dbg(0, "Memory is registered\n"); |
| 1672 | else if (mtype == MEM_UNKNOWN) |
Luck, Tony | de4772c | 2013-03-28 09:59:15 -0700 | [diff] [blame] | 1673 | edac_dbg(0, "Cannot determine memory type\n"); |
Aristeu Rozanski | 9e37544 | 2014-06-02 15:15:22 -0300 | [diff] [blame] | 1674 | else |
| 1675 | edac_dbg(0, "Memory is unregistered\n"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1676 | |
Tony Luck | fec53af | 2014-12-02 09:41:58 -0800 | [diff] [blame] | 1677 | if (mtype == MEM_DDR4 || mtype == MEM_RDDR4) |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 1678 | banks = 16; |
| 1679 | else |
| 1680 | banks = 8; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1681 | |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 1682 | for (i = 0; i < channels; i++) { |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1683 | u32 mtr; |
| 1684 | |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 1685 | int max_dimms_per_channel; |
| 1686 | |
| 1687 | if (pvt->info.type == KNIGHTS_LANDING) { |
| 1688 | max_dimms_per_channel = 1; |
| 1689 | if (!pvt->knl.pci_channel[i]) |
| 1690 | continue; |
| 1691 | } else { |
| 1692 | max_dimms_per_channel = ARRAY_SIZE(mtr_regs); |
| 1693 | if (!pvt->pci_tad[i]) |
| 1694 | continue; |
| 1695 | } |
| 1696 | |
| 1697 | for (j = 0; j < max_dimms_per_channel; j++) { |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 1698 | dimm = EDAC_DIMM_PTR(mci->layers, mci->dimms, mci->n_layers, |
| 1699 | i, j, 0); |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 1700 | if (pvt->info.type == KNIGHTS_LANDING) { |
| 1701 | pci_read_config_dword(pvt->knl.pci_channel[i], |
| 1702 | knl_mtr_reg, &mtr); |
| 1703 | } else { |
| 1704 | pci_read_config_dword(pvt->pci_tad[i], |
| 1705 | mtr_regs[j], &mtr); |
| 1706 | } |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1707 | edac_dbg(4, "Channel #%d MTR%d = %x\n", i, j, mtr); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1708 | if (IS_DIMM_PRESENT(mtr)) { |
| 1709 | pvt->channel[i].dimms++; |
| 1710 | |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 1711 | ranks = numrank(pvt->info.type, mtr); |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 1712 | |
| 1713 | if (pvt->info.type == KNIGHTS_LANDING) { |
| 1714 | /* For DDR4, this is fixed. */ |
| 1715 | cols = 1 << 10; |
| 1716 | rows = knl_mc_sizes[i] / |
| 1717 | ((u64) cols * ranks * banks * 8); |
| 1718 | } else { |
| 1719 | rows = numrow(mtr); |
| 1720 | cols = numcol(mtr); |
| 1721 | } |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1722 | |
Mauro Carvalho Chehab | deb09dd | 2012-09-20 12:09:30 -0300 | [diff] [blame] | 1723 | size = ((u64)rows * cols * banks * ranks) >> (20 - 3); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1724 | npages = MiB_TO_PAGES(size); |
| 1725 | |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 1726 | edac_dbg(0, "mc#%d: ha %d channel %d, dimm %d, %lld Mb (%d pages) bank: %d, rank: %d, row: %#x, col: %#x\n", |
| 1727 | pvt->sbridge_dev->mc, i/4, i%4, j, |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1728 | size, npages, |
| 1729 | banks, ranks, rows, cols); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1730 | |
Mauro Carvalho Chehab | a895bf8 | 2012-01-28 09:09:38 -0300 | [diff] [blame] | 1731 | dimm->nr_pages = npages; |
Mauro Carvalho Chehab | 084a4fc | 2012-01-27 18:38:08 -0300 | [diff] [blame] | 1732 | dimm->grain = 32; |
Aristeu Rozanski | 12f0721 | 2015-06-12 15:08:17 -0400 | [diff] [blame] | 1733 | dimm->dtype = pvt->info.get_width(pvt, mtr); |
Mauro Carvalho Chehab | 084a4fc | 2012-01-27 18:38:08 -0300 | [diff] [blame] | 1734 | dimm->mtype = mtype; |
| 1735 | dimm->edac_mode = mode; |
| 1736 | snprintf(dimm->label, sizeof(dimm->label), |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 1737 | "CPU_SrcID#%u_Ha#%u_Chan#%u_DIMM#%u", |
| 1738 | pvt->sbridge_dev->source_id, i/4, i%4, j); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1739 | } |
| 1740 | } |
| 1741 | } |
| 1742 | |
| 1743 | return 0; |
| 1744 | } |
| 1745 | |
| 1746 | static void get_memory_layout(const struct mem_ctl_info *mci) |
| 1747 | { |
| 1748 | struct sbridge_pvt *pvt = mci->pvt_info; |
| 1749 | int i, j, k, n_sads, n_tads, sad_interl; |
| 1750 | u32 reg; |
| 1751 | u64 limit, prv = 0; |
| 1752 | u64 tmp_mb; |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 1753 | u32 gb, mb; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1754 | u32 rir_way; |
| 1755 | |
| 1756 | /* |
| 1757 | * Step 1) Get TOLM/TOHM ranges |
| 1758 | */ |
| 1759 | |
Aristeu Rozanski | fb79a50 | 2013-10-30 13:26:57 -0300 | [diff] [blame] | 1760 | pvt->tolm = pvt->info.get_tolm(pvt); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1761 | tmp_mb = (1 + pvt->tolm) >> 20; |
| 1762 | |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 1763 | gb = div_u64_rem(tmp_mb, 1024, &mb); |
| 1764 | edac_dbg(0, "TOLM: %u.%03u GB (0x%016Lx)\n", |
| 1765 | gb, (mb*1000)/1024, (u64)pvt->tolm); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1766 | |
| 1767 | /* Address range is already 45:25 */ |
Aristeu Rozanski | 8fd6a43 | 2013-10-30 13:26:59 -0300 | [diff] [blame] | 1768 | pvt->tohm = pvt->info.get_tohm(pvt); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1769 | tmp_mb = (1 + pvt->tohm) >> 20; |
| 1770 | |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 1771 | gb = div_u64_rem(tmp_mb, 1024, &mb); |
| 1772 | edac_dbg(0, "TOHM: %u.%03u GB (0x%016Lx)\n", |
| 1773 | gb, (mb*1000)/1024, (u64)pvt->tohm); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1774 | |
| 1775 | /* |
| 1776 | * Step 2) Get SAD range and SAD Interleave list |
| 1777 | * TAD registers contain the interleave wayness. However, it |
| 1778 | * seems simpler to just discover it indirectly, with the |
| 1779 | * algorithm bellow. |
| 1780 | */ |
| 1781 | prv = 0; |
Aristeu Rozanski | 464f1d8 | 2013-10-30 13:27:00 -0300 | [diff] [blame] | 1782 | for (n_sads = 0; n_sads < pvt->info.max_sad; n_sads++) { |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1783 | /* SAD_LIMIT Address range is 45:26 */ |
Aristeu Rozanski | 464f1d8 | 2013-10-30 13:27:00 -0300 | [diff] [blame] | 1784 | pci_read_config_dword(pvt->pci_sad0, pvt->info.dram_rule[n_sads], |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1785 | ®); |
Jim Snow | c59f9c0 | 2015-12-03 10:48:52 +0100 | [diff] [blame] | 1786 | limit = pvt->info.sad_limit(reg); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1787 | |
| 1788 | if (!DRAM_RULE_ENABLE(reg)) |
| 1789 | continue; |
| 1790 | |
| 1791 | if (limit <= prv) |
| 1792 | break; |
| 1793 | |
| 1794 | tmp_mb = (limit + 1) >> 20; |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 1795 | gb = div_u64_rem(tmp_mb, 1024, &mb); |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1796 | edac_dbg(0, "SAD#%d %s up to %u.%03u GB (0x%016Lx) Interleave: %s reg=0x%08x\n", |
| 1797 | n_sads, |
Jim Snow | c59f9c0 | 2015-12-03 10:48:52 +0100 | [diff] [blame] | 1798 | show_dram_attr(pvt->info.dram_attr(reg)), |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 1799 | gb, (mb*1000)/1024, |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1800 | ((u64)tmp_mb) << 20L, |
Nicolas Iooss | 127c122 | 2017-01-22 18:28:06 +0100 | [diff] [blame] | 1801 | get_intlv_mode_str(reg, pvt->info.type), |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1802 | reg); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1803 | prv = limit; |
| 1804 | |
Aristeu Rozanski | ef1ce51 | 2013-10-30 13:27:01 -0300 | [diff] [blame] | 1805 | pci_read_config_dword(pvt->pci_sad0, pvt->info.interleave_list[n_sads], |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1806 | ®); |
Aristeu Rozanski | cc31199 | 2013-10-30 13:27:02 -0300 | [diff] [blame] | 1807 | sad_interl = sad_pkg(pvt->info.interleave_pkg, reg, 0); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1808 | for (j = 0; j < 8; j++) { |
Aristeu Rozanski | cc31199 | 2013-10-30 13:27:02 -0300 | [diff] [blame] | 1809 | u32 pkg = sad_pkg(pvt->info.interleave_pkg, reg, j); |
| 1810 | if (j > 0 && sad_interl == pkg) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1811 | break; |
| 1812 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1813 | edac_dbg(0, "SAD#%d, interleave #%d: %d\n", |
Aristeu Rozanski | cc31199 | 2013-10-30 13:27:02 -0300 | [diff] [blame] | 1814 | n_sads, j, pkg); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1815 | } |
| 1816 | } |
| 1817 | |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 1818 | if (pvt->info.type == KNIGHTS_LANDING) |
| 1819 | return; |
| 1820 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1821 | /* |
| 1822 | * Step 3) Get TAD range |
| 1823 | */ |
| 1824 | prv = 0; |
| 1825 | for (n_tads = 0; n_tads < MAX_TAD; n_tads++) { |
| 1826 | pci_read_config_dword(pvt->pci_ha0, tad_dram_rule[n_tads], |
| 1827 | ®); |
| 1828 | limit = TAD_LIMIT(reg); |
| 1829 | if (limit <= prv) |
| 1830 | break; |
| 1831 | tmp_mb = (limit + 1) >> 20; |
| 1832 | |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 1833 | gb = div_u64_rem(tmp_mb, 1024, &mb); |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1834 | edac_dbg(0, "TAD#%d: up to %u.%03u GB (0x%016Lx), socket interleave %d, memory interleave %d, TGT: %d, %d, %d, %d, reg=0x%08x\n", |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 1835 | n_tads, gb, (mb*1000)/1024, |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1836 | ((u64)tmp_mb) << 20L, |
Luck, Tony | eb1af3b | 2016-03-09 16:40:48 -0800 | [diff] [blame] | 1837 | (u32)(1 << TAD_SOCK(reg)), |
| 1838 | (u32)TAD_CH(reg) + 1, |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1839 | (u32)TAD_TGT0(reg), |
| 1840 | (u32)TAD_TGT1(reg), |
| 1841 | (u32)TAD_TGT2(reg), |
| 1842 | (u32)TAD_TGT3(reg), |
| 1843 | reg); |
Hui Wang | 7fae0db | 2012-02-06 04:11:01 -0300 | [diff] [blame] | 1844 | prv = limit; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1845 | } |
| 1846 | |
| 1847 | /* |
| 1848 | * Step 4) Get TAD offsets, per each channel |
| 1849 | */ |
| 1850 | for (i = 0; i < NUM_CHANNELS; i++) { |
| 1851 | if (!pvt->channel[i].dimms) |
| 1852 | continue; |
| 1853 | for (j = 0; j < n_tads; j++) { |
| 1854 | pci_read_config_dword(pvt->pci_tad[i], |
| 1855 | tad_ch_nilv_offset[j], |
| 1856 | ®); |
| 1857 | tmp_mb = TAD_OFFSET(reg) >> 20; |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 1858 | gb = div_u64_rem(tmp_mb, 1024, &mb); |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1859 | edac_dbg(0, "TAD CH#%d, offset #%d: %u.%03u GB (0x%016Lx), reg=0x%08x\n", |
| 1860 | i, j, |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 1861 | gb, (mb*1000)/1024, |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1862 | ((u64)tmp_mb) << 20L, |
| 1863 | reg); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1864 | } |
| 1865 | } |
| 1866 | |
| 1867 | /* |
| 1868 | * Step 6) Get RIR Wayness/Limit, per each channel |
| 1869 | */ |
| 1870 | for (i = 0; i < NUM_CHANNELS; i++) { |
| 1871 | if (!pvt->channel[i].dimms) |
| 1872 | continue; |
| 1873 | for (j = 0; j < MAX_RIR_RANGES; j++) { |
| 1874 | pci_read_config_dword(pvt->pci_tad[i], |
| 1875 | rir_way_limit[j], |
| 1876 | ®); |
| 1877 | |
| 1878 | if (!IS_RIR_VALID(reg)) |
| 1879 | continue; |
| 1880 | |
Aristeu Rozanski | b976bcf | 2014-06-02 15:15:24 -0300 | [diff] [blame] | 1881 | tmp_mb = pvt->info.rir_limit(reg) >> 20; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1882 | rir_way = 1 << RIR_WAY(reg); |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 1883 | gb = div_u64_rem(tmp_mb, 1024, &mb); |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1884 | edac_dbg(0, "CH#%d RIR#%d, limit: %u.%03u GB (0x%016Lx), way: %d, reg=0x%08x\n", |
| 1885 | i, j, |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 1886 | gb, (mb*1000)/1024, |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1887 | ((u64)tmp_mb) << 20L, |
| 1888 | rir_way, |
| 1889 | reg); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1890 | |
| 1891 | for (k = 0; k < rir_way; k++) { |
| 1892 | pci_read_config_dword(pvt->pci_tad[i], |
| 1893 | rir_offset[j][k], |
| 1894 | ®); |
Tony Luck | c7103f6 | 2016-05-31 11:50:28 -0700 | [diff] [blame] | 1895 | tmp_mb = RIR_OFFSET(pvt->info.type, reg) << 6; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1896 | |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 1897 | gb = div_u64_rem(tmp_mb, 1024, &mb); |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1898 | edac_dbg(0, "CH#%d RIR#%d INTL#%d, offset %u.%03u GB (0x%016Lx), tgt: %d, reg=0x%08x\n", |
| 1899 | i, j, k, |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 1900 | gb, (mb*1000)/1024, |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1901 | ((u64)tmp_mb) << 20L, |
Tony Luck | c7103f6 | 2016-05-31 11:50:28 -0700 | [diff] [blame] | 1902 | (u32)RIR_RNK_TGT(pvt->info.type, reg), |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1903 | reg); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1904 | } |
| 1905 | } |
| 1906 | } |
| 1907 | } |
| 1908 | |
Rashika Kheria | 8112c0c | 2013-12-14 19:32:09 +0530 | [diff] [blame] | 1909 | static struct mem_ctl_info *get_mci_for_node_id(u8 node_id) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1910 | { |
| 1911 | struct sbridge_dev *sbridge_dev; |
| 1912 | |
| 1913 | list_for_each_entry(sbridge_dev, &sbridge_edac_list, list) { |
| 1914 | if (sbridge_dev->node_id == node_id) |
| 1915 | return sbridge_dev->mci; |
| 1916 | } |
| 1917 | return NULL; |
| 1918 | } |
| 1919 | |
| 1920 | static int get_memory_error_data(struct mem_ctl_info *mci, |
| 1921 | u64 addr, |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 1922 | u8 *socket, u8 *ha, |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1923 | long *channel_mask, |
| 1924 | u8 *rank, |
Mauro Carvalho Chehab | e17a2f42a | 2012-05-11 11:41:45 -0300 | [diff] [blame] | 1925 | char **area_type, char *msg) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1926 | { |
| 1927 | struct mem_ctl_info *new_mci; |
| 1928 | struct sbridge_pvt *pvt = mci->pvt_info; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 1929 | struct pci_dev *pci_ha; |
Mauro Carvalho Chehab | c41afdc | 2014-06-26 15:35:14 -0300 | [diff] [blame] | 1930 | int n_rir, n_sads, n_tads, sad_way, sck_xch; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1931 | int sad_interl, idx, base_ch; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 1932 | int interleave_mode, shiftup = 0; |
Aristeu Rozanski | ef1ce51 | 2013-10-30 13:27:01 -0300 | [diff] [blame] | 1933 | unsigned sad_interleave[pvt->info.max_interleave]; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 1934 | u32 reg, dram_rule; |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 1935 | u8 ch_way, sck_way, pkg, sad_ha = 0, ch_add = 0; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1936 | u32 tad_offset; |
| 1937 | u32 rir_way; |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 1938 | u32 mb, gb; |
Aristeu Rozanski | bd4b968 | 2013-11-21 09:08:03 -0500 | [diff] [blame] | 1939 | u64 ch_addr, offset, limit = 0, prv = 0; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1940 | |
| 1941 | |
| 1942 | /* |
| 1943 | * Step 0) Check if the address is at special memory ranges |
| 1944 | * The check bellow is probably enough to fill all cases where |
| 1945 | * the error is not inside a memory, except for the legacy |
| 1946 | * range (e. g. VGA addresses). It is unlikely, however, that the |
| 1947 | * memory controller would generate an error on that range. |
| 1948 | */ |
Mauro Carvalho Chehab | 5b889e3 | 2011-11-07 18:26:53 -0300 | [diff] [blame] | 1949 | if ((addr > (u64) pvt->tolm) && (addr < (1LL << 32))) { |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1950 | sprintf(msg, "Error at TOLM area, on addr 0x%08Lx", addr); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1951 | return -EINVAL; |
| 1952 | } |
| 1953 | if (addr >= (u64)pvt->tohm) { |
| 1954 | sprintf(msg, "Error at MMIOH area, on addr 0x%016Lx", addr); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1955 | return -EINVAL; |
| 1956 | } |
| 1957 | |
| 1958 | /* |
| 1959 | * Step 1) Get socket |
| 1960 | */ |
Aristeu Rozanski | 464f1d8 | 2013-10-30 13:27:00 -0300 | [diff] [blame] | 1961 | for (n_sads = 0; n_sads < pvt->info.max_sad; n_sads++) { |
| 1962 | pci_read_config_dword(pvt->pci_sad0, pvt->info.dram_rule[n_sads], |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1963 | ®); |
| 1964 | |
| 1965 | if (!DRAM_RULE_ENABLE(reg)) |
| 1966 | continue; |
| 1967 | |
Jim Snow | c59f9c0 | 2015-12-03 10:48:52 +0100 | [diff] [blame] | 1968 | limit = pvt->info.sad_limit(reg); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1969 | if (limit <= prv) { |
| 1970 | sprintf(msg, "Can't discover the memory socket"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1971 | return -EINVAL; |
| 1972 | } |
| 1973 | if (addr <= limit) |
| 1974 | break; |
| 1975 | prv = limit; |
| 1976 | } |
Aristeu Rozanski | 464f1d8 | 2013-10-30 13:27:00 -0300 | [diff] [blame] | 1977 | if (n_sads == pvt->info.max_sad) { |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1978 | sprintf(msg, "Can't discover the memory socket"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1979 | return -EINVAL; |
| 1980 | } |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 1981 | dram_rule = reg; |
Jim Snow | c59f9c0 | 2015-12-03 10:48:52 +0100 | [diff] [blame] | 1982 | *area_type = show_dram_attr(pvt->info.dram_attr(dram_rule)); |
| 1983 | interleave_mode = pvt->info.interleave_mode(dram_rule); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1984 | |
Aristeu Rozanski | ef1ce51 | 2013-10-30 13:27:01 -0300 | [diff] [blame] | 1985 | pci_read_config_dword(pvt->pci_sad0, pvt->info.interleave_list[n_sads], |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1986 | ®); |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 1987 | |
| 1988 | if (pvt->info.type == SANDY_BRIDGE) { |
| 1989 | sad_interl = sad_pkg(pvt->info.interleave_pkg, reg, 0); |
| 1990 | for (sad_way = 0; sad_way < 8; sad_way++) { |
| 1991 | u32 pkg = sad_pkg(pvt->info.interleave_pkg, reg, sad_way); |
| 1992 | if (sad_way > 0 && sad_interl == pkg) |
| 1993 | break; |
| 1994 | sad_interleave[sad_way] = pkg; |
| 1995 | edac_dbg(0, "SAD interleave #%d: %d\n", |
| 1996 | sad_way, sad_interleave[sad_way]); |
| 1997 | } |
| 1998 | edac_dbg(0, "mc#%d: Error detected on SAD#%d: address 0x%016Lx < 0x%016Lx, Interleave [%d:6]%s\n", |
| 1999 | pvt->sbridge_dev->mc, |
| 2000 | n_sads, |
| 2001 | addr, |
| 2002 | limit, |
| 2003 | sad_way + 7, |
| 2004 | !interleave_mode ? "" : "XOR[18:16]"); |
| 2005 | if (interleave_mode) |
| 2006 | idx = ((addr >> 6) ^ (addr >> 16)) & 7; |
| 2007 | else |
| 2008 | idx = (addr >> 6) & 7; |
| 2009 | switch (sad_way) { |
| 2010 | case 1: |
| 2011 | idx = 0; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2012 | break; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2013 | case 2: |
| 2014 | idx = idx & 1; |
| 2015 | break; |
| 2016 | case 4: |
| 2017 | idx = idx & 3; |
| 2018 | break; |
| 2019 | case 8: |
| 2020 | break; |
| 2021 | default: |
| 2022 | sprintf(msg, "Can't discover socket interleave"); |
| 2023 | return -EINVAL; |
| 2024 | } |
| 2025 | *socket = sad_interleave[idx]; |
| 2026 | edac_dbg(0, "SAD interleave index: %d (wayness %d) = CPU socket %d\n", |
| 2027 | idx, sad_way, *socket); |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 2028 | } else if (pvt->info.type == HASWELL || pvt->info.type == BROADWELL) { |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2029 | int bits, a7mode = A7MODE(dram_rule); |
| 2030 | |
| 2031 | if (a7mode) { |
| 2032 | /* A7 mode swaps P9 with P6 */ |
| 2033 | bits = GET_BITFIELD(addr, 7, 8) << 1; |
| 2034 | bits |= GET_BITFIELD(addr, 9, 9); |
| 2035 | } else |
Tony Luck | bb89e71 | 2015-05-18 17:39:06 -0300 | [diff] [blame] | 2036 | bits = GET_BITFIELD(addr, 6, 8); |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2037 | |
Tony Luck | bb89e71 | 2015-05-18 17:39:06 -0300 | [diff] [blame] | 2038 | if (interleave_mode == 0) { |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2039 | /* interleave mode will XOR {8,7,6} with {18,17,16} */ |
| 2040 | idx = GET_BITFIELD(addr, 16, 18); |
| 2041 | idx ^= bits; |
| 2042 | } else |
| 2043 | idx = bits; |
| 2044 | |
| 2045 | pkg = sad_pkg(pvt->info.interleave_pkg, reg, idx); |
| 2046 | *socket = sad_pkg_socket(pkg); |
| 2047 | sad_ha = sad_pkg_ha(pkg); |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 2048 | if (sad_ha) |
| 2049 | ch_add = 4; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2050 | |
| 2051 | if (a7mode) { |
| 2052 | /* MCChanShiftUpEnable */ |
| 2053 | pci_read_config_dword(pvt->pci_ha0, |
| 2054 | HASWELL_HASYSDEFEATURE2, ®); |
| 2055 | shiftup = GET_BITFIELD(reg, 22, 22); |
| 2056 | } |
| 2057 | |
| 2058 | edac_dbg(0, "SAD interleave package: %d = CPU socket %d, HA %i, shiftup: %i\n", |
| 2059 | idx, *socket, sad_ha, shiftup); |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2060 | } else { |
| 2061 | /* Ivy Bridge's SAD mode doesn't support XOR interleave mode */ |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2062 | idx = (addr >> 6) & 7; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2063 | pkg = sad_pkg(pvt->info.interleave_pkg, reg, idx); |
| 2064 | *socket = sad_pkg_socket(pkg); |
| 2065 | sad_ha = sad_pkg_ha(pkg); |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 2066 | if (sad_ha) |
| 2067 | ch_add = 4; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2068 | edac_dbg(0, "SAD interleave package: %d = CPU socket %d, HA %d\n", |
| 2069 | idx, *socket, sad_ha); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2070 | } |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2071 | |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 2072 | *ha = sad_ha; |
| 2073 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2074 | /* |
| 2075 | * Move to the proper node structure, in order to access the |
| 2076 | * right PCI registers |
| 2077 | */ |
| 2078 | new_mci = get_mci_for_node_id(*socket); |
| 2079 | if (!new_mci) { |
| 2080 | sprintf(msg, "Struct for socket #%u wasn't initialized", |
| 2081 | *socket); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2082 | return -EINVAL; |
| 2083 | } |
| 2084 | mci = new_mci; |
| 2085 | pvt = mci->pvt_info; |
| 2086 | |
| 2087 | /* |
| 2088 | * Step 2) Get memory channel |
| 2089 | */ |
| 2090 | prv = 0; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2091 | if (pvt->info.type == SANDY_BRIDGE) |
| 2092 | pci_ha = pvt->pci_ha0; |
| 2093 | else { |
| 2094 | if (sad_ha) |
| 2095 | pci_ha = pvt->pci_ha1; |
| 2096 | else |
| 2097 | pci_ha = pvt->pci_ha0; |
| 2098 | } |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2099 | for (n_tads = 0; n_tads < MAX_TAD; n_tads++) { |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2100 | pci_read_config_dword(pci_ha, tad_dram_rule[n_tads], ®); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2101 | limit = TAD_LIMIT(reg); |
| 2102 | if (limit <= prv) { |
| 2103 | sprintf(msg, "Can't discover the memory channel"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2104 | return -EINVAL; |
| 2105 | } |
| 2106 | if (addr <= limit) |
| 2107 | break; |
| 2108 | prv = limit; |
| 2109 | } |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2110 | if (n_tads == MAX_TAD) { |
| 2111 | sprintf(msg, "Can't discover the memory channel"); |
| 2112 | return -EINVAL; |
| 2113 | } |
| 2114 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2115 | ch_way = TAD_CH(reg) + 1; |
Tony Luck | ff15e95 | 2016-04-14 10:21:52 -0700 | [diff] [blame] | 2116 | sck_way = TAD_SOCK(reg); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2117 | |
| 2118 | if (ch_way == 3) |
| 2119 | idx = addr >> 6; |
Tony Luck | ea5dfb5 | 2016-04-14 10:22:02 -0700 | [diff] [blame] | 2120 | else { |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2121 | idx = (addr >> (6 + sck_way + shiftup)) & 0x3; |
Tony Luck | ea5dfb5 | 2016-04-14 10:22:02 -0700 | [diff] [blame] | 2122 | if (pvt->is_chan_hash) |
| 2123 | idx = haswell_chan_hash(idx, addr); |
| 2124 | } |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2125 | idx = idx % ch_way; |
| 2126 | |
| 2127 | /* |
| 2128 | * FIXME: Shouldn't we use CHN_IDX_OFFSET() here, when ch_way == 3 ??? |
| 2129 | */ |
| 2130 | switch (idx) { |
| 2131 | case 0: |
| 2132 | base_ch = TAD_TGT0(reg); |
| 2133 | break; |
| 2134 | case 1: |
| 2135 | base_ch = TAD_TGT1(reg); |
| 2136 | break; |
| 2137 | case 2: |
| 2138 | base_ch = TAD_TGT2(reg); |
| 2139 | break; |
| 2140 | case 3: |
| 2141 | base_ch = TAD_TGT3(reg); |
| 2142 | break; |
| 2143 | default: |
| 2144 | sprintf(msg, "Can't discover the TAD target"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2145 | return -EINVAL; |
| 2146 | } |
| 2147 | *channel_mask = 1 << base_ch; |
| 2148 | |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 2149 | pci_read_config_dword(pvt->pci_tad[ch_add + base_ch], |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2150 | tad_ch_nilv_offset[n_tads], |
| 2151 | &tad_offset); |
| 2152 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2153 | if (pvt->is_mirrored) { |
| 2154 | *channel_mask |= 1 << ((base_ch + 2) % 4); |
| 2155 | switch(ch_way) { |
| 2156 | case 2: |
| 2157 | case 4: |
Tony Luck | ff15e95 | 2016-04-14 10:21:52 -0700 | [diff] [blame] | 2158 | sck_xch = (1 << sck_way) * (ch_way >> 1); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2159 | break; |
| 2160 | default: |
| 2161 | sprintf(msg, "Invalid mirror set. Can't decode addr"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2162 | return -EINVAL; |
| 2163 | } |
| 2164 | } else |
| 2165 | sck_xch = (1 << sck_way) * ch_way; |
| 2166 | |
| 2167 | if (pvt->is_lockstep) |
| 2168 | *channel_mask |= 1 << ((base_ch + 1) % 4); |
| 2169 | |
| 2170 | offset = TAD_OFFSET(tad_offset); |
| 2171 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2172 | edac_dbg(0, "TAD#%d: address 0x%016Lx < 0x%016Lx, socket interleave %d, channel interleave %d (offset 0x%08Lx), index %d, base ch: %d, ch mask: 0x%02lx\n", |
| 2173 | n_tads, |
| 2174 | addr, |
| 2175 | limit, |
Luck, Tony | eb1af3b | 2016-03-09 16:40:48 -0800 | [diff] [blame] | 2176 | sck_way, |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2177 | ch_way, |
| 2178 | offset, |
| 2179 | idx, |
| 2180 | base_ch, |
| 2181 | *channel_mask); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2182 | |
| 2183 | /* Calculate channel address */ |
| 2184 | /* Remove the TAD offset */ |
| 2185 | |
| 2186 | if (offset > addr) { |
| 2187 | sprintf(msg, "Can't calculate ch addr: TAD offset 0x%08Lx is too high for addr 0x%08Lx!", |
| 2188 | offset, addr); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2189 | return -EINVAL; |
| 2190 | } |
Luck, Tony | eb1af3b | 2016-03-09 16:40:48 -0800 | [diff] [blame] | 2191 | |
| 2192 | ch_addr = addr - offset; |
| 2193 | ch_addr >>= (6 + shiftup); |
Tony Luck | ff15e95 | 2016-04-14 10:21:52 -0700 | [diff] [blame] | 2194 | ch_addr /= sck_xch; |
Luck, Tony | eb1af3b | 2016-03-09 16:40:48 -0800 | [diff] [blame] | 2195 | ch_addr <<= (6 + shiftup); |
| 2196 | ch_addr |= addr & ((1 << (6 + shiftup)) - 1); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2197 | |
| 2198 | /* |
| 2199 | * Step 3) Decode rank |
| 2200 | */ |
| 2201 | for (n_rir = 0; n_rir < MAX_RIR_RANGES; n_rir++) { |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 2202 | pci_read_config_dword(pvt->pci_tad[ch_add + base_ch], |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2203 | rir_way_limit[n_rir], |
| 2204 | ®); |
| 2205 | |
| 2206 | if (!IS_RIR_VALID(reg)) |
| 2207 | continue; |
| 2208 | |
Aristeu Rozanski | b976bcf | 2014-06-02 15:15:24 -0300 | [diff] [blame] | 2209 | limit = pvt->info.rir_limit(reg); |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 2210 | gb = div_u64_rem(limit >> 20, 1024, &mb); |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2211 | edac_dbg(0, "RIR#%d, limit: %u.%03u GB (0x%016Lx), way: %d\n", |
| 2212 | n_rir, |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 2213 | gb, (mb*1000)/1024, |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2214 | limit, |
| 2215 | 1 << RIR_WAY(reg)); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2216 | if (ch_addr <= limit) |
| 2217 | break; |
| 2218 | } |
| 2219 | if (n_rir == MAX_RIR_RANGES) { |
| 2220 | sprintf(msg, "Can't discover the memory rank for ch addr 0x%08Lx", |
| 2221 | ch_addr); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2222 | return -EINVAL; |
| 2223 | } |
| 2224 | rir_way = RIR_WAY(reg); |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2225 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2226 | if (pvt->is_close_pg) |
| 2227 | idx = (ch_addr >> 6); |
| 2228 | else |
| 2229 | idx = (ch_addr >> 13); /* FIXME: Datasheet says to shift by 15 */ |
| 2230 | idx %= 1 << rir_way; |
| 2231 | |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 2232 | pci_read_config_dword(pvt->pci_tad[ch_add + base_ch], |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2233 | rir_offset[n_rir][idx], |
| 2234 | ®); |
Tony Luck | c7103f6 | 2016-05-31 11:50:28 -0700 | [diff] [blame] | 2235 | *rank = RIR_RNK_TGT(pvt->info.type, reg); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2236 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2237 | edac_dbg(0, "RIR#%d: channel address 0x%08Lx < 0x%08Lx, RIR interleave %d, index %d\n", |
| 2238 | n_rir, |
| 2239 | ch_addr, |
| 2240 | limit, |
| 2241 | rir_way, |
| 2242 | idx); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2243 | |
| 2244 | return 0; |
| 2245 | } |
| 2246 | |
| 2247 | /**************************************************************************** |
| 2248 | Device initialization routines: put/get, init/exit |
| 2249 | ****************************************************************************/ |
| 2250 | |
| 2251 | /* |
| 2252 | * sbridge_put_all_devices 'put' all the devices that we have |
| 2253 | * reserved via 'get' |
| 2254 | */ |
| 2255 | static void sbridge_put_devices(struct sbridge_dev *sbridge_dev) |
| 2256 | { |
| 2257 | int i; |
| 2258 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2259 | edac_dbg(0, "\n"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2260 | for (i = 0; i < sbridge_dev->n_devs; i++) { |
| 2261 | struct pci_dev *pdev = sbridge_dev->pdev[i]; |
| 2262 | if (!pdev) |
| 2263 | continue; |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2264 | edac_dbg(0, "Removing dev %02x:%02x.%d\n", |
| 2265 | pdev->bus->number, |
| 2266 | PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2267 | pci_dev_put(pdev); |
| 2268 | } |
| 2269 | } |
| 2270 | |
| 2271 | static void sbridge_put_all_devices(void) |
| 2272 | { |
| 2273 | struct sbridge_dev *sbridge_dev, *tmp; |
| 2274 | |
| 2275 | list_for_each_entry_safe(sbridge_dev, tmp, &sbridge_edac_list, list) { |
| 2276 | sbridge_put_devices(sbridge_dev); |
| 2277 | free_sbridge_dev(sbridge_dev); |
| 2278 | } |
| 2279 | } |
| 2280 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2281 | static int sbridge_get_onedevice(struct pci_dev **prev, |
| 2282 | u8 *num_mc, |
| 2283 | const struct pci_id_table *table, |
Jim Snow | c1979ba | 2015-12-03 10:48:53 +0100 | [diff] [blame] | 2284 | const unsigned devno, |
| 2285 | const int multi_bus) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2286 | { |
| 2287 | struct sbridge_dev *sbridge_dev; |
| 2288 | const struct pci_id_descr *dev_descr = &table->descr[devno]; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2289 | struct pci_dev *pdev = NULL; |
| 2290 | u8 bus = 0; |
| 2291 | |
Jiang Liu | ec5a0b3 | 2014-02-17 13:10:23 +0800 | [diff] [blame] | 2292 | sbridge_printk(KERN_DEBUG, |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2293 | "Seeking for: PCI ID %04x:%04x\n", |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2294 | PCI_VENDOR_ID_INTEL, dev_descr->dev_id); |
| 2295 | |
| 2296 | pdev = pci_get_device(PCI_VENDOR_ID_INTEL, |
| 2297 | dev_descr->dev_id, *prev); |
| 2298 | |
| 2299 | if (!pdev) { |
| 2300 | if (*prev) { |
| 2301 | *prev = pdev; |
| 2302 | return 0; |
| 2303 | } |
| 2304 | |
| 2305 | if (dev_descr->optional) |
| 2306 | return 0; |
| 2307 | |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2308 | /* if the HA wasn't found */ |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2309 | if (devno == 0) |
| 2310 | return -ENODEV; |
| 2311 | |
| 2312 | sbridge_printk(KERN_INFO, |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2313 | "Device not found: %04x:%04x\n", |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2314 | PCI_VENDOR_ID_INTEL, dev_descr->dev_id); |
| 2315 | |
| 2316 | /* End of list, leave */ |
| 2317 | return -ENODEV; |
| 2318 | } |
| 2319 | bus = pdev->bus->number; |
| 2320 | |
Jim Snow | c1979ba | 2015-12-03 10:48:53 +0100 | [diff] [blame] | 2321 | sbridge_dev = get_sbridge_dev(bus, multi_bus); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2322 | if (!sbridge_dev) { |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 2323 | sbridge_dev = alloc_sbridge_dev(bus, dev_descr->dom, table); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2324 | if (!sbridge_dev) { |
| 2325 | pci_dev_put(pdev); |
| 2326 | return -ENOMEM; |
| 2327 | } |
| 2328 | (*num_mc)++; |
| 2329 | } |
| 2330 | |
| 2331 | if (sbridge_dev->pdev[devno]) { |
| 2332 | sbridge_printk(KERN_ERR, |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2333 | "Duplicated device for %04x:%04x\n", |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2334 | PCI_VENDOR_ID_INTEL, dev_descr->dev_id); |
| 2335 | pci_dev_put(pdev); |
| 2336 | return -ENODEV; |
| 2337 | } |
| 2338 | |
| 2339 | sbridge_dev->pdev[devno] = pdev; |
| 2340 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2341 | /* Be sure that the device is enabled */ |
| 2342 | if (unlikely(pci_enable_device(pdev) < 0)) { |
| 2343 | sbridge_printk(KERN_ERR, |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2344 | "Couldn't enable %04x:%04x\n", |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2345 | PCI_VENDOR_ID_INTEL, dev_descr->dev_id); |
| 2346 | return -ENODEV; |
| 2347 | } |
| 2348 | |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2349 | edac_dbg(0, "Detected %04x:%04x\n", |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2350 | PCI_VENDOR_ID_INTEL, dev_descr->dev_id); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2351 | |
| 2352 | /* |
| 2353 | * As stated on drivers/pci/search.c, the reference count for |
| 2354 | * @from is always decremented if it is not %NULL. So, as we need |
| 2355 | * to get all devices up to null, we need to do a get for the device |
| 2356 | */ |
| 2357 | pci_dev_get(pdev); |
| 2358 | |
| 2359 | *prev = pdev; |
| 2360 | |
| 2361 | return 0; |
| 2362 | } |
| 2363 | |
Aristeu Rozanski | 5153a0f | 2013-10-30 13:27:03 -0300 | [diff] [blame] | 2364 | /* |
| 2365 | * sbridge_get_all_devices - Find and perform 'get' operation on the MCH's |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2366 | * devices we want to reference for this driver. |
Aristeu Rozanski | 5153a0f | 2013-10-30 13:27:03 -0300 | [diff] [blame] | 2367 | * @num_mc: pointer to the memory controllers count, to be incremented in case |
Mauro Carvalho Chehab | c41afdc | 2014-06-26 15:35:14 -0300 | [diff] [blame] | 2368 | * of success. |
Aristeu Rozanski | 5153a0f | 2013-10-30 13:27:03 -0300 | [diff] [blame] | 2369 | * @table: model specific table |
| 2370 | * |
| 2371 | * returns 0 in case of success or error code |
| 2372 | */ |
Tony Luck | 0ba169ac | 2016-07-14 15:38:43 -0700 | [diff] [blame] | 2373 | static int sbridge_get_all_devices(u8 *num_mc, |
| 2374 | const struct pci_id_table *table) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2375 | { |
| 2376 | int i, rc; |
| 2377 | struct pci_dev *pdev = NULL; |
Tony Luck | 0ba169ac | 2016-07-14 15:38:43 -0700 | [diff] [blame] | 2378 | int allow_dups = 0; |
| 2379 | int multi_bus = 0; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2380 | |
Tony Luck | 0ba169ac | 2016-07-14 15:38:43 -0700 | [diff] [blame] | 2381 | if (table->type == KNIGHTS_LANDING) |
| 2382 | allow_dups = multi_bus = 1; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2383 | while (table && table->descr) { |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 2384 | for (i = 0; i < table->n_devs_per_sock; i++) { |
Jim Snow | c1979ba | 2015-12-03 10:48:53 +0100 | [diff] [blame] | 2385 | if (!allow_dups || i == 0 || |
| 2386 | table->descr[i].dev_id != |
| 2387 | table->descr[i-1].dev_id) { |
| 2388 | pdev = NULL; |
| 2389 | } |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2390 | do { |
| 2391 | rc = sbridge_get_onedevice(&pdev, num_mc, |
Jim Snow | c1979ba | 2015-12-03 10:48:53 +0100 | [diff] [blame] | 2392 | table, i, multi_bus); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2393 | if (rc < 0) { |
| 2394 | if (i == 0) { |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 2395 | i = table->n_devs_per_sock; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2396 | break; |
| 2397 | } |
| 2398 | sbridge_put_all_devices(); |
| 2399 | return -ENODEV; |
| 2400 | } |
Jim Snow | c1979ba | 2015-12-03 10:48:53 +0100 | [diff] [blame] | 2401 | } while (pdev && !allow_dups); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2402 | } |
| 2403 | table++; |
| 2404 | } |
| 2405 | |
| 2406 | return 0; |
| 2407 | } |
| 2408 | |
Aristeu Rozanski | ea779b5 | 2013-10-30 13:27:04 -0300 | [diff] [blame] | 2409 | static int sbridge_mci_bind_devs(struct mem_ctl_info *mci, |
| 2410 | struct sbridge_dev *sbridge_dev) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2411 | { |
| 2412 | struct sbridge_pvt *pvt = mci->pvt_info; |
| 2413 | struct pci_dev *pdev; |
Seth Jennings | 2900ea6 | 2015-08-05 13:16:01 -0500 | [diff] [blame] | 2414 | u8 saw_chan_mask = 0; |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2415 | int i; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2416 | |
| 2417 | for (i = 0; i < sbridge_dev->n_devs; i++) { |
| 2418 | pdev = sbridge_dev->pdev[i]; |
| 2419 | if (!pdev) |
| 2420 | continue; |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2421 | |
| 2422 | switch (pdev->device) { |
| 2423 | case PCI_DEVICE_ID_INTEL_SBRIDGE_SAD0: |
| 2424 | pvt->pci_sad0 = pdev; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2425 | break; |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2426 | case PCI_DEVICE_ID_INTEL_SBRIDGE_SAD1: |
| 2427 | pvt->pci_sad1 = pdev; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2428 | break; |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2429 | case PCI_DEVICE_ID_INTEL_SBRIDGE_BR: |
| 2430 | pvt->pci_br0 = pdev; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2431 | break; |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2432 | case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_HA0: |
| 2433 | pvt->pci_ha0 = pdev; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2434 | break; |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2435 | case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA: |
| 2436 | pvt->pci_ta = pdev; |
| 2437 | break; |
| 2438 | case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_RAS: |
| 2439 | pvt->pci_ras = pdev; |
| 2440 | break; |
| 2441 | case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD0: |
| 2442 | case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD1: |
| 2443 | case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD2: |
| 2444 | case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD3: |
| 2445 | { |
| 2446 | int id = pdev->device - PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD0; |
| 2447 | pvt->pci_tad[id] = pdev; |
Seth Jennings | 2900ea6 | 2015-08-05 13:16:01 -0500 | [diff] [blame] | 2448 | saw_chan_mask |= 1 << id; |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2449 | } |
| 2450 | break; |
| 2451 | case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_DDRIO: |
| 2452 | pvt->pci_ddrio = pdev; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2453 | break; |
| 2454 | default: |
| 2455 | goto error; |
| 2456 | } |
| 2457 | |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2458 | edac_dbg(0, "Associated PCI %02x:%02x, bus %d with dev = %p\n", |
| 2459 | pdev->vendor, pdev->device, |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2460 | sbridge_dev->bus, |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2461 | pdev); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2462 | } |
| 2463 | |
| 2464 | /* Check if everything were registered */ |
| 2465 | if (!pvt->pci_sad0 || !pvt->pci_sad1 || !pvt->pci_ha0 || |
Colin Ian King | c7c3540 | 2016-09-08 09:38:01 +0100 | [diff] [blame] | 2466 | !pvt->pci_ras || !pvt->pci_ta) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2467 | goto enodev; |
| 2468 | |
Seth Jennings | 2900ea6 | 2015-08-05 13:16:01 -0500 | [diff] [blame] | 2469 | if (saw_chan_mask != 0x0f) |
| 2470 | goto enodev; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2471 | return 0; |
| 2472 | |
| 2473 | enodev: |
| 2474 | sbridge_printk(KERN_ERR, "Some needed devices are missing\n"); |
| 2475 | return -ENODEV; |
| 2476 | |
| 2477 | error: |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2478 | sbridge_printk(KERN_ERR, "Unexpected device %02x:%02x\n", |
| 2479 | PCI_VENDOR_ID_INTEL, pdev->device); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2480 | return -EINVAL; |
| 2481 | } |
| 2482 | |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2483 | static int ibridge_mci_bind_devs(struct mem_ctl_info *mci, |
| 2484 | struct sbridge_dev *sbridge_dev) |
| 2485 | { |
| 2486 | struct sbridge_pvt *pvt = mci->pvt_info; |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 2487 | struct pci_dev *pdev; |
| 2488 | u8 saw_chan_mask = 0; |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2489 | int i; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2490 | |
| 2491 | for (i = 0; i < sbridge_dev->n_devs; i++) { |
| 2492 | pdev = sbridge_dev->pdev[i]; |
| 2493 | if (!pdev) |
| 2494 | continue; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2495 | |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2496 | switch (pdev->device) { |
| 2497 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0: |
| 2498 | pvt->pci_ha0 = pdev; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2499 | break; |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2500 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA: |
| 2501 | pvt->pci_ta = pdev; |
| 2502 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_RAS: |
| 2503 | pvt->pci_ras = pdev; |
| 2504 | break; |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2505 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD0: |
| 2506 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD1: |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 2507 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD2: |
| 2508 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD3: |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2509 | { |
| 2510 | int id = pdev->device - PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD0; |
| 2511 | pvt->pci_tad[id] = pdev; |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 2512 | saw_chan_mask |= 1 << id; |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2513 | } |
| 2514 | break; |
| 2515 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_2HA_DDRIO0: |
| 2516 | pvt->pci_ddrio = pdev; |
| 2517 | break; |
| 2518 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_1HA_DDRIO0: |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 2519 | pvt->pci_ddrio = pdev; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2520 | break; |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2521 | case PCI_DEVICE_ID_INTEL_IBRIDGE_SAD: |
| 2522 | pvt->pci_sad0 = pdev; |
| 2523 | break; |
| 2524 | case PCI_DEVICE_ID_INTEL_IBRIDGE_BR0: |
| 2525 | pvt->pci_br0 = pdev; |
| 2526 | break; |
| 2527 | case PCI_DEVICE_ID_INTEL_IBRIDGE_BR1: |
| 2528 | pvt->pci_br1 = pdev; |
| 2529 | break; |
| 2530 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1: |
| 2531 | pvt->pci_ha1 = pdev; |
| 2532 | break; |
| 2533 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD0: |
| 2534 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD1: |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 2535 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD2: |
| 2536 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD3: |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2537 | { |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 2538 | int id = pdev->device - PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD0 + 4; |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2539 | pvt->pci_tad[id] = pdev; |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 2540 | saw_chan_mask |= 1 << id; |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2541 | } |
| 2542 | break; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2543 | default: |
| 2544 | goto error; |
| 2545 | } |
| 2546 | |
| 2547 | edac_dbg(0, "Associated PCI %02x.%02d.%d with dev = %p\n", |
| 2548 | sbridge_dev->bus, |
| 2549 | PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), |
| 2550 | pdev); |
| 2551 | } |
| 2552 | |
| 2553 | /* Check if everything were registered */ |
| 2554 | if (!pvt->pci_sad0 || !pvt->pci_ha0 || !pvt->pci_br0 || |
Colin Ian King | c7c3540 | 2016-09-08 09:38:01 +0100 | [diff] [blame] | 2555 | !pvt->pci_br1 || !pvt->pci_ras || !pvt->pci_ta) |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2556 | goto enodev; |
| 2557 | |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 2558 | if (saw_chan_mask != 0x0f && /* -EN */ |
| 2559 | saw_chan_mask != 0x33 && /* -EP */ |
| 2560 | saw_chan_mask != 0xff) /* -EX */ |
| 2561 | goto enodev; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2562 | return 0; |
| 2563 | |
| 2564 | enodev: |
| 2565 | sbridge_printk(KERN_ERR, "Some needed devices are missing\n"); |
| 2566 | return -ENODEV; |
| 2567 | |
| 2568 | error: |
| 2569 | sbridge_printk(KERN_ERR, |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2570 | "Unexpected device %02x:%02x\n", PCI_VENDOR_ID_INTEL, |
| 2571 | pdev->device); |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2572 | return -EINVAL; |
| 2573 | } |
| 2574 | |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2575 | static int haswell_mci_bind_devs(struct mem_ctl_info *mci, |
| 2576 | struct sbridge_dev *sbridge_dev) |
| 2577 | { |
| 2578 | struct sbridge_pvt *pvt = mci->pvt_info; |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 2579 | struct pci_dev *pdev; |
| 2580 | u8 saw_chan_mask = 0; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2581 | int i; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2582 | |
| 2583 | /* there's only one device per system; not tied to any bus */ |
| 2584 | if (pvt->info.pci_vtd == NULL) |
| 2585 | /* result will be checked later */ |
| 2586 | pvt->info.pci_vtd = pci_get_device(PCI_VENDOR_ID_INTEL, |
| 2587 | PCI_DEVICE_ID_INTEL_HASWELL_IMC_VTD_MISC, |
| 2588 | NULL); |
| 2589 | |
| 2590 | for (i = 0; i < sbridge_dev->n_devs; i++) { |
| 2591 | pdev = sbridge_dev->pdev[i]; |
| 2592 | if (!pdev) |
| 2593 | continue; |
| 2594 | |
| 2595 | switch (pdev->device) { |
| 2596 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_CBO_SAD0: |
| 2597 | pvt->pci_sad0 = pdev; |
| 2598 | break; |
| 2599 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_CBO_SAD1: |
| 2600 | pvt->pci_sad1 = pdev; |
| 2601 | break; |
| 2602 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0: |
| 2603 | pvt->pci_ha0 = pdev; |
| 2604 | break; |
| 2605 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TA: |
| 2606 | pvt->pci_ta = pdev; |
| 2607 | break; |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 2608 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TM: |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2609 | pvt->pci_ras = pdev; |
| 2610 | break; |
| 2611 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD0: |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2612 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD1: |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2613 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD2: |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2614 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD3: |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 2615 | { |
| 2616 | int id = pdev->device - PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD0; |
| 2617 | |
| 2618 | pvt->pci_tad[id] = pdev; |
| 2619 | saw_chan_mask |= 1 << id; |
| 2620 | } |
| 2621 | break; |
| 2622 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD0: |
| 2623 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD1: |
| 2624 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD2: |
| 2625 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD3: |
| 2626 | { |
| 2627 | int id = pdev->device - PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD0 + 4; |
| 2628 | |
| 2629 | pvt->pci_tad[id] = pdev; |
| 2630 | saw_chan_mask |= 1 << id; |
| 2631 | } |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2632 | break; |
| 2633 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO0: |
Aristeu Rozanski | 7179385 | 2015-06-12 09:44:52 -0400 | [diff] [blame] | 2634 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO1: |
| 2635 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO2: |
| 2636 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO3: |
| 2637 | if (!pvt->pci_ddrio) |
| 2638 | pvt->pci_ddrio = pdev; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2639 | break; |
| 2640 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1: |
| 2641 | pvt->pci_ha1 = pdev; |
| 2642 | break; |
| 2643 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TA: |
| 2644 | pvt->pci_ha1_ta = pdev; |
| 2645 | break; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2646 | default: |
| 2647 | break; |
| 2648 | } |
| 2649 | |
| 2650 | edac_dbg(0, "Associated PCI %02x.%02d.%d with dev = %p\n", |
| 2651 | sbridge_dev->bus, |
| 2652 | PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), |
| 2653 | pdev); |
| 2654 | } |
| 2655 | |
| 2656 | /* Check if everything were registered */ |
| 2657 | if (!pvt->pci_sad0 || !pvt->pci_ha0 || !pvt->pci_sad1 || |
| 2658 | !pvt->pci_ras || !pvt->pci_ta || !pvt->info.pci_vtd) |
| 2659 | goto enodev; |
| 2660 | |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 2661 | if (saw_chan_mask != 0x0f && /* -EN */ |
| 2662 | saw_chan_mask != 0x33 && /* -EP */ |
| 2663 | saw_chan_mask != 0xff) /* -EX */ |
| 2664 | goto enodev; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2665 | return 0; |
| 2666 | |
| 2667 | enodev: |
| 2668 | sbridge_printk(KERN_ERR, "Some needed devices are missing\n"); |
| 2669 | return -ENODEV; |
| 2670 | } |
| 2671 | |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 2672 | static int broadwell_mci_bind_devs(struct mem_ctl_info *mci, |
| 2673 | struct sbridge_dev *sbridge_dev) |
| 2674 | { |
| 2675 | struct sbridge_pvt *pvt = mci->pvt_info; |
| 2676 | struct pci_dev *pdev; |
Tony Luck | fa2ce64 | 2015-05-20 19:10:35 -0300 | [diff] [blame] | 2677 | u8 saw_chan_mask = 0; |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 2678 | int i; |
| 2679 | |
| 2680 | /* there's only one device per system; not tied to any bus */ |
| 2681 | if (pvt->info.pci_vtd == NULL) |
| 2682 | /* result will be checked later */ |
| 2683 | pvt->info.pci_vtd = pci_get_device(PCI_VENDOR_ID_INTEL, |
| 2684 | PCI_DEVICE_ID_INTEL_BROADWELL_IMC_VTD_MISC, |
| 2685 | NULL); |
| 2686 | |
| 2687 | for (i = 0; i < sbridge_dev->n_devs; i++) { |
| 2688 | pdev = sbridge_dev->pdev[i]; |
| 2689 | if (!pdev) |
| 2690 | continue; |
| 2691 | |
| 2692 | switch (pdev->device) { |
| 2693 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_CBO_SAD0: |
| 2694 | pvt->pci_sad0 = pdev; |
| 2695 | break; |
| 2696 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_CBO_SAD1: |
| 2697 | pvt->pci_sad1 = pdev; |
| 2698 | break; |
| 2699 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0: |
| 2700 | pvt->pci_ha0 = pdev; |
| 2701 | break; |
| 2702 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TA: |
| 2703 | pvt->pci_ta = pdev; |
| 2704 | break; |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 2705 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TM: |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 2706 | pvt->pci_ras = pdev; |
| 2707 | break; |
| 2708 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD0: |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 2709 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD1: |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 2710 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD2: |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 2711 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD3: |
Tony Luck | fa2ce64 | 2015-05-20 19:10:35 -0300 | [diff] [blame] | 2712 | { |
| 2713 | int id = pdev->device - PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD0; |
| 2714 | pvt->pci_tad[id] = pdev; |
| 2715 | saw_chan_mask |= 1 << id; |
| 2716 | } |
| 2717 | break; |
| 2718 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD0: |
| 2719 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD1: |
| 2720 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD2: |
| 2721 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD3: |
| 2722 | { |
| 2723 | int id = pdev->device - PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD0 + 4; |
| 2724 | pvt->pci_tad[id] = pdev; |
| 2725 | saw_chan_mask |= 1 << id; |
| 2726 | } |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 2727 | break; |
| 2728 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_DDRIO0: |
| 2729 | pvt->pci_ddrio = pdev; |
| 2730 | break; |
Tony Luck | fa2ce64 | 2015-05-20 19:10:35 -0300 | [diff] [blame] | 2731 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1: |
| 2732 | pvt->pci_ha1 = pdev; |
| 2733 | break; |
| 2734 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TA: |
| 2735 | pvt->pci_ha1_ta = pdev; |
| 2736 | break; |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 2737 | default: |
| 2738 | break; |
| 2739 | } |
| 2740 | |
| 2741 | edac_dbg(0, "Associated PCI %02x.%02d.%d with dev = %p\n", |
| 2742 | sbridge_dev->bus, |
| 2743 | PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), |
| 2744 | pdev); |
| 2745 | } |
| 2746 | |
| 2747 | /* Check if everything were registered */ |
| 2748 | if (!pvt->pci_sad0 || !pvt->pci_ha0 || !pvt->pci_sad1 || |
| 2749 | !pvt->pci_ras || !pvt->pci_ta || !pvt->info.pci_vtd) |
| 2750 | goto enodev; |
| 2751 | |
Tony Luck | fa2ce64 | 2015-05-20 19:10:35 -0300 | [diff] [blame] | 2752 | if (saw_chan_mask != 0x0f && /* -EN */ |
| 2753 | saw_chan_mask != 0x33 && /* -EP */ |
| 2754 | saw_chan_mask != 0xff) /* -EX */ |
| 2755 | goto enodev; |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 2756 | return 0; |
| 2757 | |
| 2758 | enodev: |
| 2759 | sbridge_printk(KERN_ERR, "Some needed devices are missing\n"); |
| 2760 | return -ENODEV; |
| 2761 | } |
| 2762 | |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 2763 | static int knl_mci_bind_devs(struct mem_ctl_info *mci, |
| 2764 | struct sbridge_dev *sbridge_dev) |
| 2765 | { |
| 2766 | struct sbridge_pvt *pvt = mci->pvt_info; |
| 2767 | struct pci_dev *pdev; |
| 2768 | int dev, func; |
| 2769 | |
| 2770 | int i; |
| 2771 | int devidx; |
| 2772 | |
| 2773 | for (i = 0; i < sbridge_dev->n_devs; i++) { |
| 2774 | pdev = sbridge_dev->pdev[i]; |
| 2775 | if (!pdev) |
| 2776 | continue; |
| 2777 | |
| 2778 | /* Extract PCI device and function. */ |
| 2779 | dev = (pdev->devfn >> 3) & 0x1f; |
| 2780 | func = pdev->devfn & 0x7; |
| 2781 | |
| 2782 | switch (pdev->device) { |
| 2783 | case PCI_DEVICE_ID_INTEL_KNL_IMC_MC: |
| 2784 | if (dev == 8) |
| 2785 | pvt->knl.pci_mc0 = pdev; |
| 2786 | else if (dev == 9) |
| 2787 | pvt->knl.pci_mc1 = pdev; |
| 2788 | else { |
| 2789 | sbridge_printk(KERN_ERR, |
| 2790 | "Memory controller in unexpected place! (dev %d, fn %d)\n", |
| 2791 | dev, func); |
| 2792 | continue; |
| 2793 | } |
| 2794 | break; |
| 2795 | |
| 2796 | case PCI_DEVICE_ID_INTEL_KNL_IMC_SAD0: |
| 2797 | pvt->pci_sad0 = pdev; |
| 2798 | break; |
| 2799 | |
| 2800 | case PCI_DEVICE_ID_INTEL_KNL_IMC_SAD1: |
| 2801 | pvt->pci_sad1 = pdev; |
| 2802 | break; |
| 2803 | |
| 2804 | case PCI_DEVICE_ID_INTEL_KNL_IMC_CHA: |
| 2805 | /* There are one of these per tile, and range from |
| 2806 | * 1.14.0 to 1.18.5. |
| 2807 | */ |
| 2808 | devidx = ((dev-14)*8)+func; |
| 2809 | |
| 2810 | if (devidx < 0 || devidx >= KNL_MAX_CHAS) { |
| 2811 | sbridge_printk(KERN_ERR, |
| 2812 | "Caching and Home Agent in unexpected place! (dev %d, fn %d)\n", |
| 2813 | dev, func); |
| 2814 | continue; |
| 2815 | } |
| 2816 | |
| 2817 | WARN_ON(pvt->knl.pci_cha[devidx] != NULL); |
| 2818 | |
| 2819 | pvt->knl.pci_cha[devidx] = pdev; |
| 2820 | break; |
| 2821 | |
Qiuxu Zhuo | 00cf50d | 2017-05-23 08:05:33 +0800 | [diff] [blame^] | 2822 | case PCI_DEVICE_ID_INTEL_KNL_IMC_CHAN: |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 2823 | devidx = -1; |
| 2824 | |
| 2825 | /* |
| 2826 | * MC0 channels 0-2 are device 9 function 2-4, |
| 2827 | * MC1 channels 3-5 are device 8 function 2-4. |
| 2828 | */ |
| 2829 | |
| 2830 | if (dev == 9) |
| 2831 | devidx = func-2; |
| 2832 | else if (dev == 8) |
| 2833 | devidx = 3 + (func-2); |
| 2834 | |
| 2835 | if (devidx < 0 || devidx >= KNL_MAX_CHANNELS) { |
| 2836 | sbridge_printk(KERN_ERR, |
| 2837 | "DRAM Channel Registers in unexpected place! (dev %d, fn %d)\n", |
| 2838 | dev, func); |
| 2839 | continue; |
| 2840 | } |
| 2841 | |
| 2842 | WARN_ON(pvt->knl.pci_channel[devidx] != NULL); |
| 2843 | pvt->knl.pci_channel[devidx] = pdev; |
| 2844 | break; |
| 2845 | |
| 2846 | case PCI_DEVICE_ID_INTEL_KNL_IMC_TOLHM: |
| 2847 | pvt->knl.pci_mc_info = pdev; |
| 2848 | break; |
| 2849 | |
| 2850 | case PCI_DEVICE_ID_INTEL_KNL_IMC_TA: |
| 2851 | pvt->pci_ta = pdev; |
| 2852 | break; |
| 2853 | |
| 2854 | default: |
| 2855 | sbridge_printk(KERN_ERR, "Unexpected device %d\n", |
| 2856 | pdev->device); |
| 2857 | break; |
| 2858 | } |
| 2859 | } |
| 2860 | |
| 2861 | if (!pvt->knl.pci_mc0 || !pvt->knl.pci_mc1 || |
| 2862 | !pvt->pci_sad0 || !pvt->pci_sad1 || |
| 2863 | !pvt->pci_ta) { |
| 2864 | goto enodev; |
| 2865 | } |
| 2866 | |
| 2867 | for (i = 0; i < KNL_MAX_CHANNELS; i++) { |
| 2868 | if (!pvt->knl.pci_channel[i]) { |
| 2869 | sbridge_printk(KERN_ERR, "Missing channel %d\n", i); |
| 2870 | goto enodev; |
| 2871 | } |
| 2872 | } |
| 2873 | |
| 2874 | for (i = 0; i < KNL_MAX_CHAS; i++) { |
| 2875 | if (!pvt->knl.pci_cha[i]) { |
| 2876 | sbridge_printk(KERN_ERR, "Missing CHA %d\n", i); |
| 2877 | goto enodev; |
| 2878 | } |
| 2879 | } |
| 2880 | |
| 2881 | return 0; |
| 2882 | |
| 2883 | enodev: |
| 2884 | sbridge_printk(KERN_ERR, "Some needed devices are missing\n"); |
| 2885 | return -ENODEV; |
| 2886 | } |
| 2887 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2888 | /**************************************************************************** |
| 2889 | Error check routines |
| 2890 | ****************************************************************************/ |
| 2891 | |
| 2892 | /* |
| 2893 | * While Sandy Bridge has error count registers, SMI BIOS read values from |
| 2894 | * and resets the counters. So, they are not reliable for the OS to read |
| 2895 | * from them. So, we have no option but to just trust on whatever MCE is |
| 2896 | * telling us about the errors. |
| 2897 | */ |
| 2898 | static void sbridge_mce_output_error(struct mem_ctl_info *mci, |
| 2899 | const struct mce *m) |
| 2900 | { |
| 2901 | struct mem_ctl_info *new_mci; |
| 2902 | struct sbridge_pvt *pvt = mci->pvt_info; |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 2903 | enum hw_event_mc_err_type tp_event; |
Mauro Carvalho Chehab | e17a2f42a | 2012-05-11 11:41:45 -0300 | [diff] [blame] | 2904 | char *type, *optype, msg[256]; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2905 | bool ripv = GET_BITFIELD(m->mcgstatus, 0, 0); |
| 2906 | bool overflow = GET_BITFIELD(m->status, 62, 62); |
| 2907 | bool uncorrected_error = GET_BITFIELD(m->status, 61, 61); |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2908 | bool recoverable; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2909 | u32 core_err_cnt = GET_BITFIELD(m->status, 38, 52); |
| 2910 | u32 mscod = GET_BITFIELD(m->status, 16, 31); |
| 2911 | u32 errcode = GET_BITFIELD(m->status, 0, 15); |
| 2912 | u32 channel = GET_BITFIELD(m->status, 0, 3); |
| 2913 | u32 optypenum = GET_BITFIELD(m->status, 4, 6); |
| 2914 | long channel_mask, first_channel; |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 2915 | u8 rank, socket, ha; |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 2916 | int rc, dimm; |
Mauro Carvalho Chehab | e17a2f42a | 2012-05-11 11:41:45 -0300 | [diff] [blame] | 2917 | char *area_type = NULL; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2918 | |
Tony Luck | fa2ce64 | 2015-05-20 19:10:35 -0300 | [diff] [blame] | 2919 | if (pvt->info.type != SANDY_BRIDGE) |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2920 | recoverable = true; |
| 2921 | else |
| 2922 | recoverable = GET_BITFIELD(m->status, 56, 56); |
| 2923 | |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 2924 | if (uncorrected_error) { |
| 2925 | if (ripv) { |
| 2926 | type = "FATAL"; |
| 2927 | tp_event = HW_EVENT_ERR_FATAL; |
| 2928 | } else { |
| 2929 | type = "NON_FATAL"; |
| 2930 | tp_event = HW_EVENT_ERR_UNCORRECTED; |
| 2931 | } |
| 2932 | } else { |
| 2933 | type = "CORRECTED"; |
| 2934 | tp_event = HW_EVENT_ERR_CORRECTED; |
| 2935 | } |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2936 | |
| 2937 | /* |
David Mackey | 15ed103 | 2012-04-17 11:30:52 -0700 | [diff] [blame] | 2938 | * According with Table 15-9 of the Intel Architecture spec vol 3A, |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2939 | * memory errors should fit in this mask: |
| 2940 | * 000f 0000 1mmm cccc (binary) |
| 2941 | * where: |
| 2942 | * f = Correction Report Filtering Bit. If 1, subsequent errors |
| 2943 | * won't be shown |
| 2944 | * mmm = error type |
| 2945 | * cccc = channel |
| 2946 | * If the mask doesn't match, report an error to the parsing logic |
| 2947 | */ |
| 2948 | if (! ((errcode & 0xef80) == 0x80)) { |
| 2949 | optype = "Can't parse: it is not a mem"; |
| 2950 | } else { |
| 2951 | switch (optypenum) { |
| 2952 | case 0: |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 2953 | optype = "generic undef request error"; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2954 | break; |
| 2955 | case 1: |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 2956 | optype = "memory read error"; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2957 | break; |
| 2958 | case 2: |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 2959 | optype = "memory write error"; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2960 | break; |
| 2961 | case 3: |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 2962 | optype = "addr/cmd error"; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2963 | break; |
| 2964 | case 4: |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 2965 | optype = "memory scrubbing error"; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2966 | break; |
| 2967 | default: |
| 2968 | optype = "reserved"; |
| 2969 | break; |
| 2970 | } |
| 2971 | } |
| 2972 | |
Aristeu Rozanski | be3036d | 2013-10-30 13:27:05 -0300 | [diff] [blame] | 2973 | /* Only decode errors with an valid address (ADDRV) */ |
| 2974 | if (!GET_BITFIELD(m->status, 58, 58)) |
| 2975 | return; |
| 2976 | |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 2977 | if (pvt->info.type == KNIGHTS_LANDING) { |
| 2978 | if (channel == 14) { |
| 2979 | edac_dbg(0, "%s%s err_code:%04x:%04x EDRAM bank %d\n", |
| 2980 | overflow ? " OVERFLOW" : "", |
| 2981 | (uncorrected_error && recoverable) |
| 2982 | ? " recoverable" : "", |
| 2983 | mscod, errcode, |
| 2984 | m->bank); |
| 2985 | } else { |
| 2986 | char A = *("A"); |
| 2987 | |
Lukasz Odzioba | c5b48fa | 2016-07-23 01:44:49 +0200 | [diff] [blame] | 2988 | /* |
| 2989 | * Reported channel is in range 0-2, so we can't map it |
| 2990 | * back to mc. To figure out mc we check machine check |
| 2991 | * bank register that reported this error. |
| 2992 | * bank15 means mc0 and bank16 means mc1. |
| 2993 | */ |
| 2994 | channel = knl_channel_remap(m->bank == 16, channel); |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 2995 | channel_mask = 1 << channel; |
Lukasz Odzioba | c5b48fa | 2016-07-23 01:44:49 +0200 | [diff] [blame] | 2996 | |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 2997 | snprintf(msg, sizeof(msg), |
| 2998 | "%s%s err_code:%04x:%04x channel:%d (DIMM_%c)", |
| 2999 | overflow ? " OVERFLOW" : "", |
| 3000 | (uncorrected_error && recoverable) |
| 3001 | ? " recoverable" : " ", |
| 3002 | mscod, errcode, channel, A + channel); |
| 3003 | edac_mc_handle_error(tp_event, mci, core_err_cnt, |
| 3004 | m->addr >> PAGE_SHIFT, m->addr & ~PAGE_MASK, 0, |
| 3005 | channel, 0, -1, |
| 3006 | optype, msg); |
| 3007 | } |
| 3008 | return; |
| 3009 | } else { |
| 3010 | rc = get_memory_error_data(mci, m->addr, &socket, &ha, |
| 3011 | &channel_mask, &rank, &area_type, msg); |
| 3012 | } |
| 3013 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3014 | if (rc < 0) |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 3015 | goto err_parsing; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3016 | new_mci = get_mci_for_node_id(socket); |
| 3017 | if (!new_mci) { |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 3018 | strcpy(msg, "Error: socket got corrupted!"); |
| 3019 | goto err_parsing; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3020 | } |
| 3021 | mci = new_mci; |
| 3022 | pvt = mci->pvt_info; |
| 3023 | |
| 3024 | first_channel = find_first_bit(&channel_mask, NUM_CHANNELS); |
| 3025 | |
| 3026 | if (rank < 4) |
| 3027 | dimm = 0; |
| 3028 | else if (rank < 8) |
| 3029 | dimm = 1; |
| 3030 | else |
| 3031 | dimm = 2; |
| 3032 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3033 | |
| 3034 | /* |
Mauro Carvalho Chehab | e17a2f42a | 2012-05-11 11:41:45 -0300 | [diff] [blame] | 3035 | * FIXME: On some memory configurations (mirror, lockstep), the |
| 3036 | * Memory Controller can't point the error to a single DIMM. The |
| 3037 | * EDAC core should be handling the channel mask, in order to point |
| 3038 | * to the group of dimm's where the error may be happening. |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3039 | */ |
Aristeu Rozanski | d7c660b | 2014-06-02 15:15:28 -0300 | [diff] [blame] | 3040 | if (!pvt->is_lockstep && !pvt->is_mirrored && !pvt->is_close_pg) |
| 3041 | channel = first_channel; |
| 3042 | |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 3043 | snprintf(msg, sizeof(msg), |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 3044 | "%s%s area:%s err_code:%04x:%04x socket:%d ha:%d channel_mask:%ld rank:%d", |
Mauro Carvalho Chehab | e17a2f42a | 2012-05-11 11:41:45 -0300 | [diff] [blame] | 3045 | overflow ? " OVERFLOW" : "", |
| 3046 | (uncorrected_error && recoverable) ? " recoverable" : "", |
| 3047 | area_type, |
| 3048 | mscod, errcode, |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 3049 | socket, ha, |
Mauro Carvalho Chehab | e17a2f42a | 2012-05-11 11:41:45 -0300 | [diff] [blame] | 3050 | channel_mask, |
| 3051 | rank); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3052 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 3053 | edac_dbg(0, "%s\n", msg); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3054 | |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 3055 | /* FIXME: need support for channel mask */ |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3056 | |
Seth Jennings | 351fc4a | 2014-09-05 14:28:47 -0500 | [diff] [blame] | 3057 | if (channel == CHANNEL_UNSPECIFIED) |
| 3058 | channel = -1; |
| 3059 | |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 3060 | /* Call the helper to output message */ |
Mauro Carvalho Chehab | c105383 | 2012-06-04 13:40:05 -0300 | [diff] [blame] | 3061 | edac_mc_handle_error(tp_event, mci, core_err_cnt, |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 3062 | m->addr >> PAGE_SHIFT, m->addr & ~PAGE_MASK, 0, |
Tony Luck | 7d375bf | 2015-05-18 17:50:42 -0300 | [diff] [blame] | 3063 | 4*ha+channel, dimm, -1, |
Mauro Carvalho Chehab | 03f7eae | 2012-06-04 11:29:25 -0300 | [diff] [blame] | 3064 | optype, msg); |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 3065 | return; |
| 3066 | err_parsing: |
Mauro Carvalho Chehab | c105383 | 2012-06-04 13:40:05 -0300 | [diff] [blame] | 3067 | edac_mc_handle_error(tp_event, mci, core_err_cnt, 0, 0, 0, |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 3068 | -1, -1, -1, |
Mauro Carvalho Chehab | 03f7eae | 2012-06-04 11:29:25 -0300 | [diff] [blame] | 3069 | msg, ""); |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 3070 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3071 | } |
| 3072 | |
| 3073 | /* |
Tony Luck | ad08c4e | 2016-04-15 14:50:32 -0700 | [diff] [blame] | 3074 | * Check that logging is enabled and that this is the right type |
| 3075 | * of error for us to handle. |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3076 | */ |
Mauro Carvalho Chehab | 3d78c9a | 2011-10-20 19:33:46 -0200 | [diff] [blame] | 3077 | static int sbridge_mce_check_error(struct notifier_block *nb, unsigned long val, |
| 3078 | void *data) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3079 | { |
Mauro Carvalho Chehab | 3d78c9a | 2011-10-20 19:33:46 -0200 | [diff] [blame] | 3080 | struct mce *mce = (struct mce *)data; |
| 3081 | struct mem_ctl_info *mci; |
| 3082 | struct sbridge_pvt *pvt; |
Aristeu Rozanski | cf40f80 | 2014-03-11 15:45:41 -0400 | [diff] [blame] | 3083 | char *type; |
Mauro Carvalho Chehab | 3d78c9a | 2011-10-20 19:33:46 -0200 | [diff] [blame] | 3084 | |
Borislav Petkov | bffc7de | 2017-02-04 18:10:14 +0100 | [diff] [blame] | 3085 | if (edac_get_report_status() == EDAC_REPORTING_DISABLED) |
Chen, Gong | fd52103 | 2013-12-06 01:17:09 -0500 | [diff] [blame] | 3086 | return NOTIFY_DONE; |
| 3087 | |
Mauro Carvalho Chehab | 3d78c9a | 2011-10-20 19:33:46 -0200 | [diff] [blame] | 3088 | mci = get_mci_for_node_id(mce->socketid); |
| 3089 | if (!mci) |
Tony Luck | c4fc195 | 2016-04-29 15:42:25 +0200 | [diff] [blame] | 3090 | return NOTIFY_DONE; |
Mauro Carvalho Chehab | 3d78c9a | 2011-10-20 19:33:46 -0200 | [diff] [blame] | 3091 | pvt = mci->pvt_info; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3092 | |
| 3093 | /* |
| 3094 | * Just let mcelog handle it if the error is |
| 3095 | * outside the memory controller. A memory error |
| 3096 | * is indicated by bit 7 = 1 and bits = 8-11,13-15 = 0. |
| 3097 | * bit 12 has an special meaning. |
| 3098 | */ |
| 3099 | if ((mce->status & 0xefff) >> 7 != 1) |
Mauro Carvalho Chehab | 3d78c9a | 2011-10-20 19:33:46 -0200 | [diff] [blame] | 3100 | return NOTIFY_DONE; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3101 | |
Aristeu Rozanski | cf40f80 | 2014-03-11 15:45:41 -0400 | [diff] [blame] | 3102 | if (mce->mcgstatus & MCG_STATUS_MCIP) |
| 3103 | type = "Exception"; |
| 3104 | else |
| 3105 | type = "Event"; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3106 | |
Aristeu Rozanski | 49856dc | 2014-03-11 15:45:42 -0400 | [diff] [blame] | 3107 | sbridge_mc_printk(mci, KERN_DEBUG, "HANDLING MCE MEMORY ERROR\n"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3108 | |
Aristeu Rozanski | 49856dc | 2014-03-11 15:45:42 -0400 | [diff] [blame] | 3109 | sbridge_mc_printk(mci, KERN_DEBUG, "CPU %d: Machine Check %s: %Lx " |
| 3110 | "Bank %d: %016Lx\n", mce->extcpu, type, |
| 3111 | mce->mcgstatus, mce->bank, mce->status); |
| 3112 | sbridge_mc_printk(mci, KERN_DEBUG, "TSC %llx ", mce->tsc); |
| 3113 | sbridge_mc_printk(mci, KERN_DEBUG, "ADDR %llx ", mce->addr); |
| 3114 | sbridge_mc_printk(mci, KERN_DEBUG, "MISC %llx ", mce->misc); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3115 | |
Aristeu Rozanski | 49856dc | 2014-03-11 15:45:42 -0400 | [diff] [blame] | 3116 | sbridge_mc_printk(mci, KERN_DEBUG, "PROCESSOR %u:%x TIME %llu SOCKET " |
| 3117 | "%u APIC %x\n", mce->cpuvendor, mce->cpuid, |
| 3118 | mce->time, mce->socketid, mce->apicid); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3119 | |
Tony Luck | ad08c4e | 2016-04-15 14:50:32 -0700 | [diff] [blame] | 3120 | sbridge_mce_output_error(mci, mce); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3121 | |
| 3122 | /* Advice mcelog that the error were handled */ |
Mauro Carvalho Chehab | 3d78c9a | 2011-10-20 19:33:46 -0200 | [diff] [blame] | 3123 | return NOTIFY_STOP; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3124 | } |
| 3125 | |
Mauro Carvalho Chehab | 3d78c9a | 2011-10-20 19:33:46 -0200 | [diff] [blame] | 3126 | static struct notifier_block sbridge_mce_dec = { |
Borislav Petkov | 9026cc8 | 2017-01-23 19:35:14 +0100 | [diff] [blame] | 3127 | .notifier_call = sbridge_mce_check_error, |
| 3128 | .priority = MCE_PRIO_EDAC, |
Mauro Carvalho Chehab | 3d78c9a | 2011-10-20 19:33:46 -0200 | [diff] [blame] | 3129 | }; |
| 3130 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3131 | /**************************************************************************** |
| 3132 | EDAC register/unregister logic |
| 3133 | ****************************************************************************/ |
| 3134 | |
| 3135 | static void sbridge_unregister_mci(struct sbridge_dev *sbridge_dev) |
| 3136 | { |
| 3137 | struct mem_ctl_info *mci = sbridge_dev->mci; |
| 3138 | struct sbridge_pvt *pvt; |
| 3139 | |
| 3140 | if (unlikely(!mci || !mci->pvt_info)) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 3141 | edac_dbg(0, "MC: dev = %p\n", &sbridge_dev->pdev[0]->dev); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3142 | |
| 3143 | sbridge_printk(KERN_ERR, "Couldn't find mci handler\n"); |
| 3144 | return; |
| 3145 | } |
| 3146 | |
| 3147 | pvt = mci->pvt_info; |
| 3148 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 3149 | edac_dbg(0, "MC: mci = %p, dev = %p\n", |
| 3150 | mci, &sbridge_dev->pdev[0]->dev); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3151 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3152 | /* Remove MC sysfs nodes */ |
Mauro Carvalho Chehab | fd68750 | 2012-03-16 07:44:18 -0300 | [diff] [blame] | 3153 | edac_mc_del_mc(mci->pdev); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3154 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 3155 | edac_dbg(1, "%s: free mci struct\n", mci->ctl_name); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3156 | kfree(mci->ctl_name); |
| 3157 | edac_mc_free(mci); |
| 3158 | sbridge_dev->mci = NULL; |
| 3159 | } |
| 3160 | |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 3161 | static int sbridge_register_mci(struct sbridge_dev *sbridge_dev, enum type type) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3162 | { |
| 3163 | struct mem_ctl_info *mci; |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 3164 | struct edac_mc_layer layers[2]; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3165 | struct sbridge_pvt *pvt; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 3166 | struct pci_dev *pdev = sbridge_dev->pdev[0]; |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 3167 | int rc; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3168 | |
| 3169 | /* Check the number of active and not disabled channels */ |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 3170 | rc = check_if_ecc_is_active(sbridge_dev->bus, type); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3171 | if (unlikely(rc < 0)) |
| 3172 | return rc; |
| 3173 | |
| 3174 | /* allocate a new MC control structure */ |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 3175 | layers[0].type = EDAC_MC_LAYER_CHANNEL; |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 3176 | layers[0].size = type == KNIGHTS_LANDING ? |
| 3177 | KNL_MAX_CHANNELS : NUM_CHANNELS; |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 3178 | layers[0].is_virt_csrow = false; |
| 3179 | layers[1].type = EDAC_MC_LAYER_SLOT; |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 3180 | layers[1].size = type == KNIGHTS_LANDING ? 1 : MAX_DIMMS; |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 3181 | layers[1].is_virt_csrow = true; |
Mauro Carvalho Chehab | ca0907b | 2012-05-02 14:37:00 -0300 | [diff] [blame] | 3182 | mci = edac_mc_alloc(sbridge_dev->mc, ARRAY_SIZE(layers), layers, |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 3183 | sizeof(*pvt)); |
| 3184 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3185 | if (unlikely(!mci)) |
| 3186 | return -ENOMEM; |
| 3187 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 3188 | edac_dbg(0, "MC: mci = %p, dev = %p\n", |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 3189 | mci, &pdev->dev); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3190 | |
| 3191 | pvt = mci->pvt_info; |
| 3192 | memset(pvt, 0, sizeof(*pvt)); |
| 3193 | |
| 3194 | /* Associate sbridge_dev and mci for future usage */ |
| 3195 | pvt->sbridge_dev = sbridge_dev; |
| 3196 | sbridge_dev->mci = mci; |
| 3197 | |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 3198 | mci->mtype_cap = type == KNIGHTS_LANDING ? |
| 3199 | MEM_FLAG_DDR4 : MEM_FLAG_DDR3; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3200 | mci->edac_ctl_cap = EDAC_FLAG_NONE; |
| 3201 | mci->edac_cap = EDAC_FLAG_NONE; |
| 3202 | mci->mod_name = "sbridge_edac.c"; |
| 3203 | mci->mod_ver = SBRIDGE_REVISION; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 3204 | mci->dev_name = pci_name(pdev); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3205 | mci->ctl_page_to_phys = NULL; |
| 3206 | |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 3207 | pvt->info.type = type; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 3208 | switch (type) { |
| 3209 | case IVY_BRIDGE: |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 3210 | pvt->info.rankcfgr = IB_RANK_CFG_A; |
| 3211 | pvt->info.get_tolm = ibridge_get_tolm; |
| 3212 | pvt->info.get_tohm = ibridge_get_tohm; |
| 3213 | pvt->info.dram_rule = ibridge_dram_rule; |
Aristeu Rozanski | 9e37544 | 2014-06-02 15:15:22 -0300 | [diff] [blame] | 3214 | pvt->info.get_memory_type = get_memory_type; |
Aristeu Rozanski | f14d689 | 2014-06-02 15:15:23 -0300 | [diff] [blame] | 3215 | pvt->info.get_node_id = get_node_id; |
Aristeu Rozanski | b976bcf | 2014-06-02 15:15:24 -0300 | [diff] [blame] | 3216 | pvt->info.rir_limit = rir_limit; |
Jim Snow | c59f9c0 | 2015-12-03 10:48:52 +0100 | [diff] [blame] | 3217 | pvt->info.sad_limit = sad_limit; |
| 3218 | pvt->info.interleave_mode = interleave_mode; |
Jim Snow | c59f9c0 | 2015-12-03 10:48:52 +0100 | [diff] [blame] | 3219 | pvt->info.dram_attr = dram_attr; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 3220 | pvt->info.max_sad = ARRAY_SIZE(ibridge_dram_rule); |
| 3221 | pvt->info.interleave_list = ibridge_interleave_list; |
| 3222 | pvt->info.max_interleave = ARRAY_SIZE(ibridge_interleave_list); |
| 3223 | pvt->info.interleave_pkg = ibridge_interleave_pkg; |
Aristeu Rozanski | 12f0721 | 2015-06-12 15:08:17 -0400 | [diff] [blame] | 3224 | pvt->info.get_width = ibridge_get_width; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 3225 | mci->ctl_name = kasprintf(GFP_KERNEL, "Ivy Bridge Socket#%d", mci->mc_idx); |
| 3226 | |
| 3227 | /* Store pci devices at mci for faster access */ |
| 3228 | rc = ibridge_mci_bind_devs(mci, sbridge_dev); |
| 3229 | if (unlikely(rc < 0)) |
| 3230 | goto fail0; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 3231 | break; |
| 3232 | case SANDY_BRIDGE: |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 3233 | pvt->info.rankcfgr = SB_RANK_CFG_A; |
| 3234 | pvt->info.get_tolm = sbridge_get_tolm; |
| 3235 | pvt->info.get_tohm = sbridge_get_tohm; |
| 3236 | pvt->info.dram_rule = sbridge_dram_rule; |
Aristeu Rozanski | 9e37544 | 2014-06-02 15:15:22 -0300 | [diff] [blame] | 3237 | pvt->info.get_memory_type = get_memory_type; |
Aristeu Rozanski | f14d689 | 2014-06-02 15:15:23 -0300 | [diff] [blame] | 3238 | pvt->info.get_node_id = get_node_id; |
Aristeu Rozanski | b976bcf | 2014-06-02 15:15:24 -0300 | [diff] [blame] | 3239 | pvt->info.rir_limit = rir_limit; |
Jim Snow | c59f9c0 | 2015-12-03 10:48:52 +0100 | [diff] [blame] | 3240 | pvt->info.sad_limit = sad_limit; |
| 3241 | pvt->info.interleave_mode = interleave_mode; |
Jim Snow | c59f9c0 | 2015-12-03 10:48:52 +0100 | [diff] [blame] | 3242 | pvt->info.dram_attr = dram_attr; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 3243 | pvt->info.max_sad = ARRAY_SIZE(sbridge_dram_rule); |
| 3244 | pvt->info.interleave_list = sbridge_interleave_list; |
| 3245 | pvt->info.max_interleave = ARRAY_SIZE(sbridge_interleave_list); |
| 3246 | pvt->info.interleave_pkg = sbridge_interleave_pkg; |
Aristeu Rozanski | 12f0721 | 2015-06-12 15:08:17 -0400 | [diff] [blame] | 3247 | pvt->info.get_width = sbridge_get_width; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 3248 | mci->ctl_name = kasprintf(GFP_KERNEL, "Sandy Bridge Socket#%d", mci->mc_idx); |
| 3249 | |
| 3250 | /* Store pci devices at mci for faster access */ |
| 3251 | rc = sbridge_mci_bind_devs(mci, sbridge_dev); |
| 3252 | if (unlikely(rc < 0)) |
| 3253 | goto fail0; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 3254 | break; |
| 3255 | case HASWELL: |
| 3256 | /* rankcfgr isn't used */ |
| 3257 | pvt->info.get_tolm = haswell_get_tolm; |
| 3258 | pvt->info.get_tohm = haswell_get_tohm; |
| 3259 | pvt->info.dram_rule = ibridge_dram_rule; |
| 3260 | pvt->info.get_memory_type = haswell_get_memory_type; |
| 3261 | pvt->info.get_node_id = haswell_get_node_id; |
| 3262 | pvt->info.rir_limit = haswell_rir_limit; |
Jim Snow | c59f9c0 | 2015-12-03 10:48:52 +0100 | [diff] [blame] | 3263 | pvt->info.sad_limit = sad_limit; |
| 3264 | pvt->info.interleave_mode = interleave_mode; |
Jim Snow | c59f9c0 | 2015-12-03 10:48:52 +0100 | [diff] [blame] | 3265 | pvt->info.dram_attr = dram_attr; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 3266 | pvt->info.max_sad = ARRAY_SIZE(ibridge_dram_rule); |
| 3267 | pvt->info.interleave_list = ibridge_interleave_list; |
| 3268 | pvt->info.max_interleave = ARRAY_SIZE(ibridge_interleave_list); |
| 3269 | pvt->info.interleave_pkg = ibridge_interleave_pkg; |
Aristeu Rozanski | 12f0721 | 2015-06-12 15:08:17 -0400 | [diff] [blame] | 3270 | pvt->info.get_width = ibridge_get_width; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 3271 | mci->ctl_name = kasprintf(GFP_KERNEL, "Haswell Socket#%d", mci->mc_idx); |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 3272 | |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 3273 | /* Store pci devices at mci for faster access */ |
| 3274 | rc = haswell_mci_bind_devs(mci, sbridge_dev); |
| 3275 | if (unlikely(rc < 0)) |
| 3276 | goto fail0; |
| 3277 | break; |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 3278 | case BROADWELL: |
| 3279 | /* rankcfgr isn't used */ |
| 3280 | pvt->info.get_tolm = haswell_get_tolm; |
| 3281 | pvt->info.get_tohm = haswell_get_tohm; |
| 3282 | pvt->info.dram_rule = ibridge_dram_rule; |
| 3283 | pvt->info.get_memory_type = haswell_get_memory_type; |
| 3284 | pvt->info.get_node_id = haswell_get_node_id; |
| 3285 | pvt->info.rir_limit = haswell_rir_limit; |
Jim Snow | c59f9c0 | 2015-12-03 10:48:52 +0100 | [diff] [blame] | 3286 | pvt->info.sad_limit = sad_limit; |
| 3287 | pvt->info.interleave_mode = interleave_mode; |
Jim Snow | c59f9c0 | 2015-12-03 10:48:52 +0100 | [diff] [blame] | 3288 | pvt->info.dram_attr = dram_attr; |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 3289 | pvt->info.max_sad = ARRAY_SIZE(ibridge_dram_rule); |
| 3290 | pvt->info.interleave_list = ibridge_interleave_list; |
| 3291 | pvt->info.max_interleave = ARRAY_SIZE(ibridge_interleave_list); |
| 3292 | pvt->info.interleave_pkg = ibridge_interleave_pkg; |
Aristeu Rozanski | 12f0721 | 2015-06-12 15:08:17 -0400 | [diff] [blame] | 3293 | pvt->info.get_width = broadwell_get_width; |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 3294 | mci->ctl_name = kasprintf(GFP_KERNEL, "Broadwell Socket#%d", mci->mc_idx); |
| 3295 | |
| 3296 | /* Store pci devices at mci for faster access */ |
| 3297 | rc = broadwell_mci_bind_devs(mci, sbridge_dev); |
| 3298 | if (unlikely(rc < 0)) |
| 3299 | goto fail0; |
| 3300 | break; |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 3301 | case KNIGHTS_LANDING: |
| 3302 | /* pvt->info.rankcfgr == ??? */ |
| 3303 | pvt->info.get_tolm = knl_get_tolm; |
| 3304 | pvt->info.get_tohm = knl_get_tohm; |
| 3305 | pvt->info.dram_rule = knl_dram_rule; |
| 3306 | pvt->info.get_memory_type = knl_get_memory_type; |
| 3307 | pvt->info.get_node_id = knl_get_node_id; |
| 3308 | pvt->info.rir_limit = NULL; |
| 3309 | pvt->info.sad_limit = knl_sad_limit; |
| 3310 | pvt->info.interleave_mode = knl_interleave_mode; |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 3311 | pvt->info.dram_attr = dram_attr_knl; |
| 3312 | pvt->info.max_sad = ARRAY_SIZE(knl_dram_rule); |
| 3313 | pvt->info.interleave_list = knl_interleave_list; |
| 3314 | pvt->info.max_interleave = ARRAY_SIZE(knl_interleave_list); |
| 3315 | pvt->info.interleave_pkg = ibridge_interleave_pkg; |
Hubert Chrzaniuk | 45f4d3a | 2015-12-11 14:21:22 +0100 | [diff] [blame] | 3316 | pvt->info.get_width = knl_get_width; |
Jim Snow | d0cdf90 | 2015-12-03 10:48:54 +0100 | [diff] [blame] | 3317 | mci->ctl_name = kasprintf(GFP_KERNEL, |
| 3318 | "Knights Landing Socket#%d", mci->mc_idx); |
| 3319 | |
| 3320 | rc = knl_mci_bind_devs(mci, sbridge_dev); |
| 3321 | if (unlikely(rc < 0)) |
| 3322 | goto fail0; |
| 3323 | break; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 3324 | } |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3325 | |
| 3326 | /* Get dimm basic config and the memory layout */ |
| 3327 | get_dimm_config(mci); |
| 3328 | get_memory_layout(mci); |
| 3329 | |
| 3330 | /* record ptr to the generic device */ |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 3331 | mci->pdev = &pdev->dev; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3332 | |
| 3333 | /* add this new MC control structure to EDAC's list of MCs */ |
| 3334 | if (unlikely(edac_mc_add_mc(mci))) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 3335 | edac_dbg(0, "MC: failed edac_mc_add_mc()\n"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3336 | rc = -EINVAL; |
| 3337 | goto fail0; |
| 3338 | } |
| 3339 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3340 | return 0; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3341 | |
| 3342 | fail0: |
| 3343 | kfree(mci->ctl_name); |
| 3344 | edac_mc_free(mci); |
| 3345 | sbridge_dev->mci = NULL; |
| 3346 | return rc; |
| 3347 | } |
| 3348 | |
Tony Luck | 2c1ea4c | 2016-04-28 15:40:00 -0700 | [diff] [blame] | 3349 | #define ICPU(model, table) \ |
| 3350 | { X86_VENDOR_INTEL, 6, model, 0, (unsigned long)&table } |
| 3351 | |
Tony Luck | 2c1ea4c | 2016-04-28 15:40:00 -0700 | [diff] [blame] | 3352 | static const struct x86_cpu_id sbridge_cpuids[] = { |
Dave Hansen | 20f4d69 | 2016-09-29 13:43:21 -0700 | [diff] [blame] | 3353 | ICPU(INTEL_FAM6_SANDYBRIDGE_X, pci_dev_descr_sbridge_table), |
| 3354 | ICPU(INTEL_FAM6_IVYBRIDGE_X, pci_dev_descr_ibridge_table), |
| 3355 | ICPU(INTEL_FAM6_HASWELL_X, pci_dev_descr_haswell_table), |
| 3356 | ICPU(INTEL_FAM6_BROADWELL_X, pci_dev_descr_broadwell_table), |
| 3357 | ICPU(INTEL_FAM6_BROADWELL_XEON_D, pci_dev_descr_broadwell_table), |
| 3358 | ICPU(INTEL_FAM6_XEON_PHI_KNL, pci_dev_descr_knl_table), |
Piotr Luc | 9a9260ca | 2016-10-13 17:30:59 +0200 | [diff] [blame] | 3359 | ICPU(INTEL_FAM6_XEON_PHI_KNM, pci_dev_descr_knl_table), |
Tony Luck | 2c1ea4c | 2016-04-28 15:40:00 -0700 | [diff] [blame] | 3360 | { } |
| 3361 | }; |
| 3362 | MODULE_DEVICE_TABLE(x86cpu, sbridge_cpuids); |
| 3363 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3364 | /* |
Tony Luck | 2c1ea4c | 2016-04-28 15:40:00 -0700 | [diff] [blame] | 3365 | * sbridge_probe Get all devices and register memory controllers |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3366 | * present. |
| 3367 | * return: |
| 3368 | * 0 for FOUND a device |
| 3369 | * < 0 for error code |
| 3370 | */ |
| 3371 | |
Tony Luck | 2c1ea4c | 2016-04-28 15:40:00 -0700 | [diff] [blame] | 3372 | static int sbridge_probe(const struct x86_cpu_id *id) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3373 | { |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 3374 | int rc = -ENODEV; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3375 | u8 mc, num_mc = 0; |
| 3376 | struct sbridge_dev *sbridge_dev; |
Tony Luck | 2c1ea4c | 2016-04-28 15:40:00 -0700 | [diff] [blame] | 3377 | struct pci_id_table *ptable = (struct pci_id_table *)id->driver_data; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3378 | |
| 3379 | /* get the pci devices we want to reserve for our use */ |
Tony Luck | 2c1ea4c | 2016-04-28 15:40:00 -0700 | [diff] [blame] | 3380 | rc = sbridge_get_all_devices(&num_mc, ptable); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3381 | |
Borislav Petkov | 11249e7 | 2015-02-05 12:39:36 +0100 | [diff] [blame] | 3382 | if (unlikely(rc < 0)) { |
Tony Luck | 2c1ea4c | 2016-04-28 15:40:00 -0700 | [diff] [blame] | 3383 | edac_dbg(0, "couldn't get all devices\n"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3384 | goto fail0; |
Borislav Petkov | 11249e7 | 2015-02-05 12:39:36 +0100 | [diff] [blame] | 3385 | } |
| 3386 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3387 | mc = 0; |
| 3388 | |
| 3389 | list_for_each_entry(sbridge_dev, &sbridge_edac_list, list) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 3390 | edac_dbg(0, "Registering MC#%d (%d of %d)\n", |
| 3391 | mc, mc + 1, num_mc); |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 3392 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3393 | sbridge_dev->mc = mc++; |
Tony Luck | 665f05e0 | 2016-06-02 10:58:08 -0700 | [diff] [blame] | 3394 | rc = sbridge_register_mci(sbridge_dev, ptable->type); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3395 | if (unlikely(rc < 0)) |
| 3396 | goto fail1; |
| 3397 | } |
| 3398 | |
Borislav Petkov | 11249e7 | 2015-02-05 12:39:36 +0100 | [diff] [blame] | 3399 | sbridge_printk(KERN_INFO, "%s\n", SBRIDGE_REVISION); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3400 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3401 | return 0; |
| 3402 | |
| 3403 | fail1: |
| 3404 | list_for_each_entry(sbridge_dev, &sbridge_edac_list, list) |
| 3405 | sbridge_unregister_mci(sbridge_dev); |
| 3406 | |
| 3407 | sbridge_put_all_devices(); |
| 3408 | fail0: |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3409 | return rc; |
| 3410 | } |
| 3411 | |
| 3412 | /* |
Tony Luck | 2c1ea4c | 2016-04-28 15:40:00 -0700 | [diff] [blame] | 3413 | * sbridge_remove cleanup |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3414 | * |
| 3415 | */ |
Tony Luck | 2c1ea4c | 2016-04-28 15:40:00 -0700 | [diff] [blame] | 3416 | static void sbridge_remove(void) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3417 | { |
| 3418 | struct sbridge_dev *sbridge_dev; |
| 3419 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 3420 | edac_dbg(0, "\n"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3421 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3422 | list_for_each_entry(sbridge_dev, &sbridge_edac_list, list) |
| 3423 | sbridge_unregister_mci(sbridge_dev); |
| 3424 | |
| 3425 | /* Release PCI resources */ |
| 3426 | sbridge_put_all_devices(); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3427 | } |
| 3428 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3429 | /* |
| 3430 | * sbridge_init Module entry function |
| 3431 | * Try to initialize this module for its devices |
| 3432 | */ |
| 3433 | static int __init sbridge_init(void) |
| 3434 | { |
Tony Luck | 2c1ea4c | 2016-04-28 15:40:00 -0700 | [diff] [blame] | 3435 | const struct x86_cpu_id *id; |
| 3436 | int rc; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3437 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 3438 | edac_dbg(2, "\n"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3439 | |
Tony Luck | 2c1ea4c | 2016-04-28 15:40:00 -0700 | [diff] [blame] | 3440 | id = x86_match_cpu(sbridge_cpuids); |
| 3441 | if (!id) |
| 3442 | return -ENODEV; |
| 3443 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3444 | /* Ensure that the OPSTATE is set correctly for POLL or NMI */ |
| 3445 | opstate_init(); |
| 3446 | |
Tony Luck | 2c1ea4c | 2016-04-28 15:40:00 -0700 | [diff] [blame] | 3447 | rc = sbridge_probe(id); |
| 3448 | |
| 3449 | if (rc >= 0) { |
Chen Gong | e35fca4 | 2012-05-08 20:40:12 -0300 | [diff] [blame] | 3450 | mce_register_decode_chain(&sbridge_mce_dec); |
Borislav Petkov | bffc7de | 2017-02-04 18:10:14 +0100 | [diff] [blame] | 3451 | if (edac_get_report_status() == EDAC_REPORTING_DISABLED) |
Chen, Gong | fd52103 | 2013-12-06 01:17:09 -0500 | [diff] [blame] | 3452 | sbridge_printk(KERN_WARNING, "Loading driver, error reporting disabled.\n"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3453 | return 0; |
Chen Gong | e35fca4 | 2012-05-08 20:40:12 -0300 | [diff] [blame] | 3454 | } |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3455 | |
| 3456 | sbridge_printk(KERN_ERR, "Failed to register device with error %d.\n", |
Tony Luck | 2c1ea4c | 2016-04-28 15:40:00 -0700 | [diff] [blame] | 3457 | rc); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3458 | |
Tony Luck | 2c1ea4c | 2016-04-28 15:40:00 -0700 | [diff] [blame] | 3459 | return rc; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3460 | } |
| 3461 | |
| 3462 | /* |
| 3463 | * sbridge_exit() Module exit function |
| 3464 | * Unregister the driver |
| 3465 | */ |
| 3466 | static void __exit sbridge_exit(void) |
| 3467 | { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 3468 | edac_dbg(2, "\n"); |
Tony Luck | 2c1ea4c | 2016-04-28 15:40:00 -0700 | [diff] [blame] | 3469 | sbridge_remove(); |
Chen Gong | e35fca4 | 2012-05-08 20:40:12 -0300 | [diff] [blame] | 3470 | mce_unregister_decode_chain(&sbridge_mce_dec); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3471 | } |
| 3472 | |
| 3473 | module_init(sbridge_init); |
| 3474 | module_exit(sbridge_exit); |
| 3475 | |
| 3476 | module_param(edac_op_state, int, 0444); |
| 3477 | MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI"); |
| 3478 | |
| 3479 | MODULE_LICENSE("GPL"); |
Mauro Carvalho Chehab | 37e59f8 | 2014-02-07 08:03:07 -0200 | [diff] [blame] | 3480 | MODULE_AUTHOR("Mauro Carvalho Chehab"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3481 | MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)"); |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 3482 | MODULE_DESCRIPTION("MC Driver for Intel Sandy Bridge and Ivy Bridge memory controllers - " |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 3483 | SBRIDGE_REVISION); |