1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include <linux/module.h>
21#include <linux/init.h>
22#include <linux/pci.h>
23#include <linux/pci_ids.h>
24#include <linux/edac.h>
25#include "edac_core.h"
26
27#define E752X_REVISION " Ver: 2.0.2"
28#define EDAC_MOD_STR "e752x_edac"
29
30static int report_non_memory_errors;
31static int force_function_unhide;
32static int sysbus_parity = -1;
33
34static struct edac_pci_ctl_info *e752x_pci;
35
36#define e752x_printk(level, fmt, arg...) \
37 edac_printk(level, "e752x", fmt, ##arg)
38
39#define e752x_mc_printk(mci, level, fmt, arg...) \
40 edac_mc_chipset_printk(mci, level, "e752x", fmt, ##arg)
41
42#ifndef PCI_DEVICE_ID_INTEL_7520_0
43#define PCI_DEVICE_ID_INTEL_7520_0 0x3590
44#endif
45
46#ifndef PCI_DEVICE_ID_INTEL_7520_1_ERR
47#define PCI_DEVICE_ID_INTEL_7520_1_ERR 0x3591
48#endif
49
50#ifndef PCI_DEVICE_ID_INTEL_7525_0
51#define PCI_DEVICE_ID_INTEL_7525_0 0x359E
52#endif
53
54#ifndef PCI_DEVICE_ID_INTEL_7525_1_ERR
55#define PCI_DEVICE_ID_INTEL_7525_1_ERR 0x3593
56#endif
57
58#ifndef PCI_DEVICE_ID_INTEL_7320_0
59#define PCI_DEVICE_ID_INTEL_7320_0 0x3592
60#endif
61
62#ifndef PCI_DEVICE_ID_INTEL_7320_1_ERR
63#define PCI_DEVICE_ID_INTEL_7320_1_ERR 0x3593
64#endif
65
66#ifndef PCI_DEVICE_ID_INTEL_3100_0
67#define PCI_DEVICE_ID_INTEL_3100_0 0x35B0
68#endif
69
70#ifndef PCI_DEVICE_ID_INTEL_3100_1_ERR
71#define PCI_DEVICE_ID_INTEL_3100_1_ERR 0x35B1
72#endif
73
74#define E752X_NR_CSROWS 8
75
76
77#define E752X_MCHSCRB 0x52
78
79
80
81
82
83
84
85#define E752X_DRB 0x60
86#define E752X_DRA 0x70
87
88
89
90
91
92
93
94
95
96
97
98#define E752X_DRC 0x7C
99
100
101
102
103
104#define E752X_DRM 0x80
105#define E752X_DDRCSR 0x9A
106
107
108
109#define E752X_TOLM 0xC4
110#define E752X_REMAPBASE 0xC6
111#define E752X_REMAPLIMIT 0xC8
112#define E752X_REMAPOFFSET 0xCA
113
114
115#define E752X_FERR_GLOBAL 0x40
116#define E752X_NERR_GLOBAL 0x44
117#define E752X_HI_FERR 0x50
118#define E752X_HI_NERR 0x52
119#define E752X_HI_ERRMASK 0x54
120#define E752X_HI_SMICMD 0x5A
121#define E752X_SYSBUS_FERR 0x60
122#define E752X_SYSBUS_NERR 0x62
123#define E752X_SYSBUS_ERRMASK 0x64
124#define E752X_SYSBUS_SMICMD 0x6A
125#define E752X_BUF_FERR 0x70
126#define E752X_BUF_NERR 0x72
127#define E752X_BUF_ERRMASK 0x74
128#define E752X_BUF_SMICMD 0x7A
129#define E752X_DRAM_FERR 0x80
130#define E752X_DRAM_NERR 0x82
131#define E752X_DRAM_ERRMASK 0x84
132#define E752X_DRAM_SMICMD 0x8A
133#define E752X_DRAM_RETR_ADD 0xAC
134#define E752X_DRAM_SEC1_ADD 0xA0
135
136
137
138
139
140
141
142#define E752X_DRAM_SEC2_ADD 0xC8
143
144
145
146
147
148
149
150#define E752X_DRAM_DED_ADD 0xA4
151
152
153
154
155
156
157
158#define E752X_DRAM_SCRB_ADD 0xA8
159
160
161
162
163
164
165
166#define E752X_DRAM_SEC1_SYNDROME 0xC4
167
168#define E752X_DRAM_SEC2_SYNDROME 0xC6
169
170#define E752X_DEVPRES1 0xF4
171
172
173#define I3100_NSI_FERR 0x48
174#define I3100_NSI_NERR 0x4C
175#define I3100_NSI_SMICMD 0x54
176#define I3100_NSI_EMASK 0x90
177
178
179#define ICH5R_PCI_STAT 0x06
180#define ICH5R_PCI_2ND_STAT 0x1E
181#define ICH5R_PCI_BRIDGE_CTL 0x3E
182
183enum e752x_chips {
184 E7520 = 0,
185 E7525 = 1,
186 E7320 = 2,
187 I3100 = 3
188};
189
190struct e752x_pvt {
191 struct pci_dev *bridge_ck;
192 struct pci_dev *dev_d0f0;
193 struct pci_dev *dev_d0f1;
194 u32 tolm;
195 u32 remapbase;
196 u32 remaplimit;
197 int mc_symmetric;
198 u8 map[8];
199 int map_type;
200 const struct e752x_dev_info *dev_info;
201};
202
203struct e752x_dev_info {
204 u16 err_dev;
205 u16 ctl_dev;
206 const char *ctl_name;
207};
208
209struct e752x_error_info {
210 u32 ferr_global;
211 u32 nerr_global;
212 u32 nsi_ferr;
213 u32 nsi_nerr;
214 u8 hi_ferr;
215 u8 hi_nerr;
216 u16 sysbus_ferr;
217 u16 sysbus_nerr;
218 u8 buf_ferr;
219 u8 buf_nerr;
220 u16 dram_ferr;
221 u16 dram_nerr;
222 u32 dram_sec1_add;
223 u32 dram_sec2_add;
224 u16 dram_sec1_syndrome;
225 u16 dram_sec2_syndrome;
226 u32 dram_ded_add;
227 u32 dram_scrb_add;
228 u32 dram_retr_add;
229};
230
231static const struct e752x_dev_info e752x_devs[] = {
232 [E7520] = {
233 .err_dev = PCI_DEVICE_ID_INTEL_7520_1_ERR,
234 .ctl_dev = PCI_DEVICE_ID_INTEL_7520_0,
235 .ctl_name = "E7520"},
236 [E7525] = {
237 .err_dev = PCI_DEVICE_ID_INTEL_7525_1_ERR,
238 .ctl_dev = PCI_DEVICE_ID_INTEL_7525_0,
239 .ctl_name = "E7525"},
240 [E7320] = {
241 .err_dev = PCI_DEVICE_ID_INTEL_7320_1_ERR,
242 .ctl_dev = PCI_DEVICE_ID_INTEL_7320_0,
243 .ctl_name = "E7320"},
244 [I3100] = {
245 .err_dev = PCI_DEVICE_ID_INTEL_3100_1_ERR,
246 .ctl_dev = PCI_DEVICE_ID_INTEL_3100_0,
247 .ctl_name = "3100"},
248};
249
250
251
252
253
254
255
256
257#define SDRATE_EOT 0xFFFFFFFF
258
259struct scrubrate {
260 u32 bandwidth;
261 u16 scrubval;
262};
263
264
265
266
267
268
269static const struct scrubrate scrubrates_e752x[] = {
270 {0, 0x00},
271 {500000, 0x02},
272 {SDRATE_EOT, 0x00}
273};
274
275
276
277
278static const struct scrubrate scrubrates_i3100[] = {
279 {0, 0x00},
280 {500000, 0x0a},
281 {62500000, 0x06},
282 {SDRATE_EOT, 0x00}
283};
284
285static unsigned long ctl_page_to_phys(struct mem_ctl_info *mci,
286 unsigned long page)
287{
288 u32 remap;
289 struct e752x_pvt *pvt = (struct e752x_pvt *)mci->pvt_info;
290
291 debugf3("%s()\n", __func__);
292
293 if (page < pvt->tolm)
294 return page;
295
296 if ((page >= 0x100000) && (page < pvt->remapbase))
297 return page;
298
299 remap = (page - pvt->tolm) + pvt->remapbase;
300
301 if (remap < pvt->remaplimit)
302 return remap;
303
304 e752x_printk(KERN_ERR, "Invalid page %lx - out of range\n", page);
305 return pvt->tolm - 1;
306}
307
308static void do_process_ce(struct mem_ctl_info *mci, u16 error_one,
309 u32 sec1_add, u16 sec1_syndrome)
310{
311 u32 page;
312 int row;
313 int channel;
314 int i;
315 struct e752x_pvt *pvt = (struct e752x_pvt *)mci->pvt_info;
316
317 debugf3("%s()\n", __func__);
318
319
320 page = sec1_add >> (PAGE_SHIFT - 4);
321
322
323 if (pvt->mc_symmetric) {
324
325 row = ((page >> 1) & 3);
326 e752x_printk(KERN_WARNING,
327 "Test row %d Table %d %d %d %d %d %d %d %d\n", row,
328 pvt->map[0], pvt->map[1], pvt->map[2], pvt->map[3],
329 pvt->map[4], pvt->map[5], pvt->map[6],
330 pvt->map[7]);
331
332
333 for (i = 0; i < 8; i++) {
334 if (pvt->map[i] == row)
335 break;
336 }
337
338 e752x_printk(KERN_WARNING, "Test computed row %d\n", i);
339
340 if (i < 8)
341 row = i;
342 else
343 e752x_mc_printk(mci, KERN_WARNING,
344 "row %d not found in remap table\n",
345 row);
346 } else
347 row = edac_mc_find_csrow_by_page(mci, page);
348
349
350 channel = !(error_one & 1);
351
352
353 edac_mc_handle_ce(mci, page, offset_in_page(sec1_add << 4),
354 sec1_syndrome, row, channel, "e752x CE");
355}
356
357static inline void process_ce(struct mem_ctl_info *mci, u16 error_one,
358 u32 sec1_add, u16 sec1_syndrome, int *error_found,
359 int handle_error)
360{
361 *error_found = 1;
362
363 if (handle_error)
364 do_process_ce(mci, error_one, sec1_add, sec1_syndrome);
365}
366
367static void do_process_ue(struct mem_ctl_info *mci, u16 error_one,
368 u32 ded_add, u32 scrb_add)
369{
370 u32 error_2b, block_page;
371 int row;
372 struct e752x_pvt *pvt = (struct e752x_pvt *)mci->pvt_info;
373
374 debugf3("%s()\n", __func__);
375
376 if (error_one & 0x0202) {
377 error_2b = ded_add;
378
379
380 block_page = error_2b >> (PAGE_SHIFT - 4);
381
382 row = pvt->mc_symmetric ?
383
384 ((block_page >> 1) & 3) :
385 edac_mc_find_csrow_by_page(mci, block_page);
386
387
388 edac_mc_handle_ue(mci, block_page,
389 offset_in_page(error_2b << 4),
390 row, "e752x UE from Read");
391 }
392 if (error_one & 0x0404) {
393 error_2b = scrb_add;
394
395
396 block_page = error_2b >> (PAGE_SHIFT - 4);
397
398 row = pvt->mc_symmetric ?
399
400 ((block_page >> 1) & 3) :
401 edac_mc_find_csrow_by_page(mci, block_page);
402
403
404 edac_mc_handle_ue(mci, block_page,
405 offset_in_page(error_2b << 4),
406 row, "e752x UE from Scruber");
407 }
408}
409
410static inline void process_ue(struct mem_ctl_info *mci, u16 error_one,
411 u32 ded_add, u32 scrb_add, int *error_found,
412 int handle_error)
413{
414 *error_found = 1;
415
416 if (handle_error)
417 do_process_ue(mci, error_one, ded_add, scrb_add);
418}
419
420static inline void process_ue_no_info_wr(struct mem_ctl_info *mci,
421 int *error_found, int handle_error)
422{
423 *error_found = 1;
424
425 if (!handle_error)
426 return;
427
428 debugf3("%s()\n", __func__);
429 edac_mc_handle_ue_no_info(mci, "e752x UE log memory write");
430}
431
432static void do_process_ded_retry(struct mem_ctl_info *mci, u16 error,
433 u32 retry_add)
434{
435 u32 error_1b, page;
436 int row;
437 struct e752x_pvt *pvt = (struct e752x_pvt *)mci->pvt_info;
438
439 error_1b = retry_add;
440 page = error_1b >> (PAGE_SHIFT - 4);
441
442
443 row = pvt->mc_symmetric ? ((page >> 1) & 3) :
444 edac_mc_find_csrow_by_page(mci, page);
445
446 e752x_mc_printk(mci, KERN_WARNING,
447 "CE page 0x%lx, row %d : Memory read retry\n",
448 (long unsigned int)page, row);
449}
450
451static inline void process_ded_retry(struct mem_ctl_info *mci, u16 error,
452 u32 retry_add, int *error_found,
453 int handle_error)
454{
455 *error_found = 1;
456
457 if (handle_error)
458 do_process_ded_retry(mci, error, retry_add);
459}
460
461static inline void process_threshold_ce(struct mem_ctl_info *mci, u16 error,
462 int *error_found, int handle_error)
463{
464 *error_found = 1;
465
466 if (handle_error)
467 e752x_mc_printk(mci, KERN_WARNING, "Memory threshold CE\n");
468}
469
470static char *global_message[11] = {
471 "PCI Express C1",
472 "PCI Express C",
473 "PCI Express B1",
474 "PCI Express B",
475 "PCI Express A1",
476 "PCI Express A",
477 "DMA Controller",
478 "HUB or NS Interface",
479 "System Bus",
480 "DRAM Controller",
481 "Internal Buffer"
482};
483
484#define DRAM_ENTRY 9
485
486static char *fatal_message[2] = { "Non-Fatal ", "Fatal " };
487
488static void do_global_error(int fatal, u32 errors)
489{
490 int i;
491
492 for (i = 0; i < 11; i++) {
493 if (errors & (1 << i)) {
494
495
496
497
498 if ((i == DRAM_ENTRY) || report_non_memory_errors)
499 e752x_printk(KERN_WARNING, "%sError %s\n",
500 fatal_message[fatal],
501 global_message[i]);
502 }
503 }
504}
505
506static inline void global_error(int fatal, u32 errors, int *error_found,
507 int handle_error)
508{
509 *error_found = 1;
510
511 if (handle_error)
512 do_global_error(fatal, errors);
513}
514
515static char *hub_message[7] = {
516 "HI Address or Command Parity", "HI Illegal Access",
517 "HI Internal Parity", "Out of Range Access",
518 "HI Data Parity", "Enhanced Config Access",
519 "Hub Interface Target Abort"
520};
521
522static void do_hub_error(int fatal, u8 errors)
523{
524 int i;
525
526 for (i = 0; i < 7; i++) {
527 if (errors & (1 << i))
528 e752x_printk(KERN_WARNING, "%sError %s\n",
529 fatal_message[fatal], hub_message[i]);
530 }
531}
532
533static inline void hub_error(int fatal, u8 errors, int *error_found,
534 int handle_error)
535{
536 *error_found = 1;
537
538 if (handle_error)
539 do_hub_error(fatal, errors);
540}
541
542#define NSI_FATAL_MASK 0x0c080081
543#define NSI_NON_FATAL_MASK 0x23a0ba64
544#define NSI_ERR_MASK (NSI_FATAL_MASK | NSI_NON_FATAL_MASK)
545
546static char *nsi_message[30] = {
547 "NSI Link Down",
548 "",
549 "NSI Parity Error",
550 "",
551 "",
552 "Correctable Error Message",
553 "Non-Fatal Error Message",
554 "Fatal Error Message",
555 "",
556 "Receiver Error",
557 "",
558 "Bad TLP",
559 "Bad DLLP",
560 "REPLAY_NUM Rollover",
561 "",
562 "Replay Timer Timeout",
563 "",
564 "",
565 "",
566 "Data Link Protocol Error",
567 "",
568 "Poisoned TLP",
569 "",
570 "Completion Timeout",
571 "Completer Abort",
572 "Unexpected Completion",
573 "Receiver Overflow",
574 "Malformed TLP",
575 "",
576 "Unsupported Request"
577};
578
579static void do_nsi_error(int fatal, u32 errors)
580{
581 int i;
582
583 for (i = 0; i < 30; i++) {
584 if (errors & (1 << i))
585 printk(KERN_WARNING "%sError %s\n",
586 fatal_message[fatal], nsi_message[i]);
587 }
588}
589
590static inline void nsi_error(int fatal, u32 errors, int *error_found,
591 int handle_error)
592{
593 *error_found = 1;
594
595 if (handle_error)
596 do_nsi_error(fatal, errors);
597}
598
599static char *membuf_message[4] = {
600 "Internal PMWB to DRAM parity",
601 "Internal PMWB to System Bus Parity",
602 "Internal System Bus or IO to PMWB Parity",
603 "Internal DRAM to PMWB Parity"
604};
605
606static void do_membuf_error(u8 errors)
607{
608 int i;
609
610 for (i = 0; i < 4; i++) {
611 if (errors & (1 << i))
612 e752x_printk(KERN_WARNING, "Non-Fatal Error %s\n",
613 membuf_message[i]);
614 }
615}
616
617static inline void membuf_error(u8 errors, int *error_found, int handle_error)
618{
619 *error_found = 1;
620
621 if (handle_error)
622 do_membuf_error(errors);
623}
624
625static char *sysbus_message[10] = {
626 "Addr or Request Parity",
627 "Data Strobe Glitch",
628 "Addr Strobe Glitch",
629 "Data Parity",
630 "Addr Above TOM",
631 "Non DRAM Lock Error",
632 "MCERR", "BINIT",
633 "Memory Parity",
634 "IO Subsystem Parity"
635};
636
637static void do_sysbus_error(int fatal, u32 errors)
638{
639 int i;
640
641 for (i = 0; i < 10; i++) {
642 if (errors & (1 << i))
643 e752x_printk(KERN_WARNING, "%sError System Bus %s\n",
644 fatal_message[fatal], sysbus_message[i]);
645 }
646}
647
648static inline void sysbus_error(int fatal, u32 errors, int *error_found,
649 int handle_error)
650{
651 *error_found = 1;
652
653 if (handle_error)
654 do_sysbus_error(fatal, errors);
655}
656
657static void e752x_check_hub_interface(struct e752x_error_info *info,
658 int *error_found, int handle_error)
659{
660 u8 stat8;
661
662
663
664 stat8 = info->hi_ferr;
665
666 if (stat8 & 0x7f) {
667 stat8 &= 0x7f;
668
669 if (stat8 & 0x2b)
670 hub_error(1, stat8 & 0x2b, error_found, handle_error);
671
672 if (stat8 & 0x54)
673 hub_error(0, stat8 & 0x54, error_found, handle_error);
674 }
675
676
677 stat8 = info->hi_nerr;
678
679 if (stat8 & 0x7f) {
680 stat8 &= 0x7f;
681
682 if (stat8 & 0x2b)
683 hub_error(1, stat8 & 0x2b, error_found, handle_error);
684
685 if (stat8 & 0x54)
686 hub_error(0, stat8 & 0x54, error_found, handle_error);
687 }
688}
689
690static void e752x_check_ns_interface(struct e752x_error_info *info,
691 int *error_found, int handle_error)
692{
693 u32 stat32;
694
695 stat32 = info->nsi_ferr;
696 if (stat32 & NSI_ERR_MASK) {
697 if (stat32 & NSI_FATAL_MASK)
698 nsi_error(1, stat32 & NSI_FATAL_MASK, error_found,
699 handle_error);
700 if (stat32 & NSI_NON_FATAL_MASK)
701 nsi_error(0, stat32 & NSI_NON_FATAL_MASK, error_found,
702 handle_error);
703 }
704 stat32 = info->nsi_nerr;
705 if (stat32 & NSI_ERR_MASK) {
706 if (stat32 & NSI_FATAL_MASK)
707 nsi_error(1, stat32 & NSI_FATAL_MASK, error_found,
708 handle_error);
709 if (stat32 & NSI_NON_FATAL_MASK)
710 nsi_error(0, stat32 & NSI_NON_FATAL_MASK, error_found,
711 handle_error);
712 }
713}
714
715static void e752x_check_sysbus(struct e752x_error_info *info,
716 int *error_found, int handle_error)
717{
718 u32 stat32, error32;
719
720
721 stat32 = info->sysbus_ferr + (info->sysbus_nerr << 16);
722
723 if (stat32 == 0)
724 return;
725
726 error32 = (stat32 >> 16) & 0x3ff;
727 stat32 = stat32 & 0x3ff;
728
729 if (stat32 & 0x087)
730 sysbus_error(1, stat32 & 0x087, error_found, handle_error);
731
732 if (stat32 & 0x378)
733 sysbus_error(0, stat32 & 0x378, error_found, handle_error);
734
735 if (error32 & 0x087)
736 sysbus_error(1, error32 & 0x087, error_found, handle_error);
737
738 if (error32 & 0x378)
739 sysbus_error(0, error32 & 0x378, error_found, handle_error);
740}
741
742static void e752x_check_membuf(struct e752x_error_info *info,
743 int *error_found, int handle_error)
744{
745 u8 stat8;
746
747 stat8 = info->buf_ferr;
748
749 if (stat8 & 0x0f) {
750 stat8 &= 0x0f;
751 membuf_error(stat8, error_found, handle_error);
752 }
753
754 stat8 = info->buf_nerr;
755
756 if (stat8 & 0x0f) {
757 stat8 &= 0x0f;
758 membuf_error(stat8, error_found, handle_error);
759 }
760}
761
762static void e752x_check_dram(struct mem_ctl_info *mci,
763 struct e752x_error_info *info, int *error_found,
764 int handle_error)
765{
766 u16 error_one, error_next;
767
768 error_one = info->dram_ferr;
769 error_next = info->dram_nerr;
770
771
772 if (error_one & 0x0101)
773 process_ce(mci, error_one, info->dram_sec1_add,
774 info->dram_sec1_syndrome, error_found, handle_error);
775
776 if (error_next & 0x0101)
777 process_ce(mci, error_next, info->dram_sec2_add,
778 info->dram_sec2_syndrome, error_found, handle_error);
779
780 if (error_one & 0x4040)
781 process_ue_no_info_wr(mci, error_found, handle_error);
782
783 if (error_next & 0x4040)
784 process_ue_no_info_wr(mci, error_found, handle_error);
785
786 if (error_one & 0x2020)
787 process_ded_retry(mci, error_one, info->dram_retr_add,
788 error_found, handle_error);
789
790 if (error_next & 0x2020)
791 process_ded_retry(mci, error_next, info->dram_retr_add,
792 error_found, handle_error);
793
794 if (error_one & 0x0808)
795 process_threshold_ce(mci, error_one, error_found, handle_error);
796
797 if (error_next & 0x0808)
798 process_threshold_ce(mci, error_next, error_found,
799 handle_error);
800
801 if (error_one & 0x0606)
802 process_ue(mci, error_one, info->dram_ded_add,
803 info->dram_scrb_add, error_found, handle_error);
804
805 if (error_next & 0x0606)
806 process_ue(mci, error_next, info->dram_ded_add,
807 info->dram_scrb_add, error_found, handle_error);
808}
809
810static void e752x_get_error_info(struct mem_ctl_info *mci,
811 struct e752x_error_info *info)
812{
813 struct pci_dev *dev;
814 struct e752x_pvt *pvt;
815
816 memset(info, 0, sizeof(*info));
817 pvt = (struct e752x_pvt *)mci->pvt_info;
818 dev = pvt->dev_d0f1;
819 pci_read_config_dword(dev, E752X_FERR_GLOBAL, &info->ferr_global);
820
821 if (info->ferr_global) {
822 if (pvt->dev_info->err_dev == PCI_DEVICE_ID_INTEL_3100_1_ERR) {
823 pci_read_config_dword(dev, I3100_NSI_FERR,
824 &info->nsi_ferr);
825 info->hi_ferr = 0;
826 } else {
827 pci_read_config_byte(dev, E752X_HI_FERR,
828 &info->hi_ferr);
829 info->nsi_ferr = 0;
830 }
831 pci_read_config_word(dev, E752X_SYSBUS_FERR,
832 &info->sysbus_ferr);
833 pci_read_config_byte(dev, E752X_BUF_FERR, &info->buf_ferr);
834 pci_read_config_word(dev, E752X_DRAM_FERR, &info->dram_ferr);
835 pci_read_config_dword(dev, E752X_DRAM_SEC1_ADD,
836 &info->dram_sec1_add);
837 pci_read_config_word(dev, E752X_DRAM_SEC1_SYNDROME,
838 &info->dram_sec1_syndrome);
839 pci_read_config_dword(dev, E752X_DRAM_DED_ADD,
840 &info->dram_ded_add);
841 pci_read_config_dword(dev, E752X_DRAM_SCRB_ADD,
842 &info->dram_scrb_add);
843 pci_read_config_dword(dev, E752X_DRAM_RETR_ADD,
844 &info->dram_retr_add);
845
846
847 if (info->hi_ferr & 0x7f)
848 pci_write_config_byte(dev, E752X_HI_FERR,
849 info->hi_ferr);
850
851 if (info->nsi_ferr & NSI_ERR_MASK)
852 pci_write_config_dword(dev, I3100_NSI_FERR,
853 info->nsi_ferr);
854
855 if (info->sysbus_ferr)
856 pci_write_config_word(dev, E752X_SYSBUS_FERR,
857 info->sysbus_ferr);
858
859 if (info->buf_ferr & 0x0f)
860 pci_write_config_byte(dev, E752X_BUF_FERR,
861 info->buf_ferr);
862
863 if (info->dram_ferr)
864 pci_write_bits16(pvt->bridge_ck, E752X_DRAM_FERR,
865 info->dram_ferr, info->dram_ferr);
866
867 pci_write_config_dword(dev, E752X_FERR_GLOBAL,
868 info->ferr_global);
869 }
870
871 pci_read_config_dword(dev, E752X_NERR_GLOBAL, &info->nerr_global);
872
873 if (info->nerr_global) {
874 if (pvt->dev_info->err_dev == PCI_DEVICE_ID_INTEL_3100_1_ERR) {
875 pci_read_config_dword(dev, I3100_NSI_NERR,
876 &info->nsi_nerr);
877 info->hi_nerr = 0;
878 } else {
879 pci_read_config_byte(dev, E752X_HI_NERR,
880 &info->hi_nerr);
881 info->nsi_nerr = 0;
882 }
883 pci_read_config_word(dev, E752X_SYSBUS_NERR,
884 &info->sysbus_nerr);
885 pci_read_config_byte(dev, E752X_BUF_NERR, &info->buf_nerr);
886 pci_read_config_word(dev, E752X_DRAM_NERR, &info->dram_nerr);
887 pci_read_config_dword(dev, E752X_DRAM_SEC2_ADD,
888 &info->dram_sec2_add);
889 pci_read_config_word(dev, E752X_DRAM_SEC2_SYNDROME,
890 &info->dram_sec2_syndrome);
891
892 if (info->hi_nerr & 0x7f)
893 pci_write_config_byte(dev, E752X_HI_NERR,
894 info->hi_nerr);
895
896 if (info->nsi_nerr & NSI_ERR_MASK)
897 pci_write_config_dword(dev, I3100_NSI_NERR,
898 info->nsi_nerr);
899
900 if (info->sysbus_nerr)
901 pci_write_config_word(dev, E752X_SYSBUS_NERR,
902 info->sysbus_nerr);
903
904 if (info->buf_nerr & 0x0f)
905 pci_write_config_byte(dev, E752X_BUF_NERR,
906 info->buf_nerr);
907
908 if (info->dram_nerr)
909 pci_write_bits16(pvt->bridge_ck, E752X_DRAM_NERR,
910 info->dram_nerr, info->dram_nerr);
911
912 pci_write_config_dword(dev, E752X_NERR_GLOBAL,
913 info->nerr_global);
914 }
915}
916
917static int e752x_process_error_info(struct mem_ctl_info *mci,
918 struct e752x_error_info *info,
919 int handle_errors)
920{
921 u32 error32, stat32;
922 int error_found;
923
924 error_found = 0;
925 error32 = (info->ferr_global >> 18) & 0x3ff;
926 stat32 = (info->ferr_global >> 4) & 0x7ff;
927
928 if (error32)
929 global_error(1, error32, &error_found, handle_errors);
930
931 if (stat32)
932 global_error(0, stat32, &error_found, handle_errors);
933
934 error32 = (info->nerr_global >> 18) & 0x3ff;
935 stat32 = (info->nerr_global >> 4) & 0x7ff;
936
937 if (error32)
938 global_error(1, error32, &error_found, handle_errors);
939
940 if (stat32)
941 global_error(0, stat32, &error_found, handle_errors);
942
943 e752x_check_hub_interface(info, &error_found, handle_errors);
944 e752x_check_ns_interface(info, &error_found, handle_errors);
945 e752x_check_sysbus(info, &error_found, handle_errors);
946 e752x_check_membuf(info, &error_found, handle_errors);
947 e752x_check_dram(mci, info, &error_found, handle_errors);
948 return error_found;
949}
950
951static void e752x_check(struct mem_ctl_info *mci)
952{
953 struct e752x_error_info info;
954
955 debugf3("%s()\n", __func__);
956 e752x_get_error_info(mci, &info);
957 e752x_process_error_info(mci, &info, 1);
958}
959
960
961static int set_sdram_scrub_rate(struct mem_ctl_info *mci, u32 new_bw)
962{
963 const struct scrubrate *scrubrates;
964 struct e752x_pvt *pvt = (struct e752x_pvt *) mci->pvt_info;
965 struct pci_dev *pdev = pvt->dev_d0f0;
966 int i;
967
968 if (pvt->dev_info->ctl_dev == PCI_DEVICE_ID_INTEL_3100_0)
969 scrubrates = scrubrates_i3100;
970 else
971 scrubrates = scrubrates_e752x;
972
973
974
975
976
977 for (i = 0; scrubrates[i].bandwidth != SDRATE_EOT; i++)
978 if (scrubrates[i].bandwidth >= new_bw)
979 break;
980
981 if (scrubrates[i].bandwidth == SDRATE_EOT)
982 return -1;
983
984 pci_write_config_word(pdev, E752X_MCHSCRB, scrubrates[i].scrubval);
985
986 return scrubrates[i].bandwidth;
987}
988
989
990static int get_sdram_scrub_rate(struct mem_ctl_info *mci)
991{
992 const struct scrubrate *scrubrates;
993 struct e752x_pvt *pvt = (struct e752x_pvt *) mci->pvt_info;
994 struct pci_dev *pdev = pvt->dev_d0f0;
995 u16 scrubval;
996 int i;
997
998 if (pvt->dev_info->ctl_dev == PCI_DEVICE_ID_INTEL_3100_0)
999 scrubrates = scrubrates_i3100;
1000 else
1001 scrubrates = scrubrates_e752x;
1002
1003
1004 pci_read_config_word(pdev, E752X_MCHSCRB, &scrubval);
1005 scrubval = scrubval & 0x0f;
1006
1007 for (i = 0; scrubrates[i].bandwidth != SDRATE_EOT; i++)
1008 if (scrubrates[i].scrubval == scrubval)
1009 break;
1010
1011 if (scrubrates[i].bandwidth == SDRATE_EOT) {
1012 e752x_printk(KERN_WARNING,
1013 "Invalid sdram scrub control value: 0x%x\n", scrubval);
1014 return -1;
1015 }
1016 return scrubrates[i].bandwidth;
1017
1018}
1019
1020
1021static inline int dual_channel_active(u16 ddrcsr)
1022{
1023 return (((ddrcsr >> 12) & 3) == 3);
1024}
1025
1026
1027
1028static inline int remap_csrow_index(struct mem_ctl_info *mci, int index)
1029{
1030 struct e752x_pvt *pvt = mci->pvt_info;
1031
1032 if (!pvt->map_type)
1033 return (7 - index);
1034
1035 return (index);
1036}
1037
1038static void e752x_init_csrows(struct mem_ctl_info *mci, struct pci_dev *pdev,
1039 u16 ddrcsr)
1040{
1041 struct csrow_info *csrow;
1042 unsigned long last_cumul_size;
1043 int index, mem_dev, drc_chan;
1044 int drc_drbg;
1045 int drc_ddim;
1046 u8 value;
1047 u32 dra, drc, cumul_size;
1048
1049 dra = 0;
1050 for (index = 0; index < 4; index++) {
1051 u8 dra_reg;
1052 pci_read_config_byte(pdev, E752X_DRA + index, &dra_reg);
1053 dra |= dra_reg << (index * 8);
1054 }
1055 pci_read_config_dword(pdev, E752X_DRC, &drc);
1056 drc_chan = dual_channel_active(ddrcsr);
1057 drc_drbg = drc_chan + 1;
1058 drc_ddim = (drc >> 20) & 0x3;
1059
1060
1061
1062
1063
1064
1065 for (last_cumul_size = index = 0; index < mci->nr_csrows; index++) {
1066
1067 mem_dev = (dra >> (index * 4 + 2)) & 0x3;
1068 csrow = &mci->csrows[remap_csrow_index(mci, index)];
1069
1070 mem_dev = (mem_dev == 2);
1071 pci_read_config_byte(pdev, E752X_DRB + index, &value);
1072
1073 cumul_size = value << (25 + drc_drbg - PAGE_SHIFT);
1074 debugf3("%s(): (%d) cumul_size 0x%x\n", __func__, index,
1075 cumul_size);
1076 if (cumul_size == last_cumul_size)
1077 continue;
1078
1079 csrow->first_page = last_cumul_size;
1080 csrow->last_page = cumul_size - 1;
1081 csrow->nr_pages = cumul_size - last_cumul_size;
1082 last_cumul_size = cumul_size;
1083 csrow->grain = 1 << 12;
1084 csrow->mtype = MEM_RDDR;
1085 csrow->dtype = mem_dev ? DEV_X4 : DEV_X8;
1086
1087
1088
1089
1090
1091 if (drc_ddim) {
1092 if (drc_chan && mem_dev) {
1093 csrow->edac_mode = EDAC_S4ECD4ED;
1094 mci->edac_cap |= EDAC_FLAG_S4ECD4ED;
1095 } else {
1096 csrow->edac_mode = EDAC_SECDED;
1097 mci->edac_cap |= EDAC_FLAG_SECDED;
1098 }
1099 } else
1100 csrow->edac_mode = EDAC_NONE;
1101 }
1102}
1103
1104static void e752x_init_mem_map_table(struct pci_dev *pdev,
1105 struct e752x_pvt *pvt)
1106{
1107 int index;
1108 u8 value, last, row;
1109
1110 last = 0;
1111 row = 0;
1112
1113 for (index = 0; index < 8; index += 2) {
1114 pci_read_config_byte(pdev, E752X_DRB + index, &value);
1115
1116 if (value == last) {
1117
1118 pvt->map[index] = 0xff;
1119 pvt->map[index + 1] = 0xff;
1120 } else {
1121 pvt->map[index] = row;
1122 row++;
1123 last = value;
1124
1125
1126
1127 pci_read_config_byte(pdev, E752X_DRB + index + 1,
1128 &value);
1129
1130
1131
1132 pvt->map[index + 1] = (value == last) ? 0xff : row;
1133 row++;
1134 last = value;
1135 }
1136 }
1137}
1138
1139
1140static int e752x_get_devs(struct pci_dev *pdev, int dev_idx,
1141 struct e752x_pvt *pvt)
1142{
1143 struct pci_dev *dev;
1144
1145 pvt->bridge_ck = pci_get_device(PCI_VENDOR_ID_INTEL,
1146 pvt->dev_info->err_dev, pvt->bridge_ck);
1147
1148 if (pvt->bridge_ck == NULL)
1149 pvt->bridge_ck = pci_scan_single_device(pdev->bus,
1150 PCI_DEVFN(0, 1));
1151
1152 if (pvt->bridge_ck == NULL) {
1153 e752x_printk(KERN_ERR, "error reporting device not found:"
1154 "vendor %x device 0x%x (broken BIOS?)\n",
1155 PCI_VENDOR_ID_INTEL, e752x_devs[dev_idx].err_dev);
1156 return 1;
1157 }
1158
1159 dev = pci_get_device(PCI_VENDOR_ID_INTEL,
1160 e752x_devs[dev_idx].ctl_dev,
1161 NULL);
1162
1163 if (dev == NULL)
1164 goto fail;
1165
1166 pvt->dev_d0f0 = dev;
1167 pvt->dev_d0f1 = pci_dev_get(pvt->bridge_ck);
1168
1169 return 0;
1170
1171fail:
1172 pci_dev_put(pvt->bridge_ck);
1173 return 1;
1174}
1175
1176
1177
1178
1179
1180static void e752x_init_sysbus_parity_mask(struct e752x_pvt *pvt)
1181{
1182 char *cpu_id = cpu_data(0).x86_model_id;
1183 struct pci_dev *dev = pvt->dev_d0f1;
1184 int enable = 1;
1185
1186
1187 if (sysbus_parity != -1) {
1188 enable = sysbus_parity;
1189 } else if (cpu_id[0] && !strstr(cpu_id, "Xeon")) {
1190 e752x_printk(KERN_INFO, "System Bus Parity not "
1191 "supported by CPU, disabling\n");
1192 enable = 0;
1193 }
1194
1195 if (enable)
1196 pci_write_config_word(dev, E752X_SYSBUS_ERRMASK, 0x0000);
1197 else
1198 pci_write_config_word(dev, E752X_SYSBUS_ERRMASK, 0x0309);
1199}
1200
1201static void e752x_init_error_reporting_regs(struct e752x_pvt *pvt)
1202{
1203 struct pci_dev *dev;
1204
1205 dev = pvt->dev_d0f1;
1206
1207 if (pvt->dev_info->err_dev == PCI_DEVICE_ID_INTEL_3100_1_ERR) {
1208 pci_write_config_dword(dev, I3100_NSI_EMASK, 0);
1209 pci_write_config_dword(dev, I3100_NSI_SMICMD, 0);
1210 } else {
1211 pci_write_config_byte(dev, E752X_HI_ERRMASK, 0x00);
1212 pci_write_config_byte(dev, E752X_HI_SMICMD, 0x00);
1213 }
1214
1215 e752x_init_sysbus_parity_mask(pvt);
1216
1217 pci_write_config_word(dev, E752X_SYSBUS_SMICMD, 0x00);
1218 pci_write_config_byte(dev, E752X_BUF_ERRMASK, 0x00);
1219 pci_write_config_byte(dev, E752X_BUF_SMICMD, 0x00);
1220 pci_write_config_byte(dev, E752X_DRAM_ERRMASK, 0x00);
1221 pci_write_config_byte(dev, E752X_DRAM_SMICMD, 0x00);
1222}
1223
1224static int e752x_probe1(struct pci_dev *pdev, int dev_idx)
1225{
1226 u16 pci_data;
1227 u8 stat8;
1228 struct mem_ctl_info *mci;
1229 struct e752x_pvt *pvt;
1230 u16 ddrcsr;
1231 int drc_chan;
1232 struct e752x_error_info discard;
1233
1234 debugf0("%s(): mci\n", __func__);
1235 debugf0("Starting Probe1\n");
1236
1237
1238
1239
1240
1241 pci_read_config_byte(pdev, E752X_DEVPRES1, &stat8);
1242 if (!force_function_unhide && !(stat8 & (1 << 5))) {
1243 printk(KERN_INFO "Contact your BIOS vendor to see if the "
1244 "E752x error registers can be safely un-hidden\n");
1245 return -ENODEV;
1246 }
1247 stat8 |= (1 << 5);
1248 pci_write_config_byte(pdev, E752X_DEVPRES1, stat8);
1249
1250 pci_read_config_word(pdev, E752X_DDRCSR, &ddrcsr);
1251
1252
1253 drc_chan = dual_channel_active(ddrcsr);
1254
1255 mci = edac_mc_alloc(sizeof(*pvt), E752X_NR_CSROWS, drc_chan + 1, 0);
1256
1257 if (mci == NULL) {
1258 return -ENOMEM;
1259 }
1260
1261 debugf3("%s(): init mci\n", __func__);
1262 mci->mtype_cap = MEM_FLAG_RDDR;
1263
1264 mci->edac_ctl_cap = (dev_idx == I3100) ? EDAC_FLAG_SECDED :
1265 (EDAC_FLAG_NONE | EDAC_FLAG_SECDED | EDAC_FLAG_S4ECD4ED);
1266
1267 mci->mod_name = EDAC_MOD_STR;
1268 mci->mod_ver = E752X_REVISION;
1269 mci->dev = &pdev->dev;
1270
1271 debugf3("%s(): init pvt\n", __func__);
1272 pvt = (struct e752x_pvt *)mci->pvt_info;
1273 pvt->dev_info = &e752x_devs[dev_idx];
1274 pvt->mc_symmetric = ((ddrcsr & 0x10) != 0);
1275
1276 if (e752x_get_devs(pdev, dev_idx, pvt)) {
1277 edac_mc_free(mci);
1278 return -ENODEV;
1279 }
1280
1281 debugf3("%s(): more mci init\n", __func__);
1282 mci->ctl_name = pvt->dev_info->ctl_name;
1283 mci->dev_name = pci_name(pdev);
1284 mci->edac_check = e752x_check;
1285 mci->ctl_page_to_phys = ctl_page_to_phys;
1286 mci->set_sdram_scrub_rate = set_sdram_scrub_rate;
1287 mci->get_sdram_scrub_rate = get_sdram_scrub_rate;
1288
1289
1290
1291
1292
1293 pci_read_config_byte(pdev, E752X_DRM, &stat8);
1294 pvt->map_type = ((stat8 & 0x0f) > ((stat8 >> 4) & 0x0f));
1295
1296 e752x_init_csrows(mci, pdev, ddrcsr);
1297 e752x_init_mem_map_table(pdev, pvt);
1298
1299 if (dev_idx == I3100)
1300 mci->edac_cap = EDAC_FLAG_SECDED;
1301 else
1302 mci->edac_cap |= EDAC_FLAG_NONE;
1303 debugf3("%s(): tolm, remapbase, remaplimit\n", __func__);
1304
1305
1306 pci_read_config_word(pdev, E752X_TOLM, &pci_data);
1307 pvt->tolm = ((u32) pci_data) << 4;
1308 pci_read_config_word(pdev, E752X_REMAPBASE, &pci_data);
1309 pvt->remapbase = ((u32) pci_data) << 14;
1310 pci_read_config_word(pdev, E752X_REMAPLIMIT, &pci_data);
1311 pvt->remaplimit = ((u32) pci_data) << 14;
1312 e752x_printk(KERN_INFO,
1313 "tolm = %x, remapbase = %x, remaplimit = %x\n",
1314 pvt->tolm, pvt->remapbase, pvt->remaplimit);
1315
1316
1317
1318
1319 if (edac_mc_add_mc(mci)) {
1320 debugf3("%s(): failed edac_mc_add_mc()\n", __func__);
1321 goto fail;
1322 }
1323
1324 e752x_init_error_reporting_regs(pvt);
1325 e752x_get_error_info(mci, &discard);
1326
1327
1328 e752x_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
1329 if (!e752x_pci) {
1330 printk(KERN_WARNING
1331 "%s(): Unable to create PCI control\n", __func__);
1332 printk(KERN_WARNING
1333 "%s(): PCI error report via EDAC not setup\n",
1334 __func__);
1335 }
1336
1337
1338 debugf3("%s(): success\n", __func__);
1339 return 0;
1340
1341fail:
1342 pci_dev_put(pvt->dev_d0f0);
1343 pci_dev_put(pvt->dev_d0f1);
1344 pci_dev_put(pvt->bridge_ck);
1345 edac_mc_free(mci);
1346
1347 return -ENODEV;
1348}
1349
1350
1351static int __devinit e752x_init_one(struct pci_dev *pdev,
1352 const struct pci_device_id *ent)
1353{
1354 debugf0("%s()\n", __func__);
1355
1356
1357 if (pci_enable_device(pdev) < 0)
1358 return -EIO;
1359
1360 return e752x_probe1(pdev, ent->driver_data);
1361}
1362
1363static void __devexit e752x_remove_one(struct pci_dev *pdev)
1364{
1365 struct mem_ctl_info *mci;
1366 struct e752x_pvt *pvt;
1367
1368 debugf0("%s()\n", __func__);
1369
1370 if (e752x_pci)
1371 edac_pci_release_generic_ctl(e752x_pci);
1372
1373 if ((mci = edac_mc_del_mc(&pdev->dev)) == NULL)
1374 return;
1375
1376 pvt = (struct e752x_pvt *)mci->pvt_info;
1377 pci_dev_put(pvt->dev_d0f0);
1378 pci_dev_put(pvt->dev_d0f1);
1379 pci_dev_put(pvt->bridge_ck);
1380 edac_mc_free(mci);
1381}
1382
1383static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
1384 {
1385 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1386 E7520},
1387 {
1388 PCI_VEND_DEV(INTEL, 7525_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1389 E7525},
1390 {
1391 PCI_VEND_DEV(INTEL, 7320_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1392 E7320},
1393 {
1394 PCI_VEND_DEV(INTEL, 3100_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1395 I3100},
1396 {
1397 0,
1398 }
1399};
1400
1401MODULE_DEVICE_TABLE(pci, e752x_pci_tbl);
1402
1403static struct pci_driver e752x_driver = {
1404 .name = EDAC_MOD_STR,
1405 .probe = e752x_init_one,
1406 .remove = __devexit_p(e752x_remove_one),
1407 .id_table = e752x_pci_tbl,
1408};
1409
1410static int __init e752x_init(void)
1411{
1412 int pci_rc;
1413
1414 debugf3("%s()\n", __func__);
1415
1416
1417 opstate_init();
1418
1419 pci_rc = pci_register_driver(&e752x_driver);
1420 return (pci_rc < 0) ? pci_rc : 0;
1421}
1422
1423static void __exit e752x_exit(void)
1424{
1425 debugf3("%s()\n", __func__);
1426 pci_unregister_driver(&e752x_driver);
1427}
1428
1429module_init(e752x_init);
1430module_exit(e752x_exit);
1431
1432MODULE_LICENSE("GPL");
1433MODULE_AUTHOR("Linux Networx (http://lnxi.com) Tom Zimmerman\n");
1434MODULE_DESCRIPTION("MC support for Intel e752x/3100 memory controllers");
1435
1436module_param(force_function_unhide, int, 0444);
1437MODULE_PARM_DESC(force_function_unhide, "if BIOS sets Dev0:Fun1 up as hidden:"
1438 " 1=force unhide and hope BIOS doesn't fight driver for "
1439 "Dev0:Fun1 access");
1440
1441module_param(edac_op_state, int, 0444);
1442MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
1443
1444module_param(sysbus_parity, int, 0444);
1445MODULE_PARM_DESC(sysbus_parity, "0=disable system bus parity checking,"
1446 " 1=enable system bus parity checking, default=auto-detect");
1447module_param(report_non_memory_errors, int, 0644);
1448MODULE_PARM_DESC(report_non_memory_errors, "0=disable non-memory error "
1449 "reporting, 1=enable non-memory error reporting");
1450