blob: a041218370f9f66bcdfd606b03257be3d662c52b [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
mark gross96941022006-05-03 19:55:07 -070031static int force_function_unhide;
32
Dave Jiang91b99042007-07-19 01:49:52 -070033static struct edac_pci_ctl_info *e752x_pci;
34
Dave Peterson537fba22006-03-26 01:38:40 -080035#define e752x_printk(level, fmt, arg...) \
Dave Petersone7ecd892006-03-26 01:38:52 -080036 edac_printk(level, "e752x", fmt, ##arg)
Dave Peterson537fba22006-03-26 01:38:40 -080037
38#define e752x_mc_printk(mci, level, fmt, arg...) \
Dave Petersone7ecd892006-03-26 01:38:52 -080039 edac_mc_chipset_printk(mci, level, "e752x", fmt, ##arg)
Dave Peterson537fba22006-03-26 01:38:40 -080040
Alan Cox806c35f2006-01-18 17:44:08 -080041#ifndef PCI_DEVICE_ID_INTEL_7520_0
42#define PCI_DEVICE_ID_INTEL_7520_0 0x3590
43#endif /* PCI_DEVICE_ID_INTEL_7520_0 */
44
45#ifndef PCI_DEVICE_ID_INTEL_7520_1_ERR
46#define PCI_DEVICE_ID_INTEL_7520_1_ERR 0x3591
47#endif /* PCI_DEVICE_ID_INTEL_7520_1_ERR */
48
49#ifndef PCI_DEVICE_ID_INTEL_7525_0
50#define PCI_DEVICE_ID_INTEL_7525_0 0x359E
51#endif /* PCI_DEVICE_ID_INTEL_7525_0 */
52
53#ifndef PCI_DEVICE_ID_INTEL_7525_1_ERR
54#define PCI_DEVICE_ID_INTEL_7525_1_ERR 0x3593
55#endif /* PCI_DEVICE_ID_INTEL_7525_1_ERR */
56
57#ifndef PCI_DEVICE_ID_INTEL_7320_0
58#define PCI_DEVICE_ID_INTEL_7320_0 0x3592
59#endif /* PCI_DEVICE_ID_INTEL_7320_0 */
60
61#ifndef PCI_DEVICE_ID_INTEL_7320_1_ERR
62#define PCI_DEVICE_ID_INTEL_7320_1_ERR 0x3593
63#endif /* PCI_DEVICE_ID_INTEL_7320_1_ERR */
64
65#define E752X_NR_CSROWS 8 /* number of csrows */
66
Alan Cox806c35f2006-01-18 17:44:08 -080067/* E752X register addresses - device 0 function 0 */
68#define E752X_DRB 0x60 /* DRAM row boundary register (8b) */
69#define E752X_DRA 0x70 /* DRAM row attribute register (8b) */
70 /*
71 * 31:30 Device width row 7
72 * 01=x8 10=x4 11=x8 DDR2
73 * 27:26 Device width row 6
74 * 23:22 Device width row 5
75 * 19:20 Device width row 4
76 * 15:14 Device width row 3
77 * 11:10 Device width row 2
78 * 7:6 Device width row 1
79 * 3:2 Device width row 0
80 */
81#define E752X_DRC 0x7C /* DRAM controller mode reg (32b) */
82 /* FIXME:IS THIS RIGHT? */
83 /*
84 * 22 Number channels 0=1,1=2
85 * 19:18 DRB Granularity 32/64MB
86 */
87#define E752X_DRM 0x80 /* Dimm mapping register */
88#define E752X_DDRCSR 0x9A /* DDR control and status reg (16b) */
89 /*
90 * 14:12 1 single A, 2 single B, 3 dual
91 */
92#define E752X_TOLM 0xC4 /* DRAM top of low memory reg (16b) */
93#define E752X_REMAPBASE 0xC6 /* DRAM remap base address reg (16b) */
94#define E752X_REMAPLIMIT 0xC8 /* DRAM remap limit address reg (16b) */
95#define E752X_REMAPOFFSET 0xCA /* DRAM remap limit offset reg (16b) */
96
97/* E752X register addresses - device 0 function 1 */
98#define E752X_FERR_GLOBAL 0x40 /* Global first error register (32b) */
99#define E752X_NERR_GLOBAL 0x44 /* Global next error register (32b) */
100#define E752X_HI_FERR 0x50 /* Hub interface first error reg (8b) */
101#define E752X_HI_NERR 0x52 /* Hub interface next error reg (8b) */
102#define E752X_HI_ERRMASK 0x54 /* Hub interface error mask reg (8b) */
103#define E752X_HI_SMICMD 0x5A /* Hub interface SMI command reg (8b) */
104#define E752X_SYSBUS_FERR 0x60 /* System buss first error reg (16b) */
105#define E752X_SYSBUS_NERR 0x62 /* System buss next error reg (16b) */
106#define E752X_SYSBUS_ERRMASK 0x64 /* System buss error mask reg (16b) */
107#define E752X_SYSBUS_SMICMD 0x6A /* System buss SMI command reg (16b) */
108#define E752X_BUF_FERR 0x70 /* Memory buffer first error reg (8b) */
109#define E752X_BUF_NERR 0x72 /* Memory buffer next error reg (8b) */
110#define E752X_BUF_ERRMASK 0x74 /* Memory buffer error mask reg (8b) */
111#define E752X_BUF_SMICMD 0x7A /* Memory buffer SMI command reg (8b) */
112#define E752X_DRAM_FERR 0x80 /* DRAM first error register (16b) */
113#define E752X_DRAM_NERR 0x82 /* DRAM next error register (16b) */
114#define E752X_DRAM_ERRMASK 0x84 /* DRAM error mask register (8b) */
115#define E752X_DRAM_SMICMD 0x8A /* DRAM SMI command register (8b) */
116#define E752X_DRAM_RETR_ADD 0xAC /* DRAM Retry address register (32b) */
117#define E752X_DRAM_SEC1_ADD 0xA0 /* DRAM first correctable memory */
118 /* error address register (32b) */
119 /*
120 * 31 Reserved
121 * 30:2 CE address (64 byte block 34:6)
122 * 1 Reserved
123 * 0 HiLoCS
124 */
125#define E752X_DRAM_SEC2_ADD 0xC8 /* DRAM first correctable memory */
126 /* error address register (32b) */
127 /*
128 * 31 Reserved
129 * 30:2 CE address (64 byte block 34:6)
130 * 1 Reserved
131 * 0 HiLoCS
132 */
133#define E752X_DRAM_DED_ADD 0xA4 /* DRAM first uncorrectable memory */
134 /* error address register (32b) */
135 /*
136 * 31 Reserved
137 * 30:2 CE address (64 byte block 34:6)
138 * 1 Reserved
139 * 0 HiLoCS
140 */
141#define E752X_DRAM_SCRB_ADD 0xA8 /* DRAM first uncorrectable scrub memory */
142 /* error address register (32b) */
143 /*
144 * 31 Reserved
145 * 30:2 CE address (64 byte block 34:6)
146 * 1 Reserved
147 * 0 HiLoCS
148 */
149#define E752X_DRAM_SEC1_SYNDROME 0xC4 /* DRAM first correctable memory */
150 /* error syndrome register (16b) */
151#define E752X_DRAM_SEC2_SYNDROME 0xC6 /* DRAM second correctable memory */
152 /* error syndrome register (16b) */
153#define E752X_DEVPRES1 0xF4 /* Device Present 1 register (8b) */
154
155/* ICH5R register addresses - device 30 function 0 */
156#define ICH5R_PCI_STAT 0x06 /* PCI status register (16b) */
157#define ICH5R_PCI_2ND_STAT 0x1E /* PCI status secondary reg (16b) */
158#define ICH5R_PCI_BRIDGE_CTL 0x3E /* PCI bridge control register (16b) */
159
160enum e752x_chips {
161 E7520 = 0,
162 E7525 = 1,
163 E7320 = 2
164};
165
Alan Cox806c35f2006-01-18 17:44:08 -0800166struct e752x_pvt {
167 struct pci_dev *bridge_ck;
168 struct pci_dev *dev_d0f0;
169 struct pci_dev *dev_d0f1;
170 u32 tolm;
171 u32 remapbase;
172 u32 remaplimit;
173 int mc_symmetric;
174 u8 map[8];
175 int map_type;
176 const struct e752x_dev_info *dev_info;
177};
178
Alan Cox806c35f2006-01-18 17:44:08 -0800179struct e752x_dev_info {
180 u16 err_dev;
Dave Peterson3847bccc2006-03-26 01:38:42 -0800181 u16 ctl_dev;
Alan Cox806c35f2006-01-18 17:44:08 -0800182 const char *ctl_name;
183};
184
185struct e752x_error_info {
186 u32 ferr_global;
187 u32 nerr_global;
188 u8 hi_ferr;
189 u8 hi_nerr;
190 u16 sysbus_ferr;
191 u16 sysbus_nerr;
192 u8 buf_ferr;
193 u8 buf_nerr;
194 u16 dram_ferr;
195 u16 dram_nerr;
196 u32 dram_sec1_add;
197 u32 dram_sec2_add;
198 u16 dram_sec1_syndrome;
199 u16 dram_sec2_syndrome;
200 u32 dram_ded_add;
201 u32 dram_scrb_add;
202 u32 dram_retr_add;
203};
204
205static const struct e752x_dev_info e752x_devs[] = {
206 [E7520] = {
Douglas Thompson052dfb42007-07-19 01:50:13 -0700207 .err_dev = PCI_DEVICE_ID_INTEL_7520_1_ERR,
208 .ctl_dev = PCI_DEVICE_ID_INTEL_7520_0,
209 .ctl_name = "E7520"},
Alan Cox806c35f2006-01-18 17:44:08 -0800210 [E7525] = {
Douglas Thompson052dfb42007-07-19 01:50:13 -0700211 .err_dev = PCI_DEVICE_ID_INTEL_7525_1_ERR,
212 .ctl_dev = PCI_DEVICE_ID_INTEL_7525_0,
213 .ctl_name = "E7525"},
Alan Cox806c35f2006-01-18 17:44:08 -0800214 [E7320] = {
Douglas Thompson052dfb42007-07-19 01:50:13 -0700215 .err_dev = PCI_DEVICE_ID_INTEL_7320_1_ERR,
216 .ctl_dev = PCI_DEVICE_ID_INTEL_7320_0,
217 .ctl_name = "E7320"},
Alan Cox806c35f2006-01-18 17:44:08 -0800218};
219
Alan Cox806c35f2006-01-18 17:44:08 -0800220static unsigned long ctl_page_to_phys(struct mem_ctl_info *mci,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700221 unsigned long page)
Alan Cox806c35f2006-01-18 17:44:08 -0800222{
223 u32 remap;
Dave Jiang203333c2007-07-19 01:50:06 -0700224 struct e752x_pvt *pvt = (struct e752x_pvt *)mci->pvt_info;
Alan Cox806c35f2006-01-18 17:44:08 -0800225
Dave Peterson537fba22006-03-26 01:38:40 -0800226 debugf3("%s()\n", __func__);
Alan Cox806c35f2006-01-18 17:44:08 -0800227
228 if (page < pvt->tolm)
229 return page;
Dave Petersone7ecd892006-03-26 01:38:52 -0800230
Alan Cox806c35f2006-01-18 17:44:08 -0800231 if ((page >= 0x100000) && (page < pvt->remapbase))
232 return page;
Dave Petersone7ecd892006-03-26 01:38:52 -0800233
Alan Cox806c35f2006-01-18 17:44:08 -0800234 remap = (page - pvt->tolm) + pvt->remapbase;
Dave Petersone7ecd892006-03-26 01:38:52 -0800235
Alan Cox806c35f2006-01-18 17:44:08 -0800236 if (remap < pvt->remaplimit)
237 return remap;
Dave Petersone7ecd892006-03-26 01:38:52 -0800238
Dave Peterson537fba22006-03-26 01:38:40 -0800239 e752x_printk(KERN_ERR, "Invalid page %lx - out of range\n", page);
Alan Cox806c35f2006-01-18 17:44:08 -0800240 return pvt->tolm - 1;
241}
242
243static void do_process_ce(struct mem_ctl_info *mci, u16 error_one,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700244 u32 sec1_add, u16 sec1_syndrome)
Alan Cox806c35f2006-01-18 17:44:08 -0800245{
246 u32 page;
247 int row;
248 int channel;
249 int i;
Dave Jiang203333c2007-07-19 01:50:06 -0700250 struct e752x_pvt *pvt = (struct e752x_pvt *)mci->pvt_info;
Alan Cox806c35f2006-01-18 17:44:08 -0800251
Dave Peterson537fba22006-03-26 01:38:40 -0800252 debugf3("%s()\n", __func__);
Alan Cox806c35f2006-01-18 17:44:08 -0800253
254 /* convert the addr to 4k page */
255 page = sec1_add >> (PAGE_SHIFT - 4);
256
257 /* FIXME - check for -1 */
258 if (pvt->mc_symmetric) {
259 /* chip select are bits 14 & 13 */
260 row = ((page >> 1) & 3);
Dave Peterson537fba22006-03-26 01:38:40 -0800261 e752x_printk(KERN_WARNING,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700262 "Test row %d Table %d %d %d %d %d %d %d %d\n", row,
263 pvt->map[0], pvt->map[1], pvt->map[2], pvt->map[3],
264 pvt->map[4], pvt->map[5], pvt->map[6],
265 pvt->map[7]);
Alan Cox806c35f2006-01-18 17:44:08 -0800266
267 /* test for channel remapping */
268 for (i = 0; i < 8; i++) {
269 if (pvt->map[i] == row)
270 break;
271 }
Dave Petersone7ecd892006-03-26 01:38:52 -0800272
Dave Peterson537fba22006-03-26 01:38:40 -0800273 e752x_printk(KERN_WARNING, "Test computed row %d\n", i);
Dave Petersone7ecd892006-03-26 01:38:52 -0800274
Alan Cox806c35f2006-01-18 17:44:08 -0800275 if (i < 8)
276 row = i;
277 else
Dave Peterson537fba22006-03-26 01:38:40 -0800278 e752x_mc_printk(mci, KERN_WARNING,
Dave Jiang203333c2007-07-19 01:50:06 -0700279 "row %d not found in remap table\n",
280 row);
Alan Cox806c35f2006-01-18 17:44:08 -0800281 } else
282 row = edac_mc_find_csrow_by_page(mci, page);
Dave Petersone7ecd892006-03-26 01:38:52 -0800283
Alan Cox806c35f2006-01-18 17:44:08 -0800284 /* 0 = channel A, 1 = channel B */
285 channel = !(error_one & 1);
286
287 if (!pvt->map_type)
288 row = 7 - row;
Alan Cox806c35f2006-01-18 17:44:08 -0800289
Mike Chan84db0032007-02-12 00:53:06 -0800290 /* e752x mc reads 34:6 of the DRAM linear address */
291 edac_mc_handle_ce(mci, page, offset_in_page(sec1_add << 4),
Douglas Thompson052dfb42007-07-19 01:50:13 -0700292 sec1_syndrome, row, channel, "e752x CE");
Dave Petersone7ecd892006-03-26 01:38:52 -0800293}
Alan Cox806c35f2006-01-18 17:44:08 -0800294
295static inline void process_ce(struct mem_ctl_info *mci, u16 error_one,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700296 u32 sec1_add, u16 sec1_syndrome, int *error_found,
297 int handle_error)
Alan Cox806c35f2006-01-18 17:44:08 -0800298{
299 *error_found = 1;
300
301 if (handle_error)
302 do_process_ce(mci, error_one, sec1_add, sec1_syndrome);
303}
304
Dave Petersone7ecd892006-03-26 01:38:52 -0800305static void do_process_ue(struct mem_ctl_info *mci, u16 error_one,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700306 u32 ded_add, u32 scrb_add)
Alan Cox806c35f2006-01-18 17:44:08 -0800307{
308 u32 error_2b, block_page;
309 int row;
Dave Jiang203333c2007-07-19 01:50:06 -0700310 struct e752x_pvt *pvt = (struct e752x_pvt *)mci->pvt_info;
Alan Cox806c35f2006-01-18 17:44:08 -0800311
Dave Peterson537fba22006-03-26 01:38:40 -0800312 debugf3("%s()\n", __func__);
Alan Cox806c35f2006-01-18 17:44:08 -0800313
314 if (error_one & 0x0202) {
315 error_2b = ded_add;
Dave Petersone7ecd892006-03-26 01:38:52 -0800316
Alan Cox806c35f2006-01-18 17:44:08 -0800317 /* convert to 4k address */
318 block_page = error_2b >> (PAGE_SHIFT - 4);
Dave Petersone7ecd892006-03-26 01:38:52 -0800319
Alan Cox806c35f2006-01-18 17:44:08 -0800320 row = pvt->mc_symmetric ?
Douglas Thompson052dfb42007-07-19 01:50:13 -0700321 /* chip select are bits 14 & 13 */
322 ((block_page >> 1) & 3) :
323 edac_mc_find_csrow_by_page(mci, block_page);
Dave Petersone7ecd892006-03-26 01:38:52 -0800324
Mike Chan84db0032007-02-12 00:53:06 -0800325 /* e752x mc reads 34:6 of the DRAM linear address */
326 edac_mc_handle_ue(mci, block_page,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700327 offset_in_page(error_2b << 4),
328 row, "e752x UE from Read");
Alan Cox806c35f2006-01-18 17:44:08 -0800329 }
330 if (error_one & 0x0404) {
331 error_2b = scrb_add;
Dave Petersone7ecd892006-03-26 01:38:52 -0800332
Alan Cox806c35f2006-01-18 17:44:08 -0800333 /* convert to 4k address */
334 block_page = error_2b >> (PAGE_SHIFT - 4);
Dave Petersone7ecd892006-03-26 01:38:52 -0800335
Alan Cox806c35f2006-01-18 17:44:08 -0800336 row = pvt->mc_symmetric ?
Douglas Thompson052dfb42007-07-19 01:50:13 -0700337 /* chip select are bits 14 & 13 */
338 ((block_page >> 1) & 3) :
339 edac_mc_find_csrow_by_page(mci, block_page);
Dave Petersone7ecd892006-03-26 01:38:52 -0800340
Mike Chan84db0032007-02-12 00:53:06 -0800341 /* e752x mc reads 34:6 of the DRAM linear address */
342 edac_mc_handle_ue(mci, block_page,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700343 offset_in_page(error_2b << 4),
344 row, "e752x UE from Scruber");
Alan Cox806c35f2006-01-18 17:44:08 -0800345 }
346}
347
348static inline void process_ue(struct mem_ctl_info *mci, u16 error_one,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700349 u32 ded_add, u32 scrb_add, int *error_found,
350 int handle_error)
Alan Cox806c35f2006-01-18 17:44:08 -0800351{
352 *error_found = 1;
353
354 if (handle_error)
355 do_process_ue(mci, error_one, ded_add, scrb_add);
356}
357
358static inline void process_ue_no_info_wr(struct mem_ctl_info *mci,
Dave Jiang203333c2007-07-19 01:50:06 -0700359 int *error_found, int handle_error)
Alan Cox806c35f2006-01-18 17:44:08 -0800360{
361 *error_found = 1;
362
363 if (!handle_error)
364 return;
365
Dave Peterson537fba22006-03-26 01:38:40 -0800366 debugf3("%s()\n", __func__);
Alan Cox806c35f2006-01-18 17:44:08 -0800367 edac_mc_handle_ue_no_info(mci, "e752x UE log memory write");
368}
369
370static void do_process_ded_retry(struct mem_ctl_info *mci, u16 error,
Dave Jiang203333c2007-07-19 01:50:06 -0700371 u32 retry_add)
Alan Cox806c35f2006-01-18 17:44:08 -0800372{
373 u32 error_1b, page;
374 int row;
Dave Jiang203333c2007-07-19 01:50:06 -0700375 struct e752x_pvt *pvt = (struct e752x_pvt *)mci->pvt_info;
Alan Cox806c35f2006-01-18 17:44:08 -0800376
377 error_1b = retry_add;
Dave Jiang203333c2007-07-19 01:50:06 -0700378 page = error_1b >> (PAGE_SHIFT - 4); /* convert the addr to 4k page */
379 row = pvt->mc_symmetric ? ((page >> 1) & 3) : /* chip select are bits 14 & 13 */
Douglas Thompson052dfb42007-07-19 01:50:13 -0700380 edac_mc_find_csrow_by_page(mci, page);
Dave Peterson537fba22006-03-26 01:38:40 -0800381 e752x_mc_printk(mci, KERN_WARNING,
Dave Jiang203333c2007-07-19 01:50:06 -0700382 "CE page 0x%lx, row %d : Memory read retry\n",
383 (long unsigned int)page, row);
Alan Cox806c35f2006-01-18 17:44:08 -0800384}
385
386static inline void process_ded_retry(struct mem_ctl_info *mci, u16 error,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700387 u32 retry_add, int *error_found,
388 int handle_error)
Alan Cox806c35f2006-01-18 17:44:08 -0800389{
390 *error_found = 1;
391
392 if (handle_error)
393 do_process_ded_retry(mci, error, retry_add);
394}
395
396static inline void process_threshold_ce(struct mem_ctl_info *mci, u16 error,
Dave Jiang203333c2007-07-19 01:50:06 -0700397 int *error_found, int handle_error)
Alan Cox806c35f2006-01-18 17:44:08 -0800398{
399 *error_found = 1;
400
401 if (handle_error)
Dave Peterson537fba22006-03-26 01:38:40 -0800402 e752x_mc_printk(mci, KERN_WARNING, "Memory threshold CE\n");
Alan Cox806c35f2006-01-18 17:44:08 -0800403}
404
Alan Coxda9bb1d2006-01-18 17:44:13 -0800405static char *global_message[11] = {
Alan Cox806c35f2006-01-18 17:44:08 -0800406 "PCI Express C1", "PCI Express C", "PCI Express B1",
407 "PCI Express B", "PCI Express A1", "PCI Express A",
408 "DMA Controler", "HUB Interface", "System Bus",
409 "DRAM Controler", "Internal Buffer"
410};
411
Alan Coxda9bb1d2006-01-18 17:44:13 -0800412static char *fatal_message[2] = { "Non-Fatal ", "Fatal " };
Alan Cox806c35f2006-01-18 17:44:08 -0800413
414static void do_global_error(int fatal, u32 errors)
415{
416 int i;
417
418 for (i = 0; i < 11; i++) {
419 if (errors & (1 << i))
Dave Peterson537fba22006-03-26 01:38:40 -0800420 e752x_printk(KERN_WARNING, "%sError %s\n",
Douglas Thompson052dfb42007-07-19 01:50:13 -0700421 fatal_message[fatal], global_message[i]);
Alan Cox806c35f2006-01-18 17:44:08 -0800422 }
423}
424
425static inline void global_error(int fatal, u32 errors, int *error_found,
Dave Jiang203333c2007-07-19 01:50:06 -0700426 int handle_error)
Alan Cox806c35f2006-01-18 17:44:08 -0800427{
428 *error_found = 1;
429
430 if (handle_error)
431 do_global_error(fatal, errors);
432}
433
Alan Coxda9bb1d2006-01-18 17:44:13 -0800434static char *hub_message[7] = {
Alan Cox806c35f2006-01-18 17:44:08 -0800435 "HI Address or Command Parity", "HI Illegal Access",
436 "HI Internal Parity", "Out of Range Access",
437 "HI Data Parity", "Enhanced Config Access",
438 "Hub Interface Target Abort"
439};
440
441static void do_hub_error(int fatal, u8 errors)
442{
443 int i;
444
445 for (i = 0; i < 7; i++) {
446 if (errors & (1 << i))
Dave Peterson537fba22006-03-26 01:38:40 -0800447 e752x_printk(KERN_WARNING, "%sError %s\n",
Douglas Thompson052dfb42007-07-19 01:50:13 -0700448 fatal_message[fatal], hub_message[i]);
Alan Cox806c35f2006-01-18 17:44:08 -0800449 }
450}
451
452static inline void hub_error(int fatal, u8 errors, int *error_found,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700453 int handle_error)
Alan Cox806c35f2006-01-18 17:44:08 -0800454{
455 *error_found = 1;
456
457 if (handle_error)
458 do_hub_error(fatal, errors);
459}
460
Alan Coxda9bb1d2006-01-18 17:44:13 -0800461static char *membuf_message[4] = {
Alan Cox806c35f2006-01-18 17:44:08 -0800462 "Internal PMWB to DRAM parity",
463 "Internal PMWB to System Bus Parity",
464 "Internal System Bus or IO to PMWB Parity",
465 "Internal DRAM to PMWB Parity"
466};
467
468static void do_membuf_error(u8 errors)
469{
470 int i;
471
472 for (i = 0; i < 4; i++) {
473 if (errors & (1 << i))
Dave Peterson537fba22006-03-26 01:38:40 -0800474 e752x_printk(KERN_WARNING, "Non-Fatal Error %s\n",
Douglas Thompson052dfb42007-07-19 01:50:13 -0700475 membuf_message[i]);
Alan Cox806c35f2006-01-18 17:44:08 -0800476 }
477}
478
479static inline void membuf_error(u8 errors, int *error_found, int handle_error)
480{
481 *error_found = 1;
482
483 if (handle_error)
484 do_membuf_error(errors);
485}
486
Dave Petersone0093562006-03-26 01:38:54 -0800487static char *sysbus_message[10] = {
Alan Cox806c35f2006-01-18 17:44:08 -0800488 "Addr or Request Parity",
489 "Data Strobe Glitch",
490 "Addr Strobe Glitch",
491 "Data Parity",
492 "Addr Above TOM",
493 "Non DRAM Lock Error",
494 "MCERR", "BINIT",
495 "Memory Parity",
496 "IO Subsystem Parity"
497};
498
499static void do_sysbus_error(int fatal, u32 errors)
500{
501 int i;
502
503 for (i = 0; i < 10; i++) {
504 if (errors & (1 << i))
Dave Peterson537fba22006-03-26 01:38:40 -0800505 e752x_printk(KERN_WARNING, "%sError System Bus %s\n",
Douglas Thompson052dfb42007-07-19 01:50:13 -0700506 fatal_message[fatal], sysbus_message[i]);
Alan Cox806c35f2006-01-18 17:44:08 -0800507 }
508}
509
510static inline void sysbus_error(int fatal, u32 errors, int *error_found,
Dave Jiang203333c2007-07-19 01:50:06 -0700511 int handle_error)
Alan Cox806c35f2006-01-18 17:44:08 -0800512{
513 *error_found = 1;
514
515 if (handle_error)
516 do_sysbus_error(fatal, errors);
517}
518
Dave Petersone7ecd892006-03-26 01:38:52 -0800519static void e752x_check_hub_interface(struct e752x_error_info *info,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700520 int *error_found, int handle_error)
Alan Cox806c35f2006-01-18 17:44:08 -0800521{
522 u8 stat8;
523
524 //pci_read_config_byte(dev,E752X_HI_FERR,&stat8);
Dave Petersone7ecd892006-03-26 01:38:52 -0800525
Alan Cox806c35f2006-01-18 17:44:08 -0800526 stat8 = info->hi_ferr;
Dave Petersone7ecd892006-03-26 01:38:52 -0800527
Dave Jiang203333c2007-07-19 01:50:06 -0700528 if (stat8 & 0x7f) { /* Error, so process */
Alan Cox806c35f2006-01-18 17:44:08 -0800529 stat8 &= 0x7f;
Dave Petersone7ecd892006-03-26 01:38:52 -0800530
Alan Cox806c35f2006-01-18 17:44:08 -0800531 if (stat8 & 0x2b)
532 hub_error(1, stat8 & 0x2b, error_found, handle_error);
Dave Petersone7ecd892006-03-26 01:38:52 -0800533
Dave Jiang203333c2007-07-19 01:50:06 -0700534 if (stat8 & 0x54)
535 hub_error(0, stat8 & 0x54, error_found, handle_error);
536 }
537 //pci_read_config_byte(dev,E752X_HI_NERR,&stat8);
538
539 stat8 = info->hi_nerr;
540
541 if (stat8 & 0x7f) { /* Error, so process */
542 stat8 &= 0x7f;
543
544 if (stat8 & 0x2b)
545 hub_error(1, stat8 & 0x2b, error_found, handle_error);
546
547 if (stat8 & 0x54)
Alan Cox806c35f2006-01-18 17:44:08 -0800548 hub_error(0, stat8 & 0x54, error_found, handle_error);
549 }
550}
551
Dave Petersone7ecd892006-03-26 01:38:52 -0800552static void e752x_check_sysbus(struct e752x_error_info *info,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700553 int *error_found, int handle_error)
Alan Cox806c35f2006-01-18 17:44:08 -0800554{
555 u32 stat32, error32;
556
557 //pci_read_config_dword(dev,E752X_SYSBUS_FERR,&stat32);
558 stat32 = info->sysbus_ferr + (info->sysbus_nerr << 16);
559
560 if (stat32 == 0)
Dave Jiang203333c2007-07-19 01:50:06 -0700561 return; /* no errors */
Alan Cox806c35f2006-01-18 17:44:08 -0800562
563 error32 = (stat32 >> 16) & 0x3ff;
564 stat32 = stat32 & 0x3ff;
Dave Petersone7ecd892006-03-26 01:38:52 -0800565
Dave Jiang203333c2007-07-19 01:50:06 -0700566 if (stat32 & 0x087)
Brian Pomerantzdfb2a762007-02-12 00:53:03 -0800567 sysbus_error(1, stat32 & 0x087, error_found, handle_error);
Dave Petersone7ecd892006-03-26 01:38:52 -0800568
Dave Jiang203333c2007-07-19 01:50:06 -0700569 if (stat32 & 0x378)
Brian Pomerantzdfb2a762007-02-12 00:53:03 -0800570 sysbus_error(0, stat32 & 0x378, error_found, handle_error);
Dave Petersone7ecd892006-03-26 01:38:52 -0800571
Dave Jiang203333c2007-07-19 01:50:06 -0700572 if (error32 & 0x087)
Brian Pomerantzdfb2a762007-02-12 00:53:03 -0800573 sysbus_error(1, error32 & 0x087, error_found, handle_error);
Dave Petersone7ecd892006-03-26 01:38:52 -0800574
Dave Jiang203333c2007-07-19 01:50:06 -0700575 if (error32 & 0x378)
Brian Pomerantzdfb2a762007-02-12 00:53:03 -0800576 sysbus_error(0, error32 & 0x378, error_found, handle_error);
Alan Cox806c35f2006-01-18 17:44:08 -0800577}
578
Dave Jiang203333c2007-07-19 01:50:06 -0700579static void e752x_check_membuf(struct e752x_error_info *info,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700580 int *error_found, int handle_error)
Alan Cox806c35f2006-01-18 17:44:08 -0800581{
582 u8 stat8;
583
584 stat8 = info->buf_ferr;
Dave Petersone7ecd892006-03-26 01:38:52 -0800585
Dave Jiang203333c2007-07-19 01:50:06 -0700586 if (stat8 & 0x0f) { /* Error, so process */
Alan Cox806c35f2006-01-18 17:44:08 -0800587 stat8 &= 0x0f;
588 membuf_error(stat8, error_found, handle_error);
589 }
Dave Petersone7ecd892006-03-26 01:38:52 -0800590
Alan Cox806c35f2006-01-18 17:44:08 -0800591 stat8 = info->buf_nerr;
Dave Petersone7ecd892006-03-26 01:38:52 -0800592
Dave Jiang203333c2007-07-19 01:50:06 -0700593 if (stat8 & 0x0f) { /* Error, so process */
Alan Cox806c35f2006-01-18 17:44:08 -0800594 stat8 &= 0x0f;
595 membuf_error(stat8, error_found, handle_error);
596 }
597}
598
Dave Jiang203333c2007-07-19 01:50:06 -0700599static void e752x_check_dram(struct mem_ctl_info *mci,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700600 struct e752x_error_info *info, int *error_found,
601 int handle_error)
Alan Cox806c35f2006-01-18 17:44:08 -0800602{
603 u16 error_one, error_next;
604
605 error_one = info->dram_ferr;
606 error_next = info->dram_nerr;
607
608 /* decode and report errors */
Dave Jiang203333c2007-07-19 01:50:06 -0700609 if (error_one & 0x0101) /* check first error correctable */
Alan Cox806c35f2006-01-18 17:44:08 -0800610 process_ce(mci, error_one, info->dram_sec1_add,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700611 info->dram_sec1_syndrome, error_found, handle_error);
Alan Cox806c35f2006-01-18 17:44:08 -0800612
Dave Jiang203333c2007-07-19 01:50:06 -0700613 if (error_next & 0x0101) /* check next error correctable */
Alan Cox806c35f2006-01-18 17:44:08 -0800614 process_ce(mci, error_next, info->dram_sec2_add,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700615 info->dram_sec2_syndrome, error_found, handle_error);
Alan Cox806c35f2006-01-18 17:44:08 -0800616
Dave Jiang203333c2007-07-19 01:50:06 -0700617 if (error_one & 0x4040)
Alan Cox806c35f2006-01-18 17:44:08 -0800618 process_ue_no_info_wr(mci, error_found, handle_error);
619
Dave Jiang203333c2007-07-19 01:50:06 -0700620 if (error_next & 0x4040)
Alan Cox806c35f2006-01-18 17:44:08 -0800621 process_ue_no_info_wr(mci, error_found, handle_error);
622
Dave Jiang203333c2007-07-19 01:50:06 -0700623 if (error_one & 0x2020)
Alan Cox806c35f2006-01-18 17:44:08 -0800624 process_ded_retry(mci, error_one, info->dram_retr_add,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700625 error_found, handle_error);
Alan Cox806c35f2006-01-18 17:44:08 -0800626
Dave Jiang203333c2007-07-19 01:50:06 -0700627 if (error_next & 0x2020)
Alan Cox806c35f2006-01-18 17:44:08 -0800628 process_ded_retry(mci, error_next, info->dram_retr_add,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700629 error_found, handle_error);
Alan Cox806c35f2006-01-18 17:44:08 -0800630
Dave Jiang203333c2007-07-19 01:50:06 -0700631 if (error_one & 0x0808)
632 process_threshold_ce(mci, error_one, error_found, handle_error);
Alan Cox806c35f2006-01-18 17:44:08 -0800633
Dave Jiang203333c2007-07-19 01:50:06 -0700634 if (error_next & 0x0808)
Alan Cox806c35f2006-01-18 17:44:08 -0800635 process_threshold_ce(mci, error_next, error_found,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700636 handle_error);
Alan Cox806c35f2006-01-18 17:44:08 -0800637
Dave Jiang203333c2007-07-19 01:50:06 -0700638 if (error_one & 0x0606)
Alan Cox806c35f2006-01-18 17:44:08 -0800639 process_ue(mci, error_one, info->dram_ded_add,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700640 info->dram_scrb_add, error_found, handle_error);
Alan Cox806c35f2006-01-18 17:44:08 -0800641
Dave Jiang203333c2007-07-19 01:50:06 -0700642 if (error_next & 0x0606)
Alan Cox806c35f2006-01-18 17:44:08 -0800643 process_ue(mci, error_next, info->dram_ded_add,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700644 info->dram_scrb_add, error_found, handle_error);
Alan Cox806c35f2006-01-18 17:44:08 -0800645}
646
Dave Jiang203333c2007-07-19 01:50:06 -0700647static void e752x_get_error_info(struct mem_ctl_info *mci,
648 struct e752x_error_info *info)
Alan Cox806c35f2006-01-18 17:44:08 -0800649{
650 struct pci_dev *dev;
651 struct e752x_pvt *pvt;
652
653 memset(info, 0, sizeof(*info));
Dave Jiang203333c2007-07-19 01:50:06 -0700654 pvt = (struct e752x_pvt *)mci->pvt_info;
Alan Cox806c35f2006-01-18 17:44:08 -0800655 dev = pvt->dev_d0f1;
Alan Cox806c35f2006-01-18 17:44:08 -0800656 pci_read_config_dword(dev, E752X_FERR_GLOBAL, &info->ferr_global);
657
658 if (info->ferr_global) {
659 pci_read_config_byte(dev, E752X_HI_FERR, &info->hi_ferr);
660 pci_read_config_word(dev, E752X_SYSBUS_FERR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700661 &info->sysbus_ferr);
Alan Cox806c35f2006-01-18 17:44:08 -0800662 pci_read_config_byte(dev, E752X_BUF_FERR, &info->buf_ferr);
Dave Jiang203333c2007-07-19 01:50:06 -0700663 pci_read_config_word(dev, E752X_DRAM_FERR, &info->dram_ferr);
Alan Cox806c35f2006-01-18 17:44:08 -0800664 pci_read_config_dword(dev, E752X_DRAM_SEC1_ADD,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700665 &info->dram_sec1_add);
Alan Cox806c35f2006-01-18 17:44:08 -0800666 pci_read_config_word(dev, E752X_DRAM_SEC1_SYNDROME,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700667 &info->dram_sec1_syndrome);
Alan Cox806c35f2006-01-18 17:44:08 -0800668 pci_read_config_dword(dev, E752X_DRAM_DED_ADD,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700669 &info->dram_ded_add);
Alan Cox806c35f2006-01-18 17:44:08 -0800670 pci_read_config_dword(dev, E752X_DRAM_SCRB_ADD,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700671 &info->dram_scrb_add);
Alan Cox806c35f2006-01-18 17:44:08 -0800672 pci_read_config_dword(dev, E752X_DRAM_RETR_ADD,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700673 &info->dram_retr_add);
Alan Cox806c35f2006-01-18 17:44:08 -0800674
675 if (info->hi_ferr & 0x7f)
676 pci_write_config_byte(dev, E752X_HI_FERR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700677 info->hi_ferr);
Alan Cox806c35f2006-01-18 17:44:08 -0800678
679 if (info->sysbus_ferr)
680 pci_write_config_word(dev, E752X_SYSBUS_FERR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700681 info->sysbus_ferr);
Alan Cox806c35f2006-01-18 17:44:08 -0800682
683 if (info->buf_ferr & 0x0f)
684 pci_write_config_byte(dev, E752X_BUF_FERR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700685 info->buf_ferr);
Alan Cox806c35f2006-01-18 17:44:08 -0800686
687 if (info->dram_ferr)
688 pci_write_bits16(pvt->bridge_ck, E752X_DRAM_FERR,
Dave Jiang203333c2007-07-19 01:50:06 -0700689 info->dram_ferr, info->dram_ferr);
Alan Cox806c35f2006-01-18 17:44:08 -0800690
691 pci_write_config_dword(dev, E752X_FERR_GLOBAL,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700692 info->ferr_global);
Alan Cox806c35f2006-01-18 17:44:08 -0800693 }
694
695 pci_read_config_dword(dev, E752X_NERR_GLOBAL, &info->nerr_global);
696
697 if (info->nerr_global) {
698 pci_read_config_byte(dev, E752X_HI_NERR, &info->hi_nerr);
699 pci_read_config_word(dev, E752X_SYSBUS_NERR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700700 &info->sysbus_nerr);
Alan Cox806c35f2006-01-18 17:44:08 -0800701 pci_read_config_byte(dev, E752X_BUF_NERR, &info->buf_nerr);
Dave Jiang203333c2007-07-19 01:50:06 -0700702 pci_read_config_word(dev, E752X_DRAM_NERR, &info->dram_nerr);
Alan Cox806c35f2006-01-18 17:44:08 -0800703 pci_read_config_dword(dev, E752X_DRAM_SEC2_ADD,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700704 &info->dram_sec2_add);
Alan Cox806c35f2006-01-18 17:44:08 -0800705 pci_read_config_word(dev, E752X_DRAM_SEC2_SYNDROME,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700706 &info->dram_sec2_syndrome);
Alan Cox806c35f2006-01-18 17:44:08 -0800707
708 if (info->hi_nerr & 0x7f)
709 pci_write_config_byte(dev, E752X_HI_NERR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700710 info->hi_nerr);
Alan Cox806c35f2006-01-18 17:44:08 -0800711
712 if (info->sysbus_nerr)
713 pci_write_config_word(dev, E752X_SYSBUS_NERR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700714 info->sysbus_nerr);
Alan Cox806c35f2006-01-18 17:44:08 -0800715
716 if (info->buf_nerr & 0x0f)
717 pci_write_config_byte(dev, E752X_BUF_NERR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700718 info->buf_nerr);
Alan Cox806c35f2006-01-18 17:44:08 -0800719
720 if (info->dram_nerr)
721 pci_write_bits16(pvt->bridge_ck, E752X_DRAM_NERR,
Dave Jiang203333c2007-07-19 01:50:06 -0700722 info->dram_nerr, info->dram_nerr);
Alan Cox806c35f2006-01-18 17:44:08 -0800723
724 pci_write_config_dword(dev, E752X_NERR_GLOBAL,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700725 info->nerr_global);
Alan Cox806c35f2006-01-18 17:44:08 -0800726 }
727}
728
Dave Jiang203333c2007-07-19 01:50:06 -0700729static int e752x_process_error_info(struct mem_ctl_info *mci,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700730 struct e752x_error_info *info,
731 int handle_errors)
Alan Cox806c35f2006-01-18 17:44:08 -0800732{
733 u32 error32, stat32;
734 int error_found;
735
736 error_found = 0;
737 error32 = (info->ferr_global >> 18) & 0x3ff;
738 stat32 = (info->ferr_global >> 4) & 0x7ff;
739
740 if (error32)
741 global_error(1, error32, &error_found, handle_errors);
742
743 if (stat32)
744 global_error(0, stat32, &error_found, handle_errors);
745
746 error32 = (info->nerr_global >> 18) & 0x3ff;
747 stat32 = (info->nerr_global >> 4) & 0x7ff;
748
749 if (error32)
750 global_error(1, error32, &error_found, handle_errors);
751
752 if (stat32)
753 global_error(0, stat32, &error_found, handle_errors);
754
755 e752x_check_hub_interface(info, &error_found, handle_errors);
756 e752x_check_sysbus(info, &error_found, handle_errors);
757 e752x_check_membuf(info, &error_found, handle_errors);
758 e752x_check_dram(mci, info, &error_found, handle_errors);
759 return error_found;
760}
761
762static void e752x_check(struct mem_ctl_info *mci)
763{
764 struct e752x_error_info info;
Dave Petersone7ecd892006-03-26 01:38:52 -0800765
Dave Peterson537fba22006-03-26 01:38:40 -0800766 debugf3("%s()\n", __func__);
Alan Cox806c35f2006-01-18 17:44:08 -0800767 e752x_get_error_info(mci, &info);
768 e752x_process_error_info(mci, &info, 1);
769}
770
Doug Thompson13189522006-06-30 01:56:08 -0700771/* Return 1 if dual channel mode is active. Else return 0. */
772static inline int dual_channel_active(u16 ddrcsr)
Alan Cox806c35f2006-01-18 17:44:08 -0800773{
Doug Thompson13189522006-06-30 01:56:08 -0700774 return (((ddrcsr >> 12) & 3) == 3);
775}
776
777static void e752x_init_csrows(struct mem_ctl_info *mci, struct pci_dev *pdev,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700778 u16 ddrcsr)
Doug Thompson13189522006-06-30 01:56:08 -0700779{
780 struct csrow_info *csrow;
Alan Cox806c35f2006-01-18 17:44:08 -0800781 unsigned long last_cumul_size;
Doug Thompson13189522006-06-30 01:56:08 -0700782 int index, mem_dev, drc_chan;
Dave Jiang203333c2007-07-19 01:50:06 -0700783 int drc_drbg; /* DRB granularity 0=64mb, 1=128mb */
784 int drc_ddim; /* DRAM Data Integrity Mode 0=none, 2=edac */
Doug Thompson13189522006-06-30 01:56:08 -0700785 u8 value;
786 u32 dra, drc, cumul_size;
Alan Cox806c35f2006-01-18 17:44:08 -0800787
Brian Pomerantz9962fd02007-02-12 00:53:05 -0800788 dra = 0;
Dave Jiang203333c2007-07-19 01:50:06 -0700789 for (index = 0; index < 4; index++) {
Brian Pomerantz9962fd02007-02-12 00:53:05 -0800790 u8 dra_reg;
Dave Jiang203333c2007-07-19 01:50:06 -0700791 pci_read_config_byte(pdev, E752X_DRA + index, &dra_reg);
Brian Pomerantz9962fd02007-02-12 00:53:05 -0800792 dra |= dra_reg << (index * 8);
793 }
Alan Cox806c35f2006-01-18 17:44:08 -0800794 pci_read_config_dword(pdev, E752X_DRC, &drc);
Doug Thompson13189522006-06-30 01:56:08 -0700795 drc_chan = dual_channel_active(ddrcsr);
Dave Jiang203333c2007-07-19 01:50:06 -0700796 drc_drbg = drc_chan + 1; /* 128 in dual mode, 64 in single */
Alan Cox806c35f2006-01-18 17:44:08 -0800797 drc_ddim = (drc >> 20) & 0x3;
798
Doug Thompson13189522006-06-30 01:56:08 -0700799 /* The dram row boundary (DRB) reg values are boundary address for
Alan Cox806c35f2006-01-18 17:44:08 -0800800 * each DRAM row with a granularity of 64 or 128MB (single/dual
801 * channel operation). DRB regs are cumulative; therefore DRB7 will
802 * contain the total memory contained in all eight rows.
803 */
804 for (last_cumul_size = index = 0; index < mci->nr_csrows; index++) {
Alan Cox806c35f2006-01-18 17:44:08 -0800805 /* mem_dev 0=x8, 1=x4 */
Doug Thompson13189522006-06-30 01:56:08 -0700806 mem_dev = (dra >> (index * 4 + 2)) & 0x3;
807 csrow = &mci->csrows[index];
Alan Cox806c35f2006-01-18 17:44:08 -0800808
809 mem_dev = (mem_dev == 2);
Doug Thompson37f04582006-06-30 01:56:07 -0700810 pci_read_config_byte(pdev, E752X_DRB + index, &value);
Alan Cox806c35f2006-01-18 17:44:08 -0800811 /* convert a 128 or 64 MiB DRB to a page size. */
812 cumul_size = value << (25 + drc_drbg - PAGE_SHIFT);
Dave Peterson537fba22006-03-26 01:38:40 -0800813 debugf3("%s(): (%d) cumul_size 0x%x\n", __func__, index,
814 cumul_size);
Alan Cox806c35f2006-01-18 17:44:08 -0800815 if (cumul_size == last_cumul_size)
Doug Thompson13189522006-06-30 01:56:08 -0700816 continue; /* not populated */
Alan Cox806c35f2006-01-18 17:44:08 -0800817
818 csrow->first_page = last_cumul_size;
819 csrow->last_page = cumul_size - 1;
820 csrow->nr_pages = cumul_size - last_cumul_size;
821 last_cumul_size = cumul_size;
Doug Thompson13189522006-06-30 01:56:08 -0700822 csrow->grain = 1 << 12; /* 4KiB - resolution of CELOG */
823 csrow->mtype = MEM_RDDR; /* only one type supported */
Alan Cox806c35f2006-01-18 17:44:08 -0800824 csrow->dtype = mem_dev ? DEV_X4 : DEV_X8;
825
826 /*
827 * if single channel or x8 devices then SECDED
828 * if dual channel and x4 then S4ECD4ED
829 */
830 if (drc_ddim) {
831 if (drc_chan && mem_dev) {
832 csrow->edac_mode = EDAC_S4ECD4ED;
833 mci->edac_cap |= EDAC_FLAG_S4ECD4ED;
834 } else {
835 csrow->edac_mode = EDAC_SECDED;
836 mci->edac_cap |= EDAC_FLAG_SECDED;
837 }
838 } else
839 csrow->edac_mode = EDAC_NONE;
840 }
Doug Thompson13189522006-06-30 01:56:08 -0700841}
Alan Cox806c35f2006-01-18 17:44:08 -0800842
Doug Thompson13189522006-06-30 01:56:08 -0700843static void e752x_init_mem_map_table(struct pci_dev *pdev,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700844 struct e752x_pvt *pvt)
Doug Thompson13189522006-06-30 01:56:08 -0700845{
846 int index;
847 u8 value, last, row, stat8;
Alan Cox806c35f2006-01-18 17:44:08 -0800848
Doug Thompson13189522006-06-30 01:56:08 -0700849 last = 0;
850 row = 0;
Dave Petersone7ecd892006-03-26 01:38:52 -0800851
Doug Thompson13189522006-06-30 01:56:08 -0700852 for (index = 0; index < 8; index += 2) {
853 pci_read_config_byte(pdev, E752X_DRB + index, &value);
854 /* test if there is a dimm in this slot */
855 if (value == last) {
856 /* no dimm in the slot, so flag it as empty */
857 pvt->map[index] = 0xff;
858 pvt->map[index + 1] = 0xff;
Dave Jiang203333c2007-07-19 01:50:06 -0700859 } else { /* there is a dimm in the slot */
Doug Thompson13189522006-06-30 01:56:08 -0700860 pvt->map[index] = row;
861 row++;
862 last = value;
863 /* test the next value to see if the dimm is double
864 * sided
865 */
866 pci_read_config_byte(pdev, E752X_DRB + index + 1,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700867 &value);
868
869 /* the dimm is single sided, so flag as empty */
870 /* this is a double sided dimm to save the next row #*/
871 pvt->map[index + 1] = (value == last) ? 0xff : row;
Doug Thompson13189522006-06-30 01:56:08 -0700872 row++;
873 last = value;
Alan Cox806c35f2006-01-18 17:44:08 -0800874 }
875 }
876
877 /* set the map type. 1 = normal, 0 = reversed */
Doug Thompson37f04582006-06-30 01:56:07 -0700878 pci_read_config_byte(pdev, E752X_DRM, &stat8);
Alan Cox806c35f2006-01-18 17:44:08 -0800879 pvt->map_type = ((stat8 & 0x0f) > ((stat8 >> 4) & 0x0f));
Doug Thompson13189522006-06-30 01:56:08 -0700880}
881
882/* Return 0 on success or 1 on failure. */
883static int e752x_get_devs(struct pci_dev *pdev, int dev_idx,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700884 struct e752x_pvt *pvt)
Doug Thompson13189522006-06-30 01:56:08 -0700885{
886 struct pci_dev *dev;
887
888 pvt->bridge_ck = pci_get_device(PCI_VENDOR_ID_INTEL,
Dave Jiang203333c2007-07-19 01:50:06 -0700889 pvt->dev_info->err_dev, pvt->bridge_ck);
Doug Thompson13189522006-06-30 01:56:08 -0700890
891 if (pvt->bridge_ck == NULL)
892 pvt->bridge_ck = pci_scan_single_device(pdev->bus,
893 PCI_DEVFN(0, 1));
894
895 if (pvt->bridge_ck == NULL) {
896 e752x_printk(KERN_ERR, "error reporting device not found:"
Douglas Thompson052dfb42007-07-19 01:50:13 -0700897 "vendor %x device 0x%x (broken BIOS?)\n",
898 PCI_VENDOR_ID_INTEL, e752x_devs[dev_idx].err_dev);
Doug Thompson13189522006-06-30 01:56:08 -0700899 return 1;
900 }
901
902 dev = pci_get_device(PCI_VENDOR_ID_INTEL, e752x_devs[dev_idx].ctl_dev,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700903 NULL);
Doug Thompson13189522006-06-30 01:56:08 -0700904
905 if (dev == NULL)
906 goto fail;
907
908 pvt->dev_d0f0 = dev;
909 pvt->dev_d0f1 = pci_dev_get(pvt->bridge_ck);
910
911 return 0;
912
Douglas Thompson052dfb42007-07-19 01:50:13 -0700913fail:
Doug Thompson13189522006-06-30 01:56:08 -0700914 pci_dev_put(pvt->bridge_ck);
915 return 1;
916}
917
918static void e752x_init_error_reporting_regs(struct e752x_pvt *pvt)
919{
920 struct pci_dev *dev;
921
922 dev = pvt->dev_d0f1;
923 /* Turn off error disable & SMI in case the BIOS turned it on */
924 pci_write_config_byte(dev, E752X_HI_ERRMASK, 0x00);
925 pci_write_config_byte(dev, E752X_HI_SMICMD, 0x00);
926 pci_write_config_word(dev, E752X_SYSBUS_ERRMASK, 0x00);
927 pci_write_config_word(dev, E752X_SYSBUS_SMICMD, 0x00);
928 pci_write_config_byte(dev, E752X_BUF_ERRMASK, 0x00);
929 pci_write_config_byte(dev, E752X_BUF_SMICMD, 0x00);
930 pci_write_config_byte(dev, E752X_DRAM_ERRMASK, 0x00);
931 pci_write_config_byte(dev, E752X_DRAM_SMICMD, 0x00);
932}
933
934static int e752x_probe1(struct pci_dev *pdev, int dev_idx)
935{
936 u16 pci_data;
937 u8 stat8;
938 struct mem_ctl_info *mci;
939 struct e752x_pvt *pvt;
940 u16 ddrcsr;
Dave Jiang203333c2007-07-19 01:50:06 -0700941 int drc_chan; /* Number of channels 0=1chan,1=2chan */
Doug Thompson13189522006-06-30 01:56:08 -0700942 struct e752x_error_info discard;
943
944 debugf0("%s(): mci\n", __func__);
945 debugf0("Starting Probe1\n");
946
Dave Jiangc0d12172007-07-19 01:49:46 -0700947 /* make sure error reporting method is sane */
Dave Jiang203333c2007-07-19 01:50:06 -0700948 switch (edac_op_state) {
949 case EDAC_OPSTATE_POLL:
950 case EDAC_OPSTATE_NMI:
951 break;
952 default:
953 edac_op_state = EDAC_OPSTATE_POLL;
954 break;
Dave Jiangc0d12172007-07-19 01:49:46 -0700955 }
956
Doug Thompson13189522006-06-30 01:56:08 -0700957 /* check to see if device 0 function 1 is enabled; if it isn't, we
958 * assume the BIOS has reserved it for a reason and is expecting
959 * exclusive access, we take care not to violate that assumption and
960 * fail the probe. */
961 pci_read_config_byte(pdev, E752X_DEVPRES1, &stat8);
962 if (!force_function_unhide && !(stat8 & (1 << 5))) {
963 printk(KERN_INFO "Contact your BIOS vendor to see if the "
Douglas Thompson052dfb42007-07-19 01:50:13 -0700964 "E752x error registers can be safely un-hidden\n");
Doug Thompson13189522006-06-30 01:56:08 -0700965 return -ENOMEM;
966 }
967 stat8 |= (1 << 5);
968 pci_write_config_byte(pdev, E752X_DEVPRES1, stat8);
969
970 pci_read_config_word(pdev, E752X_DDRCSR, &ddrcsr);
971 /* FIXME: should check >>12 or 0xf, true for all? */
972 /* Dual channel = 1, Single channel = 0 */
973 drc_chan = dual_channel_active(ddrcsr);
974
975 mci = edac_mc_alloc(sizeof(*pvt), E752X_NR_CSROWS, drc_chan + 1);
976
977 if (mci == NULL) {
978 return -ENOMEM;
979 }
980
981 debugf3("%s(): init mci\n", __func__);
982 mci->mtype_cap = MEM_FLAG_RDDR;
983 mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED |
Douglas Thompson052dfb42007-07-19 01:50:13 -0700984 EDAC_FLAG_S4ECD4ED;
Doug Thompson13189522006-06-30 01:56:08 -0700985 /* FIXME - what if different memory types are in different csrows? */
986 mci->mod_name = EDAC_MOD_STR;
987 mci->mod_ver = E752X_REVISION;
988 mci->dev = &pdev->dev;
989
990 debugf3("%s(): init pvt\n", __func__);
Dave Jiang203333c2007-07-19 01:50:06 -0700991 pvt = (struct e752x_pvt *)mci->pvt_info;
Doug Thompson13189522006-06-30 01:56:08 -0700992 pvt->dev_info = &e752x_devs[dev_idx];
993 pvt->mc_symmetric = ((ddrcsr & 0x10) != 0);
994
995 if (e752x_get_devs(pdev, dev_idx, pvt)) {
996 edac_mc_free(mci);
997 return -ENODEV;
998 }
999
1000 debugf3("%s(): more mci init\n", __func__);
1001 mci->ctl_name = pvt->dev_info->ctl_name;
Dave Jiangc4192702007-07-19 01:49:47 -07001002 mci->dev_name = pci_name(pdev);
Doug Thompson13189522006-06-30 01:56:08 -07001003 mci->edac_check = e752x_check;
1004 mci->ctl_page_to_phys = ctl_page_to_phys;
1005
1006 e752x_init_csrows(mci, pdev, ddrcsr);
1007 e752x_init_mem_map_table(pdev, pvt);
1008
1009 /* set the map type. 1 = normal, 0 = reversed */
1010 pci_read_config_byte(pdev, E752X_DRM, &stat8);
1011 pvt->map_type = ((stat8 & 0x0f) > ((stat8 >> 4) & 0x0f));
Alan Cox806c35f2006-01-18 17:44:08 -08001012
1013 mci->edac_cap |= EDAC_FLAG_NONE;
Dave Peterson537fba22006-03-26 01:38:40 -08001014 debugf3("%s(): tolm, remapbase, remaplimit\n", __func__);
Dave Petersone7ecd892006-03-26 01:38:52 -08001015
Alan Cox806c35f2006-01-18 17:44:08 -08001016 /* load the top of low memory, remap base, and remap limit vars */
Doug Thompson37f04582006-06-30 01:56:07 -07001017 pci_read_config_word(pdev, E752X_TOLM, &pci_data);
Alan Cox806c35f2006-01-18 17:44:08 -08001018 pvt->tolm = ((u32) pci_data) << 4;
Doug Thompson37f04582006-06-30 01:56:07 -07001019 pci_read_config_word(pdev, E752X_REMAPBASE, &pci_data);
Alan Cox806c35f2006-01-18 17:44:08 -08001020 pvt->remapbase = ((u32) pci_data) << 14;
Doug Thompson37f04582006-06-30 01:56:07 -07001021 pci_read_config_word(pdev, E752X_REMAPLIMIT, &pci_data);
Alan Cox806c35f2006-01-18 17:44:08 -08001022 pvt->remaplimit = ((u32) pci_data) << 14;
Dave Peterson537fba22006-03-26 01:38:40 -08001023 e752x_printk(KERN_INFO,
Douglas Thompson052dfb42007-07-19 01:50:13 -07001024 "tolm = %x, remapbase = %x, remaplimit = %x\n",
1025 pvt->tolm, pvt->remapbase, pvt->remaplimit);
Alan Cox806c35f2006-01-18 17:44:08 -08001026
Doug Thompson2d7bbb92006-06-30 01:56:08 -07001027 /* Here we assume that we will never see multiple instances of this
1028 * type of memory controller. The ID is therefore hardcoded to 0.
1029 */
Dave Jiang203333c2007-07-19 01:50:06 -07001030 if (edac_mc_add_mc(mci, 0)) {
Dave Peterson537fba22006-03-26 01:38:40 -08001031 debugf3("%s(): failed edac_mc_add_mc()\n", __func__);
Alan Cox806c35f2006-01-18 17:44:08 -08001032 goto fail;
1033 }
1034
Doug Thompson13189522006-06-30 01:56:08 -07001035 e752x_init_error_reporting_regs(pvt);
Dave Jiang203333c2007-07-19 01:50:06 -07001036 e752x_get_error_info(mci, &discard); /* clear other MCH errors */
Alan Cox806c35f2006-01-18 17:44:08 -08001037
Dave Jiang91b99042007-07-19 01:49:52 -07001038 /* allocating generic PCI control info */
1039 e752x_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
1040 if (!e752x_pci) {
1041 printk(KERN_WARNING
Douglas Thompson052dfb42007-07-19 01:50:13 -07001042 "%s(): Unable to create PCI control\n", __func__);
Dave Jiang91b99042007-07-19 01:49:52 -07001043 printk(KERN_WARNING
Douglas Thompson052dfb42007-07-19 01:50:13 -07001044 "%s(): PCI error report via EDAC not setup\n",
1045 __func__);
Dave Jiang91b99042007-07-19 01:49:52 -07001046 }
1047
Alan Cox806c35f2006-01-18 17:44:08 -08001048 /* get this far and it's successful */
Dave Peterson537fba22006-03-26 01:38:40 -08001049 debugf3("%s(): success\n", __func__);
Alan Cox806c35f2006-01-18 17:44:08 -08001050 return 0;
1051
Douglas Thompson052dfb42007-07-19 01:50:13 -07001052fail:
Doug Thompson13189522006-06-30 01:56:08 -07001053 pci_dev_put(pvt->dev_d0f0);
1054 pci_dev_put(pvt->dev_d0f1);
1055 pci_dev_put(pvt->bridge_ck);
1056 edac_mc_free(mci);
Dave Petersone7ecd892006-03-26 01:38:52 -08001057
Doug Thompson13189522006-06-30 01:56:08 -07001058 return -ENODEV;
Alan Cox806c35f2006-01-18 17:44:08 -08001059}
1060
1061/* returns count (>= 0), or negative on error */
1062static int __devinit e752x_init_one(struct pci_dev *pdev,
Douglas Thompson052dfb42007-07-19 01:50:13 -07001063 const struct pci_device_id *ent)
Alan Cox806c35f2006-01-18 17:44:08 -08001064{
Dave Peterson537fba22006-03-26 01:38:40 -08001065 debugf0("%s()\n", __func__);
Alan Cox806c35f2006-01-18 17:44:08 -08001066
1067 /* wake up and enable device */
Dave Jiang203333c2007-07-19 01:50:06 -07001068 if (pci_enable_device(pdev) < 0)
Alan Cox806c35f2006-01-18 17:44:08 -08001069 return -EIO;
Dave Petersone7ecd892006-03-26 01:38:52 -08001070
Alan Cox806c35f2006-01-18 17:44:08 -08001071 return e752x_probe1(pdev, ent->driver_data);
1072}
1073
Alan Cox806c35f2006-01-18 17:44:08 -08001074static void __devexit e752x_remove_one(struct pci_dev *pdev)
1075{
1076 struct mem_ctl_info *mci;
1077 struct e752x_pvt *pvt;
1078
Dave Peterson537fba22006-03-26 01:38:40 -08001079 debugf0("%s()\n", __func__);
Alan Cox806c35f2006-01-18 17:44:08 -08001080
Dave Jiang91b99042007-07-19 01:49:52 -07001081 if (e752x_pci)
1082 edac_pci_release_generic_ctl(e752x_pci);
1083
Doug Thompson37f04582006-06-30 01:56:07 -07001084 if ((mci = edac_mc_del_mc(&pdev->dev)) == NULL)
Alan Cox806c35f2006-01-18 17:44:08 -08001085 return;
1086
Dave Jiang203333c2007-07-19 01:50:06 -07001087 pvt = (struct e752x_pvt *)mci->pvt_info;
Alan Cox806c35f2006-01-18 17:44:08 -08001088 pci_dev_put(pvt->dev_d0f0);
1089 pci_dev_put(pvt->dev_d0f1);
1090 pci_dev_put(pvt->bridge_ck);
1091 edac_mc_free(mci);
1092}
1093
Alan Cox806c35f2006-01-18 17:44:08 -08001094static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
Dave Petersone7ecd892006-03-26 01:38:52 -08001095 {
Dave Jiang203333c2007-07-19 01:50:06 -07001096 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1097 E7520},
Dave Petersone7ecd892006-03-26 01:38:52 -08001098 {
Dave Jiang203333c2007-07-19 01:50:06 -07001099 PCI_VEND_DEV(INTEL, 7525_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1100 E7525},
Dave Petersone7ecd892006-03-26 01:38:52 -08001101 {
Dave Jiang203333c2007-07-19 01:50:06 -07001102 PCI_VEND_DEV(INTEL, 7320_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1103 E7320},
Dave Petersone7ecd892006-03-26 01:38:52 -08001104 {
Dave Jiang203333c2007-07-19 01:50:06 -07001105 0,
1106 } /* 0 terminated list. */
Alan Cox806c35f2006-01-18 17:44:08 -08001107};
1108
1109MODULE_DEVICE_TABLE(pci, e752x_pci_tbl);
1110
Alan Cox806c35f2006-01-18 17:44:08 -08001111static struct pci_driver e752x_driver = {
Dave Peterson680cbbb2006-03-26 01:38:41 -08001112 .name = EDAC_MOD_STR,
Randy Dunlap0d38b042006-02-03 03:04:24 -08001113 .probe = e752x_init_one,
1114 .remove = __devexit_p(e752x_remove_one),
1115 .id_table = e752x_pci_tbl,
Alan Cox806c35f2006-01-18 17:44:08 -08001116};
1117
Alan Coxda9bb1d2006-01-18 17:44:13 -08001118static int __init e752x_init(void)
Alan Cox806c35f2006-01-18 17:44:08 -08001119{
1120 int pci_rc;
1121
Dave Peterson537fba22006-03-26 01:38:40 -08001122 debugf3("%s()\n", __func__);
Alan Cox806c35f2006-01-18 17:44:08 -08001123 pci_rc = pci_register_driver(&e752x_driver);
1124 return (pci_rc < 0) ? pci_rc : 0;
1125}
1126
Alan Cox806c35f2006-01-18 17:44:08 -08001127static void __exit e752x_exit(void)
1128{
Dave Peterson537fba22006-03-26 01:38:40 -08001129 debugf3("%s()\n", __func__);
Alan Cox806c35f2006-01-18 17:44:08 -08001130 pci_unregister_driver(&e752x_driver);
1131}
1132
Alan Cox806c35f2006-01-18 17:44:08 -08001133module_init(e752x_init);
1134module_exit(e752x_exit);
1135
1136MODULE_LICENSE("GPL");
1137MODULE_AUTHOR("Linux Networx (http://lnxi.com) Tom Zimmerman\n");
1138MODULE_DESCRIPTION("MC support for Intel e752x memory controllers");
mark gross96941022006-05-03 19:55:07 -07001139
1140module_param(force_function_unhide, int, 0444);
1141MODULE_PARM_DESC(force_function_unhide, "if BIOS sets Dev0:Fun1 up as hidden:"
Dave Jiang203333c2007-07-19 01:50:06 -07001142 " 1=force unhide and hope BIOS doesn't fight driver for Dev0:Fun1 access");
Dave Jiangc0d12172007-07-19 01:49:46 -07001143module_param(edac_op_state, int, 0444);
1144MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");