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_core.h"
18
19#define I3000_REVISION "1.1"
20
21#define EDAC_MOD_STR "i3000_edac"
22
23#define I3000_RANKS 8
24#define I3000_RANKS_PER_CHANNEL 4
25#define I3000_CHANNELS 2
26
27
28
29#define I3000_MCHBAR 0x44
30#define I3000_MCHBAR_MASK 0xffffc000
31#define I3000_MMR_WINDOW_SIZE 16384
32
33#define I3000_EDEAP 0x70
34
35
36
37
38#define I3000_DEAP 0x58
39
40
41
42
43
44#define I3000_DEAP_GRAIN (1 << 7)
45
46
47
48
49
50
51
52
53static inline unsigned long deap_pfn(u8 edeap, u32 deap)
54{
55 deap >>= PAGE_SHIFT;
56 deap |= (edeap & 1) << (32 - PAGE_SHIFT);
57 return deap;
58}
59
60static inline unsigned long deap_offset(u32 deap)
61{
62 return deap & ~(I3000_DEAP_GRAIN - 1) & ~PAGE_MASK;
63}
64
65static inline int deap_channel(u32 deap)
66{
67 return deap & 1;
68}
69
70#define I3000_DERRSYN 0x5c
71
72
73
74
75#define I3000_ERRSTS 0xc8
76
77
78
79
80
81
82
83
84
85
86
87#define I3000_ERRSTS_BITS 0x0b03
88#define I3000_ERRSTS_UE 0x0002
89#define I3000_ERRSTS_CE 0x0001
90
91#define I3000_ERRCMD 0xca
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110#define I3000_DRB_SHIFT 25
111
112#define I3000_C0DRB 0x100
113
114
115
116#define I3000_C1DRB 0x180
117
118
119
120
121#define I3000_C0DRA 0x108
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137#define I3000_C1DRA 0x188
138
139static inline unsigned char odd_rank_attrib(unsigned char dra)
140{
141 return (dra & 0x70) >> 4;
142}
143
144static inline unsigned char even_rank_attrib(unsigned char dra)
145{
146 return dra & 0x07;
147}
148
149#define I3000_C0DRC0 0x120
150
151
152
153
154
155
156
157
158
159
160
161#define I3000_C0DRC1 0x124
162
163
164
165
166
167enum i3000p_chips {
168 I3000 = 0,
169};
170
171struct i3000_dev_info {
172 const char *ctl_name;
173};
174
175struct i3000_error_info {
176 u16 errsts;
177 u8 derrsyn;
178 u8 edeap;
179 u32 deap;
180 u16 errsts2;
181};
182
183static const struct i3000_dev_info i3000_devs[] = {
184 [I3000] = {
185 .ctl_name = "i3000"},
186};
187
188static struct pci_dev *mci_pdev;
189static int i3000_registered = 1;
190static struct edac_pci_ctl_info *i3000_pci;
191
192static void i3000_get_error_info(struct mem_ctl_info *mci,
193 struct i3000_error_info *info)
194{
195 struct pci_dev *pdev;
196
197 pdev = to_pci_dev(mci->pdev);
198
199
200
201
202
203
204 pci_read_config_word(pdev, I3000_ERRSTS, &info->errsts);
205 if (!(info->errsts & I3000_ERRSTS_BITS))
206 return;
207 pci_read_config_byte(pdev, I3000_EDEAP, &info->edeap);
208 pci_read_config_dword(pdev, I3000_DEAP, &info->deap);
209 pci_read_config_byte(pdev, I3000_DERRSYN, &info->derrsyn);
210 pci_read_config_word(pdev, I3000_ERRSTS, &info->errsts2);
211
212
213
214
215
216
217
218 if ((info->errsts ^ info->errsts2) & I3000_ERRSTS_BITS) {
219 pci_read_config_byte(pdev, I3000_EDEAP, &info->edeap);
220 pci_read_config_dword(pdev, I3000_DEAP, &info->deap);
221 pci_read_config_byte(pdev, I3000_DERRSYN, &info->derrsyn);
222 }
223
224
225
226
227
228 pci_write_bits16(pdev, I3000_ERRSTS, I3000_ERRSTS_BITS,
229 I3000_ERRSTS_BITS);
230}
231
232static int i3000_process_error_info(struct mem_ctl_info *mci,
233 struct i3000_error_info *info,
234 int handle_errors)
235{
236 int row, multi_chan, channel;
237 unsigned long pfn, offset;
238
239 multi_chan = mci->csrows[0]->nr_channels - 1;
240
241 if (!(info->errsts & I3000_ERRSTS_BITS))
242 return 0;
243
244 if (!handle_errors)
245 return 1;
246
247 if ((info->errsts ^ info->errsts2) & I3000_ERRSTS_BITS) {
248 edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1, 0, 0, 0,
249 -1, -1, -1,
250 "UE overwrote CE", "");
251 info->errsts = info->errsts2;
252 }
253
254 pfn = deap_pfn(info->edeap, info->deap);
255 offset = deap_offset(info->deap);
256 channel = deap_channel(info->deap);
257
258 row = edac_mc_find_csrow_by_page(mci, pfn);
259
260 if (info->errsts & I3000_ERRSTS_UE)
261 edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1,
262 pfn, offset, 0,
263 row, -1, -1,
264 "i3000 UE", "");
265 else
266 edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1,
267 pfn, offset, info->derrsyn,
268 row, multi_chan ? channel : 0, -1,
269 "i3000 CE", "");
270
271 return 1;
272}
273
274static void i3000_check(struct mem_ctl_info *mci)
275{
276 struct i3000_error_info info;
277
278 edac_dbg(1, "MC%d\n", mci->mc_idx);
279 i3000_get_error_info(mci, &info);
280 i3000_process_error_info(mci, &info, 1);
281}
282
283static int i3000_is_interleaved(const unsigned char *c0dra,
284 const unsigned char *c1dra,
285 const unsigned char *c0drb,
286 const unsigned char *c1drb)
287{
288 int i;
289
290
291
292
293
294 for (i = 0; i < I3000_RANKS_PER_CHANNEL / 2; i++)
295 if (odd_rank_attrib(c0dra[i]) != odd_rank_attrib(c1dra[i]) ||
296 even_rank_attrib(c0dra[i]) !=
297 even_rank_attrib(c1dra[i]))
298 return 0;
299
300
301
302
303
304 for (i = 0; i < I3000_RANKS_PER_CHANNEL; i++)
305 if (c0drb[i] != c1drb[i])
306 return 0;
307
308 return 1;
309}
310
311static int i3000_probe1(struct pci_dev *pdev, int dev_idx)
312{
313 int rc;
314 int i, j;
315 struct mem_ctl_info *mci = NULL;
316 struct edac_mc_layer layers[2];
317 unsigned long last_cumul_size, nr_pages;
318 int interleaved, nr_channels;
319 unsigned char dra[I3000_RANKS / 2], drb[I3000_RANKS];
320 unsigned char *c0dra = dra, *c1dra = &dra[I3000_RANKS_PER_CHANNEL / 2];
321 unsigned char *c0drb = drb, *c1drb = &drb[I3000_RANKS_PER_CHANNEL];
322 unsigned long mchbar;
323 void __iomem *window;
324
325 edac_dbg(0, "MC:\n");
326
327 pci_read_config_dword(pdev, I3000_MCHBAR, (u32 *) & mchbar);
328 mchbar &= I3000_MCHBAR_MASK;
329 window = ioremap_nocache(mchbar, I3000_MMR_WINDOW_SIZE);
330 if (!window) {
331 printk(KERN_ERR "i3000: cannot map mmio space at 0x%lx\n",
332 mchbar);
333 return -ENODEV;
334 }
335
336 c0dra[0] = readb(window + I3000_C0DRA + 0);
337 c0dra[1] = readb(window + I3000_C0DRA + 1);
338 c1dra[0] = readb(window + I3000_C1DRA + 0);
339 c1dra[1] = readb(window + I3000_C1DRA + 1);
340
341 for (i = 0; i < I3000_RANKS_PER_CHANNEL; i++) {
342 c0drb[i] = readb(window + I3000_C0DRB + i);
343 c1drb[i] = readb(window + I3000_C1DRB + i);
344 }
345
346 iounmap(window);
347
348
349
350
351
352
353
354
355
356 interleaved = i3000_is_interleaved(c0dra, c1dra, c0drb, c1drb);
357 nr_channels = interleaved ? 2 : 1;
358
359 layers[0].type = EDAC_MC_LAYER_CHIP_SELECT;
360 layers[0].size = I3000_RANKS / nr_channels;
361 layers[0].is_virt_csrow = true;
362 layers[1].type = EDAC_MC_LAYER_CHANNEL;
363 layers[1].size = nr_channels;
364 layers[1].is_virt_csrow = false;
365 mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, 0);
366 if (!mci)
367 return -ENOMEM;
368
369 edac_dbg(3, "MC: init mci\n");
370
371 mci->pdev = &pdev->dev;
372 mci->mtype_cap = MEM_FLAG_DDR2;
373
374 mci->edac_ctl_cap = EDAC_FLAG_SECDED;
375 mci->edac_cap = EDAC_FLAG_SECDED;
376
377 mci->mod_name = EDAC_MOD_STR;
378 mci->mod_ver = I3000_REVISION;
379 mci->ctl_name = i3000_devs[dev_idx].ctl_name;
380 mci->dev_name = pci_name(pdev);
381 mci->edac_check = i3000_check;
382 mci->ctl_page_to_phys = NULL;
383
384
385
386
387
388
389
390
391
392
393 for (last_cumul_size = i = 0; i < mci->nr_csrows; i++) {
394 u8 value;
395 u32 cumul_size;
396 struct csrow_info *csrow = mci->csrows[i];
397
398 value = drb[i];
399 cumul_size = value << (I3000_DRB_SHIFT - PAGE_SHIFT);
400 if (interleaved)
401 cumul_size <<= 1;
402 edac_dbg(3, "MC: (%d) cumul_size 0x%x\n", i, cumul_size);
403 if (cumul_size == last_cumul_size)
404 continue;
405
406 csrow->first_page = last_cumul_size;
407 csrow->last_page = cumul_size - 1;
408 nr_pages = cumul_size - last_cumul_size;
409 last_cumul_size = cumul_size;
410
411 for (j = 0; j < nr_channels; j++) {
412 struct dimm_info *dimm = csrow->channels[j]->dimm;
413
414 dimm->nr_pages = nr_pages / nr_channels;
415 dimm->grain = I3000_DEAP_GRAIN;
416 dimm->mtype = MEM_DDR2;
417 dimm->dtype = DEV_UNKNOWN;
418 dimm->edac_mode = EDAC_UNKNOWN;
419 }
420 }
421
422
423
424
425
426 pci_write_bits16(pdev, I3000_ERRSTS, I3000_ERRSTS_BITS,
427 I3000_ERRSTS_BITS);
428
429 rc = -ENODEV;
430 if (edac_mc_add_mc(mci)) {
431 edac_dbg(3, "MC: failed edac_mc_add_mc()\n");
432 goto fail;
433 }
434
435
436 i3000_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
437 if (!i3000_pci) {
438 printk(KERN_WARNING
439 "%s(): Unable to create PCI control\n",
440 __func__);
441 printk(KERN_WARNING
442 "%s(): PCI error report via EDAC not setup\n",
443 __func__);
444 }
445
446
447 edac_dbg(3, "MC: success\n");
448 return 0;
449
450fail:
451 if (mci)
452 edac_mc_free(mci);
453
454 return rc;
455}
456
457
458static int i3000_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
459{
460 int rc;
461
462 edac_dbg(0, "MC:\n");
463
464 if (pci_enable_device(pdev) < 0)
465 return -EIO;
466
467 rc = i3000_probe1(pdev, ent->driver_data);
468 if (!mci_pdev)
469 mci_pdev = pci_dev_get(pdev);
470
471 return rc;
472}
473
474static void i3000_remove_one(struct pci_dev *pdev)
475{
476 struct mem_ctl_info *mci;
477
478 edac_dbg(0, "\n");
479
480 if (i3000_pci)
481 edac_pci_release_generic_ctl(i3000_pci);
482
483 mci = edac_mc_del_mc(&pdev->dev);
484 if (!mci)
485 return;
486
487 edac_mc_free(mci);
488}
489
490static const struct pci_device_id i3000_pci_tbl[] = {
491 {
492 PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
493 I3000},
494 {
495 0,
496 }
497};
498
499MODULE_DEVICE_TABLE(pci, i3000_pci_tbl);
500
501static struct pci_driver i3000_driver = {
502 .name = EDAC_MOD_STR,
503 .probe = i3000_init_one,
504 .remove = i3000_remove_one,
505 .id_table = i3000_pci_tbl,
506};
507
508static int __init i3000_init(void)
509{
510 int pci_rc;
511
512 edac_dbg(3, "MC:\n");
513
514
515 opstate_init();
516
517 pci_rc = pci_register_driver(&i3000_driver);
518 if (pci_rc < 0)
519 goto fail0;
520
521 if (!mci_pdev) {
522 i3000_registered = 0;
523 mci_pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
524 PCI_DEVICE_ID_INTEL_3000_HB, NULL);
525 if (!mci_pdev) {
526 edac_dbg(0, "i3000 pci_get_device fail\n");
527 pci_rc = -ENODEV;
528 goto fail1;
529 }
530
531 pci_rc = i3000_init_one(mci_pdev, i3000_pci_tbl);
532 if (pci_rc < 0) {
533 edac_dbg(0, "i3000 init fail\n");
534 pci_rc = -ENODEV;
535 goto fail1;
536 }
537 }
538
539 return 0;
540
541fail1:
542 pci_unregister_driver(&i3000_driver);
543
544fail0:
545 pci_dev_put(mci_pdev);
546
547 return pci_rc;
548}
549
550static void __exit i3000_exit(void)
551{
552 edac_dbg(3, "MC:\n");
553
554 pci_unregister_driver(&i3000_driver);
555 if (!i3000_registered) {
556 i3000_remove_one(mci_pdev);
557 pci_dev_put(mci_pdev);
558 }
559}
560
561module_init(i3000_init);
562module_exit(i3000_exit);
563
564MODULE_LICENSE("GPL");
565MODULE_AUTHOR("Akamai Technologies Arthur Ulfeldt/Jason Uhlenkott");
566MODULE_DESCRIPTION("MC support for Intel 3000 memory hub controllers");
567
568module_param(edac_op_state, int, 0444);
569MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
570