0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/module.h>
0013 #include <linux/init.h>
0014 #include <linux/pci.h>
0015 #include <linux/pci_ids.h>
0016 #include <linux/edac.h>
0017 #include "edac_module.h"
0018
0019 #define EDAC_MOD_STR "i82975x_edac"
0020
0021 #define i82975x_printk(level, fmt, arg...) \
0022 edac_printk(level, "i82975x", fmt, ##arg)
0023
0024 #define i82975x_mc_printk(mci, level, fmt, arg...) \
0025 edac_mc_chipset_printk(mci, level, "i82975x", fmt, ##arg)
0026
0027 #ifndef PCI_DEVICE_ID_INTEL_82975_0
0028 #define PCI_DEVICE_ID_INTEL_82975_0 0x277c
0029 #endif
0030
0031 #define I82975X_NR_DIMMS 8
0032 #define I82975X_NR_CSROWS(nr_chans) (I82975X_NR_DIMMS / (nr_chans))
0033
0034
0035 #define I82975X_EAP 0x58
0036
0037
0038
0039
0040
0041
0042 #define I82975X_DERRSYN 0x5c
0043
0044
0045
0046
0047 #define I82975X_DES 0x5d
0048
0049
0050
0051
0052
0053 #define I82975X_ERRSTS 0xc8
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071 #define I82975X_ERRCMD 0xca
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083 #define I82975X_SMICMD 0xcc
0084
0085
0086
0087
0088
0089
0090 #define I82975X_SCICMD 0xce
0091
0092
0093
0094
0095
0096
0097 #define I82975X_XEAP 0xfc
0098
0099
0100
0101
0102
0103 #define I82975X_MCHBAR 0x44
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114 #define I82975X_DRB_SHIFT 25
0115
0116 #define I82975X_DRB 0x100
0117
0118
0119
0120
0121
0122
0123
0124 #define I82975X_DRB_CH0R0 0x100
0125 #define I82975X_DRB_CH0R1 0x101
0126 #define I82975X_DRB_CH0R2 0x102
0127 #define I82975X_DRB_CH0R3 0x103
0128 #define I82975X_DRB_CH1R0 0x180
0129 #define I82975X_DRB_CH1R1 0x181
0130 #define I82975X_DRB_CH1R2 0x182
0131 #define I82975X_DRB_CH1R3 0x183
0132
0133
0134 #define I82975X_DRA 0x108
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149 #define I82975X_DRA_CH0R01 0x108
0150 #define I82975X_DRA_CH0R23 0x109
0151 #define I82975X_DRA_CH1R01 0x188
0152 #define I82975X_DRA_CH1R23 0x189
0153
0154
0155 #define I82975X_BNKARC 0x10e
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166 #define I82975X_C0BNKARC 0x10e
0167 #define I82975X_C1BNKARC 0x18e
0168
0169
0170
0171 #define I82975X_DRC 0x120
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191 #define I82975X_DRC_CH0M0 0x120
0192 #define I82975X_DRC_CH1M0 0x1A0
0193
0194
0195 #define I82975X_DRC_M1 0x124
0196
0197
0198
0199
0200
0201 #define I82975X_DRC_CH0M1 0x124
0202 #define I82975X_DRC_CH1M1 0x1A4
0203
0204 enum i82975x_chips {
0205 I82975X = 0,
0206 };
0207
0208 struct i82975x_pvt {
0209 void __iomem *mch_window;
0210 };
0211
0212 struct i82975x_dev_info {
0213 const char *ctl_name;
0214 };
0215
0216 struct i82975x_error_info {
0217 u16 errsts;
0218 u32 eap;
0219 u8 des;
0220 u8 derrsyn;
0221 u16 errsts2;
0222 u8 chan;
0223 u8 xeap;
0224 };
0225
0226 static const struct i82975x_dev_info i82975x_devs[] = {
0227 [I82975X] = {
0228 .ctl_name = "i82975x"
0229 },
0230 };
0231
0232 static struct pci_dev *mci_pdev;
0233
0234
0235
0236 static int i82975x_registered = 1;
0237
0238 static void i82975x_get_error_info(struct mem_ctl_info *mci,
0239 struct i82975x_error_info *info)
0240 {
0241 struct pci_dev *pdev;
0242
0243 pdev = to_pci_dev(mci->pdev);
0244
0245
0246
0247
0248
0249
0250 pci_read_config_word(pdev, I82975X_ERRSTS, &info->errsts);
0251 pci_read_config_dword(pdev, I82975X_EAP, &info->eap);
0252 pci_read_config_byte(pdev, I82975X_XEAP, &info->xeap);
0253 pci_read_config_byte(pdev, I82975X_DES, &info->des);
0254 pci_read_config_byte(pdev, I82975X_DERRSYN, &info->derrsyn);
0255 pci_read_config_word(pdev, I82975X_ERRSTS, &info->errsts2);
0256
0257 pci_write_bits16(pdev, I82975X_ERRSTS, 0x0003, 0x0003);
0258
0259
0260
0261
0262
0263
0264
0265 if (!(info->errsts2 & 0x0003))
0266 return;
0267
0268 if ((info->errsts ^ info->errsts2) & 0x0003) {
0269 pci_read_config_dword(pdev, I82975X_EAP, &info->eap);
0270 pci_read_config_byte(pdev, I82975X_XEAP, &info->xeap);
0271 pci_read_config_byte(pdev, I82975X_DES, &info->des);
0272 pci_read_config_byte(pdev, I82975X_DERRSYN,
0273 &info->derrsyn);
0274 }
0275 }
0276
0277 static int i82975x_process_error_info(struct mem_ctl_info *mci,
0278 struct i82975x_error_info *info, int handle_errors)
0279 {
0280 int row, chan;
0281 unsigned long offst, page;
0282
0283 if (!(info->errsts2 & 0x0003))
0284 return 0;
0285
0286 if (!handle_errors)
0287 return 1;
0288
0289 if ((info->errsts ^ info->errsts2) & 0x0003) {
0290 edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1, 0, 0, 0,
0291 -1, -1, -1, "UE overwrote CE", "");
0292 info->errsts = info->errsts2;
0293 }
0294
0295 page = (unsigned long) info->eap;
0296 page >>= 1;
0297 if (info->xeap & 1)
0298 page |= 0x80000000;
0299 page >>= (PAGE_SHIFT - 1);
0300 row = edac_mc_find_csrow_by_page(mci, page);
0301
0302 if (row == -1) {
0303 i82975x_mc_printk(mci, KERN_ERR, "error processing EAP:\n"
0304 "\tXEAP=%u\n"
0305 "\t EAP=0x%08x\n"
0306 "\tPAGE=0x%08x\n",
0307 (info->xeap & 1) ? 1 : 0, info->eap, (unsigned int) page);
0308 return 0;
0309 }
0310 chan = (mci->csrows[row]->nr_channels == 1) ? 0 : info->eap & 1;
0311 offst = info->eap
0312 & ((1 << PAGE_SHIFT) -
0313 (1 << mci->csrows[row]->channels[chan]->dimm->grain));
0314
0315 if (info->errsts & 0x0002)
0316 edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1,
0317 page, offst, 0,
0318 row, -1, -1,
0319 "i82975x UE", "");
0320 else
0321 edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1,
0322 page, offst, info->derrsyn,
0323 row, chan ? chan : 0, -1,
0324 "i82975x CE", "");
0325
0326 return 1;
0327 }
0328
0329 static void i82975x_check(struct mem_ctl_info *mci)
0330 {
0331 struct i82975x_error_info info;
0332
0333 i82975x_get_error_info(mci, &info);
0334 i82975x_process_error_info(mci, &info, 1);
0335 }
0336
0337
0338 static int dual_channel_active(void __iomem *mch_window)
0339 {
0340
0341
0342
0343
0344
0345
0346
0347
0348 u8 drb[4][2];
0349 int row;
0350 int dualch;
0351
0352 for (dualch = 1, row = 0; dualch && (row < 4); row++) {
0353 drb[row][0] = readb(mch_window + I82975X_DRB + row);
0354 drb[row][1] = readb(mch_window + I82975X_DRB + row + 0x80);
0355 dualch = dualch && (drb[row][0] == drb[row][1]);
0356 }
0357 return dualch;
0358 }
0359
0360 static void i82975x_init_csrows(struct mem_ctl_info *mci,
0361 struct pci_dev *pdev, void __iomem *mch_window)
0362 {
0363 struct csrow_info *csrow;
0364 unsigned long last_cumul_size;
0365 u8 value;
0366 u32 cumul_size, nr_pages;
0367 int index, chan;
0368 struct dimm_info *dimm;
0369
0370 last_cumul_size = 0;
0371
0372
0373
0374
0375
0376
0377
0378
0379
0380
0381 for (index = 0; index < mci->nr_csrows; index++) {
0382 csrow = mci->csrows[index];
0383
0384 value = readb(mch_window + I82975X_DRB + index +
0385 ((index >= 4) ? 0x80 : 0));
0386 cumul_size = value;
0387 cumul_size <<= (I82975X_DRB_SHIFT - PAGE_SHIFT);
0388
0389
0390
0391
0392 if (csrow->nr_channels > 1)
0393 cumul_size <<= 1;
0394 edac_dbg(3, "(%d) cumul_size 0x%x\n", index, cumul_size);
0395
0396 nr_pages = cumul_size - last_cumul_size;
0397 if (!nr_pages)
0398 continue;
0399
0400
0401
0402
0403
0404
0405
0406 for (chan = 0; chan < csrow->nr_channels; chan++) {
0407 dimm = mci->csrows[index]->channels[chan]->dimm;
0408
0409 dimm->nr_pages = nr_pages / csrow->nr_channels;
0410
0411 snprintf(csrow->channels[chan]->dimm->label, EDAC_MC_LABEL_LEN, "DIMM %c%d",
0412 (chan == 0) ? 'A' : 'B',
0413 index);
0414 dimm->grain = 1 << 7;
0415
0416
0417 dimm->dtype = DEV_X8;
0418
0419 dimm->mtype = MEM_DDR2;
0420 dimm->edac_mode = EDAC_SECDED;
0421 }
0422
0423 csrow->first_page = last_cumul_size;
0424 csrow->last_page = cumul_size - 1;
0425 last_cumul_size = cumul_size;
0426 }
0427 }
0428
0429
0430
0431 #ifdef i82975x_DEBUG_IOMEM
0432 static void i82975x_print_dram_timings(void __iomem *mch_window)
0433 {
0434
0435
0436
0437
0438
0439
0440 static const int caslats[4] = { 5, 4, 3, 6 };
0441 u32 dtreg[2];
0442
0443 dtreg[0] = readl(mch_window + 0x114);
0444 dtreg[1] = readl(mch_window + 0x194);
0445 i82975x_printk(KERN_INFO, "DRAM Timings : Ch0 Ch1\n"
0446 " RAS Active Min = %d %d\n"
0447 " CAS latency = %d %d\n"
0448 " RAS to CAS = %d %d\n"
0449 " RAS precharge = %d %d\n",
0450 (dtreg[0] >> 19 ) & 0x0f,
0451 (dtreg[1] >> 19) & 0x0f,
0452 caslats[(dtreg[0] >> 8) & 0x03],
0453 caslats[(dtreg[1] >> 8) & 0x03],
0454 ((dtreg[0] >> 4) & 0x07) + 2,
0455 ((dtreg[1] >> 4) & 0x07) + 2,
0456 (dtreg[0] & 0x07) + 2,
0457 (dtreg[1] & 0x07) + 2
0458 );
0459
0460 }
0461 #endif
0462
0463 static int i82975x_probe1(struct pci_dev *pdev, int dev_idx)
0464 {
0465 int rc = -ENODEV;
0466 struct mem_ctl_info *mci;
0467 struct edac_mc_layer layers[2];
0468 struct i82975x_pvt *pvt;
0469 void __iomem *mch_window;
0470 u32 mchbar;
0471 u32 drc[2];
0472 struct i82975x_error_info discard;
0473 int chans;
0474 #ifdef i82975x_DEBUG_IOMEM
0475 u8 c0drb[4];
0476 u8 c1drb[4];
0477 #endif
0478
0479 edac_dbg(0, "\n");
0480
0481 pci_read_config_dword(pdev, I82975X_MCHBAR, &mchbar);
0482 if (!(mchbar & 1)) {
0483 edac_dbg(3, "failed, MCHBAR disabled!\n");
0484 goto fail0;
0485 }
0486 mchbar &= 0xffffc000;
0487 mch_window = ioremap(mchbar, 0x1000);
0488 if (!mch_window) {
0489 edac_dbg(3, "error ioremapping MCHBAR!\n");
0490 goto fail0;
0491 }
0492
0493 #ifdef i82975x_DEBUG_IOMEM
0494 i82975x_printk(KERN_INFO, "MCHBAR real = %0x, remapped = %p\n",
0495 mchbar, mch_window);
0496
0497 c0drb[0] = readb(mch_window + I82975X_DRB_CH0R0);
0498 c0drb[1] = readb(mch_window + I82975X_DRB_CH0R1);
0499 c0drb[2] = readb(mch_window + I82975X_DRB_CH0R2);
0500 c0drb[3] = readb(mch_window + I82975X_DRB_CH0R3);
0501 c1drb[0] = readb(mch_window + I82975X_DRB_CH1R0);
0502 c1drb[1] = readb(mch_window + I82975X_DRB_CH1R1);
0503 c1drb[2] = readb(mch_window + I82975X_DRB_CH1R2);
0504 c1drb[3] = readb(mch_window + I82975X_DRB_CH1R3);
0505 i82975x_printk(KERN_INFO, "DRBCH0R0 = 0x%02x\n", c0drb[0]);
0506 i82975x_printk(KERN_INFO, "DRBCH0R1 = 0x%02x\n", c0drb[1]);
0507 i82975x_printk(KERN_INFO, "DRBCH0R2 = 0x%02x\n", c0drb[2]);
0508 i82975x_printk(KERN_INFO, "DRBCH0R3 = 0x%02x\n", c0drb[3]);
0509 i82975x_printk(KERN_INFO, "DRBCH1R0 = 0x%02x\n", c1drb[0]);
0510 i82975x_printk(KERN_INFO, "DRBCH1R1 = 0x%02x\n", c1drb[1]);
0511 i82975x_printk(KERN_INFO, "DRBCH1R2 = 0x%02x\n", c1drb[2]);
0512 i82975x_printk(KERN_INFO, "DRBCH1R3 = 0x%02x\n", c1drb[3]);
0513 #endif
0514
0515 drc[0] = readl(mch_window + I82975X_DRC_CH0M0);
0516 drc[1] = readl(mch_window + I82975X_DRC_CH1M0);
0517 #ifdef i82975x_DEBUG_IOMEM
0518 i82975x_printk(KERN_INFO, "DRC_CH0 = %0x, %s\n", drc[0],
0519 ((drc[0] >> 21) & 3) == 1 ?
0520 "ECC enabled" : "ECC disabled");
0521 i82975x_printk(KERN_INFO, "DRC_CH1 = %0x, %s\n", drc[1],
0522 ((drc[1] >> 21) & 3) == 1 ?
0523 "ECC enabled" : "ECC disabled");
0524
0525 i82975x_printk(KERN_INFO, "C0 BNKARC = %0x\n",
0526 readw(mch_window + I82975X_C0BNKARC));
0527 i82975x_printk(KERN_INFO, "C1 BNKARC = %0x\n",
0528 readw(mch_window + I82975X_C1BNKARC));
0529 i82975x_print_dram_timings(mch_window);
0530 goto fail1;
0531 #endif
0532 if (!(((drc[0] >> 21) & 3) == 1 || ((drc[1] >> 21) & 3) == 1)) {
0533 i82975x_printk(KERN_INFO, "ECC disabled on both channels.\n");
0534 goto fail1;
0535 }
0536
0537 chans = dual_channel_active(mch_window) + 1;
0538
0539
0540 layers[0].type = EDAC_MC_LAYER_CHIP_SELECT;
0541 layers[0].size = I82975X_NR_DIMMS;
0542 layers[0].is_virt_csrow = true;
0543 layers[1].type = EDAC_MC_LAYER_CHANNEL;
0544 layers[1].size = I82975X_NR_CSROWS(chans);
0545 layers[1].is_virt_csrow = false;
0546 mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, sizeof(*pvt));
0547 if (!mci) {
0548 rc = -ENOMEM;
0549 goto fail1;
0550 }
0551
0552 edac_dbg(3, "init mci\n");
0553 mci->pdev = &pdev->dev;
0554 mci->mtype_cap = MEM_FLAG_DDR2;
0555 mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED;
0556 mci->edac_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED;
0557 mci->mod_name = EDAC_MOD_STR;
0558 mci->ctl_name = i82975x_devs[dev_idx].ctl_name;
0559 mci->dev_name = pci_name(pdev);
0560 mci->edac_check = i82975x_check;
0561 mci->ctl_page_to_phys = NULL;
0562 edac_dbg(3, "init pvt\n");
0563 pvt = (struct i82975x_pvt *) mci->pvt_info;
0564 pvt->mch_window = mch_window;
0565 i82975x_init_csrows(mci, pdev, mch_window);
0566 mci->scrub_mode = SCRUB_HW_SRC;
0567 i82975x_get_error_info(mci, &discard);
0568
0569
0570 if (edac_mc_add_mc(mci)) {
0571 edac_dbg(3, "failed edac_mc_add_mc()\n");
0572 goto fail2;
0573 }
0574
0575
0576 edac_dbg(3, "success\n");
0577 return 0;
0578
0579 fail2:
0580 edac_mc_free(mci);
0581
0582 fail1:
0583 iounmap(mch_window);
0584 fail0:
0585 return rc;
0586 }
0587
0588
0589 static int i82975x_init_one(struct pci_dev *pdev,
0590 const struct pci_device_id *ent)
0591 {
0592 int rc;
0593
0594 edac_dbg(0, "\n");
0595
0596 if (pci_enable_device(pdev) < 0)
0597 return -EIO;
0598
0599 rc = i82975x_probe1(pdev, ent->driver_data);
0600
0601 if (mci_pdev == NULL)
0602 mci_pdev = pci_dev_get(pdev);
0603
0604 return rc;
0605 }
0606
0607 static void i82975x_remove_one(struct pci_dev *pdev)
0608 {
0609 struct mem_ctl_info *mci;
0610 struct i82975x_pvt *pvt;
0611
0612 edac_dbg(0, "\n");
0613
0614 mci = edac_mc_del_mc(&pdev->dev);
0615 if (mci == NULL)
0616 return;
0617
0618 pvt = mci->pvt_info;
0619 if (pvt->mch_window)
0620 iounmap( pvt->mch_window );
0621
0622 edac_mc_free(mci);
0623 }
0624
0625 static const struct pci_device_id i82975x_pci_tbl[] = {
0626 {
0627 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
0628 I82975X
0629 },
0630 {
0631 0,
0632 }
0633 };
0634
0635 MODULE_DEVICE_TABLE(pci, i82975x_pci_tbl);
0636
0637 static struct pci_driver i82975x_driver = {
0638 .name = EDAC_MOD_STR,
0639 .probe = i82975x_init_one,
0640 .remove = i82975x_remove_one,
0641 .id_table = i82975x_pci_tbl,
0642 };
0643
0644 static int __init i82975x_init(void)
0645 {
0646 int pci_rc;
0647
0648 edac_dbg(3, "\n");
0649
0650
0651 opstate_init();
0652
0653 pci_rc = pci_register_driver(&i82975x_driver);
0654 if (pci_rc < 0)
0655 goto fail0;
0656
0657 if (mci_pdev == NULL) {
0658 mci_pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
0659 PCI_DEVICE_ID_INTEL_82975_0, NULL);
0660
0661 if (!mci_pdev) {
0662 edac_dbg(0, "i82975x pci_get_device fail\n");
0663 pci_rc = -ENODEV;
0664 goto fail1;
0665 }
0666
0667 pci_rc = i82975x_init_one(mci_pdev, i82975x_pci_tbl);
0668
0669 if (pci_rc < 0) {
0670 edac_dbg(0, "i82975x init fail\n");
0671 pci_rc = -ENODEV;
0672 goto fail1;
0673 }
0674 }
0675
0676 return 0;
0677
0678 fail1:
0679 pci_unregister_driver(&i82975x_driver);
0680
0681 fail0:
0682 pci_dev_put(mci_pdev);
0683 return pci_rc;
0684 }
0685
0686 static void __exit i82975x_exit(void)
0687 {
0688 edac_dbg(3, "\n");
0689
0690 pci_unregister_driver(&i82975x_driver);
0691
0692 if (!i82975x_registered) {
0693 i82975x_remove_one(mci_pdev);
0694 pci_dev_put(mci_pdev);
0695 }
0696 }
0697
0698 module_init(i82975x_init);
0699 module_exit(i82975x_exit);
0700
0701 MODULE_LICENSE("GPL");
0702 MODULE_AUTHOR("Arvind R. <arvino55@gmail.com>");
0703 MODULE_DESCRIPTION("MC support for Intel 82975 memory hub controllers");
0704
0705 module_param(edac_op_state, int, 0444);
0706 MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");