Blame view

drivers/edac/mv64x60_edac.c 21.8 KB
4f4aeeabc   Dave Jiang   drivers-edac: add...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  /*
   * Marvell MV64x60 Memory Controller kernel module for PPC platforms
   *
   * Author: Dave Jiang <djiang@mvista.com>
   *
   * 2006-2007 (c) MontaVista Software, Inc. This file is licensed under
   * the terms of the GNU General Public License version 2. This program
   * is licensed "as is" without any warranty of any kind, whether express
   * or implied.
   *
   */
  
  #include <linux/module.h>
  #include <linux/init.h>
4f4aeeabc   Dave Jiang   drivers-edac: add...
15
16
17
  #include <linux/interrupt.h>
  #include <linux/io.h>
  #include <linux/edac.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
18
  #include <linux/gfp.h>
4f4aeeabc   Dave Jiang   drivers-edac: add...
19

4f4aeeabc   Dave Jiang   drivers-edac: add...
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  #include "edac_module.h"
  #include "mv64x60_edac.h"
  
  static const char *mv64x60_ctl_name = "MV64x60";
  static int edac_dev_idx;
  static int edac_pci_idx;
  static int edac_mc_idx;
  
  /*********************** PCI err device **********************************/
  #ifdef CONFIG_PCI
  static void mv64x60_pci_check(struct edac_pci_ctl_info *pci)
  {
  	struct mv64x60_pci_pdata *pdata = pci->pvt_info;
  	u32 cause;
  
  	cause = in_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_CAUSE);
  	if (!cause)
  		return;
  
  	printk(KERN_ERR "Error in PCI %d Interface
  ", pdata->pci_hose);
  	printk(KERN_ERR "Cause register: 0x%08x
  ", cause);
  	printk(KERN_ERR "Address Low: 0x%08x
  ",
  	       in_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_ADDR_LO));
  	printk(KERN_ERR "Address High: 0x%08x
  ",
  	       in_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_ADDR_HI));
  	printk(KERN_ERR "Attribute: 0x%08x
  ",
  	       in_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_ATTR));
  	printk(KERN_ERR "Command: 0x%08x
  ",
  	       in_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_CMD));
  	out_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_CAUSE, ~cause);
  
  	if (cause & MV64X60_PCI_PE_MASK)
  		edac_pci_handle_pe(pci, pci->ctl_name);
  
  	if (!(cause & MV64X60_PCI_PE_MASK))
  		edac_pci_handle_npe(pci, pci->ctl_name);
  }
  
  static irqreturn_t mv64x60_pci_isr(int irq, void *dev_id)
  {
  	struct edac_pci_ctl_info *pci = dev_id;
  	struct mv64x60_pci_pdata *pdata = pci->pvt_info;
  	u32 val;
  
  	val = in_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_CAUSE);
  	if (!val)
  		return IRQ_NONE;
  
  	mv64x60_pci_check(pci);
  
  	return IRQ_HANDLED;
  }
