e752x_edac.c 36.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Intel e752x Memory Controller kernel module
 * (C) 2004 Linux Networx (http://lnxi.com)
 * This file may be distributed under the terms of the
 * GNU General Public License.
 *
 * See "enum e752x_chips" below for supported chipsets
 *
 * Written by Tom Zimmerman
 *
 * Contributors:
 * 	Thayne Harbaugh at realmsys.com (?)
 * 	Wang Zhenyu at intel.com
 * 	Dave Jiang at mvista.com
 *
A
Alan Cox 已提交
16
 * $Id: edac_e752x.c,v 1.5.2.11 2005/10/05 00:43:44 dsp_llnl Exp $
17 18 19 20 21 22 23 24
 *
 */

#include <linux/module.h>
#include <linux/init.h>
#include <linux/pci.h>
#include <linux/pci_ids.h>
#include <linux/slab.h>
D
Dave Jiang 已提交
25
#include <linux/edac.h>
26
#include "edac_core.h"
27

28
#define E752X_REVISION	" Ver: 2.0.2 " __DATE__
29
#define EDAC_MOD_STR	"e752x_edac"
30

31
static int report_non_memory_errors;
M
mark gross 已提交
32
static int force_function_unhide;
33
static int sysbus_parity = -1;
M
mark gross 已提交
34

35 36
static struct edac_pci_ctl_info *e752x_pci;

D
Dave Peterson 已提交
37
#define e752x_printk(level, fmt, arg...) \
D
Dave Peterson 已提交
38
	edac_printk(level, "e752x", fmt, ##arg)
D
Dave Peterson 已提交
39 40

#define e752x_mc_printk(mci, level, fmt, arg...) \
D
Dave Peterson 已提交
41
	edac_mc_chipset_printk(mci, level, "e752x", fmt, ##arg)
D
Dave Peterson 已提交
42

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
#ifndef PCI_DEVICE_ID_INTEL_7520_0
#define PCI_DEVICE_ID_INTEL_7520_0      0x3590
#endif				/* PCI_DEVICE_ID_INTEL_7520_0      */

#ifndef PCI_DEVICE_ID_INTEL_7520_1_ERR
#define PCI_DEVICE_ID_INTEL_7520_1_ERR  0x3591
#endif				/* PCI_DEVICE_ID_INTEL_7520_1_ERR  */

#ifndef PCI_DEVICE_ID_INTEL_7525_0
#define PCI_DEVICE_ID_INTEL_7525_0      0x359E
#endif				/* PCI_DEVICE_ID_INTEL_7525_0      */

#ifndef PCI_DEVICE_ID_INTEL_7525_1_ERR
#define PCI_DEVICE_ID_INTEL_7525_1_ERR  0x3593
#endif				/* PCI_DEVICE_ID_INTEL_7525_1_ERR  */

#ifndef PCI_DEVICE_ID_INTEL_7320_0
#define PCI_DEVICE_ID_INTEL_7320_0	0x3592
#endif				/* PCI_DEVICE_ID_INTEL_7320_0 */

#ifndef PCI_DEVICE_ID_INTEL_7320_1_ERR
#define PCI_DEVICE_ID_INTEL_7320_1_ERR	0x3593
#endif				/* PCI_DEVICE_ID_INTEL_7320_1_ERR */

67 68 69 70 71 72 73 74
#ifndef PCI_DEVICE_ID_INTEL_3100_0
#define PCI_DEVICE_ID_INTEL_3100_0	0x35B0
#endif				/* PCI_DEVICE_ID_INTEL_3100_0 */

#ifndef PCI_DEVICE_ID_INTEL_3100_1_ERR
#define PCI_DEVICE_ID_INTEL_3100_1_ERR	0x35B1
#endif				/* PCI_DEVICE_ID_INTEL_3100_1_ERR */

75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
#define E752X_NR_CSROWS		8	/* number of csrows */

/* E752X register addresses - device 0 function 0 */
#define E752X_DRB		0x60	/* DRAM row boundary register (8b) */
#define E752X_DRA		0x70	/* DRAM row attribute register (8b) */
					/*
					 * 31:30   Device width row 7
					 *      01=x8 10=x4 11=x8 DDR2
					 * 27:26   Device width row 6
					 * 23:22   Device width row 5
					 * 19:20   Device width row 4
					 * 15:14   Device width row 3
					 * 11:10   Device width row 2
					 *  7:6    Device width row 1
					 *  3:2    Device width row 0
					 */
#define E752X_DRC		0x7C	/* DRAM controller mode reg (32b) */
					/* FIXME:IS THIS RIGHT? */
					/*
					 * 22    Number channels 0=1,1=2
					 * 19:18 DRB Granularity 32/64MB
					 */
#define E752X_DRM		0x80	/* Dimm mapping register */
#define E752X_DDRCSR		0x9A	/* DDR control and status reg (16b) */
					/*
					 * 14:12 1 single A, 2 single B, 3 dual
					 */
#define E752X_TOLM		0xC4	/* DRAM top of low memory reg (16b) */
#define E752X_REMAPBASE		0xC6	/* DRAM remap base address reg (16b) */
#define E752X_REMAPLIMIT	0xC8	/* DRAM remap limit address reg (16b) */
#define E752X_REMAPOFFSET	0xCA	/* DRAM remap limit offset reg (16b) */

/* E752X register addresses - device 0 function 1 */
#define E752X_FERR_GLOBAL	0x40	/* Global first error register (32b) */
#define E752X_NERR_GLOBAL	0x44	/* Global next error register (32b) */
#define E752X_HI_FERR		0x50	/* Hub interface first error reg (8b) */
#define E752X_HI_NERR		0x52	/* Hub interface next error reg (8b) */
#define E752X_HI_ERRMASK	0x54	/* Hub interface error mask reg (8b) */
#define E752X_HI_SMICMD		0x5A	/* Hub interface SMI command reg (8b) */
#define E752X_SYSBUS_FERR	0x60	/* System buss first error reg (16b) */
#define E752X_SYSBUS_NERR	0x62	/* System buss next error reg (16b) */
#define E752X_SYSBUS_ERRMASK	0x64	/* System buss error mask reg (16b) */
#define E752X_SYSBUS_SMICMD	0x6A	/* System buss SMI command reg (16b) */
#define E752X_BUF_FERR		0x70	/* Memory buffer first error reg (8b) */
#define E752X_BUF_NERR		0x72	/* Memory buffer next error reg (8b) */
#define E752X_BUF_ERRMASK	0x74	/* Memory buffer error mask reg (8b) */
121
#define E752X_BUF_SMICMD	0x7A	/* Memory buffer SMI cmd reg (8b) */
122 123 124 125 126 127 128 129 130
#define E752X_DRAM_FERR		0x80	/* DRAM first error register (16b) */
#define E752X_DRAM_NERR		0x82	/* DRAM next error register (16b) */
#define E752X_DRAM_ERRMASK	0x84	/* DRAM error mask register (8b) */
#define E752X_DRAM_SMICMD	0x8A	/* DRAM SMI command register (8b) */
#define E752X_DRAM_RETR_ADD	0xAC	/* DRAM Retry address register (32b) */
#define E752X_DRAM_SEC1_ADD	0xA0	/* DRAM first correctable memory */
					/*     error address register (32b) */
					/*
					 * 31    Reserved
131
					 * 30:2  CE address (64 byte block 34:6
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
					 * 1     Reserved
					 * 0     HiLoCS
					 */
#define E752X_DRAM_SEC2_ADD	0xC8	/* DRAM first correctable memory */
					/*     error address register (32b) */
					/*
					 * 31    Reserved
					 * 30:2  CE address (64 byte block 34:6)
					 * 1     Reserved
					 * 0     HiLoCS
					 */
#define E752X_DRAM_DED_ADD	0xA4	/* DRAM first uncorrectable memory */
					/*     error address register (32b) */
					/*
					 * 31    Reserved
					 * 30:2  CE address (64 byte block 34:6)
					 * 1     Reserved
					 * 0     HiLoCS
					 */
151
#define E752X_DRAM_SCRB_ADD	0xA8	/* DRAM 1st uncorrectable scrub mem */
152 153 154
					/*     error address register (32b) */
					/*
					 * 31    Reserved
155
					 * 30:2  CE address (64 byte block 34:6
156 157 158 159 160 161 162 163 164
					 * 1     Reserved
					 * 0     HiLoCS
					 */
#define E752X_DRAM_SEC1_SYNDROME 0xC4	/* DRAM first correctable memory */
					/*     error syndrome register (16b) */
#define E752X_DRAM_SEC2_SYNDROME 0xC6	/* DRAM second correctable memory */
					/*     error syndrome register (16b) */
#define E752X_DEVPRES1		0xF4	/* Device Present 1 register (8b) */

165 166 167 168 169 170
/* 3100 IMCH specific register addresses - device 0 function 1 */
#define I3100_NSI_FERR		0x48	/* NSI first error reg (32b) */
#define I3100_NSI_NERR		0x4C	/* NSI next error reg (32b) */
#define I3100_NSI_SMICMD	0x54	/* NSI SMI command register (32b) */
#define I3100_NSI_EMASK		0x90	/* NSI error mask register (32b) */

171 172 173 174 175 176 177 178
/* ICH5R register addresses - device 30 function 0 */
#define ICH5R_PCI_STAT		0x06	/* PCI status register (16b) */
#define ICH5R_PCI_2ND_STAT	0x1E	/* PCI status secondary reg (16b) */
#define ICH5R_PCI_BRIDGE_CTL	0x3E	/* PCI bridge control register (16b) */

enum e752x_chips {
	E7520 = 0,
	E7525 = 1,
179 180
	E7320 = 2,
	I3100 = 3
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
};

struct e752x_pvt {
	struct pci_dev *bridge_ck;
	struct pci_dev *dev_d0f0;
	struct pci_dev *dev_d0f1;
	u32 tolm;
	u32 remapbase;
	u32 remaplimit;
	int mc_symmetric;
	u8 map[8];
	int map_type;
	const struct e752x_dev_info *dev_info;
};

struct e752x_dev_info {
	u16 err_dev;
D
Dave Peterson 已提交
198
	u16 ctl_dev;
199 200 201 202 203 204
	const char *ctl_name;
};

struct e752x_error_info {
	u32 ferr_global;
	u32 nerr_global;
205 206 207 208
	u32 nsi_ferr;	/* 3100 only */
	u32 nsi_nerr;	/* 3100 only */
	u8 hi_ferr;	/* all but 3100 */
	u8 hi_nerr;	/* all but 3100 */
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
	u16 sysbus_ferr;
	u16 sysbus_nerr;
	u8 buf_ferr;
	u8 buf_nerr;
	u16 dram_ferr;
	u16 dram_nerr;
	u32 dram_sec1_add;
	u32 dram_sec2_add;
	u16 dram_sec1_syndrome;
	u16 dram_sec2_syndrome;
	u32 dram_ded_add;
	u32 dram_scrb_add;
	u32 dram_retr_add;
};

static const struct e752x_dev_info e752x_devs[] = {
	[E7520] = {
226 227 228
		.err_dev = PCI_DEVICE_ID_INTEL_7520_1_ERR,
		.ctl_dev = PCI_DEVICE_ID_INTEL_7520_0,
		.ctl_name = "E7520"},
229
	[E7525] = {
230 231 232
		.err_dev = PCI_DEVICE_ID_INTEL_7525_1_ERR,
		.ctl_dev = PCI_DEVICE_ID_INTEL_7525_0,
		.ctl_name = "E7525"},
233
	[E7320] = {
234 235 236
		.err_dev = PCI_DEVICE_ID_INTEL_7320_1_ERR,
		.ctl_dev = PCI_DEVICE_ID_INTEL_7320_0,
		.ctl_name = "E7320"},
237 238 239 240
	[I3100] = {
		.err_dev = PCI_DEVICE_ID_INTEL_3100_1_ERR,
		.ctl_dev = PCI_DEVICE_ID_INTEL_3100_0,
		.ctl_name = "3100"},
241 242 243
};

static unsigned long ctl_page_to_phys(struct mem_ctl_info *mci,
244
				unsigned long page)
245 246
{
	u32 remap;
D
Dave Jiang 已提交
247
	struct e752x_pvt *pvt = (struct e752x_pvt *)mci->pvt_info;
248

D
Dave Peterson 已提交
249
	debugf3("%s()\n", __func__);
250 251 252

	if (page < pvt->tolm)
		return page;
D
Dave Peterson 已提交
253

254 255
	if ((page >= 0x100000) && (page < pvt->remapbase))
		return page;
D
Dave Peterson 已提交
256

257
	remap = (page - pvt->tolm) + pvt->remapbase;
D
Dave Peterson 已提交
258

259 260
	if (remap < pvt->remaplimit)
		return remap;
D
Dave Peterson 已提交
261

D
Dave Peterson 已提交
262
	e752x_printk(KERN_ERR, "Invalid page %lx - out of range\n", page);
263 264 265 266
	return pvt->tolm - 1;
}

static void do_process_ce(struct mem_ctl_info *mci, u16 error_one,
267
			u32 sec1_add, u16 sec1_syndrome)
268 269 270 271 272
{
	u32 page;
	int row;
	int channel;
	int i;
D
Dave Jiang 已提交
273
	struct e752x_pvt *pvt = (struct e752x_pvt *)mci->pvt_info;
274

D
Dave Peterson 已提交
275
	debugf3("%s()\n", __func__);
276 277 278 279 280 281 282 283

	/* convert the addr to 4k page */
	page = sec1_add >> (PAGE_SHIFT - 4);

	/* FIXME - check for -1 */
	if (pvt->mc_symmetric) {
		/* chip select are bits 14 & 13 */
		row = ((page >> 1) & 3);
D
Dave Peterson 已提交
284
		e752x_printk(KERN_WARNING,
285 286 287 288
			"Test row %d Table %d %d %d %d %d %d %d %d\n", row,
			pvt->map[0], pvt->map[1], pvt->map[2], pvt->map[3],
			pvt->map[4], pvt->map[5], pvt->map[6],
			pvt->map[7]);
289 290 291 292 293 294

		/* test for channel remapping */
		for (i = 0; i < 8; i++) {
			if (pvt->map[i] == row)
				break;
		}
D
Dave Peterson 已提交
295

D
Dave Peterson 已提交
296
		e752x_printk(KERN_WARNING, "Test computed row %d\n", i);
D
Dave Peterson 已提交
297

298 299 300
		if (i < 8)
			row = i;
		else
D
Dave Peterson 已提交
301
			e752x_mc_printk(mci, KERN_WARNING,
D
Dave Jiang 已提交
302 303
					"row %d not found in remap table\n",
					row);
304 305
	} else
		row = edac_mc_find_csrow_by_page(mci, page);
D
Dave Peterson 已提交
306

307 308 309
	/* 0 = channel A, 1 = channel B */
	channel = !(error_one & 1);

M
Mike Chan 已提交
310 311
	/* e752x mc reads 34:6 of the DRAM linear address */
	edac_mc_handle_ce(mci, page, offset_in_page(sec1_add << 4),
312
			sec1_syndrome, row, channel, "e752x CE");
313 314 315
}

static inline void process_ce(struct mem_ctl_info *mci, u16 error_one,
316 317
			u32 sec1_add, u16 sec1_syndrome, int *error_found,
			int handle_error)
318 319 320 321 322 323 324
{
	*error_found = 1;

	if (handle_error)
		do_process_ce(mci, error_one, sec1_add, sec1_syndrome);
}

D
Dave Peterson 已提交
325
static void do_process_ue(struct mem_ctl_info *mci, u16 error_one,
326
			u32 ded_add, u32 scrb_add)
327 328 329
{
	u32 error_2b, block_page;
	int row;
D
Dave Jiang 已提交
330
	struct e752x_pvt *pvt = (struct e752x_pvt *)mci->pvt_info;
331

D
Dave Peterson 已提交
332
	debugf3("%s()\n", __func__);
333 334 335

	if (error_one & 0x0202) {
		error_2b = ded_add;
D
Dave Peterson 已提交
336

337 338
		/* convert to 4k address */
		block_page = error_2b >> (PAGE_SHIFT - 4);
D
Dave Peterson 已提交
339

340
		row = pvt->mc_symmetric ?
341 342 343
		/* chip select are bits 14 & 13 */
			((block_page >> 1) & 3) :
			edac_mc_find_csrow_by_page(mci, block_page);
D
Dave Peterson 已提交
344

M
Mike Chan 已提交
345 346
		/* e752x mc reads 34:6 of the DRAM linear address */
		edac_mc_handle_ue(mci, block_page,
347 348
				offset_in_page(error_2b << 4),
				row, "e752x UE from Read");
349 350 351
	}
	if (error_one & 0x0404) {
		error_2b = scrb_add;
D
Dave Peterson 已提交
352

353 354
		/* convert to 4k address */
		block_page = error_2b >> (PAGE_SHIFT - 4);
D
Dave Peterson 已提交
355

356
		row = pvt->mc_symmetric ?
357 358 359
		/* chip select are bits 14 & 13 */
			((block_page >> 1) & 3) :
			edac_mc_find_csrow_by_page(mci, block_page);
D
Dave Peterson 已提交
360

M
Mike Chan 已提交
361 362
		/* e752x mc reads 34:6 of the DRAM linear address */
		edac_mc_handle_ue(mci, block_page,
363 364
				offset_in_page(error_2b << 4),
				row, "e752x UE from Scruber");
365 366 367 368
	}
}

static inline void process_ue(struct mem_ctl_info *mci, u16 error_one,
369 370
			u32 ded_add, u32 scrb_add, int *error_found,
			int handle_error)
371 372 373 374 375 376 377 378
{
	*error_found = 1;

	if (handle_error)
		do_process_ue(mci, error_one, ded_add, scrb_add);
}

static inline void process_ue_no_info_wr(struct mem_ctl_info *mci,
D
Dave Jiang 已提交
379
					 int *error_found, int handle_error)
380 381 382 383 384 385
{
	*error_found = 1;

	if (!handle_error)
		return;

D
Dave Peterson 已提交
386
	debugf3("%s()\n", __func__);
387 388 389 390
	edac_mc_handle_ue_no_info(mci, "e752x UE log memory write");
}

static void do_process_ded_retry(struct mem_ctl_info *mci, u16 error,
D
Dave Jiang 已提交
391
				 u32 retry_add)
392 393 394
{
	u32 error_1b, page;
	int row;
D
Dave Jiang 已提交
395
	struct e752x_pvt *pvt = (struct e752x_pvt *)mci->pvt_info;
396 397

	error_1b = retry_add;
398 399 400 401
	page = error_1b >> (PAGE_SHIFT - 4);  /* convert the addr to 4k page */

	/* chip select are bits 14 & 13 */
	row = pvt->mc_symmetric ? ((page >> 1) & 3) :
402
		edac_mc_find_csrow_by_page(mci, page);
403

D
Dave Peterson 已提交
404
	e752x_mc_printk(mci, KERN_WARNING,
D
Dave Jiang 已提交
405 406
			"CE page 0x%lx, row %d : Memory read retry\n",
			(long unsigned int)page, row);
407 408 409
}

static inline void process_ded_retry(struct mem_ctl_info *mci, u16 error,
410 411
				u32 retry_add, int *error_found,
				int handle_error)
412 413 414 415 416 417 418 419
{
	*error_found = 1;

	if (handle_error)
		do_process_ded_retry(mci, error, retry_add);
}

static inline void process_threshold_ce(struct mem_ctl_info *mci, u16 error,
D
Dave Jiang 已提交
420
					int *error_found, int handle_error)
421 422 423 424
{
	*error_found = 1;

	if (handle_error)
D
Dave Peterson 已提交
425
		e752x_mc_printk(mci, KERN_WARNING, "Memory threshold CE\n");
426 427
}

A
Alan Cox 已提交
428
static char *global_message[11] = {
429 430 431 432 433 434 435 436 437 438 439
	"PCI Express C1",
	"PCI Express C",
	"PCI Express B1",
	"PCI Express B",
	"PCI Express A1",
	"PCI Express A",
	"DMA Controller",
	"HUB or NS Interface",
	"System Bus",
	"DRAM Controller",  /* 9th entry */
	"Internal Buffer"
440 441
};

442 443
#define DRAM_ENTRY	9

A
Alan Cox 已提交
444
static char *fatal_message[2] = { "Non-Fatal ", "Fatal " };
445 446 447 448 449 450

static void do_global_error(int fatal, u32 errors)
{
	int i;

	for (i = 0; i < 11; i++) {
451 452 453 454 455 456 457 458 459 460
		if (errors & (1 << i)) {
			/* If the error is from DRAM Controller OR
			 * we are to report ALL errors, then
			 * report the error
			 */
			if ((i == DRAM_ENTRY) || report_non_memory_errors)
				e752x_printk(KERN_WARNING, "%sError %s\n",
					fatal_message[fatal],
					global_message[i]);
		}
461 462 463 464
	}
}

static inline void global_error(int fatal, u32 errors, int *error_found,
D
Dave Jiang 已提交
465
				int handle_error)
466 467 468 469 470 471 472
{
	*error_found = 1;

	if (handle_error)
		do_global_error(fatal, errors);
}

A
Alan Cox 已提交
473
static char *hub_message[7] = {
474 475 476 477 478 479 480 481 482 483 484 485
	"HI Address or Command Parity", "HI Illegal Access",
	"HI Internal Parity", "Out of Range Access",
	"HI Data Parity", "Enhanced Config Access",
	"Hub Interface Target Abort"
};

static void do_hub_error(int fatal, u8 errors)
{
	int i;

	for (i = 0; i < 7; i++) {
		if (errors & (1 << i))
D
Dave Peterson 已提交
486
			e752x_printk(KERN_WARNING, "%sError %s\n",
487
				fatal_message[fatal], hub_message[i]);
488 489 490 491
	}
}

static inline void hub_error(int fatal, u8 errors, int *error_found,
492
			int handle_error)
493 494 495 496 497 498 499
{
	*error_found = 1;

	if (handle_error)
		do_hub_error(fatal, errors);
}

500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
#define NSI_FATAL_MASK		0x0c080081
#define NSI_NON_FATAL_MASK	0x23a0ba64
#define NSI_ERR_MASK		(NSI_FATAL_MASK | NSI_NON_FATAL_MASK)

static char *nsi_message[30] = {
	"NSI Link Down",	/* NSI_FERR/NSI_NERR bit 0, fatal error */
	"",						/* reserved */
	"NSI Parity Error",				/* bit 2, non-fatal */
	"",						/* reserved */
	"",						/* reserved */
	"Correctable Error Message",			/* bit 5, non-fatal */
	"Non-Fatal Error Message",			/* bit 6, non-fatal */
	"Fatal Error Message",				/* bit 7, fatal */
	"",						/* reserved */
	"Receiver Error",				/* bit 9, non-fatal */
	"",						/* reserved */
	"Bad TLP",					/* bit 11, non-fatal */
	"Bad DLLP",					/* bit 12, non-fatal */
	"REPLAY_NUM Rollover",				/* bit 13, non-fatal */
	"",						/* reserved */
	"Replay Timer Timeout",				/* bit 15, non-fatal */
	"",						/* reserved */
	"",						/* reserved */
	"",						/* reserved */
	"Data Link Protocol Error",			/* bit 19, fatal */
	"",						/* reserved */
	"Poisoned TLP",					/* bit 21, non-fatal */
	"",						/* reserved */
	"Completion Timeout",				/* bit 23, non-fatal */
	"Completer Abort",				/* bit 24, non-fatal */
	"Unexpected Completion",			/* bit 25, non-fatal */
	"Receiver Overflow",				/* bit 26, fatal */
	"Malformed TLP",				/* bit 27, fatal */
	"",						/* reserved */
	"Unsupported Request"				/* bit 29, non-fatal */
};

static void do_nsi_error(int fatal, u32 errors)
{
	int i;

	for (i = 0; i < 30; i++) {
		if (errors & (1 << i))
			printk(KERN_WARNING "%sError %s\n",
			       fatal_message[fatal], nsi_message[i]);
	}
}

static inline void nsi_error(int fatal, u32 errors, int *error_found,
		int handle_error)
{
	*error_found = 1;

	if (handle_error)
		do_nsi_error(fatal, errors);
}

A
Alan Cox 已提交
557
static char *membuf_message[4] = {
558 559 560 561 562 563 564 565 566 567 568 569
	"Internal PMWB to DRAM parity",
	"Internal PMWB to System Bus Parity",
	"Internal System Bus or IO to PMWB Parity",
	"Internal DRAM to PMWB Parity"
};

static void do_membuf_error(u8 errors)
{
	int i;

	for (i = 0; i < 4; i++) {
		if (errors & (1 << i))
D
Dave Peterson 已提交
570
			e752x_printk(KERN_WARNING, "Non-Fatal Error %s\n",
571
				membuf_message[i]);
572 573 574 575 576 577 578 579 580 581 582
	}
}

static inline void membuf_error(u8 errors, int *error_found, int handle_error)
{
	*error_found = 1;

	if (handle_error)
		do_membuf_error(errors);
}

583
static char *sysbus_message[10] = {
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
	"Addr or Request Parity",
	"Data Strobe Glitch",
	"Addr Strobe Glitch",
	"Data Parity",
	"Addr Above TOM",
	"Non DRAM Lock Error",
	"MCERR", "BINIT",
	"Memory Parity",
	"IO Subsystem Parity"
};

static void do_sysbus_error(int fatal, u32 errors)
{
	int i;

	for (i = 0; i < 10; i++) {
		if (errors & (1 << i))
D
Dave Peterson 已提交
601
			e752x_printk(KERN_WARNING, "%sError System Bus %s\n",
602
				fatal_message[fatal], sysbus_message[i]);
603 604 605 606
	}
}

static inline void sysbus_error(int fatal, u32 errors, int *error_found,
D
Dave Jiang 已提交
607
				int handle_error)
608 609 610 611 612 613 614
{
	*error_found = 1;

	if (handle_error)
		do_sysbus_error(fatal, errors);
}

D
Dave Peterson 已提交
615
static void e752x_check_hub_interface(struct e752x_error_info *info,
616
				int *error_found, int handle_error)
617 618 619 620
{
	u8 stat8;

	//pci_read_config_byte(dev,E752X_HI_FERR,&stat8);
D
Dave Peterson 已提交
621

622
	stat8 = info->hi_ferr;
D
Dave Peterson 已提交
623

D
Dave Jiang 已提交
624
	if (stat8 & 0x7f) {	/* Error, so process */
625
		stat8 &= 0x7f;
D
Dave Peterson 已提交
626

D
Dave Jiang 已提交
627
		if (stat8 & 0x2b)
628
			hub_error(1, stat8 & 0x2b, error_found, handle_error);
D
Dave Peterson 已提交
629

D
Dave Jiang 已提交
630
		if (stat8 & 0x54)
631 632 633
			hub_error(0, stat8 & 0x54, error_found, handle_error);
	}
	//pci_read_config_byte(dev,E752X_HI_NERR,&stat8);
D
Dave Peterson 已提交
634

635
	stat8 = info->hi_nerr;
D
Dave Peterson 已提交
636

D
Dave Jiang 已提交
637
	if (stat8 & 0x7f) {	/* Error, so process */
638
		stat8 &= 0x7f;
D
Dave Peterson 已提交
639

640 641
		if (stat8 & 0x2b)
			hub_error(1, stat8 & 0x2b, error_found, handle_error);
D
Dave Peterson 已提交
642

D
Dave Jiang 已提交
643
		if (stat8 & 0x54)
644 645 646 647
			hub_error(0, stat8 & 0x54, error_found, handle_error);
	}
}

648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672
static void e752x_check_ns_interface(struct e752x_error_info *info,
				int *error_found, int handle_error)
{
	u32 stat32;

	stat32 = info->nsi_ferr;
	if (stat32 & NSI_ERR_MASK) { /* Error, so process */
		if (stat32 & NSI_FATAL_MASK)	/* check for fatal errors */
			nsi_error(1, stat32 & NSI_FATAL_MASK, error_found,
				  handle_error);
		if (stat32 & NSI_NON_FATAL_MASK) /* check for non-fatal ones */
			nsi_error(0, stat32 & NSI_NON_FATAL_MASK, error_found,
				  handle_error);
	}
	stat32 = info->nsi_nerr;
	if (stat32 & NSI_ERR_MASK) {
		if (stat32 & NSI_FATAL_MASK)
			nsi_error(1, stat32 & NSI_FATAL_MASK, error_found,
				  handle_error);
		if (stat32 & NSI_NON_FATAL_MASK)
			nsi_error(0, stat32 & NSI_NON_FATAL_MASK, error_found,
				  handle_error);
	}
}

D
Dave Peterson 已提交
673
static void e752x_check_sysbus(struct e752x_error_info *info,
674
			int *error_found, int handle_error)
675 676 677 678 679 680 681
{
	u32 stat32, error32;

	//pci_read_config_dword(dev,E752X_SYSBUS_FERR,&stat32);
	stat32 = info->sysbus_ferr + (info->sysbus_nerr << 16);

	if (stat32 == 0)
D
Dave Jiang 已提交
682
		return;		/* no errors */
683 684 685

	error32 = (stat32 >> 16) & 0x3ff;
	stat32 = stat32 & 0x3ff;
D
Dave Peterson 已提交
686

D
Dave Jiang 已提交
687
	if (stat32 & 0x087)
688
		sysbus_error(1, stat32 & 0x087, error_found, handle_error);
D
Dave Peterson 已提交
689

D
Dave Jiang 已提交
690
	if (stat32 & 0x378)
691
		sysbus_error(0, stat32 & 0x378, error_found, handle_error);
D
Dave Peterson 已提交
692

D
Dave Jiang 已提交
693
	if (error32 & 0x087)
694
		sysbus_error(1, error32 & 0x087, error_found, handle_error);
D
Dave Peterson 已提交
695

D
Dave Jiang 已提交
696
	if (error32 & 0x378)
697
		sysbus_error(0, error32 & 0x378, error_found, handle_error);
698 699
}

D
Dave Jiang 已提交
700
static void e752x_check_membuf(struct e752x_error_info *info,
701
			int *error_found, int handle_error)
702 703 704 705
{
	u8 stat8;

	stat8 = info->buf_ferr;
D
Dave Peterson 已提交
706

D
Dave Jiang 已提交
707
	if (stat8 & 0x0f) {	/* Error, so process */
708 709 710
		stat8 &= 0x0f;
		membuf_error(stat8, error_found, handle_error);
	}
D
Dave Peterson 已提交
711

712
	stat8 = info->buf_nerr;
D
Dave Peterson 已提交
713

D
Dave Jiang 已提交
714
	if (stat8 & 0x0f) {	/* Error, so process */
715 716 717 718 719
		stat8 &= 0x0f;
		membuf_error(stat8, error_found, handle_error);
	}
}

D
Dave Jiang 已提交
720
static void e752x_check_dram(struct mem_ctl_info *mci,
721 722
			struct e752x_error_info *info, int *error_found,
			int handle_error)
723 724 725 726 727 728 729
{
	u16 error_one, error_next;

	error_one = info->dram_ferr;
	error_next = info->dram_nerr;

	/* decode and report errors */
D
Dave Jiang 已提交
730
	if (error_one & 0x0101)	/* check first error correctable */
731
		process_ce(mci, error_one, info->dram_sec1_add,
732
			info->dram_sec1_syndrome, error_found, handle_error);
733

D
Dave Jiang 已提交
734
	if (error_next & 0x0101)	/* check next error correctable */
735
		process_ce(mci, error_next, info->dram_sec2_add,
736
			info->dram_sec2_syndrome, error_found, handle_error);
737

D
Dave Jiang 已提交
738
	if (error_one & 0x4040)
739 740
		process_ue_no_info_wr(mci, error_found, handle_error);

D
Dave Jiang 已提交
741
	if (error_next & 0x4040)
742 743
		process_ue_no_info_wr(mci, error_found, handle_error);

D
Dave Jiang 已提交
744
	if (error_one & 0x2020)
745
		process_ded_retry(mci, error_one, info->dram_retr_add,
746
				error_found, handle_error);
747

D
Dave Jiang 已提交
748
	if (error_next & 0x2020)
749
		process_ded_retry(mci, error_next, info->dram_retr_add,
750
				error_found, handle_error);
751

D
Dave Jiang 已提交
752 753
	if (error_one & 0x0808)
		process_threshold_ce(mci, error_one, error_found, handle_error);
754

D
Dave Jiang 已提交
755
	if (error_next & 0x0808)
756
		process_threshold_ce(mci, error_next, error_found,
757
				handle_error);
758

D
Dave Jiang 已提交
759
	if (error_one & 0x0606)
760
		process_ue(mci, error_one, info->dram_ded_add,
761
			info->dram_scrb_add, error_found, handle_error);
762

D
Dave Jiang 已提交
763
	if (error_next & 0x0606)
764
		process_ue(mci, error_next, info->dram_ded_add,
765
			info->dram_scrb_add, error_found, handle_error);
766 767
}

D
Dave Jiang 已提交
768 769
static void e752x_get_error_info(struct mem_ctl_info *mci,
				 struct e752x_error_info *info)
770 771 772 773 774
{
	struct pci_dev *dev;
	struct e752x_pvt *pvt;

	memset(info, 0, sizeof(*info));
D
Dave Jiang 已提交
775
	pvt = (struct e752x_pvt *)mci->pvt_info;
776 777 778 779
	dev = pvt->dev_d0f1;
	pci_read_config_dword(dev, E752X_FERR_GLOBAL, &info->ferr_global);

	if (info->ferr_global) {
780 781 782 783 784 785 786 787 788
		if (pvt->dev_info->err_dev == PCI_DEVICE_ID_INTEL_3100_1_ERR) {
			pci_read_config_dword(dev, I3100_NSI_FERR,
					     &info->nsi_ferr);
			info->hi_ferr = 0;
		} else {
			pci_read_config_byte(dev, E752X_HI_FERR,
					     &info->hi_ferr);
			info->nsi_ferr = 0;
		}
789
		pci_read_config_word(dev, E752X_SYSBUS_FERR,
790
				&info->sysbus_ferr);
791
		pci_read_config_byte(dev, E752X_BUF_FERR, &info->buf_ferr);
D
Dave Jiang 已提交
792
		pci_read_config_word(dev, E752X_DRAM_FERR, &info->dram_ferr);
793
		pci_read_config_dword(dev, E752X_DRAM_SEC1_ADD,
794
				&info->dram_sec1_add);
795
		pci_read_config_word(dev, E752X_DRAM_SEC1_SYNDROME,
796
				&info->dram_sec1_syndrome);
797
		pci_read_config_dword(dev, E752X_DRAM_DED_ADD,
798
				&info->dram_ded_add);
799
		pci_read_config_dword(dev, E752X_DRAM_SCRB_ADD,
800
				&info->dram_scrb_add);
801
		pci_read_config_dword(dev, E752X_DRAM_RETR_ADD,
802
				&info->dram_retr_add);
803

804
		/* ignore the reserved bits just in case */
805 806
		if (info->hi_ferr & 0x7f)
			pci_write_config_byte(dev, E752X_HI_FERR,
807
					info->hi_ferr);
808

809 810 811 812
		if (info->nsi_ferr & NSI_ERR_MASK)
			pci_write_config_dword(dev, I3100_NSI_FERR,
					info->nsi_ferr);

813 814
		if (info->sysbus_ferr)
			pci_write_config_word(dev, E752X_SYSBUS_FERR,
815
					info->sysbus_ferr);
816 817 818

		if (info->buf_ferr & 0x0f)
			pci_write_config_byte(dev, E752X_BUF_FERR,
819
					info->buf_ferr);
820 821 822

		if (info->dram_ferr)
			pci_write_bits16(pvt->bridge_ck, E752X_DRAM_FERR,
D
Dave Jiang 已提交
823
					 info->dram_ferr, info->dram_ferr);
824 825

		pci_write_config_dword(dev, E752X_FERR_GLOBAL,
826
				info->ferr_global);
827 828 829 830 831
	}

	pci_read_config_dword(dev, E752X_NERR_GLOBAL, &info->nerr_global);

	if (info->nerr_global) {
832 833 834 835 836 837 838 839 840
		if (pvt->dev_info->err_dev == PCI_DEVICE_ID_INTEL_3100_1_ERR) {
			pci_read_config_dword(dev, I3100_NSI_NERR,
					     &info->nsi_nerr);
			info->hi_nerr = 0;
		} else {
			pci_read_config_byte(dev, E752X_HI_NERR,
					     &info->hi_nerr);
			info->nsi_nerr = 0;
		}
841
		pci_read_config_word(dev, E752X_SYSBUS_NERR,
842
				&info->sysbus_nerr);
843
		pci_read_config_byte(dev, E752X_BUF_NERR, &info->buf_nerr);
D
Dave Jiang 已提交
844
		pci_read_config_word(dev, E752X_DRAM_NERR, &info->dram_nerr);
845
		pci_read_config_dword(dev, E752X_DRAM_SEC2_ADD,
846
				&info->dram_sec2_add);
847
		pci_read_config_word(dev, E752X_DRAM_SEC2_SYNDROME,
848
				&info->dram_sec2_syndrome);
849 850 851

		if (info->hi_nerr & 0x7f)
			pci_write_config_byte(dev, E752X_HI_NERR,
852
					info->hi_nerr);
853

854 855 856 857
		if (info->nsi_nerr & NSI_ERR_MASK)
			pci_write_config_dword(dev, I3100_NSI_NERR,
					info->nsi_nerr);

858 859
		if (info->sysbus_nerr)
			pci_write_config_word(dev, E752X_SYSBUS_NERR,
860
					info->sysbus_nerr);
861 862 863

		if (info->buf_nerr & 0x0f)
			pci_write_config_byte(dev, E752X_BUF_NERR,
864
					info->buf_nerr);
865 866 867

		if (info->dram_nerr)
			pci_write_bits16(pvt->bridge_ck, E752X_DRAM_NERR,
D
Dave Jiang 已提交
868
					 info->dram_nerr, info->dram_nerr);
869 870

		pci_write_config_dword(dev, E752X_NERR_GLOBAL,
871
				info->nerr_global);
872 873 874
	}
}

D
Dave Jiang 已提交
875
static int e752x_process_error_info(struct mem_ctl_info *mci,
876 877
				struct e752x_error_info *info,
				int handle_errors)
878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901
{
	u32 error32, stat32;
	int error_found;

	error_found = 0;
	error32 = (info->ferr_global >> 18) & 0x3ff;
	stat32 = (info->ferr_global >> 4) & 0x7ff;

	if (error32)
		global_error(1, error32, &error_found, handle_errors);

	if (stat32)
		global_error(0, stat32, &error_found, handle_errors);

	error32 = (info->nerr_global >> 18) & 0x3ff;
	stat32 = (info->nerr_global >> 4) & 0x7ff;

	if (error32)
		global_error(1, error32, &error_found, handle_errors);

	if (stat32)
		global_error(0, stat32, &error_found, handle_errors);

	e752x_check_hub_interface(info, &error_found, handle_errors);
902
	e752x_check_ns_interface(info, &error_found, handle_errors);
903 904 905 906 907 908 909 910 911
	e752x_check_sysbus(info, &error_found, handle_errors);
	e752x_check_membuf(info, &error_found, handle_errors);
	e752x_check_dram(mci, info, &error_found, handle_errors);
	return error_found;
}

static void e752x_check(struct mem_ctl_info *mci)
{
	struct e752x_error_info info;
D
Dave Peterson 已提交
912

D
Dave Peterson 已提交
913
	debugf3("%s()\n", __func__);
914 915 916 917
	e752x_get_error_info(mci, &info);
	e752x_process_error_info(mci, &info, 1);
}

918 919 920 921 922 923
/* Return 1 if dual channel mode is active.  Else return 0. */
static inline int dual_channel_active(u16 ddrcsr)
{
	return (((ddrcsr >> 12) & 3) == 3);
}

924 925 926 927 928 929 930 931 932 933 934 935
/* Remap csrow index numbers if map_type is "reverse"
 */
static inline int remap_csrow_index(struct mem_ctl_info *mci, int index)
{
	struct e752x_pvt *pvt = mci->pvt_info;

	if (!pvt->map_type)
		return (7 - index);

	return (index);
}

936
static void e752x_init_csrows(struct mem_ctl_info *mci, struct pci_dev *pdev,
937
			u16 ddrcsr)
938 939 940 941
{
	struct csrow_info *csrow;
	unsigned long last_cumul_size;
	int index, mem_dev, drc_chan;
D
Dave Jiang 已提交
942 943
	int drc_drbg;		/* DRB granularity 0=64mb, 1=128mb */
	int drc_ddim;		/* DRAM Data Integrity Mode 0=none, 2=edac */
944 945 946
	u8 value;
	u32 dra, drc, cumul_size;

947
	dra = 0;
D
Dave Jiang 已提交
948
	for (index = 0; index < 4; index++) {
949
		u8 dra_reg;
D
Dave Jiang 已提交
950
		pci_read_config_byte(pdev, E752X_DRA + index, &dra_reg);
951 952
		dra |= dra_reg << (index * 8);
	}
953 954
	pci_read_config_dword(pdev, E752X_DRC, &drc);
	drc_chan = dual_channel_active(ddrcsr);
D
Dave Jiang 已提交
955
	drc_drbg = drc_chan + 1;	/* 128 in dual mode, 64 in single */
956 957 958 959 960 961 962 963 964 965
	drc_ddim = (drc >> 20) & 0x3;

	/* The dram row boundary (DRB) reg values are boundary address for
	 * each DRAM row with a granularity of 64 or 128MB (single/dual
	 * channel operation).  DRB regs are cumulative; therefore DRB7 will
	 * contain the total memory contained in all eight rows.
	 */
	for (last_cumul_size = index = 0; index < mci->nr_csrows; index++) {
		/* mem_dev 0=x8, 1=x4 */
		mem_dev = (dra >> (index * 4 + 2)) & 0x3;
966
		csrow = &mci->csrows[remap_csrow_index(mci, index)];
967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002

		mem_dev = (mem_dev == 2);
		pci_read_config_byte(pdev, E752X_DRB + index, &value);
		/* convert a 128 or 64 MiB DRB to a page size. */
		cumul_size = value << (25 + drc_drbg - PAGE_SHIFT);
		debugf3("%s(): (%d) cumul_size 0x%x\n", __func__, index,
			cumul_size);
		if (cumul_size == last_cumul_size)
			continue;	/* not populated */

		csrow->first_page = last_cumul_size;
		csrow->last_page = cumul_size - 1;
		csrow->nr_pages = cumul_size - last_cumul_size;
		last_cumul_size = cumul_size;
		csrow->grain = 1 << 12;	/* 4KiB - resolution of CELOG */
		csrow->mtype = MEM_RDDR;	/* only one type supported */
		csrow->dtype = mem_dev ? DEV_X4 : DEV_X8;

		/*
		 * if single channel or x8 devices then SECDED
		 * if dual channel and x4 then S4ECD4ED
		 */
		if (drc_ddim) {
			if (drc_chan && mem_dev) {
				csrow->edac_mode = EDAC_S4ECD4ED;
				mci->edac_cap |= EDAC_FLAG_S4ECD4ED;
			} else {
				csrow->edac_mode = EDAC_SECDED;
				mci->edac_cap |= EDAC_FLAG_SECDED;
			}
		} else
			csrow->edac_mode = EDAC_NONE;
	}
}

static void e752x_init_mem_map_table(struct pci_dev *pdev,
1003
				struct e752x_pvt *pvt)
1004 1005
{
	int index;
1006
	u8 value, last, row;
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017

	last = 0;
	row = 0;

	for (index = 0; index < 8; index += 2) {
		pci_read_config_byte(pdev, E752X_DRB + index, &value);
		/* test if there is a dimm in this slot */
		if (value == last) {
			/* no dimm in the slot, so flag it as empty */
			pvt->map[index] = 0xff;
			pvt->map[index + 1] = 0xff;
D
Dave Jiang 已提交
1018
		} else {	/* there is a dimm in the slot */
1019 1020 1021 1022 1023 1024 1025
			pvt->map[index] = row;
			row++;
			last = value;
			/* test the next value to see if the dimm is double
			 * sided
			 */
			pci_read_config_byte(pdev, E752X_DRB + index + 1,
1026 1027 1028 1029 1030
					&value);

			/* the dimm is single sided, so flag as empty */
			/* this is a double sided dimm to save the next row #*/
			pvt->map[index + 1] = (value == last) ? 0xff :	row;
1031 1032 1033 1034 1035 1036 1037 1038
			row++;
			last = value;
		}
	}
}

/* Return 0 on success or 1 on failure. */
static int e752x_get_devs(struct pci_dev *pdev, int dev_idx,
1039
			struct e752x_pvt *pvt)
1040 1041 1042 1043
{
	struct pci_dev *dev;

	pvt->bridge_ck = pci_get_device(PCI_VENDOR_ID_INTEL,
1044
				pvt->dev_info->err_dev, pvt->bridge_ck);
1045 1046 1047 1048 1049 1050 1051

	if (pvt->bridge_ck == NULL)
		pvt->bridge_ck = pci_scan_single_device(pdev->bus,
							PCI_DEVFN(0, 1));

	if (pvt->bridge_ck == NULL) {
		e752x_printk(KERN_ERR, "error reporting device not found:"
1052 1053
			"vendor %x device 0x%x (broken BIOS?)\n",
			PCI_VENDOR_ID_INTEL, e752x_devs[dev_idx].err_dev);
1054 1055 1056
		return 1;
	}

1057 1058 1059
	dev = pci_get_device(PCI_VENDOR_ID_INTEL,
				e752x_devs[dev_idx].ctl_dev,
				NULL);
1060 1061 1062 1063 1064 1065 1066 1067 1068

	if (dev == NULL)
		goto fail;

	pvt->dev_d0f0 = dev;
	pvt->dev_d0f1 = pci_dev_get(pvt->bridge_ck);

	return 0;

1069
fail:
1070 1071 1072 1073
	pci_dev_put(pvt->bridge_ck);
	return 1;
}

1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104
/* Setup system bus parity mask register.
 * Sysbus parity supported on:
 *   e7320/e7520/e7525 + Xeon
 *   i3100 + Xeon/Celeron
 * Sysbus parity not supported on:
 *   i3100 + Pentium M/Celeron M/Core Duo/Core2 Duo
 */
static void e752x_init_sysbus_parity_mask(struct e752x_pvt *pvt)
{
	char *cpu_id = cpu_data(0).x86_model_id;
	struct pci_dev *dev = pvt->dev_d0f1;
	int enable = 1;

	/* Allow module paramter override, else see if CPU supports parity */
	if (sysbus_parity != -1) {
		enable = sysbus_parity;
	} else if (cpu_id[0] &&
		   ((strstr(cpu_id, "Pentium") && strstr(cpu_id, " M ")) ||
		    (strstr(cpu_id, "Celeron") && strstr(cpu_id, " M ")) ||
		    (strstr(cpu_id, "Core") && strstr(cpu_id, "Duo")))) {
		e752x_printk(KERN_INFO, "System Bus Parity not "
			     "supported by CPU, disabling\n");
		enable = 0;
	}

	if (enable)
		pci_write_config_word(dev, E752X_SYSBUS_ERRMASK, 0x0000);
	else
		pci_write_config_word(dev, E752X_SYSBUS_ERRMASK, 0x0309);
}

1105 1106 1107 1108 1109 1110
static void e752x_init_error_reporting_regs(struct e752x_pvt *pvt)
{
	struct pci_dev *dev;

	dev = pvt->dev_d0f1;
	/* Turn off error disable & SMI in case the BIOS turned it on */
1111 1112 1113 1114 1115 1116 1117
	if (pvt->dev_info->err_dev == PCI_DEVICE_ID_INTEL_3100_1_ERR) {
		pci_write_config_dword(dev, I3100_NSI_EMASK, 0);
		pci_write_config_dword(dev, I3100_NSI_SMICMD, 0);
	} else {
		pci_write_config_byte(dev, E752X_HI_ERRMASK, 0x00);
		pci_write_config_byte(dev, E752X_HI_SMICMD, 0x00);
	}
1118 1119 1120

	e752x_init_sysbus_parity_mask(pvt);

1121 1122 1123 1124 1125 1126 1127 1128 1129
	pci_write_config_word(dev, E752X_SYSBUS_SMICMD, 0x00);
	pci_write_config_byte(dev, E752X_BUF_ERRMASK, 0x00);
	pci_write_config_byte(dev, E752X_BUF_SMICMD, 0x00);
	pci_write_config_byte(dev, E752X_DRAM_ERRMASK, 0x00);
	pci_write_config_byte(dev, E752X_DRAM_SMICMD, 0x00);
}

static int e752x_probe1(struct pci_dev *pdev, int dev_idx)
{
D
Dave Peterson 已提交
1130
	u16 pci_data;
1131
	u8 stat8;
1132 1133
	struct mem_ctl_info *mci;
	struct e752x_pvt *pvt;
1134
	u16 ddrcsr;
D
Dave Jiang 已提交
1135
	int drc_chan;		/* Number of channels 0=1chan,1=2chan */
1136
	struct e752x_error_info discard;
1137

D
Dave Peterson 已提交
1138
	debugf0("%s(): mci\n", __func__);
1139 1140
	debugf0("Starting Probe1\n");

M
mark gross 已提交
1141 1142 1143 1144
	/* check to see if device 0 function 1 is enabled; if it isn't, we
	 * assume the BIOS has reserved it for a reason and is expecting
	 * exclusive access, we take care not to violate that assumption and
	 * fail the probe. */
1145
	pci_read_config_byte(pdev, E752X_DEVPRES1, &stat8);
M
mark gross 已提交
1146 1147
	if (!force_function_unhide && !(stat8 & (1 << 5))) {
		printk(KERN_INFO "Contact your BIOS vendor to see if the "
1148
			"E752x error registers can be safely un-hidden\n");
1149
		return -ENODEV;
M
mark gross 已提交
1150
	}
1151 1152 1153 1154 1155 1156
	stat8 |= (1 << 5);
	pci_write_config_byte(pdev, E752X_DEVPRES1, stat8);

	pci_read_config_word(pdev, E752X_DDRCSR, &ddrcsr);
	/* FIXME: should check >>12 or 0xf, true for all? */
	/* Dual channel = 1, Single channel = 0 */
1157
	drc_chan = dual_channel_active(ddrcsr);
1158

1159
	mci = edac_mc_alloc(sizeof(*pvt), E752X_NR_CSROWS, drc_chan + 1, 0);
1160 1161

	if (mci == NULL) {
1162
		return -ENOMEM;
1163 1164
	}

D
Dave Peterson 已提交
1165
	debugf3("%s(): init mci\n", __func__);
1166
	mci->mtype_cap = MEM_FLAG_RDDR;
1167 1168 1169
	/* 3100 IMCH supports SECDEC only */
	mci->edac_ctl_cap = (dev_idx == I3100) ? EDAC_FLAG_SECDED :
		(EDAC_FLAG_NONE | EDAC_FLAG_SECDED | EDAC_FLAG_S4ECD4ED);
1170
	/* FIXME - what if different memory types are in different csrows? */
D
Dave Peterson 已提交
1171
	mci->mod_name = EDAC_MOD_STR;
1172 1173
	mci->mod_ver = E752X_REVISION;
	mci->dev = &pdev->dev;
1174

D
Dave Peterson 已提交
1175
	debugf3("%s(): init pvt\n", __func__);
D
Dave Jiang 已提交
1176
	pvt = (struct e752x_pvt *)mci->pvt_info;
1177
	pvt->dev_info = &e752x_devs[dev_idx];
1178
	pvt->mc_symmetric = ((ddrcsr & 0x10) != 0);
D
Dave Peterson 已提交
1179

1180 1181 1182
	if (e752x_get_devs(pdev, dev_idx, pvt)) {
		edac_mc_free(mci);
		return -ENODEV;
1183 1184
	}

D
Dave Peterson 已提交
1185
	debugf3("%s(): more mci init\n", __func__);
1186
	mci->ctl_name = pvt->dev_info->ctl_name;
1187
	mci->dev_name = pci_name(pdev);
1188 1189 1190
	mci->edac_check = e752x_check;
	mci->ctl_page_to_phys = ctl_page_to_phys;

1191 1192 1193 1194
	/* set the map type.  1 = normal, 0 = reversed
	 * Must be set before e752x_init_csrows in case csrow mapping
	 * is reversed.
	 */
1195
	pci_read_config_byte(pdev, E752X_DRM, &stat8);
1196 1197
	pvt->map_type = ((stat8 & 0x0f) > ((stat8 >> 4) & 0x0f));

1198 1199 1200
	e752x_init_csrows(mci, pdev, ddrcsr);
	e752x_init_mem_map_table(pdev, pvt);

1201 1202 1203 1204
	if (dev_idx == I3100)
		mci->edac_cap = EDAC_FLAG_SECDED; /* the only mode supported */
	else
		mci->edac_cap |= EDAC_FLAG_NONE;
D
Dave Peterson 已提交
1205
	debugf3("%s(): tolm, remapbase, remaplimit\n", __func__);
D
Dave Peterson 已提交
1206

1207
	/* load the top of low memory, remap base, and remap limit vars */
1208
	pci_read_config_word(pdev, E752X_TOLM, &pci_data);
1209
	pvt->tolm = ((u32) pci_data) << 4;
1210
	pci_read_config_word(pdev, E752X_REMAPBASE, &pci_data);
1211
	pvt->remapbase = ((u32) pci_data) << 14;
1212
	pci_read_config_word(pdev, E752X_REMAPLIMIT, &pci_data);
1213
	pvt->remaplimit = ((u32) pci_data) << 14;
D
Dave Peterson 已提交
1214
	e752x_printk(KERN_INFO,
1215 1216
			"tolm = %x, remapbase = %x, remaplimit = %x\n",
			pvt->tolm, pvt->remapbase, pvt->remaplimit);
1217

1218 1219 1220
	/* Here we assume that we will never see multiple instances of this
	 * type of memory controller.  The ID is therefore hardcoded to 0.
	 */
1221
	if (edac_mc_add_mc(mci)) {
D
Dave Peterson 已提交
1222
		debugf3("%s(): failed edac_mc_add_mc()\n", __func__);
1223 1224 1225
		goto fail;
	}

1226
	e752x_init_error_reporting_regs(pvt);
D
Dave Jiang 已提交
1227
	e752x_get_error_info(mci, &discard);	/* clear other MCH errors */
1228

1229 1230 1231 1232
	/* allocating generic PCI control info */
	e752x_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
	if (!e752x_pci) {
		printk(KERN_WARNING
1233
			"%s(): Unable to create PCI control\n", __func__);
1234
		printk(KERN_WARNING
1235 1236
			"%s(): PCI error report via EDAC not setup\n",
			__func__);
1237 1238
	}

1239
	/* get this far and it's successful */
D
Dave Peterson 已提交
1240
	debugf3("%s(): success\n", __func__);
1241 1242
	return 0;

1243
fail:
1244 1245 1246 1247
	pci_dev_put(pvt->dev_d0f0);
	pci_dev_put(pvt->dev_d0f1);
	pci_dev_put(pvt->bridge_ck);
	edac_mc_free(mci);
D
Dave Peterson 已提交
1248

1249
	return -ENODEV;
1250 1251 1252 1253
}

/* returns count (>= 0), or negative on error */
static int __devinit e752x_init_one(struct pci_dev *pdev,
1254
				const struct pci_device_id *ent)
1255
{
D
Dave Peterson 已提交
1256
	debugf0("%s()\n", __func__);
1257 1258

	/* wake up and enable device */
D
Dave Jiang 已提交
1259
	if (pci_enable_device(pdev) < 0)
1260
		return -EIO;
D
Dave Peterson 已提交
1261

1262 1263 1264 1265 1266 1267 1268 1269
	return e752x_probe1(pdev, ent->driver_data);
}

static void __devexit e752x_remove_one(struct pci_dev *pdev)
{
	struct mem_ctl_info *mci;
	struct e752x_pvt *pvt;

D
Dave Peterson 已提交
1270
	debugf0("%s()\n", __func__);
1271

1272 1273 1274
	if (e752x_pci)
		edac_pci_release_generic_ctl(e752x_pci);

1275
	if ((mci = edac_mc_del_mc(&pdev->dev)) == NULL)
1276 1277
		return;

D
Dave Jiang 已提交
1278
	pvt = (struct e752x_pvt *)mci->pvt_info;
1279 1280 1281 1282 1283 1284 1285
	pci_dev_put(pvt->dev_d0f0);
	pci_dev_put(pvt->dev_d0f1);
	pci_dev_put(pvt->bridge_ck);
	edac_mc_free(mci);
}

static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
D
Dave Peterson 已提交
1286
	{
D
Dave Jiang 已提交
1287 1288
	 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
	 E7520},
D
Dave Peterson 已提交
1289
	{
D
Dave Jiang 已提交
1290 1291
	 PCI_VEND_DEV(INTEL, 7525_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
	 E7525},
D
Dave Peterson 已提交
1292
	{
D
Dave Jiang 已提交
1293 1294
	 PCI_VEND_DEV(INTEL, 7320_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
	 E7320},
1295 1296 1297
	{
	 PCI_VEND_DEV(INTEL, 3100_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
	 I3100},
D
Dave Peterson 已提交
1298
	{
D
Dave Jiang 已提交
1299 1300
	 0,
	 }			/* 0 terminated list. */
1301 1302 1303 1304 1305
};

MODULE_DEVICE_TABLE(pci, e752x_pci_tbl);

static struct pci_driver e752x_driver = {
D
Dave Peterson 已提交
1306
	.name = EDAC_MOD_STR,
1307 1308 1309
	.probe = e752x_init_one,
	.remove = __devexit_p(e752x_remove_one),
	.id_table = e752x_pci_tbl,
1310 1311
};

A
Alan Cox 已提交
1312
static int __init e752x_init(void)
1313 1314 1315
{
	int pci_rc;

D
Dave Peterson 已提交
1316
	debugf3("%s()\n", __func__);
1317 1318 1319 1320

       /* Ensure that the OPSTATE is set correctly for POLL or NMI */
       opstate_init();

1321 1322 1323 1324 1325 1326
	pci_rc = pci_register_driver(&e752x_driver);
	return (pci_rc < 0) ? pci_rc : 0;
}

static void __exit e752x_exit(void)
{
D
Dave Peterson 已提交
1327
	debugf3("%s()\n", __func__);
1328 1329 1330 1331 1332 1333 1334 1335
	pci_unregister_driver(&e752x_driver);
}

module_init(e752x_init);
module_exit(e752x_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Linux Networx (http://lnxi.com) Tom Zimmerman\n");
1336
MODULE_DESCRIPTION("MC support for Intel e752x/3100 memory controllers");
M
mark gross 已提交
1337 1338 1339

module_param(force_function_unhide, int, 0444);
MODULE_PARM_DESC(force_function_unhide, "if BIOS sets Dev0:Fun1 up as hidden:"
1340 1341
		 " 1=force unhide and hope BIOS doesn't fight driver for "
		"Dev0:Fun1 access");
1342

D
Dave Jiang 已提交
1343 1344
module_param(edac_op_state, int, 0444);
MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
1345 1346 1347 1348

module_param(sysbus_parity, int, 0444);
MODULE_PARM_DESC(sysbus_parity, "0=disable system bus parity checking,"
		" 1=enable system bus parity checking, default=auto-detect");
1349 1350 1351
module_param(report_non_memory_errors, int, 0644);
MODULE_PARM_DESC(report_non_memory_errors, "0=disable non-memory error "
		"reporting, 1=enable non-memory error reporting");