1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <linux/module.h>
22#include <linux/init.h>
23#include <linux/pci.h>
24#include <linux/pci_ids.h>
25#include <linux/slab.h>
26#include <linux/edac.h>
27#include <linux/mmzone.h>
28
29#include "edac_core.h"
30
31
32
33
34#define I7300_REVISION " Ver: 1.0.0"
35
36#define EDAC_MOD_STR "i7300_edac"
37
38#define i7300_printk(level, fmt, arg...) \
39 edac_printk(level, "i7300", fmt, ##arg)
40
41#define i7300_mc_printk(mci, level, fmt, arg...) \
42 edac_mc_chipset_printk(mci, level, "i7300", fmt, ##arg)
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63#define MAX_SLOTS 8
64#define MAX_BRANCHES 2
65#define MAX_CH_PER_BRANCH 2
66#define MAX_CHANNELS (MAX_CH_PER_BRANCH * MAX_BRANCHES)
67#define MAX_MIR 3
68
69#define to_channel(ch, branch) ((((branch)) << 1) | (ch))
70
71#define to_csrow(slot, ch, branch) \
72 (to_channel(ch, branch) | ((slot) << 2))
73
74
75struct i7300_dev_info {
76 const char *ctl_name;
77 u16 fsb_mapping_errors;
78};
79
80
81static const struct i7300_dev_info i7300_devs[] = {
82 {
83 .ctl_name = "I7300",
84 .fsb_mapping_errors = PCI_DEVICE_ID_INTEL_I7300_MCH_ERR,
85 },
86};
87
88struct i7300_dimm_info {
89 int megabytes;
90};
91
92
93struct i7300_pvt {
94 struct pci_dev *pci_dev_16_0_fsb_ctlr;
95 struct pci_dev *pci_dev_16_1_fsb_addr_map;
96 struct pci_dev *pci_dev_16_2_fsb_err_regs;
97 struct pci_dev *pci_dev_2x_0_fbd_branch[MAX_BRANCHES];
98
99 u16 tolm;
100 u64 ambase;
101
102 u32 mc_settings;
103 u32 mc_settings_a;
104
105 u16 mir[MAX_MIR];
106
107 u16 mtr[MAX_SLOTS][MAX_BRANCHES];
108 u16 ambpresent[MAX_CHANNELS];
109
110
111 struct i7300_dimm_info dimm_info[MAX_SLOTS][MAX_CHANNELS];
112
113
114 char *tmp_prt_buffer;
115};
116
117
118static struct edac_pci_ctl_info *i7300_pci;
119
120
121
122
123
124
125
126
127
128
129
130
131#define AMBASE 0x48
132#define MAXCH 0x56
133#define MAXDIMMPERCH 0x57
134
135
136#define MC_SETTINGS 0x40
137 #define IS_MIRRORED(mc) ((mc) & (1 << 16))
138 #define IS_ECC_ENABLED(mc) ((mc) & (1 << 5))
139 #define IS_RETRY_ENABLED(mc) ((mc) & (1 << 31))
140 #define IS_SCRBALGO_ENHANCED(mc) ((mc) & (1 << 8))
141
142#define MC_SETTINGS_A 0x58
143 #define IS_SINGLE_MODE(mca) ((mca) & (1 << 14))
144
145#define TOLM 0x6C
146
147#define MIR0 0x80
148#define MIR1 0x84
149#define MIR2 0x88
150
151
152
153
154
155
156
157
158
159
160
161
162#define AMBPRESENT_0 0x64
163#define AMBPRESENT_1 0x66
164
165static const u16 mtr_regs[MAX_SLOTS] = {
166 0x80, 0x84, 0x88, 0x8c,
167 0x82, 0x86, 0x8a, 0x8e
168};
169
170
171
172
173
174#define MTR_DIMMS_PRESENT(mtr) ((mtr) & (1 << 8))
175#define MTR_DIMMS_ETHROTTLE(mtr) ((mtr) & (1 << 7))
176#define MTR_DRAM_WIDTH(mtr) (((mtr) & (1 << 6)) ? 8 : 4)
177#define MTR_DRAM_BANKS(mtr) (((mtr) & (1 << 5)) ? 8 : 4)
178#define MTR_DIMM_RANKS(mtr) (((mtr) & (1 << 4)) ? 1 : 0)
179#define MTR_DIMM_ROWS(mtr) (((mtr) >> 2) & 0x3)
180#define MTR_DRAM_BANKS_ADDR_BITS 2
181#define MTR_DIMM_ROWS_ADDR_BITS(mtr) (MTR_DIMM_ROWS(mtr) + 13)
182#define MTR_DIMM_COLS(mtr) ((mtr) & 0x3)
183#define MTR_DIMM_COLS_ADDR_BITS(mtr) (MTR_DIMM_COLS(mtr) + 10)
184
185
186
187
188
189
190
191
192#define FERR_FAT_FBD 0x98
193static const char *ferr_fat_fbd_name[] = {
194 [22] = "Non-Redundant Fast Reset Timeout",
195 [2] = ">Tmid Thermal event with intelligent throttling disabled",
196 [1] = "Memory or FBD configuration CRC read error",
197 [0] = "Memory Write error on non-redundant retry or "
198 "FBD configuration Write error on retry",
199};
200#define GET_FBD_FAT_IDX(fbderr) (((fbderr) >> 28) & 3)
201#define FERR_FAT_FBD_ERR_MASK ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 22))
202
203#define FERR_NF_FBD 0xa0
204static const char *ferr_nf_fbd_name[] = {
205 [24] = "DIMM-Spare Copy Completed",
206 [23] = "DIMM-Spare Copy Initiated",
207 [22] = "Redundant Fast Reset Timeout",
208 [21] = "Memory Write error on redundant retry",
209 [18] = "SPD protocol Error",
210 [17] = "FBD Northbound parity error on FBD Sync Status",
211 [16] = "Correctable Patrol Data ECC",
212 [15] = "Correctable Resilver- or Spare-Copy Data ECC",
213 [14] = "Correctable Mirrored Demand Data ECC",
214 [13] = "Correctable Non-Mirrored Demand Data ECC",
215 [11] = "Memory or FBD configuration CRC read error",
216 [10] = "FBD Configuration Write error on first attempt",
217 [9] = "Memory Write error on first attempt",
218 [8] = "Non-Aliased Uncorrectable Patrol Data ECC",
219 [7] = "Non-Aliased Uncorrectable Resilver- or Spare-Copy Data ECC",
220 [6] = "Non-Aliased Uncorrectable Mirrored Demand Data ECC",
221 [5] = "Non-Aliased Uncorrectable Non-Mirrored Demand Data ECC",
222 [4] = "Aliased Uncorrectable Patrol Data ECC",
223 [3] = "Aliased Uncorrectable Resilver- or Spare-Copy Data ECC",
224 [2] = "Aliased Uncorrectable Mirrored Demand Data ECC",
225 [1] = "Aliased Uncorrectable Non-Mirrored Demand Data ECC",
226 [0] = "Uncorrectable Data ECC on Replay",
227};
228#define GET_FBD_NF_IDX(fbderr) (((fbderr) >> 28) & 3)
229#define FERR_NF_FBD_ERR_MASK ((1 << 24) | (1 << 23) | (1 << 22) | (1 << 21) |\
230 (1 << 18) | (1 << 17) | (1 << 16) | (1 << 15) |\
231 (1 << 14) | (1 << 13) | (1 << 11) | (1 << 10) |\
232 (1 << 9) | (1 << 8) | (1 << 7) | (1 << 6) |\
233 (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2) |\
234 (1 << 1) | (1 << 0))
235
236#define EMASK_FBD 0xa8
237#define EMASK_FBD_ERR_MASK ((1 << 27) | (1 << 26) | (1 << 25) | (1 << 24) |\
238 (1 << 22) | (1 << 21) | (1 << 20) | (1 << 19) |\
239 (1 << 18) | (1 << 17) | (1 << 16) | (1 << 14) |\
240 (1 << 13) | (1 << 12) | (1 << 11) | (1 << 10) |\
241 (1 << 9) | (1 << 8) | (1 << 7) | (1 << 6) |\
242 (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2) |\
243 (1 << 1) | (1 << 0))
244
245
246
247
248
249#define FERR_GLOBAL_HI 0x48
250static const char *ferr_global_hi_name[] = {
251 [3] = "FSB 3 Fatal Error",
252 [2] = "FSB 2 Fatal Error",
253 [1] = "FSB 1 Fatal Error",
254 [0] = "FSB 0 Fatal Error",
255};
256#define ferr_global_hi_is_fatal(errno) 1
257
258#define FERR_GLOBAL_LO 0x40
259static const char *ferr_global_lo_name[] = {
260 [31] = "Internal MCH Fatal Error",
261 [30] = "Intel QuickData Technology Device Fatal Error",
262 [29] = "FSB1 Fatal Error",
263 [28] = "FSB0 Fatal Error",
264 [27] = "FBD Channel 3 Fatal Error",
265 [26] = "FBD Channel 2 Fatal Error",
266 [25] = "FBD Channel 1 Fatal Error",
267 [24] = "FBD Channel 0 Fatal Error",
268 [23] = "PCI Express Device 7Fatal Error",
269 [22] = "PCI Express Device 6 Fatal Error",
270 [21] = "PCI Express Device 5 Fatal Error",
271 [20] = "PCI Express Device 4 Fatal Error",
272 [19] = "PCI Express Device 3 Fatal Error",
273 [18] = "PCI Express Device 2 Fatal Error",
274 [17] = "PCI Express Device 1 Fatal Error",
275 [16] = "ESI Fatal Error",
276 [15] = "Internal MCH Non-Fatal Error",
277 [14] = "Intel QuickData Technology Device Non Fatal Error",
278 [13] = "FSB1 Non-Fatal Error",
279 [12] = "FSB 0 Non-Fatal Error",
280 [11] = "FBD Channel 3 Non-Fatal Error",
281 [10] = "FBD Channel 2 Non-Fatal Error",
282 [9] = "FBD Channel 1 Non-Fatal Error",
283 [8] = "FBD Channel 0 Non-Fatal Error",
284 [7] = "PCI Express Device 7 Non-Fatal Error",
285 [6] = "PCI Express Device 6 Non-Fatal Error",
286 [5] = "PCI Express Device 5 Non-Fatal Error",
287 [4] = "PCI Express Device 4 Non-Fatal Error",
288 [3] = "PCI Express Device 3 Non-Fatal Error",
289 [2] = "PCI Express Device 2 Non-Fatal Error",
290 [1] = "PCI Express Device 1 Non-Fatal Error",
291 [0] = "ESI Non-Fatal Error",
292};
293#define ferr_global_lo_is_fatal(errno) ((errno < 16) ? 0 : 1)
294
295#define NRECMEMA 0xbe
296 #define NRECMEMA_BANK(v) (((v) >> 12) & 7)
297 #define NRECMEMA_RANK(v) (((v) >> 8) & 15)
298
299#define NRECMEMB 0xc0
300 #define NRECMEMB_IS_WR(v) ((v) & (1 << 31))
301 #define NRECMEMB_CAS(v) (((v) >> 16) & 0x1fff)
302 #define NRECMEMB_RAS(v) ((v) & 0xffff)
303
304#define REDMEMA 0xdc
305
306#define REDMEMB 0x7c
307 #define IS_SECOND_CH(v) ((v) * (1 << 17))
308
309#define RECMEMA 0xe0
310 #define RECMEMA_BANK(v) (((v) >> 12) & 7)
311 #define RECMEMA_RANK(v) (((v) >> 8) & 15)
312
313#define RECMEMB 0xe4
314 #define RECMEMB_IS_WR(v) ((v) & (1 << 31))
315 #define RECMEMB_CAS(v) (((v) >> 16) & 0x1fff)
316 #define RECMEMB_RAS(v) ((v) & 0xffff)
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334static const char *get_err_from_table(const char *table[], int size, int pos)
335{
336 if (unlikely(pos >= size))
337 return "Reserved";
338
339 if (unlikely(!table[pos]))
340 return "Reserved";
341
342 return table[pos];
343}
344
345#define GET_ERR_FROM_TABLE(table, pos) \
346 get_err_from_table(table, ARRAY_SIZE(table), pos)
347
348
349
350
351
352
353
354static void i7300_process_error_global(struct mem_ctl_info *mci)
355{
356 struct i7300_pvt *pvt;
357 u32 errnum, error_reg;
358 unsigned long errors;
359 const char *specific;
360 bool is_fatal;
361
362 pvt = mci->pvt_info;
363
364
365 pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
366 FERR_GLOBAL_HI, &error_reg);
367 if (unlikely(error_reg)) {
368 errors = error_reg;
369 errnum = find_first_bit(&errors,
370 ARRAY_SIZE(ferr_global_hi_name));
371 specific = GET_ERR_FROM_TABLE(ferr_global_hi_name, errnum);
372 is_fatal = ferr_global_hi_is_fatal(errnum);
373
374
375 pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
376 FERR_GLOBAL_HI, error_reg);
377
378 goto error_global;
379 }
380
381 pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
382 FERR_GLOBAL_LO, &error_reg);
383 if (unlikely(error_reg)) {
384 errors = error_reg;
385 errnum = find_first_bit(&errors,
386 ARRAY_SIZE(ferr_global_lo_name));
387 specific = GET_ERR_FROM_TABLE(ferr_global_lo_name, errnum);
388 is_fatal = ferr_global_lo_is_fatal(errnum);
389
390
391 pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
392 FERR_GLOBAL_LO, error_reg);
393
394 goto error_global;
395 }
396 return;
397
398error_global:
399 i7300_mc_printk(mci, KERN_EMERG, "%s misc error: %s\n",
400 is_fatal ? "Fatal" : "NOT fatal", specific);
401}
402
403
404
405
406
407
408
409static void i7300_process_fbd_error(struct mem_ctl_info *mci)
410{
411 struct i7300_pvt *pvt;
412 u32 errnum, value, error_reg;
413 u16 val16;
414 unsigned branch, channel, bank, rank, cas, ras;
415 u32 syndrome;
416
417 unsigned long errors;
418 const char *specific;
419 bool is_wr;
420
421 pvt = mci->pvt_info;
422
423
424 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
425 FERR_FAT_FBD, &error_reg);
426 if (unlikely(error_reg & FERR_FAT_FBD_ERR_MASK)) {
427 errors = error_reg & FERR_FAT_FBD_ERR_MASK ;
428 errnum = find_first_bit(&errors,
429 ARRAY_SIZE(ferr_fat_fbd_name));
430 specific = GET_ERR_FROM_TABLE(ferr_fat_fbd_name, errnum);
431 branch = (GET_FBD_FAT_IDX(error_reg) == 2) ? 1 : 0;
432
433 pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map,
434 NRECMEMA, &val16);
435 bank = NRECMEMA_BANK(val16);
436 rank = NRECMEMA_RANK(val16);
437
438 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
439 NRECMEMB, &value);
440 is_wr = NRECMEMB_IS_WR(value);
441 cas = NRECMEMB_CAS(value);
442 ras = NRECMEMB_RAS(value);
443
444
445 pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
446 FERR_FAT_FBD, error_reg);
447
448 snprintf(pvt->tmp_prt_buffer, PAGE_SIZE,
449 "Bank=%d RAS=%d CAS=%d Err=0x%lx (%s))",
450 bank, ras, cas, errors, specific);
451
452 edac_mc_handle_error(HW_EVENT_ERR_FATAL, mci, 1, 0, 0, 0,
453 branch, -1, rank,
454 is_wr ? "Write error" : "Read error",
455 pvt->tmp_prt_buffer);
456
457 }
458
459
460 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
461 FERR_NF_FBD, &error_reg);
462 if (unlikely(error_reg & FERR_NF_FBD_ERR_MASK)) {
463 errors = error_reg & FERR_NF_FBD_ERR_MASK;
464 errnum = find_first_bit(&errors,
465 ARRAY_SIZE(ferr_nf_fbd_name));
466 specific = GET_ERR_FROM_TABLE(ferr_nf_fbd_name, errnum);
467 branch = (GET_FBD_NF_IDX(error_reg) == 2) ? 1 : 0;
468
469 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
470 REDMEMA, &syndrome);
471
472 pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map,
473 RECMEMA, &val16);
474 bank = RECMEMA_BANK(val16);
475 rank = RECMEMA_RANK(val16);
476
477 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
478 RECMEMB, &value);
479 is_wr = RECMEMB_IS_WR(value);
480 cas = RECMEMB_CAS(value);
481 ras = RECMEMB_RAS(value);
482
483 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
484 REDMEMB, &value);
485 channel = (branch << 1);
486 if (IS_SECOND_CH(value))
487 channel++;
488
489
490 pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
491 FERR_NF_FBD, error_reg);
492
493
494 snprintf(pvt->tmp_prt_buffer, PAGE_SIZE,
495 "DRAM-Bank=%d RAS=%d CAS=%d, Err=0x%lx (%s))",
496 bank, ras, cas, errors, specific);
497
498 edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1, 0, 0,
499 syndrome,
500 branch >> 1, channel % 2, rank,
501 is_wr ? "Write error" : "Read error",
502 pvt->tmp_prt_buffer);
503 }
504 return;
505}
506
507
508
509
510
511static void i7300_check_error(struct mem_ctl_info *mci)
512{
513 i7300_process_error_global(mci);
514 i7300_process_fbd_error(mci);
515};
516
517
518
519
520
521static void i7300_clear_error(struct mem_ctl_info *mci)
522{
523 struct i7300_pvt *pvt = mci->pvt_info;
524 u32 value;
525
526
527
528
529
530
531 pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
532 FERR_GLOBAL_HI, &value);
533 pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
534 FERR_GLOBAL_HI, value);
535
536 pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
537 FERR_GLOBAL_LO, &value);
538 pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
539 FERR_GLOBAL_LO, value);
540
541
542 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
543 FERR_FAT_FBD, &value);
544 pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
545 FERR_FAT_FBD, value);
546
547 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
548 FERR_NF_FBD, &value);
549 pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
550 FERR_NF_FBD, value);
551}
552
553
554
555
556
557
558static void i7300_enable_error_reporting(struct mem_ctl_info *mci)
559{
560 struct i7300_pvt *pvt = mci->pvt_info;
561 u32 fbd_error_mask;
562
563
564 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
565 EMASK_FBD, &fbd_error_mask);
566
567
568 fbd_error_mask &= ~(EMASK_FBD_ERR_MASK);
569
570 pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
571 EMASK_FBD, fbd_error_mask);
572}
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587static int decode_mtr(struct i7300_pvt *pvt,
588 int slot, int ch, int branch,
589 struct i7300_dimm_info *dinfo,
590 struct dimm_info *dimm)
591{
592 int mtr, ans, addrBits, channel;
593
594 channel = to_channel(ch, branch);
595
596 mtr = pvt->mtr[slot][branch];
597 ans = MTR_DIMMS_PRESENT(mtr) ? 1 : 0;
598
599 edac_dbg(2, "\tMTR%d CH%d: DIMMs are %sPresent (mtr)\n",
600 slot, channel, ans ? "" : "NOT ");
601
602
603 if (!ans)
604 return 0;
605
606
607
608 addrBits = MTR_DRAM_BANKS_ADDR_BITS;
609
610 addrBits += MTR_DIMM_ROWS_ADDR_BITS(mtr);
611
612 addrBits += MTR_DIMM_COLS_ADDR_BITS(mtr);
613
614 addrBits += MTR_DIMM_RANKS(mtr);
615
616 addrBits += 6;
617 addrBits -= 20;
618 addrBits -= 3;
619
620 dinfo->megabytes = 1 << addrBits;
621
622 edac_dbg(2, "\t\tWIDTH: x%d\n", MTR_DRAM_WIDTH(mtr));
623
624 edac_dbg(2, "\t\tELECTRICAL THROTTLING is %s\n",
625 MTR_DIMMS_ETHROTTLE(mtr) ? "enabled" : "disabled");
626
627 edac_dbg(2, "\t\tNUMBANK: %d bank(s)\n", MTR_DRAM_BANKS(mtr));
628 edac_dbg(2, "\t\tNUMRANK: %s\n",
629 MTR_DIMM_RANKS(mtr) ? "double" : "single");
630 edac_dbg(2, "\t\tNUMROW: %s\n",
631 MTR_DIMM_ROWS(mtr) == 0 ? "8,192 - 13 rows" :
632 MTR_DIMM_ROWS(mtr) == 1 ? "16,384 - 14 rows" :
633 MTR_DIMM_ROWS(mtr) == 2 ? "32,768 - 15 rows" :
634 "65,536 - 16 rows");
635 edac_dbg(2, "\t\tNUMCOL: %s\n",
636 MTR_DIMM_COLS(mtr) == 0 ? "1,024 - 10 columns" :
637 MTR_DIMM_COLS(mtr) == 1 ? "2,048 - 11 columns" :
638 MTR_DIMM_COLS(mtr) == 2 ? "4,096 - 12 columns" :
639 "reserved");
640 edac_dbg(2, "\t\tSIZE: %d MB\n", dinfo->megabytes);
641
642
643
644
645
646
647
648
649
650
651 dimm->nr_pages = MiB_TO_PAGES(dinfo->megabytes);
652 dimm->grain = 8;
653 dimm->mtype = MEM_FB_DDR2;
654 if (IS_SINGLE_MODE(pvt->mc_settings_a)) {
655 dimm->edac_mode = EDAC_SECDED;
656 edac_dbg(2, "\t\tECC code is 8-byte-over-32-byte SECDED+ code\n");
657 } else {
658 edac_dbg(2, "\t\tECC code is on Lockstep mode\n");
659 if (MTR_DRAM_WIDTH(mtr) == 8)
660 dimm->edac_mode = EDAC_S8ECD8ED;
661 else
662 dimm->edac_mode = EDAC_S4ECD4ED;
663 }
664
665
666 if (MTR_DRAM_WIDTH(mtr) == 8) {
667 edac_dbg(2, "\t\tScrub algorithm for x8 is on %s mode\n",
668 IS_SCRBALGO_ENHANCED(pvt->mc_settings) ?
669 "enhanced" : "normal");
670
671 dimm->dtype = DEV_X8;
672 } else
673 dimm->dtype = DEV_X4;
674
675 return mtr;
676}
677
678
679
680
681
682
683
684static void print_dimm_size(struct i7300_pvt *pvt)
685{
686#ifdef CONFIG_EDAC_DEBUG
687 struct i7300_dimm_info *dinfo;
688 char *p;
689 int space, n;
690 int channel, slot;
691
692 space = PAGE_SIZE;
693 p = pvt->tmp_prt_buffer;
694
695 n = snprintf(p, space, " ");
696 p += n;
697 space -= n;
698 for (channel = 0; channel < MAX_CHANNELS; channel++) {
699 n = snprintf(p, space, "channel %d | ", channel);
700 p += n;
701 space -= n;
702 }
703 edac_dbg(2, "%s\n", pvt->tmp_prt_buffer);
704 p = pvt->tmp_prt_buffer;
705 space = PAGE_SIZE;
706 n = snprintf(p, space, "-------------------------------"
707 "------------------------------");
708 p += n;
709 space -= n;
710 edac_dbg(2, "%s\n", pvt->tmp_prt_buffer);
711 p = pvt->tmp_prt_buffer;
712 space = PAGE_SIZE;
713
714 for (slot = 0; slot < MAX_SLOTS; slot++) {
715 n = snprintf(p, space, "csrow/SLOT %d ", slot);
716 p += n;
717 space -= n;
718
719 for (channel = 0; channel < MAX_CHANNELS; channel++) {
720 dinfo = &pvt->dimm_info[slot][channel];
721 n = snprintf(p, space, "%4d MB | ", dinfo->megabytes);
722 p += n;
723 space -= n;
724 }
725
726 edac_dbg(2, "%s\n", pvt->tmp_prt_buffer);
727 p = pvt->tmp_prt_buffer;
728 space = PAGE_SIZE;
729 }
730
731 n = snprintf(p, space, "-------------------------------"
732 "------------------------------");
733 p += n;
734 space -= n;
735 edac_dbg(2, "%s\n", pvt->tmp_prt_buffer);
736 p = pvt->tmp_prt_buffer;
737 space = PAGE_SIZE;
738#endif
739}
740
741
742
743
744
745
746
747static int i7300_init_csrows(struct mem_ctl_info *mci)
748{
749 struct i7300_pvt *pvt;
750 struct i7300_dimm_info *dinfo;
751 int rc = -ENODEV;
752 int mtr;
753 int ch, branch, slot, channel, max_channel, max_branch;
754 struct dimm_info *dimm;
755
756 pvt = mci->pvt_info;
757
758 edac_dbg(2, "Memory Technology Registers:\n");
759
760 if (IS_SINGLE_MODE(pvt->mc_settings_a)) {
761 max_branch = 1;
762 max_channel = 1;
763 } else {
764 max_branch = MAX_BRANCHES;
765 max_channel = MAX_CH_PER_BRANCH;
766 }
767
768
769 for (branch = 0; branch < max_branch; branch++) {
770
771 channel = to_channel(0, branch);
772 pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch],
773 AMBPRESENT_0,
774 &pvt->ambpresent[channel]);
775 edac_dbg(2, "\t\tAMB-present CH%d = 0x%x:\n",
776 channel, pvt->ambpresent[channel]);
777
778 if (max_channel == 1)
779 continue;
780
781 channel = to_channel(1, branch);
782 pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch],
783 AMBPRESENT_1,
784 &pvt->ambpresent[channel]);
785 edac_dbg(2, "\t\tAMB-present CH%d = 0x%x:\n",
786 channel, pvt->ambpresent[channel]);
787 }
788
789
790 for (slot = 0; slot < MAX_SLOTS; slot++) {
791 int where = mtr_regs[slot];
792 for (branch = 0; branch < max_branch; branch++) {
793 pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch],
794 where,
795 &pvt->mtr[slot][branch]);
796 for (ch = 0; ch < max_channel; ch++) {
797 int channel = to_channel(ch, branch);
798
799 dimm = EDAC_DIMM_PTR(mci->layers, mci->dimms,
800 mci->n_layers, branch, ch, slot);
801
802 dinfo = &pvt->dimm_info[slot][channel];
803
804 mtr = decode_mtr(pvt, slot, ch, branch,
805 dinfo, dimm);
806
807
808 if (!MTR_DIMMS_PRESENT(mtr))
809 continue;
810
811 rc = 0;
812
813 }
814 }
815 }
816
817 return rc;
818}
819
820
821
822
823
824
825static void decode_mir(int mir_no, u16 mir[MAX_MIR])
826{
827 if (mir[mir_no] & 3)
828 edac_dbg(2, "MIR%d: limit= 0x%x Branch(es) that participate: %s %s\n",
829 mir_no,
830 (mir[mir_no] >> 4) & 0xfff,
831 (mir[mir_no] & 1) ? "B0" : "",
832 (mir[mir_no] & 2) ? "B1" : "");
833}
834
835
836
837
838
839
840
841static int i7300_get_mc_regs(struct mem_ctl_info *mci)
842{
843 struct i7300_pvt *pvt;
844 u32 actual_tolm;
845 int i, rc;
846
847 pvt = mci->pvt_info;
848
849 pci_read_config_dword(pvt->pci_dev_16_0_fsb_ctlr, AMBASE,
850 (u32 *) &pvt->ambase);
851
852 edac_dbg(2, "AMBASE= 0x%lx\n", (long unsigned int)pvt->ambase);
853
854
855 pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, TOLM, &pvt->tolm);
856 pvt->tolm >>= 12;
857 edac_dbg(2, "TOLM (number of 256M regions) =%u (0x%x)\n",
858 pvt->tolm, pvt->tolm);
859
860 actual_tolm = (u32) ((1000l * pvt->tolm) >> (30 - 28));
861 edac_dbg(2, "Actual TOLM byte addr=%u.%03u GB (0x%x)\n",
862 actual_tolm/1000, actual_tolm % 1000, pvt->tolm << 28);
863
864
865 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, MC_SETTINGS,
866 &pvt->mc_settings);
867 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, MC_SETTINGS_A,
868 &pvt->mc_settings_a);
869
870 if (IS_SINGLE_MODE(pvt->mc_settings_a))
871 edac_dbg(0, "Memory controller operating on single mode\n");
872 else
873 edac_dbg(0, "Memory controller operating on %smirrored mode\n",
874 IS_MIRRORED(pvt->mc_settings) ? "" : "non-");
875
876 edac_dbg(0, "Error detection is %s\n",
877 IS_ECC_ENABLED(pvt->mc_settings) ? "enabled" : "disabled");
878 edac_dbg(0, "Retry is %s\n",
879 IS_RETRY_ENABLED(pvt->mc_settings) ? "enabled" : "disabled");
880
881
882 pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR0,
883 &pvt->mir[0]);
884 pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR1,
885 &pvt->mir[1]);
886 pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR2,
887 &pvt->mir[2]);
888
889
890 for (i = 0; i < MAX_MIR; i++)
891 decode_mir(i, pvt->mir);
892
893 rc = i7300_init_csrows(mci);
894 if (rc < 0)
895 return rc;
896
897
898
899 print_dimm_size(pvt);
900
901 return 0;
902}
903
904
905
906
907
908
909
910
911
912static void i7300_put_devices(struct mem_ctl_info *mci)
913{
914 struct i7300_pvt *pvt;
915 int branch;
916
917 pvt = mci->pvt_info;
918
919
920 for (branch = 0; branch < MAX_CH_PER_BRANCH; branch++)
921 pci_dev_put(pvt->pci_dev_2x_0_fbd_branch[branch]);
922 pci_dev_put(pvt->pci_dev_16_2_fsb_err_regs);
923 pci_dev_put(pvt->pci_dev_16_1_fsb_addr_map);
924}
925
926
927
928
929
930
931
932
933
934
935
936
937static int i7300_get_devices(struct mem_ctl_info *mci)
938{
939 struct i7300_pvt *pvt;
940 struct pci_dev *pdev;
941
942 pvt = mci->pvt_info;
943
944
945 pdev = NULL;
946 while (!pvt->pci_dev_16_1_fsb_addr_map ||
947 !pvt->pci_dev_16_2_fsb_err_regs) {
948 pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
949 PCI_DEVICE_ID_INTEL_I7300_MCH_ERR, pdev);
950 if (!pdev) {
951
952 i7300_printk(KERN_ERR,
953 "'system address,Process Bus' "
954 "device not found:"
955 "vendor 0x%x device 0x%x ERR funcs "
956 "(broken BIOS?)\n",
957 PCI_VENDOR_ID_INTEL,
958 PCI_DEVICE_ID_INTEL_I7300_MCH_ERR);
959 goto error;
960 }
961
962
963 switch (PCI_FUNC(pdev->devfn)) {
964 case 1:
965 pvt->pci_dev_16_1_fsb_addr_map = pdev;
966 break;
967 case 2:
968 pvt->pci_dev_16_2_fsb_err_regs = pdev;
969 break;
970 }
971 }
972
973 edac_dbg(1, "System Address, processor bus- PCI Bus ID: %s %x:%x\n",
974 pci_name(pvt->pci_dev_16_0_fsb_ctlr),
975 pvt->pci_dev_16_0_fsb_ctlr->vendor,
976 pvt->pci_dev_16_0_fsb_ctlr->device);
977 edac_dbg(1, "Branchmap, control and errors - PCI Bus ID: %s %x:%x\n",
978 pci_name(pvt->pci_dev_16_1_fsb_addr_map),
979 pvt->pci_dev_16_1_fsb_addr_map->vendor,
980 pvt->pci_dev_16_1_fsb_addr_map->device);
981 edac_dbg(1, "FSB Error Regs - PCI Bus ID: %s %x:%x\n",
982 pci_name(pvt->pci_dev_16_2_fsb_err_regs),
983 pvt->pci_dev_16_2_fsb_err_regs->vendor,
984 pvt->pci_dev_16_2_fsb_err_regs->device);
985
986 pvt->pci_dev_2x_0_fbd_branch[0] = pci_get_device(PCI_VENDOR_ID_INTEL,
987 PCI_DEVICE_ID_INTEL_I7300_MCH_FB0,
988 NULL);
989 if (!pvt->pci_dev_2x_0_fbd_branch[0]) {
990 i7300_printk(KERN_ERR,
991 "MC: 'BRANCH 0' device not found:"
992 "vendor 0x%x device 0x%x Func 0 (broken BIOS?)\n",
993 PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_FB0);
994 goto error;
995 }
996
997 pvt->pci_dev_2x_0_fbd_branch[1] = pci_get_device(PCI_VENDOR_ID_INTEL,
998 PCI_DEVICE_ID_INTEL_I7300_MCH_FB1,
999 NULL);
1000 if (!pvt->pci_dev_2x_0_fbd_branch[1]) {
1001 i7300_printk(KERN_ERR,
1002 "MC: 'BRANCH 1' device not found:"
1003 "vendor 0x%x device 0x%x Func 0 "
1004 "(broken BIOS?)\n",
1005 PCI_VENDOR_ID_INTEL,
1006 PCI_DEVICE_ID_INTEL_I7300_MCH_FB1);
1007 goto error;
1008 }
1009
1010 return 0;
1011
1012error:
1013 i7300_put_devices(mci);
1014 return -ENODEV;
1015}
1016
1017
1018
1019
1020
1021
1022static int i7300_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
1023{
1024 struct mem_ctl_info *mci;
1025 struct edac_mc_layer layers[3];
1026 struct i7300_pvt *pvt;
1027 int rc;
1028
1029
1030 rc = pci_enable_device(pdev);
1031 if (rc == -EIO)
1032 return rc;
1033
1034 edac_dbg(0, "MC: pdev bus %u dev=0x%x fn=0x%x\n",
1035 pdev->bus->number,
1036 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
1037
1038
1039 if (PCI_FUNC(pdev->devfn) != 0)
1040 return -ENODEV;
1041
1042
1043 layers[0].type = EDAC_MC_LAYER_BRANCH;
1044 layers[0].size = MAX_BRANCHES;
1045 layers[0].is_virt_csrow = false;
1046 layers[1].type = EDAC_MC_LAYER_CHANNEL;
1047 layers[1].size = MAX_CH_PER_BRANCH;
1048 layers[1].is_virt_csrow = true;
1049 layers[2].type = EDAC_MC_LAYER_SLOT;
1050 layers[2].size = MAX_SLOTS;
1051 layers[2].is_virt_csrow = true;
1052 mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, sizeof(*pvt));
1053 if (mci == NULL)
1054 return -ENOMEM;
1055
1056 edac_dbg(0, "MC: mci = %p\n", mci);
1057
1058 mci->pdev = &pdev->dev;
1059
1060 pvt = mci->pvt_info;
1061 pvt->pci_dev_16_0_fsb_ctlr = pdev;
1062
1063 pvt->tmp_prt_buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);
1064 if (!pvt->tmp_prt_buffer) {
1065 edac_mc_free(mci);
1066 return -ENOMEM;
1067 }
1068
1069
1070 if (i7300_get_devices(mci))
1071 goto fail0;
1072
1073 mci->mc_idx = 0;
1074 mci->mtype_cap = MEM_FLAG_FB_DDR2;
1075 mci->edac_ctl_cap = EDAC_FLAG_NONE;
1076 mci->edac_cap = EDAC_FLAG_NONE;
1077 mci->mod_name = "i7300_edac.c";
1078 mci->mod_ver = I7300_REVISION;
1079 mci->ctl_name = i7300_devs[0].ctl_name;
1080 mci->dev_name = pci_name(pdev);
1081 mci->ctl_page_to_phys = NULL;
1082
1083
1084 mci->edac_check = i7300_check_error;
1085
1086
1087
1088 if (i7300_get_mc_regs(mci)) {
1089 edac_dbg(0, "MC: Setting mci->edac_cap to EDAC_FLAG_NONE because i7300_init_csrows() returned nonzero value\n");
1090 mci->edac_cap = EDAC_FLAG_NONE;
1091 } else {
1092 edac_dbg(1, "MC: Enable error reporting now\n");
1093 i7300_enable_error_reporting(mci);
1094 }
1095
1096
1097 if (edac_mc_add_mc(mci)) {
1098 edac_dbg(0, "MC: failed edac_mc_add_mc()\n");
1099
1100
1101
1102 goto fail1;
1103 }
1104
1105 i7300_clear_error(mci);
1106
1107
1108 i7300_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
1109 if (!i7300_pci) {
1110 printk(KERN_WARNING
1111 "%s(): Unable to create PCI control\n",
1112 __func__);
1113 printk(KERN_WARNING
1114 "%s(): PCI error report via EDAC not setup\n",
1115 __func__);
1116 }
1117
1118 return 0;
1119
1120
1121fail1:
1122
1123 i7300_put_devices(mci);
1124
1125fail0:
1126 kfree(pvt->tmp_prt_buffer);
1127 edac_mc_free(mci);
1128 return -ENODEV;
1129}
1130
1131
1132
1133
1134
1135static void i7300_remove_one(struct pci_dev *pdev)
1136{
1137 struct mem_ctl_info *mci;
1138 char *tmp;
1139
1140 edac_dbg(0, "\n");
1141
1142 if (i7300_pci)
1143 edac_pci_release_generic_ctl(i7300_pci);
1144
1145 mci = edac_mc_del_mc(&pdev->dev);
1146 if (!mci)
1147 return;
1148
1149 tmp = ((struct i7300_pvt *)mci->pvt_info)->tmp_prt_buffer;
1150
1151
1152 i7300_put_devices(mci);
1153
1154 kfree(tmp);
1155 edac_mc_free(mci);
1156}
1157
1158
1159
1160
1161
1162
1163static DEFINE_PCI_DEVICE_TABLE(i7300_pci_tbl) = {
1164 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
1165 {0,}
1166};
1167
1168MODULE_DEVICE_TABLE(pci, i7300_pci_tbl);
1169
1170
1171
1172
1173static struct pci_driver i7300_driver = {
1174 .name = "i7300_edac",
1175 .probe = i7300_init_one,
1176 .remove = i7300_remove_one,
1177 .id_table = i7300_pci_tbl,
1178};
1179
1180
1181
1182
1183static int __init i7300_init(void)
1184{
1185 int pci_rc;
1186
1187 edac_dbg(2, "\n");
1188
1189
1190 opstate_init();
1191
1192 pci_rc = pci_register_driver(&i7300_driver);
1193
1194 return (pci_rc < 0) ? pci_rc : 0;
1195}
1196
1197
1198
1199
1200static void __exit i7300_exit(void)
1201{
1202 edac_dbg(2, "\n");
1203 pci_unregister_driver(&i7300_driver);
1204}
1205
1206module_init(i7300_init);
1207module_exit(i7300_exit);
1208
1209MODULE_LICENSE("GPL");
1210MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
1211MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
1212MODULE_DESCRIPTION("MC Driver for Intel I7300 memory controllers - "
1213 I7300_REVISION);
1214
1215module_param(edac_op_state, int, 0444);
1216MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
1217