1 /* Intel i7 core/Nehalem Memory Controller kernel module
3 * This driver supports the memory controllers found on the Intel
4 * processor families i7core, i7core 7xx/8xx, i5core, Xeon 35xx,
5 * Xeon 55xx and Xeon 56xx also known as Nehalem, Nehalem-EP, Lynnfield
8 * This file may be distributed under the terms of the
9 * GNU General Public License version 2 only.
11 * Copyright (c) 2009-2010 by:
12 * Mauro Carvalho Chehab <mchehab@redhat.com>
14 * Red Hat Inc. http://www.redhat.com
16 * Forked and adapted from the i5400_edac driver
18 * Based on the following public Intel datasheets:
19 * Intel Core i7 Processor Extreme Edition and Intel Core i7 Processor
20 * Datasheet, Volume 2:
21 * http://download.intel.com/design/processor/datashts/320835.pdf
22 * Intel Xeon Processor 5500 Series Datasheet Volume 2
23 * http://www.intel.com/Assets/PDF/datasheet/321322.pdf
25 * http://www.arrownac.com/manufacturers/intel/s/nehalem/5500-datasheet-v2.pdf
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/pci.h>
31 #include <linux/pci_ids.h>
32 #include <linux/slab.h>
33 #include <linux/delay.h>
34 #include <linux/dmi.h>
35 #include <linux/edac.h>
36 #include <linux/mmzone.h>
37 #include <linux/smp.h>
39 #include <asm/processor.h>
41 #include "edac_core.h"
44 static LIST_HEAD(i7core_edac_list
);
45 static DEFINE_MUTEX(i7core_edac_lock
);
48 static int use_pci_fixup
;
49 module_param(use_pci_fixup
, int, 0444);
50 MODULE_PARM_DESC(use_pci_fixup
, "Enable PCI fixup to seek for hidden devices");
52 * This is used for Nehalem-EP and Nehalem-EX devices, where the non-core
53 * registers start at bus 255, and are not reported by BIOS.
54 * We currently find devices with only 2 sockets. In order to support more QPI
55 * Quick Path Interconnect, just increment this number.
57 #define MAX_SOCKET_BUSES 2
61 * Alter this version for the module when modifications are made
63 #define I7CORE_REVISION " Ver: 1.0.0"
64 #define EDAC_MOD_STR "i7core_edac"
69 #define i7core_printk(level, fmt, arg...) \
70 edac_printk(level, "i7core", fmt, ##arg)
72 #define i7core_mc_printk(mci, level, fmt, arg...) \
73 edac_mc_chipset_printk(mci, level, "i7core", fmt, ##arg)
76 * i7core Memory Controller Registers
79 /* OFFSETS for Device 0 Function 0 */
81 #define MC_CFG_CONTROL 0x90
82 #define MC_CFG_UNLOCK 0x02
83 #define MC_CFG_LOCK 0x00
85 /* OFFSETS for Device 3 Function 0 */
87 #define MC_CONTROL 0x48
88 #define MC_STATUS 0x4c
89 #define MC_MAX_DOD 0x64
92 * OFFSETS for Device 3 Function 4, as inicated on Xeon 5500 datasheet:
93 * http://www.arrownac.com/manufacturers/intel/s/nehalem/5500-datasheet-v2.pdf
96 #define MC_TEST_ERR_RCV1 0x60
97 #define DIMM2_COR_ERR(r) ((r) & 0x7fff)
99 #define MC_TEST_ERR_RCV0 0x64
100 #define DIMM1_COR_ERR(r) (((r) >> 16) & 0x7fff)
101 #define DIMM0_COR_ERR(r) ((r) & 0x7fff)
103 /* OFFSETS for Device 3 Function 2, as inicated on Xeon 5500 datasheet */
104 #define MC_SSRCONTROL 0x48
105 #define SSR_MODE_DISABLE 0x00
106 #define SSR_MODE_ENABLE 0x01
107 #define SSR_MODE_MASK 0x03
109 #define MC_SCRUB_CONTROL 0x4c
110 #define STARTSCRUB (1 << 24)
111 #define SCRUBINTERVAL_MASK 0xffffff
113 #define MC_COR_ECC_CNT_0 0x80
114 #define MC_COR_ECC_CNT_1 0x84
115 #define MC_COR_ECC_CNT_2 0x88
116 #define MC_COR_ECC_CNT_3 0x8c
117 #define MC_COR_ECC_CNT_4 0x90
118 #define MC_COR_ECC_CNT_5 0x94
120 #define DIMM_TOP_COR_ERR(r) (((r) >> 16) & 0x7fff)
121 #define DIMM_BOT_COR_ERR(r) ((r) & 0x7fff)
124 /* OFFSETS for Devices 4,5 and 6 Function 0 */
126 #define MC_CHANNEL_DIMM_INIT_PARAMS 0x58
127 #define THREE_DIMMS_PRESENT (1 << 24)
128 #define SINGLE_QUAD_RANK_PRESENT (1 << 23)
129 #define QUAD_RANK_PRESENT (1 << 22)
130 #define REGISTERED_DIMM (1 << 15)
132 #define MC_CHANNEL_MAPPER 0x60
133 #define RDLCH(r, ch) ((((r) >> (3 + (ch * 6))) & 0x07) - 1)
134 #define WRLCH(r, ch) ((((r) >> (ch * 6)) & 0x07) - 1)
136 #define MC_CHANNEL_RANK_PRESENT 0x7c
137 #define RANK_PRESENT_MASK 0xffff
139 #define MC_CHANNEL_ADDR_MATCH 0xf0
140 #define MC_CHANNEL_ERROR_MASK 0xf8
141 #define MC_CHANNEL_ERROR_INJECT 0xfc
142 #define INJECT_ADDR_PARITY 0x10
143 #define INJECT_ECC 0x08
144 #define MASK_CACHELINE 0x06
145 #define MASK_FULL_CACHELINE 0x06
146 #define MASK_MSB32_CACHELINE 0x04
147 #define MASK_LSB32_CACHELINE 0x02
148 #define NO_MASK_CACHELINE 0x00
149 #define REPEAT_EN 0x01
151 /* OFFSETS for Devices 4,5 and 6 Function 1 */
153 #define MC_DOD_CH_DIMM0 0x48
154 #define MC_DOD_CH_DIMM1 0x4c
155 #define MC_DOD_CH_DIMM2 0x50
156 #define RANKOFFSET_MASK ((1 << 12) | (1 << 11) | (1 << 10))
157 #define RANKOFFSET(x) ((x & RANKOFFSET_MASK) >> 10)
158 #define DIMM_PRESENT_MASK (1 << 9)
159 #define DIMM_PRESENT(x) (((x) & DIMM_PRESENT_MASK) >> 9)
160 #define MC_DOD_NUMBANK_MASK ((1 << 8) | (1 << 7))
161 #define MC_DOD_NUMBANK(x) (((x) & MC_DOD_NUMBANK_MASK) >> 7)
162 #define MC_DOD_NUMRANK_MASK ((1 << 6) | (1 << 5))
163 #define MC_DOD_NUMRANK(x) (((x) & MC_DOD_NUMRANK_MASK) >> 5)
164 #define MC_DOD_NUMROW_MASK ((1 << 4) | (1 << 3) | (1 << 2))
165 #define MC_DOD_NUMROW(x) (((x) & MC_DOD_NUMROW_MASK) >> 2)
166 #define MC_DOD_NUMCOL_MASK 3
167 #define MC_DOD_NUMCOL(x) ((x) & MC_DOD_NUMCOL_MASK)
169 #define MC_RANK_PRESENT 0x7c
171 #define MC_SAG_CH_0 0x80
172 #define MC_SAG_CH_1 0x84
173 #define MC_SAG_CH_2 0x88
174 #define MC_SAG_CH_3 0x8c
175 #define MC_SAG_CH_4 0x90
176 #define MC_SAG_CH_5 0x94
177 #define MC_SAG_CH_6 0x98
178 #define MC_SAG_CH_7 0x9c
180 #define MC_RIR_LIMIT_CH_0 0x40
181 #define MC_RIR_LIMIT_CH_1 0x44
182 #define MC_RIR_LIMIT_CH_2 0x48
183 #define MC_RIR_LIMIT_CH_3 0x4C
184 #define MC_RIR_LIMIT_CH_4 0x50
185 #define MC_RIR_LIMIT_CH_5 0x54
186 #define MC_RIR_LIMIT_CH_6 0x58
187 #define MC_RIR_LIMIT_CH_7 0x5C
188 #define MC_RIR_LIMIT_MASK ((1 << 10) - 1)
190 #define MC_RIR_WAY_CH 0x80
191 #define MC_RIR_WAY_OFFSET_MASK (((1 << 14) - 1) & ~0x7)
192 #define MC_RIR_WAY_RANK_MASK 0x7
199 #define MAX_DIMMS 3 /* Max DIMMS per channel */
200 #define MAX_MCR_FUNC 4
201 #define MAX_CHAN_FUNC 3
211 struct i7core_inject
{
218 /* Error address mask */
219 int channel
, dimm
, rank
, bank
, page
, col
;
222 struct i7core_channel
{
227 struct pci_id_descr
{
234 struct pci_id_table
{
235 const struct pci_id_descr
*descr
;
240 struct list_head list
;
242 struct pci_dev
**pdev
;
244 struct mem_ctl_info
*mci
;
248 struct pci_dev
*pci_noncore
;
249 struct pci_dev
*pci_mcr
[MAX_MCR_FUNC
+ 1];
250 struct pci_dev
*pci_ch
[NUM_CHANS
][MAX_CHAN_FUNC
+ 1];
252 struct i7core_dev
*i7core_dev
;
254 struct i7core_info info
;
255 struct i7core_inject inject
;
256 struct i7core_channel channel
[NUM_CHANS
];
258 int ce_count_available
;
259 int csrow_map
[NUM_CHANS
][MAX_DIMMS
];
261 /* ECC corrected errors counts per udimm */
262 unsigned long udimm_ce_count
[MAX_DIMMS
];
263 int udimm_last_ce_count
[MAX_DIMMS
];
264 /* ECC corrected errors counts per rdimm */
265 unsigned long rdimm_ce_count
[NUM_CHANS
][MAX_DIMMS
];
266 int rdimm_last_ce_count
[NUM_CHANS
][MAX_DIMMS
];
268 bool is_registered
, enable_scrub
;
270 /* Fifo double buffers */
271 struct mce mce_entry
[MCE_LOG_LEN
];
272 struct mce mce_outentry
[MCE_LOG_LEN
];
274 /* Fifo in/out counters */
275 unsigned mce_in
, mce_out
;
277 /* Count indicator to show errors not got */
278 unsigned mce_overrun
;
280 /* DCLK Frequency used for computing scrub rate */
283 /* Struct to control EDAC polling */
284 struct edac_pci_ctl_info
*i7core_pci
;
287 #define PCI_DESCR(device, function, device_id) \
289 .func = (function), \
290 .dev_id = (device_id)
292 static const struct pci_id_descr pci_dev_descr_i7core_nehalem
[] = {
293 /* Memory controller */
294 { PCI_DESCR(3, 0, PCI_DEVICE_ID_INTEL_I7_MCR
) },
295 { PCI_DESCR(3, 1, PCI_DEVICE_ID_INTEL_I7_MC_TAD
) },
296 /* Exists only for RDIMM */
297 { PCI_DESCR(3, 2, PCI_DEVICE_ID_INTEL_I7_MC_RAS
), .optional
= 1 },
298 { PCI_DESCR(3, 4, PCI_DEVICE_ID_INTEL_I7_MC_TEST
) },
301 { PCI_DESCR(4, 0, PCI_DEVICE_ID_INTEL_I7_MC_CH0_CTRL
) },
302 { PCI_DESCR(4, 1, PCI_DEVICE_ID_INTEL_I7_MC_CH0_ADDR
) },
303 { PCI_DESCR(4, 2, PCI_DEVICE_ID_INTEL_I7_MC_CH0_RANK
) },
304 { PCI_DESCR(4, 3, PCI_DEVICE_ID_INTEL_I7_MC_CH0_TC
) },
307 { PCI_DESCR(5, 0, PCI_DEVICE_ID_INTEL_I7_MC_CH1_CTRL
) },
308 { PCI_DESCR(5, 1, PCI_DEVICE_ID_INTEL_I7_MC_CH1_ADDR
) },
309 { PCI_DESCR(5, 2, PCI_DEVICE_ID_INTEL_I7_MC_CH1_RANK
) },
310 { PCI_DESCR(5, 3, PCI_DEVICE_ID_INTEL_I7_MC_CH1_TC
) },
313 { PCI_DESCR(6, 0, PCI_DEVICE_ID_INTEL_I7_MC_CH2_CTRL
) },
314 { PCI_DESCR(6, 1, PCI_DEVICE_ID_INTEL_I7_MC_CH2_ADDR
) },
315 { PCI_DESCR(6, 2, PCI_DEVICE_ID_INTEL_I7_MC_CH2_RANK
) },
316 { PCI_DESCR(6, 3, PCI_DEVICE_ID_INTEL_I7_MC_CH2_TC
) },
318 /* Generic Non-core registers */
320 * This is the PCI device on i7core and on Xeon 35xx (8086:2c41)
321 * On Xeon 55xx, however, it has a different id (8086:2c40). So,
322 * the probing code needs to test for the other address in case of
323 * failure of this one
325 { PCI_DESCR(0, 0, PCI_DEVICE_ID_INTEL_I7_NONCORE
) },
329 static const struct pci_id_descr pci_dev_descr_lynnfield
[] = {
330 { PCI_DESCR( 3, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_MCR
) },
331 { PCI_DESCR( 3, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_TAD
) },
332 { PCI_DESCR( 3, 4, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_TEST
) },
334 { PCI_DESCR( 4, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_CTRL
) },
335 { PCI_DESCR( 4, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_ADDR
) },
336 { PCI_DESCR( 4, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_RANK
) },
337 { PCI_DESCR( 4, 3, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_TC
) },
339 { PCI_DESCR( 5, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_CTRL
) },
340 { PCI_DESCR( 5, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_ADDR
) },
341 { PCI_DESCR( 5, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_RANK
) },
342 { PCI_DESCR( 5, 3, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_TC
) },
345 * This is the PCI device has an alternate address on some
346 * processors like Core i7 860
348 { PCI_DESCR( 0, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE
) },
351 static const struct pci_id_descr pci_dev_descr_i7core_westmere
[] = {
352 /* Memory controller */
353 { PCI_DESCR(3, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_MCR_REV2
) },
354 { PCI_DESCR(3, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_TAD_REV2
) },
355 /* Exists only for RDIMM */
356 { PCI_DESCR(3, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_RAS_REV2
), .optional
= 1 },
357 { PCI_DESCR(3, 4, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_TEST_REV2
) },
360 { PCI_DESCR(4, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_CTRL_REV2
) },
361 { PCI_DESCR(4, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_ADDR_REV2
) },
362 { PCI_DESCR(4, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_RANK_REV2
) },
363 { PCI_DESCR(4, 3, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_TC_REV2
) },
366 { PCI_DESCR(5, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_CTRL_REV2
) },
367 { PCI_DESCR(5, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_ADDR_REV2
) },
368 { PCI_DESCR(5, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_RANK_REV2
) },
369 { PCI_DESCR(5, 3, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_TC_REV2
) },
372 { PCI_DESCR(6, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH2_CTRL_REV2
) },
373 { PCI_DESCR(6, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH2_ADDR_REV2
) },
374 { PCI_DESCR(6, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH2_RANK_REV2
) },
375 { PCI_DESCR(6, 3, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH2_TC_REV2
) },
377 /* Generic Non-core registers */
378 { PCI_DESCR(0, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE_REV2
) },
382 #define PCI_ID_TABLE_ENTRY(A) { .descr=A, .n_devs = ARRAY_SIZE(A) }
383 static const struct pci_id_table pci_dev_table
[] = {
384 PCI_ID_TABLE_ENTRY(pci_dev_descr_i7core_nehalem
),
385 PCI_ID_TABLE_ENTRY(pci_dev_descr_lynnfield
),
386 PCI_ID_TABLE_ENTRY(pci_dev_descr_i7core_westmere
),
387 {0,} /* 0 terminated list. */
391 * pci_device_id table for which devices we are looking for
393 static const struct pci_device_id i7core_pci_tbl
[] __devinitdata
= {
394 {PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_X58_HUB_MGMT
)},
395 {PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_LYNNFIELD_QPI_LINK0
)},
396 {0,} /* 0 terminated list. */
399 /****************************************************************************
400 Anciliary status routines
401 ****************************************************************************/
403 /* MC_CONTROL bits */
404 #define CH_ACTIVE(pvt, ch) ((pvt)->info.mc_control & (1 << (8 + ch)))
405 #define ECCx8(pvt) ((pvt)->info.mc_control & (1 << 1))
408 #define ECC_ENABLED(pvt) ((pvt)->info.mc_status & (1 << 4))
409 #define CH_DISABLED(pvt, ch) ((pvt)->info.mc_status & (1 << ch))
411 /* MC_MAX_DOD read functions */
412 static inline int numdimms(u32 dimms
)
414 return (dimms
& 0x3) + 1;
417 static inline int numrank(u32 rank
)
419 static int ranks
[4] = { 1, 2, 4, -EINVAL
};
421 return ranks
[rank
& 0x3];
424 static inline int numbank(u32 bank
)
426 static int banks
[4] = { 4, 8, 16, -EINVAL
};
428 return banks
[bank
& 0x3];
431 static inline int numrow(u32 row
)
433 static int rows
[8] = {
434 1 << 12, 1 << 13, 1 << 14, 1 << 15,
435 1 << 16, -EINVAL
, -EINVAL
, -EINVAL
,
438 return rows
[row
& 0x7];
441 static inline int numcol(u32 col
)
443 static int cols
[8] = {
444 1 << 10, 1 << 11, 1 << 12, -EINVAL
,
446 return cols
[col
& 0x3];
449 static struct i7core_dev
*get_i7core_dev(u8 socket
)
451 struct i7core_dev
*i7core_dev
;
453 list_for_each_entry(i7core_dev
, &i7core_edac_list
, list
) {
454 if (i7core_dev
->socket
== socket
)
461 static struct i7core_dev
*alloc_i7core_dev(u8 socket
,
462 const struct pci_id_table
*table
)
464 struct i7core_dev
*i7core_dev
;
466 i7core_dev
= kzalloc(sizeof(*i7core_dev
), GFP_KERNEL
);
470 i7core_dev
->pdev
= kzalloc(sizeof(*i7core_dev
->pdev
) * table
->n_devs
,
472 if (!i7core_dev
->pdev
) {
477 i7core_dev
->socket
= socket
;
478 i7core_dev
->n_devs
= table
->n_devs
;
479 list_add_tail(&i7core_dev
->list
, &i7core_edac_list
);
484 static void free_i7core_dev(struct i7core_dev
*i7core_dev
)
486 list_del(&i7core_dev
->list
);
487 kfree(i7core_dev
->pdev
);
491 /****************************************************************************
492 Memory check routines
493 ****************************************************************************/
494 static struct pci_dev
*get_pdev_slot_func(u8 socket
, unsigned slot
,
497 struct i7core_dev
*i7core_dev
= get_i7core_dev(socket
);
503 for (i
= 0; i
< i7core_dev
->n_devs
; i
++) {
504 if (!i7core_dev
->pdev
[i
])
507 if (PCI_SLOT(i7core_dev
->pdev
[i
]->devfn
) == slot
&&
508 PCI_FUNC(i7core_dev
->pdev
[i
]->devfn
) == func
) {
509 return i7core_dev
->pdev
[i
];
517 * i7core_get_active_channels() - gets the number of channels and csrows
518 * @socket: Quick Path Interconnect socket
519 * @channels: Number of channels that will be returned
520 * @csrows: Number of csrows found
522 * Since EDAC core needs to know in advance the number of available channels
523 * and csrows, in order to allocate memory for csrows/channels, it is needed
524 * to run two similar steps. At the first step, implemented on this function,
525 * it checks the number of csrows/channels present at one socket.
526 * this is used in order to properly allocate the size of mci components.
528 * It should be noticed that none of the current available datasheets explain
529 * or even mention how csrows are seen by the memory controller. So, we need
530 * to add a fake description for csrows.
531 * So, this driver is attributing one DIMM memory for one csrow.
533 static int i7core_get_active_channels(const u8 socket
, unsigned *channels
,
536 struct pci_dev
*pdev
= NULL
;
543 pdev
= get_pdev_slot_func(socket
, 3, 0);
545 i7core_printk(KERN_ERR
, "Couldn't find socket %d fn 3.0!!!\n",
550 /* Device 3 function 0 reads */
551 pci_read_config_dword(pdev
, MC_STATUS
, &status
);
552 pci_read_config_dword(pdev
, MC_CONTROL
, &control
);
554 for (i
= 0; i
< NUM_CHANS
; i
++) {
556 /* Check if the channel is active */
557 if (!(control
& (1 << (8 + i
))))
560 /* Check if the channel is disabled */
561 if (status
& (1 << i
))
564 pdev
= get_pdev_slot_func(socket
, i
+ 4, 1);
566 i7core_printk(KERN_ERR
, "Couldn't find socket %d "
571 /* Devices 4-6 function 1 */
572 pci_read_config_dword(pdev
,
573 MC_DOD_CH_DIMM0
, &dimm_dod
[0]);
574 pci_read_config_dword(pdev
,
575 MC_DOD_CH_DIMM1
, &dimm_dod
[1]);
576 pci_read_config_dword(pdev
,
577 MC_DOD_CH_DIMM2
, &dimm_dod
[2]);
581 for (j
= 0; j
< 3; j
++) {
582 if (!DIMM_PRESENT(dimm_dod
[j
]))
588 debugf0("Number of active channels on socket %d: %d\n",
594 static int get_dimm_config(const struct mem_ctl_info
*mci
)
596 struct i7core_pvt
*pvt
= mci
->pvt_info
;
597 struct csrow_info
*csr
;
598 struct pci_dev
*pdev
;
601 unsigned long last_page
= 0;
605 /* Get data from the MC register, function 0 */
606 pdev
= pvt
->pci_mcr
[0];
610 /* Device 3 function 0 reads */
611 pci_read_config_dword(pdev
, MC_CONTROL
, &pvt
->info
.mc_control
);
612 pci_read_config_dword(pdev
, MC_STATUS
, &pvt
->info
.mc_status
);
613 pci_read_config_dword(pdev
, MC_MAX_DOD
, &pvt
->info
.max_dod
);
614 pci_read_config_dword(pdev
, MC_CHANNEL_MAPPER
, &pvt
->info
.ch_map
);
616 debugf0("QPI %d control=0x%08x status=0x%08x dod=0x%08x map=0x%08x\n",
617 pvt
->i7core_dev
->socket
, pvt
->info
.mc_control
, pvt
->info
.mc_status
,
618 pvt
->info
.max_dod
, pvt
->info
.ch_map
);
620 if (ECC_ENABLED(pvt
)) {
621 debugf0("ECC enabled with x%d SDCC\n", ECCx8(pvt
) ? 8 : 4);
623 mode
= EDAC_S8ECD8ED
;
625 mode
= EDAC_S4ECD4ED
;
627 debugf0("ECC disabled\n");
631 /* FIXME: need to handle the error codes */
632 debugf0("DOD Max limits: DIMMS: %d, %d-ranked, %d-banked "
634 numdimms(pvt
->info
.max_dod
),
635 numrank(pvt
->info
.max_dod
>> 2),
636 numbank(pvt
->info
.max_dod
>> 4),
637 numrow(pvt
->info
.max_dod
>> 6),
638 numcol(pvt
->info
.max_dod
>> 9));
640 for (i
= 0; i
< NUM_CHANS
; i
++) {
641 u32 data
, dimm_dod
[3], value
[8];
643 if (!pvt
->pci_ch
[i
][0])
646 if (!CH_ACTIVE(pvt
, i
)) {
647 debugf0("Channel %i is not active\n", i
);
650 if (CH_DISABLED(pvt
, i
)) {
651 debugf0("Channel %i is disabled\n", i
);
655 /* Devices 4-6 function 0 */
656 pci_read_config_dword(pvt
->pci_ch
[i
][0],
657 MC_CHANNEL_DIMM_INIT_PARAMS
, &data
);
659 pvt
->channel
[i
].ranks
= (data
& QUAD_RANK_PRESENT
) ?
662 if (data
& REGISTERED_DIMM
)
667 if (data
& THREE_DIMMS_PRESENT
)
668 pvt
->channel
[i
].dimms
= 3;
669 else if (data
& SINGLE_QUAD_RANK_PRESENT
)
670 pvt
->channel
[i
].dimms
= 1;
672 pvt
->channel
[i
].dimms
= 2;
675 /* Devices 4-6 function 1 */
676 pci_read_config_dword(pvt
->pci_ch
[i
][1],
677 MC_DOD_CH_DIMM0
, &dimm_dod
[0]);
678 pci_read_config_dword(pvt
->pci_ch
[i
][1],
679 MC_DOD_CH_DIMM1
, &dimm_dod
[1]);
680 pci_read_config_dword(pvt
->pci_ch
[i
][1],
681 MC_DOD_CH_DIMM2
, &dimm_dod
[2]);
683 debugf0("Ch%d phy rd%d, wr%d (0x%08x): "
684 "%d ranks, %cDIMMs\n",
686 RDLCH(pvt
->info
.ch_map
, i
), WRLCH(pvt
->info
.ch_map
, i
),
688 pvt
->channel
[i
].ranks
,
689 (data
& REGISTERED_DIMM
) ? 'R' : 'U');
691 for (j
= 0; j
< 3; j
++) {
692 u32 banks
, ranks
, rows
, cols
;
695 if (!DIMM_PRESENT(dimm_dod
[j
]))
698 banks
= numbank(MC_DOD_NUMBANK(dimm_dod
[j
]));
699 ranks
= numrank(MC_DOD_NUMRANK(dimm_dod
[j
]));
700 rows
= numrow(MC_DOD_NUMROW(dimm_dod
[j
]));
701 cols
= numcol(MC_DOD_NUMCOL(dimm_dod
[j
]));
703 /* DDR3 has 8 I/O banks */
704 size
= (rows
* cols
* banks
* ranks
) >> (20 - 3);
706 pvt
->channel
[i
].dimms
++;
708 debugf0("\tdimm %d %d Mb offset: %x, "
709 "bank: %d, rank: %d, row: %#x, col: %#x\n",
711 RANKOFFSET(dimm_dod
[j
]),
712 banks
, ranks
, rows
, cols
);
714 npages
= MiB_TO_PAGES(size
);
716 csr
= &mci
->csrows
[csrow
];
717 csr
->first_page
= last_page
+ 1;
719 csr
->last_page
= last_page
;
720 csr
->nr_pages
= npages
;
724 csr
->csrow_idx
= csrow
;
725 csr
->nr_channels
= 1;
727 csr
->channels
[0].chan_idx
= i
;
728 csr
->channels
[0].ce_count
= 0;
730 pvt
->csrow_map
[i
][j
] = csrow
;
740 csr
->dtype
= DEV_X16
;
743 csr
->dtype
= DEV_UNKNOWN
;
746 csr
->edac_mode
= mode
;
752 pci_read_config_dword(pdev
, MC_SAG_CH_0
, &value
[0]);
753 pci_read_config_dword(pdev
, MC_SAG_CH_1
, &value
[1]);
754 pci_read_config_dword(pdev
, MC_SAG_CH_2
, &value
[2]);
755 pci_read_config_dword(pdev
, MC_SAG_CH_3
, &value
[3]);
756 pci_read_config_dword(pdev
, MC_SAG_CH_4
, &value
[4]);
757 pci_read_config_dword(pdev
, MC_SAG_CH_5
, &value
[5]);
758 pci_read_config_dword(pdev
, MC_SAG_CH_6
, &value
[6]);
759 pci_read_config_dword(pdev
, MC_SAG_CH_7
, &value
[7]);
760 debugf1("\t[%i] DIVBY3\tREMOVED\tOFFSET\n", i
);
761 for (j
= 0; j
< 8; j
++)
762 debugf1("\t\t%#x\t%#x\t%#x\n",
763 (value
[j
] >> 27) & 0x1,
764 (value
[j
] >> 24) & 0x7,
765 (value
[j
] & ((1 << 24) - 1)));
771 /****************************************************************************
772 Error insertion routines
773 ****************************************************************************/
775 /* The i7core has independent error injection features per channel.
776 However, to have a simpler code, we don't allow enabling error injection
777 on more than one channel.
778 Also, since a change at an inject parameter will be applied only at enable,
779 we're disabling error injection on all write calls to the sysfs nodes that
780 controls the error code injection.
782 static int disable_inject(const struct mem_ctl_info
*mci
)
784 struct i7core_pvt
*pvt
= mci
->pvt_info
;
786 pvt
->inject
.enable
= 0;
788 if (!pvt
->pci_ch
[pvt
->inject
.channel
][0])
791 pci_write_config_dword(pvt
->pci_ch
[pvt
->inject
.channel
][0],
792 MC_CHANNEL_ERROR_INJECT
, 0);
798 * i7core inject inject.section
800 * accept and store error injection inject.section value
801 * bit 0 - refers to the lower 32-byte half cacheline
802 * bit 1 - refers to the upper 32-byte half cacheline
804 static ssize_t
i7core_inject_section_store(struct mem_ctl_info
*mci
,
805 const char *data
, size_t count
)
807 struct i7core_pvt
*pvt
= mci
->pvt_info
;
811 if (pvt
->inject
.enable
)
814 rc
= strict_strtoul(data
, 10, &value
);
815 if ((rc
< 0) || (value
> 3))
818 pvt
->inject
.section
= (u32
) value
;
822 static ssize_t
i7core_inject_section_show(struct mem_ctl_info
*mci
,
825 struct i7core_pvt
*pvt
= mci
->pvt_info
;
826 return sprintf(data
, "0x%08x\n", pvt
->inject
.section
);
832 * accept and store error injection inject.section value
833 * bit 0 - repeat enable - Enable error repetition
834 * bit 1 - inject ECC error
835 * bit 2 - inject parity error
837 static ssize_t
i7core_inject_type_store(struct mem_ctl_info
*mci
,
838 const char *data
, size_t count
)
840 struct i7core_pvt
*pvt
= mci
->pvt_info
;
844 if (pvt
->inject
.enable
)
847 rc
= strict_strtoul(data
, 10, &value
);
848 if ((rc
< 0) || (value
> 7))
851 pvt
->inject
.type
= (u32
) value
;
855 static ssize_t
i7core_inject_type_show(struct mem_ctl_info
*mci
,
858 struct i7core_pvt
*pvt
= mci
->pvt_info
;
859 return sprintf(data
, "0x%08x\n", pvt
->inject
.type
);
863 * i7core_inject_inject.eccmask_store
865 * The type of error (UE/CE) will depend on the inject.eccmask value:
866 * Any bits set to a 1 will flip the corresponding ECC bit
867 * Correctable errors can be injected by flipping 1 bit or the bits within
868 * a symbol pair (2 consecutive aligned 8-bit pairs - i.e. 7:0 and 15:8 or
869 * 23:16 and 31:24). Flipping bits in two symbol pairs will cause an
870 * uncorrectable error to be injected.
872 static ssize_t
i7core_inject_eccmask_store(struct mem_ctl_info
*mci
,
873 const char *data
, size_t count
)
875 struct i7core_pvt
*pvt
= mci
->pvt_info
;
879 if (pvt
->inject
.enable
)
882 rc
= strict_strtoul(data
, 10, &value
);
886 pvt
->inject
.eccmask
= (u32
) value
;
890 static ssize_t
i7core_inject_eccmask_show(struct mem_ctl_info
*mci
,
893 struct i7core_pvt
*pvt
= mci
->pvt_info
;
894 return sprintf(data
, "0x%08x\n", pvt
->inject
.eccmask
);
900 * The type of error (UE/CE) will depend on the inject.eccmask value:
901 * Any bits set to a 1 will flip the corresponding ECC bit
902 * Correctable errors can be injected by flipping 1 bit or the bits within
903 * a symbol pair (2 consecutive aligned 8-bit pairs - i.e. 7:0 and 15:8 or
904 * 23:16 and 31:24). Flipping bits in two symbol pairs will cause an
905 * uncorrectable error to be injected.
908 #define DECLARE_ADDR_MATCH(param, limit) \
909 static ssize_t i7core_inject_store_##param( \
910 struct mem_ctl_info *mci, \
911 const char *data, size_t count) \
913 struct i7core_pvt *pvt; \
917 debugf1("%s()\n", __func__); \
918 pvt = mci->pvt_info; \
920 if (pvt->inject.enable) \
921 disable_inject(mci); \
923 if (!strcasecmp(data, "any") || !strcasecmp(data, "any\n"))\
926 rc = strict_strtoul(data, 10, &value); \
927 if ((rc < 0) || (value >= limit)) \
931 pvt->inject.param = value; \
936 static ssize_t i7core_inject_show_##param( \
937 struct mem_ctl_info *mci, \
940 struct i7core_pvt *pvt; \
942 pvt = mci->pvt_info; \
943 debugf1("%s() pvt=%p\n", __func__, pvt); \
944 if (pvt->inject.param < 0) \
945 return sprintf(data, "any\n"); \
947 return sprintf(data, "%d\n", pvt->inject.param);\
950 #define ATTR_ADDR_MATCH(param) \
954 .mode = (S_IRUGO | S_IWUSR) \
956 .show = i7core_inject_show_##param, \
957 .store = i7core_inject_store_##param, \
960 DECLARE_ADDR_MATCH(channel
, 3);
961 DECLARE_ADDR_MATCH(dimm
, 3);
962 DECLARE_ADDR_MATCH(rank
, 4);
963 DECLARE_ADDR_MATCH(bank
, 32);
964 DECLARE_ADDR_MATCH(page
, 0x10000);
965 DECLARE_ADDR_MATCH(col
, 0x4000);
967 static int write_and_test(struct pci_dev
*dev
, const int where
, const u32 val
)
972 debugf0("setting pci %02x:%02x.%x reg=%02x value=%08x\n",
973 dev
->bus
->number
, PCI_SLOT(dev
->devfn
), PCI_FUNC(dev
->devfn
),
976 for (count
= 0; count
< 10; count
++) {
979 pci_write_config_dword(dev
, where
, val
);
980 pci_read_config_dword(dev
, where
, &read
);
986 i7core_printk(KERN_ERR
, "Error during set pci %02x:%02x.%x reg=%02x "
987 "write=%08x. Read=%08x\n",
988 dev
->bus
->number
, PCI_SLOT(dev
->devfn
), PCI_FUNC(dev
->devfn
),
995 * This routine prepares the Memory Controller for error injection.
996 * The error will be injected when some process tries to write to the
997 * memory that matches the given criteria.
998 * The criteria can be set in terms of a mask where dimm, rank, bank, page
999 * and col can be specified.
1000 * A -1 value for any of the mask items will make the MCU to ignore
1001 * that matching criteria for error injection.
1003 * It should be noticed that the error will only happen after a write operation
1004 * on a memory that matches the condition. if REPEAT_EN is not enabled at
1005 * inject mask, then it will produce just one error. Otherwise, it will repeat
1006 * until the injectmask would be cleaned.
1008 * FIXME: This routine assumes that MAXNUMDIMMS value of MC_MAX_DOD
1009 * is reliable enough to check if the MC is using the
1010 * three channels. However, this is not clear at the datasheet.
1012 static ssize_t
i7core_inject_enable_store(struct mem_ctl_info
*mci
,
1013 const char *data
, size_t count
)
1015 struct i7core_pvt
*pvt
= mci
->pvt_info
;
1021 if (!pvt
->pci_ch
[pvt
->inject
.channel
][0])
1024 rc
= strict_strtoul(data
, 10, &enable
);
1029 pvt
->inject
.enable
= 1;
1031 disable_inject(mci
);
1035 /* Sets pvt->inject.dimm mask */
1036 if (pvt
->inject
.dimm
< 0)
1039 if (pvt
->channel
[pvt
->inject
.channel
].dimms
> 2)
1040 mask
|= (pvt
->inject
.dimm
& 0x3LL
) << 35;
1042 mask
|= (pvt
->inject
.dimm
& 0x1LL
) << 36;
1045 /* Sets pvt->inject.rank mask */
1046 if (pvt
->inject
.rank
< 0)
1049 if (pvt
->channel
[pvt
->inject
.channel
].dimms
> 2)
1050 mask
|= (pvt
->inject
.rank
& 0x1LL
) << 34;
1052 mask
|= (pvt
->inject
.rank
& 0x3LL
) << 34;
1055 /* Sets pvt->inject.bank mask */
1056 if (pvt
->inject
.bank
< 0)
1059 mask
|= (pvt
->inject
.bank
& 0x15LL
) << 30;
1061 /* Sets pvt->inject.page mask */
1062 if (pvt
->inject
.page
< 0)
1065 mask
|= (pvt
->inject
.page
& 0xffff) << 14;
1067 /* Sets pvt->inject.column mask */
1068 if (pvt
->inject
.col
< 0)
1071 mask
|= (pvt
->inject
.col
& 0x3fff);
1075 * bits 1-2: MASK_HALF_CACHELINE
1077 * bit 4: INJECT_ADDR_PARITY
1080 injectmask
= (pvt
->inject
.type
& 1) |
1081 (pvt
->inject
.section
& 0x3) << 1 |
1082 (pvt
->inject
.type
& 0x6) << (3 - 1);
1084 /* Unlock writes to registers - this register is write only */
1085 pci_write_config_dword(pvt
->pci_noncore
,
1086 MC_CFG_CONTROL
, 0x2);
1088 write_and_test(pvt
->pci_ch
[pvt
->inject
.channel
][0],
1089 MC_CHANNEL_ADDR_MATCH
, mask
);
1090 write_and_test(pvt
->pci_ch
[pvt
->inject
.channel
][0],
1091 MC_CHANNEL_ADDR_MATCH
+ 4, mask
>> 32L);
1093 write_and_test(pvt
->pci_ch
[pvt
->inject
.channel
][0],
1094 MC_CHANNEL_ERROR_MASK
, pvt
->inject
.eccmask
);
1096 write_and_test(pvt
->pci_ch
[pvt
->inject
.channel
][0],
1097 MC_CHANNEL_ERROR_INJECT
, injectmask
);
1100 * This is something undocumented, based on my tests
1101 * Without writing 8 to this register, errors aren't injected. Not sure
1104 pci_write_config_dword(pvt
->pci_noncore
,
1107 debugf0("Error inject addr match 0x%016llx, ecc 0x%08x,"
1109 mask
, pvt
->inject
.eccmask
, injectmask
);
1115 static ssize_t
i7core_inject_enable_show(struct mem_ctl_info
*mci
,
1118 struct i7core_pvt
*pvt
= mci
->pvt_info
;
1121 if (!pvt
->pci_ch
[pvt
->inject
.channel
][0])
1124 pci_read_config_dword(pvt
->pci_ch
[pvt
->inject
.channel
][0],
1125 MC_CHANNEL_ERROR_INJECT
, &injectmask
);
1127 debugf0("Inject error read: 0x%018x\n", injectmask
);
1129 if (injectmask
& 0x0c)
1130 pvt
->inject
.enable
= 1;
1132 return sprintf(data
, "%d\n", pvt
->inject
.enable
);
1135 #define DECLARE_COUNTER(param) \
1136 static ssize_t i7core_show_counter_##param( \
1137 struct mem_ctl_info *mci, \
1140 struct i7core_pvt *pvt = mci->pvt_info; \
1142 debugf1("%s() \n", __func__); \
1143 if (!pvt->ce_count_available || (pvt->is_registered)) \
1144 return sprintf(data, "data unavailable\n"); \
1145 return sprintf(data, "%lu\n", \
1146 pvt->udimm_ce_count[param]); \
1149 #define ATTR_COUNTER(param) \
1152 .name = __stringify(udimm##param), \
1153 .mode = (S_IRUGO | S_IWUSR) \
1155 .show = i7core_show_counter_##param \
1166 static const struct mcidev_sysfs_attribute i7core_addrmatch_attrs
[] = {
1167 ATTR_ADDR_MATCH(channel
),
1168 ATTR_ADDR_MATCH(dimm
),
1169 ATTR_ADDR_MATCH(rank
),
1170 ATTR_ADDR_MATCH(bank
),
1171 ATTR_ADDR_MATCH(page
),
1172 ATTR_ADDR_MATCH(col
),
1173 { } /* End of list */
1176 static const struct mcidev_sysfs_group i7core_inject_addrmatch
= {
1177 .name
= "inject_addrmatch",
1178 .mcidev_attr
= i7core_addrmatch_attrs
,
1181 static const struct mcidev_sysfs_attribute i7core_udimm_counters_attrs
[] = {
1185 { .attr
= { .name
= NULL
} }
1188 static const struct mcidev_sysfs_group i7core_udimm_counters
= {
1189 .name
= "all_channel_counts",
1190 .mcidev_attr
= i7core_udimm_counters_attrs
,
1193 static const struct mcidev_sysfs_attribute i7core_sysfs_rdimm_attrs
[] = {
1196 .name
= "inject_section",
1197 .mode
= (S_IRUGO
| S_IWUSR
)
1199 .show
= i7core_inject_section_show
,
1200 .store
= i7core_inject_section_store
,
1203 .name
= "inject_type",
1204 .mode
= (S_IRUGO
| S_IWUSR
)
1206 .show
= i7core_inject_type_show
,
1207 .store
= i7core_inject_type_store
,
1210 .name
= "inject_eccmask",
1211 .mode
= (S_IRUGO
| S_IWUSR
)
1213 .show
= i7core_inject_eccmask_show
,
1214 .store
= i7core_inject_eccmask_store
,
1216 .grp
= &i7core_inject_addrmatch
,
1219 .name
= "inject_enable",
1220 .mode
= (S_IRUGO
| S_IWUSR
)
1222 .show
= i7core_inject_enable_show
,
1223 .store
= i7core_inject_enable_store
,
1225 { } /* End of list */
1228 static const struct mcidev_sysfs_attribute i7core_sysfs_udimm_attrs
[] = {
1231 .name
= "inject_section",
1232 .mode
= (S_IRUGO
| S_IWUSR
)
1234 .show
= i7core_inject_section_show
,
1235 .store
= i7core_inject_section_store
,
1238 .name
= "inject_type",
1239 .mode
= (S_IRUGO
| S_IWUSR
)
1241 .show
= i7core_inject_type_show
,
1242 .store
= i7core_inject_type_store
,
1245 .name
= "inject_eccmask",
1246 .mode
= (S_IRUGO
| S_IWUSR
)
1248 .show
= i7core_inject_eccmask_show
,
1249 .store
= i7core_inject_eccmask_store
,
1251 .grp
= &i7core_inject_addrmatch
,
1254 .name
= "inject_enable",
1255 .mode
= (S_IRUGO
| S_IWUSR
)
1257 .show
= i7core_inject_enable_show
,
1258 .store
= i7core_inject_enable_store
,
1260 .grp
= &i7core_udimm_counters
,
1262 { } /* End of list */
1265 /****************************************************************************
1266 Device initialization routines: put/get, init/exit
1267 ****************************************************************************/
1270 * i7core_put_all_devices 'put' all the devices that we have
1271 * reserved via 'get'
1273 static void i7core_put_devices(struct i7core_dev
*i7core_dev
)
1277 debugf0(__FILE__
": %s()\n", __func__
);
1278 for (i
= 0; i
< i7core_dev
->n_devs
; i
++) {
1279 struct pci_dev
*pdev
= i7core_dev
->pdev
[i
];
1282 debugf0("Removing dev %02x:%02x.%d\n",
1284 PCI_SLOT(pdev
->devfn
), PCI_FUNC(pdev
->devfn
));
1289 static void i7core_put_all_devices(void)
1291 struct i7core_dev
*i7core_dev
, *tmp
;
1293 list_for_each_entry_safe(i7core_dev
, tmp
, &i7core_edac_list
, list
) {
1294 i7core_put_devices(i7core_dev
);
1295 free_i7core_dev(i7core_dev
);
1299 static void __init
i7core_xeon_pci_fixup(const struct pci_id_table
*table
)
1301 struct pci_dev
*pdev
= NULL
;
1305 * On Xeon 55xx, the Intel Quick Path Arch Generic Non-core pci buses
1306 * aren't announced by acpi. So, we need to use a legacy scan probing
1309 while (table
&& table
->descr
) {
1310 pdev
= pci_get_device(PCI_VENDOR_ID_INTEL
, table
->descr
[0].dev_id
, NULL
);
1311 if (unlikely(!pdev
)) {
1312 for (i
= 0; i
< MAX_SOCKET_BUSES
; i
++)
1313 pcibios_scan_specific_bus(255-i
);
1320 static unsigned i7core_pci_lastbus(void)
1322 int last_bus
= 0, bus
;
1323 struct pci_bus
*b
= NULL
;
1325 while ((b
= pci_find_next_bus(b
)) != NULL
) {
1327 debugf0("Found bus %d\n", bus
);
1332 debugf0("Last bus %d\n", last_bus
);
1338 * i7core_get_all_devices Find and perform 'get' operation on the MCH's
1339 * device/functions we want to reference for this driver
1341 * Need to 'get' device 16 func 1 and func 2
1343 static int i7core_get_onedevice(struct pci_dev
**prev
,
1344 const struct pci_id_table
*table
,
1345 const unsigned devno
,
1346 const unsigned last_bus
)
1348 struct i7core_dev
*i7core_dev
;
1349 const struct pci_id_descr
*dev_descr
= &table
->descr
[devno
];
1351 struct pci_dev
*pdev
= NULL
;
1355 pdev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
1356 dev_descr
->dev_id
, *prev
);
1359 * On Xeon 55xx, the Intel Quckpath Arch Generic Non-core regs
1360 * is at addr 8086:2c40, instead of 8086:2c41. So, we need
1361 * to probe for the alternate address in case of failure
1363 if (dev_descr
->dev_id
== PCI_DEVICE_ID_INTEL_I7_NONCORE
&& !pdev
)
1364 pdev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
1365 PCI_DEVICE_ID_INTEL_I7_NONCORE_ALT
, *prev
);
1367 if (dev_descr
->dev_id
== PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE
&& !pdev
)
1368 pdev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
1369 PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE_ALT
,
1378 if (dev_descr
->optional
)
1384 i7core_printk(KERN_INFO
,
1385 "Device not found: dev %02x.%d PCI ID %04x:%04x\n",
1386 dev_descr
->dev
, dev_descr
->func
,
1387 PCI_VENDOR_ID_INTEL
, dev_descr
->dev_id
);
1389 /* End of list, leave */
1392 bus
= pdev
->bus
->number
;
1394 socket
= last_bus
- bus
;
1396 i7core_dev
= get_i7core_dev(socket
);
1398 i7core_dev
= alloc_i7core_dev(socket
, table
);
1405 if (i7core_dev
->pdev
[devno
]) {
1406 i7core_printk(KERN_ERR
,
1407 "Duplicated device for "
1408 "dev %02x:%02x.%d PCI ID %04x:%04x\n",
1409 bus
, dev_descr
->dev
, dev_descr
->func
,
1410 PCI_VENDOR_ID_INTEL
, dev_descr
->dev_id
);
1415 i7core_dev
->pdev
[devno
] = pdev
;
1418 if (unlikely(PCI_SLOT(pdev
->devfn
) != dev_descr
->dev
||
1419 PCI_FUNC(pdev
->devfn
) != dev_descr
->func
)) {
1420 i7core_printk(KERN_ERR
,
1421 "Device PCI ID %04x:%04x "
1422 "has dev %02x:%02x.%d instead of dev %02x:%02x.%d\n",
1423 PCI_VENDOR_ID_INTEL
, dev_descr
->dev_id
,
1424 bus
, PCI_SLOT(pdev
->devfn
), PCI_FUNC(pdev
->devfn
),
1425 bus
, dev_descr
->dev
, dev_descr
->func
);
1429 /* Be sure that the device is enabled */
1430 if (unlikely(pci_enable_device(pdev
) < 0)) {
1431 i7core_printk(KERN_ERR
,
1433 "dev %02x:%02x.%d PCI ID %04x:%04x\n",
1434 bus
, dev_descr
->dev
, dev_descr
->func
,
1435 PCI_VENDOR_ID_INTEL
, dev_descr
->dev_id
);
1439 debugf0("Detected socket %d dev %02x:%02x.%d PCI ID %04x:%04x\n",
1440 socket
, bus
, dev_descr
->dev
,
1442 PCI_VENDOR_ID_INTEL
, dev_descr
->dev_id
);
1445 * As stated on drivers/pci/search.c, the reference count for
1446 * @from is always decremented if it is not %NULL. So, as we need
1447 * to get all devices up to null, we need to do a get for the device
1456 static int i7core_get_all_devices(void)
1458 int i
, rc
, last_bus
;
1459 struct pci_dev
*pdev
= NULL
;
1460 const struct pci_id_table
*table
= pci_dev_table
;
1462 last_bus
= i7core_pci_lastbus();
1464 while (table
&& table
->descr
) {
1465 for (i
= 0; i
< table
->n_devs
; i
++) {
1468 rc
= i7core_get_onedevice(&pdev
, table
, i
,
1475 i7core_put_all_devices();
1486 static int mci_bind_devs(struct mem_ctl_info
*mci
,
1487 struct i7core_dev
*i7core_dev
)
1489 struct i7core_pvt
*pvt
= mci
->pvt_info
;
1490 struct pci_dev
*pdev
;
1494 pvt
->is_registered
= false;
1495 pvt
->enable_scrub
= false;
1496 for (i
= 0; i
< i7core_dev
->n_devs
; i
++) {
1497 pdev
= i7core_dev
->pdev
[i
];
1501 func
= PCI_FUNC(pdev
->devfn
);
1502 slot
= PCI_SLOT(pdev
->devfn
);
1504 if (unlikely(func
> MAX_MCR_FUNC
))
1506 pvt
->pci_mcr
[func
] = pdev
;
1507 } else if (likely(slot
>= 4 && slot
< 4 + NUM_CHANS
)) {
1508 if (unlikely(func
> MAX_CHAN_FUNC
))
1510 pvt
->pci_ch
[slot
- 4][func
] = pdev
;
1511 } else if (!slot
&& !func
) {
1512 pvt
->pci_noncore
= pdev
;
1514 /* Detect the processor family */
1515 switch (pdev
->device
) {
1516 case PCI_DEVICE_ID_INTEL_I7_NONCORE
:
1517 family
= "Xeon 35xx/ i7core";
1518 pvt
->enable_scrub
= false;
1520 case PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE_ALT
:
1521 family
= "i7-800/i5-700";
1522 pvt
->enable_scrub
= false;
1524 case PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE
:
1525 family
= "Xeon 34xx";
1526 pvt
->enable_scrub
= false;
1528 case PCI_DEVICE_ID_INTEL_I7_NONCORE_ALT
:
1529 family
= "Xeon 55xx";
1530 pvt
->enable_scrub
= true;
1532 case PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE_REV2
:
1533 family
= "Xeon 56xx / i7-900";
1534 pvt
->enable_scrub
= true;
1538 pvt
->enable_scrub
= false;
1540 debugf0("Detected a processor type %s\n", family
);
1544 debugf0("Associated fn %d.%d, dev = %p, socket %d\n",
1545 PCI_SLOT(pdev
->devfn
), PCI_FUNC(pdev
->devfn
),
1546 pdev
, i7core_dev
->socket
);
1548 if (PCI_SLOT(pdev
->devfn
) == 3 &&
1549 PCI_FUNC(pdev
->devfn
) == 2)
1550 pvt
->is_registered
= true;
1556 i7core_printk(KERN_ERR
, "Device %d, function %d "
1557 "is out of the expected range\n",
1562 /****************************************************************************
1563 Error check routines
1564 ****************************************************************************/
1565 static void i7core_rdimm_update_csrow(struct mem_ctl_info
*mci
,
1571 struct i7core_pvt
*pvt
= mci
->pvt_info
;
1572 int row
= pvt
->csrow_map
[chan
][dimm
], i
;
1574 for (i
= 0; i
< add
; i
++) {
1575 msg
= kasprintf(GFP_KERNEL
, "Corrected error "
1576 "(Socket=%d channel=%d dimm=%d)",
1577 pvt
->i7core_dev
->socket
, chan
, dimm
);
1579 edac_mc_handle_fbd_ce(mci
, row
, 0, msg
);
1584 static void i7core_rdimm_update_ce_count(struct mem_ctl_info
*mci
,
1590 struct i7core_pvt
*pvt
= mci
->pvt_info
;
1591 int add0
= 0, add1
= 0, add2
= 0;
1592 /* Updates CE counters if it is not the first time here */
1593 if (pvt
->ce_count_available
) {
1594 /* Updates CE counters */
1596 add2
= new2
- pvt
->rdimm_last_ce_count
[chan
][2];
1597 add1
= new1
- pvt
->rdimm_last_ce_count
[chan
][1];
1598 add0
= new0
- pvt
->rdimm_last_ce_count
[chan
][0];
1602 pvt
->rdimm_ce_count
[chan
][2] += add2
;
1606 pvt
->rdimm_ce_count
[chan
][1] += add1
;
1610 pvt
->rdimm_ce_count
[chan
][0] += add0
;
1612 pvt
->ce_count_available
= 1;
1614 /* Store the new values */
1615 pvt
->rdimm_last_ce_count
[chan
][2] = new2
;
1616 pvt
->rdimm_last_ce_count
[chan
][1] = new1
;
1617 pvt
->rdimm_last_ce_count
[chan
][0] = new0
;
1619 /*updated the edac core */
1621 i7core_rdimm_update_csrow(mci
, chan
, 0, add0
);
1623 i7core_rdimm_update_csrow(mci
, chan
, 1, add1
);
1625 i7core_rdimm_update_csrow(mci
, chan
, 2, add2
);
1629 static void i7core_rdimm_check_mc_ecc_err(struct mem_ctl_info
*mci
)
1631 struct i7core_pvt
*pvt
= mci
->pvt_info
;
1633 int i
, new0
, new1
, new2
;
1635 /*Read DEV 3: FUN 2: MC_COR_ECC_CNT regs directly*/
1636 pci_read_config_dword(pvt
->pci_mcr
[2], MC_COR_ECC_CNT_0
,
1638 pci_read_config_dword(pvt
->pci_mcr
[2], MC_COR_ECC_CNT_1
,
1640 pci_read_config_dword(pvt
->pci_mcr
[2], MC_COR_ECC_CNT_2
,
1642 pci_read_config_dword(pvt
->pci_mcr
[2], MC_COR_ECC_CNT_3
,
1644 pci_read_config_dword(pvt
->pci_mcr
[2], MC_COR_ECC_CNT_4
,
1646 pci_read_config_dword(pvt
->pci_mcr
[2], MC_COR_ECC_CNT_5
,
1648 for (i
= 0 ; i
< 3; i
++) {
1649 debugf3("MC_COR_ECC_CNT%d = 0x%x; MC_COR_ECC_CNT%d = 0x%x\n",
1650 (i
* 2), rcv
[i
][0], (i
* 2) + 1, rcv
[i
][1]);
1651 /*if the channel has 3 dimms*/
1652 if (pvt
->channel
[i
].dimms
> 2) {
1653 new0
= DIMM_BOT_COR_ERR(rcv
[i
][0]);
1654 new1
= DIMM_TOP_COR_ERR(rcv
[i
][0]);
1655 new2
= DIMM_BOT_COR_ERR(rcv
[i
][1]);
1657 new0
= DIMM_TOP_COR_ERR(rcv
[i
][0]) +
1658 DIMM_BOT_COR_ERR(rcv
[i
][0]);
1659 new1
= DIMM_TOP_COR_ERR(rcv
[i
][1]) +
1660 DIMM_BOT_COR_ERR(rcv
[i
][1]);
1664 i7core_rdimm_update_ce_count(mci
, i
, new0
, new1
, new2
);
1668 /* This function is based on the device 3 function 4 registers as described on:
1669 * Intel Xeon Processor 5500 Series Datasheet Volume 2
1670 * http://www.intel.com/Assets/PDF/datasheet/321322.pdf
1671 * also available at:
1672 * http://www.arrownac.com/manufacturers/intel/s/nehalem/5500-datasheet-v2.pdf
1674 static void i7core_udimm_check_mc_ecc_err(struct mem_ctl_info
*mci
)
1676 struct i7core_pvt
*pvt
= mci
->pvt_info
;
1678 int new0
, new1
, new2
;
1680 if (!pvt
->pci_mcr
[4]) {
1681 debugf0("%s MCR registers not found\n", __func__
);
1685 /* Corrected test errors */
1686 pci_read_config_dword(pvt
->pci_mcr
[4], MC_TEST_ERR_RCV1
, &rcv1
);
1687 pci_read_config_dword(pvt
->pci_mcr
[4], MC_TEST_ERR_RCV0
, &rcv0
);
1689 /* Store the new values */
1690 new2
= DIMM2_COR_ERR(rcv1
);
1691 new1
= DIMM1_COR_ERR(rcv0
);
1692 new0
= DIMM0_COR_ERR(rcv0
);
1694 /* Updates CE counters if it is not the first time here */
1695 if (pvt
->ce_count_available
) {
1696 /* Updates CE counters */
1697 int add0
, add1
, add2
;
1699 add2
= new2
- pvt
->udimm_last_ce_count
[2];
1700 add1
= new1
- pvt
->udimm_last_ce_count
[1];
1701 add0
= new0
- pvt
->udimm_last_ce_count
[0];
1705 pvt
->udimm_ce_count
[2] += add2
;
1709 pvt
->udimm_ce_count
[1] += add1
;
1713 pvt
->udimm_ce_count
[0] += add0
;
1715 if (add0
| add1
| add2
)
1716 i7core_printk(KERN_ERR
, "New Corrected error(s): "
1717 "dimm0: +%d, dimm1: +%d, dimm2 +%d\n",
1720 pvt
->ce_count_available
= 1;
1722 /* Store the new values */
1723 pvt
->udimm_last_ce_count
[2] = new2
;
1724 pvt
->udimm_last_ce_count
[1] = new1
;
1725 pvt
->udimm_last_ce_count
[0] = new0
;
1729 * According with tables E-11 and E-12 of chapter E.3.3 of Intel 64 and IA-32
1730 * Architectures Software Developer’s Manual Volume 3B.
1731 * Nehalem are defined as family 0x06, model 0x1a
1733 * The MCA registers used here are the following ones:
1734 * struct mce field MCA Register
1735 * m->status MSR_IA32_MC8_STATUS
1736 * m->addr MSR_IA32_MC8_ADDR
1737 * m->misc MSR_IA32_MC8_MISC
1738 * In the case of Nehalem, the error information is masked at .status and .misc
1741 static void i7core_mce_output_error(struct mem_ctl_info
*mci
,
1742 const struct mce
*m
)
1744 struct i7core_pvt
*pvt
= mci
->pvt_info
;
1745 char *type
, *optype
, *err
, *msg
;
1746 unsigned long error
= m
->status
& 0x1ff0000l
;
1747 u32 optypenum
= (m
->status
>> 4) & 0x07;
1748 u32 core_err_cnt
= (m
->status
>> 38) & 0x7fff;
1749 u32 dimm
= (m
->misc
>> 16) & 0x3;
1750 u32 channel
= (m
->misc
>> 18) & 0x3;
1751 u32 syndrome
= m
->misc
>> 32;
1752 u32 errnum
= find_first_bit(&error
, 32);
1755 if (m
->mcgstatus
& 1)
1760 switch (optypenum
) {
1762 optype
= "generic undef request";
1765 optype
= "read error";
1768 optype
= "write error";
1771 optype
= "addr/cmd error";
1774 optype
= "scrubbing error";
1777 optype
= "reserved";
1783 err
= "read ECC error";
1786 err
= "RAS ECC error";
1789 err
= "write parity error";
1792 err
= "redundacy loss";
1798 err
= "memory range error";
1801 err
= "RTID out of range";
1804 err
= "address parity error";
1807 err
= "byte enable parity error";
1813 /* FIXME: should convert addr into bank and rank information */
1814 msg
= kasprintf(GFP_ATOMIC
,
1815 "%s (addr = 0x%08llx, cpu=%d, Dimm=%d, Channel=%d, "
1816 "syndrome=0x%08x, count=%d, Err=%08llx:%08llx (%s: %s))\n",
1817 type
, (long long) m
->addr
, m
->cpu
, dimm
, channel
,
1818 syndrome
, core_err_cnt
, (long long)m
->status
,
1819 (long long)m
->misc
, optype
, err
);
1823 csrow
= pvt
->csrow_map
[channel
][dimm
];
1825 /* Call the helper to output message */
1826 if (m
->mcgstatus
& 1)
1827 edac_mc_handle_fbd_ue(mci
, csrow
, 0,
1828 0 /* FIXME: should be channel here */, msg
);
1829 else if (!pvt
->is_registered
)
1830 edac_mc_handle_fbd_ce(mci
, csrow
,
1831 0 /* FIXME: should be channel here */, msg
);
1837 * i7core_check_error Retrieve and process errors reported by the
1838 * hardware. Called by the Core module.
1840 static void i7core_check_error(struct mem_ctl_info
*mci
)
1842 struct i7core_pvt
*pvt
= mci
->pvt_info
;
1848 * MCE first step: Copy all mce errors into a temporary buffer
1849 * We use a double buffering here, to reduce the risk of
1853 count
= (pvt
->mce_out
+ MCE_LOG_LEN
- pvt
->mce_in
)
1856 goto check_ce_error
;
1858 m
= pvt
->mce_outentry
;
1859 if (pvt
->mce_in
+ count
> MCE_LOG_LEN
) {
1860 unsigned l
= MCE_LOG_LEN
- pvt
->mce_in
;
1862 memcpy(m
, &pvt
->mce_entry
[pvt
->mce_in
], sizeof(*m
) * l
);
1868 memcpy(m
, &pvt
->mce_entry
[pvt
->mce_in
], sizeof(*m
) * count
);
1870 pvt
->mce_in
+= count
;
1873 if (pvt
->mce_overrun
) {
1874 i7core_printk(KERN_ERR
, "Lost %d memory errors\n",
1877 pvt
->mce_overrun
= 0;
1881 * MCE second step: parse errors and display
1883 for (i
= 0; i
< count
; i
++)
1884 i7core_mce_output_error(mci
, &pvt
->mce_outentry
[i
]);
1887 * Now, let's increment CE error counts
1890 if (!pvt
->is_registered
)
1891 i7core_udimm_check_mc_ecc_err(mci
);
1893 i7core_rdimm_check_mc_ecc_err(mci
);
1897 * i7core_mce_check_error Replicates mcelog routine to get errors
1898 * This routine simply queues mcelog errors, and
1899 * return. The error itself should be handled later
1900 * by i7core_check_error.
1901 * WARNING: As this routine should be called at NMI time, extra care should
1902 * be taken to avoid deadlocks, and to be as fast as possible.
1904 static int i7core_mce_check_error(struct notifier_block
*nb
, unsigned long val
,
1907 struct mce
*mce
= (struct mce
*)data
;
1908 struct i7core_dev
*i7_dev
;
1909 struct mem_ctl_info
*mci
;
1910 struct i7core_pvt
*pvt
;
1912 i7_dev
= get_i7core_dev(mce
->socketid
);
1917 pvt
= mci
->pvt_info
;
1920 * Just let mcelog handle it if the error is
1921 * outside the memory controller
1923 if (((mce
->status
& 0xffff) >> 7) != 1)
1926 /* Bank 8 registers are the only ones that we know how to handle */
1931 /* Only handle if it is the right mc controller */
1932 if (mce
->socketid
!= pvt
->i7core_dev
->socket
)
1937 if ((pvt
->mce_out
+ 1) % MCE_LOG_LEN
== pvt
->mce_in
) {
1943 /* Copy memory error at the ringbuffer */
1944 memcpy(&pvt
->mce_entry
[pvt
->mce_out
], mce
, sizeof(*mce
));
1946 pvt
->mce_out
= (pvt
->mce_out
+ 1) % MCE_LOG_LEN
;
1948 /* Handle fatal errors immediately */
1949 if (mce
->mcgstatus
& 1)
1950 i7core_check_error(mci
);
1952 /* Advise mcelog that the errors were handled */
1956 static struct notifier_block i7_mce_dec
= {
1957 .notifier_call
= i7core_mce_check_error
,
1960 struct memdev_dmi_entry
{
1964 u16 phys_mem_array_handle
;
1965 u16 mem_err_info_handle
;
1982 u16 conf_mem_clk_speed
;
1983 } __attribute__((__packed__
));
1987 * Decode the DRAM Clock Frequency, be paranoid, make sure that all
1988 * memory devices show the same speed, and if they don't then consider
1989 * all speeds to be invalid.
1991 static void decode_dclk(const struct dmi_header
*dh
, void *_dclk_freq
)
1993 int *dclk_freq
= _dclk_freq
;
1994 u16 dmi_mem_clk_speed
;
1996 if (*dclk_freq
== -1)
1999 if (dh
->type
== DMI_ENTRY_MEM_DEVICE
) {
2000 struct memdev_dmi_entry
*memdev_dmi_entry
=
2001 (struct memdev_dmi_entry
*)dh
;
2002 unsigned long conf_mem_clk_speed_offset
=
2003 (unsigned long)&memdev_dmi_entry
->conf_mem_clk_speed
-
2004 (unsigned long)&memdev_dmi_entry
->type
;
2005 unsigned long speed_offset
=
2006 (unsigned long)&memdev_dmi_entry
->speed
-
2007 (unsigned long)&memdev_dmi_entry
->type
;
2009 /* Check that a DIMM is present */
2010 if (memdev_dmi_entry
->size
== 0)
2014 * Pick the configured speed if it's available, otherwise
2015 * pick the DIMM speed, or we don't have a speed.
2017 if (memdev_dmi_entry
->length
> conf_mem_clk_speed_offset
) {
2019 memdev_dmi_entry
->conf_mem_clk_speed
;
2020 } else if (memdev_dmi_entry
->length
> speed_offset
) {
2021 dmi_mem_clk_speed
= memdev_dmi_entry
->speed
;
2027 if (*dclk_freq
== 0) {
2028 /* First pass, speed was 0 */
2029 if (dmi_mem_clk_speed
> 0) {
2030 /* Set speed if a valid speed is read */
2031 *dclk_freq
= dmi_mem_clk_speed
;
2033 /* Otherwise we don't have a valid speed */
2036 } else if (*dclk_freq
> 0 &&
2037 *dclk_freq
!= dmi_mem_clk_speed
) {
2039 * If we have a speed, check that all DIMMS are the same
2040 * speed, otherwise set the speed as invalid.
2048 * The default DCLK frequency is used as a fallback if we
2049 * fail to find anything reliable in the DMI. The value
2050 * is taken straight from the datasheet.
2052 #define DEFAULT_DCLK_FREQ 800
2054 static int get_dclk_freq(void)
2058 dmi_walk(decode_dclk
, (void *)&dclk_freq
);
2061 return DEFAULT_DCLK_FREQ
;
2067 * set_sdram_scrub_rate This routine sets byte/sec bandwidth scrub rate
2068 * to hardware according to SCRUBINTERVAL formula
2069 * found in datasheet.
2071 static int set_sdram_scrub_rate(struct mem_ctl_info
*mci
, u32 new_bw
)
2073 struct i7core_pvt
*pvt
= mci
->pvt_info
;
2074 struct pci_dev
*pdev
;
2078 /* Get data from the MC register, function 2 */
2079 pdev
= pvt
->pci_mcr
[2];
2083 pci_read_config_dword(pdev
, MC_SCRUB_CONTROL
, &dw_scrub
);
2086 /* Prepare to disable petrol scrub */
2087 dw_scrub
&= ~STARTSCRUB
;
2088 /* Stop the patrol scrub engine */
2089 write_and_test(pdev
, MC_SCRUB_CONTROL
,
2090 dw_scrub
& ~SCRUBINTERVAL_MASK
);
2092 /* Get current status of scrub rate and set bit to disable */
2093 pci_read_config_dword(pdev
, MC_SSRCONTROL
, &dw_ssr
);
2094 dw_ssr
&= ~SSR_MODE_MASK
;
2095 dw_ssr
|= SSR_MODE_DISABLE
;
2097 const int cache_line_size
= 64;
2098 const u32 freq_dclk_mhz
= pvt
->dclk_freq
;
2099 unsigned long long scrub_interval
;
2101 * Translate the desired scrub rate to a register value and
2102 * program the corresponding register value.
2104 scrub_interval
= (unsigned long long)freq_dclk_mhz
*
2105 cache_line_size
* 1000000 / new_bw
;
2107 if (!scrub_interval
|| scrub_interval
> SCRUBINTERVAL_MASK
)
2110 dw_scrub
= SCRUBINTERVAL_MASK
& scrub_interval
;
2112 /* Start the patrol scrub engine */
2113 pci_write_config_dword(pdev
, MC_SCRUB_CONTROL
,
2114 STARTSCRUB
| dw_scrub
);
2116 /* Get current status of scrub rate and set bit to enable */
2117 pci_read_config_dword(pdev
, MC_SSRCONTROL
, &dw_ssr
);
2118 dw_ssr
&= ~SSR_MODE_MASK
;
2119 dw_ssr
|= SSR_MODE_ENABLE
;
2121 /* Disable or enable scrubbing */
2122 pci_write_config_dword(pdev
, MC_SSRCONTROL
, dw_ssr
);
2128 * get_sdram_scrub_rate This routine convert current scrub rate value
2129 * into byte/sec bandwidth accourding to
2130 * SCRUBINTERVAL formula found in datasheet.
2132 static int get_sdram_scrub_rate(struct mem_ctl_info
*mci
)
2134 struct i7core_pvt
*pvt
= mci
->pvt_info
;
2135 struct pci_dev
*pdev
;
2136 const u32 cache_line_size
= 64;
2137 const u32 freq_dclk_mhz
= pvt
->dclk_freq
;
2138 unsigned long long scrub_rate
;
2141 /* Get data from the MC register, function 2 */
2142 pdev
= pvt
->pci_mcr
[2];
2146 /* Get current scrub control data */
2147 pci_read_config_dword(pdev
, MC_SCRUB_CONTROL
, &scrubval
);
2149 /* Mask highest 8-bits to 0 */
2150 scrubval
&= SCRUBINTERVAL_MASK
;
2154 /* Calculate scrub rate value into byte/sec bandwidth */
2155 scrub_rate
= (unsigned long long)freq_dclk_mhz
*
2156 1000000 * cache_line_size
/ scrubval
;
2157 return (int)scrub_rate
;
2160 static void enable_sdram_scrub_setting(struct mem_ctl_info
*mci
)
2162 struct i7core_pvt
*pvt
= mci
->pvt_info
;
2165 /* Unlock writes to pci registers */
2166 pci_read_config_dword(pvt
->pci_noncore
, MC_CFG_CONTROL
, &pci_lock
);
2168 pci_write_config_dword(pvt
->pci_noncore
, MC_CFG_CONTROL
,
2169 pci_lock
| MC_CFG_UNLOCK
);
2171 mci
->set_sdram_scrub_rate
= set_sdram_scrub_rate
;
2172 mci
->get_sdram_scrub_rate
= get_sdram_scrub_rate
;
2175 static void disable_sdram_scrub_setting(struct mem_ctl_info
*mci
)
2177 struct i7core_pvt
*pvt
= mci
->pvt_info
;
2180 /* Lock writes to pci registers */
2181 pci_read_config_dword(pvt
->pci_noncore
, MC_CFG_CONTROL
, &pci_lock
);
2183 pci_write_config_dword(pvt
->pci_noncore
, MC_CFG_CONTROL
,
2184 pci_lock
| MC_CFG_LOCK
);
2187 static void i7core_pci_ctl_create(struct i7core_pvt
*pvt
)
2189 pvt
->i7core_pci
= edac_pci_create_generic_ctl(
2190 &pvt
->i7core_dev
->pdev
[0]->dev
,
2192 if (unlikely(!pvt
->i7core_pci
))
2193 i7core_printk(KERN_WARNING
,
2194 "Unable to setup PCI error report via EDAC\n");
2197 static void i7core_pci_ctl_release(struct i7core_pvt
*pvt
)
2199 if (likely(pvt
->i7core_pci
))
2200 edac_pci_release_generic_ctl(pvt
->i7core_pci
);
2202 i7core_printk(KERN_ERR
,
2203 "Couldn't find mem_ctl_info for socket %d\n",
2204 pvt
->i7core_dev
->socket
);
2205 pvt
->i7core_pci
= NULL
;
2208 static void i7core_unregister_mci(struct i7core_dev
*i7core_dev
)
2210 struct mem_ctl_info
*mci
= i7core_dev
->mci
;
2211 struct i7core_pvt
*pvt
;
2213 if (unlikely(!mci
|| !mci
->pvt_info
)) {
2214 debugf0("MC: " __FILE__
": %s(): dev = %p\n",
2215 __func__
, &i7core_dev
->pdev
[0]->dev
);
2217 i7core_printk(KERN_ERR
, "Couldn't find mci handler\n");
2221 pvt
= mci
->pvt_info
;
2223 debugf0("MC: " __FILE__
": %s(): mci = %p, dev = %p\n",
2224 __func__
, mci
, &i7core_dev
->pdev
[0]->dev
);
2226 /* Disable scrubrate setting */
2227 if (pvt
->enable_scrub
)
2228 disable_sdram_scrub_setting(mci
);
2230 atomic_notifier_chain_unregister(&x86_mce_decoder_chain
, &i7_mce_dec
);
2232 /* Disable EDAC polling */
2233 i7core_pci_ctl_release(pvt
);
2235 /* Remove MC sysfs nodes */
2236 edac_mc_del_mc(mci
->dev
);
2238 debugf1("%s: free mci struct\n", mci
->ctl_name
);
2239 kfree(mci
->ctl_name
);
2241 i7core_dev
->mci
= NULL
;
2244 static int i7core_register_mci(struct i7core_dev
*i7core_dev
)
2246 struct mem_ctl_info
*mci
;
2247 struct i7core_pvt
*pvt
;
2248 int rc
, channels
, csrows
;
2250 /* Check the number of active and not disabled channels */
2251 rc
= i7core_get_active_channels(i7core_dev
->socket
, &channels
, &csrows
);
2252 if (unlikely(rc
< 0))
2255 /* allocate a new MC control structure */
2256 mci
= edac_mc_alloc(sizeof(*pvt
), csrows
, channels
, i7core_dev
->socket
);
2260 debugf0("MC: " __FILE__
": %s(): mci = %p, dev = %p\n",
2261 __func__
, mci
, &i7core_dev
->pdev
[0]->dev
);
2263 pvt
= mci
->pvt_info
;
2264 memset(pvt
, 0, sizeof(*pvt
));
2266 /* Associates i7core_dev and mci for future usage */
2267 pvt
->i7core_dev
= i7core_dev
;
2268 i7core_dev
->mci
= mci
;
2271 * FIXME: how to handle RDDR3 at MCI level? It is possible to have
2272 * Mixed RDDR3/UDDR3 with Nehalem, provided that they are on different
2275 mci
->mtype_cap
= MEM_FLAG_DDR3
;
2276 mci
->edac_ctl_cap
= EDAC_FLAG_NONE
;
2277 mci
->edac_cap
= EDAC_FLAG_NONE
;
2278 mci
->mod_name
= "i7core_edac.c";
2279 mci
->mod_ver
= I7CORE_REVISION
;
2280 mci
->ctl_name
= kasprintf(GFP_KERNEL
, "i7 core #%d",
2281 i7core_dev
->socket
);
2282 mci
->dev_name
= pci_name(i7core_dev
->pdev
[0]);
2283 mci
->ctl_page_to_phys
= NULL
;
2285 /* Store pci devices at mci for faster access */
2286 rc
= mci_bind_devs(mci
, i7core_dev
);
2287 if (unlikely(rc
< 0))
2290 if (pvt
->is_registered
)
2291 mci
->mc_driver_sysfs_attributes
= i7core_sysfs_rdimm_attrs
;
2293 mci
->mc_driver_sysfs_attributes
= i7core_sysfs_udimm_attrs
;
2295 /* Get dimm basic config */
2296 get_dimm_config(mci
);
2297 /* record ptr to the generic device */
2298 mci
->dev
= &i7core_dev
->pdev
[0]->dev
;
2299 /* Set the function pointer to an actual operation function */
2300 mci
->edac_check
= i7core_check_error
;
2302 /* Enable scrubrate setting */
2303 if (pvt
->enable_scrub
)
2304 enable_sdram_scrub_setting(mci
);
2306 /* add this new MC control structure to EDAC's list of MCs */
2307 if (unlikely(edac_mc_add_mc(mci
))) {
2308 debugf0("MC: " __FILE__
2309 ": %s(): failed edac_mc_add_mc()\n", __func__
);
2310 /* FIXME: perhaps some code should go here that disables error
2311 * reporting if we just enabled it
2318 /* Default error mask is any memory */
2319 pvt
->inject
.channel
= 0;
2320 pvt
->inject
.dimm
= -1;
2321 pvt
->inject
.rank
= -1;
2322 pvt
->inject
.bank
= -1;
2323 pvt
->inject
.page
= -1;
2324 pvt
->inject
.col
= -1;
2326 /* allocating generic PCI control info */
2327 i7core_pci_ctl_create(pvt
);
2329 /* DCLK for scrub rate setting */
2330 pvt
->dclk_freq
= get_dclk_freq();
2332 atomic_notifier_chain_register(&x86_mce_decoder_chain
, &i7_mce_dec
);
2337 kfree(mci
->ctl_name
);
2339 i7core_dev
->mci
= NULL
;
2344 * i7core_probe Probe for ONE instance of device to see if it is
2347 * 0 for FOUND a device
2348 * < 0 for error code
2351 static int __devinit
i7core_probe(struct pci_dev
*pdev
,
2352 const struct pci_device_id
*id
)
2355 struct i7core_dev
*i7core_dev
;
2357 /* get the pci devices we want to reserve for our use */
2358 mutex_lock(&i7core_edac_lock
);
2361 * All memory controllers are allocated at the first pass.
2363 if (unlikely(probed
>= 1)) {
2364 mutex_unlock(&i7core_edac_lock
);
2369 rc
= i7core_get_all_devices();
2370 if (unlikely(rc
< 0))
2373 list_for_each_entry(i7core_dev
, &i7core_edac_list
, list
) {
2375 rc
= i7core_register_mci(i7core_dev
);
2376 if (unlikely(rc
< 0))
2381 * Nehalem-EX uses a different memory controller. However, as the
2382 * memory controller is not visible on some Nehalem/Nehalem-EP, we
2383 * need to indirectly probe via a X58 PCI device. The same devices
2384 * are found on (some) Nehalem-EX. So, on those machines, the
2385 * probe routine needs to return -ENODEV, as the actual Memory
2386 * Controller registers won't be detected.
2393 i7core_printk(KERN_INFO
,
2394 "Driver loaded, %d memory controller(s) found.\n",
2397 mutex_unlock(&i7core_edac_lock
);
2401 list_for_each_entry(i7core_dev
, &i7core_edac_list
, list
)
2402 i7core_unregister_mci(i7core_dev
);
2404 i7core_put_all_devices();
2406 mutex_unlock(&i7core_edac_lock
);
2411 * i7core_remove destructor for one instance of device
2414 static void __devexit
i7core_remove(struct pci_dev
*pdev
)
2416 struct i7core_dev
*i7core_dev
;
2418 debugf0(__FILE__
": %s()\n", __func__
);
2421 * we have a trouble here: pdev value for removal will be wrong, since
2422 * it will point to the X58 register used to detect that the machine
2423 * is a Nehalem or upper design. However, due to the way several PCI
2424 * devices are grouped together to provide MC functionality, we need
2425 * to use a different method for releasing the devices
2428 mutex_lock(&i7core_edac_lock
);
2430 if (unlikely(!probed
)) {
2431 mutex_unlock(&i7core_edac_lock
);
2435 list_for_each_entry(i7core_dev
, &i7core_edac_list
, list
)
2436 i7core_unregister_mci(i7core_dev
);
2438 /* Release PCI resources */
2439 i7core_put_all_devices();
2443 mutex_unlock(&i7core_edac_lock
);
2446 MODULE_DEVICE_TABLE(pci
, i7core_pci_tbl
);
2449 * i7core_driver pci_driver structure for this module
2452 static struct pci_driver i7core_driver
= {
2453 .name
= "i7core_edac",
2454 .probe
= i7core_probe
,
2455 .remove
= __devexit_p(i7core_remove
),
2456 .id_table
= i7core_pci_tbl
,
2460 * i7core_init Module entry function
2461 * Try to initialize this module for its devices
2463 static int __init
i7core_init(void)
2467 debugf2("MC: " __FILE__
": %s()\n", __func__
);
2469 /* Ensure that the OPSTATE is set correctly for POLL or NMI */
2473 i7core_xeon_pci_fixup(pci_dev_table
);
2475 pci_rc
= pci_register_driver(&i7core_driver
);
2480 i7core_printk(KERN_ERR
, "Failed to register device with error %d.\n",
2487 * i7core_exit() Module exit function
2488 * Unregister the driver
2490 static void __exit
i7core_exit(void)
2492 debugf2("MC: " __FILE__
": %s()\n", __func__
);
2493 pci_unregister_driver(&i7core_driver
);
2496 module_init(i7core_init
);
2497 module_exit(i7core_exit
);
2499 MODULE_LICENSE("GPL");
2500 MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
2501 MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
2502 MODULE_DESCRIPTION("MC Driver for Intel i7 Core memory controllers - "
2505 module_param(edac_op_state
, int, 0444);
2506 MODULE_PARM_DESC(edac_op_state
, "EDAC Error Reporting state: 0=Poll,1=NMI");