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> |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 24 | #include <asm/processor.h> |
Mauro Carvalho Chehab | 3d78c9a | 2011-10-20 19:33:46 -0200 | [diff] [blame] | 25 | #include <asm/mce.h> |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 26 | |
| 27 | #include "edac_core.h" |
| 28 | |
| 29 | /* Static vars */ |
| 30 | static LIST_HEAD(sbridge_edac_list); |
| 31 | static DEFINE_MUTEX(sbridge_edac_lock); |
| 32 | static int probed; |
| 33 | |
| 34 | /* |
| 35 | * Alter this version for the module when modifications are made |
| 36 | */ |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 37 | #define SBRIDGE_REVISION " Ver: 1.1.0 " |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 38 | #define EDAC_MOD_STR "sbridge_edac" |
| 39 | |
| 40 | /* |
| 41 | * Debug macros |
| 42 | */ |
| 43 | #define sbridge_printk(level, fmt, arg...) \ |
| 44 | edac_printk(level, "sbridge", fmt, ##arg) |
| 45 | |
| 46 | #define sbridge_mc_printk(mci, level, fmt, arg...) \ |
| 47 | edac_mc_chipset_printk(mci, level, "sbridge", fmt, ##arg) |
| 48 | |
| 49 | /* |
| 50 | * Get a bit field at register value <v>, from bit <lo> to bit <hi> |
| 51 | */ |
| 52 | #define GET_BITFIELD(v, lo, hi) \ |
Chen, Gong | 10ef6b0 | 2013-10-18 14:29:07 -0700 | [diff] [blame] | 53 | (((v) & GENMASK_ULL(hi, lo)) >> (lo)) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 54 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 55 | /* Devices 12 Function 6, Offsets 0x80 to 0xcc */ |
Aristeu Rozanski | 464f1d8 | 2013-10-30 13:27:00 -0300 | [diff] [blame] | 56 | static const u32 sbridge_dram_rule[] = { |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 57 | 0x80, 0x88, 0x90, 0x98, 0xa0, |
| 58 | 0xa8, 0xb0, 0xb8, 0xc0, 0xc8, |
| 59 | }; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 60 | |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 61 | static const u32 ibridge_dram_rule[] = { |
| 62 | 0x60, 0x68, 0x70, 0x78, 0x80, |
| 63 | 0x88, 0x90, 0x98, 0xa0, 0xa8, |
| 64 | 0xb0, 0xb8, 0xc0, 0xc8, 0xd0, |
| 65 | 0xd8, 0xe0, 0xe8, 0xf0, 0xf8, |
| 66 | }; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 67 | |
| 68 | #define SAD_LIMIT(reg) ((GET_BITFIELD(reg, 6, 25) << 26) | 0x3ffffff) |
| 69 | #define DRAM_ATTR(reg) GET_BITFIELD(reg, 2, 3) |
| 70 | #define INTERLEAVE_MODE(reg) GET_BITFIELD(reg, 1, 1) |
| 71 | #define DRAM_RULE_ENABLE(reg) GET_BITFIELD(reg, 0, 0) |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 72 | #define A7MODE(reg) GET_BITFIELD(reg, 26, 26) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 73 | |
| 74 | static char *get_dram_attr(u32 reg) |
| 75 | { |
| 76 | switch(DRAM_ATTR(reg)) { |
| 77 | case 0: |
| 78 | return "DRAM"; |
| 79 | case 1: |
| 80 | return "MMCFG"; |
| 81 | case 2: |
| 82 | return "NXM"; |
| 83 | default: |
| 84 | return "unknown"; |
| 85 | } |
| 86 | } |
| 87 | |
Aristeu Rozanski | ef1ce51 | 2013-10-30 13:27:01 -0300 | [diff] [blame] | 88 | static const u32 sbridge_interleave_list[] = { |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 89 | 0x84, 0x8c, 0x94, 0x9c, 0xa4, |
| 90 | 0xac, 0xb4, 0xbc, 0xc4, 0xcc, |
| 91 | }; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 92 | |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 93 | static const u32 ibridge_interleave_list[] = { |
| 94 | 0x64, 0x6c, 0x74, 0x7c, 0x84, |
| 95 | 0x8c, 0x94, 0x9c, 0xa4, 0xac, |
| 96 | 0xb4, 0xbc, 0xc4, 0xcc, 0xd4, |
| 97 | 0xdc, 0xe4, 0xec, 0xf4, 0xfc, |
| 98 | }; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 99 | |
Aristeu Rozanski | cc31199 | 2013-10-30 13:27:02 -0300 | [diff] [blame] | 100 | struct interleave_pkg { |
| 101 | unsigned char start; |
| 102 | unsigned char end; |
| 103 | }; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 104 | |
Aristeu Rozanski | cc31199 | 2013-10-30 13:27:02 -0300 | [diff] [blame] | 105 | static const struct interleave_pkg sbridge_interleave_pkg[] = { |
| 106 | { 0, 2 }, |
| 107 | { 3, 5 }, |
| 108 | { 8, 10 }, |
| 109 | { 11, 13 }, |
| 110 | { 16, 18 }, |
| 111 | { 19, 21 }, |
| 112 | { 24, 26 }, |
| 113 | { 27, 29 }, |
| 114 | }; |
| 115 | |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 116 | static const struct interleave_pkg ibridge_interleave_pkg[] = { |
| 117 | { 0, 3 }, |
| 118 | { 4, 7 }, |
| 119 | { 8, 11 }, |
| 120 | { 12, 15 }, |
| 121 | { 16, 19 }, |
| 122 | { 20, 23 }, |
| 123 | { 24, 27 }, |
| 124 | { 28, 31 }, |
| 125 | }; |
| 126 | |
Aristeu Rozanski | cc31199 | 2013-10-30 13:27:02 -0300 | [diff] [blame] | 127 | static inline int sad_pkg(const struct interleave_pkg *table, u32 reg, |
| 128 | int interleave) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 129 | { |
Aristeu Rozanski | cc31199 | 2013-10-30 13:27:02 -0300 | [diff] [blame] | 130 | return GET_BITFIELD(reg, table[interleave].start, |
| 131 | table[interleave].end); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | /* Devices 12 Function 7 */ |
| 135 | |
| 136 | #define TOLM 0x80 |
| 137 | #define TOHM 0x84 |
Tony Luck | f7cf2a2 | 2014-10-29 10:36:50 -0700 | [diff] [blame] | 138 | #define HASWELL_TOLM 0xd0 |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 139 | #define HASWELL_TOHM_0 0xd4 |
| 140 | #define HASWELL_TOHM_1 0xd8 |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 141 | |
| 142 | #define GET_TOLM(reg) ((GET_BITFIELD(reg, 0, 3) << 28) | 0x3ffffff) |
| 143 | #define GET_TOHM(reg) ((GET_BITFIELD(reg, 0, 20) << 25) | 0x3ffffff) |
| 144 | |
| 145 | /* Device 13 Function 6 */ |
| 146 | |
| 147 | #define SAD_TARGET 0xf0 |
| 148 | |
| 149 | #define SOURCE_ID(reg) GET_BITFIELD(reg, 9, 11) |
| 150 | |
| 151 | #define SAD_CONTROL 0xf4 |
| 152 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 153 | /* Device 14 function 0 */ |
| 154 | |
| 155 | static const u32 tad_dram_rule[] = { |
| 156 | 0x40, 0x44, 0x48, 0x4c, |
| 157 | 0x50, 0x54, 0x58, 0x5c, |
| 158 | 0x60, 0x64, 0x68, 0x6c, |
| 159 | }; |
| 160 | #define MAX_TAD ARRAY_SIZE(tad_dram_rule) |
| 161 | |
| 162 | #define TAD_LIMIT(reg) ((GET_BITFIELD(reg, 12, 31) << 26) | 0x3ffffff) |
| 163 | #define TAD_SOCK(reg) GET_BITFIELD(reg, 10, 11) |
| 164 | #define TAD_CH(reg) GET_BITFIELD(reg, 8, 9) |
| 165 | #define TAD_TGT3(reg) GET_BITFIELD(reg, 6, 7) |
| 166 | #define TAD_TGT2(reg) GET_BITFIELD(reg, 4, 5) |
| 167 | #define TAD_TGT1(reg) GET_BITFIELD(reg, 2, 3) |
| 168 | #define TAD_TGT0(reg) GET_BITFIELD(reg, 0, 1) |
| 169 | |
| 170 | /* Device 15, function 0 */ |
| 171 | |
| 172 | #define MCMTR 0x7c |
| 173 | |
| 174 | #define IS_ECC_ENABLED(mcmtr) GET_BITFIELD(mcmtr, 2, 2) |
| 175 | #define IS_LOCKSTEP_ENABLED(mcmtr) GET_BITFIELD(mcmtr, 1, 1) |
| 176 | #define IS_CLOSE_PG(mcmtr) GET_BITFIELD(mcmtr, 0, 0) |
| 177 | |
| 178 | /* Device 15, function 1 */ |
| 179 | |
| 180 | #define RASENABLES 0xac |
| 181 | #define IS_MIRROR_ENABLED(reg) GET_BITFIELD(reg, 0, 0) |
| 182 | |
| 183 | /* Device 15, functions 2-5 */ |
| 184 | |
| 185 | static const int mtr_regs[] = { |
| 186 | 0x80, 0x84, 0x88, |
| 187 | }; |
| 188 | |
| 189 | #define RANK_DISABLE(mtr) GET_BITFIELD(mtr, 16, 19) |
| 190 | #define IS_DIMM_PRESENT(mtr) GET_BITFIELD(mtr, 14, 14) |
| 191 | #define RANK_CNT_BITS(mtr) GET_BITFIELD(mtr, 12, 13) |
| 192 | #define RANK_WIDTH_BITS(mtr) GET_BITFIELD(mtr, 2, 4) |
| 193 | #define COL_WIDTH_BITS(mtr) GET_BITFIELD(mtr, 0, 1) |
| 194 | |
| 195 | static const u32 tad_ch_nilv_offset[] = { |
| 196 | 0x90, 0x94, 0x98, 0x9c, |
| 197 | 0xa0, 0xa4, 0xa8, 0xac, |
| 198 | 0xb0, 0xb4, 0xb8, 0xbc, |
| 199 | }; |
| 200 | #define CHN_IDX_OFFSET(reg) GET_BITFIELD(reg, 28, 29) |
| 201 | #define TAD_OFFSET(reg) (GET_BITFIELD(reg, 6, 25) << 26) |
| 202 | |
| 203 | static const u32 rir_way_limit[] = { |
| 204 | 0x108, 0x10c, 0x110, 0x114, 0x118, |
| 205 | }; |
| 206 | #define MAX_RIR_RANGES ARRAY_SIZE(rir_way_limit) |
| 207 | |
| 208 | #define IS_RIR_VALID(reg) GET_BITFIELD(reg, 31, 31) |
| 209 | #define RIR_WAY(reg) GET_BITFIELD(reg, 28, 29) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 210 | |
| 211 | #define MAX_RIR_WAY 8 |
| 212 | |
| 213 | static const u32 rir_offset[MAX_RIR_RANGES][MAX_RIR_WAY] = { |
| 214 | { 0x120, 0x124, 0x128, 0x12c, 0x130, 0x134, 0x138, 0x13c }, |
| 215 | { 0x140, 0x144, 0x148, 0x14c, 0x150, 0x154, 0x158, 0x15c }, |
| 216 | { 0x160, 0x164, 0x168, 0x16c, 0x170, 0x174, 0x178, 0x17c }, |
| 217 | { 0x180, 0x184, 0x188, 0x18c, 0x190, 0x194, 0x198, 0x19c }, |
| 218 | { 0x1a0, 0x1a4, 0x1a8, 0x1ac, 0x1b0, 0x1b4, 0x1b8, 0x1bc }, |
| 219 | }; |
| 220 | |
| 221 | #define RIR_RNK_TGT(reg) GET_BITFIELD(reg, 16, 19) |
| 222 | #define RIR_OFFSET(reg) GET_BITFIELD(reg, 2, 14) |
| 223 | |
| 224 | /* Device 16, functions 2-7 */ |
| 225 | |
| 226 | /* |
| 227 | * FIXME: Implement the error count reads directly |
| 228 | */ |
| 229 | |
| 230 | static const u32 correrrcnt[] = { |
| 231 | 0x104, 0x108, 0x10c, 0x110, |
| 232 | }; |
| 233 | |
| 234 | #define RANK_ODD_OV(reg) GET_BITFIELD(reg, 31, 31) |
| 235 | #define RANK_ODD_ERR_CNT(reg) GET_BITFIELD(reg, 16, 30) |
| 236 | #define RANK_EVEN_OV(reg) GET_BITFIELD(reg, 15, 15) |
| 237 | #define RANK_EVEN_ERR_CNT(reg) GET_BITFIELD(reg, 0, 14) |
| 238 | |
| 239 | static const u32 correrrthrsld[] = { |
| 240 | 0x11c, 0x120, 0x124, 0x128, |
| 241 | }; |
| 242 | |
| 243 | #define RANK_ODD_ERR_THRSLD(reg) GET_BITFIELD(reg, 16, 30) |
| 244 | #define RANK_EVEN_ERR_THRSLD(reg) GET_BITFIELD(reg, 0, 14) |
| 245 | |
| 246 | |
| 247 | /* Device 17, function 0 */ |
| 248 | |
Aristeu Rozanski | ef1e8d0 | 2013-10-30 13:26:56 -0300 | [diff] [blame] | 249 | #define SB_RANK_CFG_A 0x0328 |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 250 | |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 251 | #define IB_RANK_CFG_A 0x0320 |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 252 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 253 | /* |
| 254 | * sbridge structs |
| 255 | */ |
| 256 | |
Seth Jennings | 351fc4a | 2014-09-05 14:28:47 -0500 | [diff] [blame] | 257 | #define NUM_CHANNELS 4 |
| 258 | #define MAX_DIMMS 3 /* Max DIMMS per channel */ |
| 259 | #define CHANNEL_UNSPECIFIED 0xf /* Intel IA32 SDM 15-14 */ |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 260 | |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 261 | enum type { |
| 262 | SANDY_BRIDGE, |
| 263 | IVY_BRIDGE, |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 264 | HASWELL, |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 265 | BROADWELL, |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 266 | }; |
| 267 | |
Aristeu Rozanski | fb79a50 | 2013-10-30 13:26:57 -0300 | [diff] [blame] | 268 | struct sbridge_pvt; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 269 | struct sbridge_info { |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 270 | enum type type; |
Aristeu Rozanski | 464f1d8 | 2013-10-30 13:27:00 -0300 | [diff] [blame] | 271 | u32 mcmtr; |
| 272 | u32 rankcfgr; |
| 273 | u64 (*get_tolm)(struct sbridge_pvt *pvt); |
| 274 | u64 (*get_tohm)(struct sbridge_pvt *pvt); |
Aristeu Rozanski | b976bcf | 2014-06-02 15:15:24 -0300 | [diff] [blame] | 275 | u64 (*rir_limit)(u32 reg); |
Aristeu Rozanski | 464f1d8 | 2013-10-30 13:27:00 -0300 | [diff] [blame] | 276 | const u32 *dram_rule; |
Aristeu Rozanski | ef1ce51 | 2013-10-30 13:27:01 -0300 | [diff] [blame] | 277 | const u32 *interleave_list; |
Aristeu Rozanski | cc31199 | 2013-10-30 13:27:02 -0300 | [diff] [blame] | 278 | const struct interleave_pkg *interleave_pkg; |
Aristeu Rozanski | 464f1d8 | 2013-10-30 13:27:00 -0300 | [diff] [blame] | 279 | u8 max_sad; |
Aristeu Rozanski | ef1ce51 | 2013-10-30 13:27:01 -0300 | [diff] [blame] | 280 | u8 max_interleave; |
Aristeu Rozanski | f14d689 | 2014-06-02 15:15:23 -0300 | [diff] [blame] | 281 | u8 (*get_node_id)(struct sbridge_pvt *pvt); |
Aristeu Rozanski | 9e37544 | 2014-06-02 15:15:22 -0300 | [diff] [blame] | 282 | enum mem_type (*get_memory_type)(struct sbridge_pvt *pvt); |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 283 | struct pci_dev *pci_vtd; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 284 | }; |
| 285 | |
| 286 | struct sbridge_channel { |
| 287 | u32 ranks; |
| 288 | u32 dimms; |
| 289 | }; |
| 290 | |
| 291 | struct pci_id_descr { |
Mauro Carvalho Chehab | c41afdc | 2014-06-26 15:35:14 -0300 | [diff] [blame] | 292 | int dev_id; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 293 | int optional; |
| 294 | }; |
| 295 | |
| 296 | struct pci_id_table { |
| 297 | const struct pci_id_descr *descr; |
| 298 | int n_devs; |
| 299 | }; |
| 300 | |
| 301 | struct sbridge_dev { |
| 302 | struct list_head list; |
| 303 | u8 bus, mc; |
| 304 | u8 node_id, source_id; |
| 305 | struct pci_dev **pdev; |
| 306 | int n_devs; |
| 307 | struct mem_ctl_info *mci; |
| 308 | }; |
| 309 | |
| 310 | struct sbridge_pvt { |
| 311 | struct pci_dev *pci_ta, *pci_ddrio, *pci_ras; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 312 | struct pci_dev *pci_sad0, *pci_sad1; |
| 313 | struct pci_dev *pci_ha0, *pci_ha1; |
| 314 | struct pci_dev *pci_br0, *pci_br1; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 315 | struct pci_dev *pci_ha1_ta; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 316 | struct pci_dev *pci_tad[NUM_CHANNELS]; |
| 317 | |
| 318 | struct sbridge_dev *sbridge_dev; |
| 319 | |
| 320 | struct sbridge_info info; |
| 321 | struct sbridge_channel channel[NUM_CHANNELS]; |
| 322 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 323 | /* Memory type detection */ |
| 324 | bool is_mirrored, is_lockstep, is_close_pg; |
| 325 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 326 | /* Fifo double buffers */ |
| 327 | struct mce mce_entry[MCE_LOG_LEN]; |
| 328 | struct mce mce_outentry[MCE_LOG_LEN]; |
| 329 | |
| 330 | /* Fifo in/out counters */ |
| 331 | unsigned mce_in, mce_out; |
| 332 | |
| 333 | /* Count indicator to show errors not got */ |
| 334 | unsigned mce_overrun; |
| 335 | |
| 336 | /* Memory description */ |
| 337 | u64 tolm, tohm; |
| 338 | }; |
| 339 | |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 340 | #define PCI_DESCR(device_id, opt) \ |
| 341 | .dev_id = (device_id), \ |
Luck, Tony | de4772c | 2013-03-28 09:59:15 -0700 | [diff] [blame] | 342 | .optional = opt |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 343 | |
| 344 | static const struct pci_id_descr pci_dev_descr_sbridge[] = { |
| 345 | /* Processor Home Agent */ |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 346 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_HA0, 0) }, |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 347 | |
| 348 | /* Memory controller */ |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 349 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA, 0) }, |
| 350 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_RAS, 0) }, |
| 351 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD0, 0) }, |
| 352 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD1, 0) }, |
| 353 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD2, 0) }, |
| 354 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD3, 0) }, |
| 355 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_DDRIO, 1) }, |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 356 | |
| 357 | /* System Address Decoder */ |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 358 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_SAD0, 0) }, |
| 359 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_SAD1, 0) }, |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 360 | |
| 361 | /* Broadcast Registers */ |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 362 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_BR, 0) }, |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 363 | }; |
| 364 | |
| 365 | #define PCI_ID_TABLE_ENTRY(A) { .descr=A, .n_devs = ARRAY_SIZE(A) } |
| 366 | static const struct pci_id_table pci_dev_descr_sbridge_table[] = { |
| 367 | PCI_ID_TABLE_ENTRY(pci_dev_descr_sbridge), |
| 368 | {0,} /* 0 terminated list. */ |
| 369 | }; |
| 370 | |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 371 | /* This changes depending if 1HA or 2HA: |
| 372 | * 1HA: |
| 373 | * 0x0eb8 (17.0) is DDRIO0 |
| 374 | * 2HA: |
| 375 | * 0x0ebc (17.4) is DDRIO0 |
| 376 | */ |
| 377 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_1HA_DDRIO0 0x0eb8 |
| 378 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_2HA_DDRIO0 0x0ebc |
| 379 | |
| 380 | /* pci ids */ |
| 381 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0 0x0ea0 |
| 382 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA 0x0ea8 |
| 383 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_RAS 0x0e71 |
| 384 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD0 0x0eaa |
| 385 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD1 0x0eab |
| 386 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD2 0x0eac |
| 387 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD3 0x0ead |
| 388 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_SAD 0x0ec8 |
| 389 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_BR0 0x0ec9 |
| 390 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_BR1 0x0eca |
| 391 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1 0x0e60 |
| 392 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TA 0x0e68 |
| 393 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_RAS 0x0e79 |
| 394 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD0 0x0e6a |
| 395 | #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD1 0x0e6b |
| 396 | |
| 397 | static const struct pci_id_descr pci_dev_descr_ibridge[] = { |
| 398 | /* Processor Home Agent */ |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 399 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0, 0) }, |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 400 | |
| 401 | /* Memory controller */ |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 402 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA, 0) }, |
| 403 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_RAS, 0) }, |
| 404 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD0, 0) }, |
| 405 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD1, 0) }, |
| 406 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD2, 0) }, |
| 407 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD3, 0) }, |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 408 | |
| 409 | /* System Address Decoder */ |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 410 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_SAD, 0) }, |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 411 | |
| 412 | /* Broadcast Registers */ |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 413 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_BR0, 1) }, |
| 414 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_BR1, 0) }, |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 415 | |
| 416 | /* Optional, mode 2HA */ |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 417 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1, 1) }, |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 418 | #if 0 |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 419 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TA, 1) }, |
| 420 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_RAS, 1) }, |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 421 | #endif |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 422 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD0, 1) }, |
| 423 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD1, 1) }, |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 424 | |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 425 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_1HA_DDRIO0, 1) }, |
| 426 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_2HA_DDRIO0, 1) }, |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 427 | }; |
| 428 | |
| 429 | static const struct pci_id_table pci_dev_descr_ibridge_table[] = { |
| 430 | PCI_ID_TABLE_ENTRY(pci_dev_descr_ibridge), |
| 431 | {0,} /* 0 terminated list. */ |
| 432 | }; |
| 433 | |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 434 | /* Haswell support */ |
| 435 | /* EN processor: |
| 436 | * - 1 IMC |
| 437 | * - 3 DDR3 channels, 2 DPC per channel |
| 438 | * EP processor: |
| 439 | * - 1 or 2 IMC |
| 440 | * - 4 DDR4 channels, 3 DPC per channel |
| 441 | * EP 4S processor: |
| 442 | * - 2 IMC |
| 443 | * - 4 DDR4 channels, 3 DPC per channel |
| 444 | * EX processor: |
| 445 | * - 2 IMC |
| 446 | * - each IMC interfaces with a SMI 2 channel |
| 447 | * - each SMI channel interfaces with a scalable memory buffer |
| 448 | * - each scalable memory buffer supports 4 DDR3/DDR4 channels, 3 DPC |
| 449 | */ |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 450 | #define HASWELL_DDRCRCLKCONTROLS 0xa10 /* Ditto on Broadwell */ |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 451 | #define HASWELL_HASYSDEFEATURE2 0x84 |
| 452 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_VTD_MISC 0x2f28 |
| 453 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0 0x2fa0 |
| 454 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1 0x2f60 |
| 455 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TA 0x2fa8 |
| 456 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_THERMAL 0x2f71 |
| 457 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TA 0x2f68 |
| 458 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_THERMAL 0x2f79 |
| 459 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_CBO_SAD0 0x2ffc |
| 460 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_CBO_SAD1 0x2ffd |
| 461 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD0 0x2faa |
| 462 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD1 0x2fab |
| 463 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD2 0x2fac |
| 464 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD3 0x2fad |
| 465 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD0 0x2f6a |
| 466 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD1 0x2f6b |
| 467 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD2 0x2f6c |
| 468 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD3 0x2f6d |
| 469 | #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO0 0x2fbd |
| 470 | static const struct pci_id_descr pci_dev_descr_haswell[] = { |
| 471 | /* first item must be the HA */ |
| 472 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0, 0) }, |
| 473 | |
| 474 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_CBO_SAD0, 0) }, |
| 475 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_CBO_SAD1, 0) }, |
| 476 | |
| 477 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1, 1) }, |
| 478 | |
| 479 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TA, 0) }, |
| 480 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_THERMAL, 0) }, |
| 481 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD0, 0) }, |
| 482 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD1, 0) }, |
| 483 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD2, 1) }, |
| 484 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD3, 1) }, |
| 485 | |
| 486 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO0, 1) }, |
| 487 | |
| 488 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TA, 1) }, |
| 489 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_THERMAL, 1) }, |
| 490 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD0, 1) }, |
| 491 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD1, 1) }, |
| 492 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD2, 1) }, |
| 493 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD3, 1) }, |
| 494 | }; |
| 495 | |
| 496 | static const struct pci_id_table pci_dev_descr_haswell_table[] = { |
| 497 | PCI_ID_TABLE_ENTRY(pci_dev_descr_haswell), |
| 498 | {0,} /* 0 terminated list. */ |
| 499 | }; |
| 500 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 501 | /* |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 502 | * Broadwell support |
| 503 | * |
| 504 | * DE processor: |
| 505 | * - 1 IMC |
| 506 | * - 2 DDR3 channels, 2 DPC per channel |
| 507 | */ |
| 508 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_VTD_MISC 0x6f28 |
| 509 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0 0x6fa0 |
| 510 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TA 0x6fa8 |
| 511 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_THERMAL 0x6f71 |
| 512 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_CBO_SAD0 0x6ffc |
| 513 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_CBO_SAD1 0x6ffd |
| 514 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD0 0x6faa |
| 515 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD1 0x6fab |
| 516 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD2 0x6fac |
| 517 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD3 0x6fad |
| 518 | #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_DDRIO0 0x6faf |
| 519 | |
| 520 | static const struct pci_id_descr pci_dev_descr_broadwell[] = { |
| 521 | /* first item must be the HA */ |
| 522 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0, 0) }, |
| 523 | |
| 524 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_CBO_SAD0, 0) }, |
| 525 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_CBO_SAD1, 0) }, |
| 526 | |
| 527 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TA, 0) }, |
| 528 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_THERMAL, 0) }, |
| 529 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD0, 0) }, |
| 530 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD1, 0) }, |
| 531 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD2, 0) }, |
| 532 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD3, 0) }, |
| 533 | { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_DDRIO0, 1) }, |
| 534 | }; |
| 535 | |
| 536 | static const struct pci_id_table pci_dev_descr_broadwell_table[] = { |
| 537 | PCI_ID_TABLE_ENTRY(pci_dev_descr_broadwell), |
| 538 | {0,} /* 0 terminated list. */ |
| 539 | }; |
| 540 | |
| 541 | /* |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 542 | * pci_device_id table for which devices we are looking for |
| 543 | */ |
Jingoo Han | ba935f4 | 2013-12-06 10:23:08 +0100 | [diff] [blame] | 544 | static const struct pci_device_id sbridge_pci_tbl[] = { |
Andy Lutomirski | d0585cd | 2014-08-14 14:45:41 -0700 | [diff] [blame] | 545 | {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_HA0)}, |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 546 | {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA)}, |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 547 | {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0)}, |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 548 | {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0)}, |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 549 | {0,} /* 0 terminated list. */ |
| 550 | }; |
| 551 | |
| 552 | |
| 553 | /**************************************************************************** |
David Mackey | 15ed103 | 2012-04-17 11:30:52 -0700 | [diff] [blame] | 554 | Ancillary status routines |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 555 | ****************************************************************************/ |
| 556 | |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 557 | static inline int numrank(enum type type, u32 mtr) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 558 | { |
| 559 | int ranks = (1 << RANK_CNT_BITS(mtr)); |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 560 | int max = 4; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 561 | |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 562 | if (type == HASWELL) |
| 563 | max = 8; |
| 564 | |
| 565 | if (ranks > max) { |
| 566 | edac_dbg(0, "Invalid number of ranks: %d (max = %i) raw value = %x (%04x)\n", |
| 567 | ranks, max, (unsigned int)RANK_CNT_BITS(mtr), mtr); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 568 | return -EINVAL; |
| 569 | } |
| 570 | |
| 571 | return ranks; |
| 572 | } |
| 573 | |
| 574 | static inline int numrow(u32 mtr) |
| 575 | { |
| 576 | int rows = (RANK_WIDTH_BITS(mtr) + 12); |
| 577 | |
| 578 | if (rows < 13 || rows > 18) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 579 | edac_dbg(0, "Invalid number of rows: %d (should be between 14 and 17) raw value = %x (%04x)\n", |
| 580 | rows, (unsigned int)RANK_WIDTH_BITS(mtr), mtr); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 581 | return -EINVAL; |
| 582 | } |
| 583 | |
| 584 | return 1 << rows; |
| 585 | } |
| 586 | |
| 587 | static inline int numcol(u32 mtr) |
| 588 | { |
| 589 | int cols = (COL_WIDTH_BITS(mtr) + 10); |
| 590 | |
| 591 | if (cols > 12) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 592 | edac_dbg(0, "Invalid number of cols: %d (max = 4) raw value = %x (%04x)\n", |
| 593 | cols, (unsigned int)COL_WIDTH_BITS(mtr), mtr); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 594 | return -EINVAL; |
| 595 | } |
| 596 | |
| 597 | return 1 << cols; |
| 598 | } |
| 599 | |
| 600 | static struct sbridge_dev *get_sbridge_dev(u8 bus) |
| 601 | { |
| 602 | struct sbridge_dev *sbridge_dev; |
| 603 | |
| 604 | list_for_each_entry(sbridge_dev, &sbridge_edac_list, list) { |
| 605 | if (sbridge_dev->bus == bus) |
| 606 | return sbridge_dev; |
| 607 | } |
| 608 | |
| 609 | return NULL; |
| 610 | } |
| 611 | |
| 612 | static struct sbridge_dev *alloc_sbridge_dev(u8 bus, |
| 613 | const struct pci_id_table *table) |
| 614 | { |
| 615 | struct sbridge_dev *sbridge_dev; |
| 616 | |
| 617 | sbridge_dev = kzalloc(sizeof(*sbridge_dev), GFP_KERNEL); |
| 618 | if (!sbridge_dev) |
| 619 | return NULL; |
| 620 | |
| 621 | sbridge_dev->pdev = kzalloc(sizeof(*sbridge_dev->pdev) * table->n_devs, |
| 622 | GFP_KERNEL); |
| 623 | if (!sbridge_dev->pdev) { |
| 624 | kfree(sbridge_dev); |
| 625 | return NULL; |
| 626 | } |
| 627 | |
| 628 | sbridge_dev->bus = bus; |
| 629 | sbridge_dev->n_devs = table->n_devs; |
| 630 | list_add_tail(&sbridge_dev->list, &sbridge_edac_list); |
| 631 | |
| 632 | return sbridge_dev; |
| 633 | } |
| 634 | |
| 635 | static void free_sbridge_dev(struct sbridge_dev *sbridge_dev) |
| 636 | { |
| 637 | list_del(&sbridge_dev->list); |
| 638 | kfree(sbridge_dev->pdev); |
| 639 | kfree(sbridge_dev); |
| 640 | } |
| 641 | |
Aristeu Rozanski | fb79a50 | 2013-10-30 13:26:57 -0300 | [diff] [blame] | 642 | static u64 sbridge_get_tolm(struct sbridge_pvt *pvt) |
| 643 | { |
| 644 | u32 reg; |
| 645 | |
| 646 | /* Address range is 32:28 */ |
| 647 | pci_read_config_dword(pvt->pci_sad1, TOLM, ®); |
| 648 | return GET_TOLM(reg); |
| 649 | } |
| 650 | |
Aristeu Rozanski | 8fd6a43 | 2013-10-30 13:26:59 -0300 | [diff] [blame] | 651 | static u64 sbridge_get_tohm(struct sbridge_pvt *pvt) |
| 652 | { |
| 653 | u32 reg; |
| 654 | |
| 655 | pci_read_config_dword(pvt->pci_sad1, TOHM, ®); |
| 656 | return GET_TOHM(reg); |
| 657 | } |
| 658 | |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 659 | static u64 ibridge_get_tolm(struct sbridge_pvt *pvt) |
| 660 | { |
| 661 | u32 reg; |
| 662 | |
| 663 | pci_read_config_dword(pvt->pci_br1, TOLM, ®); |
| 664 | |
| 665 | return GET_TOLM(reg); |
| 666 | } |
| 667 | |
| 668 | static u64 ibridge_get_tohm(struct sbridge_pvt *pvt) |
| 669 | { |
| 670 | u32 reg; |
| 671 | |
| 672 | pci_read_config_dword(pvt->pci_br1, TOHM, ®); |
| 673 | |
| 674 | return GET_TOHM(reg); |
| 675 | } |
| 676 | |
Aristeu Rozanski | b976bcf | 2014-06-02 15:15:24 -0300 | [diff] [blame] | 677 | static u64 rir_limit(u32 reg) |
| 678 | { |
| 679 | return ((u64)GET_BITFIELD(reg, 1, 10) << 29) | 0x1fffffff; |
| 680 | } |
| 681 | |
Aristeu Rozanski | 9e37544 | 2014-06-02 15:15:22 -0300 | [diff] [blame] | 682 | static enum mem_type get_memory_type(struct sbridge_pvt *pvt) |
| 683 | { |
| 684 | u32 reg; |
| 685 | enum mem_type mtype; |
| 686 | |
| 687 | if (pvt->pci_ddrio) { |
| 688 | pci_read_config_dword(pvt->pci_ddrio, pvt->info.rankcfgr, |
| 689 | ®); |
| 690 | if (GET_BITFIELD(reg, 11, 11)) |
| 691 | /* FIXME: Can also be LRDIMM */ |
| 692 | mtype = MEM_RDDR3; |
| 693 | else |
| 694 | mtype = MEM_DDR3; |
| 695 | } else |
| 696 | mtype = MEM_UNKNOWN; |
| 697 | |
| 698 | return mtype; |
| 699 | } |
| 700 | |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 701 | static enum mem_type haswell_get_memory_type(struct sbridge_pvt *pvt) |
| 702 | { |
| 703 | u32 reg; |
| 704 | bool registered = false; |
| 705 | enum mem_type mtype = MEM_UNKNOWN; |
| 706 | |
| 707 | if (!pvt->pci_ddrio) |
| 708 | goto out; |
| 709 | |
| 710 | pci_read_config_dword(pvt->pci_ddrio, |
| 711 | HASWELL_DDRCRCLKCONTROLS, ®); |
| 712 | /* Is_Rdimm */ |
| 713 | if (GET_BITFIELD(reg, 16, 16)) |
| 714 | registered = true; |
| 715 | |
| 716 | pci_read_config_dword(pvt->pci_ta, MCMTR, ®); |
| 717 | if (GET_BITFIELD(reg, 14, 14)) { |
| 718 | if (registered) |
| 719 | mtype = MEM_RDDR4; |
| 720 | else |
| 721 | mtype = MEM_DDR4; |
| 722 | } else { |
| 723 | if (registered) |
| 724 | mtype = MEM_RDDR3; |
| 725 | else |
| 726 | mtype = MEM_DDR3; |
| 727 | } |
| 728 | |
| 729 | out: |
| 730 | return mtype; |
| 731 | } |
| 732 | |
Aristeu Rozanski | f14d689 | 2014-06-02 15:15:23 -0300 | [diff] [blame] | 733 | static u8 get_node_id(struct sbridge_pvt *pvt) |
| 734 | { |
| 735 | u32 reg; |
| 736 | pci_read_config_dword(pvt->pci_br0, SAD_CONTROL, ®); |
| 737 | return GET_BITFIELD(reg, 0, 2); |
| 738 | } |
| 739 | |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 740 | static u8 haswell_get_node_id(struct sbridge_pvt *pvt) |
| 741 | { |
| 742 | u32 reg; |
| 743 | |
| 744 | pci_read_config_dword(pvt->pci_sad1, SAD_CONTROL, ®); |
| 745 | return GET_BITFIELD(reg, 0, 3); |
| 746 | } |
| 747 | |
| 748 | static u64 haswell_get_tolm(struct sbridge_pvt *pvt) |
| 749 | { |
| 750 | u32 reg; |
| 751 | |
Tony Luck | f7cf2a2 | 2014-10-29 10:36:50 -0700 | [diff] [blame] | 752 | pci_read_config_dword(pvt->info.pci_vtd, HASWELL_TOLM, ®); |
| 753 | return (GET_BITFIELD(reg, 26, 31) << 26) | 0x3ffffff; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | static u64 haswell_get_tohm(struct sbridge_pvt *pvt) |
| 757 | { |
| 758 | u64 rc; |
| 759 | u32 reg; |
| 760 | |
| 761 | pci_read_config_dword(pvt->info.pci_vtd, HASWELL_TOHM_0, ®); |
| 762 | rc = GET_BITFIELD(reg, 26, 31); |
| 763 | pci_read_config_dword(pvt->info.pci_vtd, HASWELL_TOHM_1, ®); |
| 764 | rc = ((reg << 6) | rc) << 26; |
| 765 | |
| 766 | return rc | 0x1ffffff; |
| 767 | } |
| 768 | |
| 769 | static u64 haswell_rir_limit(u32 reg) |
| 770 | { |
| 771 | return (((u64)GET_BITFIELD(reg, 1, 11) + 1) << 29) - 1; |
| 772 | } |
| 773 | |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 774 | static inline u8 sad_pkg_socket(u8 pkg) |
| 775 | { |
| 776 | /* 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] | 777 | return ((pkg >> 3) << 2) | (pkg & 0x3); |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | static inline u8 sad_pkg_ha(u8 pkg) |
| 781 | { |
| 782 | return (pkg >> 2) & 0x1; |
| 783 | } |
| 784 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 785 | /**************************************************************************** |
| 786 | Memory check routines |
| 787 | ****************************************************************************/ |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 788 | static struct pci_dev *get_pdev_same_bus(u8 bus, u32 id) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 789 | { |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 790 | struct pci_dev *pdev = NULL; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 791 | |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 792 | do { |
| 793 | pdev = pci_get_device(PCI_VENDOR_ID_INTEL, id, pdev); |
| 794 | if (pdev && pdev->bus->number == bus) |
| 795 | break; |
| 796 | } while (pdev); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 797 | |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 798 | return pdev; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | /** |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 802 | * check_if_ecc_is_active() - Checks if ECC is active |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 803 | * @bus: Device bus |
| 804 | * @type: Memory controller type |
| 805 | * returns: 0 in case ECC is active, -ENODEV if it can't be determined or |
| 806 | * disabled |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 807 | */ |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 808 | static int check_if_ecc_is_active(const u8 bus, enum type type) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 809 | { |
| 810 | struct pci_dev *pdev = NULL; |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 811 | u32 mcmtr, id; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 812 | |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 813 | switch (type) { |
| 814 | case IVY_BRIDGE: |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 815 | id = PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA; |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 816 | break; |
| 817 | case HASWELL: |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 818 | id = PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TA; |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 819 | break; |
| 820 | case SANDY_BRIDGE: |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 821 | id = PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA; |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 822 | break; |
| 823 | case BROADWELL: |
| 824 | id = PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TA; |
| 825 | break; |
| 826 | default: |
| 827 | return -ENODEV; |
| 828 | } |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 829 | |
| 830 | pdev = get_pdev_same_bus(bus, id); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 831 | if (!pdev) { |
| 832 | sbridge_printk(KERN_ERR, "Couldn't find PCI device " |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 833 | "%04x:%04x! on bus %02d\n", |
| 834 | PCI_VENDOR_ID_INTEL, id, bus); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 835 | return -ENODEV; |
| 836 | } |
| 837 | |
| 838 | pci_read_config_dword(pdev, MCMTR, &mcmtr); |
| 839 | if (!IS_ECC_ENABLED(mcmtr)) { |
| 840 | sbridge_printk(KERN_ERR, "ECC is disabled. Aborting\n"); |
| 841 | return -ENODEV; |
| 842 | } |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 843 | return 0; |
| 844 | } |
| 845 | |
Mauro Carvalho Chehab | 084a4fc | 2012-01-27 18:38:08 -0300 | [diff] [blame] | 846 | static int get_dimm_config(struct mem_ctl_info *mci) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 847 | { |
| 848 | struct sbridge_pvt *pvt = mci->pvt_info; |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 849 | struct dimm_info *dimm; |
Mauro Carvalho Chehab | deb09dd | 2012-09-20 12:09:30 -0300 | [diff] [blame] | 850 | unsigned i, j, banks, ranks, rows, cols, npages; |
| 851 | u64 size; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 852 | u32 reg; |
| 853 | enum edac_type mode; |
Mark A. Grondona | c6e13b5 | 2011-10-18 11:02:58 -0200 | [diff] [blame] | 854 | enum mem_type mtype; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 855 | |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 856 | if (pvt->info.type == HASWELL || pvt->info.type == BROADWELL) |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 857 | pci_read_config_dword(pvt->pci_sad1, SAD_TARGET, ®); |
| 858 | else |
| 859 | pci_read_config_dword(pvt->pci_br0, SAD_TARGET, ®); |
| 860 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 861 | pvt->sbridge_dev->source_id = SOURCE_ID(reg); |
| 862 | |
Aristeu Rozanski | f14d689 | 2014-06-02 15:15:23 -0300 | [diff] [blame] | 863 | pvt->sbridge_dev->node_id = pvt->info.get_node_id(pvt); |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 864 | edac_dbg(0, "mc#%d: Node ID: %d, source ID: %d\n", |
| 865 | pvt->sbridge_dev->mc, |
| 866 | pvt->sbridge_dev->node_id, |
| 867 | pvt->sbridge_dev->source_id); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 868 | |
| 869 | pci_read_config_dword(pvt->pci_ras, RASENABLES, ®); |
| 870 | if (IS_MIRROR_ENABLED(reg)) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 871 | edac_dbg(0, "Memory mirror is enabled\n"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 872 | pvt->is_mirrored = true; |
| 873 | } else { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 874 | edac_dbg(0, "Memory mirror is disabled\n"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 875 | pvt->is_mirrored = false; |
| 876 | } |
| 877 | |
| 878 | pci_read_config_dword(pvt->pci_ta, MCMTR, &pvt->info.mcmtr); |
| 879 | if (IS_LOCKSTEP_ENABLED(pvt->info.mcmtr)) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 880 | edac_dbg(0, "Lockstep is enabled\n"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 881 | mode = EDAC_S8ECD8ED; |
| 882 | pvt->is_lockstep = true; |
| 883 | } else { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 884 | edac_dbg(0, "Lockstep is disabled\n"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 885 | mode = EDAC_S4ECD4ED; |
| 886 | pvt->is_lockstep = false; |
| 887 | } |
| 888 | if (IS_CLOSE_PG(pvt->info.mcmtr)) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 889 | edac_dbg(0, "address map is on closed page mode\n"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 890 | pvt->is_close_pg = true; |
| 891 | } else { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 892 | edac_dbg(0, "address map is on open page mode\n"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 893 | pvt->is_close_pg = false; |
| 894 | } |
| 895 | |
Aristeu Rozanski | 9e37544 | 2014-06-02 15:15:22 -0300 | [diff] [blame] | 896 | mtype = pvt->info.get_memory_type(pvt); |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 897 | if (mtype == MEM_RDDR3 || mtype == MEM_RDDR4) |
Aristeu Rozanski | 9e37544 | 2014-06-02 15:15:22 -0300 | [diff] [blame] | 898 | edac_dbg(0, "Memory is registered\n"); |
| 899 | else if (mtype == MEM_UNKNOWN) |
Luck, Tony | de4772c | 2013-03-28 09:59:15 -0700 | [diff] [blame] | 900 | edac_dbg(0, "Cannot determine memory type\n"); |
Aristeu Rozanski | 9e37544 | 2014-06-02 15:15:22 -0300 | [diff] [blame] | 901 | else |
| 902 | edac_dbg(0, "Memory is unregistered\n"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 903 | |
Tony Luck | fec53af | 2014-12-02 09:41:58 -0800 | [diff] [blame] | 904 | if (mtype == MEM_DDR4 || mtype == MEM_RDDR4) |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 905 | banks = 16; |
| 906 | else |
| 907 | banks = 8; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 908 | |
| 909 | for (i = 0; i < NUM_CHANNELS; i++) { |
| 910 | u32 mtr; |
| 911 | |
| 912 | for (j = 0; j < ARRAY_SIZE(mtr_regs); j++) { |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 913 | dimm = EDAC_DIMM_PTR(mci->layers, mci->dimms, mci->n_layers, |
| 914 | i, j, 0); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 915 | pci_read_config_dword(pvt->pci_tad[i], |
| 916 | mtr_regs[j], &mtr); |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 917 | edac_dbg(4, "Channel #%d MTR%d = %x\n", i, j, mtr); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 918 | if (IS_DIMM_PRESENT(mtr)) { |
| 919 | pvt->channel[i].dimms++; |
| 920 | |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 921 | ranks = numrank(pvt->info.type, mtr); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 922 | rows = numrow(mtr); |
| 923 | cols = numcol(mtr); |
| 924 | |
Mauro Carvalho Chehab | deb09dd | 2012-09-20 12:09:30 -0300 | [diff] [blame] | 925 | size = ((u64)rows * cols * banks * ranks) >> (20 - 3); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 926 | npages = MiB_TO_PAGES(size); |
| 927 | |
Mauro Carvalho Chehab | deb09dd | 2012-09-20 12:09:30 -0300 | [diff] [blame] | 928 | edac_dbg(0, "mc#%d: channel %d, dimm %d, %Ld Mb (%d pages) bank: %d, rank: %d, row: %#x, col: %#x\n", |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 929 | pvt->sbridge_dev->mc, i, j, |
| 930 | size, npages, |
| 931 | banks, ranks, rows, cols); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 932 | |
Mauro Carvalho Chehab | a895bf8 | 2012-01-28 09:09:38 -0300 | [diff] [blame] | 933 | dimm->nr_pages = npages; |
Mauro Carvalho Chehab | 084a4fc | 2012-01-27 18:38:08 -0300 | [diff] [blame] | 934 | dimm->grain = 32; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 935 | switch (banks) { |
| 936 | case 16: |
| 937 | dimm->dtype = DEV_X16; |
| 938 | break; |
| 939 | case 8: |
| 940 | dimm->dtype = DEV_X8; |
| 941 | break; |
| 942 | case 4: |
| 943 | dimm->dtype = DEV_X4; |
| 944 | break; |
| 945 | } |
Mauro Carvalho Chehab | 084a4fc | 2012-01-27 18:38:08 -0300 | [diff] [blame] | 946 | dimm->mtype = mtype; |
| 947 | dimm->edac_mode = mode; |
| 948 | snprintf(dimm->label, sizeof(dimm->label), |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 949 | "CPU_SrcID#%u_Channel#%u_DIMM#%u", |
| 950 | pvt->sbridge_dev->source_id, i, j); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 951 | } |
| 952 | } |
| 953 | } |
| 954 | |
| 955 | return 0; |
| 956 | } |
| 957 | |
| 958 | static void get_memory_layout(const struct mem_ctl_info *mci) |
| 959 | { |
| 960 | struct sbridge_pvt *pvt = mci->pvt_info; |
| 961 | int i, j, k, n_sads, n_tads, sad_interl; |
| 962 | u32 reg; |
| 963 | u64 limit, prv = 0; |
| 964 | u64 tmp_mb; |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 965 | u32 gb, mb; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 966 | u32 rir_way; |
| 967 | |
| 968 | /* |
| 969 | * Step 1) Get TOLM/TOHM ranges |
| 970 | */ |
| 971 | |
Aristeu Rozanski | fb79a50 | 2013-10-30 13:26:57 -0300 | [diff] [blame] | 972 | pvt->tolm = pvt->info.get_tolm(pvt); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 973 | tmp_mb = (1 + pvt->tolm) >> 20; |
| 974 | |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 975 | gb = div_u64_rem(tmp_mb, 1024, &mb); |
| 976 | edac_dbg(0, "TOLM: %u.%03u GB (0x%016Lx)\n", |
| 977 | gb, (mb*1000)/1024, (u64)pvt->tolm); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 978 | |
| 979 | /* Address range is already 45:25 */ |
Aristeu Rozanski | 8fd6a43 | 2013-10-30 13:26:59 -0300 | [diff] [blame] | 980 | pvt->tohm = pvt->info.get_tohm(pvt); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 981 | tmp_mb = (1 + pvt->tohm) >> 20; |
| 982 | |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 983 | gb = div_u64_rem(tmp_mb, 1024, &mb); |
| 984 | edac_dbg(0, "TOHM: %u.%03u GB (0x%016Lx)\n", |
| 985 | gb, (mb*1000)/1024, (u64)pvt->tohm); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 986 | |
| 987 | /* |
| 988 | * Step 2) Get SAD range and SAD Interleave list |
| 989 | * TAD registers contain the interleave wayness. However, it |
| 990 | * seems simpler to just discover it indirectly, with the |
| 991 | * algorithm bellow. |
| 992 | */ |
| 993 | prv = 0; |
Aristeu Rozanski | 464f1d8 | 2013-10-30 13:27:00 -0300 | [diff] [blame] | 994 | 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] | 995 | /* SAD_LIMIT Address range is 45:26 */ |
Aristeu Rozanski | 464f1d8 | 2013-10-30 13:27:00 -0300 | [diff] [blame] | 996 | 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] | 997 | ®); |
| 998 | limit = SAD_LIMIT(reg); |
| 999 | |
| 1000 | if (!DRAM_RULE_ENABLE(reg)) |
| 1001 | continue; |
| 1002 | |
| 1003 | if (limit <= prv) |
| 1004 | break; |
| 1005 | |
| 1006 | tmp_mb = (limit + 1) >> 20; |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 1007 | gb = div_u64_rem(tmp_mb, 1024, &mb); |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1008 | edac_dbg(0, "SAD#%d %s up to %u.%03u GB (0x%016Lx) Interleave: %s reg=0x%08x\n", |
| 1009 | n_sads, |
| 1010 | get_dram_attr(reg), |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 1011 | gb, (mb*1000)/1024, |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1012 | ((u64)tmp_mb) << 20L, |
| 1013 | INTERLEAVE_MODE(reg) ? "8:6" : "[8:6]XOR[18:16]", |
| 1014 | reg); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1015 | prv = limit; |
| 1016 | |
Aristeu Rozanski | ef1ce51 | 2013-10-30 13:27:01 -0300 | [diff] [blame] | 1017 | 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] | 1018 | ®); |
Aristeu Rozanski | cc31199 | 2013-10-30 13:27:02 -0300 | [diff] [blame] | 1019 | sad_interl = sad_pkg(pvt->info.interleave_pkg, reg, 0); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1020 | for (j = 0; j < 8; j++) { |
Aristeu Rozanski | cc31199 | 2013-10-30 13:27:02 -0300 | [diff] [blame] | 1021 | u32 pkg = sad_pkg(pvt->info.interleave_pkg, reg, j); |
| 1022 | if (j > 0 && sad_interl == pkg) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1023 | break; |
| 1024 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1025 | edac_dbg(0, "SAD#%d, interleave #%d: %d\n", |
Aristeu Rozanski | cc31199 | 2013-10-30 13:27:02 -0300 | [diff] [blame] | 1026 | n_sads, j, pkg); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1027 | } |
| 1028 | } |
| 1029 | |
| 1030 | /* |
| 1031 | * Step 3) Get TAD range |
| 1032 | */ |
| 1033 | prv = 0; |
| 1034 | for (n_tads = 0; n_tads < MAX_TAD; n_tads++) { |
| 1035 | pci_read_config_dword(pvt->pci_ha0, tad_dram_rule[n_tads], |
| 1036 | ®); |
| 1037 | limit = TAD_LIMIT(reg); |
| 1038 | if (limit <= prv) |
| 1039 | break; |
| 1040 | tmp_mb = (limit + 1) >> 20; |
| 1041 | |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 1042 | gb = div_u64_rem(tmp_mb, 1024, &mb); |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1043 | 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] | 1044 | n_tads, gb, (mb*1000)/1024, |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1045 | ((u64)tmp_mb) << 20L, |
| 1046 | (u32)TAD_SOCK(reg), |
| 1047 | (u32)TAD_CH(reg), |
| 1048 | (u32)TAD_TGT0(reg), |
| 1049 | (u32)TAD_TGT1(reg), |
| 1050 | (u32)TAD_TGT2(reg), |
| 1051 | (u32)TAD_TGT3(reg), |
| 1052 | reg); |
Hui Wang | 7fae0db | 2012-02-06 04:11:01 -0300 | [diff] [blame] | 1053 | prv = limit; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | /* |
| 1057 | * Step 4) Get TAD offsets, per each channel |
| 1058 | */ |
| 1059 | for (i = 0; i < NUM_CHANNELS; i++) { |
| 1060 | if (!pvt->channel[i].dimms) |
| 1061 | continue; |
| 1062 | for (j = 0; j < n_tads; j++) { |
| 1063 | pci_read_config_dword(pvt->pci_tad[i], |
| 1064 | tad_ch_nilv_offset[j], |
| 1065 | ®); |
| 1066 | tmp_mb = TAD_OFFSET(reg) >> 20; |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 1067 | gb = div_u64_rem(tmp_mb, 1024, &mb); |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1068 | edac_dbg(0, "TAD CH#%d, offset #%d: %u.%03u GB (0x%016Lx), reg=0x%08x\n", |
| 1069 | i, j, |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 1070 | gb, (mb*1000)/1024, |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1071 | ((u64)tmp_mb) << 20L, |
| 1072 | reg); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1073 | } |
| 1074 | } |
| 1075 | |
| 1076 | /* |
| 1077 | * Step 6) Get RIR Wayness/Limit, per each channel |
| 1078 | */ |
| 1079 | for (i = 0; i < NUM_CHANNELS; i++) { |
| 1080 | if (!pvt->channel[i].dimms) |
| 1081 | continue; |
| 1082 | for (j = 0; j < MAX_RIR_RANGES; j++) { |
| 1083 | pci_read_config_dword(pvt->pci_tad[i], |
| 1084 | rir_way_limit[j], |
| 1085 | ®); |
| 1086 | |
| 1087 | if (!IS_RIR_VALID(reg)) |
| 1088 | continue; |
| 1089 | |
Aristeu Rozanski | b976bcf | 2014-06-02 15:15:24 -0300 | [diff] [blame] | 1090 | tmp_mb = pvt->info.rir_limit(reg) >> 20; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1091 | rir_way = 1 << RIR_WAY(reg); |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 1092 | gb = div_u64_rem(tmp_mb, 1024, &mb); |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1093 | edac_dbg(0, "CH#%d RIR#%d, limit: %u.%03u GB (0x%016Lx), way: %d, reg=0x%08x\n", |
| 1094 | i, j, |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 1095 | gb, (mb*1000)/1024, |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1096 | ((u64)tmp_mb) << 20L, |
| 1097 | rir_way, |
| 1098 | reg); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1099 | |
| 1100 | for (k = 0; k < rir_way; k++) { |
| 1101 | pci_read_config_dword(pvt->pci_tad[i], |
| 1102 | rir_offset[j][k], |
| 1103 | ®); |
| 1104 | tmp_mb = RIR_OFFSET(reg) << 6; |
| 1105 | |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 1106 | gb = div_u64_rem(tmp_mb, 1024, &mb); |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1107 | edac_dbg(0, "CH#%d RIR#%d INTL#%d, offset %u.%03u GB (0x%016Lx), tgt: %d, reg=0x%08x\n", |
| 1108 | i, j, k, |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 1109 | gb, (mb*1000)/1024, |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1110 | ((u64)tmp_mb) << 20L, |
| 1111 | (u32)RIR_RNK_TGT(reg), |
| 1112 | reg); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1113 | } |
| 1114 | } |
| 1115 | } |
| 1116 | } |
| 1117 | |
Rashika Kheria | 8112c0c | 2013-12-14 19:32:09 +0530 | [diff] [blame] | 1118 | static struct mem_ctl_info *get_mci_for_node_id(u8 node_id) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1119 | { |
| 1120 | struct sbridge_dev *sbridge_dev; |
| 1121 | |
| 1122 | list_for_each_entry(sbridge_dev, &sbridge_edac_list, list) { |
| 1123 | if (sbridge_dev->node_id == node_id) |
| 1124 | return sbridge_dev->mci; |
| 1125 | } |
| 1126 | return NULL; |
| 1127 | } |
| 1128 | |
| 1129 | static int get_memory_error_data(struct mem_ctl_info *mci, |
| 1130 | u64 addr, |
| 1131 | u8 *socket, |
| 1132 | long *channel_mask, |
| 1133 | u8 *rank, |
Mauro Carvalho Chehab | e17a2f42a | 2012-05-11 11:41:45 -0300 | [diff] [blame] | 1134 | char **area_type, char *msg) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1135 | { |
| 1136 | struct mem_ctl_info *new_mci; |
| 1137 | struct sbridge_pvt *pvt = mci->pvt_info; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 1138 | struct pci_dev *pci_ha; |
Mauro Carvalho Chehab | c41afdc | 2014-06-26 15:35:14 -0300 | [diff] [blame] | 1139 | int n_rir, n_sads, n_tads, sad_way, sck_xch; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1140 | int sad_interl, idx, base_ch; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 1141 | int interleave_mode, shiftup = 0; |
Aristeu Rozanski | ef1ce51 | 2013-10-30 13:27:01 -0300 | [diff] [blame] | 1142 | unsigned sad_interleave[pvt->info.max_interleave]; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 1143 | u32 reg, dram_rule; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 1144 | u8 ch_way, sck_way, pkg, sad_ha = 0; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1145 | u32 tad_offset; |
| 1146 | u32 rir_way; |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 1147 | u32 mb, gb; |
Aristeu Rozanski | bd4b968 | 2013-11-21 09:08:03 -0500 | [diff] [blame] | 1148 | u64 ch_addr, offset, limit = 0, prv = 0; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1149 | |
| 1150 | |
| 1151 | /* |
| 1152 | * Step 0) Check if the address is at special memory ranges |
| 1153 | * The check bellow is probably enough to fill all cases where |
| 1154 | * the error is not inside a memory, except for the legacy |
| 1155 | * range (e. g. VGA addresses). It is unlikely, however, that the |
| 1156 | * memory controller would generate an error on that range. |
| 1157 | */ |
Mauro Carvalho Chehab | 5b889e3 | 2011-11-07 18:26:53 -0300 | [diff] [blame] | 1158 | if ((addr > (u64) pvt->tolm) && (addr < (1LL << 32))) { |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1159 | sprintf(msg, "Error at TOLM area, on addr 0x%08Lx", addr); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1160 | return -EINVAL; |
| 1161 | } |
| 1162 | if (addr >= (u64)pvt->tohm) { |
| 1163 | sprintf(msg, "Error at MMIOH area, on addr 0x%016Lx", addr); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1164 | return -EINVAL; |
| 1165 | } |
| 1166 | |
| 1167 | /* |
| 1168 | * Step 1) Get socket |
| 1169 | */ |
Aristeu Rozanski | 464f1d8 | 2013-10-30 13:27:00 -0300 | [diff] [blame] | 1170 | for (n_sads = 0; n_sads < pvt->info.max_sad; n_sads++) { |
| 1171 | 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] | 1172 | ®); |
| 1173 | |
| 1174 | if (!DRAM_RULE_ENABLE(reg)) |
| 1175 | continue; |
| 1176 | |
| 1177 | limit = SAD_LIMIT(reg); |
| 1178 | if (limit <= prv) { |
| 1179 | sprintf(msg, "Can't discover the memory socket"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1180 | return -EINVAL; |
| 1181 | } |
| 1182 | if (addr <= limit) |
| 1183 | break; |
| 1184 | prv = limit; |
| 1185 | } |
Aristeu Rozanski | 464f1d8 | 2013-10-30 13:27:00 -0300 | [diff] [blame] | 1186 | if (n_sads == pvt->info.max_sad) { |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1187 | sprintf(msg, "Can't discover the memory socket"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1188 | return -EINVAL; |
| 1189 | } |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 1190 | dram_rule = reg; |
| 1191 | *area_type = get_dram_attr(dram_rule); |
| 1192 | interleave_mode = INTERLEAVE_MODE(dram_rule); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1193 | |
Aristeu Rozanski | ef1ce51 | 2013-10-30 13:27:01 -0300 | [diff] [blame] | 1194 | 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] | 1195 | ®); |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 1196 | |
| 1197 | if (pvt->info.type == SANDY_BRIDGE) { |
| 1198 | sad_interl = sad_pkg(pvt->info.interleave_pkg, reg, 0); |
| 1199 | for (sad_way = 0; sad_way < 8; sad_way++) { |
| 1200 | u32 pkg = sad_pkg(pvt->info.interleave_pkg, reg, sad_way); |
| 1201 | if (sad_way > 0 && sad_interl == pkg) |
| 1202 | break; |
| 1203 | sad_interleave[sad_way] = pkg; |
| 1204 | edac_dbg(0, "SAD interleave #%d: %d\n", |
| 1205 | sad_way, sad_interleave[sad_way]); |
| 1206 | } |
| 1207 | edac_dbg(0, "mc#%d: Error detected on SAD#%d: address 0x%016Lx < 0x%016Lx, Interleave [%d:6]%s\n", |
| 1208 | pvt->sbridge_dev->mc, |
| 1209 | n_sads, |
| 1210 | addr, |
| 1211 | limit, |
| 1212 | sad_way + 7, |
| 1213 | !interleave_mode ? "" : "XOR[18:16]"); |
| 1214 | if (interleave_mode) |
| 1215 | idx = ((addr >> 6) ^ (addr >> 16)) & 7; |
| 1216 | else |
| 1217 | idx = (addr >> 6) & 7; |
| 1218 | switch (sad_way) { |
| 1219 | case 1: |
| 1220 | idx = 0; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1221 | break; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 1222 | case 2: |
| 1223 | idx = idx & 1; |
| 1224 | break; |
| 1225 | case 4: |
| 1226 | idx = idx & 3; |
| 1227 | break; |
| 1228 | case 8: |
| 1229 | break; |
| 1230 | default: |
| 1231 | sprintf(msg, "Can't discover socket interleave"); |
| 1232 | return -EINVAL; |
| 1233 | } |
| 1234 | *socket = sad_interleave[idx]; |
| 1235 | edac_dbg(0, "SAD interleave index: %d (wayness %d) = CPU socket %d\n", |
| 1236 | idx, sad_way, *socket); |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 1237 | } else if (pvt->info.type == HASWELL || pvt->info.type == BROADWELL) { |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 1238 | int bits, a7mode = A7MODE(dram_rule); |
| 1239 | |
| 1240 | if (a7mode) { |
| 1241 | /* A7 mode swaps P9 with P6 */ |
| 1242 | bits = GET_BITFIELD(addr, 7, 8) << 1; |
| 1243 | bits |= GET_BITFIELD(addr, 9, 9); |
| 1244 | } else |
| 1245 | bits = GET_BITFIELD(addr, 7, 9); |
| 1246 | |
| 1247 | if (interleave_mode) { |
| 1248 | /* interleave mode will XOR {8,7,6} with {18,17,16} */ |
| 1249 | idx = GET_BITFIELD(addr, 16, 18); |
| 1250 | idx ^= bits; |
| 1251 | } else |
| 1252 | idx = bits; |
| 1253 | |
| 1254 | pkg = sad_pkg(pvt->info.interleave_pkg, reg, idx); |
| 1255 | *socket = sad_pkg_socket(pkg); |
| 1256 | sad_ha = sad_pkg_ha(pkg); |
| 1257 | |
| 1258 | if (a7mode) { |
| 1259 | /* MCChanShiftUpEnable */ |
| 1260 | pci_read_config_dword(pvt->pci_ha0, |
| 1261 | HASWELL_HASYSDEFEATURE2, ®); |
| 1262 | shiftup = GET_BITFIELD(reg, 22, 22); |
| 1263 | } |
| 1264 | |
| 1265 | edac_dbg(0, "SAD interleave package: %d = CPU socket %d, HA %i, shiftup: %i\n", |
| 1266 | idx, *socket, sad_ha, shiftup); |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 1267 | } else { |
| 1268 | /* Ivy Bridge's SAD mode doesn't support XOR interleave mode */ |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1269 | idx = (addr >> 6) & 7; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 1270 | pkg = sad_pkg(pvt->info.interleave_pkg, reg, idx); |
| 1271 | *socket = sad_pkg_socket(pkg); |
| 1272 | sad_ha = sad_pkg_ha(pkg); |
| 1273 | edac_dbg(0, "SAD interleave package: %d = CPU socket %d, HA %d\n", |
| 1274 | idx, *socket, sad_ha); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1275 | } |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1276 | |
| 1277 | /* |
| 1278 | * Move to the proper node structure, in order to access the |
| 1279 | * right PCI registers |
| 1280 | */ |
| 1281 | new_mci = get_mci_for_node_id(*socket); |
| 1282 | if (!new_mci) { |
| 1283 | sprintf(msg, "Struct for socket #%u wasn't initialized", |
| 1284 | *socket); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1285 | return -EINVAL; |
| 1286 | } |
| 1287 | mci = new_mci; |
| 1288 | pvt = mci->pvt_info; |
| 1289 | |
| 1290 | /* |
| 1291 | * Step 2) Get memory channel |
| 1292 | */ |
| 1293 | prv = 0; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 1294 | if (pvt->info.type == SANDY_BRIDGE) |
| 1295 | pci_ha = pvt->pci_ha0; |
| 1296 | else { |
| 1297 | if (sad_ha) |
| 1298 | pci_ha = pvt->pci_ha1; |
| 1299 | else |
| 1300 | pci_ha = pvt->pci_ha0; |
| 1301 | } |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1302 | for (n_tads = 0; n_tads < MAX_TAD; n_tads++) { |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 1303 | pci_read_config_dword(pci_ha, tad_dram_rule[n_tads], ®); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1304 | limit = TAD_LIMIT(reg); |
| 1305 | if (limit <= prv) { |
| 1306 | sprintf(msg, "Can't discover the memory channel"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1307 | return -EINVAL; |
| 1308 | } |
| 1309 | if (addr <= limit) |
| 1310 | break; |
| 1311 | prv = limit; |
| 1312 | } |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 1313 | if (n_tads == MAX_TAD) { |
| 1314 | sprintf(msg, "Can't discover the memory channel"); |
| 1315 | return -EINVAL; |
| 1316 | } |
| 1317 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1318 | ch_way = TAD_CH(reg) + 1; |
| 1319 | sck_way = TAD_SOCK(reg) + 1; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1320 | |
| 1321 | if (ch_way == 3) |
| 1322 | idx = addr >> 6; |
| 1323 | else |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 1324 | idx = (addr >> (6 + sck_way + shiftup)) & 0x3; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1325 | idx = idx % ch_way; |
| 1326 | |
| 1327 | /* |
| 1328 | * FIXME: Shouldn't we use CHN_IDX_OFFSET() here, when ch_way == 3 ??? |
| 1329 | */ |
| 1330 | switch (idx) { |
| 1331 | case 0: |
| 1332 | base_ch = TAD_TGT0(reg); |
| 1333 | break; |
| 1334 | case 1: |
| 1335 | base_ch = TAD_TGT1(reg); |
| 1336 | break; |
| 1337 | case 2: |
| 1338 | base_ch = TAD_TGT2(reg); |
| 1339 | break; |
| 1340 | case 3: |
| 1341 | base_ch = TAD_TGT3(reg); |
| 1342 | break; |
| 1343 | default: |
| 1344 | sprintf(msg, "Can't discover the TAD target"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1345 | return -EINVAL; |
| 1346 | } |
| 1347 | *channel_mask = 1 << base_ch; |
| 1348 | |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 1349 | pci_read_config_dword(pvt->pci_tad[base_ch], |
| 1350 | tad_ch_nilv_offset[n_tads], |
| 1351 | &tad_offset); |
| 1352 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1353 | if (pvt->is_mirrored) { |
| 1354 | *channel_mask |= 1 << ((base_ch + 2) % 4); |
| 1355 | switch(ch_way) { |
| 1356 | case 2: |
| 1357 | case 4: |
| 1358 | sck_xch = 1 << sck_way * (ch_way >> 1); |
| 1359 | break; |
| 1360 | default: |
| 1361 | sprintf(msg, "Invalid mirror set. Can't decode addr"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1362 | return -EINVAL; |
| 1363 | } |
| 1364 | } else |
| 1365 | sck_xch = (1 << sck_way) * ch_way; |
| 1366 | |
| 1367 | if (pvt->is_lockstep) |
| 1368 | *channel_mask |= 1 << ((base_ch + 1) % 4); |
| 1369 | |
| 1370 | offset = TAD_OFFSET(tad_offset); |
| 1371 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1372 | 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", |
| 1373 | n_tads, |
| 1374 | addr, |
| 1375 | limit, |
| 1376 | (u32)TAD_SOCK(reg), |
| 1377 | ch_way, |
| 1378 | offset, |
| 1379 | idx, |
| 1380 | base_ch, |
| 1381 | *channel_mask); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1382 | |
| 1383 | /* Calculate channel address */ |
| 1384 | /* Remove the TAD offset */ |
| 1385 | |
| 1386 | if (offset > addr) { |
| 1387 | sprintf(msg, "Can't calculate ch addr: TAD offset 0x%08Lx is too high for addr 0x%08Lx!", |
| 1388 | offset, addr); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1389 | return -EINVAL; |
| 1390 | } |
| 1391 | addr -= offset; |
| 1392 | /* Store the low bits [0:6] of the addr */ |
| 1393 | ch_addr = addr & 0x7f; |
| 1394 | /* Remove socket wayness and remove 6 bits */ |
| 1395 | addr >>= 6; |
Mauro Carvalho Chehab | 5b889e3 | 2011-11-07 18:26:53 -0300 | [diff] [blame] | 1396 | addr = div_u64(addr, sck_xch); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1397 | #if 0 |
| 1398 | /* Divide by channel way */ |
| 1399 | addr = addr / ch_way; |
| 1400 | #endif |
| 1401 | /* Recover the last 6 bits */ |
| 1402 | ch_addr |= addr << 6; |
| 1403 | |
| 1404 | /* |
| 1405 | * Step 3) Decode rank |
| 1406 | */ |
| 1407 | for (n_rir = 0; n_rir < MAX_RIR_RANGES; n_rir++) { |
| 1408 | pci_read_config_dword(pvt->pci_tad[base_ch], |
| 1409 | rir_way_limit[n_rir], |
| 1410 | ®); |
| 1411 | |
| 1412 | if (!IS_RIR_VALID(reg)) |
| 1413 | continue; |
| 1414 | |
Aristeu Rozanski | b976bcf | 2014-06-02 15:15:24 -0300 | [diff] [blame] | 1415 | limit = pvt->info.rir_limit(reg); |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 1416 | gb = div_u64_rem(limit >> 20, 1024, &mb); |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1417 | edac_dbg(0, "RIR#%d, limit: %u.%03u GB (0x%016Lx), way: %d\n", |
| 1418 | n_rir, |
Jim Snow | 8c00910 | 2014-11-18 14:51:09 +0100 | [diff] [blame] | 1419 | gb, (mb*1000)/1024, |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1420 | limit, |
| 1421 | 1 << RIR_WAY(reg)); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1422 | if (ch_addr <= limit) |
| 1423 | break; |
| 1424 | } |
| 1425 | if (n_rir == MAX_RIR_RANGES) { |
| 1426 | sprintf(msg, "Can't discover the memory rank for ch addr 0x%08Lx", |
| 1427 | ch_addr); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1428 | return -EINVAL; |
| 1429 | } |
| 1430 | rir_way = RIR_WAY(reg); |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 1431 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1432 | if (pvt->is_close_pg) |
| 1433 | idx = (ch_addr >> 6); |
| 1434 | else |
| 1435 | idx = (ch_addr >> 13); /* FIXME: Datasheet says to shift by 15 */ |
| 1436 | idx %= 1 << rir_way; |
| 1437 | |
| 1438 | pci_read_config_dword(pvt->pci_tad[base_ch], |
| 1439 | rir_offset[n_rir][idx], |
| 1440 | ®); |
| 1441 | *rank = RIR_RNK_TGT(reg); |
| 1442 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1443 | edac_dbg(0, "RIR#%d: channel address 0x%08Lx < 0x%08Lx, RIR interleave %d, index %d\n", |
| 1444 | n_rir, |
| 1445 | ch_addr, |
| 1446 | limit, |
| 1447 | rir_way, |
| 1448 | idx); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1449 | |
| 1450 | return 0; |
| 1451 | } |
| 1452 | |
| 1453 | /**************************************************************************** |
| 1454 | Device initialization routines: put/get, init/exit |
| 1455 | ****************************************************************************/ |
| 1456 | |
| 1457 | /* |
| 1458 | * sbridge_put_all_devices 'put' all the devices that we have |
| 1459 | * reserved via 'get' |
| 1460 | */ |
| 1461 | static void sbridge_put_devices(struct sbridge_dev *sbridge_dev) |
| 1462 | { |
| 1463 | int i; |
| 1464 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1465 | edac_dbg(0, "\n"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1466 | for (i = 0; i < sbridge_dev->n_devs; i++) { |
| 1467 | struct pci_dev *pdev = sbridge_dev->pdev[i]; |
| 1468 | if (!pdev) |
| 1469 | continue; |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1470 | edac_dbg(0, "Removing dev %02x:%02x.%d\n", |
| 1471 | pdev->bus->number, |
| 1472 | PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1473 | pci_dev_put(pdev); |
| 1474 | } |
| 1475 | } |
| 1476 | |
| 1477 | static void sbridge_put_all_devices(void) |
| 1478 | { |
| 1479 | struct sbridge_dev *sbridge_dev, *tmp; |
| 1480 | |
| 1481 | list_for_each_entry_safe(sbridge_dev, tmp, &sbridge_edac_list, list) { |
| 1482 | sbridge_put_devices(sbridge_dev); |
| 1483 | free_sbridge_dev(sbridge_dev); |
| 1484 | } |
| 1485 | } |
| 1486 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1487 | static int sbridge_get_onedevice(struct pci_dev **prev, |
| 1488 | u8 *num_mc, |
| 1489 | const struct pci_id_table *table, |
| 1490 | const unsigned devno) |
| 1491 | { |
| 1492 | struct sbridge_dev *sbridge_dev; |
| 1493 | const struct pci_id_descr *dev_descr = &table->descr[devno]; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1494 | struct pci_dev *pdev = NULL; |
| 1495 | u8 bus = 0; |
| 1496 | |
Jiang Liu | ec5a0b3 | 2014-02-17 13:10:23 +0800 | [diff] [blame] | 1497 | sbridge_printk(KERN_DEBUG, |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1498 | "Seeking for: PCI ID %04x:%04x\n", |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1499 | PCI_VENDOR_ID_INTEL, dev_descr->dev_id); |
| 1500 | |
| 1501 | pdev = pci_get_device(PCI_VENDOR_ID_INTEL, |
| 1502 | dev_descr->dev_id, *prev); |
| 1503 | |
| 1504 | if (!pdev) { |
| 1505 | if (*prev) { |
| 1506 | *prev = pdev; |
| 1507 | return 0; |
| 1508 | } |
| 1509 | |
| 1510 | if (dev_descr->optional) |
| 1511 | return 0; |
| 1512 | |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1513 | /* if the HA wasn't found */ |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1514 | if (devno == 0) |
| 1515 | return -ENODEV; |
| 1516 | |
| 1517 | sbridge_printk(KERN_INFO, |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1518 | "Device not found: %04x:%04x\n", |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1519 | PCI_VENDOR_ID_INTEL, dev_descr->dev_id); |
| 1520 | |
| 1521 | /* End of list, leave */ |
| 1522 | return -ENODEV; |
| 1523 | } |
| 1524 | bus = pdev->bus->number; |
| 1525 | |
| 1526 | sbridge_dev = get_sbridge_dev(bus); |
| 1527 | if (!sbridge_dev) { |
| 1528 | sbridge_dev = alloc_sbridge_dev(bus, table); |
| 1529 | if (!sbridge_dev) { |
| 1530 | pci_dev_put(pdev); |
| 1531 | return -ENOMEM; |
| 1532 | } |
| 1533 | (*num_mc)++; |
| 1534 | } |
| 1535 | |
| 1536 | if (sbridge_dev->pdev[devno]) { |
| 1537 | sbridge_printk(KERN_ERR, |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1538 | "Duplicated device for %04x:%04x\n", |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1539 | PCI_VENDOR_ID_INTEL, dev_descr->dev_id); |
| 1540 | pci_dev_put(pdev); |
| 1541 | return -ENODEV; |
| 1542 | } |
| 1543 | |
| 1544 | sbridge_dev->pdev[devno] = pdev; |
| 1545 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1546 | /* Be sure that the device is enabled */ |
| 1547 | if (unlikely(pci_enable_device(pdev) < 0)) { |
| 1548 | sbridge_printk(KERN_ERR, |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1549 | "Couldn't enable %04x:%04x\n", |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1550 | PCI_VENDOR_ID_INTEL, dev_descr->dev_id); |
| 1551 | return -ENODEV; |
| 1552 | } |
| 1553 | |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1554 | edac_dbg(0, "Detected %04x:%04x\n", |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1555 | PCI_VENDOR_ID_INTEL, dev_descr->dev_id); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1556 | |
| 1557 | /* |
| 1558 | * As stated on drivers/pci/search.c, the reference count for |
| 1559 | * @from is always decremented if it is not %NULL. So, as we need |
| 1560 | * to get all devices up to null, we need to do a get for the device |
| 1561 | */ |
| 1562 | pci_dev_get(pdev); |
| 1563 | |
| 1564 | *prev = pdev; |
| 1565 | |
| 1566 | return 0; |
| 1567 | } |
| 1568 | |
Aristeu Rozanski | 5153a0f | 2013-10-30 13:27:03 -0300 | [diff] [blame] | 1569 | /* |
| 1570 | * 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] | 1571 | * devices we want to reference for this driver. |
Aristeu Rozanski | 5153a0f | 2013-10-30 13:27:03 -0300 | [diff] [blame] | 1572 | * @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] | 1573 | * of success. |
Aristeu Rozanski | 5153a0f | 2013-10-30 13:27:03 -0300 | [diff] [blame] | 1574 | * @table: model specific table |
| 1575 | * |
| 1576 | * returns 0 in case of success or error code |
| 1577 | */ |
| 1578 | static int sbridge_get_all_devices(u8 *num_mc, |
| 1579 | const struct pci_id_table *table) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1580 | { |
| 1581 | int i, rc; |
| 1582 | struct pci_dev *pdev = NULL; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1583 | |
| 1584 | while (table && table->descr) { |
| 1585 | for (i = 0; i < table->n_devs; i++) { |
| 1586 | pdev = NULL; |
| 1587 | do { |
| 1588 | rc = sbridge_get_onedevice(&pdev, num_mc, |
| 1589 | table, i); |
| 1590 | if (rc < 0) { |
| 1591 | if (i == 0) { |
| 1592 | i = table->n_devs; |
| 1593 | break; |
| 1594 | } |
| 1595 | sbridge_put_all_devices(); |
| 1596 | return -ENODEV; |
| 1597 | } |
| 1598 | } while (pdev); |
| 1599 | } |
| 1600 | table++; |
| 1601 | } |
| 1602 | |
| 1603 | return 0; |
| 1604 | } |
| 1605 | |
Aristeu Rozanski | ea779b5 | 2013-10-30 13:27:04 -0300 | [diff] [blame] | 1606 | static int sbridge_mci_bind_devs(struct mem_ctl_info *mci, |
| 1607 | struct sbridge_dev *sbridge_dev) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1608 | { |
| 1609 | struct sbridge_pvt *pvt = mci->pvt_info; |
| 1610 | struct pci_dev *pdev; |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1611 | int i; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1612 | |
| 1613 | for (i = 0; i < sbridge_dev->n_devs; i++) { |
| 1614 | pdev = sbridge_dev->pdev[i]; |
| 1615 | if (!pdev) |
| 1616 | continue; |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1617 | |
| 1618 | switch (pdev->device) { |
| 1619 | case PCI_DEVICE_ID_INTEL_SBRIDGE_SAD0: |
| 1620 | pvt->pci_sad0 = pdev; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1621 | break; |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1622 | case PCI_DEVICE_ID_INTEL_SBRIDGE_SAD1: |
| 1623 | pvt->pci_sad1 = pdev; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1624 | break; |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1625 | case PCI_DEVICE_ID_INTEL_SBRIDGE_BR: |
| 1626 | pvt->pci_br0 = pdev; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1627 | break; |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1628 | case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_HA0: |
| 1629 | pvt->pci_ha0 = pdev; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1630 | break; |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1631 | case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA: |
| 1632 | pvt->pci_ta = pdev; |
| 1633 | break; |
| 1634 | case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_RAS: |
| 1635 | pvt->pci_ras = pdev; |
| 1636 | break; |
| 1637 | case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD0: |
| 1638 | case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD1: |
| 1639 | case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD2: |
| 1640 | case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD3: |
| 1641 | { |
| 1642 | int id = pdev->device - PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD0; |
| 1643 | pvt->pci_tad[id] = pdev; |
| 1644 | } |
| 1645 | break; |
| 1646 | case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_DDRIO: |
| 1647 | pvt->pci_ddrio = pdev; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1648 | break; |
| 1649 | default: |
| 1650 | goto error; |
| 1651 | } |
| 1652 | |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1653 | edac_dbg(0, "Associated PCI %02x:%02x, bus %d with dev = %p\n", |
| 1654 | pdev->vendor, pdev->device, |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1655 | sbridge_dev->bus, |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1656 | pdev); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | /* Check if everything were registered */ |
| 1660 | if (!pvt->pci_sad0 || !pvt->pci_sad1 || !pvt->pci_ha0 || |
Luck, Tony | de4772c | 2013-03-28 09:59:15 -0700 | [diff] [blame] | 1661 | !pvt-> pci_tad || !pvt->pci_ras || !pvt->pci_ta) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1662 | goto enodev; |
| 1663 | |
| 1664 | for (i = 0; i < NUM_CHANNELS; i++) { |
| 1665 | if (!pvt->pci_tad[i]) |
| 1666 | goto enodev; |
| 1667 | } |
| 1668 | return 0; |
| 1669 | |
| 1670 | enodev: |
| 1671 | sbridge_printk(KERN_ERR, "Some needed devices are missing\n"); |
| 1672 | return -ENODEV; |
| 1673 | |
| 1674 | error: |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1675 | sbridge_printk(KERN_ERR, "Unexpected device %02x:%02x\n", |
| 1676 | PCI_VENDOR_ID_INTEL, pdev->device); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1677 | return -EINVAL; |
| 1678 | } |
| 1679 | |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 1680 | static int ibridge_mci_bind_devs(struct mem_ctl_info *mci, |
| 1681 | struct sbridge_dev *sbridge_dev) |
| 1682 | { |
| 1683 | struct sbridge_pvt *pvt = mci->pvt_info; |
| 1684 | struct pci_dev *pdev, *tmp; |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1685 | int i; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 1686 | bool mode_2ha = false; |
| 1687 | |
| 1688 | tmp = pci_get_device(PCI_VENDOR_ID_INTEL, |
| 1689 | PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1, NULL); |
| 1690 | if (tmp) { |
| 1691 | mode_2ha = true; |
| 1692 | pci_dev_put(tmp); |
| 1693 | } |
| 1694 | |
| 1695 | for (i = 0; i < sbridge_dev->n_devs; i++) { |
| 1696 | pdev = sbridge_dev->pdev[i]; |
| 1697 | if (!pdev) |
| 1698 | continue; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 1699 | |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1700 | switch (pdev->device) { |
| 1701 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0: |
| 1702 | pvt->pci_ha0 = pdev; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 1703 | break; |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1704 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA: |
| 1705 | pvt->pci_ta = pdev; |
| 1706 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_RAS: |
| 1707 | pvt->pci_ras = pdev; |
| 1708 | break; |
| 1709 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD2: |
| 1710 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD3: |
| 1711 | /* if we have 2 HAs active, channels 2 and 3 |
| 1712 | * are in other device */ |
| 1713 | if (mode_2ha) |
| 1714 | break; |
| 1715 | /* fall through */ |
| 1716 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD0: |
| 1717 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD1: |
| 1718 | { |
| 1719 | int id = pdev->device - PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD0; |
| 1720 | pvt->pci_tad[id] = pdev; |
| 1721 | } |
| 1722 | break; |
| 1723 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_2HA_DDRIO0: |
| 1724 | pvt->pci_ddrio = pdev; |
| 1725 | break; |
| 1726 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_1HA_DDRIO0: |
| 1727 | if (!mode_2ha) |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 1728 | pvt->pci_ddrio = pdev; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 1729 | break; |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1730 | case PCI_DEVICE_ID_INTEL_IBRIDGE_SAD: |
| 1731 | pvt->pci_sad0 = pdev; |
| 1732 | break; |
| 1733 | case PCI_DEVICE_ID_INTEL_IBRIDGE_BR0: |
| 1734 | pvt->pci_br0 = pdev; |
| 1735 | break; |
| 1736 | case PCI_DEVICE_ID_INTEL_IBRIDGE_BR1: |
| 1737 | pvt->pci_br1 = pdev; |
| 1738 | break; |
| 1739 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1: |
| 1740 | pvt->pci_ha1 = pdev; |
| 1741 | break; |
| 1742 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD0: |
| 1743 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD1: |
| 1744 | { |
| 1745 | int id = pdev->device - PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD0 + 2; |
| 1746 | |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 1747 | /* we shouldn't have this device if we have just one |
| 1748 | * HA present */ |
| 1749 | WARN_ON(!mode_2ha); |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1750 | pvt->pci_tad[id] = pdev; |
| 1751 | } |
| 1752 | break; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 1753 | default: |
| 1754 | goto error; |
| 1755 | } |
| 1756 | |
| 1757 | edac_dbg(0, "Associated PCI %02x.%02d.%d with dev = %p\n", |
| 1758 | sbridge_dev->bus, |
| 1759 | PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), |
| 1760 | pdev); |
| 1761 | } |
| 1762 | |
| 1763 | /* Check if everything were registered */ |
| 1764 | if (!pvt->pci_sad0 || !pvt->pci_ha0 || !pvt->pci_br0 || |
| 1765 | !pvt->pci_br1 || !pvt->pci_tad || !pvt->pci_ras || |
| 1766 | !pvt->pci_ta) |
| 1767 | goto enodev; |
| 1768 | |
| 1769 | for (i = 0; i < NUM_CHANNELS; i++) { |
| 1770 | if (!pvt->pci_tad[i]) |
| 1771 | goto enodev; |
| 1772 | } |
| 1773 | return 0; |
| 1774 | |
| 1775 | enodev: |
| 1776 | sbridge_printk(KERN_ERR, "Some needed devices are missing\n"); |
| 1777 | return -ENODEV; |
| 1778 | |
| 1779 | error: |
| 1780 | sbridge_printk(KERN_ERR, |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 1781 | "Unexpected device %02x:%02x\n", PCI_VENDOR_ID_INTEL, |
| 1782 | pdev->device); |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 1783 | return -EINVAL; |
| 1784 | } |
| 1785 | |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 1786 | static int haswell_mci_bind_devs(struct mem_ctl_info *mci, |
| 1787 | struct sbridge_dev *sbridge_dev) |
| 1788 | { |
| 1789 | struct sbridge_pvt *pvt = mci->pvt_info; |
| 1790 | struct pci_dev *pdev, *tmp; |
| 1791 | int i; |
| 1792 | bool mode_2ha = false; |
| 1793 | |
| 1794 | tmp = pci_get_device(PCI_VENDOR_ID_INTEL, |
| 1795 | PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1, NULL); |
| 1796 | if (tmp) { |
| 1797 | mode_2ha = true; |
| 1798 | pci_dev_put(tmp); |
| 1799 | } |
| 1800 | |
| 1801 | /* there's only one device per system; not tied to any bus */ |
| 1802 | if (pvt->info.pci_vtd == NULL) |
| 1803 | /* result will be checked later */ |
| 1804 | pvt->info.pci_vtd = pci_get_device(PCI_VENDOR_ID_INTEL, |
| 1805 | PCI_DEVICE_ID_INTEL_HASWELL_IMC_VTD_MISC, |
| 1806 | NULL); |
| 1807 | |
| 1808 | for (i = 0; i < sbridge_dev->n_devs; i++) { |
| 1809 | pdev = sbridge_dev->pdev[i]; |
| 1810 | if (!pdev) |
| 1811 | continue; |
| 1812 | |
| 1813 | switch (pdev->device) { |
| 1814 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_CBO_SAD0: |
| 1815 | pvt->pci_sad0 = pdev; |
| 1816 | break; |
| 1817 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_CBO_SAD1: |
| 1818 | pvt->pci_sad1 = pdev; |
| 1819 | break; |
| 1820 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0: |
| 1821 | pvt->pci_ha0 = pdev; |
| 1822 | break; |
| 1823 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TA: |
| 1824 | pvt->pci_ta = pdev; |
| 1825 | break; |
| 1826 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_THERMAL: |
| 1827 | pvt->pci_ras = pdev; |
| 1828 | break; |
| 1829 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD0: |
| 1830 | pvt->pci_tad[0] = pdev; |
| 1831 | break; |
| 1832 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD1: |
| 1833 | pvt->pci_tad[1] = pdev; |
| 1834 | break; |
| 1835 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD2: |
| 1836 | if (!mode_2ha) |
| 1837 | pvt->pci_tad[2] = pdev; |
| 1838 | break; |
| 1839 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD3: |
| 1840 | if (!mode_2ha) |
| 1841 | pvt->pci_tad[3] = pdev; |
| 1842 | break; |
| 1843 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO0: |
| 1844 | pvt->pci_ddrio = pdev; |
| 1845 | break; |
| 1846 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1: |
| 1847 | pvt->pci_ha1 = pdev; |
| 1848 | break; |
| 1849 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TA: |
| 1850 | pvt->pci_ha1_ta = pdev; |
| 1851 | break; |
| 1852 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD0: |
| 1853 | if (mode_2ha) |
| 1854 | pvt->pci_tad[2] = pdev; |
| 1855 | break; |
| 1856 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD1: |
| 1857 | if (mode_2ha) |
| 1858 | pvt->pci_tad[3] = pdev; |
| 1859 | break; |
| 1860 | default: |
| 1861 | break; |
| 1862 | } |
| 1863 | |
| 1864 | edac_dbg(0, "Associated PCI %02x.%02d.%d with dev = %p\n", |
| 1865 | sbridge_dev->bus, |
| 1866 | PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), |
| 1867 | pdev); |
| 1868 | } |
| 1869 | |
| 1870 | /* Check if everything were registered */ |
| 1871 | if (!pvt->pci_sad0 || !pvt->pci_ha0 || !pvt->pci_sad1 || |
| 1872 | !pvt->pci_ras || !pvt->pci_ta || !pvt->info.pci_vtd) |
| 1873 | goto enodev; |
| 1874 | |
| 1875 | for (i = 0; i < NUM_CHANNELS; i++) { |
| 1876 | if (!pvt->pci_tad[i]) |
| 1877 | goto enodev; |
| 1878 | } |
| 1879 | return 0; |
| 1880 | |
| 1881 | enodev: |
| 1882 | sbridge_printk(KERN_ERR, "Some needed devices are missing\n"); |
| 1883 | return -ENODEV; |
| 1884 | } |
| 1885 | |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 1886 | static int broadwell_mci_bind_devs(struct mem_ctl_info *mci, |
| 1887 | struct sbridge_dev *sbridge_dev) |
| 1888 | { |
| 1889 | struct sbridge_pvt *pvt = mci->pvt_info; |
| 1890 | struct pci_dev *pdev; |
| 1891 | int i; |
| 1892 | |
| 1893 | /* there's only one device per system; not tied to any bus */ |
| 1894 | if (pvt->info.pci_vtd == NULL) |
| 1895 | /* result will be checked later */ |
| 1896 | pvt->info.pci_vtd = pci_get_device(PCI_VENDOR_ID_INTEL, |
| 1897 | PCI_DEVICE_ID_INTEL_BROADWELL_IMC_VTD_MISC, |
| 1898 | NULL); |
| 1899 | |
| 1900 | for (i = 0; i < sbridge_dev->n_devs; i++) { |
| 1901 | pdev = sbridge_dev->pdev[i]; |
| 1902 | if (!pdev) |
| 1903 | continue; |
| 1904 | |
| 1905 | switch (pdev->device) { |
| 1906 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_CBO_SAD0: |
| 1907 | pvt->pci_sad0 = pdev; |
| 1908 | break; |
| 1909 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_CBO_SAD1: |
| 1910 | pvt->pci_sad1 = pdev; |
| 1911 | break; |
| 1912 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0: |
| 1913 | pvt->pci_ha0 = pdev; |
| 1914 | break; |
| 1915 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TA: |
| 1916 | pvt->pci_ta = pdev; |
| 1917 | break; |
| 1918 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_THERMAL: |
| 1919 | pvt->pci_ras = pdev; |
| 1920 | break; |
| 1921 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD0: |
| 1922 | pvt->pci_tad[0] = pdev; |
| 1923 | break; |
| 1924 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD1: |
| 1925 | pvt->pci_tad[1] = pdev; |
| 1926 | break; |
| 1927 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD2: |
| 1928 | pvt->pci_tad[2] = pdev; |
| 1929 | break; |
| 1930 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD3: |
| 1931 | pvt->pci_tad[3] = pdev; |
| 1932 | break; |
| 1933 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_DDRIO0: |
| 1934 | pvt->pci_ddrio = pdev; |
| 1935 | break; |
| 1936 | default: |
| 1937 | break; |
| 1938 | } |
| 1939 | |
| 1940 | edac_dbg(0, "Associated PCI %02x.%02d.%d with dev = %p\n", |
| 1941 | sbridge_dev->bus, |
| 1942 | PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), |
| 1943 | pdev); |
| 1944 | } |
| 1945 | |
| 1946 | /* Check if everything were registered */ |
| 1947 | if (!pvt->pci_sad0 || !pvt->pci_ha0 || !pvt->pci_sad1 || |
| 1948 | !pvt->pci_ras || !pvt->pci_ta || !pvt->info.pci_vtd) |
| 1949 | goto enodev; |
| 1950 | |
| 1951 | for (i = 0; i < NUM_CHANNELS; i++) { |
| 1952 | if (!pvt->pci_tad[i]) |
| 1953 | goto enodev; |
| 1954 | } |
| 1955 | return 0; |
| 1956 | |
| 1957 | enodev: |
| 1958 | sbridge_printk(KERN_ERR, "Some needed devices are missing\n"); |
| 1959 | return -ENODEV; |
| 1960 | } |
| 1961 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1962 | /**************************************************************************** |
| 1963 | Error check routines |
| 1964 | ****************************************************************************/ |
| 1965 | |
| 1966 | /* |
| 1967 | * While Sandy Bridge has error count registers, SMI BIOS read values from |
| 1968 | * and resets the counters. So, they are not reliable for the OS to read |
| 1969 | * from them. So, we have no option but to just trust on whatever MCE is |
| 1970 | * telling us about the errors. |
| 1971 | */ |
| 1972 | static void sbridge_mce_output_error(struct mem_ctl_info *mci, |
| 1973 | const struct mce *m) |
| 1974 | { |
| 1975 | struct mem_ctl_info *new_mci; |
| 1976 | struct sbridge_pvt *pvt = mci->pvt_info; |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 1977 | enum hw_event_mc_err_type tp_event; |
Mauro Carvalho Chehab | e17a2f42a | 2012-05-11 11:41:45 -0300 | [diff] [blame] | 1978 | char *type, *optype, msg[256]; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1979 | bool ripv = GET_BITFIELD(m->mcgstatus, 0, 0); |
| 1980 | bool overflow = GET_BITFIELD(m->status, 62, 62); |
| 1981 | bool uncorrected_error = GET_BITFIELD(m->status, 61, 61); |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 1982 | bool recoverable; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1983 | u32 core_err_cnt = GET_BITFIELD(m->status, 38, 52); |
| 1984 | u32 mscod = GET_BITFIELD(m->status, 16, 31); |
| 1985 | u32 errcode = GET_BITFIELD(m->status, 0, 15); |
| 1986 | u32 channel = GET_BITFIELD(m->status, 0, 3); |
| 1987 | u32 optypenum = GET_BITFIELD(m->status, 4, 6); |
| 1988 | long channel_mask, first_channel; |
| 1989 | u8 rank, socket; |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 1990 | int rc, dimm; |
Mauro Carvalho Chehab | e17a2f42a | 2012-05-11 11:41:45 -0300 | [diff] [blame] | 1991 | char *area_type = NULL; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 1992 | |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 1993 | if (pvt->info.type == IVY_BRIDGE) |
| 1994 | recoverable = true; |
| 1995 | else |
| 1996 | recoverable = GET_BITFIELD(m->status, 56, 56); |
| 1997 | |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 1998 | if (uncorrected_error) { |
| 1999 | if (ripv) { |
| 2000 | type = "FATAL"; |
| 2001 | tp_event = HW_EVENT_ERR_FATAL; |
| 2002 | } else { |
| 2003 | type = "NON_FATAL"; |
| 2004 | tp_event = HW_EVENT_ERR_UNCORRECTED; |
| 2005 | } |
| 2006 | } else { |
| 2007 | type = "CORRECTED"; |
| 2008 | tp_event = HW_EVENT_ERR_CORRECTED; |
| 2009 | } |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2010 | |
| 2011 | /* |
David Mackey | 15ed103 | 2012-04-17 11:30:52 -0700 | [diff] [blame] | 2012 | * 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] | 2013 | * memory errors should fit in this mask: |
| 2014 | * 000f 0000 1mmm cccc (binary) |
| 2015 | * where: |
| 2016 | * f = Correction Report Filtering Bit. If 1, subsequent errors |
| 2017 | * won't be shown |
| 2018 | * mmm = error type |
| 2019 | * cccc = channel |
| 2020 | * If the mask doesn't match, report an error to the parsing logic |
| 2021 | */ |
| 2022 | if (! ((errcode & 0xef80) == 0x80)) { |
| 2023 | optype = "Can't parse: it is not a mem"; |
| 2024 | } else { |
| 2025 | switch (optypenum) { |
| 2026 | case 0: |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 2027 | optype = "generic undef request error"; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2028 | break; |
| 2029 | case 1: |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 2030 | optype = "memory read error"; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2031 | break; |
| 2032 | case 2: |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 2033 | optype = "memory write error"; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2034 | break; |
| 2035 | case 3: |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 2036 | optype = "addr/cmd error"; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2037 | break; |
| 2038 | case 4: |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 2039 | optype = "memory scrubbing error"; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2040 | break; |
| 2041 | default: |
| 2042 | optype = "reserved"; |
| 2043 | break; |
| 2044 | } |
| 2045 | } |
| 2046 | |
Aristeu Rozanski | be3036d | 2013-10-30 13:27:05 -0300 | [diff] [blame] | 2047 | /* Only decode errors with an valid address (ADDRV) */ |
| 2048 | if (!GET_BITFIELD(m->status, 58, 58)) |
| 2049 | return; |
| 2050 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2051 | rc = get_memory_error_data(mci, m->addr, &socket, |
Mauro Carvalho Chehab | e17a2f42a | 2012-05-11 11:41:45 -0300 | [diff] [blame] | 2052 | &channel_mask, &rank, &area_type, msg); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2053 | if (rc < 0) |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 2054 | goto err_parsing; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2055 | new_mci = get_mci_for_node_id(socket); |
| 2056 | if (!new_mci) { |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 2057 | strcpy(msg, "Error: socket got corrupted!"); |
| 2058 | goto err_parsing; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2059 | } |
| 2060 | mci = new_mci; |
| 2061 | pvt = mci->pvt_info; |
| 2062 | |
| 2063 | first_channel = find_first_bit(&channel_mask, NUM_CHANNELS); |
| 2064 | |
| 2065 | if (rank < 4) |
| 2066 | dimm = 0; |
| 2067 | else if (rank < 8) |
| 2068 | dimm = 1; |
| 2069 | else |
| 2070 | dimm = 2; |
| 2071 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2072 | |
| 2073 | /* |
Mauro Carvalho Chehab | e17a2f42a | 2012-05-11 11:41:45 -0300 | [diff] [blame] | 2074 | * FIXME: On some memory configurations (mirror, lockstep), the |
| 2075 | * Memory Controller can't point the error to a single DIMM. The |
| 2076 | * EDAC core should be handling the channel mask, in order to point |
| 2077 | * 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] | 2078 | */ |
Aristeu Rozanski | d7c660b | 2014-06-02 15:15:28 -0300 | [diff] [blame] | 2079 | if (!pvt->is_lockstep && !pvt->is_mirrored && !pvt->is_close_pg) |
| 2080 | channel = first_channel; |
| 2081 | |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 2082 | snprintf(msg, sizeof(msg), |
Mauro Carvalho Chehab | c105383 | 2012-06-04 13:40:05 -0300 | [diff] [blame] | 2083 | "%s%s area:%s err_code:%04x:%04x socket:%d channel_mask:%ld rank:%d", |
Mauro Carvalho Chehab | e17a2f42a | 2012-05-11 11:41:45 -0300 | [diff] [blame] | 2084 | overflow ? " OVERFLOW" : "", |
| 2085 | (uncorrected_error && recoverable) ? " recoverable" : "", |
| 2086 | area_type, |
| 2087 | mscod, errcode, |
| 2088 | socket, |
| 2089 | channel_mask, |
| 2090 | rank); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2091 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2092 | edac_dbg(0, "%s\n", msg); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2093 | |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 2094 | /* FIXME: need support for channel mask */ |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2095 | |
Seth Jennings | 351fc4a | 2014-09-05 14:28:47 -0500 | [diff] [blame] | 2096 | if (channel == CHANNEL_UNSPECIFIED) |
| 2097 | channel = -1; |
| 2098 | |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 2099 | /* Call the helper to output message */ |
Mauro Carvalho Chehab | c105383 | 2012-06-04 13:40:05 -0300 | [diff] [blame] | 2100 | edac_mc_handle_error(tp_event, mci, core_err_cnt, |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 2101 | m->addr >> PAGE_SHIFT, m->addr & ~PAGE_MASK, 0, |
| 2102 | channel, dimm, -1, |
Mauro Carvalho Chehab | 03f7eae | 2012-06-04 11:29:25 -0300 | [diff] [blame] | 2103 | optype, msg); |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 2104 | return; |
| 2105 | err_parsing: |
Mauro Carvalho Chehab | c105383 | 2012-06-04 13:40:05 -0300 | [diff] [blame] | 2106 | 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] | 2107 | -1, -1, -1, |
Mauro Carvalho Chehab | 03f7eae | 2012-06-04 11:29:25 -0300 | [diff] [blame] | 2108 | msg, ""); |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 2109 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2110 | } |
| 2111 | |
| 2112 | /* |
| 2113 | * sbridge_check_error Retrieve and process errors reported by the |
| 2114 | * hardware. Called by the Core module. |
| 2115 | */ |
| 2116 | static void sbridge_check_error(struct mem_ctl_info *mci) |
| 2117 | { |
| 2118 | struct sbridge_pvt *pvt = mci->pvt_info; |
| 2119 | int i; |
| 2120 | unsigned count = 0; |
| 2121 | struct mce *m; |
| 2122 | |
| 2123 | /* |
| 2124 | * MCE first step: Copy all mce errors into a temporary buffer |
| 2125 | * We use a double buffering here, to reduce the risk of |
| 2126 | * loosing an error. |
| 2127 | */ |
| 2128 | smp_rmb(); |
| 2129 | count = (pvt->mce_out + MCE_LOG_LEN - pvt->mce_in) |
| 2130 | % MCE_LOG_LEN; |
| 2131 | if (!count) |
| 2132 | return; |
| 2133 | |
| 2134 | m = pvt->mce_outentry; |
| 2135 | if (pvt->mce_in + count > MCE_LOG_LEN) { |
| 2136 | unsigned l = MCE_LOG_LEN - pvt->mce_in; |
| 2137 | |
| 2138 | memcpy(m, &pvt->mce_entry[pvt->mce_in], sizeof(*m) * l); |
| 2139 | smp_wmb(); |
| 2140 | pvt->mce_in = 0; |
| 2141 | count -= l; |
| 2142 | m += l; |
| 2143 | } |
| 2144 | memcpy(m, &pvt->mce_entry[pvt->mce_in], sizeof(*m) * count); |
| 2145 | smp_wmb(); |
| 2146 | pvt->mce_in += count; |
| 2147 | |
| 2148 | smp_rmb(); |
| 2149 | if (pvt->mce_overrun) { |
| 2150 | sbridge_printk(KERN_ERR, "Lost %d memory errors\n", |
| 2151 | pvt->mce_overrun); |
| 2152 | smp_wmb(); |
| 2153 | pvt->mce_overrun = 0; |
| 2154 | } |
| 2155 | |
| 2156 | /* |
| 2157 | * MCE second step: parse errors and display |
| 2158 | */ |
| 2159 | for (i = 0; i < count; i++) |
| 2160 | sbridge_mce_output_error(mci, &pvt->mce_outentry[i]); |
| 2161 | } |
| 2162 | |
| 2163 | /* |
| 2164 | * sbridge_mce_check_error Replicates mcelog routine to get errors |
| 2165 | * This routine simply queues mcelog errors, and |
| 2166 | * return. The error itself should be handled later |
| 2167 | * by sbridge_check_error. |
| 2168 | * WARNING: As this routine should be called at NMI time, extra care should |
| 2169 | * be taken to avoid deadlocks, and to be as fast as possible. |
| 2170 | */ |
Mauro Carvalho Chehab | 3d78c9a | 2011-10-20 19:33:46 -0200 | [diff] [blame] | 2171 | static int sbridge_mce_check_error(struct notifier_block *nb, unsigned long val, |
| 2172 | void *data) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2173 | { |
Mauro Carvalho Chehab | 3d78c9a | 2011-10-20 19:33:46 -0200 | [diff] [blame] | 2174 | struct mce *mce = (struct mce *)data; |
| 2175 | struct mem_ctl_info *mci; |
| 2176 | struct sbridge_pvt *pvt; |
Aristeu Rozanski | cf40f80 | 2014-03-11 15:45:41 -0400 | [diff] [blame] | 2177 | char *type; |
Mauro Carvalho Chehab | 3d78c9a | 2011-10-20 19:33:46 -0200 | [diff] [blame] | 2178 | |
Chen, Gong | fd52103 | 2013-12-06 01:17:09 -0500 | [diff] [blame] | 2179 | if (get_edac_report_status() == EDAC_REPORTING_DISABLED) |
| 2180 | return NOTIFY_DONE; |
| 2181 | |
Mauro Carvalho Chehab | 3d78c9a | 2011-10-20 19:33:46 -0200 | [diff] [blame] | 2182 | mci = get_mci_for_node_id(mce->socketid); |
| 2183 | if (!mci) |
| 2184 | return NOTIFY_BAD; |
| 2185 | pvt = mci->pvt_info; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2186 | |
| 2187 | /* |
| 2188 | * Just let mcelog handle it if the error is |
| 2189 | * outside the memory controller. A memory error |
| 2190 | * is indicated by bit 7 = 1 and bits = 8-11,13-15 = 0. |
| 2191 | * bit 12 has an special meaning. |
| 2192 | */ |
| 2193 | if ((mce->status & 0xefff) >> 7 != 1) |
Mauro Carvalho Chehab | 3d78c9a | 2011-10-20 19:33:46 -0200 | [diff] [blame] | 2194 | return NOTIFY_DONE; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2195 | |
Aristeu Rozanski | cf40f80 | 2014-03-11 15:45:41 -0400 | [diff] [blame] | 2196 | if (mce->mcgstatus & MCG_STATUS_MCIP) |
| 2197 | type = "Exception"; |
| 2198 | else |
| 2199 | type = "Event"; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2200 | |
Aristeu Rozanski | 49856dc | 2014-03-11 15:45:42 -0400 | [diff] [blame] | 2201 | sbridge_mc_printk(mci, KERN_DEBUG, "HANDLING MCE MEMORY ERROR\n"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2202 | |
Aristeu Rozanski | 49856dc | 2014-03-11 15:45:42 -0400 | [diff] [blame] | 2203 | sbridge_mc_printk(mci, KERN_DEBUG, "CPU %d: Machine Check %s: %Lx " |
| 2204 | "Bank %d: %016Lx\n", mce->extcpu, type, |
| 2205 | mce->mcgstatus, mce->bank, mce->status); |
| 2206 | sbridge_mc_printk(mci, KERN_DEBUG, "TSC %llx ", mce->tsc); |
| 2207 | sbridge_mc_printk(mci, KERN_DEBUG, "ADDR %llx ", mce->addr); |
| 2208 | sbridge_mc_printk(mci, KERN_DEBUG, "MISC %llx ", mce->misc); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2209 | |
Aristeu Rozanski | 49856dc | 2014-03-11 15:45:42 -0400 | [diff] [blame] | 2210 | sbridge_mc_printk(mci, KERN_DEBUG, "PROCESSOR %u:%x TIME %llu SOCKET " |
| 2211 | "%u APIC %x\n", mce->cpuvendor, mce->cpuid, |
| 2212 | mce->time, mce->socketid, mce->apicid); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2213 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2214 | smp_rmb(); |
| 2215 | if ((pvt->mce_out + 1) % MCE_LOG_LEN == pvt->mce_in) { |
| 2216 | smp_wmb(); |
| 2217 | pvt->mce_overrun++; |
Mauro Carvalho Chehab | 3d78c9a | 2011-10-20 19:33:46 -0200 | [diff] [blame] | 2218 | return NOTIFY_DONE; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2219 | } |
| 2220 | |
| 2221 | /* Copy memory error at the ringbuffer */ |
| 2222 | memcpy(&pvt->mce_entry[pvt->mce_out], mce, sizeof(*mce)); |
| 2223 | smp_wmb(); |
| 2224 | pvt->mce_out = (pvt->mce_out + 1) % MCE_LOG_LEN; |
| 2225 | |
| 2226 | /* Handle fatal errors immediately */ |
| 2227 | if (mce->mcgstatus & 1) |
| 2228 | sbridge_check_error(mci); |
| 2229 | |
| 2230 | /* Advice mcelog that the error were handled */ |
Mauro Carvalho Chehab | 3d78c9a | 2011-10-20 19:33:46 -0200 | [diff] [blame] | 2231 | return NOTIFY_STOP; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2232 | } |
| 2233 | |
Mauro Carvalho Chehab | 3d78c9a | 2011-10-20 19:33:46 -0200 | [diff] [blame] | 2234 | static struct notifier_block sbridge_mce_dec = { |
| 2235 | .notifier_call = sbridge_mce_check_error, |
| 2236 | }; |
| 2237 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2238 | /**************************************************************************** |
| 2239 | EDAC register/unregister logic |
| 2240 | ****************************************************************************/ |
| 2241 | |
| 2242 | static void sbridge_unregister_mci(struct sbridge_dev *sbridge_dev) |
| 2243 | { |
| 2244 | struct mem_ctl_info *mci = sbridge_dev->mci; |
| 2245 | struct sbridge_pvt *pvt; |
| 2246 | |
| 2247 | if (unlikely(!mci || !mci->pvt_info)) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2248 | 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] | 2249 | |
| 2250 | sbridge_printk(KERN_ERR, "Couldn't find mci handler\n"); |
| 2251 | return; |
| 2252 | } |
| 2253 | |
| 2254 | pvt = mci->pvt_info; |
| 2255 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2256 | edac_dbg(0, "MC: mci = %p, dev = %p\n", |
| 2257 | mci, &sbridge_dev->pdev[0]->dev); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2258 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2259 | /* Remove MC sysfs nodes */ |
Mauro Carvalho Chehab | fd68750 | 2012-03-16 07:44:18 -0300 | [diff] [blame] | 2260 | edac_mc_del_mc(mci->pdev); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2261 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2262 | edac_dbg(1, "%s: free mci struct\n", mci->ctl_name); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2263 | kfree(mci->ctl_name); |
| 2264 | edac_mc_free(mci); |
| 2265 | sbridge_dev->mci = NULL; |
| 2266 | } |
| 2267 | |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2268 | 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] | 2269 | { |
| 2270 | struct mem_ctl_info *mci; |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 2271 | struct edac_mc_layer layers[2]; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2272 | struct sbridge_pvt *pvt; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2273 | struct pci_dev *pdev = sbridge_dev->pdev[0]; |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 2274 | int rc; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2275 | |
| 2276 | /* Check the number of active and not disabled channels */ |
Aristeu Rozanski | dbc954d | 2014-06-02 15:15:25 -0300 | [diff] [blame] | 2277 | rc = check_if_ecc_is_active(sbridge_dev->bus, type); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2278 | if (unlikely(rc < 0)) |
| 2279 | return rc; |
| 2280 | |
| 2281 | /* allocate a new MC control structure */ |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 2282 | layers[0].type = EDAC_MC_LAYER_CHANNEL; |
| 2283 | layers[0].size = NUM_CHANNELS; |
| 2284 | layers[0].is_virt_csrow = false; |
| 2285 | layers[1].type = EDAC_MC_LAYER_SLOT; |
| 2286 | layers[1].size = MAX_DIMMS; |
| 2287 | layers[1].is_virt_csrow = true; |
Mauro Carvalho Chehab | ca0907b | 2012-05-02 14:37:00 -0300 | [diff] [blame] | 2288 | mci = edac_mc_alloc(sbridge_dev->mc, ARRAY_SIZE(layers), layers, |
Mauro Carvalho Chehab | c36e3e7 | 2012-04-16 15:12:22 -0300 | [diff] [blame] | 2289 | sizeof(*pvt)); |
| 2290 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2291 | if (unlikely(!mci)) |
| 2292 | return -ENOMEM; |
| 2293 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2294 | edac_dbg(0, "MC: mci = %p, dev = %p\n", |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2295 | mci, &pdev->dev); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2296 | |
| 2297 | pvt = mci->pvt_info; |
| 2298 | memset(pvt, 0, sizeof(*pvt)); |
| 2299 | |
| 2300 | /* Associate sbridge_dev and mci for future usage */ |
| 2301 | pvt->sbridge_dev = sbridge_dev; |
| 2302 | sbridge_dev->mci = mci; |
| 2303 | |
| 2304 | mci->mtype_cap = MEM_FLAG_DDR3; |
| 2305 | mci->edac_ctl_cap = EDAC_FLAG_NONE; |
| 2306 | mci->edac_cap = EDAC_FLAG_NONE; |
| 2307 | mci->mod_name = "sbridge_edac.c"; |
| 2308 | mci->mod_ver = SBRIDGE_REVISION; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2309 | mci->dev_name = pci_name(pdev); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2310 | mci->ctl_page_to_phys = NULL; |
| 2311 | |
| 2312 | /* Set the function pointer to an actual operation function */ |
| 2313 | mci->edac_check = sbridge_check_error; |
| 2314 | |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2315 | pvt->info.type = type; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2316 | switch (type) { |
| 2317 | case IVY_BRIDGE: |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2318 | pvt->info.rankcfgr = IB_RANK_CFG_A; |
| 2319 | pvt->info.get_tolm = ibridge_get_tolm; |
| 2320 | pvt->info.get_tohm = ibridge_get_tohm; |
| 2321 | pvt->info.dram_rule = ibridge_dram_rule; |
Aristeu Rozanski | 9e37544 | 2014-06-02 15:15:22 -0300 | [diff] [blame] | 2322 | pvt->info.get_memory_type = get_memory_type; |
Aristeu Rozanski | f14d689 | 2014-06-02 15:15:23 -0300 | [diff] [blame] | 2323 | pvt->info.get_node_id = get_node_id; |
Aristeu Rozanski | b976bcf | 2014-06-02 15:15:24 -0300 | [diff] [blame] | 2324 | pvt->info.rir_limit = rir_limit; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2325 | pvt->info.max_sad = ARRAY_SIZE(ibridge_dram_rule); |
| 2326 | pvt->info.interleave_list = ibridge_interleave_list; |
| 2327 | pvt->info.max_interleave = ARRAY_SIZE(ibridge_interleave_list); |
| 2328 | pvt->info.interleave_pkg = ibridge_interleave_pkg; |
| 2329 | mci->ctl_name = kasprintf(GFP_KERNEL, "Ivy Bridge Socket#%d", mci->mc_idx); |
| 2330 | |
| 2331 | /* Store pci devices at mci for faster access */ |
| 2332 | rc = ibridge_mci_bind_devs(mci, sbridge_dev); |
| 2333 | if (unlikely(rc < 0)) |
| 2334 | goto fail0; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2335 | break; |
| 2336 | case SANDY_BRIDGE: |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2337 | pvt->info.rankcfgr = SB_RANK_CFG_A; |
| 2338 | pvt->info.get_tolm = sbridge_get_tolm; |
| 2339 | pvt->info.get_tohm = sbridge_get_tohm; |
| 2340 | pvt->info.dram_rule = sbridge_dram_rule; |
Aristeu Rozanski | 9e37544 | 2014-06-02 15:15:22 -0300 | [diff] [blame] | 2341 | pvt->info.get_memory_type = get_memory_type; |
Aristeu Rozanski | f14d689 | 2014-06-02 15:15:23 -0300 | [diff] [blame] | 2342 | pvt->info.get_node_id = get_node_id; |
Aristeu Rozanski | b976bcf | 2014-06-02 15:15:24 -0300 | [diff] [blame] | 2343 | pvt->info.rir_limit = rir_limit; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2344 | pvt->info.max_sad = ARRAY_SIZE(sbridge_dram_rule); |
| 2345 | pvt->info.interleave_list = sbridge_interleave_list; |
| 2346 | pvt->info.max_interleave = ARRAY_SIZE(sbridge_interleave_list); |
| 2347 | pvt->info.interleave_pkg = sbridge_interleave_pkg; |
| 2348 | mci->ctl_name = kasprintf(GFP_KERNEL, "Sandy Bridge Socket#%d", mci->mc_idx); |
| 2349 | |
| 2350 | /* Store pci devices at mci for faster access */ |
| 2351 | rc = sbridge_mci_bind_devs(mci, sbridge_dev); |
| 2352 | if (unlikely(rc < 0)) |
| 2353 | goto fail0; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2354 | break; |
| 2355 | case HASWELL: |
| 2356 | /* rankcfgr isn't used */ |
| 2357 | pvt->info.get_tolm = haswell_get_tolm; |
| 2358 | pvt->info.get_tohm = haswell_get_tohm; |
| 2359 | pvt->info.dram_rule = ibridge_dram_rule; |
| 2360 | pvt->info.get_memory_type = haswell_get_memory_type; |
| 2361 | pvt->info.get_node_id = haswell_get_node_id; |
| 2362 | pvt->info.rir_limit = haswell_rir_limit; |
| 2363 | pvt->info.max_sad = ARRAY_SIZE(ibridge_dram_rule); |
| 2364 | pvt->info.interleave_list = ibridge_interleave_list; |
| 2365 | pvt->info.max_interleave = ARRAY_SIZE(ibridge_interleave_list); |
| 2366 | pvt->info.interleave_pkg = ibridge_interleave_pkg; |
| 2367 | mci->ctl_name = kasprintf(GFP_KERNEL, "Haswell Socket#%d", mci->mc_idx); |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2368 | |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2369 | /* Store pci devices at mci for faster access */ |
| 2370 | rc = haswell_mci_bind_devs(mci, sbridge_dev); |
| 2371 | if (unlikely(rc < 0)) |
| 2372 | goto fail0; |
| 2373 | break; |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 2374 | case BROADWELL: |
| 2375 | /* rankcfgr isn't used */ |
| 2376 | pvt->info.get_tolm = haswell_get_tolm; |
| 2377 | pvt->info.get_tohm = haswell_get_tohm; |
| 2378 | pvt->info.dram_rule = ibridge_dram_rule; |
| 2379 | pvt->info.get_memory_type = haswell_get_memory_type; |
| 2380 | pvt->info.get_node_id = haswell_get_node_id; |
| 2381 | pvt->info.rir_limit = haswell_rir_limit; |
| 2382 | pvt->info.max_sad = ARRAY_SIZE(ibridge_dram_rule); |
| 2383 | pvt->info.interleave_list = ibridge_interleave_list; |
| 2384 | pvt->info.max_interleave = ARRAY_SIZE(ibridge_interleave_list); |
| 2385 | pvt->info.interleave_pkg = ibridge_interleave_pkg; |
| 2386 | mci->ctl_name = kasprintf(GFP_KERNEL, "Broadwell Socket#%d", mci->mc_idx); |
| 2387 | |
| 2388 | /* Store pci devices at mci for faster access */ |
| 2389 | rc = broadwell_mci_bind_devs(mci, sbridge_dev); |
| 2390 | if (unlikely(rc < 0)) |
| 2391 | goto fail0; |
| 2392 | break; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2393 | } |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2394 | |
| 2395 | /* Get dimm basic config and the memory layout */ |
| 2396 | get_dimm_config(mci); |
| 2397 | get_memory_layout(mci); |
| 2398 | |
| 2399 | /* record ptr to the generic device */ |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2400 | mci->pdev = &pdev->dev; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2401 | |
| 2402 | /* add this new MC control structure to EDAC's list of MCs */ |
| 2403 | if (unlikely(edac_mc_add_mc(mci))) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2404 | edac_dbg(0, "MC: failed edac_mc_add_mc()\n"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2405 | rc = -EINVAL; |
| 2406 | goto fail0; |
| 2407 | } |
| 2408 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2409 | return 0; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2410 | |
| 2411 | fail0: |
| 2412 | kfree(mci->ctl_name); |
| 2413 | edac_mc_free(mci); |
| 2414 | sbridge_dev->mci = NULL; |
| 2415 | return rc; |
| 2416 | } |
| 2417 | |
| 2418 | /* |
| 2419 | * sbridge_probe Probe for ONE instance of device to see if it is |
| 2420 | * present. |
| 2421 | * return: |
| 2422 | * 0 for FOUND a device |
| 2423 | * < 0 for error code |
| 2424 | */ |
| 2425 | |
Greg Kroah-Hartman | 9b3c6e8 | 2012-12-21 13:23:51 -0800 | [diff] [blame] | 2426 | static int sbridge_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2427 | { |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2428 | int rc = -ENODEV; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2429 | u8 mc, num_mc = 0; |
| 2430 | struct sbridge_dev *sbridge_dev; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2431 | enum type type = SANDY_BRIDGE; |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2432 | |
| 2433 | /* get the pci devices we want to reserve for our use */ |
| 2434 | mutex_lock(&sbridge_edac_lock); |
| 2435 | |
| 2436 | /* |
| 2437 | * All memory controllers are allocated at the first pass. |
| 2438 | */ |
| 2439 | if (unlikely(probed >= 1)) { |
| 2440 | mutex_unlock(&sbridge_edac_lock); |
| 2441 | return -ENODEV; |
| 2442 | } |
| 2443 | probed++; |
| 2444 | |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2445 | switch (pdev->device) { |
| 2446 | case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA: |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2447 | rc = sbridge_get_all_devices(&num_mc, pci_dev_descr_ibridge_table); |
| 2448 | type = IVY_BRIDGE; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2449 | break; |
Borislav Petkov | 11249e7 | 2015-02-05 12:39:36 +0100 | [diff] [blame] | 2450 | case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_HA0: |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2451 | rc = sbridge_get_all_devices(&num_mc, pci_dev_descr_sbridge_table); |
| 2452 | type = SANDY_BRIDGE; |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2453 | break; |
| 2454 | case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0: |
| 2455 | rc = sbridge_get_all_devices(&num_mc, pci_dev_descr_haswell_table); |
| 2456 | type = HASWELL; |
| 2457 | break; |
Tony Luck | 1f39581 | 2014-12-02 09:27:30 -0800 | [diff] [blame] | 2458 | case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0: |
| 2459 | rc = sbridge_get_all_devices(&num_mc, pci_dev_descr_broadwell_table); |
| 2460 | type = BROADWELL; |
| 2461 | break; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2462 | } |
Borislav Petkov | 11249e7 | 2015-02-05 12:39:36 +0100 | [diff] [blame] | 2463 | if (unlikely(rc < 0)) { |
| 2464 | edac_dbg(0, "couldn't get all devices for 0x%x\n", pdev->device); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2465 | goto fail0; |
Borislav Petkov | 11249e7 | 2015-02-05 12:39:36 +0100 | [diff] [blame] | 2466 | } |
| 2467 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2468 | mc = 0; |
| 2469 | |
| 2470 | list_for_each_entry(sbridge_dev, &sbridge_edac_list, list) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2471 | edac_dbg(0, "Registering MC#%d (%d of %d)\n", |
| 2472 | mc, mc + 1, num_mc); |
Aristeu Rozanski | 50d1bb9 | 2014-06-20 10:27:54 -0300 | [diff] [blame] | 2473 | |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2474 | sbridge_dev->mc = mc++; |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2475 | rc = sbridge_register_mci(sbridge_dev, type); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2476 | if (unlikely(rc < 0)) |
| 2477 | goto fail1; |
| 2478 | } |
| 2479 | |
Borislav Petkov | 11249e7 | 2015-02-05 12:39:36 +0100 | [diff] [blame] | 2480 | sbridge_printk(KERN_INFO, "%s\n", SBRIDGE_REVISION); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2481 | |
| 2482 | mutex_unlock(&sbridge_edac_lock); |
| 2483 | return 0; |
| 2484 | |
| 2485 | fail1: |
| 2486 | list_for_each_entry(sbridge_dev, &sbridge_edac_list, list) |
| 2487 | sbridge_unregister_mci(sbridge_dev); |
| 2488 | |
| 2489 | sbridge_put_all_devices(); |
| 2490 | fail0: |
| 2491 | mutex_unlock(&sbridge_edac_lock); |
| 2492 | return rc; |
| 2493 | } |
| 2494 | |
| 2495 | /* |
| 2496 | * sbridge_remove destructor for one instance of device |
| 2497 | * |
| 2498 | */ |
Greg Kroah-Hartman | 9b3c6e8 | 2012-12-21 13:23:51 -0800 | [diff] [blame] | 2499 | static void sbridge_remove(struct pci_dev *pdev) |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2500 | { |
| 2501 | struct sbridge_dev *sbridge_dev; |
| 2502 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2503 | edac_dbg(0, "\n"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2504 | |
| 2505 | /* |
| 2506 | * we have a trouble here: pdev value for removal will be wrong, since |
| 2507 | * it will point to the X58 register used to detect that the machine |
| 2508 | * is a Nehalem or upper design. However, due to the way several PCI |
| 2509 | * devices are grouped together to provide MC functionality, we need |
| 2510 | * to use a different method for releasing the devices |
| 2511 | */ |
| 2512 | |
| 2513 | mutex_lock(&sbridge_edac_lock); |
| 2514 | |
| 2515 | if (unlikely(!probed)) { |
| 2516 | mutex_unlock(&sbridge_edac_lock); |
| 2517 | return; |
| 2518 | } |
| 2519 | |
| 2520 | list_for_each_entry(sbridge_dev, &sbridge_edac_list, list) |
| 2521 | sbridge_unregister_mci(sbridge_dev); |
| 2522 | |
| 2523 | /* Release PCI resources */ |
| 2524 | sbridge_put_all_devices(); |
| 2525 | |
| 2526 | probed--; |
| 2527 | |
| 2528 | mutex_unlock(&sbridge_edac_lock); |
| 2529 | } |
| 2530 | |
| 2531 | MODULE_DEVICE_TABLE(pci, sbridge_pci_tbl); |
| 2532 | |
| 2533 | /* |
| 2534 | * sbridge_driver pci_driver structure for this module |
| 2535 | * |
| 2536 | */ |
| 2537 | static struct pci_driver sbridge_driver = { |
| 2538 | .name = "sbridge_edac", |
| 2539 | .probe = sbridge_probe, |
Greg Kroah-Hartman | 9b3c6e8 | 2012-12-21 13:23:51 -0800 | [diff] [blame] | 2540 | .remove = sbridge_remove, |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2541 | .id_table = sbridge_pci_tbl, |
| 2542 | }; |
| 2543 | |
| 2544 | /* |
| 2545 | * sbridge_init Module entry function |
| 2546 | * Try to initialize this module for its devices |
| 2547 | */ |
| 2548 | static int __init sbridge_init(void) |
| 2549 | { |
| 2550 | int pci_rc; |
| 2551 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2552 | edac_dbg(2, "\n"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2553 | |
| 2554 | /* Ensure that the OPSTATE is set correctly for POLL or NMI */ |
| 2555 | opstate_init(); |
| 2556 | |
| 2557 | pci_rc = pci_register_driver(&sbridge_driver); |
Chen Gong | e35fca4 | 2012-05-08 20:40:12 -0300 | [diff] [blame] | 2558 | if (pci_rc >= 0) { |
| 2559 | mce_register_decode_chain(&sbridge_mce_dec); |
Chen, Gong | fd52103 | 2013-12-06 01:17:09 -0500 | [diff] [blame] | 2560 | if (get_edac_report_status() == EDAC_REPORTING_DISABLED) |
| 2561 | sbridge_printk(KERN_WARNING, "Loading driver, error reporting disabled.\n"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2562 | return 0; |
Chen Gong | e35fca4 | 2012-05-08 20:40:12 -0300 | [diff] [blame] | 2563 | } |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2564 | |
| 2565 | sbridge_printk(KERN_ERR, "Failed to register device with error %d.\n", |
| 2566 | pci_rc); |
| 2567 | |
| 2568 | return pci_rc; |
| 2569 | } |
| 2570 | |
| 2571 | /* |
| 2572 | * sbridge_exit() Module exit function |
| 2573 | * Unregister the driver |
| 2574 | */ |
| 2575 | static void __exit sbridge_exit(void) |
| 2576 | { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2577 | edac_dbg(2, "\n"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2578 | pci_unregister_driver(&sbridge_driver); |
Chen Gong | e35fca4 | 2012-05-08 20:40:12 -0300 | [diff] [blame] | 2579 | mce_unregister_decode_chain(&sbridge_mce_dec); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2580 | } |
| 2581 | |
| 2582 | module_init(sbridge_init); |
| 2583 | module_exit(sbridge_exit); |
| 2584 | |
| 2585 | module_param(edac_op_state, int, 0444); |
| 2586 | MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI"); |
| 2587 | |
| 2588 | MODULE_LICENSE("GPL"); |
Mauro Carvalho Chehab | 37e59f8 | 2014-02-07 08:03:07 -0200 | [diff] [blame] | 2589 | MODULE_AUTHOR("Mauro Carvalho Chehab"); |
Mauro Carvalho Chehab | eebf11a | 2011-10-20 19:18:01 -0200 | [diff] [blame] | 2590 | MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)"); |
Aristeu Rozanski | 4d715a8 | 2013-10-30 13:27:06 -0300 | [diff] [blame] | 2591 | 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] | 2592 | SBRIDGE_REVISION); |