fcb19171d   Dave Jiang   edac: mv64x60 add...
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  /*
   * Bit 0 of MV64x60_PCIx_ERR_MASK does not exist on the 64360 and because of
   * errata FEr-#11 and FEr-##16 for the 64460, it should be 0 on that chip as
   * well.  IOW, don't set bit 0.
   */
  
  /* Erratum FEr PCI-#16: clear bit 0 of PCI SERRn Mask reg. */
  static int __init mv64x60_pci_fixup(struct platform_device *pdev)
  {
  	struct resource *r;
  	void __iomem *pci_serr;
  
  	r = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  	if (!r) {
  		printk(KERN_ERR "%s: Unable to get resource for "
  		       "PCI err regs
  ", __func__);
  		return -ENOENT;
  	}
30a61fff3   Julia Lawall   edac: fix resourc...
97
  	pci_serr = ioremap(r->start, resource_size(r));
fcb19171d   Dave Jiang   edac: mv64x60 add...
98
99
100
101
102
103
104
105
  	if (!pci_serr)
  		return -ENOMEM;
  
  	out_le32(pci_serr, in_le32(pci_serr) & ~0x1);
  	iounmap(pci_serr);
  
  	return 0;
  }
9b3c6e85c   Greg Kroah-Hartman   Drivers: edac: re...
106
  static int mv64x60_pci_err_probe(struct platform_device *pdev)
4f4aeeabc   Dave Jiang   drivers-edac: add...
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
  {
  	struct edac_pci_ctl_info *pci;
  	struct mv64x60_pci_pdata *pdata;
  	struct resource *r;
  	int res = 0;
  
  	if (!devres_open_group(&pdev->dev, mv64x60_pci_err_probe, GFP_KERNEL))
  		return -ENOMEM;
  
  	pci = edac_pci_alloc_ctl_info(sizeof(*pdata), "mv64x60_pci_err");
  	if (!pci)
  		return -ENOMEM;
  
  	pdata = pci->pvt_info;
  
  	pdata->pci_hose = pdev->id;
  	pdata->name = "mpc85xx_pci_err";
4f4aeeabc   Dave Jiang   drivers-edac: add...
124
125
  	platform_set_drvdata(pdev, pci);
  	pci->dev = &pdev->dev;
031d55185   Kay Sievers   edac: struct devi...
126
  	pci->dev_name = dev_name(&pdev->dev);
4f4aeeabc   Dave Jiang   drivers-edac: add...
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
  	pci->mod_name = EDAC_MOD_STR;
  	pci->ctl_name = pdata->name;
  
  	if (edac_op_state == EDAC_OPSTATE_POLL)
  		pci->edac_check = mv64x60_pci_check;
  
  	pdata->edac_idx = edac_pci_idx++;
  
  	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  	if (!r) {
  		printk(KERN_ERR "%s: Unable to get resource for "
  		       "PCI err regs
  ", __func__);
  		res = -ENOENT;
  		goto err;
  	}
  
  	if (!devm_request_mem_region(&pdev->dev,
  				     r->start,
30a61fff3   Julia Lawall   edac: fix resourc...
146
  				     resource_size(r),
4f4aeeabc   Dave Jiang   drivers-edac: add...
147
148
149
150
151
152
153
154
155
156
  				     pdata->name)) {
  		printk(KERN_ERR "%s: Error while requesting mem region
  ",
  		       __func__);
  		res = -EBUSY;
  		goto err;
  	}
  
  	pdata->pci_vbase = devm_ioremap(&pdev->dev,
  					r->start,
30a61fff3   Julia Lawall   edac: fix resourc...
157
  					resource_size(r));
4f4aeeabc   Dave Jiang   drivers-edac: add...
158
159
160
161
162
163
  	if (!pdata->pci_vbase) {
  		printk(KERN_ERR "%s: Unable to setup PCI err regs
  ", __func__);
  		res = -ENOMEM;
  		goto err;
  	}
fcb19171d   Dave Jiang   edac: mv64x60 add...
164
165
166
167
168
169
  	res = mv64x60_pci_fixup(pdev);
  	if (res < 0) {
  		printk(KERN_ERR "%s: PCI fixup failed
  ", __func__);
  		goto err;
  	}
4f4aeeabc   Dave Jiang   drivers-edac: add...
170
171
172
173
174
175
  	out_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_CAUSE, 0);
  	out_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_MASK, 0);
  	out_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_MASK,
  		 MV64X60_PCIx_ERR_MASK_VAL);
  
  	if (edac_pci_add_device(pci, pdata->edac_idx) > 0) {
956b9ba15   Joe Perches   edac: Convert deb...
176
177
  		edac_dbg(3, "failed edac_pci_add_device()
  ");
4f4aeeabc   Dave Jiang   drivers-edac: add...
178
179
180
181
182
183
184
185
  		goto err;
  	}
  
  	if (edac_op_state == EDAC_OPSTATE_INT) {
  		pdata->irq = platform_get_irq(pdev, 0);
  		res = devm_request_irq(&pdev->dev,
  				       pdata->irq,
  				       mv64x60_pci_isr,
5c43cbdf7   Michael Opdenacker   {mv64x60,ppc4xx}_...
186
  				       0,
4f4aeeabc   Dave Jiang   drivers-edac: add...
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
  				       "[EDAC] PCI err",
  				       pci);
  		if (res < 0) {
  			printk(KERN_ERR "%s: Unable to request irq %d for "
  			       "MV64x60 PCI ERR
  ", __func__, pdata->irq);
  			res = -ENODEV;
  			goto err2;
  		}
  		printk(KERN_INFO EDAC_MOD_STR " acquired irq %d for PCI Err
  ",
  		       pdata->irq);
  	}
  
  	devres_remove_group(&pdev->dev, mv64x60_pci_err_probe);
  
  	/* get this far and it's successful */
956b9ba15   Joe Perches   edac: Convert deb...
204
205
  	edac_dbg(3, "success
  ");
4f4aeeabc   Dave Jiang   drivers-edac: add...
206
207
208
209
210
211
212
213
214
215
216
217
218
219
  
  	return 0;
  
  err2:
  	edac_pci_del_device(&pdev->dev);
  err:
  	edac_pci_free_ctl_info(pci);
  	devres_release_group(&pdev->dev, mv64x60_pci_err_probe);
  	return res;
  }
  
  static int mv64x60_pci_err_remove(struct platform_device *pdev)
  {
  	struct edac_pci_ctl_info *pci = platform_get_drvdata(pdev);
956b9ba15   Joe Perches   edac: Convert deb...
220
221
  	edac_dbg(0, "
  ");
4f4aeeabc   Dave Jiang   drivers-edac: add...
222
223
224
225
226
227
228
229
230
231
  
  	edac_pci_del_device(&pdev->dev);
  
  	edac_pci_free_ctl_info(pci);
  
  	return 0;
  }
  
  static struct platform_driver mv64x60_pci_err_driver = {
  	.probe = mv64x60_pci_err_probe,
9b3c6e85c   Greg Kroah-Hartman   Drivers: edac: re...
232
  	.remove = mv64x60_pci_err_remove,
4f4aeeabc   Dave Jiang   drivers-edac: add...
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
  	.driver = {
  		   .name = "mv64x60_pci_err",
  	}
  };
  
  #endif /* CONFIG_PCI */
  
  /*********************** SRAM err device **********************************/
  static void mv64x60_sram_check(struct edac_device_ctl_info *edac_dev)
  {
  	struct mv64x60_sram_pdata *pdata = edac_dev->pvt_info;
  	u32 cause;
  
  	cause = in_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_CAUSE);
  	if (!cause)
  		return;
  
  	printk(KERN_ERR "Error in internal SRAM
  ");
  	printk(KERN_ERR "Cause register: 0x%08x
  ", cause);
  	printk(KERN_ERR "Address Low: 0x%08x
  ",
  	       in_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_ADDR_LO));
  	printk(KERN_ERR "Address High: 0x%08x
  ",
  	       in_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_ADDR_HI));
  	printk(KERN_ERR "Data Low: 0x%08x
  ",
  	       in_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_DATA_LO));
  	printk(KERN_ERR "Data High: 0x%08x
  ",
  	       in_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_DATA_HI));
  	printk(KERN_ERR "Parity: 0x%08x
  ",
  	       in_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_PARITY));
  	out_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_CAUSE, 0);
  
  	edac_device_handle_ue(edac_dev, 0, 0, edac_dev->ctl_name);
  }
  
  static irqreturn_t mv64x60_sram_isr(int irq, void *dev_id)
  {
  	struct edac_device_ctl_info *edac_dev = dev_id;
  	struct mv64x60_sram_pdata *pdata = edac_dev->pvt_info;
  	u32 cause;
  
  	cause = in_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_CAUSE);
  	if (!cause)
  		return IRQ_NONE;
  
  	mv64x60_sram_check(edac_dev);
  
  	return IRQ_HANDLED;
  }
