1 /* Intel Sandy Bridge -EN/-EP/-EX Memory Controller kernel module
3 * This driver supports the memory controllers found on the Intel
4 * processor family Sandy Bridge.
6 * This file may be distributed under the terms of the
7 * GNU General Public License version 2 only.
9 * Copyright (c) 2011 by:
10 * Mauro Carvalho Chehab
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>
21 #include <linux/smp.h>
22 #include <linux/bitmap.h>
23 #include <linux/math64.h>
24 #include <asm/processor.h>
27 #include "edac_core.h"
30 static LIST_HEAD(sbridge_edac_list
);
31 static DEFINE_MUTEX(sbridge_edac_lock
);
35 * Alter this version for the module when modifications are made
37 #define SBRIDGE_REVISION " Ver: 1.1.1 "
38 #define EDAC_MOD_STR "sbridge_edac"
43 #define sbridge_printk(level, fmt, arg...) \
44 edac_printk(level, "sbridge", fmt, ##arg)
46 #define sbridge_mc_printk(mci, level, fmt, arg...) \
47 edac_mc_chipset_printk(mci, level, "sbridge", fmt, ##arg)
50 * Get a bit field at register value <v>, from bit <lo> to bit <hi>
52 #define GET_BITFIELD(v, lo, hi) \
53 (((v) & GENMASK_ULL(hi, lo)) >> (lo))
55 /* Devices 12 Function 6, Offsets 0x80 to 0xcc */
56 static const u32 sbridge_dram_rule
[] = {
57 0x80, 0x88, 0x90, 0x98, 0xa0,
58 0xa8, 0xb0, 0xb8, 0xc0, 0xc8,
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,
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)
72 #define A7MODE(reg) GET_BITFIELD(reg, 26, 26)
74 static char *get_dram_attr(u32 reg
)
76 switch(DRAM_ATTR(reg
)) {
88 static const u32 sbridge_interleave_list
[] = {
89 0x84, 0x8c, 0x94, 0x9c, 0xa4,
90 0xac, 0xb4, 0xbc, 0xc4, 0xcc,
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,
100 struct interleave_pkg
{
105 static const struct interleave_pkg sbridge_interleave_pkg
[] = {
116 static const struct interleave_pkg ibridge_interleave_pkg
[] = {
127 static inline int sad_pkg(const struct interleave_pkg
*table
, u32 reg
,
130 return GET_BITFIELD(reg
, table
[interleave
].start
,
131 table
[interleave
].end
);
134 /* Devices 12 Function 7 */
138 #define HASWELL_TOLM 0xd0
139 #define HASWELL_TOHM_0 0xd4
140 #define HASWELL_TOHM_1 0xd8
142 #define GET_TOLM(reg) ((GET_BITFIELD(reg, 0, 3) << 28) | 0x3ffffff)
143 #define GET_TOHM(reg) ((GET_BITFIELD(reg, 0, 20) << 25) | 0x3ffffff)
145 /* Device 13 Function 6 */
147 #define SAD_TARGET 0xf0
149 #define SOURCE_ID(reg) GET_BITFIELD(reg, 9, 11)
151 #define SAD_CONTROL 0xf4
153 /* Device 14 function 0 */
155 static const u32 tad_dram_rule
[] = {
156 0x40, 0x44, 0x48, 0x4c,
157 0x50, 0x54, 0x58, 0x5c,
158 0x60, 0x64, 0x68, 0x6c,
160 #define MAX_TAD ARRAY_SIZE(tad_dram_rule)
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)
170 /* Device 15, function 0 */
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)
178 /* Device 15, function 1 */
180 #define RASENABLES 0xac
181 #define IS_MIRROR_ENABLED(reg) GET_BITFIELD(reg, 0, 0)
183 /* Device 15, functions 2-5 */
185 static const int mtr_regs
[] = {
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)
195 static const u32 tad_ch_nilv_offset
[] = {
196 0x90, 0x94, 0x98, 0x9c,
197 0xa0, 0xa4, 0xa8, 0xac,
198 0xb0, 0xb4, 0xb8, 0xbc,
200 #define CHN_IDX_OFFSET(reg) GET_BITFIELD(reg, 28, 29)
201 #define TAD_OFFSET(reg) (GET_BITFIELD(reg, 6, 25) << 26)
203 static const u32 rir_way_limit
[] = {
204 0x108, 0x10c, 0x110, 0x114, 0x118,
206 #define MAX_RIR_RANGES ARRAY_SIZE(rir_way_limit)
208 #define IS_RIR_VALID(reg) GET_BITFIELD(reg, 31, 31)
209 #define RIR_WAY(reg) GET_BITFIELD(reg, 28, 29)
211 #define MAX_RIR_WAY 8
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 },
221 #define RIR_RNK_TGT(reg) GET_BITFIELD(reg, 16, 19)
222 #define RIR_OFFSET(reg) GET_BITFIELD(reg, 2, 14)
224 /* Device 16, functions 2-7 */
227 * FIXME: Implement the error count reads directly
230 static const u32 correrrcnt
[] = {
231 0x104, 0x108, 0x10c, 0x110,
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)
239 static const u32 correrrthrsld
[] = {
240 0x11c, 0x120, 0x124, 0x128,
243 #define RANK_ODD_ERR_THRSLD(reg) GET_BITFIELD(reg, 16, 30)
244 #define RANK_EVEN_ERR_THRSLD(reg) GET_BITFIELD(reg, 0, 14)
247 /* Device 17, function 0 */
249 #define SB_RANK_CFG_A 0x0328
251 #define IB_RANK_CFG_A 0x0320
257 #define NUM_CHANNELS 8 /* 2MC per socket, four chan per MC */
258 #define MAX_DIMMS 3 /* Max DIMMS per channel */
259 #define CHANNEL_UNSPECIFIED 0xf /* Intel IA32 SDM 15-14 */
269 struct sbridge_info
{
273 u64 (*get_tolm
)(struct sbridge_pvt
*pvt
);
274 u64 (*get_tohm
)(struct sbridge_pvt
*pvt
);
275 u64 (*rir_limit
)(u32 reg
);
276 const u32
*dram_rule
;
277 const u32
*interleave_list
;
278 const struct interleave_pkg
*interleave_pkg
;
281 u8 (*get_node_id
)(struct sbridge_pvt
*pvt
);
282 enum mem_type (*get_memory_type
)(struct sbridge_pvt
*pvt
);
283 struct pci_dev
*pci_vtd
;
286 struct sbridge_channel
{
291 struct pci_id_descr
{
296 struct pci_id_table
{
297 const struct pci_id_descr
*descr
;
302 struct list_head list
;
304 u8 node_id
, source_id
;
305 struct pci_dev
**pdev
;
307 struct mem_ctl_info
*mci
;
311 struct pci_dev
*pci_ta
, *pci_ddrio
, *pci_ras
;
312 struct pci_dev
*pci_sad0
, *pci_sad1
;
313 struct pci_dev
*pci_ha0
, *pci_ha1
;
314 struct pci_dev
*pci_br0
, *pci_br1
;
315 struct pci_dev
*pci_ha1_ta
;
316 struct pci_dev
*pci_tad
[NUM_CHANNELS
];
318 struct sbridge_dev
*sbridge_dev
;
320 struct sbridge_info info
;
321 struct sbridge_channel channel
[NUM_CHANNELS
];
323 /* Memory type detection */
324 bool is_mirrored
, is_lockstep
, is_close_pg
;
326 /* Fifo double buffers */
327 struct mce mce_entry
[MCE_LOG_LEN
];
328 struct mce mce_outentry
[MCE_LOG_LEN
];
330 /* Fifo in/out counters */
331 unsigned mce_in
, mce_out
;
333 /* Count indicator to show errors not got */
334 unsigned mce_overrun
;
336 /* Memory description */
340 #define PCI_DESCR(device_id, opt) \
341 .dev_id = (device_id), \
344 static const struct pci_id_descr pci_dev_descr_sbridge
[] = {
345 /* Processor Home Agent */
346 { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_HA0
, 0) },
348 /* Memory controller */
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) },
357 /* System Address Decoder */
358 { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_SAD0
, 0) },
359 { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_SAD1
, 0) },
361 /* Broadcast Registers */
362 { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_BR
, 0) },
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. */
371 /* This changes depending if 1HA or 2HA:
373 * 0x0eb8 (17.0) is DDRIO0
375 * 0x0ebc (17.4) is DDRIO0
377 #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_1HA_DDRIO0 0x0eb8
378 #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_2HA_DDRIO0 0x0ebc
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 #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD2 0x0e6c
397 #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD3 0x0e6d
399 static const struct pci_id_descr pci_dev_descr_ibridge
[] = {
400 /* Processor Home Agent */
401 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0
, 0) },
403 /* Memory controller */
404 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA
, 0) },
405 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_RAS
, 0) },
406 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD0
, 0) },
407 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD1
, 0) },
408 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD2
, 0) },
409 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD3
, 0) },
411 /* System Address Decoder */
412 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_SAD
, 0) },
414 /* Broadcast Registers */
415 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_BR0
, 1) },
416 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_BR1
, 0) },
418 /* Optional, mode 2HA */
419 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1
, 1) },
421 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TA
, 1) },
422 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_RAS
, 1) },
424 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD0
, 1) },
425 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD1
, 1) },
426 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD2
, 1) },
427 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD3
, 1) },
429 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_1HA_DDRIO0
, 1) },
430 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_2HA_DDRIO0
, 1) },
433 static const struct pci_id_table pci_dev_descr_ibridge_table
[] = {
434 PCI_ID_TABLE_ENTRY(pci_dev_descr_ibridge
),
435 {0,} /* 0 terminated list. */
438 /* Haswell support */
441 * - 3 DDR3 channels, 2 DPC per channel
444 * - 4 DDR4 channels, 3 DPC per channel
447 * - 4 DDR4 channels, 3 DPC per channel
450 * - each IMC interfaces with a SMI 2 channel
451 * - each SMI channel interfaces with a scalable memory buffer
452 * - each scalable memory buffer supports 4 DDR3/DDR4 channels, 3 DPC
454 #define HASWELL_DDRCRCLKCONTROLS 0xa10 /* Ditto on Broadwell */
455 #define HASWELL_HASYSDEFEATURE2 0x84
456 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_VTD_MISC 0x2f28
457 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0 0x2fa0
458 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1 0x2f60
459 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TA 0x2fa8
460 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_THERMAL 0x2f71
461 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TA 0x2f68
462 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_THERMAL 0x2f79
463 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_CBO_SAD0 0x2ffc
464 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_CBO_SAD1 0x2ffd
465 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD0 0x2faa
466 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD1 0x2fab
467 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD2 0x2fac
468 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD3 0x2fad
469 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD0 0x2f6a
470 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD1 0x2f6b
471 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD2 0x2f6c
472 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD3 0x2f6d
473 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO0 0x2fbd
474 static const struct pci_id_descr pci_dev_descr_haswell
[] = {
475 /* first item must be the HA */
476 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0
, 0) },
478 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_CBO_SAD0
, 0) },
479 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_CBO_SAD1
, 0) },
481 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1
, 1) },
483 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TA
, 0) },
484 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_THERMAL
, 0) },
485 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD0
, 0) },
486 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD1
, 0) },
487 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD2
, 1) },
488 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD3
, 1) },
490 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO0
, 1) },
492 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TA
, 1) },
493 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_THERMAL
, 1) },
494 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD0
, 1) },
495 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD1
, 1) },
496 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD2
, 1) },
497 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD3
, 1) },
500 static const struct pci_id_table pci_dev_descr_haswell_table
[] = {
501 PCI_ID_TABLE_ENTRY(pci_dev_descr_haswell
),
502 {0,} /* 0 terminated list. */
510 * - 2 DDR3 channels, 2 DPC per channel
513 * - 4 DDR4 channels, 3 DPC per channel
516 * - 4 DDR4 channels, 3 DPC per channel
519 * - each IMC interfaces with a SMI 2 channel
520 * - each SMI channel interfaces with a scalable memory buffer
521 * - each scalable memory buffer supports 4 DDR3/DDR4 channels, 3 DPC
523 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_VTD_MISC 0x6f28
524 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0 0x6fa0
525 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1 0x6f60
526 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TA 0x6fa8
527 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_THERMAL 0x6f71
528 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TA 0x6f68
529 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_THERMAL 0x6f79
530 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_CBO_SAD0 0x6ffc
531 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_CBO_SAD1 0x6ffd
532 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD0 0x6faa
533 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD1 0x6fab
534 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD2 0x6fac
535 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD3 0x6fad
536 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD0 0x6f6a
537 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD1 0x6f6b
538 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD2 0x6f6c
539 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD3 0x6f6d
540 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_DDRIO0 0x6faf
542 static const struct pci_id_descr pci_dev_descr_broadwell
[] = {
543 /* first item must be the HA */
544 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0
, 0) },
546 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_CBO_SAD0
, 0) },
547 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_CBO_SAD1
, 0) },
549 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1
, 1) },
551 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TA
, 0) },
552 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_THERMAL
, 0) },
553 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD0
, 0) },
554 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD1
, 0) },
555 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD2
, 1) },
556 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD3
, 1) },
558 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_DDRIO0
, 1) },
560 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TA
, 1) },
561 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_THERMAL
, 1) },
562 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD0
, 1) },
563 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD1
, 1) },
564 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD2
, 1) },
565 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD3
, 1) },
568 static const struct pci_id_table pci_dev_descr_broadwell_table
[] = {
569 PCI_ID_TABLE_ENTRY(pci_dev_descr_broadwell
),
570 {0,} /* 0 terminated list. */
574 * pci_device_id table for which devices we are looking for
576 static const struct pci_device_id sbridge_pci_tbl
[] = {
577 {PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_HA0
)},
578 {PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA
)},
579 {PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0
)},
580 {PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0
)},
581 {0,} /* 0 terminated list. */
585 /****************************************************************************
586 Ancillary status routines
587 ****************************************************************************/
589 static inline int numrank(enum type type
, u32 mtr
)
591 int ranks
= (1 << RANK_CNT_BITS(mtr
));
594 if (type
== HASWELL
|| type
== BROADWELL
)
598 edac_dbg(0, "Invalid number of ranks: %d (max = %i) raw value = %x (%04x)\n",
599 ranks
, max
, (unsigned int)RANK_CNT_BITS(mtr
), mtr
);
606 static inline int numrow(u32 mtr
)
608 int rows
= (RANK_WIDTH_BITS(mtr
) + 12);
610 if (rows
< 13 || rows
> 18) {
611 edac_dbg(0, "Invalid number of rows: %d (should be between 14 and 17) raw value = %x (%04x)\n",
612 rows
, (unsigned int)RANK_WIDTH_BITS(mtr
), mtr
);
619 static inline int numcol(u32 mtr
)
621 int cols
= (COL_WIDTH_BITS(mtr
) + 10);
624 edac_dbg(0, "Invalid number of cols: %d (max = 4) raw value = %x (%04x)\n",
625 cols
, (unsigned int)COL_WIDTH_BITS(mtr
), mtr
);
632 static struct sbridge_dev
*get_sbridge_dev(u8 bus
)
634 struct sbridge_dev
*sbridge_dev
;
636 list_for_each_entry(sbridge_dev
, &sbridge_edac_list
, list
) {
637 if (sbridge_dev
->bus
== bus
)
644 static struct sbridge_dev
*alloc_sbridge_dev(u8 bus
,
645 const struct pci_id_table
*table
)
647 struct sbridge_dev
*sbridge_dev
;
649 sbridge_dev
= kzalloc(sizeof(*sbridge_dev
), GFP_KERNEL
);
653 sbridge_dev
->pdev
= kzalloc(sizeof(*sbridge_dev
->pdev
) * table
->n_devs
,
655 if (!sbridge_dev
->pdev
) {
660 sbridge_dev
->bus
= bus
;
661 sbridge_dev
->n_devs
= table
->n_devs
;
662 list_add_tail(&sbridge_dev
->list
, &sbridge_edac_list
);
667 static void free_sbridge_dev(struct sbridge_dev
*sbridge_dev
)
669 list_del(&sbridge_dev
->list
);
670 kfree(sbridge_dev
->pdev
);
674 static u64
sbridge_get_tolm(struct sbridge_pvt
*pvt
)
678 /* Address range is 32:28 */
679 pci_read_config_dword(pvt
->pci_sad1
, TOLM
, ®
);
680 return GET_TOLM(reg
);
683 static u64
sbridge_get_tohm(struct sbridge_pvt
*pvt
)
687 pci_read_config_dword(pvt
->pci_sad1
, TOHM
, ®
);
688 return GET_TOHM(reg
);
691 static u64
ibridge_get_tolm(struct sbridge_pvt
*pvt
)
695 pci_read_config_dword(pvt
->pci_br1
, TOLM
, ®
);
697 return GET_TOLM(reg
);
700 static u64
ibridge_get_tohm(struct sbridge_pvt
*pvt
)
704 pci_read_config_dword(pvt
->pci_br1
, TOHM
, ®
);
706 return GET_TOHM(reg
);
709 static u64
rir_limit(u32 reg
)
711 return ((u64
)GET_BITFIELD(reg
, 1, 10) << 29) | 0x1fffffff;
714 static enum mem_type
get_memory_type(struct sbridge_pvt
*pvt
)
719 if (pvt
->pci_ddrio
) {
720 pci_read_config_dword(pvt
->pci_ddrio
, pvt
->info
.rankcfgr
,
722 if (GET_BITFIELD(reg
, 11, 11))
723 /* FIXME: Can also be LRDIMM */
733 static enum mem_type
haswell_get_memory_type(struct sbridge_pvt
*pvt
)
736 bool registered
= false;
737 enum mem_type mtype
= MEM_UNKNOWN
;
742 pci_read_config_dword(pvt
->pci_ddrio
,
743 HASWELL_DDRCRCLKCONTROLS
, ®
);
745 if (GET_BITFIELD(reg
, 16, 16))
748 pci_read_config_dword(pvt
->pci_ta
, MCMTR
, ®
);
749 if (GET_BITFIELD(reg
, 14, 14)) {
765 static u8
get_node_id(struct sbridge_pvt
*pvt
)
768 pci_read_config_dword(pvt
->pci_br0
, SAD_CONTROL
, ®
);
769 return GET_BITFIELD(reg
, 0, 2);
772 static u8
haswell_get_node_id(struct sbridge_pvt
*pvt
)
776 pci_read_config_dword(pvt
->pci_sad1
, SAD_CONTROL
, ®
);
777 return GET_BITFIELD(reg
, 0, 3);
780 static u64
haswell_get_tolm(struct sbridge_pvt
*pvt
)
784 pci_read_config_dword(pvt
->info
.pci_vtd
, HASWELL_TOLM
, ®
);
785 return (GET_BITFIELD(reg
, 26, 31) << 26) | 0x3ffffff;
788 static u64
haswell_get_tohm(struct sbridge_pvt
*pvt
)
793 pci_read_config_dword(pvt
->info
.pci_vtd
, HASWELL_TOHM_0
, ®
);
794 rc
= GET_BITFIELD(reg
, 26, 31);
795 pci_read_config_dword(pvt
->info
.pci_vtd
, HASWELL_TOHM_1
, ®
);
796 rc
= ((reg
<< 6) | rc
) << 26;
798 return rc
| 0x1ffffff;
801 static u64
haswell_rir_limit(u32 reg
)
803 return (((u64
)GET_BITFIELD(reg
, 1, 11) + 1) << 29) - 1;
806 static inline u8
sad_pkg_socket(u8 pkg
)
808 /* on Ivy Bridge, nodeID is SASS, where A is HA and S is node id */
809 return ((pkg
>> 3) << 2) | (pkg
& 0x3);
812 static inline u8
sad_pkg_ha(u8 pkg
)
814 return (pkg
>> 2) & 0x1;
817 /****************************************************************************
818 Memory check routines
819 ****************************************************************************/
820 static struct pci_dev
*get_pdev_same_bus(u8 bus
, u32 id
)
822 struct pci_dev
*pdev
= NULL
;
825 pdev
= pci_get_device(PCI_VENDOR_ID_INTEL
, id
, pdev
);
826 if (pdev
&& pdev
->bus
->number
== bus
)
834 * check_if_ecc_is_active() - Checks if ECC is active
836 * @type: Memory controller type
837 * returns: 0 in case ECC is active, -ENODEV if it can't be determined or
840 static int check_if_ecc_is_active(const u8 bus
, enum type type
)
842 struct pci_dev
*pdev
= NULL
;
847 id
= PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA
;
850 id
= PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TA
;
853 id
= PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA
;
856 id
= PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TA
;
862 pdev
= get_pdev_same_bus(bus
, id
);
864 sbridge_printk(KERN_ERR
, "Couldn't find PCI device "
865 "%04x:%04x! on bus %02d\n",
866 PCI_VENDOR_ID_INTEL
, id
, bus
);
870 pci_read_config_dword(pdev
, MCMTR
, &mcmtr
);
871 if (!IS_ECC_ENABLED(mcmtr
)) {
872 sbridge_printk(KERN_ERR
, "ECC is disabled. Aborting\n");
878 static int get_dimm_config(struct mem_ctl_info
*mci
)
880 struct sbridge_pvt
*pvt
= mci
->pvt_info
;
881 struct dimm_info
*dimm
;
882 unsigned i
, j
, banks
, ranks
, rows
, cols
, npages
;
888 if (pvt
->info
.type
== HASWELL
|| pvt
->info
.type
== BROADWELL
)
889 pci_read_config_dword(pvt
->pci_sad1
, SAD_TARGET
, ®
);
891 pci_read_config_dword(pvt
->pci_br0
, SAD_TARGET
, ®
);
893 pvt
->sbridge_dev
->source_id
= SOURCE_ID(reg
);
895 pvt
->sbridge_dev
->node_id
= pvt
->info
.get_node_id(pvt
);
896 edac_dbg(0, "mc#%d: Node ID: %d, source ID: %d\n",
897 pvt
->sbridge_dev
->mc
,
898 pvt
->sbridge_dev
->node_id
,
899 pvt
->sbridge_dev
->source_id
);
901 pci_read_config_dword(pvt
->pci_ras
, RASENABLES
, ®
);
902 if (IS_MIRROR_ENABLED(reg
)) {
903 edac_dbg(0, "Memory mirror is enabled\n");
904 pvt
->is_mirrored
= true;
906 edac_dbg(0, "Memory mirror is disabled\n");
907 pvt
->is_mirrored
= false;
910 pci_read_config_dword(pvt
->pci_ta
, MCMTR
, &pvt
->info
.mcmtr
);
911 if (IS_LOCKSTEP_ENABLED(pvt
->info
.mcmtr
)) {
912 edac_dbg(0, "Lockstep is enabled\n");
913 mode
= EDAC_S8ECD8ED
;
914 pvt
->is_lockstep
= true;
916 edac_dbg(0, "Lockstep is disabled\n");
917 mode
= EDAC_S4ECD4ED
;
918 pvt
->is_lockstep
= false;
920 if (IS_CLOSE_PG(pvt
->info
.mcmtr
)) {
921 edac_dbg(0, "address map is on closed page mode\n");
922 pvt
->is_close_pg
= true;
924 edac_dbg(0, "address map is on open page mode\n");
925 pvt
->is_close_pg
= false;
928 mtype
= pvt
->info
.get_memory_type(pvt
);
929 if (mtype
== MEM_RDDR3
|| mtype
== MEM_RDDR4
)
930 edac_dbg(0, "Memory is registered\n");
931 else if (mtype
== MEM_UNKNOWN
)
932 edac_dbg(0, "Cannot determine memory type\n");
934 edac_dbg(0, "Memory is unregistered\n");
936 if (mtype
== MEM_DDR4
|| mtype
== MEM_RDDR4
)
941 for (i
= 0; i
< NUM_CHANNELS
; i
++) {
944 if (!pvt
->pci_tad
[i
])
946 for (j
= 0; j
< ARRAY_SIZE(mtr_regs
); j
++) {
947 dimm
= EDAC_DIMM_PTR(mci
->layers
, mci
->dimms
, mci
->n_layers
,
949 pci_read_config_dword(pvt
->pci_tad
[i
],
951 edac_dbg(4, "Channel #%d MTR%d = %x\n", i
, j
, mtr
);
952 if (IS_DIMM_PRESENT(mtr
)) {
953 pvt
->channel
[i
].dimms
++;
955 ranks
= numrank(pvt
->info
.type
, mtr
);
959 size
= ((u64
)rows
* cols
* banks
* ranks
) >> (20 - 3);
960 npages
= MiB_TO_PAGES(size
);
962 edac_dbg(0, "mc#%d: ha %d channel %d, dimm %d, %lld Mb (%d pages) bank: %d, rank: %d, row: %#x, col: %#x\n",
963 pvt
->sbridge_dev
->mc
, i
/4, i
%4, j
,
965 banks
, ranks
, rows
, cols
);
967 dimm
->nr_pages
= npages
;
971 dimm
->dtype
= DEV_X16
;
974 dimm
->dtype
= DEV_X8
;
977 dimm
->dtype
= DEV_X4
;
981 dimm
->edac_mode
= mode
;
982 snprintf(dimm
->label
, sizeof(dimm
->label
),
983 "CPU_SrcID#%u_Ha#%u_Chan#%u_DIMM#%u",
984 pvt
->sbridge_dev
->source_id
, i
/4, i
%4, j
);
992 static void get_memory_layout(const struct mem_ctl_info
*mci
)
994 struct sbridge_pvt
*pvt
= mci
->pvt_info
;
995 int i
, j
, k
, n_sads
, n_tads
, sad_interl
;
1003 * Step 1) Get TOLM/TOHM ranges
1006 pvt
->tolm
= pvt
->info
.get_tolm(pvt
);
1007 tmp_mb
= (1 + pvt
->tolm
) >> 20;
1009 gb
= div_u64_rem(tmp_mb
, 1024, &mb
);
1010 edac_dbg(0, "TOLM: %u.%03u GB (0x%016Lx)\n",
1011 gb
, (mb
*1000)/1024, (u64
)pvt
->tolm
);
1013 /* Address range is already 45:25 */
1014 pvt
->tohm
= pvt
->info
.get_tohm(pvt
);
1015 tmp_mb
= (1 + pvt
->tohm
) >> 20;
1017 gb
= div_u64_rem(tmp_mb
, 1024, &mb
);
1018 edac_dbg(0, "TOHM: %u.%03u GB (0x%016Lx)\n",
1019 gb
, (mb
*1000)/1024, (u64
)pvt
->tohm
);
1022 * Step 2) Get SAD range and SAD Interleave list
1023 * TAD registers contain the interleave wayness. However, it
1024 * seems simpler to just discover it indirectly, with the
1028 for (n_sads
= 0; n_sads
< pvt
->info
.max_sad
; n_sads
++) {
1029 /* SAD_LIMIT Address range is 45:26 */
1030 pci_read_config_dword(pvt
->pci_sad0
, pvt
->info
.dram_rule
[n_sads
],
1032 limit
= SAD_LIMIT(reg
);
1034 if (!DRAM_RULE_ENABLE(reg
))
1040 tmp_mb
= (limit
+ 1) >> 20;
1041 gb
= div_u64_rem(tmp_mb
, 1024, &mb
);
1042 edac_dbg(0, "SAD#%d %s up to %u.%03u GB (0x%016Lx) Interleave: %s reg=0x%08x\n",
1046 ((u64
)tmp_mb
) << 20L,
1047 INTERLEAVE_MODE(reg
) ? "8:6" : "[8:6]XOR[18:16]",
1051 pci_read_config_dword(pvt
->pci_sad0
, pvt
->info
.interleave_list
[n_sads
],
1053 sad_interl
= sad_pkg(pvt
->info
.interleave_pkg
, reg
, 0);
1054 for (j
= 0; j
< 8; j
++) {
1055 u32 pkg
= sad_pkg(pvt
->info
.interleave_pkg
, reg
, j
);
1056 if (j
> 0 && sad_interl
== pkg
)
1059 edac_dbg(0, "SAD#%d, interleave #%d: %d\n",
1065 * Step 3) Get TAD range
1068 for (n_tads
= 0; n_tads
< MAX_TAD
; n_tads
++) {
1069 pci_read_config_dword(pvt
->pci_ha0
, tad_dram_rule
[n_tads
],
1071 limit
= TAD_LIMIT(reg
);
1074 tmp_mb
= (limit
+ 1) >> 20;
1076 gb
= div_u64_rem(tmp_mb
, 1024, &mb
);
1077 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",
1078 n_tads
, gb
, (mb
*1000)/1024,
1079 ((u64
)tmp_mb
) << 20L,
1091 * Step 4) Get TAD offsets, per each channel
1093 for (i
= 0; i
< NUM_CHANNELS
; i
++) {
1094 if (!pvt
->channel
[i
].dimms
)
1096 for (j
= 0; j
< n_tads
; j
++) {
1097 pci_read_config_dword(pvt
->pci_tad
[i
],
1098 tad_ch_nilv_offset
[j
],
1100 tmp_mb
= TAD_OFFSET(reg
) >> 20;
1101 gb
= div_u64_rem(tmp_mb
, 1024, &mb
);
1102 edac_dbg(0, "TAD CH#%d, offset #%d: %u.%03u GB (0x%016Lx), reg=0x%08x\n",
1105 ((u64
)tmp_mb
) << 20L,
1111 * Step 6) Get RIR Wayness/Limit, per each channel
1113 for (i
= 0; i
< NUM_CHANNELS
; i
++) {
1114 if (!pvt
->channel
[i
].dimms
)
1116 for (j
= 0; j
< MAX_RIR_RANGES
; j
++) {
1117 pci_read_config_dword(pvt
->pci_tad
[i
],
1121 if (!IS_RIR_VALID(reg
))
1124 tmp_mb
= pvt
->info
.rir_limit(reg
) >> 20;
1125 rir_way
= 1 << RIR_WAY(reg
);
1126 gb
= div_u64_rem(tmp_mb
, 1024, &mb
);
1127 edac_dbg(0, "CH#%d RIR#%d, limit: %u.%03u GB (0x%016Lx), way: %d, reg=0x%08x\n",
1130 ((u64
)tmp_mb
) << 20L,
1134 for (k
= 0; k
< rir_way
; k
++) {
1135 pci_read_config_dword(pvt
->pci_tad
[i
],
1138 tmp_mb
= RIR_OFFSET(reg
) << 6;
1140 gb
= div_u64_rem(tmp_mb
, 1024, &mb
);
1141 edac_dbg(0, "CH#%d RIR#%d INTL#%d, offset %u.%03u GB (0x%016Lx), tgt: %d, reg=0x%08x\n",
1144 ((u64
)tmp_mb
) << 20L,
1145 (u32
)RIR_RNK_TGT(reg
),
1152 static struct mem_ctl_info
*get_mci_for_node_id(u8 node_id
)
1154 struct sbridge_dev
*sbridge_dev
;
1156 list_for_each_entry(sbridge_dev
, &sbridge_edac_list
, list
) {
1157 if (sbridge_dev
->node_id
== node_id
)
1158 return sbridge_dev
->mci
;
1163 static int get_memory_error_data(struct mem_ctl_info
*mci
,
1168 char **area_type
, char *msg
)
1170 struct mem_ctl_info
*new_mci
;
1171 struct sbridge_pvt
*pvt
= mci
->pvt_info
;
1172 struct pci_dev
*pci_ha
;
1173 int n_rir
, n_sads
, n_tads
, sad_way
, sck_xch
;
1174 int sad_interl
, idx
, base_ch
;
1175 int interleave_mode
, shiftup
= 0;
1176 unsigned sad_interleave
[pvt
->info
.max_interleave
];
1178 u8 ch_way
, sck_way
, pkg
, sad_ha
= 0, ch_add
= 0;
1182 u64 ch_addr
, offset
, limit
= 0, prv
= 0;
1186 * Step 0) Check if the address is at special memory ranges
1187 * The check bellow is probably enough to fill all cases where
1188 * the error is not inside a memory, except for the legacy
1189 * range (e. g. VGA addresses). It is unlikely, however, that the
1190 * memory controller would generate an error on that range.
1192 if ((addr
> (u64
) pvt
->tolm
) && (addr
< (1LL << 32))) {
1193 sprintf(msg
, "Error at TOLM area, on addr 0x%08Lx", addr
);
1196 if (addr
>= (u64
)pvt
->tohm
) {
1197 sprintf(msg
, "Error at MMIOH area, on addr 0x%016Lx", addr
);
1202 * Step 1) Get socket
1204 for (n_sads
= 0; n_sads
< pvt
->info
.max_sad
; n_sads
++) {
1205 pci_read_config_dword(pvt
->pci_sad0
, pvt
->info
.dram_rule
[n_sads
],
1208 if (!DRAM_RULE_ENABLE(reg
))
1211 limit
= SAD_LIMIT(reg
);
1213 sprintf(msg
, "Can't discover the memory socket");
1220 if (n_sads
== pvt
->info
.max_sad
) {
1221 sprintf(msg
, "Can't discover the memory socket");
1225 *area_type
= get_dram_attr(dram_rule
);
1226 interleave_mode
= INTERLEAVE_MODE(dram_rule
);
1228 pci_read_config_dword(pvt
->pci_sad0
, pvt
->info
.interleave_list
[n_sads
],
1231 if (pvt
->info
.type
== SANDY_BRIDGE
) {
1232 sad_interl
= sad_pkg(pvt
->info
.interleave_pkg
, reg
, 0);
1233 for (sad_way
= 0; sad_way
< 8; sad_way
++) {
1234 u32 pkg
= sad_pkg(pvt
->info
.interleave_pkg
, reg
, sad_way
);
1235 if (sad_way
> 0 && sad_interl
== pkg
)
1237 sad_interleave
[sad_way
] = pkg
;
1238 edac_dbg(0, "SAD interleave #%d: %d\n",
1239 sad_way
, sad_interleave
[sad_way
]);
1241 edac_dbg(0, "mc#%d: Error detected on SAD#%d: address 0x%016Lx < 0x%016Lx, Interleave [%d:6]%s\n",
1242 pvt
->sbridge_dev
->mc
,
1247 !interleave_mode
? "" : "XOR[18:16]");
1248 if (interleave_mode
)
1249 idx
= ((addr
>> 6) ^ (addr
>> 16)) & 7;
1251 idx
= (addr
>> 6) & 7;
1265 sprintf(msg
, "Can't discover socket interleave");
1268 *socket
= sad_interleave
[idx
];
1269 edac_dbg(0, "SAD interleave index: %d (wayness %d) = CPU socket %d\n",
1270 idx
, sad_way
, *socket
);
1271 } else if (pvt
->info
.type
== HASWELL
|| pvt
->info
.type
== BROADWELL
) {
1272 int bits
, a7mode
= A7MODE(dram_rule
);
1275 /* A7 mode swaps P9 with P6 */
1276 bits
= GET_BITFIELD(addr
, 7, 8) << 1;
1277 bits
|= GET_BITFIELD(addr
, 9, 9);
1279 bits
= GET_BITFIELD(addr
, 6, 8);
1281 if (interleave_mode
== 0) {
1282 /* interleave mode will XOR {8,7,6} with {18,17,16} */
1283 idx
= GET_BITFIELD(addr
, 16, 18);
1288 pkg
= sad_pkg(pvt
->info
.interleave_pkg
, reg
, idx
);
1289 *socket
= sad_pkg_socket(pkg
);
1290 sad_ha
= sad_pkg_ha(pkg
);
1295 /* MCChanShiftUpEnable */
1296 pci_read_config_dword(pvt
->pci_ha0
,
1297 HASWELL_HASYSDEFEATURE2
, ®
);
1298 shiftup
= GET_BITFIELD(reg
, 22, 22);
1301 edac_dbg(0, "SAD interleave package: %d = CPU socket %d, HA %i, shiftup: %i\n",
1302 idx
, *socket
, sad_ha
, shiftup
);
1304 /* Ivy Bridge's SAD mode doesn't support XOR interleave mode */
1305 idx
= (addr
>> 6) & 7;
1306 pkg
= sad_pkg(pvt
->info
.interleave_pkg
, reg
, idx
);
1307 *socket
= sad_pkg_socket(pkg
);
1308 sad_ha
= sad_pkg_ha(pkg
);
1311 edac_dbg(0, "SAD interleave package: %d = CPU socket %d, HA %d\n",
1312 idx
, *socket
, sad_ha
);
1318 * Move to the proper node structure, in order to access the
1319 * right PCI registers
1321 new_mci
= get_mci_for_node_id(*socket
);
1323 sprintf(msg
, "Struct for socket #%u wasn't initialized",
1328 pvt
= mci
->pvt_info
;
1331 * Step 2) Get memory channel
1334 if (pvt
->info
.type
== SANDY_BRIDGE
)
1335 pci_ha
= pvt
->pci_ha0
;
1338 pci_ha
= pvt
->pci_ha1
;
1340 pci_ha
= pvt
->pci_ha0
;
1342 for (n_tads
= 0; n_tads
< MAX_TAD
; n_tads
++) {
1343 pci_read_config_dword(pci_ha
, tad_dram_rule
[n_tads
], ®
);
1344 limit
= TAD_LIMIT(reg
);
1346 sprintf(msg
, "Can't discover the memory channel");
1353 if (n_tads
== MAX_TAD
) {
1354 sprintf(msg
, "Can't discover the memory channel");
1358 ch_way
= TAD_CH(reg
) + 1;
1359 sck_way
= TAD_SOCK(reg
) + 1;
1364 idx
= (addr
>> (6 + sck_way
+ shiftup
)) & 0x3;
1368 * FIXME: Shouldn't we use CHN_IDX_OFFSET() here, when ch_way == 3 ???
1372 base_ch
= TAD_TGT0(reg
);
1375 base_ch
= TAD_TGT1(reg
);
1378 base_ch
= TAD_TGT2(reg
);
1381 base_ch
= TAD_TGT3(reg
);
1384 sprintf(msg
, "Can't discover the TAD target");
1387 *channel_mask
= 1 << base_ch
;
1389 pci_read_config_dword(pvt
->pci_tad
[ch_add
+ base_ch
],
1390 tad_ch_nilv_offset
[n_tads
],
1393 if (pvt
->is_mirrored
) {
1394 *channel_mask
|= 1 << ((base_ch
+ 2) % 4);
1398 sck_xch
= 1 << sck_way
* (ch_way
>> 1);
1401 sprintf(msg
, "Invalid mirror set. Can't decode addr");
1405 sck_xch
= (1 << sck_way
) * ch_way
;
1407 if (pvt
->is_lockstep
)
1408 *channel_mask
|= 1 << ((base_ch
+ 1) % 4);
1410 offset
= TAD_OFFSET(tad_offset
);
1412 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",
1423 /* Calculate channel address */
1424 /* Remove the TAD offset */
1426 if (offset
> addr
) {
1427 sprintf(msg
, "Can't calculate ch addr: TAD offset 0x%08Lx is too high for addr 0x%08Lx!",
1432 /* Store the low bits [0:6] of the addr */
1433 ch_addr
= addr
& 0x7f;
1434 /* Remove socket wayness and remove 6 bits */
1436 addr
= div_u64(addr
, sck_xch
);
1438 /* Divide by channel way */
1439 addr
= addr
/ ch_way
;
1441 /* Recover the last 6 bits */
1442 ch_addr
|= addr
<< 6;
1445 * Step 3) Decode rank
1447 for (n_rir
= 0; n_rir
< MAX_RIR_RANGES
; n_rir
++) {
1448 pci_read_config_dword(pvt
->pci_tad
[ch_add
+ base_ch
],
1449 rir_way_limit
[n_rir
],
1452 if (!IS_RIR_VALID(reg
))
1455 limit
= pvt
->info
.rir_limit(reg
);
1456 gb
= div_u64_rem(limit
>> 20, 1024, &mb
);
1457 edac_dbg(0, "RIR#%d, limit: %u.%03u GB (0x%016Lx), way: %d\n",
1462 if (ch_addr
<= limit
)
1465 if (n_rir
== MAX_RIR_RANGES
) {
1466 sprintf(msg
, "Can't discover the memory rank for ch addr 0x%08Lx",
1470 rir_way
= RIR_WAY(reg
);
1472 if (pvt
->is_close_pg
)
1473 idx
= (ch_addr
>> 6);
1475 idx
= (ch_addr
>> 13); /* FIXME: Datasheet says to shift by 15 */
1476 idx
%= 1 << rir_way
;
1478 pci_read_config_dword(pvt
->pci_tad
[ch_add
+ base_ch
],
1479 rir_offset
[n_rir
][idx
],
1481 *rank
= RIR_RNK_TGT(reg
);
1483 edac_dbg(0, "RIR#%d: channel address 0x%08Lx < 0x%08Lx, RIR interleave %d, index %d\n",
1493 /****************************************************************************
1494 Device initialization routines: put/get, init/exit
1495 ****************************************************************************/
1498 * sbridge_put_all_devices 'put' all the devices that we have
1499 * reserved via 'get'
1501 static void sbridge_put_devices(struct sbridge_dev
*sbridge_dev
)
1506 for (i
= 0; i
< sbridge_dev
->n_devs
; i
++) {
1507 struct pci_dev
*pdev
= sbridge_dev
->pdev
[i
];
1510 edac_dbg(0, "Removing dev %02x:%02x.%d\n",
1512 PCI_SLOT(pdev
->devfn
), PCI_FUNC(pdev
->devfn
));
1517 static void sbridge_put_all_devices(void)
1519 struct sbridge_dev
*sbridge_dev
, *tmp
;
1521 list_for_each_entry_safe(sbridge_dev
, tmp
, &sbridge_edac_list
, list
) {
1522 sbridge_put_devices(sbridge_dev
);
1523 free_sbridge_dev(sbridge_dev
);
1527 static int sbridge_get_onedevice(struct pci_dev
**prev
,
1529 const struct pci_id_table
*table
,
1530 const unsigned devno
)
1532 struct sbridge_dev
*sbridge_dev
;
1533 const struct pci_id_descr
*dev_descr
= &table
->descr
[devno
];
1534 struct pci_dev
*pdev
= NULL
;
1537 sbridge_printk(KERN_DEBUG
,
1538 "Seeking for: PCI ID %04x:%04x\n",
1539 PCI_VENDOR_ID_INTEL
, dev_descr
->dev_id
);
1541 pdev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
1542 dev_descr
->dev_id
, *prev
);
1550 if (dev_descr
->optional
)
1553 /* if the HA wasn't found */
1557 sbridge_printk(KERN_INFO
,
1558 "Device not found: %04x:%04x\n",
1559 PCI_VENDOR_ID_INTEL
, dev_descr
->dev_id
);
1561 /* End of list, leave */
1564 bus
= pdev
->bus
->number
;
1566 sbridge_dev
= get_sbridge_dev(bus
);
1568 sbridge_dev
= alloc_sbridge_dev(bus
, table
);
1576 if (sbridge_dev
->pdev
[devno
]) {
1577 sbridge_printk(KERN_ERR
,
1578 "Duplicated device for %04x:%04x\n",
1579 PCI_VENDOR_ID_INTEL
, dev_descr
->dev_id
);
1584 sbridge_dev
->pdev
[devno
] = pdev
;
1586 /* Be sure that the device is enabled */
1587 if (unlikely(pci_enable_device(pdev
) < 0)) {
1588 sbridge_printk(KERN_ERR
,
1589 "Couldn't enable %04x:%04x\n",
1590 PCI_VENDOR_ID_INTEL
, dev_descr
->dev_id
);
1594 edac_dbg(0, "Detected %04x:%04x\n",
1595 PCI_VENDOR_ID_INTEL
, dev_descr
->dev_id
);
1598 * As stated on drivers/pci/search.c, the reference count for
1599 * @from is always decremented if it is not %NULL. So, as we need
1600 * to get all devices up to null, we need to do a get for the device
1610 * sbridge_get_all_devices - Find and perform 'get' operation on the MCH's
1611 * devices we want to reference for this driver.
1612 * @num_mc: pointer to the memory controllers count, to be incremented in case
1614 * @table: model specific table
1616 * returns 0 in case of success or error code
1618 static int sbridge_get_all_devices(u8
*num_mc
,
1619 const struct pci_id_table
*table
)
1622 struct pci_dev
*pdev
= NULL
;
1624 while (table
&& table
->descr
) {
1625 for (i
= 0; i
< table
->n_devs
; i
++) {
1628 rc
= sbridge_get_onedevice(&pdev
, num_mc
,
1635 sbridge_put_all_devices();
1646 static int sbridge_mci_bind_devs(struct mem_ctl_info
*mci
,
1647 struct sbridge_dev
*sbridge_dev
)
1649 struct sbridge_pvt
*pvt
= mci
->pvt_info
;
1650 struct pci_dev
*pdev
;
1653 for (i
= 0; i
< sbridge_dev
->n_devs
; i
++) {
1654 pdev
= sbridge_dev
->pdev
[i
];
1658 switch (pdev
->device
) {
1659 case PCI_DEVICE_ID_INTEL_SBRIDGE_SAD0
:
1660 pvt
->pci_sad0
= pdev
;
1662 case PCI_DEVICE_ID_INTEL_SBRIDGE_SAD1
:
1663 pvt
->pci_sad1
= pdev
;
1665 case PCI_DEVICE_ID_INTEL_SBRIDGE_BR
:
1666 pvt
->pci_br0
= pdev
;
1668 case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_HA0
:
1669 pvt
->pci_ha0
= pdev
;
1671 case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA
:
1674 case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_RAS
:
1675 pvt
->pci_ras
= pdev
;
1677 case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD0
:
1678 case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD1
:
1679 case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD2
:
1680 case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD3
:
1682 int id
= pdev
->device
- PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD0
;
1683 pvt
->pci_tad
[id
] = pdev
;
1686 case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_DDRIO
:
1687 pvt
->pci_ddrio
= pdev
;
1693 edac_dbg(0, "Associated PCI %02x:%02x, bus %d with dev = %p\n",
1694 pdev
->vendor
, pdev
->device
,
1699 /* Check if everything were registered */
1700 if (!pvt
->pci_sad0
|| !pvt
->pci_sad1
|| !pvt
->pci_ha0
||
1701 !pvt
-> pci_tad
|| !pvt
->pci_ras
|| !pvt
->pci_ta
)
1704 for (i
= 0; i
< NUM_CHANNELS
; i
++) {
1705 if (!pvt
->pci_tad
[i
])
1711 sbridge_printk(KERN_ERR
, "Some needed devices are missing\n");
1715 sbridge_printk(KERN_ERR
, "Unexpected device %02x:%02x\n",
1716 PCI_VENDOR_ID_INTEL
, pdev
->device
);
1720 static int ibridge_mci_bind_devs(struct mem_ctl_info
*mci
,
1721 struct sbridge_dev
*sbridge_dev
)
1723 struct sbridge_pvt
*pvt
= mci
->pvt_info
;
1724 struct pci_dev
*pdev
;
1725 u8 saw_chan_mask
= 0;
1728 for (i
= 0; i
< sbridge_dev
->n_devs
; i
++) {
1729 pdev
= sbridge_dev
->pdev
[i
];
1733 switch (pdev
->device
) {
1734 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0
:
1735 pvt
->pci_ha0
= pdev
;
1737 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA
:
1739 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_RAS
:
1740 pvt
->pci_ras
= pdev
;
1742 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD0
:
1743 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD1
:
1744 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD2
:
1745 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD3
:
1747 int id
= pdev
->device
- PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD0
;
1748 pvt
->pci_tad
[id
] = pdev
;
1749 saw_chan_mask
|= 1 << id
;
1752 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_2HA_DDRIO0
:
1753 pvt
->pci_ddrio
= pdev
;
1755 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_1HA_DDRIO0
:
1756 pvt
->pci_ddrio
= pdev
;
1758 case PCI_DEVICE_ID_INTEL_IBRIDGE_SAD
:
1759 pvt
->pci_sad0
= pdev
;
1761 case PCI_DEVICE_ID_INTEL_IBRIDGE_BR0
:
1762 pvt
->pci_br0
= pdev
;
1764 case PCI_DEVICE_ID_INTEL_IBRIDGE_BR1
:
1765 pvt
->pci_br1
= pdev
;
1767 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1
:
1768 pvt
->pci_ha1
= pdev
;
1770 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD0
:
1771 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD1
:
1772 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD2
:
1773 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD3
:
1775 int id
= pdev
->device
- PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD0
+ 4;
1776 pvt
->pci_tad
[id
] = pdev
;
1777 saw_chan_mask
|= 1 << id
;
1784 edac_dbg(0, "Associated PCI %02x.%02d.%d with dev = %p\n",
1786 PCI_SLOT(pdev
->devfn
), PCI_FUNC(pdev
->devfn
),
1790 /* Check if everything were registered */
1791 if (!pvt
->pci_sad0
|| !pvt
->pci_ha0
|| !pvt
->pci_br0
||
1792 !pvt
->pci_br1
|| !pvt
->pci_tad
|| !pvt
->pci_ras
||
1796 if (saw_chan_mask
!= 0x0f && /* -EN */
1797 saw_chan_mask
!= 0x33 && /* -EP */
1798 saw_chan_mask
!= 0xff) /* -EX */
1803 sbridge_printk(KERN_ERR
, "Some needed devices are missing\n");
1807 sbridge_printk(KERN_ERR
,
1808 "Unexpected device %02x:%02x\n", PCI_VENDOR_ID_INTEL
,
1813 static int haswell_mci_bind_devs(struct mem_ctl_info
*mci
,
1814 struct sbridge_dev
*sbridge_dev
)
1816 struct sbridge_pvt
*pvt
= mci
->pvt_info
;
1817 struct pci_dev
*pdev
;
1818 u8 saw_chan_mask
= 0;
1821 /* there's only one device per system; not tied to any bus */
1822 if (pvt
->info
.pci_vtd
== NULL
)
1823 /* result will be checked later */
1824 pvt
->info
.pci_vtd
= pci_get_device(PCI_VENDOR_ID_INTEL
,
1825 PCI_DEVICE_ID_INTEL_HASWELL_IMC_VTD_MISC
,
1828 for (i
= 0; i
< sbridge_dev
->n_devs
; i
++) {
1829 pdev
= sbridge_dev
->pdev
[i
];
1833 switch (pdev
->device
) {
1834 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_CBO_SAD0
:
1835 pvt
->pci_sad0
= pdev
;
1837 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_CBO_SAD1
:
1838 pvt
->pci_sad1
= pdev
;
1840 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0
:
1841 pvt
->pci_ha0
= pdev
;
1843 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TA
:
1846 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_THERMAL
:
1847 pvt
->pci_ras
= pdev
;
1849 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD0
:
1850 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD1
:
1851 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD2
:
1852 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD3
:
1854 int id
= pdev
->device
- PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD0
;
1856 pvt
->pci_tad
[id
] = pdev
;
1857 saw_chan_mask
|= 1 << id
;
1860 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD0
:
1861 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD1
:
1862 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD2
:
1863 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD3
:
1865 int id
= pdev
->device
- PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD0
+ 4;
1867 pvt
->pci_tad
[id
] = pdev
;
1868 saw_chan_mask
|= 1 << id
;
1871 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO0
:
1872 pvt
->pci_ddrio
= pdev
;
1874 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1
:
1875 pvt
->pci_ha1
= pdev
;
1877 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TA
:
1878 pvt
->pci_ha1_ta
= pdev
;
1884 edac_dbg(0, "Associated PCI %02x.%02d.%d with dev = %p\n",
1886 PCI_SLOT(pdev
->devfn
), PCI_FUNC(pdev
->devfn
),
1890 /* Check if everything were registered */
1891 if (!pvt
->pci_sad0
|| !pvt
->pci_ha0
|| !pvt
->pci_sad1
||
1892 !pvt
->pci_ras
|| !pvt
->pci_ta
|| !pvt
->info
.pci_vtd
)
1895 if (saw_chan_mask
!= 0x0f && /* -EN */
1896 saw_chan_mask
!= 0x33 && /* -EP */
1897 saw_chan_mask
!= 0xff) /* -EX */
1902 sbridge_printk(KERN_ERR
, "Some needed devices are missing\n");
1906 static int broadwell_mci_bind_devs(struct mem_ctl_info
*mci
,
1907 struct sbridge_dev
*sbridge_dev
)
1909 struct sbridge_pvt
*pvt
= mci
->pvt_info
;
1910 struct pci_dev
*pdev
;
1911 u8 saw_chan_mask
= 0;
1914 /* there's only one device per system; not tied to any bus */
1915 if (pvt
->info
.pci_vtd
== NULL
)
1916 /* result will be checked later */
1917 pvt
->info
.pci_vtd
= pci_get_device(PCI_VENDOR_ID_INTEL
,
1918 PCI_DEVICE_ID_INTEL_BROADWELL_IMC_VTD_MISC
,
1921 for (i
= 0; i
< sbridge_dev
->n_devs
; i
++) {
1922 pdev
= sbridge_dev
->pdev
[i
];
1926 switch (pdev
->device
) {
1927 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_CBO_SAD0
:
1928 pvt
->pci_sad0
= pdev
;
1930 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_CBO_SAD1
:
1931 pvt
->pci_sad1
= pdev
;
1933 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0
:
1934 pvt
->pci_ha0
= pdev
;
1936 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TA
:
1939 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_THERMAL
:
1940 pvt
->pci_ras
= pdev
;
1942 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD0
:
1943 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD1
:
1944 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD2
:
1945 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD3
:
1947 int id
= pdev
->device
- PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD0
;
1948 pvt
->pci_tad
[id
] = pdev
;
1949 saw_chan_mask
|= 1 << id
;
1952 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD0
:
1953 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD1
:
1954 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD2
:
1955 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD3
:
1957 int id
= pdev
->device
- PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD0
+ 4;
1958 pvt
->pci_tad
[id
] = pdev
;
1959 saw_chan_mask
|= 1 << id
;
1962 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_DDRIO0
:
1963 pvt
->pci_ddrio
= pdev
;
1965 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1
:
1966 pvt
->pci_ha1
= pdev
;
1968 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TA
:
1969 pvt
->pci_ha1_ta
= pdev
;
1975 edac_dbg(0, "Associated PCI %02x.%02d.%d with dev = %p\n",
1977 PCI_SLOT(pdev
->devfn
), PCI_FUNC(pdev
->devfn
),
1981 /* Check if everything were registered */
1982 if (!pvt
->pci_sad0
|| !pvt
->pci_ha0
|| !pvt
->pci_sad1
||
1983 !pvt
->pci_ras
|| !pvt
->pci_ta
|| !pvt
->info
.pci_vtd
)
1986 if (saw_chan_mask
!= 0x0f && /* -EN */
1987 saw_chan_mask
!= 0x33 && /* -EP */
1988 saw_chan_mask
!= 0xff) /* -EX */
1993 sbridge_printk(KERN_ERR
, "Some needed devices are missing\n");
1997 /****************************************************************************
1998 Error check routines
1999 ****************************************************************************/
2002 * While Sandy Bridge has error count registers, SMI BIOS read values from
2003 * and resets the counters. So, they are not reliable for the OS to read
2004 * from them. So, we have no option but to just trust on whatever MCE is
2005 * telling us about the errors.
2007 static void sbridge_mce_output_error(struct mem_ctl_info
*mci
,
2008 const struct mce
*m
)
2010 struct mem_ctl_info
*new_mci
;
2011 struct sbridge_pvt
*pvt
= mci
->pvt_info
;
2012 enum hw_event_mc_err_type tp_event
;
2013 char *type
, *optype
, msg
[256];
2014 bool ripv
= GET_BITFIELD(m
->mcgstatus
, 0, 0);
2015 bool overflow
= GET_BITFIELD(m
->status
, 62, 62);
2016 bool uncorrected_error
= GET_BITFIELD(m
->status
, 61, 61);
2018 u32 core_err_cnt
= GET_BITFIELD(m
->status
, 38, 52);
2019 u32 mscod
= GET_BITFIELD(m
->status
, 16, 31);
2020 u32 errcode
= GET_BITFIELD(m
->status
, 0, 15);
2021 u32 channel
= GET_BITFIELD(m
->status
, 0, 3);
2022 u32 optypenum
= GET_BITFIELD(m
->status
, 4, 6);
2023 long channel_mask
, first_channel
;
2024 u8 rank
, socket
, ha
;
2026 char *area_type
= NULL
;
2028 if (pvt
->info
.type
!= SANDY_BRIDGE
)
2031 recoverable
= GET_BITFIELD(m
->status
, 56, 56);
2033 if (uncorrected_error
) {
2036 tp_event
= HW_EVENT_ERR_FATAL
;
2039 tp_event
= HW_EVENT_ERR_UNCORRECTED
;
2043 tp_event
= HW_EVENT_ERR_CORRECTED
;
2047 * According with Table 15-9 of the Intel Architecture spec vol 3A,
2048 * memory errors should fit in this mask:
2049 * 000f 0000 1mmm cccc (binary)
2051 * f = Correction Report Filtering Bit. If 1, subsequent errors
2055 * If the mask doesn't match, report an error to the parsing logic
2057 if (! ((errcode
& 0xef80) == 0x80)) {
2058 optype
= "Can't parse: it is not a mem";
2060 switch (optypenum
) {
2062 optype
= "generic undef request error";
2065 optype
= "memory read error";
2068 optype
= "memory write error";
2071 optype
= "addr/cmd error";
2074 optype
= "memory scrubbing error";
2077 optype
= "reserved";
2082 /* Only decode errors with an valid address (ADDRV) */
2083 if (!GET_BITFIELD(m
->status
, 58, 58))
2086 rc
= get_memory_error_data(mci
, m
->addr
, &socket
, &ha
,
2087 &channel_mask
, &rank
, &area_type
, msg
);
2090 new_mci
= get_mci_for_node_id(socket
);
2092 strcpy(msg
, "Error: socket got corrupted!");
2096 pvt
= mci
->pvt_info
;
2098 first_channel
= find_first_bit(&channel_mask
, NUM_CHANNELS
);
2109 * FIXME: On some memory configurations (mirror, lockstep), the
2110 * Memory Controller can't point the error to a single DIMM. The
2111 * EDAC core should be handling the channel mask, in order to point
2112 * to the group of dimm's where the error may be happening.
2114 if (!pvt
->is_lockstep
&& !pvt
->is_mirrored
&& !pvt
->is_close_pg
)
2115 channel
= first_channel
;
2117 snprintf(msg
, sizeof(msg
),
2118 "%s%s area:%s err_code:%04x:%04x socket:%d ha:%d channel_mask:%ld rank:%d",
2119 overflow
? " OVERFLOW" : "",
2120 (uncorrected_error
&& recoverable
) ? " recoverable" : "",
2127 edac_dbg(0, "%s\n", msg
);
2129 /* FIXME: need support for channel mask */
2131 if (channel
== CHANNEL_UNSPECIFIED
)
2134 /* Call the helper to output message */
2135 edac_mc_handle_error(tp_event
, mci
, core_err_cnt
,
2136 m
->addr
>> PAGE_SHIFT
, m
->addr
& ~PAGE_MASK
, 0,
2137 4*ha
+channel
, dimm
, -1,
2141 edac_mc_handle_error(tp_event
, mci
, core_err_cnt
, 0, 0, 0,
2148 * sbridge_check_error Retrieve and process errors reported by the
2149 * hardware. Called by the Core module.
2151 static void sbridge_check_error(struct mem_ctl_info
*mci
)
2153 struct sbridge_pvt
*pvt
= mci
->pvt_info
;
2159 * MCE first step: Copy all mce errors into a temporary buffer
2160 * We use a double buffering here, to reduce the risk of
2164 count
= (pvt
->mce_out
+ MCE_LOG_LEN
- pvt
->mce_in
)
2169 m
= pvt
->mce_outentry
;
2170 if (pvt
->mce_in
+ count
> MCE_LOG_LEN
) {
2171 unsigned l
= MCE_LOG_LEN
- pvt
->mce_in
;
2173 memcpy(m
, &pvt
->mce_entry
[pvt
->mce_in
], sizeof(*m
) * l
);
2179 memcpy(m
, &pvt
->mce_entry
[pvt
->mce_in
], sizeof(*m
) * count
);
2181 pvt
->mce_in
+= count
;
2184 if (pvt
->mce_overrun
) {
2185 sbridge_printk(KERN_ERR
, "Lost %d memory errors\n",
2188 pvt
->mce_overrun
= 0;
2192 * MCE second step: parse errors and display
2194 for (i
= 0; i
< count
; i
++)
2195 sbridge_mce_output_error(mci
, &pvt
->mce_outentry
[i
]);
2199 * sbridge_mce_check_error Replicates mcelog routine to get errors
2200 * This routine simply queues mcelog errors, and
2201 * return. The error itself should be handled later
2202 * by sbridge_check_error.
2203 * WARNING: As this routine should be called at NMI time, extra care should
2204 * be taken to avoid deadlocks, and to be as fast as possible.
2206 static int sbridge_mce_check_error(struct notifier_block
*nb
, unsigned long val
,
2209 struct mce
*mce
= (struct mce
*)data
;
2210 struct mem_ctl_info
*mci
;
2211 struct sbridge_pvt
*pvt
;
2214 if (get_edac_report_status() == EDAC_REPORTING_DISABLED
)
2217 mci
= get_mci_for_node_id(mce
->socketid
);
2220 pvt
= mci
->pvt_info
;
2223 * Just let mcelog handle it if the error is
2224 * outside the memory controller. A memory error
2225 * is indicated by bit 7 = 1 and bits = 8-11,13-15 = 0.
2226 * bit 12 has an special meaning.
2228 if ((mce
->status
& 0xefff) >> 7 != 1)
2231 if (mce
->mcgstatus
& MCG_STATUS_MCIP
)
2236 sbridge_mc_printk(mci
, KERN_DEBUG
, "HANDLING MCE MEMORY ERROR\n");
2238 sbridge_mc_printk(mci
, KERN_DEBUG
, "CPU %d: Machine Check %s: %Lx "
2239 "Bank %d: %016Lx\n", mce
->extcpu
, type
,
2240 mce
->mcgstatus
, mce
->bank
, mce
->status
);
2241 sbridge_mc_printk(mci
, KERN_DEBUG
, "TSC %llx ", mce
->tsc
);
2242 sbridge_mc_printk(mci
, KERN_DEBUG
, "ADDR %llx ", mce
->addr
);
2243 sbridge_mc_printk(mci
, KERN_DEBUG
, "MISC %llx ", mce
->misc
);
2245 sbridge_mc_printk(mci
, KERN_DEBUG
, "PROCESSOR %u:%x TIME %llu SOCKET "
2246 "%u APIC %x\n", mce
->cpuvendor
, mce
->cpuid
,
2247 mce
->time
, mce
->socketid
, mce
->apicid
);
2250 if ((pvt
->mce_out
+ 1) % MCE_LOG_LEN
== pvt
->mce_in
) {
2256 /* Copy memory error at the ringbuffer */
2257 memcpy(&pvt
->mce_entry
[pvt
->mce_out
], mce
, sizeof(*mce
));
2259 pvt
->mce_out
= (pvt
->mce_out
+ 1) % MCE_LOG_LEN
;
2261 /* Handle fatal errors immediately */
2262 if (mce
->mcgstatus
& 1)
2263 sbridge_check_error(mci
);
2265 /* Advice mcelog that the error were handled */
2269 static struct notifier_block sbridge_mce_dec
= {
2270 .notifier_call
= sbridge_mce_check_error
,
2273 /****************************************************************************
2274 EDAC register/unregister logic
2275 ****************************************************************************/
2277 static void sbridge_unregister_mci(struct sbridge_dev
*sbridge_dev
)
2279 struct mem_ctl_info
*mci
= sbridge_dev
->mci
;
2280 struct sbridge_pvt
*pvt
;
2282 if (unlikely(!mci
|| !mci
->pvt_info
)) {
2283 edac_dbg(0, "MC: dev = %p\n", &sbridge_dev
->pdev
[0]->dev
);
2285 sbridge_printk(KERN_ERR
, "Couldn't find mci handler\n");
2289 pvt
= mci
->pvt_info
;
2291 edac_dbg(0, "MC: mci = %p, dev = %p\n",
2292 mci
, &sbridge_dev
->pdev
[0]->dev
);
2294 /* Remove MC sysfs nodes */
2295 edac_mc_del_mc(mci
->pdev
);
2297 edac_dbg(1, "%s: free mci struct\n", mci
->ctl_name
);
2298 kfree(mci
->ctl_name
);
2300 sbridge_dev
->mci
= NULL
;
2303 static int sbridge_register_mci(struct sbridge_dev
*sbridge_dev
, enum type type
)
2305 struct mem_ctl_info
*mci
;
2306 struct edac_mc_layer layers
[2];
2307 struct sbridge_pvt
*pvt
;
2308 struct pci_dev
*pdev
= sbridge_dev
->pdev
[0];
2311 /* Check the number of active and not disabled channels */
2312 rc
= check_if_ecc_is_active(sbridge_dev
->bus
, type
);
2313 if (unlikely(rc
< 0))
2316 /* allocate a new MC control structure */
2317 layers
[0].type
= EDAC_MC_LAYER_CHANNEL
;
2318 layers
[0].size
= NUM_CHANNELS
;
2319 layers
[0].is_virt_csrow
= false;
2320 layers
[1].type
= EDAC_MC_LAYER_SLOT
;
2321 layers
[1].size
= MAX_DIMMS
;
2322 layers
[1].is_virt_csrow
= true;
2323 mci
= edac_mc_alloc(sbridge_dev
->mc
, ARRAY_SIZE(layers
), layers
,
2329 edac_dbg(0, "MC: mci = %p, dev = %p\n",
2332 pvt
= mci
->pvt_info
;
2333 memset(pvt
, 0, sizeof(*pvt
));
2335 /* Associate sbridge_dev and mci for future usage */
2336 pvt
->sbridge_dev
= sbridge_dev
;
2337 sbridge_dev
->mci
= mci
;
2339 mci
->mtype_cap
= MEM_FLAG_DDR3
;
2340 mci
->edac_ctl_cap
= EDAC_FLAG_NONE
;
2341 mci
->edac_cap
= EDAC_FLAG_NONE
;
2342 mci
->mod_name
= "sbridge_edac.c";
2343 mci
->mod_ver
= SBRIDGE_REVISION
;
2344 mci
->dev_name
= pci_name(pdev
);
2345 mci
->ctl_page_to_phys
= NULL
;
2347 /* Set the function pointer to an actual operation function */
2348 mci
->edac_check
= sbridge_check_error
;
2350 pvt
->info
.type
= type
;
2353 pvt
->info
.rankcfgr
= IB_RANK_CFG_A
;
2354 pvt
->info
.get_tolm
= ibridge_get_tolm
;
2355 pvt
->info
.get_tohm
= ibridge_get_tohm
;
2356 pvt
->info
.dram_rule
= ibridge_dram_rule
;
2357 pvt
->info
.get_memory_type
= get_memory_type
;
2358 pvt
->info
.get_node_id
= get_node_id
;
2359 pvt
->info
.rir_limit
= rir_limit
;
2360 pvt
->info
.max_sad
= ARRAY_SIZE(ibridge_dram_rule
);
2361 pvt
->info
.interleave_list
= ibridge_interleave_list
;
2362 pvt
->info
.max_interleave
= ARRAY_SIZE(ibridge_interleave_list
);
2363 pvt
->info
.interleave_pkg
= ibridge_interleave_pkg
;
2364 mci
->ctl_name
= kasprintf(GFP_KERNEL
, "Ivy Bridge Socket#%d", mci
->mc_idx
);
2366 /* Store pci devices at mci for faster access */
2367 rc
= ibridge_mci_bind_devs(mci
, sbridge_dev
);
2368 if (unlikely(rc
< 0))
2372 pvt
->info
.rankcfgr
= SB_RANK_CFG_A
;
2373 pvt
->info
.get_tolm
= sbridge_get_tolm
;
2374 pvt
->info
.get_tohm
= sbridge_get_tohm
;
2375 pvt
->info
.dram_rule
= sbridge_dram_rule
;
2376 pvt
->info
.get_memory_type
= get_memory_type
;
2377 pvt
->info
.get_node_id
= get_node_id
;
2378 pvt
->info
.rir_limit
= rir_limit
;
2379 pvt
->info
.max_sad
= ARRAY_SIZE(sbridge_dram_rule
);
2380 pvt
->info
.interleave_list
= sbridge_interleave_list
;
2381 pvt
->info
.max_interleave
= ARRAY_SIZE(sbridge_interleave_list
);
2382 pvt
->info
.interleave_pkg
= sbridge_interleave_pkg
;
2383 mci
->ctl_name
= kasprintf(GFP_KERNEL
, "Sandy Bridge Socket#%d", mci
->mc_idx
);
2385 /* Store pci devices at mci for faster access */
2386 rc
= sbridge_mci_bind_devs(mci
, sbridge_dev
);
2387 if (unlikely(rc
< 0))
2391 /* rankcfgr isn't used */
2392 pvt
->info
.get_tolm
= haswell_get_tolm
;
2393 pvt
->info
.get_tohm
= haswell_get_tohm
;
2394 pvt
->info
.dram_rule
= ibridge_dram_rule
;
2395 pvt
->info
.get_memory_type
= haswell_get_memory_type
;
2396 pvt
->info
.get_node_id
= haswell_get_node_id
;
2397 pvt
->info
.rir_limit
= haswell_rir_limit
;
2398 pvt
->info
.max_sad
= ARRAY_SIZE(ibridge_dram_rule
);
2399 pvt
->info
.interleave_list
= ibridge_interleave_list
;
2400 pvt
->info
.max_interleave
= ARRAY_SIZE(ibridge_interleave_list
);
2401 pvt
->info
.interleave_pkg
= ibridge_interleave_pkg
;
2402 mci
->ctl_name
= kasprintf(GFP_KERNEL
, "Haswell Socket#%d", mci
->mc_idx
);
2404 /* Store pci devices at mci for faster access */
2405 rc
= haswell_mci_bind_devs(mci
, sbridge_dev
);
2406 if (unlikely(rc
< 0))
2410 /* rankcfgr isn't used */
2411 pvt
->info
.get_tolm
= haswell_get_tolm
;
2412 pvt
->info
.get_tohm
= haswell_get_tohm
;
2413 pvt
->info
.dram_rule
= ibridge_dram_rule
;
2414 pvt
->info
.get_memory_type
= haswell_get_memory_type
;
2415 pvt
->info
.get_node_id
= haswell_get_node_id
;
2416 pvt
->info
.rir_limit
= haswell_rir_limit
;
2417 pvt
->info
.max_sad
= ARRAY_SIZE(ibridge_dram_rule
);
2418 pvt
->info
.interleave_list
= ibridge_interleave_list
;
2419 pvt
->info
.max_interleave
= ARRAY_SIZE(ibridge_interleave_list
);
2420 pvt
->info
.interleave_pkg
= ibridge_interleave_pkg
;
2421 mci
->ctl_name
= kasprintf(GFP_KERNEL
, "Broadwell Socket#%d", mci
->mc_idx
);
2423 /* Store pci devices at mci for faster access */
2424 rc
= broadwell_mci_bind_devs(mci
, sbridge_dev
);
2425 if (unlikely(rc
< 0))
2430 /* Get dimm basic config and the memory layout */
2431 get_dimm_config(mci
);
2432 get_memory_layout(mci
);
2434 /* record ptr to the generic device */
2435 mci
->pdev
= &pdev
->dev
;
2437 /* add this new MC control structure to EDAC's list of MCs */
2438 if (unlikely(edac_mc_add_mc(mci
))) {
2439 edac_dbg(0, "MC: failed edac_mc_add_mc()\n");
2447 kfree(mci
->ctl_name
);
2449 sbridge_dev
->mci
= NULL
;
2454 * sbridge_probe Probe for ONE instance of device to see if it is
2457 * 0 for FOUND a device
2458 * < 0 for error code
2461 static int sbridge_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
2465 struct sbridge_dev
*sbridge_dev
;
2466 enum type type
= SANDY_BRIDGE
;
2468 /* get the pci devices we want to reserve for our use */
2469 mutex_lock(&sbridge_edac_lock
);
2472 * All memory controllers are allocated at the first pass.
2474 if (unlikely(probed
>= 1)) {
2475 mutex_unlock(&sbridge_edac_lock
);
2480 switch (pdev
->device
) {
2481 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA
:
2482 rc
= sbridge_get_all_devices(&num_mc
, pci_dev_descr_ibridge_table
);
2485 case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_HA0
:
2486 rc
= sbridge_get_all_devices(&num_mc
, pci_dev_descr_sbridge_table
);
2487 type
= SANDY_BRIDGE
;
2489 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0
:
2490 rc
= sbridge_get_all_devices(&num_mc
, pci_dev_descr_haswell_table
);
2493 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0
:
2494 rc
= sbridge_get_all_devices(&num_mc
, pci_dev_descr_broadwell_table
);
2498 if (unlikely(rc
< 0)) {
2499 edac_dbg(0, "couldn't get all devices for 0x%x\n", pdev
->device
);
2505 list_for_each_entry(sbridge_dev
, &sbridge_edac_list
, list
) {
2506 edac_dbg(0, "Registering MC#%d (%d of %d)\n",
2507 mc
, mc
+ 1, num_mc
);
2509 sbridge_dev
->mc
= mc
++;
2510 rc
= sbridge_register_mci(sbridge_dev
, type
);
2511 if (unlikely(rc
< 0))
2515 sbridge_printk(KERN_INFO
, "%s\n", SBRIDGE_REVISION
);
2517 mutex_unlock(&sbridge_edac_lock
);
2521 list_for_each_entry(sbridge_dev
, &sbridge_edac_list
, list
)
2522 sbridge_unregister_mci(sbridge_dev
);
2524 sbridge_put_all_devices();
2526 mutex_unlock(&sbridge_edac_lock
);
2531 * sbridge_remove destructor for one instance of device
2534 static void sbridge_remove(struct pci_dev
*pdev
)
2536 struct sbridge_dev
*sbridge_dev
;
2541 * we have a trouble here: pdev value for removal will be wrong, since
2542 * it will point to the X58 register used to detect that the machine
2543 * is a Nehalem or upper design. However, due to the way several PCI
2544 * devices are grouped together to provide MC functionality, we need
2545 * to use a different method for releasing the devices
2548 mutex_lock(&sbridge_edac_lock
);
2550 if (unlikely(!probed
)) {
2551 mutex_unlock(&sbridge_edac_lock
);
2555 list_for_each_entry(sbridge_dev
, &sbridge_edac_list
, list
)
2556 sbridge_unregister_mci(sbridge_dev
);
2558 /* Release PCI resources */
2559 sbridge_put_all_devices();
2563 mutex_unlock(&sbridge_edac_lock
);
2566 MODULE_DEVICE_TABLE(pci
, sbridge_pci_tbl
);
2569 * sbridge_driver pci_driver structure for this module
2572 static struct pci_driver sbridge_driver
= {
2573 .name
= "sbridge_edac",
2574 .probe
= sbridge_probe
,
2575 .remove
= sbridge_remove
,
2576 .id_table
= sbridge_pci_tbl
,
2580 * sbridge_init Module entry function
2581 * Try to initialize this module for its devices
2583 static int __init
sbridge_init(void)
2589 /* Ensure that the OPSTATE is set correctly for POLL or NMI */
2592 pci_rc
= pci_register_driver(&sbridge_driver
);
2594 mce_register_decode_chain(&sbridge_mce_dec
);
2595 if (get_edac_report_status() == EDAC_REPORTING_DISABLED
)
2596 sbridge_printk(KERN_WARNING
, "Loading driver, error reporting disabled.\n");
2600 sbridge_printk(KERN_ERR
, "Failed to register device with error %d.\n",
2607 * sbridge_exit() Module exit function
2608 * Unregister the driver
2610 static void __exit
sbridge_exit(void)
2613 pci_unregister_driver(&sbridge_driver
);
2614 mce_unregister_decode_chain(&sbridge_mce_dec
);
2617 module_init(sbridge_init
);
2618 module_exit(sbridge_exit
);
2620 module_param(edac_op_state
, int, 0444);
2621 MODULE_PARM_DESC(edac_op_state
, "EDAC Error Reporting state: 0=Poll,1=NMI");
2623 MODULE_LICENSE("GPL");
2624 MODULE_AUTHOR("Mauro Carvalho Chehab");
2625 MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
2626 MODULE_DESCRIPTION("MC Driver for Intel Sandy Bridge and Ivy Bridge memory controllers - "