12 #include <linux/module.h>
14 #include <linux/pci.h>
19 #define X38_REVISION "1.1"
21 #define EDAC_MOD_STR "x38_edac"
23 #define PCI_DEVICE_ID_INTEL_X38_HB 0x29e0
26 #define X38_RANKS_PER_CHANNEL 4
27 #define X38_CHANNELS 2
31 #define X38_MCHBAR_LOW 0x48
32 #define X38_MCHBAR_HIGH 0x4c
33 #define X38_MCHBAR_MASK 0xfffffc000ULL
34 #define X38_MMR_WINDOW_SIZE 16384
41 #define X38_TOM_MASK 0x3ff
42 #define X38_TOM_SHIFT 26
44 #define X38_ERRSTS 0xc8
62 #define X38_ERRSTS_UE 0x0002
63 #define X38_ERRSTS_CE 0x0001
64 #define X38_ERRSTS_BITS (X38_ERRSTS_UE | X38_ERRSTS_CE)
69 #define X38_C0DRB 0x200
74 #define X38_C1DRB 0x600
75 #define X38_DRB_MASK 0x3ff
76 #define X38_DRB_SHIFT 26
78 #define X38_C0ECCERRLOG 0x280
90 #define X38_C1ECCERRLOG 0x680
91 #define X38_ECCERRLOG_CE 0x1
92 #define X38_ECCERRLOG_UE 0x2
93 #define X38_ECCERRLOG_RANK_BITS 0x18000000
94 #define X38_ECCERRLOG_SYNDROME_BITS 0xff0000
96 #define X38_CAPID0 0xe0
98 static int x38_channel_num;
100 static int how_many_channel(
struct pci_dev *pdev)
102 unsigned char capid0_8b;
104 pci_read_config_byte(pdev,
X38_CAPID0 + 8, &capid0_8b);
105 if (capid0_8b & 0x20) {
106 edac_dbg(0,
"In single channel mode\n");
109 edac_dbg(0,
"In dual channel mode\n");
113 return x38_channel_num;
116 static unsigned long eccerrlog_syndrome(
u64 log)
121 static int eccerrlog_row(
int channel,
u64 log)
146 static struct pci_dev *mci_pdev;
147 static int x38_registered = 1;
187 if (x38_channel_num == 2)
200 if (x38_channel_num == 2)
205 x38_clear_error_info(mci);
208 static void x38_process_error_info(
struct mem_ctl_info *mci,
220 "UE overwrote CE",
"");
224 for (channel = 0; channel < x38_channel_num; channel++) {
229 eccerrlog_row(channel, log),
234 0, 0, eccerrlog_syndrome(log),
235 eccerrlog_row(channel, log),
247 x38_get_and_clear_error_info(mci, &info);
248 x38_process_error_info(mci, &info);
270 "x38: mmio space beyond accessible range (0x%llx)\n",
271 (
unsigned long long)
u.mchbar);
278 (
unsigned long long)
u.mchbar);
284 static void x38_get_drbs(
void __iomem *window,
295 static bool x38_is_stacked(
struct pci_dev *pdev,
300 pci_read_config_word(pdev,
X38_TOM, &tom);
303 return drbs[
X38_CHANNELS - 1][X38_RANKS_PER_CHANNEL - 1] == tom;
306 static unsigned long drb_to_nr_pages(
308 bool stacked,
int channel,
int rank)
315 if (stacked && (channel == 1) && drbs[channel][rank] ==
316 drbs[channel][X38_RANKS_PER_CHANNEL - 1]) {
317 n -= drbs[0][X38_RANKS_PER_CHANNEL - 1];
324 static int x38_probe1(
struct pci_dev *pdev,
int dev_idx)
340 x38_get_drbs(window, drbs);
342 how_many_channel(pdev);
347 layers[0].is_virt_csrow =
true;
349 layers[1].size = x38_channel_num;
350 layers[1].is_virt_csrow =
false;
371 stacked = x38_is_stacked(pdev, drbs);
380 unsigned long nr_pages;
383 nr_pages = drb_to_nr_pages(drbs, stacked,
384 i / X38_RANKS_PER_CHANNEL,
385 i % X38_RANKS_PER_CHANNEL);
390 for (j = 0; j < x38_channel_num; j++) {
393 dimm->
nr_pages = nr_pages / x38_channel_num;
401 x38_clear_error_info(mci);
405 edac_dbg(3,
"MC: failed edac_mc_add_mc()\n");
466 .probe = x38_init_one,
468 .id_table = x38_pci_tbl,
471 static int __init x38_init(
void)
480 pci_rc = pci_register_driver(&x38_driver);
489 edac_dbg(0,
"x38 pci_get_device fail\n");
494 pci_rc = x38_init_one(mci_pdev, x38_pci_tbl);
514 static void __exit x38_exit(
void)
519 if (!x38_registered) {
520 x38_remove_one(mci_pdev);