This source file includes following definitions.
- i82975x_get_error_info
- i82975x_process_error_info
- i82975x_check
- dual_channel_active
- i82975x_init_csrows
- i82975x_print_dram_timings
- i82975x_probe1
- i82975x_init_one
- i82975x_remove_one
- i82975x_init
- i82975x_exit
1
2
3
4
5
6
7
8
9
10
11
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/pci.h>
15 #include <linux/pci_ids.h>
16 #include <linux/edac.h>
17 #include "edac_module.h"
18
19 #define EDAC_MOD_STR "i82975x_edac"
20
21 #define i82975x_printk(level, fmt, arg...) \
22 edac_printk(level, "i82975x", fmt, ##arg)
23
24 #define i82975x_mc_printk(mci, level, fmt, arg...) \
25 edac_mc_chipset_printk(mci, level, "i82975x", fmt, ##arg)
26
27 #ifndef PCI_DEVICE_ID_INTEL_82975_0
28 #define PCI_DEVICE_ID_INTEL_82975_0 0x277c
29 #endif
30
31 #define I82975X_NR_DIMMS 8
32 #define I82975X_NR_CSROWS(nr_chans) (I82975X_NR_DIMMS / (nr_chans))
33
34
35 #define I82975X_EAP 0x58
36
37
38
39
40
41
42 #define I82975X_DERRSYN 0x5c
43
44
45
46
47 #define I82975X_DES 0x5d
48
49
50
51
52
53 #define I82975X_ERRSTS 0xc8
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 #define I82975X_ERRCMD 0xca
72
73
74
75
76
77
78
79
80
81
82
83 #define I82975X_SMICMD 0xcc
84
85
86
87
88
89
90 #define I82975X_SCICMD 0xce
91
92
93
94
95
96
97 #define I82975X_XEAP 0xfc
98
99
100
101
102
103 #define I82975X_MCHBAR 0x44
104
105
106
107
108
109
110
111
112
113
114 #define I82975X_DRB_SHIFT 25
115
116 #define I82975X_DRB 0x100
117
118
119
120
121
122
123
124 #define I82975X_DRB_CH0R0 0x100
125 #define I82975X_DRB_CH0R1 0x101
126 #define I82975X_DRB_CH0R2 0x102
127 #define I82975X_DRB_CH0R3 0x103
128 #define I82975X_DRB_CH1R0 0x180
129 #define I82975X_DRB_CH1R1 0x181
130 #define I82975X_DRB_CH1R2 0x182
131 #define I82975X_DRB_CH1R3 0x183
132
133
134 #define I82975X_DRA 0x108
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149 #define I82975X_DRA_CH0R01 0x108
150 #define I82975X_DRA_CH0R23 0x109
151 #define I82975X_DRA_CH1R01 0x188
152 #define I82975X_DRA_CH1R23 0x189
153
154
155 #define I82975X_BNKARC 0x10e
156
157
158
159
160
161
162
163
164
165
166 #define I82975X_C0BNKARC 0x10e
167 #define I82975X_C1BNKARC 0x18e
168
169
170
171 #define I82975X_DRC 0x120
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191 #define I82975X_DRC_CH0M0 0x120
192 #define I82975X_DRC_CH1M0 0x1A0
193
194
195 #define I82975X_DRC_M1 0x124
196
197
198
199
200
201 #define I82975X_DRC_CH0M1 0x124
202 #define I82975X_DRC_CH1M1 0x1A4
203
204 enum i82975x_chips {
205 I82975X = 0,
206 };
207
208 struct i82975x_pvt {
209 void __iomem *mch_window;
210 };
211
212 struct i82975x_dev_info {
213 const char *ctl_name;
214 };
215
216 struct i82975x_error_info {
217 u16 errsts;
218 u32 eap;
219 u8 des;
220 u8 derrsyn;
221 u16 errsts2;
222 u8 chan;
223 u8 xeap;
224 };
225
226 static const struct i82975x_dev_info i82975x_devs[] = {
227 [I82975X] = {
228 .ctl_name = "i82975x"
229 },
230 };
231
232 static struct pci_dev *mci_pdev;
233
234
235
236 static int i82975x_registered = 1;
237
238 static void i82975x_get_error_info(struct mem_ctl_info *mci,
239 struct i82975x_error_info *info)
240 {
241 struct pci_dev *pdev;
242
243 pdev = to_pci_dev(mci->pdev);
244
245
246
247
248
249
250 pci_read_config_word(pdev, I82975X_ERRSTS, &info->errsts);
251 pci_read_config_dword(pdev, I82975X_EAP, &info->eap);
252 pci_read_config_byte(pdev, I82975X_XEAP, &info->xeap);
253 pci_read_config_byte(pdev, I82975X_DES, &info->des);
254 pci_read_config_byte(pdev, I82975X_DERRSYN, &info->derrsyn);
255 pci_read_config_word(pdev, I82975X_ERRSTS, &info->errsts2);
256
257 pci_write_bits16(pdev, I82975X_ERRSTS, 0x0003, 0x0003);
258
259
260
261
262
263
264
265 if (!(info->errsts2 & 0x0003))
266 return;
267
268 if ((info->errsts ^ info->errsts2) & 0x0003) {
269 pci_read_config_dword(pdev, I82975X_EAP, &info->eap);
270 pci_read_config_byte(pdev, I82975X_XEAP, &info->xeap);
271 pci_read_config_byte(pdev, I82975X_DES, &info->des);
272 pci_read_config_byte(pdev, I82975X_DERRSYN,
273 &info->derrsyn);
274 }
275 }
276
277 static int i82975x_process_error_info(struct mem_ctl_info *mci,
278 struct i82975x_error_info *info, int handle_errors)
279 {
280 int row, chan;
281 unsigned long offst, page;
282
283 if (!(info->errsts2 & 0x0003))
284 return 0;
285
286 if (!handle_errors)
287 return 1;
288
289 if ((info->errsts ^ info->errsts2) & 0x0003) {
290 edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1, 0, 0, 0,
291 -1, -1, -1, "UE overwrote CE", "");
292 info->errsts = info->errsts2;
293 }
294
295 page = (unsigned long) info->eap;
296 page >>= 1;
297 if (info->xeap & 1)
298 page |= 0x80000000;
299 page >>= (PAGE_SHIFT - 1);
300 row = edac_mc_find_csrow_by_page(mci, page);
301
302 if (row == -1) {
303 i82975x_mc_printk(mci, KERN_ERR, "error processing EAP:\n"
304 "\tXEAP=%u\n"
305 "\t EAP=0x%08x\n"
306 "\tPAGE=0x%08x\n",
307 (info->xeap & 1) ? 1 : 0, info->eap, (unsigned int) page);
308 return 0;
309 }
310 chan = (mci->csrows[row]->nr_channels == 1) ? 0 : info->eap & 1;
311 offst = info->eap
312 & ((1 << PAGE_SHIFT) -
313 (1 << mci->csrows[row]->channels[chan]->dimm->grain));
314
315 if (info->errsts & 0x0002)
316 edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1,
317 page, offst, 0,
318 row, -1, -1,
319 "i82975x UE", "");
320 else
321 edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1,
322 page, offst, info->derrsyn,
323 row, chan ? chan : 0, -1,
324 "i82975x CE", "");
325
326 return 1;
327 }
328
329 static void i82975x_check(struct mem_ctl_info *mci)
330 {
331 struct i82975x_error_info info;
332
333 edac_dbg(1, "MC%d\n", mci->mc_idx);
334 i82975x_get_error_info(mci, &info);
335 i82975x_process_error_info(mci, &info, 1);
336 }
337
338
339 static int dual_channel_active(void __iomem *mch_window)
340 {
341
342
343
344
345
346
347
348
349 u8 drb[4][2];
350 int row;
351 int dualch;
352
353 for (dualch = 1, row = 0; dualch && (row < 4); row++) {
354 drb[row][0] = readb(mch_window + I82975X_DRB + row);
355 drb[row][1] = readb(mch_window + I82975X_DRB + row + 0x80);
356 dualch = dualch && (drb[row][0] == drb[row][1]);
357 }
358 return dualch;
359 }
360
361 static void i82975x_init_csrows(struct mem_ctl_info *mci,
362 struct pci_dev *pdev, void __iomem *mch_window)
363 {
364 struct csrow_info *csrow;
365 unsigned long last_cumul_size;
366 u8 value;
367 u32 cumul_size, nr_pages;
368 int index, chan;
369 struct dimm_info *dimm;
370
371 last_cumul_size = 0;
372
373
374
375
376
377
378
379
380
381
382 for (index = 0; index < mci->nr_csrows; index++) {
383 csrow = mci->csrows[index];
384
385 value = readb(mch_window + I82975X_DRB + index +
386 ((index >= 4) ? 0x80 : 0));
387 cumul_size = value;
388 cumul_size <<= (I82975X_DRB_SHIFT - PAGE_SHIFT);
389
390
391
392
393 if (csrow->nr_channels > 1)
394 cumul_size <<= 1;
395 edac_dbg(3, "(%d) cumul_size 0x%x\n", index, cumul_size);
396
397 nr_pages = cumul_size - last_cumul_size;
398 if (!nr_pages)
399 continue;
400
401
402
403
404
405
406
407 for (chan = 0; chan < csrow->nr_channels; chan++) {
408 dimm = mci->csrows[index]->channels[chan]->dimm;
409
410 dimm->nr_pages = nr_pages / csrow->nr_channels;
411
412 snprintf(csrow->channels[chan]->dimm->label, EDAC_MC_LABEL_LEN, "DIMM %c%d",
413 (chan == 0) ? 'A' : 'B',
414 index);
415 dimm->grain = 1 << 7;
416
417
418 dimm->dtype = DEV_X8;
419
420 dimm->mtype = MEM_DDR2;
421 dimm->edac_mode = EDAC_SECDED;
422 }
423
424 csrow->first_page = last_cumul_size;
425 csrow->last_page = cumul_size - 1;
426 last_cumul_size = cumul_size;
427 }
428 }
429
430
431
432 #ifdef i82975x_DEBUG_IOMEM
433 static void i82975x_print_dram_timings(void __iomem *mch_window)
434 {
435
436
437
438
439
440
441 static const int caslats[4] = { 5, 4, 3, 6 };
442 u32 dtreg[2];
443
444 dtreg[0] = readl(mch_window + 0x114);
445 dtreg[1] = readl(mch_window + 0x194);
446 i82975x_printk(KERN_INFO, "DRAM Timings : Ch0 Ch1\n"
447 " RAS Active Min = %d %d\n"
448 " CAS latency = %d %d\n"
449 " RAS to CAS = %d %d\n"
450 " RAS precharge = %d %d\n",
451 (dtreg[0] >> 19 ) & 0x0f,
452 (dtreg[1] >> 19) & 0x0f,
453 caslats[(dtreg[0] >> 8) & 0x03],
454 caslats[(dtreg[1] >> 8) & 0x03],
455 ((dtreg[0] >> 4) & 0x07) + 2,
456 ((dtreg[1] >> 4) & 0x07) + 2,
457 (dtreg[0] & 0x07) + 2,
458 (dtreg[1] & 0x07) + 2
459 );
460
461 }
462 #endif
463
464 static int i82975x_probe1(struct pci_dev *pdev, int dev_idx)
465 {
466 int rc = -ENODEV;
467 struct mem_ctl_info *mci;
468 struct edac_mc_layer layers[2];
469 struct i82975x_pvt *pvt;
470 void __iomem *mch_window;
471 u32 mchbar;
472 u32 drc[2];
473 struct i82975x_error_info discard;
474 int chans;
475 #ifdef i82975x_DEBUG_IOMEM
476 u8 c0drb[4];
477 u8 c1drb[4];
478 #endif
479
480 edac_dbg(0, "\n");
481
482 pci_read_config_dword(pdev, I82975X_MCHBAR, &mchbar);
483 if (!(mchbar & 1)) {
484 edac_dbg(3, "failed, MCHBAR disabled!\n");
485 goto fail0;
486 }
487 mchbar &= 0xffffc000;
488 mch_window = ioremap_nocache(mchbar, 0x1000);
489 if (!mch_window) {
490 edac_dbg(3, "error ioremapping MCHBAR!\n");
491 goto fail0;
492 }
493
494 #ifdef i82975x_DEBUG_IOMEM
495 i82975x_printk(KERN_INFO, "MCHBAR real = %0x, remapped = %p\n",
496 mchbar, mch_window);
497
498 c0drb[0] = readb(mch_window + I82975X_DRB_CH0R0);
499 c0drb[1] = readb(mch_window + I82975X_DRB_CH0R1);
500 c0drb[2] = readb(mch_window + I82975X_DRB_CH0R2);
501 c0drb[3] = readb(mch_window + I82975X_DRB_CH0R3);
502 c1drb[0] = readb(mch_window + I82975X_DRB_CH1R0);
503 c1drb[1] = readb(mch_window + I82975X_DRB_CH1R1);
504 c1drb[2] = readb(mch_window + I82975X_DRB_CH1R2);
505 c1drb[3] = readb(mch_window + I82975X_DRB_CH1R3);
506 i82975x_printk(KERN_INFO, "DRBCH0R0 = 0x%02x\n", c0drb[0]);
507 i82975x_printk(KERN_INFO, "DRBCH0R1 = 0x%02x\n", c0drb[1]);
508 i82975x_printk(KERN_INFO, "DRBCH0R2 = 0x%02x\n", c0drb[2]);
509 i82975x_printk(KERN_INFO, "DRBCH0R3 = 0x%02x\n", c0drb[3]);
510 i82975x_printk(KERN_INFO, "DRBCH1R0 = 0x%02x\n", c1drb[0]);
511 i82975x_printk(KERN_INFO, "DRBCH1R1 = 0x%02x\n", c1drb[1]);
512 i82975x_printk(KERN_INFO, "DRBCH1R2 = 0x%02x\n", c1drb[2]);
513 i82975x_printk(KERN_INFO, "DRBCH1R3 = 0x%02x\n", c1drb[3]);
514 #endif
515
516 drc[0] = readl(mch_window + I82975X_DRC_CH0M0);
517 drc[1] = readl(mch_window + I82975X_DRC_CH1M0);
518 #ifdef i82975x_DEBUG_IOMEM
519 i82975x_printk(KERN_INFO, "DRC_CH0 = %0x, %s\n", drc[0],
520 ((drc[0] >> 21) & 3) == 1 ?
521 "ECC enabled" : "ECC disabled");
522 i82975x_printk(KERN_INFO, "DRC_CH1 = %0x, %s\n", drc[1],
523 ((drc[1] >> 21) & 3) == 1 ?
524 "ECC enabled" : "ECC disabled");
525
526 i82975x_printk(KERN_INFO, "C0 BNKARC = %0x\n",
527 readw(mch_window + I82975X_C0BNKARC));
528 i82975x_printk(KERN_INFO, "C1 BNKARC = %0x\n",
529 readw(mch_window + I82975X_C1BNKARC));
530 i82975x_print_dram_timings(mch_window);
531 goto fail1;
532 #endif
533 if (!(((drc[0] >> 21) & 3) == 1 || ((drc[1] >> 21) & 3) == 1)) {
534 i82975x_printk(KERN_INFO, "ECC disabled on both channels.\n");
535 goto fail1;
536 }
537
538 chans = dual_channel_active(mch_window) + 1;
539
540
541 layers[0].type = EDAC_MC_LAYER_CHIP_SELECT;
542 layers[0].size = I82975X_NR_DIMMS;
543 layers[0].is_virt_csrow = true;
544 layers[1].type = EDAC_MC_LAYER_CHANNEL;
545 layers[1].size = I82975X_NR_CSROWS(chans);
546 layers[1].is_virt_csrow = false;
547 mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, sizeof(*pvt));
548 if (!mci) {
549 rc = -ENOMEM;
550 goto fail1;
551 }
552
553 edac_dbg(3, "init mci\n");
554 mci->pdev = &pdev->dev;
555 mci->mtype_cap = MEM_FLAG_DDR2;
556 mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED;
557 mci->edac_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED;
558 mci->mod_name = EDAC_MOD_STR;
559 mci->ctl_name = i82975x_devs[dev_idx].ctl_name;
560 mci->dev_name = pci_name(pdev);
561 mci->edac_check = i82975x_check;
562 mci->ctl_page_to_phys = NULL;
563 edac_dbg(3, "init pvt\n");
564 pvt = (struct i82975x_pvt *) mci->pvt_info;
565 pvt->mch_window = mch_window;
566 i82975x_init_csrows(mci, pdev, mch_window);
567 mci->scrub_mode = SCRUB_HW_SRC;
568 i82975x_get_error_info(mci, &discard);
569
570
571 if (edac_mc_add_mc(mci)) {
572 edac_dbg(3, "failed edac_mc_add_mc()\n");
573 goto fail2;
574 }
575
576
577 edac_dbg(3, "success\n");
578 return 0;
579
580 fail2:
581 edac_mc_free(mci);
582
583 fail1:
584 iounmap(mch_window);
585 fail0:
586 return rc;
587 }
588
589
590 static int i82975x_init_one(struct pci_dev *pdev,
591 const struct pci_device_id *ent)
592 {
593 int rc;
594
595 edac_dbg(0, "\n");
596
597 if (pci_enable_device(pdev) < 0)
598 return -EIO;
599
600 rc = i82975x_probe1(pdev, ent->driver_data);
601
602 if (mci_pdev == NULL)
603 mci_pdev = pci_dev_get(pdev);
604
605 return rc;
606 }
607
608 static void i82975x_remove_one(struct pci_dev *pdev)
609 {
610 struct mem_ctl_info *mci;
611 struct i82975x_pvt *pvt;
612
613 edac_dbg(0, "\n");
614
615 mci = edac_mc_del_mc(&pdev->dev);
616 if (mci == NULL)
617 return;
618
619 pvt = mci->pvt_info;
620 if (pvt->mch_window)
621 iounmap( pvt->mch_window );
622
623 edac_mc_free(mci);
624 }
625
626 static const struct pci_device_id i82975x_pci_tbl[] = {
627 {
628 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
629 I82975X
630 },
631 {
632 0,
633 }
634 };
635
636 MODULE_DEVICE_TABLE(pci, i82975x_pci_tbl);
637
638 static struct pci_driver i82975x_driver = {
639 .name = EDAC_MOD_STR,
640 .probe = i82975x_init_one,
641 .remove = i82975x_remove_one,
642 .id_table = i82975x_pci_tbl,
643 };
644
645 static int __init i82975x_init(void)
646 {
647 int pci_rc;
648
649 edac_dbg(3, "\n");
650
651
652 opstate_init();
653
654 pci_rc = pci_register_driver(&i82975x_driver);
655 if (pci_rc < 0)
656 goto fail0;
657
658 if (mci_pdev == NULL) {
659 mci_pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
660 PCI_DEVICE_ID_INTEL_82975_0, NULL);
661
662 if (!mci_pdev) {
663 edac_dbg(0, "i82975x pci_get_device fail\n");
664 pci_rc = -ENODEV;
665 goto fail1;
666 }
667
668 pci_rc = i82975x_init_one(mci_pdev, i82975x_pci_tbl);
669
670 if (pci_rc < 0) {
671 edac_dbg(0, "i82975x init fail\n");
672 pci_rc = -ENODEV;
673 goto fail1;
674 }
675 }
676
677 return 0;
678
679 fail1:
680 pci_unregister_driver(&i82975x_driver);
681
682 fail0:
683 pci_dev_put(mci_pdev);
684 return pci_rc;
685 }
686
687 static void __exit i82975x_exit(void)
688 {
689 edac_dbg(3, "\n");
690
691 pci_unregister_driver(&i82975x_driver);
692
693 if (!i82975x_registered) {
694 i82975x_remove_one(mci_pdev);
695 pci_dev_put(mci_pdev);
696 }
697 }
698
699 module_init(i82975x_init);
700 module_exit(i82975x_exit);
701
702 MODULE_LICENSE("GPL");
703 MODULE_AUTHOR("Arvind R. <arvino55@gmail.com>");
704 MODULE_DESCRIPTION("MC support for Intel 82975 memory hub controllers");
705
706 module_param(edac_op_state, int, 0444);
707 MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");