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