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