blob: 243e9aacad69dd28cbcbf58893670f2ac9856bce [file] [log] [blame]
Alan Cox806c35f2006-01-18 17:44:08 -08001/*
2 * Intel e752x Memory Controller kernel module
3 * (C) 2004 Linux Networx (http://lnxi.com)
4 * This file may be distributed under the terms of the
5 * GNU General Public License.
6 *
7 * See "enum e752x_chips" below for supported chipsets
8 *
9 * Written by Tom Zimmerman
10 *
11 * Contributors:
12 * Thayne Harbaugh at realmsys.com (?)
13 * Wang Zhenyu at intel.com
14 * Dave Jiang at mvista.com
15 *
Alan Coxda9bb1d2006-01-18 17:44:13 -080016 * $Id: edac_e752x.c,v 1.5.2.11 2005/10/05 00:43:44 dsp_llnl Exp $
Alan Cox806c35f2006-01-18 17:44:08 -080017 *
18 */
19
Alan Cox806c35f2006-01-18 17:44:08 -080020#include <linux/module.h>
21#include <linux/init.h>
Alan Cox806c35f2006-01-18 17:44:08 -080022#include <linux/pci.h>
23#include <linux/pci_ids.h>
Alan Cox806c35f2006-01-18 17:44:08 -080024#include <linux/slab.h>
Dave Jiangc0d12172007-07-19 01:49:46 -070025#include <linux/edac.h>
Douglas Thompson20bcb7a2007-07-19 01:49:47 -070026#include "edac_core.h"
Alan Cox806c35f2006-01-18 17:44:08 -080027
Douglas Thompson20bcb7a2007-07-19 01:49:47 -070028#define E752X_REVISION " Ver: 2.0.2 " __DATE__
Doug Thompson929a40e2006-07-01 04:35:45 -070029#define EDAC_MOD_STR "e752x_edac"
Doug Thompson37f04582006-06-30 01:56:07 -070030
Doug Thompson10d33e92008-07-25 01:49:12 -070031static int report_non_memory_errors;
mark gross96941022006-05-03 19:55:07 -070032static int force_function_unhide;
Peter Tyser94ee1cf2008-04-29 01:03:15 -070033static int sysbus_parity = -1;
mark gross96941022006-05-03 19:55:07 -070034
Dave Jiang91b99042007-07-19 01:49:52 -070035static struct edac_pci_ctl_info *e752x_pci;
36
Dave Peterson537fba22006-03-26 01:38:40 -080037#define e752x_printk(level, fmt, arg...) \
Dave Petersone7ecd892006-03-26 01:38:52 -080038 edac_printk(level, "e752x", fmt, ##arg)
Dave Peterson537fba22006-03-26 01:38:40 -080039
40#define e752x_mc_printk(mci, level, fmt, arg...) \
Dave Petersone7ecd892006-03-26 01:38:52 -080041 edac_mc_chipset_printk(mci, level, "e752x", fmt, ##arg)
Dave Peterson537fba22006-03-26 01:38:40 -080042
Alan Cox806c35f2006-01-18 17:44:08 -080043#ifndef PCI_DEVICE_ID_INTEL_7520_0
44#define PCI_DEVICE_ID_INTEL_7520_0 0x3590
45#endif /* PCI_DEVICE_ID_INTEL_7520_0 */
46
47#ifndef PCI_DEVICE_ID_INTEL_7520_1_ERR
48#define PCI_DEVICE_ID_INTEL_7520_1_ERR 0x3591
49#endif /* PCI_DEVICE_ID_INTEL_7520_1_ERR */
50
51#ifndef PCI_DEVICE_ID_INTEL_7525_0
52#define PCI_DEVICE_ID_INTEL_7525_0 0x359E
53#endif /* PCI_DEVICE_ID_INTEL_7525_0 */
54
55#ifndef PCI_DEVICE_ID_INTEL_7525_1_ERR
56#define PCI_DEVICE_ID_INTEL_7525_1_ERR 0x3593
57#endif /* PCI_DEVICE_ID_INTEL_7525_1_ERR */
58
59#ifndef PCI_DEVICE_ID_INTEL_7320_0
60#define PCI_DEVICE_ID_INTEL_7320_0 0x3592
61#endif /* PCI_DEVICE_ID_INTEL_7320_0 */
62
63#ifndef PCI_DEVICE_ID_INTEL_7320_1_ERR
64#define PCI_DEVICE_ID_INTEL_7320_1_ERR 0x3593
65#endif /* PCI_DEVICE_ID_INTEL_7320_1_ERR */
66
Andrei Konovalov5135b792008-04-29 01:03:13 -070067#ifndef PCI_DEVICE_ID_INTEL_3100_0
68#define PCI_DEVICE_ID_INTEL_3100_0 0x35B0
69#endif /* PCI_DEVICE_ID_INTEL_3100_0 */
70
71#ifndef PCI_DEVICE_ID_INTEL_3100_1_ERR
72#define PCI_DEVICE_ID_INTEL_3100_1_ERR 0x35B1
73#endif /* PCI_DEVICE_ID_INTEL_3100_1_ERR */
74
Alan Cox806c35f2006-01-18 17:44:08 -080075#define E752X_NR_CSROWS 8 /* number of csrows */
76
Alan Cox806c35f2006-01-18 17:44:08 -080077/* E752X register addresses - device 0 function 0 */
Peter Tyser8004fd22010-03-10 15:23:15 -080078#define E752X_MCHSCRB 0x52 /* Memory Scrub register (16b) */
79 /*
80 * 6:5 Scrub Completion Count
81 * 3:2 Scrub Rate (i3100 only)
82 * 01=fast 10=normal
83 * 1:0 Scrub Mode enable
84 * 00=off 10=on
85 */
Alan Cox806c35f2006-01-18 17:44:08 -080086#define E752X_DRB 0x60 /* DRAM row boundary register (8b) */
87#define E752X_DRA 0x70 /* DRAM row attribute register (8b) */
88 /*
89 * 31:30 Device width row 7
90 * 01=x8 10=x4 11=x8 DDR2
91 * 27:26 Device width row 6
92 * 23:22 Device width row 5
93 * 19:20 Device width row 4
94 * 15:14 Device width row 3
95 * 11:10 Device width row 2
96 * 7:6 Device width row 1
97 * 3:2 Device width row 0
98 */
99#define E752X_DRC 0x7C /* DRAM controller mode reg (32b) */
100 /* FIXME:IS THIS RIGHT? */
101 /*
102 * 22 Number channels 0=1,1=2
103 * 19:18 DRB Granularity 32/64MB
104 */
105#define E752X_DRM 0x80 /* Dimm mapping register */
106#define E752X_DDRCSR 0x9A /* DDR control and status reg (16b) */
107 /*
108 * 14:12 1 single A, 2 single B, 3 dual
109 */
110#define E752X_TOLM 0xC4 /* DRAM top of low memory reg (16b) */
111#define E752X_REMAPBASE 0xC6 /* DRAM remap base address reg (16b) */
112#define E752X_REMAPLIMIT 0xC8 /* DRAM remap limit address reg (16b) */
113#define E752X_REMAPOFFSET 0xCA /* DRAM remap limit offset reg (16b) */
114
115/* E752X register addresses - device 0 function 1 */
116#define E752X_FERR_GLOBAL 0x40 /* Global first error register (32b) */
117#define E752X_NERR_GLOBAL 0x44 /* Global next error register (32b) */
118#define E752X_HI_FERR 0x50 /* Hub interface first error reg (8b) */
119#define E752X_HI_NERR 0x52 /* Hub interface next error reg (8b) */
120#define E752X_HI_ERRMASK 0x54 /* Hub interface error mask reg (8b) */
121#define E752X_HI_SMICMD 0x5A /* Hub interface SMI command reg (8b) */
122#define E752X_SYSBUS_FERR 0x60 /* System buss first error reg (16b) */
123#define E752X_SYSBUS_NERR 0x62 /* System buss next error reg (16b) */
124#define E752X_SYSBUS_ERRMASK 0x64 /* System buss error mask reg (16b) */
125#define E752X_SYSBUS_SMICMD 0x6A /* System buss SMI command reg (16b) */
126#define E752X_BUF_FERR 0x70 /* Memory buffer first error reg (8b) */
127#define E752X_BUF_NERR 0x72 /* Memory buffer next error reg (8b) */
128#define E752X_BUF_ERRMASK 0x74 /* Memory buffer error mask reg (8b) */
Doug Thompson10d33e92008-07-25 01:49:12 -0700129#define E752X_BUF_SMICMD 0x7A /* Memory buffer SMI cmd reg (8b) */
Alan Cox806c35f2006-01-18 17:44:08 -0800130#define E752X_DRAM_FERR 0x80 /* DRAM first error register (16b) */
131#define E752X_DRAM_NERR 0x82 /* DRAM next error register (16b) */
132#define E752X_DRAM_ERRMASK 0x84 /* DRAM error mask register (8b) */
133#define E752X_DRAM_SMICMD 0x8A /* DRAM SMI command register (8b) */
134#define E752X_DRAM_RETR_ADD 0xAC /* DRAM Retry address register (32b) */
135#define E752X_DRAM_SEC1_ADD 0xA0 /* DRAM first correctable memory */
136 /* error address register (32b) */
137 /*
138 * 31 Reserved
Doug Thompson10d33e92008-07-25 01:49:12 -0700139 * 30:2 CE address (64 byte block 34:6
Alan Cox806c35f2006-01-18 17:44:08 -0800140 * 1 Reserved
141 * 0 HiLoCS
142 */
143#define E752X_DRAM_SEC2_ADD 0xC8 /* DRAM first correctable memory */
144 /* error address register (32b) */
145 /*
146 * 31 Reserved
147 * 30:2 CE address (64 byte block 34:6)
148 * 1 Reserved
149 * 0 HiLoCS
150 */
151#define E752X_DRAM_DED_ADD 0xA4 /* DRAM first uncorrectable memory */
152 /* error address register (32b) */
153 /*
154 * 31 Reserved
155 * 30:2 CE address (64 byte block 34:6)
156 * 1 Reserved
157 * 0 HiLoCS
158 */
Doug Thompson10d33e92008-07-25 01:49:12 -0700159#define E752X_DRAM_SCRB_ADD 0xA8 /* DRAM 1st uncorrectable scrub mem */
Alan Cox806c35f2006-01-18 17:44:08 -0800160 /* error address register (32b) */
161 /*
162 * 31 Reserved
Doug Thompson10d33e92008-07-25 01:49:12 -0700163 * 30:2 CE address (64 byte block 34:6
Alan Cox806c35f2006-01-18 17:44:08 -0800164 * 1 Reserved
165 * 0 HiLoCS
166 */
167#define E752X_DRAM_SEC1_SYNDROME 0xC4 /* DRAM first correctable memory */
168 /* error syndrome register (16b) */
169#define E752X_DRAM_SEC2_SYNDROME 0xC6 /* DRAM second correctable memory */
170 /* error syndrome register (16b) */
171#define E752X_DEVPRES1 0xF4 /* Device Present 1 register (8b) */
172
Andrei Konovalov5135b792008-04-29 01:03:13 -0700173/* 3100 IMCH specific register addresses - device 0 function 1 */
174#define I3100_NSI_FERR 0x48 /* NSI first error reg (32b) */
175#define I3100_NSI_NERR 0x4C /* NSI next error reg (32b) */
176#define I3100_NSI_SMICMD 0x54 /* NSI SMI command register (32b) */
177#define I3100_NSI_EMASK 0x90 /* NSI error mask register (32b) */
178
Alan Cox806c35f2006-01-18 17:44:08 -0800179/* ICH5R register addresses - device 30 function 0 */
180#define ICH5R_PCI_STAT 0x06 /* PCI status register (16b) */
181#define ICH5R_PCI_2ND_STAT 0x1E /* PCI status secondary reg (16b) */
182#define ICH5R_PCI_BRIDGE_CTL 0x3E /* PCI bridge control register (16b) */
183
184enum e752x_chips {
185 E7520 = 0,
186 E7525 = 1,
Andrei Konovalov5135b792008-04-29 01:03:13 -0700187 E7320 = 2,
188 I3100 = 3
Alan Cox806c35f2006-01-18 17:44:08 -0800189};
190
Alan Cox806c35f2006-01-18 17:44:08 -0800191struct e752x_pvt {
192 struct pci_dev *bridge_ck;
193 struct pci_dev *dev_d0f0;
194 struct pci_dev *dev_d0f1;
195 u32 tolm;
196 u32 remapbase;
197 u32 remaplimit;
198 int mc_symmetric;
199 u8 map[8];
200 int map_type;
201 const struct e752x_dev_info *dev_info;
202};
203
Alan Cox806c35f2006-01-18 17:44:08 -0800204struct e752x_dev_info {
205 u16 err_dev;
Dave Peterson3847bccc2006-03-26 01:38:42 -0800206 u16 ctl_dev;
Alan Cox806c35f2006-01-18 17:44:08 -0800207 const char *ctl_name;
208};
209
210struct e752x_error_info {
211 u32 ferr_global;
212 u32 nerr_global;
Andrei Konovalov5135b792008-04-29 01:03:13 -0700213 u32 nsi_ferr; /* 3100 only */
214 u32 nsi_nerr; /* 3100 only */
215 u8 hi_ferr; /* all but 3100 */
216 u8 hi_nerr; /* all but 3100 */
Alan Cox806c35f2006-01-18 17:44:08 -0800217 u16 sysbus_ferr;
218 u16 sysbus_nerr;
219 u8 buf_ferr;
220 u8 buf_nerr;
221 u16 dram_ferr;
222 u16 dram_nerr;
223 u32 dram_sec1_add;
224 u32 dram_sec2_add;
225 u16 dram_sec1_syndrome;
226 u16 dram_sec2_syndrome;
227 u32 dram_ded_add;
228 u32 dram_scrb_add;
229 u32 dram_retr_add;
230};
231
232static const struct e752x_dev_info e752x_devs[] = {
233 [E7520] = {
Douglas Thompson052dfb42007-07-19 01:50:13 -0700234 .err_dev = PCI_DEVICE_ID_INTEL_7520_1_ERR,
235 .ctl_dev = PCI_DEVICE_ID_INTEL_7520_0,
236 .ctl_name = "E7520"},
Alan Cox806c35f2006-01-18 17:44:08 -0800237 [E7525] = {
Douglas Thompson052dfb42007-07-19 01:50:13 -0700238 .err_dev = PCI_DEVICE_ID_INTEL_7525_1_ERR,
239 .ctl_dev = PCI_DEVICE_ID_INTEL_7525_0,
240 .ctl_name = "E7525"},
Alan Cox806c35f2006-01-18 17:44:08 -0800241 [E7320] = {
Douglas Thompson052dfb42007-07-19 01:50:13 -0700242 .err_dev = PCI_DEVICE_ID_INTEL_7320_1_ERR,
243 .ctl_dev = PCI_DEVICE_ID_INTEL_7320_0,
244 .ctl_name = "E7320"},
Andrei Konovalov5135b792008-04-29 01:03:13 -0700245 [I3100] = {
246 .err_dev = PCI_DEVICE_ID_INTEL_3100_1_ERR,
247 .ctl_dev = PCI_DEVICE_ID_INTEL_3100_0,
248 .ctl_name = "3100"},
Alan Cox806c35f2006-01-18 17:44:08 -0800249};
250
Peter Tyser8004fd22010-03-10 15:23:15 -0800251/* Valid scrub rates for the e752x/3100 hardware memory scrubber. We
252 * map the scrubbing bandwidth to a hardware register value. The 'set'
253 * operation finds the 'matching or higher value'. Note that scrubbing
254 * on the e752x can only be enabled/disabled. The 3100 supports
255 * a normal and fast mode.
256 */
257
258#define SDRATE_EOT 0xFFFFFFFF
259
260struct scrubrate {
261 u32 bandwidth; /* bandwidth consumed by scrubbing in bytes/sec */
262 u16 scrubval; /* register value for scrub rate */
263};
264
265/* Rate below assumes same performance as i3100 using PC3200 DDR2 in
266 * normal mode. e752x bridges don't support choosing normal or fast mode,
267 * so the scrubbing bandwidth value isn't all that important - scrubbing is
268 * either on or off.
269 */
270static const struct scrubrate scrubrates_e752x[] = {
271 {0, 0x00}, /* Scrubbing Off */
272 {500000, 0x02}, /* Scrubbing On */
273 {SDRATE_EOT, 0x00} /* End of Table */
274};
275
276/* Fast mode: 2 GByte PC3200 DDR2 scrubbed in 33s = 63161283 bytes/s
277 * Normal mode: 125 (32000 / 256) times slower than fast mode.
278 */
279static const struct scrubrate scrubrates_i3100[] = {
280 {0, 0x00}, /* Scrubbing Off */
281 {500000, 0x0a}, /* Normal mode - 32k clocks */
282 {62500000, 0x06}, /* Fast mode - 256 clocks */
283 {SDRATE_EOT, 0x00} /* End of Table */
284};
285
Alan Cox806c35f2006-01-18 17:44:08 -0800286static unsigned long ctl_page_to_phys(struct mem_ctl_info *mci,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700287 unsigned long page)
Alan Cox806c35f2006-01-18 17:44:08 -0800288{
289 u32 remap;
Dave Jiang203333c2007-07-19 01:50:06 -0700290 struct e752x_pvt *pvt = (struct e752x_pvt *)mci->pvt_info;
Alan Cox806c35f2006-01-18 17:44:08 -0800291
Dave Peterson537fba22006-03-26 01:38:40 -0800292 debugf3("%s()\n", __func__);
Alan Cox806c35f2006-01-18 17:44:08 -0800293
294 if (page < pvt->tolm)
295 return page;
Dave Petersone7ecd892006-03-26 01:38:52 -0800296
Alan Cox806c35f2006-01-18 17:44:08 -0800297 if ((page >= 0x100000) && (page < pvt->remapbase))
298 return page;
Dave Petersone7ecd892006-03-26 01:38:52 -0800299
Alan Cox806c35f2006-01-18 17:44:08 -0800300 remap = (page - pvt->tolm) + pvt->remapbase;
Dave Petersone7ecd892006-03-26 01:38:52 -0800301
Alan Cox806c35f2006-01-18 17:44:08 -0800302 if (remap < pvt->remaplimit)
303 return remap;
Dave Petersone7ecd892006-03-26 01:38:52 -0800304
Dave Peterson537fba22006-03-26 01:38:40 -0800305 e752x_printk(KERN_ERR, "Invalid page %lx - out of range\n", page);
Alan Cox806c35f2006-01-18 17:44:08 -0800306 return pvt->tolm - 1;
307}
308
309static void do_process_ce(struct mem_ctl_info *mci, u16 error_one,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700310 u32 sec1_add, u16 sec1_syndrome)
Alan Cox806c35f2006-01-18 17:44:08 -0800311{
312 u32 page;
313 int row;
314 int channel;
315 int i;
Dave Jiang203333c2007-07-19 01:50:06 -0700316 struct e752x_pvt *pvt = (struct e752x_pvt *)mci->pvt_info;
Alan Cox806c35f2006-01-18 17:44:08 -0800317
Dave Peterson537fba22006-03-26 01:38:40 -0800318 debugf3("%s()\n", __func__);
Alan Cox806c35f2006-01-18 17:44:08 -0800319
320 /* convert the addr to 4k page */
321 page = sec1_add >> (PAGE_SHIFT - 4);
322
323 /* FIXME - check for -1 */
324 if (pvt->mc_symmetric) {
325 /* chip select are bits 14 & 13 */
326 row = ((page >> 1) & 3);
Dave Peterson537fba22006-03-26 01:38:40 -0800327 e752x_printk(KERN_WARNING,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700328 "Test row %d Table %d %d %d %d %d %d %d %d\n", row,
329 pvt->map[0], pvt->map[1], pvt->map[2], pvt->map[3],
330 pvt->map[4], pvt->map[5], pvt->map[6],
331 pvt->map[7]);
Alan Cox806c35f2006-01-18 17:44:08 -0800332
333 /* test for channel remapping */
334 for (i = 0; i < 8; i++) {
335 if (pvt->map[i] == row)
336 break;
337 }
Dave Petersone7ecd892006-03-26 01:38:52 -0800338
Dave Peterson537fba22006-03-26 01:38:40 -0800339 e752x_printk(KERN_WARNING, "Test computed row %d\n", i);
Dave Petersone7ecd892006-03-26 01:38:52 -0800340
Alan Cox806c35f2006-01-18 17:44:08 -0800341 if (i < 8)
342 row = i;
343 else
Dave Peterson537fba22006-03-26 01:38:40 -0800344 e752x_mc_printk(mci, KERN_WARNING,
Dave Jiang203333c2007-07-19 01:50:06 -0700345 "row %d not found in remap table\n",
346 row);
Alan Cox806c35f2006-01-18 17:44:08 -0800347 } else
348 row = edac_mc_find_csrow_by_page(mci, page);
Dave Petersone7ecd892006-03-26 01:38:52 -0800349
Alan Cox806c35f2006-01-18 17:44:08 -0800350 /* 0 = channel A, 1 = channel B */
351 channel = !(error_one & 1);
352
Mike Chan84db0032007-02-12 00:53:06 -0800353 /* e752x mc reads 34:6 of the DRAM linear address */
354 edac_mc_handle_ce(mci, page, offset_in_page(sec1_add << 4),
Douglas Thompson052dfb42007-07-19 01:50:13 -0700355 sec1_syndrome, row, channel, "e752x CE");
Dave Petersone7ecd892006-03-26 01:38:52 -0800356}
Alan Cox806c35f2006-01-18 17:44:08 -0800357
358static inline void process_ce(struct mem_ctl_info *mci, u16 error_one,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700359 u32 sec1_add, u16 sec1_syndrome, int *error_found,
360 int handle_error)
Alan Cox806c35f2006-01-18 17:44:08 -0800361{
362 *error_found = 1;
363
364 if (handle_error)
365 do_process_ce(mci, error_one, sec1_add, sec1_syndrome);
366}
367
Dave Petersone7ecd892006-03-26 01:38:52 -0800368static void do_process_ue(struct mem_ctl_info *mci, u16 error_one,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700369 u32 ded_add, u32 scrb_add)
Alan Cox806c35f2006-01-18 17:44:08 -0800370{
371 u32 error_2b, block_page;
372 int row;
Dave Jiang203333c2007-07-19 01:50:06 -0700373 struct e752x_pvt *pvt = (struct e752x_pvt *)mci->pvt_info;
Alan Cox806c35f2006-01-18 17:44:08 -0800374
Dave Peterson537fba22006-03-26 01:38:40 -0800375 debugf3("%s()\n", __func__);
Alan Cox806c35f2006-01-18 17:44:08 -0800376
377 if (error_one & 0x0202) {
378 error_2b = ded_add;
Dave Petersone7ecd892006-03-26 01:38:52 -0800379
Alan Cox806c35f2006-01-18 17:44:08 -0800380 /* convert to 4k address */
381 block_page = error_2b >> (PAGE_SHIFT - 4);
Dave Petersone7ecd892006-03-26 01:38:52 -0800382
Alan Cox806c35f2006-01-18 17:44:08 -0800383 row = pvt->mc_symmetric ?
Douglas Thompson052dfb42007-07-19 01:50:13 -0700384 /* chip select are bits 14 & 13 */
385 ((block_page >> 1) & 3) :
386 edac_mc_find_csrow_by_page(mci, block_page);
Dave Petersone7ecd892006-03-26 01:38:52 -0800387
Mike Chan84db0032007-02-12 00:53:06 -0800388 /* e752x mc reads 34:6 of the DRAM linear address */
389 edac_mc_handle_ue(mci, block_page,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700390 offset_in_page(error_2b << 4),
391 row, "e752x UE from Read");
Alan Cox806c35f2006-01-18 17:44:08 -0800392 }
393 if (error_one & 0x0404) {
394 error_2b = scrb_add;
Dave Petersone7ecd892006-03-26 01:38:52 -0800395
Alan Cox806c35f2006-01-18 17:44:08 -0800396 /* convert to 4k address */
397 block_page = error_2b >> (PAGE_SHIFT - 4);
Dave Petersone7ecd892006-03-26 01:38:52 -0800398
Alan Cox806c35f2006-01-18 17:44:08 -0800399 row = pvt->mc_symmetric ?
Douglas Thompson052dfb42007-07-19 01:50:13 -0700400 /* chip select are bits 14 & 13 */
401 ((block_page >> 1) & 3) :
402 edac_mc_find_csrow_by_page(mci, block_page);
Dave Petersone7ecd892006-03-26 01:38:52 -0800403
Mike Chan84db0032007-02-12 00:53:06 -0800404 /* e752x mc reads 34:6 of the DRAM linear address */
405 edac_mc_handle_ue(mci, block_page,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700406 offset_in_page(error_2b << 4),
407 row, "e752x UE from Scruber");
Alan Cox806c35f2006-01-18 17:44:08 -0800408 }
409}
410
411static inline void process_ue(struct mem_ctl_info *mci, u16 error_one,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700412 u32 ded_add, u32 scrb_add, int *error_found,
413 int handle_error)
Alan Cox806c35f2006-01-18 17:44:08 -0800414{
415 *error_found = 1;
416
417 if (handle_error)
418 do_process_ue(mci, error_one, ded_add, scrb_add);
419}
420
421static inline void process_ue_no_info_wr(struct mem_ctl_info *mci,
Dave Jiang203333c2007-07-19 01:50:06 -0700422 int *error_found, int handle_error)
Alan Cox806c35f2006-01-18 17:44:08 -0800423{
424 *error_found = 1;
425
426 if (!handle_error)
427 return;
428
Dave Peterson537fba22006-03-26 01:38:40 -0800429 debugf3("%s()\n", __func__);
Alan Cox806c35f2006-01-18 17:44:08 -0800430 edac_mc_handle_ue_no_info(mci, "e752x UE log memory write");
431}
432
433static void do_process_ded_retry(struct mem_ctl_info *mci, u16 error,
Dave Jiang203333c2007-07-19 01:50:06 -0700434 u32 retry_add)
Alan Cox806c35f2006-01-18 17:44:08 -0800435{
436 u32 error_1b, page;
437 int row;
Dave Jiang203333c2007-07-19 01:50:06 -0700438 struct e752x_pvt *pvt = (struct e752x_pvt *)mci->pvt_info;
Alan Cox806c35f2006-01-18 17:44:08 -0800439
440 error_1b = retry_add;
Doug Thompson10d33e92008-07-25 01:49:12 -0700441 page = error_1b >> (PAGE_SHIFT - 4); /* convert the addr to 4k page */
442
443 /* chip select are bits 14 & 13 */
444 row = pvt->mc_symmetric ? ((page >> 1) & 3) :
Douglas Thompson052dfb42007-07-19 01:50:13 -0700445 edac_mc_find_csrow_by_page(mci, page);
Doug Thompson10d33e92008-07-25 01:49:12 -0700446
Dave Peterson537fba22006-03-26 01:38:40 -0800447 e752x_mc_printk(mci, KERN_WARNING,
Dave Jiang203333c2007-07-19 01:50:06 -0700448 "CE page 0x%lx, row %d : Memory read retry\n",
449 (long unsigned int)page, row);
Alan Cox806c35f2006-01-18 17:44:08 -0800450}
451
452static inline void process_ded_retry(struct mem_ctl_info *mci, u16 error,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700453 u32 retry_add, int *error_found,
454 int handle_error)
Alan Cox806c35f2006-01-18 17:44:08 -0800455{
456 *error_found = 1;
457
458 if (handle_error)
459 do_process_ded_retry(mci, error, retry_add);
460}
461
462static inline void process_threshold_ce(struct mem_ctl_info *mci, u16 error,
Dave Jiang203333c2007-07-19 01:50:06 -0700463 int *error_found, int handle_error)
Alan Cox806c35f2006-01-18 17:44:08 -0800464{
465 *error_found = 1;
466
467 if (handle_error)
Dave Peterson537fba22006-03-26 01:38:40 -0800468 e752x_mc_printk(mci, KERN_WARNING, "Memory threshold CE\n");
Alan Cox806c35f2006-01-18 17:44:08 -0800469}
470
Alan Coxda9bb1d2006-01-18 17:44:13 -0800471static char *global_message[11] = {
Doug Thompson10d33e92008-07-25 01:49:12 -0700472 "PCI Express C1",
473 "PCI Express C",
474 "PCI Express B1",
475 "PCI Express B",
476 "PCI Express A1",
477 "PCI Express A",
478 "DMA Controller",
479 "HUB or NS Interface",
480 "System Bus",
481 "DRAM Controller", /* 9th entry */
482 "Internal Buffer"
Alan Cox806c35f2006-01-18 17:44:08 -0800483};
484
Doug Thompson10d33e92008-07-25 01:49:12 -0700485#define DRAM_ENTRY 9
486
Alan Coxda9bb1d2006-01-18 17:44:13 -0800487static char *fatal_message[2] = { "Non-Fatal ", "Fatal " };
Alan Cox806c35f2006-01-18 17:44:08 -0800488
489static void do_global_error(int fatal, u32 errors)
490{
491 int i;
492
493 for (i = 0; i < 11; i++) {
Doug Thompson10d33e92008-07-25 01:49:12 -0700494 if (errors & (1 << i)) {
495 /* If the error is from DRAM Controller OR
496 * we are to report ALL errors, then
497 * report the error
498 */
499 if ((i == DRAM_ENTRY) || report_non_memory_errors)
500 e752x_printk(KERN_WARNING, "%sError %s\n",
501 fatal_message[fatal],
502 global_message[i]);
503 }
Alan Cox806c35f2006-01-18 17:44:08 -0800504 }
505}
506
507static inline void global_error(int fatal, u32 errors, int *error_found,
Dave Jiang203333c2007-07-19 01:50:06 -0700508 int handle_error)
Alan Cox806c35f2006-01-18 17:44:08 -0800509{
510 *error_found = 1;
511
512 if (handle_error)
513 do_global_error(fatal, errors);
514}
515
Alan Coxda9bb1d2006-01-18 17:44:13 -0800516static char *hub_message[7] = {
Alan Cox806c35f2006-01-18 17:44:08 -0800517 "HI Address or Command Parity", "HI Illegal Access",
518 "HI Internal Parity", "Out of Range Access",
519 "HI Data Parity", "Enhanced Config Access",
520 "Hub Interface Target Abort"
521};
522
523static void do_hub_error(int fatal, u8 errors)
524{
525 int i;
526
527 for (i = 0; i < 7; i++) {
528 if (errors & (1 << i))
Dave Peterson537fba22006-03-26 01:38:40 -0800529 e752x_printk(KERN_WARNING, "%sError %s\n",
Douglas Thompson052dfb42007-07-19 01:50:13 -0700530 fatal_message[fatal], hub_message[i]);
Alan Cox806c35f2006-01-18 17:44:08 -0800531 }
532}
533
534static inline void hub_error(int fatal, u8 errors, int *error_found,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700535 int handle_error)
Alan Cox806c35f2006-01-18 17:44:08 -0800536{
537 *error_found = 1;
538
539 if (handle_error)
540 do_hub_error(fatal, errors);
541}
542
Andrei Konovalov5135b792008-04-29 01:03:13 -0700543#define NSI_FATAL_MASK 0x0c080081
544#define NSI_NON_FATAL_MASK 0x23a0ba64
545#define NSI_ERR_MASK (NSI_FATAL_MASK | NSI_NON_FATAL_MASK)
546
547static char *nsi_message[30] = {
548 "NSI Link Down", /* NSI_FERR/NSI_NERR bit 0, fatal error */
549 "", /* reserved */
550 "NSI Parity Error", /* bit 2, non-fatal */
551 "", /* reserved */
552 "", /* reserved */
553 "Correctable Error Message", /* bit 5, non-fatal */
554 "Non-Fatal Error Message", /* bit 6, non-fatal */
555 "Fatal Error Message", /* bit 7, fatal */
556 "", /* reserved */
557 "Receiver Error", /* bit 9, non-fatal */
558 "", /* reserved */
559 "Bad TLP", /* bit 11, non-fatal */
560 "Bad DLLP", /* bit 12, non-fatal */
561 "REPLAY_NUM Rollover", /* bit 13, non-fatal */
562 "", /* reserved */
563 "Replay Timer Timeout", /* bit 15, non-fatal */
564 "", /* reserved */
565 "", /* reserved */
566 "", /* reserved */
567 "Data Link Protocol Error", /* bit 19, fatal */
568 "", /* reserved */
569 "Poisoned TLP", /* bit 21, non-fatal */
570 "", /* reserved */
571 "Completion Timeout", /* bit 23, non-fatal */
572 "Completer Abort", /* bit 24, non-fatal */
573 "Unexpected Completion", /* bit 25, non-fatal */
574 "Receiver Overflow", /* bit 26, fatal */
575 "Malformed TLP", /* bit 27, fatal */
576 "", /* reserved */
577 "Unsupported Request" /* bit 29, non-fatal */
578};
579
580static void do_nsi_error(int fatal, u32 errors)
581{
582 int i;
583
584 for (i = 0; i < 30; i++) {
585 if (errors & (1 << i))
586 printk(KERN_WARNING "%sError %s\n",
587 fatal_message[fatal], nsi_message[i]);
588 }
589}
590
591static inline void nsi_error(int fatal, u32 errors, int *error_found,
592 int handle_error)
593{
594 *error_found = 1;
595
596 if (handle_error)
597 do_nsi_error(fatal, errors);
598}
599
Alan Coxda9bb1d2006-01-18 17:44:13 -0800600static char *membuf_message[4] = {
Alan Cox806c35f2006-01-18 17:44:08 -0800601 "Internal PMWB to DRAM parity",
602 "Internal PMWB to System Bus Parity",
603 "Internal System Bus or IO to PMWB Parity",
604 "Internal DRAM to PMWB Parity"
605};
606
607static void do_membuf_error(u8 errors)
608{
609 int i;
610
611 for (i = 0; i < 4; i++) {
612 if (errors & (1 << i))
Dave Peterson537fba22006-03-26 01:38:40 -0800613 e752x_printk(KERN_WARNING, "Non-Fatal Error %s\n",
Douglas Thompson052dfb42007-07-19 01:50:13 -0700614 membuf_message[i]);
Alan Cox806c35f2006-01-18 17:44:08 -0800615 }
616}
617
618static inline void membuf_error(u8 errors, int *error_found, int handle_error)
619{
620 *error_found = 1;
621
622 if (handle_error)
623 do_membuf_error(errors);
624}
625
Dave Petersone0093562006-03-26 01:38:54 -0800626static char *sysbus_message[10] = {
Alan Cox806c35f2006-01-18 17:44:08 -0800627 "Addr or Request Parity",
628 "Data Strobe Glitch",
629 "Addr Strobe Glitch",
630 "Data Parity",
631 "Addr Above TOM",
632 "Non DRAM Lock Error",
633 "MCERR", "BINIT",
634 "Memory Parity",
635 "IO Subsystem Parity"
636};
637
638static void do_sysbus_error(int fatal, u32 errors)
639{
640 int i;
641
642 for (i = 0; i < 10; i++) {
643 if (errors & (1 << i))
Dave Peterson537fba22006-03-26 01:38:40 -0800644 e752x_printk(KERN_WARNING, "%sError System Bus %s\n",
Douglas Thompson052dfb42007-07-19 01:50:13 -0700645 fatal_message[fatal], sysbus_message[i]);
Alan Cox806c35f2006-01-18 17:44:08 -0800646 }
647}
648
649static inline void sysbus_error(int fatal, u32 errors, int *error_found,
Dave Jiang203333c2007-07-19 01:50:06 -0700650 int handle_error)
Alan Cox806c35f2006-01-18 17:44:08 -0800651{
652 *error_found = 1;
653
654 if (handle_error)
655 do_sysbus_error(fatal, errors);
656}
657
Dave Petersone7ecd892006-03-26 01:38:52 -0800658static void e752x_check_hub_interface(struct e752x_error_info *info,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700659 int *error_found, int handle_error)
Alan Cox806c35f2006-01-18 17:44:08 -0800660{
661 u8 stat8;
662
663 //pci_read_config_byte(dev,E752X_HI_FERR,&stat8);
Dave Petersone7ecd892006-03-26 01:38:52 -0800664
Alan Cox806c35f2006-01-18 17:44:08 -0800665 stat8 = info->hi_ferr;
Dave Petersone7ecd892006-03-26 01:38:52 -0800666
Dave Jiang203333c2007-07-19 01:50:06 -0700667 if (stat8 & 0x7f) { /* Error, so process */
Alan Cox806c35f2006-01-18 17:44:08 -0800668 stat8 &= 0x7f;
Dave Petersone7ecd892006-03-26 01:38:52 -0800669
Alan Cox806c35f2006-01-18 17:44:08 -0800670 if (stat8 & 0x2b)
671 hub_error(1, stat8 & 0x2b, error_found, handle_error);
Dave Petersone7ecd892006-03-26 01:38:52 -0800672
Dave Jiang203333c2007-07-19 01:50:06 -0700673 if (stat8 & 0x54)
674 hub_error(0, stat8 & 0x54, error_found, handle_error);
675 }
676 //pci_read_config_byte(dev,E752X_HI_NERR,&stat8);
677
678 stat8 = info->hi_nerr;
679
680 if (stat8 & 0x7f) { /* Error, so process */
681 stat8 &= 0x7f;
682
683 if (stat8 & 0x2b)
684 hub_error(1, stat8 & 0x2b, error_found, handle_error);
685
686 if (stat8 & 0x54)
Alan Cox806c35f2006-01-18 17:44:08 -0800687 hub_error(0, stat8 & 0x54, error_found, handle_error);
688 }
689}
690
Andrei Konovalov5135b792008-04-29 01:03:13 -0700691static void e752x_check_ns_interface(struct e752x_error_info *info,
692 int *error_found, int handle_error)
693{
694 u32 stat32;
695
696 stat32 = info->nsi_ferr;
697 if (stat32 & NSI_ERR_MASK) { /* Error, so process */
698 if (stat32 & NSI_FATAL_MASK) /* check for fatal errors */
699 nsi_error(1, stat32 & NSI_FATAL_MASK, error_found,
700 handle_error);
701 if (stat32 & NSI_NON_FATAL_MASK) /* check for non-fatal ones */
702 nsi_error(0, stat32 & NSI_NON_FATAL_MASK, error_found,
703 handle_error);
704 }
705 stat32 = info->nsi_nerr;
706 if (stat32 & NSI_ERR_MASK) {
707 if (stat32 & NSI_FATAL_MASK)
708 nsi_error(1, stat32 & NSI_FATAL_MASK, error_found,
709 handle_error);
710 if (stat32 & NSI_NON_FATAL_MASK)
711 nsi_error(0, stat32 & NSI_NON_FATAL_MASK, error_found,
712 handle_error);
713 }
714}
715
Dave Petersone7ecd892006-03-26 01:38:52 -0800716static void e752x_check_sysbus(struct e752x_error_info *info,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700717 int *error_found, int handle_error)
Alan Cox806c35f2006-01-18 17:44:08 -0800718{
719 u32 stat32, error32;
720
721 //pci_read_config_dword(dev,E752X_SYSBUS_FERR,&stat32);
722 stat32 = info->sysbus_ferr + (info->sysbus_nerr << 16);
723
724 if (stat32 == 0)
Dave Jiang203333c2007-07-19 01:50:06 -0700725 return; /* no errors */
Alan Cox806c35f2006-01-18 17:44:08 -0800726
727 error32 = (stat32 >> 16) & 0x3ff;
728 stat32 = stat32 & 0x3ff;
Dave Petersone7ecd892006-03-26 01:38:52 -0800729
Dave Jiang203333c2007-07-19 01:50:06 -0700730 if (stat32 & 0x087)
Brian Pomerantzdfb2a762007-02-12 00:53:03 -0800731 sysbus_error(1, stat32 & 0x087, error_found, handle_error);
Dave Petersone7ecd892006-03-26 01:38:52 -0800732
Dave Jiang203333c2007-07-19 01:50:06 -0700733 if (stat32 & 0x378)
Brian Pomerantzdfb2a762007-02-12 00:53:03 -0800734 sysbus_error(0, stat32 & 0x378, error_found, handle_error);
Dave Petersone7ecd892006-03-26 01:38:52 -0800735
Dave Jiang203333c2007-07-19 01:50:06 -0700736 if (error32 & 0x087)
Brian Pomerantzdfb2a762007-02-12 00:53:03 -0800737 sysbus_error(1, error32 & 0x087, error_found, handle_error);
Dave Petersone7ecd892006-03-26 01:38:52 -0800738
Dave Jiang203333c2007-07-19 01:50:06 -0700739 if (error32 & 0x378)
Brian Pomerantzdfb2a762007-02-12 00:53:03 -0800740 sysbus_error(0, error32 & 0x378, error_found, handle_error);
Alan Cox806c35f2006-01-18 17:44:08 -0800741}
742
Dave Jiang203333c2007-07-19 01:50:06 -0700743static void e752x_check_membuf(struct e752x_error_info *info,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700744 int *error_found, int handle_error)
Alan Cox806c35f2006-01-18 17:44:08 -0800745{
746 u8 stat8;
747
748 stat8 = info->buf_ferr;
Dave Petersone7ecd892006-03-26 01:38:52 -0800749
Dave Jiang203333c2007-07-19 01:50:06 -0700750 if (stat8 & 0x0f) { /* Error, so process */
Alan Cox806c35f2006-01-18 17:44:08 -0800751 stat8 &= 0x0f;
752 membuf_error(stat8, error_found, handle_error);
753 }
Dave Petersone7ecd892006-03-26 01:38:52 -0800754
Alan Cox806c35f2006-01-18 17:44:08 -0800755 stat8 = info->buf_nerr;
Dave Petersone7ecd892006-03-26 01:38:52 -0800756
Dave Jiang203333c2007-07-19 01:50:06 -0700757 if (stat8 & 0x0f) { /* Error, so process */
Alan Cox806c35f2006-01-18 17:44:08 -0800758 stat8 &= 0x0f;
759 membuf_error(stat8, error_found, handle_error);
760 }
761}
762
Dave Jiang203333c2007-07-19 01:50:06 -0700763static void e752x_check_dram(struct mem_ctl_info *mci,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700764 struct e752x_error_info *info, int *error_found,
765 int handle_error)
Alan Cox806c35f2006-01-18 17:44:08 -0800766{
767 u16 error_one, error_next;
768
769 error_one = info->dram_ferr;
770 error_next = info->dram_nerr;
771
772 /* decode and report errors */
Dave Jiang203333c2007-07-19 01:50:06 -0700773 if (error_one & 0x0101) /* check first error correctable */
Alan Cox806c35f2006-01-18 17:44:08 -0800774 process_ce(mci, error_one, info->dram_sec1_add,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700775 info->dram_sec1_syndrome, error_found, handle_error);
Alan Cox806c35f2006-01-18 17:44:08 -0800776
Dave Jiang203333c2007-07-19 01:50:06 -0700777 if (error_next & 0x0101) /* check next error correctable */
Alan Cox806c35f2006-01-18 17:44:08 -0800778 process_ce(mci, error_next, info->dram_sec2_add,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700779 info->dram_sec2_syndrome, error_found, handle_error);
Alan Cox806c35f2006-01-18 17:44:08 -0800780
Dave Jiang203333c2007-07-19 01:50:06 -0700781 if (error_one & 0x4040)
Alan Cox806c35f2006-01-18 17:44:08 -0800782 process_ue_no_info_wr(mci, error_found, handle_error);
783
Dave Jiang203333c2007-07-19 01:50:06 -0700784 if (error_next & 0x4040)
Alan Cox806c35f2006-01-18 17:44:08 -0800785 process_ue_no_info_wr(mci, error_found, handle_error);
786
Dave Jiang203333c2007-07-19 01:50:06 -0700787 if (error_one & 0x2020)
Alan Cox806c35f2006-01-18 17:44:08 -0800788 process_ded_retry(mci, error_one, info->dram_retr_add,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700789 error_found, handle_error);
Alan Cox806c35f2006-01-18 17:44:08 -0800790
Dave Jiang203333c2007-07-19 01:50:06 -0700791 if (error_next & 0x2020)
Alan Cox806c35f2006-01-18 17:44:08 -0800792 process_ded_retry(mci, error_next, info->dram_retr_add,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700793 error_found, handle_error);
Alan Cox806c35f2006-01-18 17:44:08 -0800794
Dave Jiang203333c2007-07-19 01:50:06 -0700795 if (error_one & 0x0808)
796 process_threshold_ce(mci, error_one, error_found, handle_error);
Alan Cox806c35f2006-01-18 17:44:08 -0800797
Dave Jiang203333c2007-07-19 01:50:06 -0700798 if (error_next & 0x0808)
Alan Cox806c35f2006-01-18 17:44:08 -0800799 process_threshold_ce(mci, error_next, error_found,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700800 handle_error);
Alan Cox806c35f2006-01-18 17:44:08 -0800801
Dave Jiang203333c2007-07-19 01:50:06 -0700802 if (error_one & 0x0606)
Alan Cox806c35f2006-01-18 17:44:08 -0800803 process_ue(mci, error_one, info->dram_ded_add,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700804 info->dram_scrb_add, error_found, handle_error);
Alan Cox806c35f2006-01-18 17:44:08 -0800805
Dave Jiang203333c2007-07-19 01:50:06 -0700806 if (error_next & 0x0606)
Alan Cox806c35f2006-01-18 17:44:08 -0800807 process_ue(mci, error_next, info->dram_ded_add,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700808 info->dram_scrb_add, error_found, handle_error);
Alan Cox806c35f2006-01-18 17:44:08 -0800809}
810
Dave Jiang203333c2007-07-19 01:50:06 -0700811static void e752x_get_error_info(struct mem_ctl_info *mci,
812 struct e752x_error_info *info)
Alan Cox806c35f2006-01-18 17:44:08 -0800813{
814 struct pci_dev *dev;
815 struct e752x_pvt *pvt;
816
817 memset(info, 0, sizeof(*info));
Dave Jiang203333c2007-07-19 01:50:06 -0700818 pvt = (struct e752x_pvt *)mci->pvt_info;
Alan Cox806c35f2006-01-18 17:44:08 -0800819 dev = pvt->dev_d0f1;
Alan Cox806c35f2006-01-18 17:44:08 -0800820 pci_read_config_dword(dev, E752X_FERR_GLOBAL, &info->ferr_global);
821
822 if (info->ferr_global) {
Andrei Konovalov5135b792008-04-29 01:03:13 -0700823 if (pvt->dev_info->err_dev == PCI_DEVICE_ID_INTEL_3100_1_ERR) {
824 pci_read_config_dword(dev, I3100_NSI_FERR,
825 &info->nsi_ferr);
826 info->hi_ferr = 0;
827 } else {
828 pci_read_config_byte(dev, E752X_HI_FERR,
829 &info->hi_ferr);
830 info->nsi_ferr = 0;
831 }
Alan Cox806c35f2006-01-18 17:44:08 -0800832 pci_read_config_word(dev, E752X_SYSBUS_FERR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700833 &info->sysbus_ferr);
Alan Cox806c35f2006-01-18 17:44:08 -0800834 pci_read_config_byte(dev, E752X_BUF_FERR, &info->buf_ferr);
Dave Jiang203333c2007-07-19 01:50:06 -0700835 pci_read_config_word(dev, E752X_DRAM_FERR, &info->dram_ferr);
Alan Cox806c35f2006-01-18 17:44:08 -0800836 pci_read_config_dword(dev, E752X_DRAM_SEC1_ADD,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700837 &info->dram_sec1_add);
Alan Cox806c35f2006-01-18 17:44:08 -0800838 pci_read_config_word(dev, E752X_DRAM_SEC1_SYNDROME,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700839 &info->dram_sec1_syndrome);
Alan Cox806c35f2006-01-18 17:44:08 -0800840 pci_read_config_dword(dev, E752X_DRAM_DED_ADD,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700841 &info->dram_ded_add);
Alan Cox806c35f2006-01-18 17:44:08 -0800842 pci_read_config_dword(dev, E752X_DRAM_SCRB_ADD,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700843 &info->dram_scrb_add);
Alan Cox806c35f2006-01-18 17:44:08 -0800844 pci_read_config_dword(dev, E752X_DRAM_RETR_ADD,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700845 &info->dram_retr_add);
Alan Cox806c35f2006-01-18 17:44:08 -0800846
Andrei Konovalov5135b792008-04-29 01:03:13 -0700847 /* ignore the reserved bits just in case */
Alan Cox806c35f2006-01-18 17:44:08 -0800848 if (info->hi_ferr & 0x7f)
849 pci_write_config_byte(dev, E752X_HI_FERR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700850 info->hi_ferr);
Alan Cox806c35f2006-01-18 17:44:08 -0800851
Andrei Konovalov5135b792008-04-29 01:03:13 -0700852 if (info->nsi_ferr & NSI_ERR_MASK)
853 pci_write_config_dword(dev, I3100_NSI_FERR,
854 info->nsi_ferr);
855
Alan Cox806c35f2006-01-18 17:44:08 -0800856 if (info->sysbus_ferr)
857 pci_write_config_word(dev, E752X_SYSBUS_FERR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700858 info->sysbus_ferr);
Alan Cox806c35f2006-01-18 17:44:08 -0800859
860 if (info->buf_ferr & 0x0f)
861 pci_write_config_byte(dev, E752X_BUF_FERR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700862 info->buf_ferr);
Alan Cox806c35f2006-01-18 17:44:08 -0800863
864 if (info->dram_ferr)
865 pci_write_bits16(pvt->bridge_ck, E752X_DRAM_FERR,
Dave Jiang203333c2007-07-19 01:50:06 -0700866 info->dram_ferr, info->dram_ferr);
Alan Cox806c35f2006-01-18 17:44:08 -0800867
868 pci_write_config_dword(dev, E752X_FERR_GLOBAL,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700869 info->ferr_global);
Alan Cox806c35f2006-01-18 17:44:08 -0800870 }
871
872 pci_read_config_dword(dev, E752X_NERR_GLOBAL, &info->nerr_global);
873
874 if (info->nerr_global) {
Andrei Konovalov5135b792008-04-29 01:03:13 -0700875 if (pvt->dev_info->err_dev == PCI_DEVICE_ID_INTEL_3100_1_ERR) {
876 pci_read_config_dword(dev, I3100_NSI_NERR,
877 &info->nsi_nerr);
878 info->hi_nerr = 0;
879 } else {
880 pci_read_config_byte(dev, E752X_HI_NERR,
881 &info->hi_nerr);
882 info->nsi_nerr = 0;
883 }
Alan Cox806c35f2006-01-18 17:44:08 -0800884 pci_read_config_word(dev, E752X_SYSBUS_NERR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700885 &info->sysbus_nerr);
Alan Cox806c35f2006-01-18 17:44:08 -0800886 pci_read_config_byte(dev, E752X_BUF_NERR, &info->buf_nerr);
Dave Jiang203333c2007-07-19 01:50:06 -0700887 pci_read_config_word(dev, E752X_DRAM_NERR, &info->dram_nerr);
Alan Cox806c35f2006-01-18 17:44:08 -0800888 pci_read_config_dword(dev, E752X_DRAM_SEC2_ADD,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700889 &info->dram_sec2_add);
Alan Cox806c35f2006-01-18 17:44:08 -0800890 pci_read_config_word(dev, E752X_DRAM_SEC2_SYNDROME,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700891 &info->dram_sec2_syndrome);
Alan Cox806c35f2006-01-18 17:44:08 -0800892
893 if (info->hi_nerr & 0x7f)
894 pci_write_config_byte(dev, E752X_HI_NERR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700895 info->hi_nerr);
Alan Cox806c35f2006-01-18 17:44:08 -0800896
Andrei Konovalov5135b792008-04-29 01:03:13 -0700897 if (info->nsi_nerr & NSI_ERR_MASK)
898 pci_write_config_dword(dev, I3100_NSI_NERR,
899 info->nsi_nerr);
900
Alan Cox806c35f2006-01-18 17:44:08 -0800901 if (info->sysbus_nerr)
902 pci_write_config_word(dev, E752X_SYSBUS_NERR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700903 info->sysbus_nerr);
Alan Cox806c35f2006-01-18 17:44:08 -0800904
905 if (info->buf_nerr & 0x0f)
906 pci_write_config_byte(dev, E752X_BUF_NERR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700907 info->buf_nerr);
Alan Cox806c35f2006-01-18 17:44:08 -0800908
909 if (info->dram_nerr)
910 pci_write_bits16(pvt->bridge_ck, E752X_DRAM_NERR,
Dave Jiang203333c2007-07-19 01:50:06 -0700911 info->dram_nerr, info->dram_nerr);
Alan Cox806c35f2006-01-18 17:44:08 -0800912
913 pci_write_config_dword(dev, E752X_NERR_GLOBAL,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700914 info->nerr_global);
Alan Cox806c35f2006-01-18 17:44:08 -0800915 }
916}
917
Dave Jiang203333c2007-07-19 01:50:06 -0700918static int e752x_process_error_info(struct mem_ctl_info *mci,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700919 struct e752x_error_info *info,
920 int handle_errors)
Alan Cox806c35f2006-01-18 17:44:08 -0800921{
922 u32 error32, stat32;
923 int error_found;
924
925 error_found = 0;
926 error32 = (info->ferr_global >> 18) & 0x3ff;
927 stat32 = (info->ferr_global >> 4) & 0x7ff;
928
929 if (error32)
930 global_error(1, error32, &error_found, handle_errors);
931
932 if (stat32)
933 global_error(0, stat32, &error_found, handle_errors);
934
935 error32 = (info->nerr_global >> 18) & 0x3ff;
936 stat32 = (info->nerr_global >> 4) & 0x7ff;
937
938 if (error32)
939 global_error(1, error32, &error_found, handle_errors);
940
941 if (stat32)
942 global_error(0, stat32, &error_found, handle_errors);
943
944 e752x_check_hub_interface(info, &error_found, handle_errors);
Andrei Konovalov5135b792008-04-29 01:03:13 -0700945 e752x_check_ns_interface(info, &error_found, handle_errors);
Alan Cox806c35f2006-01-18 17:44:08 -0800946 e752x_check_sysbus(info, &error_found, handle_errors);
947 e752x_check_membuf(info, &error_found, handle_errors);
948 e752x_check_dram(mci, info, &error_found, handle_errors);
949 return error_found;
950}
951
952static void e752x_check(struct mem_ctl_info *mci)
953{
954 struct e752x_error_info info;
Dave Petersone7ecd892006-03-26 01:38:52 -0800955
Dave Peterson537fba22006-03-26 01:38:40 -0800956 debugf3("%s()\n", __func__);
Alan Cox806c35f2006-01-18 17:44:08 -0800957 e752x_get_error_info(mci, &info);
958 e752x_process_error_info(mci, &info, 1);
959}
960
Peter Tyser8004fd22010-03-10 15:23:15 -0800961/* Program byte/sec bandwidth scrub rate to hardware */
962static int set_sdram_scrub_rate(struct mem_ctl_info *mci, u32 *new_bw)
963{
964 const struct scrubrate *scrubrates;
965 struct e752x_pvt *pvt = (struct e752x_pvt *) mci->pvt_info;
966 struct pci_dev *pdev = pvt->dev_d0f0;
967 int i;
968
969 if (pvt->dev_info->ctl_dev == PCI_DEVICE_ID_INTEL_3100_0)
970 scrubrates = scrubrates_i3100;
971 else
972 scrubrates = scrubrates_e752x;
973
974 /* Translate the desired scrub rate to a e752x/3100 register value.
975 * Search for the bandwidth that is equal or greater than the
976 * desired rate and program the cooresponding register value.
977 */
978 for (i = 0; scrubrates[i].bandwidth != SDRATE_EOT; i++)
979 if (scrubrates[i].bandwidth >= *new_bw)
980 break;
981
982 if (scrubrates[i].bandwidth == SDRATE_EOT)
983 return -1;
984
985 pci_write_config_word(pdev, E752X_MCHSCRB, scrubrates[i].scrubval);
986
987 return 0;
988}
989
990/* Convert current scrub rate value into byte/sec bandwidth */
991static int get_sdram_scrub_rate(struct mem_ctl_info *mci, u32 *bw)
992{
993 const struct scrubrate *scrubrates;
994 struct e752x_pvt *pvt = (struct e752x_pvt *) mci->pvt_info;
995 struct pci_dev *pdev = pvt->dev_d0f0;
996 u16 scrubval;
997 int i;
998
999 if (pvt->dev_info->ctl_dev == PCI_DEVICE_ID_INTEL_3100_0)
1000 scrubrates = scrubrates_i3100;
1001 else
1002 scrubrates = scrubrates_e752x;
1003
1004 /* Find the bandwidth matching the memory scrubber configuration */
1005 pci_read_config_word(pdev, E752X_MCHSCRB, &scrubval);
1006 scrubval = scrubval & 0x0f;
1007
1008 for (i = 0; scrubrates[i].bandwidth != SDRATE_EOT; i++)
1009 if (scrubrates[i].scrubval == scrubval)
1010 break;
1011
1012 if (scrubrates[i].bandwidth == SDRATE_EOT) {
1013 e752x_printk(KERN_WARNING,
1014 "Invalid sdram scrub control value: 0x%x\n", scrubval);
1015 return -1;
1016 }
1017
1018 *bw = scrubrates[i].bandwidth;
1019
1020 return 0;
1021}
1022
Doug Thompson13189522006-06-30 01:56:08 -07001023/* Return 1 if dual channel mode is active. Else return 0. */
1024static inline int dual_channel_active(u16 ddrcsr)
Alan Cox806c35f2006-01-18 17:44:08 -08001025{
Doug Thompson13189522006-06-30 01:56:08 -07001026 return (((ddrcsr >> 12) & 3) == 3);
1027}
1028
Mark Grondona7297c262007-07-19 01:50:23 -07001029/* Remap csrow index numbers if map_type is "reverse"
1030 */
1031static inline int remap_csrow_index(struct mem_ctl_info *mci, int index)
1032{
1033 struct e752x_pvt *pvt = mci->pvt_info;
1034
1035 if (!pvt->map_type)
1036 return (7 - index);
1037
1038 return (index);
1039}
1040
Doug Thompson13189522006-06-30 01:56:08 -07001041static void e752x_init_csrows(struct mem_ctl_info *mci, struct pci_dev *pdev,
Douglas Thompson052dfb42007-07-19 01:50:13 -07001042 u16 ddrcsr)
Doug Thompson13189522006-06-30 01:56:08 -07001043{
1044 struct csrow_info *csrow;
Alan Cox806c35f2006-01-18 17:44:08 -08001045 unsigned long last_cumul_size;
Doug Thompson13189522006-06-30 01:56:08 -07001046 int index, mem_dev, drc_chan;
Dave Jiang203333c2007-07-19 01:50:06 -07001047 int drc_drbg; /* DRB granularity 0=64mb, 1=128mb */
1048 int drc_ddim; /* DRAM Data Integrity Mode 0=none, 2=edac */
Doug Thompson13189522006-06-30 01:56:08 -07001049 u8 value;
1050 u32 dra, drc, cumul_size;
Alan Cox806c35f2006-01-18 17:44:08 -08001051
Brian Pomerantz9962fd02007-02-12 00:53:05 -08001052 dra = 0;
Dave Jiang203333c2007-07-19 01:50:06 -07001053 for (index = 0; index < 4; index++) {
Brian Pomerantz9962fd02007-02-12 00:53:05 -08001054 u8 dra_reg;
Dave Jiang203333c2007-07-19 01:50:06 -07001055 pci_read_config_byte(pdev, E752X_DRA + index, &dra_reg);
Brian Pomerantz9962fd02007-02-12 00:53:05 -08001056 dra |= dra_reg << (index * 8);
1057 }
Alan Cox806c35f2006-01-18 17:44:08 -08001058 pci_read_config_dword(pdev, E752X_DRC, &drc);
Doug Thompson13189522006-06-30 01:56:08 -07001059 drc_chan = dual_channel_active(ddrcsr);
Dave Jiang203333c2007-07-19 01:50:06 -07001060 drc_drbg = drc_chan + 1; /* 128 in dual mode, 64 in single */
Alan Cox806c35f2006-01-18 17:44:08 -08001061 drc_ddim = (drc >> 20) & 0x3;
1062
Doug Thompson13189522006-06-30 01:56:08 -07001063 /* The dram row boundary (DRB) reg values are boundary address for
Alan Cox806c35f2006-01-18 17:44:08 -08001064 * each DRAM row with a granularity of 64 or 128MB (single/dual
1065 * channel operation). DRB regs are cumulative; therefore DRB7 will
1066 * contain the total memory contained in all eight rows.
1067 */
1068 for (last_cumul_size = index = 0; index < mci->nr_csrows; index++) {
Alan Cox806c35f2006-01-18 17:44:08 -08001069 /* mem_dev 0=x8, 1=x4 */
Doug Thompson13189522006-06-30 01:56:08 -07001070 mem_dev = (dra >> (index * 4 + 2)) & 0x3;
Mark Grondona7297c262007-07-19 01:50:23 -07001071 csrow = &mci->csrows[remap_csrow_index(mci, index)];
Alan Cox806c35f2006-01-18 17:44:08 -08001072
1073 mem_dev = (mem_dev == 2);
Doug Thompson37f04582006-06-30 01:56:07 -07001074 pci_read_config_byte(pdev, E752X_DRB + index, &value);
Alan Cox806c35f2006-01-18 17:44:08 -08001075 /* convert a 128 or 64 MiB DRB to a page size. */
1076 cumul_size = value << (25 + drc_drbg - PAGE_SHIFT);
Dave Peterson537fba22006-03-26 01:38:40 -08001077 debugf3("%s(): (%d) cumul_size 0x%x\n", __func__, index,
1078 cumul_size);
Alan Cox806c35f2006-01-18 17:44:08 -08001079 if (cumul_size == last_cumul_size)
Doug Thompson13189522006-06-30 01:56:08 -07001080 continue; /* not populated */
Alan Cox806c35f2006-01-18 17:44:08 -08001081
1082 csrow->first_page = last_cumul_size;
1083 csrow->last_page = cumul_size - 1;
1084 csrow->nr_pages = cumul_size - last_cumul_size;
1085 last_cumul_size = cumul_size;
Doug Thompson13189522006-06-30 01:56:08 -07001086 csrow->grain = 1 << 12; /* 4KiB - resolution of CELOG */
1087 csrow->mtype = MEM_RDDR; /* only one type supported */
Alan Cox806c35f2006-01-18 17:44:08 -08001088 csrow->dtype = mem_dev ? DEV_X4 : DEV_X8;
1089
1090 /*
1091 * if single channel or x8 devices then SECDED
1092 * if dual channel and x4 then S4ECD4ED
1093 */
1094 if (drc_ddim) {
1095 if (drc_chan && mem_dev) {
1096 csrow->edac_mode = EDAC_S4ECD4ED;
1097 mci->edac_cap |= EDAC_FLAG_S4ECD4ED;
1098 } else {
1099 csrow->edac_mode = EDAC_SECDED;
1100 mci->edac_cap |= EDAC_FLAG_SECDED;
1101 }
1102 } else
1103 csrow->edac_mode = EDAC_NONE;
1104 }
Doug Thompson13189522006-06-30 01:56:08 -07001105}
Alan Cox806c35f2006-01-18 17:44:08 -08001106
Doug Thompson13189522006-06-30 01:56:08 -07001107static void e752x_init_mem_map_table(struct pci_dev *pdev,
Douglas Thompson052dfb42007-07-19 01:50:13 -07001108 struct e752x_pvt *pvt)
Doug Thompson13189522006-06-30 01:56:08 -07001109{
1110 int index;
Mark Grondona7297c262007-07-19 01:50:23 -07001111 u8 value, last, row;
Alan Cox806c35f2006-01-18 17:44:08 -08001112
Doug Thompson13189522006-06-30 01:56:08 -07001113 last = 0;
1114 row = 0;
Dave Petersone7ecd892006-03-26 01:38:52 -08001115
Doug Thompson13189522006-06-30 01:56:08 -07001116 for (index = 0; index < 8; index += 2) {
1117 pci_read_config_byte(pdev, E752X_DRB + index, &value);
1118 /* test if there is a dimm in this slot */
1119 if (value == last) {
1120 /* no dimm in the slot, so flag it as empty */
1121 pvt->map[index] = 0xff;
1122 pvt->map[index + 1] = 0xff;
Dave Jiang203333c2007-07-19 01:50:06 -07001123 } else { /* there is a dimm in the slot */
Doug Thompson13189522006-06-30 01:56:08 -07001124 pvt->map[index] = row;
1125 row++;
1126 last = value;
1127 /* test the next value to see if the dimm is double
1128 * sided
1129 */
1130 pci_read_config_byte(pdev, E752X_DRB + index + 1,
Douglas Thompson052dfb42007-07-19 01:50:13 -07001131 &value);
1132
1133 /* the dimm is single sided, so flag as empty */
1134 /* this is a double sided dimm to save the next row #*/
1135 pvt->map[index + 1] = (value == last) ? 0xff : row;
Doug Thompson13189522006-06-30 01:56:08 -07001136 row++;
1137 last = value;
Alan Cox806c35f2006-01-18 17:44:08 -08001138 }
1139 }
Doug Thompson13189522006-06-30 01:56:08 -07001140}
1141
1142/* Return 0 on success or 1 on failure. */
1143static int e752x_get_devs(struct pci_dev *pdev, int dev_idx,
Douglas Thompson052dfb42007-07-19 01:50:13 -07001144 struct e752x_pvt *pvt)
Doug Thompson13189522006-06-30 01:56:08 -07001145{
1146 struct pci_dev *dev;
1147
1148 pvt->bridge_ck = pci_get_device(PCI_VENDOR_ID_INTEL,
Doug Thompson10d33e92008-07-25 01:49:12 -07001149 pvt->dev_info->err_dev, pvt->bridge_ck);
Doug Thompson13189522006-06-30 01:56:08 -07001150
1151 if (pvt->bridge_ck == NULL)
1152 pvt->bridge_ck = pci_scan_single_device(pdev->bus,
1153 PCI_DEVFN(0, 1));
1154
1155 if (pvt->bridge_ck == NULL) {
1156 e752x_printk(KERN_ERR, "error reporting device not found:"
Douglas Thompson052dfb42007-07-19 01:50:13 -07001157 "vendor %x device 0x%x (broken BIOS?)\n",
1158 PCI_VENDOR_ID_INTEL, e752x_devs[dev_idx].err_dev);
Doug Thompson13189522006-06-30 01:56:08 -07001159 return 1;
1160 }
1161
Doug Thompson10d33e92008-07-25 01:49:12 -07001162 dev = pci_get_device(PCI_VENDOR_ID_INTEL,
1163 e752x_devs[dev_idx].ctl_dev,
1164 NULL);
Doug Thompson13189522006-06-30 01:56:08 -07001165
1166 if (dev == NULL)
1167 goto fail;
1168
1169 pvt->dev_d0f0 = dev;
1170 pvt->dev_d0f1 = pci_dev_get(pvt->bridge_ck);
1171
1172 return 0;
1173
Douglas Thompson052dfb42007-07-19 01:50:13 -07001174fail:
Doug Thompson13189522006-06-30 01:56:08 -07001175 pci_dev_put(pvt->bridge_ck);
1176 return 1;
1177}
1178
Peter Tyser94ee1cf2008-04-29 01:03:15 -07001179/* Setup system bus parity mask register.
1180 * Sysbus parity supported on:
Konstantin Olifer8de5c1a2010-03-10 15:23:14 -08001181 * e7320/e7520/e7525 + Xeon
Peter Tyser94ee1cf2008-04-29 01:03:15 -07001182 */
1183static void e752x_init_sysbus_parity_mask(struct e752x_pvt *pvt)
1184{
1185 char *cpu_id = cpu_data(0).x86_model_id;
1186 struct pci_dev *dev = pvt->dev_d0f1;
1187 int enable = 1;
1188
Martin Olsson98a17082009-04-22 18:21:29 +02001189 /* Allow module parameter override, else see if CPU supports parity */
Peter Tyser94ee1cf2008-04-29 01:03:15 -07001190 if (sysbus_parity != -1) {
1191 enable = sysbus_parity;
Konstantin Olifer8de5c1a2010-03-10 15:23:14 -08001192 } else if (cpu_id[0] && !strstr(cpu_id, "Xeon")) {
Peter Tyser94ee1cf2008-04-29 01:03:15 -07001193 e752x_printk(KERN_INFO, "System Bus Parity not "
1194 "supported by CPU, disabling\n");
1195 enable = 0;
1196 }
1197
1198 if (enable)
1199 pci_write_config_word(dev, E752X_SYSBUS_ERRMASK, 0x0000);
1200 else
1201 pci_write_config_word(dev, E752X_SYSBUS_ERRMASK, 0x0309);
1202}
1203
Doug Thompson13189522006-06-30 01:56:08 -07001204static void e752x_init_error_reporting_regs(struct e752x_pvt *pvt)
1205{
1206 struct pci_dev *dev;
1207
1208 dev = pvt->dev_d0f1;
1209 /* Turn off error disable & SMI in case the BIOS turned it on */
Andrei Konovalov5135b792008-04-29 01:03:13 -07001210 if (pvt->dev_info->err_dev == PCI_DEVICE_ID_INTEL_3100_1_ERR) {
1211 pci_write_config_dword(dev, I3100_NSI_EMASK, 0);
1212 pci_write_config_dword(dev, I3100_NSI_SMICMD, 0);
1213 } else {
1214 pci_write_config_byte(dev, E752X_HI_ERRMASK, 0x00);
1215 pci_write_config_byte(dev, E752X_HI_SMICMD, 0x00);
1216 }
Peter Tyser94ee1cf2008-04-29 01:03:15 -07001217
1218 e752x_init_sysbus_parity_mask(pvt);
1219
Doug Thompson13189522006-06-30 01:56:08 -07001220 pci_write_config_word(dev, E752X_SYSBUS_SMICMD, 0x00);
1221 pci_write_config_byte(dev, E752X_BUF_ERRMASK, 0x00);
1222 pci_write_config_byte(dev, E752X_BUF_SMICMD, 0x00);
1223 pci_write_config_byte(dev, E752X_DRAM_ERRMASK, 0x00);
1224 pci_write_config_byte(dev, E752X_DRAM_SMICMD, 0x00);
1225}
1226
1227static int e752x_probe1(struct pci_dev *pdev, int dev_idx)
1228{
1229 u16 pci_data;
1230 u8 stat8;
1231 struct mem_ctl_info *mci;
1232 struct e752x_pvt *pvt;
1233 u16 ddrcsr;
Dave Jiang203333c2007-07-19 01:50:06 -07001234 int drc_chan; /* Number of channels 0=1chan,1=2chan */
Doug Thompson13189522006-06-30 01:56:08 -07001235 struct e752x_error_info discard;
1236
1237 debugf0("%s(): mci\n", __func__);
1238 debugf0("Starting Probe1\n");
1239
1240 /* check to see if device 0 function 1 is enabled; if it isn't, we
1241 * assume the BIOS has reserved it for a reason and is expecting
1242 * exclusive access, we take care not to violate that assumption and
1243 * fail the probe. */
1244 pci_read_config_byte(pdev, E752X_DEVPRES1, &stat8);
1245 if (!force_function_unhide && !(stat8 & (1 << 5))) {
1246 printk(KERN_INFO "Contact your BIOS vendor to see if the "
Douglas Thompson052dfb42007-07-19 01:50:13 -07001247 "E752x error registers can be safely un-hidden\n");
Aristeu Rozanskif9b5a5d2007-09-11 15:23:32 -07001248 return -ENODEV;
Doug Thompson13189522006-06-30 01:56:08 -07001249 }
1250 stat8 |= (1 << 5);
1251 pci_write_config_byte(pdev, E752X_DEVPRES1, stat8);
1252
1253 pci_read_config_word(pdev, E752X_DDRCSR, &ddrcsr);
1254 /* FIXME: should check >>12 or 0xf, true for all? */
1255 /* Dual channel = 1, Single channel = 0 */
1256 drc_chan = dual_channel_active(ddrcsr);
1257
Doug Thompsonb8f6f972007-07-19 01:50:26 -07001258 mci = edac_mc_alloc(sizeof(*pvt), E752X_NR_CSROWS, drc_chan + 1, 0);
Doug Thompson13189522006-06-30 01:56:08 -07001259
1260 if (mci == NULL) {
1261 return -ENOMEM;
1262 }
1263
1264 debugf3("%s(): init mci\n", __func__);
1265 mci->mtype_cap = MEM_FLAG_RDDR;
Andrei Konovalov5135b792008-04-29 01:03:13 -07001266 /* 3100 IMCH supports SECDEC only */
1267 mci->edac_ctl_cap = (dev_idx == I3100) ? EDAC_FLAG_SECDED :
1268 (EDAC_FLAG_NONE | EDAC_FLAG_SECDED | EDAC_FLAG_S4ECD4ED);
Doug Thompson13189522006-06-30 01:56:08 -07001269 /* FIXME - what if different memory types are in different csrows? */
1270 mci->mod_name = EDAC_MOD_STR;
1271 mci->mod_ver = E752X_REVISION;
1272 mci->dev = &pdev->dev;
1273
1274 debugf3("%s(): init pvt\n", __func__);
Dave Jiang203333c2007-07-19 01:50:06 -07001275 pvt = (struct e752x_pvt *)mci->pvt_info;
Doug Thompson13189522006-06-30 01:56:08 -07001276 pvt->dev_info = &e752x_devs[dev_idx];
1277 pvt->mc_symmetric = ((ddrcsr & 0x10) != 0);
1278
1279 if (e752x_get_devs(pdev, dev_idx, pvt)) {
1280 edac_mc_free(mci);
1281 return -ENODEV;
1282 }
1283
1284 debugf3("%s(): more mci init\n", __func__);
1285 mci->ctl_name = pvt->dev_info->ctl_name;
Dave Jiangc4192702007-07-19 01:49:47 -07001286 mci->dev_name = pci_name(pdev);
Doug Thompson13189522006-06-30 01:56:08 -07001287 mci->edac_check = e752x_check;
1288 mci->ctl_page_to_phys = ctl_page_to_phys;
Peter Tyser8004fd22010-03-10 15:23:15 -08001289 mci->set_sdram_scrub_rate = set_sdram_scrub_rate;
1290 mci->get_sdram_scrub_rate = get_sdram_scrub_rate;
Doug Thompson13189522006-06-30 01:56:08 -07001291
Mark Grondona7297c262007-07-19 01:50:23 -07001292 /* set the map type. 1 = normal, 0 = reversed
1293 * Must be set before e752x_init_csrows in case csrow mapping
1294 * is reversed.
1295 */
Doug Thompson13189522006-06-30 01:56:08 -07001296 pci_read_config_byte(pdev, E752X_DRM, &stat8);
1297 pvt->map_type = ((stat8 & 0x0f) > ((stat8 >> 4) & 0x0f));
Alan Cox806c35f2006-01-18 17:44:08 -08001298
Mark Grondona7297c262007-07-19 01:50:23 -07001299 e752x_init_csrows(mci, pdev, ddrcsr);
1300 e752x_init_mem_map_table(pdev, pvt);
1301
Andrei Konovalov5135b792008-04-29 01:03:13 -07001302 if (dev_idx == I3100)
1303 mci->edac_cap = EDAC_FLAG_SECDED; /* the only mode supported */
1304 else
1305 mci->edac_cap |= EDAC_FLAG_NONE;
Dave Peterson537fba22006-03-26 01:38:40 -08001306 debugf3("%s(): tolm, remapbase, remaplimit\n", __func__);
Dave Petersone7ecd892006-03-26 01:38:52 -08001307
Alan Cox806c35f2006-01-18 17:44:08 -08001308 /* load the top of low memory, remap base, and remap limit vars */
Doug Thompson37f04582006-06-30 01:56:07 -07001309 pci_read_config_word(pdev, E752X_TOLM, &pci_data);
Alan Cox806c35f2006-01-18 17:44:08 -08001310 pvt->tolm = ((u32) pci_data) << 4;
Doug Thompson37f04582006-06-30 01:56:07 -07001311 pci_read_config_word(pdev, E752X_REMAPBASE, &pci_data);
Alan Cox806c35f2006-01-18 17:44:08 -08001312 pvt->remapbase = ((u32) pci_data) << 14;
Doug Thompson37f04582006-06-30 01:56:07 -07001313 pci_read_config_word(pdev, E752X_REMAPLIMIT, &pci_data);
Alan Cox806c35f2006-01-18 17:44:08 -08001314 pvt->remaplimit = ((u32) pci_data) << 14;
Dave Peterson537fba22006-03-26 01:38:40 -08001315 e752x_printk(KERN_INFO,
Douglas Thompson052dfb42007-07-19 01:50:13 -07001316 "tolm = %x, remapbase = %x, remaplimit = %x\n",
1317 pvt->tolm, pvt->remapbase, pvt->remaplimit);
Alan Cox806c35f2006-01-18 17:44:08 -08001318
Doug Thompson2d7bbb92006-06-30 01:56:08 -07001319 /* Here we assume that we will never see multiple instances of this
1320 * type of memory controller. The ID is therefore hardcoded to 0.
1321 */
Doug Thompsonb8f6f972007-07-19 01:50:26 -07001322 if (edac_mc_add_mc(mci)) {
Dave Peterson537fba22006-03-26 01:38:40 -08001323 debugf3("%s(): failed edac_mc_add_mc()\n", __func__);
Alan Cox806c35f2006-01-18 17:44:08 -08001324 goto fail;
1325 }
1326
Doug Thompson13189522006-06-30 01:56:08 -07001327 e752x_init_error_reporting_regs(pvt);
Dave Jiang203333c2007-07-19 01:50:06 -07001328 e752x_get_error_info(mci, &discard); /* clear other MCH errors */
Alan Cox806c35f2006-01-18 17:44:08 -08001329
Dave Jiang91b99042007-07-19 01:49:52 -07001330 /* allocating generic PCI control info */
1331 e752x_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
1332 if (!e752x_pci) {
1333 printk(KERN_WARNING
Douglas Thompson052dfb42007-07-19 01:50:13 -07001334 "%s(): Unable to create PCI control\n", __func__);
Dave Jiang91b99042007-07-19 01:49:52 -07001335 printk(KERN_WARNING
Douglas Thompson052dfb42007-07-19 01:50:13 -07001336 "%s(): PCI error report via EDAC not setup\n",
1337 __func__);
Dave Jiang91b99042007-07-19 01:49:52 -07001338 }
1339
Alan Cox806c35f2006-01-18 17:44:08 -08001340 /* get this far and it's successful */
Dave Peterson537fba22006-03-26 01:38:40 -08001341 debugf3("%s(): success\n", __func__);
Alan Cox806c35f2006-01-18 17:44:08 -08001342 return 0;
1343
Douglas Thompson052dfb42007-07-19 01:50:13 -07001344fail:
Doug Thompson13189522006-06-30 01:56:08 -07001345 pci_dev_put(pvt->dev_d0f0);
1346 pci_dev_put(pvt->dev_d0f1);
1347 pci_dev_put(pvt->bridge_ck);
1348 edac_mc_free(mci);
Dave Petersone7ecd892006-03-26 01:38:52 -08001349
Doug Thompson13189522006-06-30 01:56:08 -07001350 return -ENODEV;
Alan Cox806c35f2006-01-18 17:44:08 -08001351}
1352
1353/* returns count (>= 0), or negative on error */
1354static int __devinit e752x_init_one(struct pci_dev *pdev,
Douglas Thompson052dfb42007-07-19 01:50:13 -07001355 const struct pci_device_id *ent)
Alan Cox806c35f2006-01-18 17:44:08 -08001356{
Dave Peterson537fba22006-03-26 01:38:40 -08001357 debugf0("%s()\n", __func__);
Alan Cox806c35f2006-01-18 17:44:08 -08001358
1359 /* wake up and enable device */
Dave Jiang203333c2007-07-19 01:50:06 -07001360 if (pci_enable_device(pdev) < 0)
Alan Cox806c35f2006-01-18 17:44:08 -08001361 return -EIO;
Dave Petersone7ecd892006-03-26 01:38:52 -08001362
Alan Cox806c35f2006-01-18 17:44:08 -08001363 return e752x_probe1(pdev, ent->driver_data);
1364}
1365
Alan Cox806c35f2006-01-18 17:44:08 -08001366static void __devexit e752x_remove_one(struct pci_dev *pdev)
1367{
1368 struct mem_ctl_info *mci;
1369 struct e752x_pvt *pvt;
1370
Dave Peterson537fba22006-03-26 01:38:40 -08001371 debugf0("%s()\n", __func__);
Alan Cox806c35f2006-01-18 17:44:08 -08001372
Dave Jiang91b99042007-07-19 01:49:52 -07001373 if (e752x_pci)
1374 edac_pci_release_generic_ctl(e752x_pci);
1375
Doug Thompson37f04582006-06-30 01:56:07 -07001376 if ((mci = edac_mc_del_mc(&pdev->dev)) == NULL)
Alan Cox806c35f2006-01-18 17:44:08 -08001377 return;
1378
Dave Jiang203333c2007-07-19 01:50:06 -07001379 pvt = (struct e752x_pvt *)mci->pvt_info;
Alan Cox806c35f2006-01-18 17:44:08 -08001380 pci_dev_put(pvt->dev_d0f0);
1381 pci_dev_put(pvt->dev_d0f1);
1382 pci_dev_put(pvt->bridge_ck);
1383 edac_mc_free(mci);
1384}
1385
Alan Cox806c35f2006-01-18 17:44:08 -08001386static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
Dave Petersone7ecd892006-03-26 01:38:52 -08001387 {
Dave Jiang203333c2007-07-19 01:50:06 -07001388 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1389 E7520},
Dave Petersone7ecd892006-03-26 01:38:52 -08001390 {
Dave Jiang203333c2007-07-19 01:50:06 -07001391 PCI_VEND_DEV(INTEL, 7525_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1392 E7525},
Dave Petersone7ecd892006-03-26 01:38:52 -08001393 {
Dave Jiang203333c2007-07-19 01:50:06 -07001394 PCI_VEND_DEV(INTEL, 7320_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1395 E7320},
Dave Petersone7ecd892006-03-26 01:38:52 -08001396 {
Andrei Konovalov5135b792008-04-29 01:03:13 -07001397 PCI_VEND_DEV(INTEL, 3100_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1398 I3100},
1399 {
Dave Jiang203333c2007-07-19 01:50:06 -07001400 0,
1401 } /* 0 terminated list. */
Alan Cox806c35f2006-01-18 17:44:08 -08001402};
1403
1404MODULE_DEVICE_TABLE(pci, e752x_pci_tbl);
1405
Alan Cox806c35f2006-01-18 17:44:08 -08001406static struct pci_driver e752x_driver = {
Dave Peterson680cbbb2006-03-26 01:38:41 -08001407 .name = EDAC_MOD_STR,
Randy Dunlap0d38b042006-02-03 03:04:24 -08001408 .probe = e752x_init_one,
1409 .remove = __devexit_p(e752x_remove_one),
1410 .id_table = e752x_pci_tbl,
Alan Cox806c35f2006-01-18 17:44:08 -08001411};
1412
Alan Coxda9bb1d2006-01-18 17:44:13 -08001413static int __init e752x_init(void)
Alan Cox806c35f2006-01-18 17:44:08 -08001414{
1415 int pci_rc;
1416
Dave Peterson537fba22006-03-26 01:38:40 -08001417 debugf3("%s()\n", __func__);
Hitoshi Mitakec3c52bc2008-04-29 01:03:18 -07001418
1419 /* Ensure that the OPSTATE is set correctly for POLL or NMI */
1420 opstate_init();
1421
Alan Cox806c35f2006-01-18 17:44:08 -08001422 pci_rc = pci_register_driver(&e752x_driver);
1423 return (pci_rc < 0) ? pci_rc : 0;
1424}
1425
Alan Cox806c35f2006-01-18 17:44:08 -08001426static void __exit e752x_exit(void)
1427{
Dave Peterson537fba22006-03-26 01:38:40 -08001428 debugf3("%s()\n", __func__);
Alan Cox806c35f2006-01-18 17:44:08 -08001429 pci_unregister_driver(&e752x_driver);
1430}
1431
Alan Cox806c35f2006-01-18 17:44:08 -08001432module_init(e752x_init);
1433module_exit(e752x_exit);
1434
1435MODULE_LICENSE("GPL");
1436MODULE_AUTHOR("Linux Networx (http://lnxi.com) Tom Zimmerman\n");
Andrei Konovalov5135b792008-04-29 01:03:13 -07001437MODULE_DESCRIPTION("MC support for Intel e752x/3100 memory controllers");
mark gross96941022006-05-03 19:55:07 -07001438
1439module_param(force_function_unhide, int, 0444);
1440MODULE_PARM_DESC(force_function_unhide, "if BIOS sets Dev0:Fun1 up as hidden:"
Doug Thompson10d33e92008-07-25 01:49:12 -07001441 " 1=force unhide and hope BIOS doesn't fight driver for "
1442 "Dev0:Fun1 access");
Hitoshi Mitakec3c52bc2008-04-29 01:03:18 -07001443
Dave Jiangc0d12172007-07-19 01:49:46 -07001444module_param(edac_op_state, int, 0444);
1445MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
Peter Tyser94ee1cf2008-04-29 01:03:15 -07001446
1447module_param(sysbus_parity, int, 0444);
1448MODULE_PARM_DESC(sysbus_parity, "0=disable system bus parity checking,"
1449 " 1=enable system bus parity checking, default=auto-detect");
Doug Thompson10d33e92008-07-25 01:49:12 -07001450module_param(report_non_memory_errors, int, 0644);
1451MODULE_PARM_DESC(report_non_memory_errors, "0=disable non-memory error "
1452 "reporting, 1=enable non-memory error reporting");