9b3c6e85c   Greg Kroah-Hartman   Drivers: edac: re...
288
  static int mv64x60_sram_err_probe(struct platform_device *pdev)
4f4aeeabc   Dave Jiang   drivers-edac: add...
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
  {
  	struct edac_device_ctl_info *edac_dev;
  	struct mv64x60_sram_pdata *pdata;
  	struct resource *r;
  	int res = 0;
  
  	if (!devres_open_group(&pdev->dev, mv64x60_sram_err_probe, GFP_KERNEL))
  		return -ENOMEM;
  
  	edac_dev = edac_device_alloc_ctl_info(sizeof(*pdata),
  					      "sram", 1, NULL, 0, 0, NULL, 0,
  					      edac_dev_idx);
  	if (!edac_dev) {
  		devres_release_group(&pdev->dev, mv64x60_sram_err_probe);
  		return -ENOMEM;
  	}
  
  	pdata = edac_dev->pvt_info;
  	pdata->name = "mv64x60_sram_err";
4f4aeeabc   Dave Jiang   drivers-edac: add...
308
309
  	edac_dev->dev = &pdev->dev;
  	platform_set_drvdata(pdev, edac_dev);
031d55185   Kay Sievers   edac: struct devi...
310
  	edac_dev->dev_name = dev_name(&pdev->dev);
4f4aeeabc   Dave Jiang   drivers-edac: add...
311
312
313
314
315
316
317
318
319
320
321
322
  
  	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  	if (!r) {
  		printk(KERN_ERR "%s: Unable to get resource for "
  		       "SRAM err regs
  ", __func__);
  		res = -ENOENT;
  		goto err;
  	}
  
  	if (!devm_request_mem_region(&pdev->dev,
  				     r->start,
30a61fff3   Julia Lawall   edac: fix resourc...
323
  				     resource_size(r),
4f4aeeabc   Dave Jiang   drivers-edac: add...
324
325
326
327
328
329
330
331
332
333
  				     pdata->name)) {
  		printk(KERN_ERR "%s: Error while request mem region
  ",
  		       __func__);
  		res = -EBUSY;
  		goto err;
  	}
  
  	pdata->sram_vbase = devm_ioremap(&pdev->dev,
  					 r->start,
30a61fff3   Julia Lawall   edac: fix resourc...
334
  					 resource_size(r));
4f4aeeabc   Dave Jiang   drivers-edac: add...
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
  	if (!pdata->sram_vbase) {
  		printk(KERN_ERR "%s: Unable to setup SRAM err regs
  ",
  		       __func__);
  		res = -ENOMEM;
  		goto err;
  	}
  
  	/* setup SRAM err registers */
  	out_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_CAUSE, 0);
  
  	edac_dev->mod_name = EDAC_MOD_STR;
  	edac_dev->ctl_name = pdata->name;
  
  	if (edac_op_state == EDAC_OPSTATE_POLL)
  		edac_dev->edac_check = mv64x60_sram_check;
  
  	pdata->edac_idx = edac_dev_idx++;
  
  	if (edac_device_add_device(edac_dev) > 0) {
956b9ba15   Joe Perches   edac: Convert deb...
355
356
  		edac_dbg(3, "failed edac_device_add_device()
  ");
4f4aeeabc   Dave Jiang   drivers-edac: add...
357
358
359
360
361
362
363
364
  		goto err;
  	}
  
  	if (edac_op_state == EDAC_OPSTATE_INT) {
  		pdata->irq = platform_get_irq(pdev, 0);
  		res = devm_request_irq(&pdev->dev,
  				       pdata->irq,
  				       mv64x60_sram_isr,
5c43cbdf7   Michael Opdenacker   {mv64x60,ppc4xx}_...
365
  				       0,
4f4aeeabc   Dave Jiang   drivers-edac: add...
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
  				       "[EDAC] SRAM err",
  				       edac_dev);
  		if (res < 0) {
  			printk(KERN_ERR
  			       "%s: Unable to request irq %d for "
  			       "MV64x60 SRAM ERR
  ", __func__, pdata->irq);
  			res = -ENODEV;
  			goto err2;
  		}
  
  		printk(KERN_INFO EDAC_MOD_STR " acquired irq %d for SRAM Err
  ",
  		       pdata->irq);
  	}
  
  	devres_remove_group(&pdev->dev, mv64x60_sram_err_probe);
  
  	/* get this far and it's successful */
956b9ba15   Joe Perches   edac: Convert deb...
385
386
  	edac_dbg(3, "success
  ");
4f4aeeabc   Dave Jiang   drivers-edac: add...
387
388
389
390
391
392
393
394
395
396
397
398
399
400
  
  	return 0;
  
  err2:
  	edac_device_del_device(&pdev->dev);
  err:
  	devres_release_group(&pdev->dev, mv64x60_sram_err_probe);
  	edac_device_free_ctl_info(edac_dev);
  	return res;
  }
  
  static int mv64x60_sram_err_remove(struct platform_device *pdev)
  {
  	struct edac_device_ctl_info *edac_dev = platform_get_drvdata(pdev);
956b9ba15   Joe Perches   edac: Convert deb...
401
402
  	edac_dbg(0, "
  ");
4f4aeeabc   Dave Jiang   drivers-edac: add...
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
  
  	edac_device_del_device(&pdev->dev);
  	edac_device_free_ctl_info(edac_dev);
  
  	return 0;
  }
  
  static struct platform_driver mv64x60_sram_err_driver = {
  	.probe = mv64x60_sram_err_probe,
  	.remove = mv64x60_sram_err_remove,
  	.driver = {
  		   .name = "mv64x60_sram_err",
  	}
  };
  
  /*********************** CPU err device **********************************/
  static void mv64x60_cpu_check(struct edac_device_ctl_info *edac_dev)
  {
  	struct mv64x60_cpu_pdata *pdata = edac_dev->pvt_info;
  	u32 cause;
  
  	cause = in_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_CAUSE) &
  	    MV64x60_CPU_CAUSE_MASK;
  	if (!cause)
  		return;
  
  	printk(KERN_ERR "Error on CPU interface
  ");
  	printk(KERN_ERR "Cause register: 0x%08x
  ", cause);
  	printk(KERN_ERR "Address Low: 0x%08x
  ",
  	       in_le32(pdata->cpu_vbase[0] + MV64x60_CPU_ERR_ADDR_LO));
  	printk(KERN_ERR "Address High: 0x%08x
  ",
  	       in_le32(pdata->cpu_vbase[0] + MV64x60_CPU_ERR_ADDR_HI));
  	printk(KERN_ERR "Data Low: 0x%08x
  ",
  	       in_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_DATA_LO));
  	printk(KERN_ERR "Data High: 0x%08x
  ",
  	       in_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_DATA_HI));
  	printk(KERN_ERR "Parity: 0x%08x
  ",
  	       in_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_PARITY));
  	out_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_CAUSE, 0);
  
  	edac_device_handle_ue(edac_dev, 0, 0, edac_dev->ctl_name);
  }
  
  static irqreturn_t mv64x60_cpu_isr(int irq, void *dev_id)
  {
  	struct edac_device_ctl_info *edac_dev = dev_id;
  	struct mv64x60_cpu_pdata *pdata = edac_dev->pvt_info;
  	u32 cause;
  
  	cause = in_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_CAUSE) &
  	    MV64x60_CPU_CAUSE_MASK;
  	if (!cause)
  		return IRQ_NONE;
  
  	mv64x60_cpu_check(edac_dev);
  
  	return IRQ_HANDLED;
  }
9b3c6e85c   Greg Kroah-Hartman   Drivers: edac: re...
468
  static int mv64x60_cpu_err_probe(struct platform_device *pdev)
4f4aeeabc   Dave Jiang   drivers-edac: add...
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
  {
  	struct edac_device_ctl_info *edac_dev;
  	struct resource *r;
  	struct mv64x60_cpu_pdata *pdata;
  	int res = 0;
  
  	if (!devres_open_group(&pdev->dev, mv64x60_cpu_err_probe, GFP_KERNEL))
  		return -ENOMEM;
  
  	edac_dev = edac_device_alloc_ctl_info(sizeof(*pdata),
  					      "cpu", 1, NULL, 0, 0, NULL, 0,
  					      edac_dev_idx);
  	if (!edac_dev) {
  		devres_release_group(&pdev->dev, mv64x60_cpu_err_probe);
  		return -ENOMEM;
  	}
  
  	pdata = edac_dev->pvt_info;
  	pdata->name = "mv64x60_cpu_err";
4f4aeeabc   Dave Jiang   drivers-edac: add...
488
489
  	edac_dev->dev = &pdev->dev;
  	platform_set_drvdata(pdev, edac_dev);
031d55185   Kay Sievers   edac: struct devi...
490
  	edac_dev->dev_name = dev_name(&pdev->dev);
4f4aeeabc   Dave Jiang   drivers-edac: add...
491
492
493
494
495
496
497
498
499
500
501
502
  
  	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  	if (!r) {
  		printk(KERN_ERR "%s: Unable to get resource for "
  		       "CPU err regs
  ", __func__);
  		res = -ENOENT;
  		goto err;
  	}
  
  	if (!devm_request_mem_region(&pdev->dev,
  				     r->start,
30a61fff3   Julia Lawall   edac: fix resourc...
503
  				     resource_size(r),
4f4aeeabc   Dave Jiang   drivers-edac: add...
504
505
506
507
508
509
510
511
512
513
  				     pdata->name)) {
  		printk(KERN_ERR "%s: Error while requesting mem region
  ",
  		       __func__);
  		res = -EBUSY;
  		goto err;
  	}
  
  	pdata->cpu_vbase[0] = devm_ioremap(&pdev->dev,
  					   r->start,
30a61fff3   Julia Lawall   edac: fix resourc...
514
  					   resource_size(r));
4f4aeeabc   Dave Jiang   drivers-edac: add...
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
  	if (!pdata->cpu_vbase[0]) {
  		printk(KERN_ERR "%s: Unable to setup CPU err regs
  ", __func__);
  		res = -ENOMEM;
  		goto err;
  	}
  
  	r = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  	if (!r) {
  		printk(KERN_ERR "%s: Unable to get resource for "
  		       "CPU err regs
  ", __func__);
  		res = -ENOENT;
  		goto err;
  	}
  
  	if (!devm_request_mem_region(&pdev->dev,
  				     r->start,
30a61fff3   Julia Lawall   edac: fix resourc...
533
  				     resource_size(r),
4f4aeeabc   Dave Jiang   drivers-edac: add...
534
535
536
537
538
539
540
541
542
543
  				     pdata->name)) {
  		printk(KERN_ERR "%s: Error while requesting mem region
  ",
  		       __func__);
  		res = -EBUSY;
  		goto err;
  	}
  
  	pdata->cpu_vbase[1] = devm_ioremap(&pdev->dev,
  					   r->start,
30a61fff3   Julia Lawall   edac: fix resourc...
544
  					   resource_size(r));
4f4aeeabc   Dave Jiang   drivers-edac: add...
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
  	if (!pdata->cpu_vbase[1]) {
  		printk(KERN_ERR "%s: Unable to setup CPU err regs
  ", __func__);
  		res = -ENOMEM;
  		goto err;
  	}
  
  	/* setup CPU err registers */
  	out_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_CAUSE, 0);
  	out_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_MASK, 0);
  	out_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_MASK, 0x000000ff);
  
  	edac_dev->mod_name = EDAC_MOD_STR;
  	edac_dev->ctl_name = pdata->name;
  	if (edac_op_state == EDAC_OPSTATE_POLL)
  		edac_dev->edac_check = mv64x60_cpu_check;
  
  	pdata->edac_idx = edac_dev_idx++;
  
  	if (edac_device_add_device(edac_dev) > 0) {
956b9ba15   Joe Perches   edac: Convert deb...
565
566
  		edac_dbg(3, "failed edac_device_add_device()
  ");
4f4aeeabc   Dave Jiang   drivers-edac: add...
567
568
569
570
571
572
573
574
  		goto err;
  	}
  
  	if (edac_op_state == EDAC_OPSTATE_INT) {
  		pdata->irq = platform_get_irq(pdev, 0);
  		res = devm_request_irq(&pdev->dev,
  				       pdata->irq,
  				       mv64x60_cpu_isr,
5c43cbdf7   Michael Opdenacker   {mv64x60,ppc4xx}_...
575
  				       0,
4f4aeeabc   Dave Jiang   drivers-edac: add...
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
  				       "[EDAC] CPU err",
  				       edac_dev);
  		if (res < 0) {
  			printk(KERN_ERR
  			       "%s: Unable to request irq %d for MV64x60 "
  			       "CPU ERR
  ", __func__, pdata->irq);
  			res = -ENODEV;
  			goto err2;
  		}
  
  		printk(KERN_INFO EDAC_MOD_STR
  		       " acquired irq %d for CPU Err
  ", pdata->irq);
  	}
  
  	devres_remove_group(&pdev->dev, mv64x60_cpu_err_probe);
  
  	/* get this far and it's successful */
956b9ba15   Joe Perches   edac: Convert deb...
595
596
  	edac_dbg(3, "success
  ");
4f4aeeabc   Dave Jiang   drivers-edac: add...
597
598
599
600
601
602
603
604
605
606
607
608
609
610
  
  	return 0;
  
  err2:
  	edac_device_del_device(&pdev->dev);
  err:
  	devres_release_group(&pdev->dev, mv64x60_cpu_err_probe);
  	edac_device_free_ctl_info(edac_dev);
  	return res;
  }
  
  static int mv64x60_cpu_err_remove(struct platform_device *pdev)
  {
  	struct edac_device_ctl_info *edac_dev = platform_get_drvdata(pdev);
956b9ba15   Joe Perches   edac: Convert deb...
611
612
  	edac_dbg(0, "
  ");
4f4aeeabc   Dave Jiang   drivers-edac: add...
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
  
  	edac_device_del_device(&pdev->dev);
  	edac_device_free_ctl_info(edac_dev);
  	return 0;
  }
  
  static struct platform_driver mv64x60_cpu_err_driver = {
  	.probe = mv64x60_cpu_err_probe,
  	.remove = mv64x60_cpu_err_remove,
  	.driver = {
  		   .name = "mv64x60_cpu_err",
  	}
  };
  
  /*********************** DRAM err device **********************************/
  
  static void mv64x60_mc_check(struct mem_ctl_info *mci)
  {
  	struct mv64x60_mc_pdata *pdata = mci->pvt_info;
  	u32 reg;
  	u32 err_addr;
  	u32 sdram_ecc;
  	u32 comp_ecc;
  	u32 syndrome;
  
  	reg = in_le32(pdata->mc_vbase + MV64X60_SDRAM_ERR_ADDR);
  	if (!reg)
  		return;
  
  	err_addr = reg & ~0x3;
  	sdram_ecc = in_le32(pdata->mc_vbase + MV64X60_SDRAM_ERR_ECC_RCVD);
  	comp_ecc = in_le32(pdata->mc_vbase + MV64X60_SDRAM_ERR_ECC_CALC);
  	syndrome = sdram_ecc ^ comp_ecc;
  
  	/* first bit clear in ECC Err Reg, 1 bit error, correctable by HW */
  	if (!(reg & 0x1))
9eb07a7fb   Mauro Carvalho Chehab   edac: edac_mc_han...
649
  		edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1,
a583ac6ca   Mauro Carvalho Chehab   mv64x60_edac: con...
650
651
652
  				     err_addr >> PAGE_SHIFT,
  				     err_addr & PAGE_MASK, syndrome,
  				     0, 0, -1,
03f7eae80   Mauro Carvalho Chehab   edac: remove arch...
653
  				     mci->ctl_name, "");
4f4aeeabc   Dave Jiang   drivers-edac: add...
654
  	else	/* 2 bit error, UE */
9eb07a7fb   Mauro Carvalho Chehab   edac: edac_mc_han...
655
  		edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1,
a583ac6ca   Mauro Carvalho Chehab   mv64x60_edac: con...
656
657
658
  				     err_addr >> PAGE_SHIFT,
  				     err_addr & PAGE_MASK, 0,
  				     0, 0, -1,
03f7eae80   Mauro Carvalho Chehab   edac: remove arch...
659
  				     mci->ctl_name, "");
4f4aeeabc   Dave Jiang   drivers-edac: add...
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
  
  	/* clear the error */
  	out_le32(pdata->mc_vbase + MV64X60_SDRAM_ERR_ADDR, 0);
  }
  
  static irqreturn_t mv64x60_mc_isr(int irq, void *dev_id)
  {
  	struct mem_ctl_info *mci = dev_id;
  	struct mv64x60_mc_pdata *pdata = mci->pvt_info;
  	u32 reg;
  
  	reg = in_le32(pdata->mc_vbase + MV64X60_SDRAM_ERR_ADDR);
  	if (!reg)
  		return IRQ_NONE;
  
  	/* writing 0's to the ECC err addr in check function clears irq */
  	mv64x60_mc_check(mci);
  
  	return IRQ_HANDLED;
  }
  
  static void get_total_mem(struct mv64x60_mc_pdata *pdata)
  {
  	struct device_node *np = NULL;
  	const unsigned int *reg;
  
  	np = of_find_node_by_type(NULL, "memory");
  	if (!np)
  		return;
596d39410   Dave Jiang   edac: mv64x60 fix...
689
  	reg = of_get_property(np, "reg", NULL);
4f4aeeabc   Dave Jiang   drivers-edac: add...
690
691
692
693
694
695
696
697
  
  	pdata->total_mem = reg[1];
  }
  
  static void mv64x60_init_csrows(struct mem_ctl_info *mci,
  				struct mv64x60_mc_pdata *pdata)
  {
  	struct csrow_info *csrow;
084a4fcce   Mauro Carvalho Chehab   edac: move dimm p...
698
  	struct dimm_info *dimm;
4f4aeeabc   Dave Jiang   drivers-edac: add...
699
700
701
702
703
704
  	u32 devtype;
  	u32 ctl;
  
  	get_total_mem(pdata);
  
  	ctl = in_le32(pdata->mc_vbase + MV64X60_SDRAM_CONFIG);
de3910eb7   Mauro Carvalho Chehab   edac: change the ...
705
706
  	csrow = mci->csrows[0];
  	dimm = csrow->channels[0]->dimm;
a895bf8b1   Mauro Carvalho Chehab   edac: move nr_pag...
707
708
  
  	dimm->nr_pages = pdata->total_mem >> PAGE_SHIFT;
084a4fcce   Mauro Carvalho Chehab   edac: move dimm p...
709
  	dimm->grain = 8;
4f4aeeabc   Dave Jiang   drivers-edac: add...
710

084a4fcce   Mauro Carvalho Chehab   edac: move dimm p...
711
  	dimm->mtype = (ctl & MV64X60_SDRAM_REGISTERED) ? MEM_RDDR : MEM_DDR;
4f4aeeabc   Dave Jiang   drivers-edac: add...
712
713
714
715
  
  	devtype = (ctl >> 20) & 0x3;
  	switch (devtype) {
  	case 0x0:
084a4fcce   Mauro Carvalho Chehab   edac: move dimm p...
716
  		dimm->dtype = DEV_X32;
4f4aeeabc   Dave Jiang   drivers-edac: add...
717
718
  		break;
  	case 0x2:		/* could be X8 too, but no way to tell */
084a4fcce   Mauro Carvalho Chehab   edac: move dimm p...
719
  		dimm->dtype = DEV_X16;
4f4aeeabc   Dave Jiang   drivers-edac: add...
720
721
  		break;
  	case 0x3:
084a4fcce   Mauro Carvalho Chehab   edac: move dimm p...
722
  		dimm->dtype = DEV_X4;
4f4aeeabc   Dave Jiang   drivers-edac: add...
723
724
  		break;
  	default:
084a4fcce   Mauro Carvalho Chehab   edac: move dimm p...
725
  		dimm->dtype = DEV_UNKNOWN;
4f4aeeabc   Dave Jiang   drivers-edac: add...
726
727
  		break;
  	}
084a4fcce   Mauro Carvalho Chehab   edac: move dimm p...
728
  	dimm->edac_mode = EDAC_SECDED;
4f4aeeabc   Dave Jiang   drivers-edac: add...
729
  }
9b3c6e85c   Greg Kroah-Hartman   Drivers: edac: re...
730
  static int mv64x60_mc_err_probe(struct platform_device *pdev)
4f4aeeabc   Dave Jiang   drivers-edac: add...
731
732
  {
  	struct mem_ctl_info *mci;
a583ac6ca   Mauro Carvalho Chehab   mv64x60_edac: con...
733
  	struct edac_mc_layer layers[2];
4f4aeeabc   Dave Jiang   drivers-edac: add...
734
735
736
737
738
739
740
  	struct mv64x60_mc_pdata *pdata;
  	struct resource *r;
  	u32 ctl;
  	int res = 0;
  
  	if (!devres_open_group(&pdev->dev, mv64x60_mc_err_probe, GFP_KERNEL))
  		return -ENOMEM;
a583ac6ca   Mauro Carvalho Chehab   mv64x60_edac: con...
741
742
743
744
745
746
  	layers[0].type = EDAC_MC_LAYER_CHIP_SELECT;
  	layers[0].size = 1;
  	layers[0].is_virt_csrow = true;
  	layers[1].type = EDAC_MC_LAYER_CHANNEL;
  	layers[1].size = 1;
  	layers[1].is_virt_csrow = false;
ca0907b9e   Mauro Carvalho Chehab   edac: Remove the ...
747
  	mci = edac_mc_alloc(edac_mc_idx, ARRAY_SIZE(layers), layers,
a583ac6ca   Mauro Carvalho Chehab   mv64x60_edac: con...
748
  			    sizeof(struct mv64x60_mc_pdata));
4f4aeeabc   Dave Jiang   drivers-edac: add...
749
750
751
752
753
754
755
756
  	if (!mci) {
  		printk(KERN_ERR "%s: No memory for CPU err
  ", __func__);
  		devres_release_group(&pdev->dev, mv64x60_mc_err_probe);
  		return -ENOMEM;
  	}
  
  	pdata = mci->pvt_info;
fd687502d   Mauro Carvalho Chehab   edac: Rename the ...
757
  	mci->pdev = &pdev->dev;
4f4aeeabc   Dave Jiang   drivers-edac: add...
758
759
  	platform_set_drvdata(pdev, mci);
  	pdata->name = "mv64x60_mc_err";
031d55185   Kay Sievers   edac: struct devi...
760
  	mci->dev_name = dev_name(&pdev->dev);
4f4aeeabc   Dave Jiang   drivers-edac: add...
761
762
763
764
765
766
767
768
769
770
771
772
773
  	pdata->edac_idx = edac_mc_idx++;
  
  	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  	if (!r) {
  		printk(KERN_ERR "%s: Unable to get resource for "
  		       "MC err regs
  ", __func__);
  		res = -ENOENT;
  		goto err;
  	}
  
  	if (!devm_request_mem_region(&pdev->dev,
  				     r->start,
30a61fff3   Julia Lawall   edac: fix resourc...
774
  				     resource_size(r),
4f4aeeabc   Dave Jiang   drivers-edac: add...
775
776
777
778
779
780
781
782
783
784
  				     pdata->name)) {
  		printk(KERN_ERR "%s: Error while requesting mem region
  ",
  		       __func__);
  		res = -EBUSY;
  		goto err;
  	}
  
  	pdata->mc_vbase = devm_ioremap(&pdev->dev,
  				       r->start,
30a61fff3   Julia Lawall   edac: fix resourc...
785
  				       resource_size(r));
4f4aeeabc   Dave Jiang   drivers-edac: add...
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
  	if (!pdata->mc_vbase) {
  		printk(KERN_ERR "%s: Unable to setup MC err regs
  ", __func__);
  		res = -ENOMEM;
  		goto err;
  	}
  
  	ctl = in_le32(pdata->mc_vbase + MV64X60_SDRAM_CONFIG);
  	if (!(ctl & MV64X60_SDRAM_ECC)) {
  		/* Non-ECC RAM? */
  		printk(KERN_WARNING "%s: No ECC DIMMs discovered
  ", __func__);
  		res = -ENODEV;
  		goto err2;
  	}
956b9ba15   Joe Perches   edac: Convert deb...
801
802
  	edac_dbg(3, "init mci
  ");
4f4aeeabc   Dave Jiang   drivers-edac: add...
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
  	mci->mtype_cap = MEM_FLAG_RDDR | MEM_FLAG_DDR;
  	mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED;
  	mci->edac_cap = EDAC_FLAG_SECDED;
  	mci->mod_name = EDAC_MOD_STR;
  	mci->mod_ver = MV64x60_REVISION;
  	mci->ctl_name = mv64x60_ctl_name;
  
  	if (edac_op_state == EDAC_OPSTATE_POLL)
  		mci->edac_check = mv64x60_mc_check;
  
  	mci->ctl_page_to_phys = NULL;
  
  	mci->scrub_mode = SCRUB_SW_SRC;
  
  	mv64x60_init_csrows(mci, pdata);
  
  	/* setup MC registers */
  	out_le32(pdata->mc_vbase + MV64X60_SDRAM_ERR_ADDR, 0);
  	ctl = in_le32(pdata->mc_vbase + MV64X60_SDRAM_ERR_ECC_CNTL);
  	ctl = (ctl & 0xff00ffff) | 0x10000;
  	out_le32(pdata->mc_vbase + MV64X60_SDRAM_ERR_ECC_CNTL, ctl);
30263b405   Dan Carpenter   EDAC, mv64x60_eda...
824
825
  	res = edac_mc_add_mc(mci);
  	if (res) {
956b9ba15   Joe Perches   edac: Convert deb...
826
827
  		edac_dbg(3, "failed edac_mc_add_mc()
  ");
4f4aeeabc   Dave Jiang   drivers-edac: add...
828
829
830
831
832
833
834
835
836
  		goto err;
  	}
  
  	if (edac_op_state == EDAC_OPSTATE_INT) {
  		/* acquire interrupt that reports errors */
  		pdata->irq = platform_get_irq(pdev, 0);
  		res = devm_request_irq(&pdev->dev,
  				       pdata->irq,
  				       mv64x60_mc_isr,
5c43cbdf7   Michael Opdenacker   {mv64x60,ppc4xx}_...
837
  				       0,
4f4aeeabc   Dave Jiang   drivers-edac: add...
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
  				       "[EDAC] MC err",
  				       mci);
  		if (res < 0) {
  			printk(KERN_ERR "%s: Unable to request irq %d for "
  			       "MV64x60 DRAM ERR
  ", __func__, pdata->irq);
  			res = -ENODEV;
  			goto err2;
  		}
  
  		printk(KERN_INFO EDAC_MOD_STR " acquired irq %d for MC Err
  ",
  		       pdata->irq);
  	}
  
  	/* get this far and it's successful */
956b9ba15   Joe Perches   edac: Convert deb...
854
855
  	edac_dbg(3, "success
  ");
4f4aeeabc   Dave Jiang   drivers-edac: add...
856
857
858
859
860
861
862
863
864
865
866
867
868
869
  
  	return 0;
  
  err2:
  	edac_mc_del_mc(&pdev->dev);
  err:
  	devres_release_group(&pdev->dev, mv64x60_mc_err_probe);
  	edac_mc_free(mci);
  	return res;
  }
  
  static int mv64x60_mc_err_remove(struct platform_device *pdev)
  {
  	struct mem_ctl_info *mci = platform_get_drvdata(pdev);
956b9ba15   Joe Perches   edac: Convert deb...
870
871
  	edac_dbg(0, "
  ");
4f4aeeabc   Dave Jiang   drivers-edac: add...
872
873
874
875
876
877
878
879
880
881
882
883
884
  
  	edac_mc_del_mc(&pdev->dev);
  	edac_mc_free(mci);
  	return 0;
  }
  
  static struct platform_driver mv64x60_mc_err_driver = {
  	.probe = mv64x60_mc_err_probe,
  	.remove = mv64x60_mc_err_remove,
  	.driver = {
  		   .name = "mv64x60_mc_err",
  	}
  };
768ce42cc   Thierry Reding   EDAC, mv64x60: Us...
885
886
887
888
889
890
891
892
  static struct platform_driver * const drivers[] = {
  	&mv64x60_mc_err_driver,
  	&mv64x60_cpu_err_driver,
  	&mv64x60_sram_err_driver,
  #ifdef CONFIG_PCI
  	&mv64x60_pci_err_driver,
  #endif
  };
4f4aeeabc   Dave Jiang   drivers-edac: add...
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
  static int __init mv64x60_edac_init(void)
  {
  	int ret = 0;
  
  	printk(KERN_INFO "Marvell MV64x60 EDAC driver " MV64x60_REVISION "
  ");
  	printk(KERN_INFO "\t(C) 2006-2007 MontaVista Software
  ");
  	/* make sure error reporting method is sane */
  	switch (edac_op_state) {
  	case EDAC_OPSTATE_POLL:
  	case EDAC_OPSTATE_INT:
  		break;
  	default:
  		edac_op_state = EDAC_OPSTATE_INT;
  		break;
  	}
768ce42cc   Thierry Reding   EDAC, mv64x60: Us...
910
  	return platform_register_drivers(drivers, ARRAY_SIZE(drivers));
4f4aeeabc   Dave Jiang   drivers-edac: add...
911
912
913
914
915
  }
  module_init(mv64x60_edac_init);
  
  static void __exit mv64x60_edac_exit(void)
  {
768ce42cc   Thierry Reding   EDAC, mv64x60: Us...
916
  	platform_unregister_drivers(drivers, ARRAY_SIZE(drivers));
4f4aeeabc   Dave Jiang   drivers-edac: add...
917
918
919
920
921
922
923
924
  }
  module_exit(mv64x60_edac_exit);
  
  MODULE_LICENSE("GPL");
  MODULE_AUTHOR("Montavista Software, Inc.");
  module_param(edac_op_state, int, 0444);
  MODULE_PARM_DESC(edac_op_state,
  		 "EDAC Error Reporting state: 0=Poll, 2=Interrupt");