xref: /linux/drivers/edac/i5000_edac.c (revision eb60705ac5a9869b2d078f0b472ea64b9b52b684)
1*eb60705aSEric Wollesen /*
2*eb60705aSEric Wollesen  * Intel 5000(P/V/X) class Memory Controllers kernel module
3*eb60705aSEric Wollesen  *
4*eb60705aSEric Wollesen  * This file may be distributed under the terms of the
5*eb60705aSEric Wollesen  * GNU General Public License.
6*eb60705aSEric Wollesen  *
7*eb60705aSEric Wollesen  * Written by Douglas Thompson Linux Networx (http://lnxi.com)
8*eb60705aSEric Wollesen  *	norsk5@xmission.com
9*eb60705aSEric Wollesen  *
10*eb60705aSEric Wollesen  * This module is based on the following document:
11*eb60705aSEric Wollesen  *
12*eb60705aSEric Wollesen  * Intel 5000X Chipset Memory Controller Hub (MCH) - Datasheet
13*eb60705aSEric Wollesen  * 	http://developer.intel.com/design/chipsets/datashts/313070.htm
14*eb60705aSEric Wollesen  *
15*eb60705aSEric Wollesen  */
16*eb60705aSEric Wollesen 
17*eb60705aSEric Wollesen #include <linux/module.h>
18*eb60705aSEric Wollesen #include <linux/init.h>
19*eb60705aSEric Wollesen #include <linux/pci.h>
20*eb60705aSEric Wollesen #include <linux/pci_ids.h>
21*eb60705aSEric Wollesen #include <linux/slab.h>
22*eb60705aSEric Wollesen #include <asm/mmzone.h>
23*eb60705aSEric Wollesen 
24*eb60705aSEric Wollesen #include "edac_mc.h"
25*eb60705aSEric Wollesen 
26*eb60705aSEric Wollesen /*
27*eb60705aSEric Wollesen  * Alter this version for the I5000 module when modifications are made
28*eb60705aSEric Wollesen  */
29*eb60705aSEric Wollesen #define I5000_REVISION    " Ver: 2.0.11.devel " __DATE__
30*eb60705aSEric Wollesen 
31*eb60705aSEric Wollesen #define i5000_printk(level, fmt, arg...) \
32*eb60705aSEric Wollesen         edac_printk(level, "i5000", fmt, ##arg)
33*eb60705aSEric Wollesen 
34*eb60705aSEric Wollesen #define i5000_mc_printk(mci, level, fmt, arg...) \
35*eb60705aSEric Wollesen         edac_mc_chipset_printk(mci, level, "i5000", fmt, ##arg)
36*eb60705aSEric Wollesen 
37*eb60705aSEric Wollesen #ifndef PCI_DEVICE_ID_INTEL_FBD_0
38*eb60705aSEric Wollesen #define PCI_DEVICE_ID_INTEL_FBD_0	0x25F5
39*eb60705aSEric Wollesen #endif
40*eb60705aSEric Wollesen #ifndef PCI_DEVICE_ID_INTEL_FBD_1
41*eb60705aSEric Wollesen #define PCI_DEVICE_ID_INTEL_FBD_1	0x25F6
42*eb60705aSEric Wollesen #endif
43*eb60705aSEric Wollesen 
44*eb60705aSEric Wollesen /* Device 16,
45*eb60705aSEric Wollesen  * Function 0: System Address
46*eb60705aSEric Wollesen  * Function 1: Memory Branch Map, Control, Errors Register
47*eb60705aSEric Wollesen  * Function 2: FSB Error Registers
48*eb60705aSEric Wollesen  *
49*eb60705aSEric Wollesen  * All 3 functions of Device 16 (0,1,2) share the SAME DID
50*eb60705aSEric Wollesen  */
51*eb60705aSEric Wollesen #define	PCI_DEVICE_ID_INTEL_I5000_DEV16	0x25F0
52*eb60705aSEric Wollesen 
53*eb60705aSEric Wollesen /* OFFSETS for Function 0 */
54*eb60705aSEric Wollesen 
55*eb60705aSEric Wollesen /* OFFSETS for Function 1 */
56*eb60705aSEric Wollesen #define		AMBASE			0x48
57*eb60705aSEric Wollesen #define		MAXCH			0x56
58*eb60705aSEric Wollesen #define		MAXDIMMPERCH		0x57
59*eb60705aSEric Wollesen #define		TOLM			0x6C
60*eb60705aSEric Wollesen #define		REDMEMB			0x7C
61*eb60705aSEric Wollesen #define			RED_ECC_LOCATOR(x)	((x) & 0x3FFFF)
62*eb60705aSEric Wollesen #define			REC_ECC_LOCATOR_EVEN(x)	((x) & 0x001FF)
63*eb60705aSEric Wollesen #define			REC_ECC_LOCATOR_ODD(x)	((x) & 0x3FE00)
64*eb60705aSEric Wollesen #define		MIR0			0x80
65*eb60705aSEric Wollesen #define		MIR1			0x84
66*eb60705aSEric Wollesen #define		MIR2			0x88
67*eb60705aSEric Wollesen #define		AMIR0			0x8C
68*eb60705aSEric Wollesen #define		AMIR1			0x90
69*eb60705aSEric Wollesen #define		AMIR2			0x94
70*eb60705aSEric Wollesen 
71*eb60705aSEric Wollesen #define		FERR_FAT_FBD		0x98
72*eb60705aSEric Wollesen #define		NERR_FAT_FBD		0x9C
73*eb60705aSEric Wollesen #define			EXTRACT_FBDCHAN_INDX(x)	(((x)>>28) & 0x3)
74*eb60705aSEric Wollesen #define			FERR_FAT_FBDCHAN 0x30000000
75*eb60705aSEric Wollesen #define			FERR_FAT_M3ERR	0x00000004
76*eb60705aSEric Wollesen #define			FERR_FAT_M2ERR	0x00000002
77*eb60705aSEric Wollesen #define			FERR_FAT_M1ERR	0x00000001
78*eb60705aSEric Wollesen #define			FERR_FAT_MASK	  (FERR_FAT_M1ERR | \
79*eb60705aSEric Wollesen 						FERR_FAT_M2ERR | \
80*eb60705aSEric Wollesen 						FERR_FAT_M3ERR)
81*eb60705aSEric Wollesen 
82*eb60705aSEric Wollesen #define		FERR_NF_FBD		0xA0
83*eb60705aSEric Wollesen 
84*eb60705aSEric Wollesen /* Thermal and SPD or BFD errors */
85*eb60705aSEric Wollesen #define			FERR_NF_M28ERR	0x01000000
86*eb60705aSEric Wollesen #define			FERR_NF_M27ERR	0x00800000
87*eb60705aSEric Wollesen #define			FERR_NF_M26ERR	0x00400000
88*eb60705aSEric Wollesen #define			FERR_NF_M25ERR	0x00200000
89*eb60705aSEric Wollesen #define			FERR_NF_M24ERR	0x00100000
90*eb60705aSEric Wollesen #define			FERR_NF_M23ERR	0x00080000
91*eb60705aSEric Wollesen #define			FERR_NF_M22ERR	0x00040000
92*eb60705aSEric Wollesen #define			FERR_NF_M21ERR	0x00020000
93*eb60705aSEric Wollesen 
94*eb60705aSEric Wollesen /* Correctable errors */
95*eb60705aSEric Wollesen #define			FERR_NF_M20ERR	0x00010000
96*eb60705aSEric Wollesen #define			FERR_NF_M19ERR	0x00008000
97*eb60705aSEric Wollesen #define			FERR_NF_M18ERR	0x00004000
98*eb60705aSEric Wollesen #define			FERR_NF_M17ERR	0x00002000
99*eb60705aSEric Wollesen 
100*eb60705aSEric Wollesen /* Non-Retry or redundant Retry errors */
101*eb60705aSEric Wollesen #define			FERR_NF_M16ERR	0x00001000
102*eb60705aSEric Wollesen #define			FERR_NF_M15ERR	0x00000800
103*eb60705aSEric Wollesen #define			FERR_NF_M14ERR	0x00000400
104*eb60705aSEric Wollesen #define			FERR_NF_M13ERR	0x00000200
105*eb60705aSEric Wollesen 
106*eb60705aSEric Wollesen /* Uncorrectable errors */
107*eb60705aSEric Wollesen #define			FERR_NF_M12ERR	0x00000100
108*eb60705aSEric Wollesen #define			FERR_NF_M11ERR	0x00000080
109*eb60705aSEric Wollesen #define			FERR_NF_M10ERR	0x00000040
110*eb60705aSEric Wollesen #define			FERR_NF_M9ERR	0x00000020
111*eb60705aSEric Wollesen #define			FERR_NF_M8ERR	0x00000010
112*eb60705aSEric Wollesen #define			FERR_NF_M7ERR	0x00000008
113*eb60705aSEric Wollesen #define			FERR_NF_M6ERR	0x00000004
114*eb60705aSEric Wollesen #define			FERR_NF_M5ERR	0x00000002
115*eb60705aSEric Wollesen #define			FERR_NF_M4ERR	0x00000001
116*eb60705aSEric Wollesen 
117*eb60705aSEric Wollesen #define			FERR_NF_UNCORRECTABLE	(FERR_NF_M12ERR | \
118*eb60705aSEric Wollesen 							FERR_NF_M11ERR | \
119*eb60705aSEric Wollesen 							FERR_NF_M10ERR | \
120*eb60705aSEric Wollesen 		       					FERR_NF_M8ERR | \
121*eb60705aSEric Wollesen 							FERR_NF_M7ERR | \
122*eb60705aSEric Wollesen 							FERR_NF_M6ERR | \
123*eb60705aSEric Wollesen 							FERR_NF_M5ERR | \
124*eb60705aSEric Wollesen 							FERR_NF_M4ERR)
125*eb60705aSEric Wollesen #define			FERR_NF_CORRECTABLE	(FERR_NF_M20ERR | \
126*eb60705aSEric Wollesen 							FERR_NF_M19ERR | \
127*eb60705aSEric Wollesen 							FERR_NF_M18ERR | \
128*eb60705aSEric Wollesen 							FERR_NF_M17ERR)
129*eb60705aSEric Wollesen #define			FERR_NF_DIMM_SPARE	(FERR_NF_M27ERR | \
130*eb60705aSEric Wollesen 							FERR_NF_M28ERR)
131*eb60705aSEric Wollesen #define			FERR_NF_THERMAL		(FERR_NF_M26ERR | \
132*eb60705aSEric Wollesen 	       						FERR_NF_M25ERR | \
133*eb60705aSEric Wollesen 							FERR_NF_M24ERR | \
134*eb60705aSEric Wollesen 							FERR_NF_M23ERR)
135*eb60705aSEric Wollesen #define			FERR_NF_SPD_PROTOCOL	(FERR_NF_M22ERR)
136*eb60705aSEric Wollesen #define			FERR_NF_NORTH_CRC	(FERR_NF_M21ERR)
137*eb60705aSEric Wollesen #define			FERR_NF_NON_RETRY	(FERR_NF_M13ERR | \
138*eb60705aSEric Wollesen 							FERR_NF_M14ERR | \
139*eb60705aSEric Wollesen 							FERR_NF_M15ERR)
140*eb60705aSEric Wollesen 
141*eb60705aSEric Wollesen #define		NERR_NF_FBD		0xA4
142*eb60705aSEric Wollesen #define			FERR_NF_MASK		(FERR_NF_UNCORRECTABLE | \
143*eb60705aSEric Wollesen 							FERR_NF_CORRECTABLE | \
144*eb60705aSEric Wollesen 							FERR_NF_DIMM_SPARE | \
145*eb60705aSEric Wollesen 							FERR_NF_THERMAL | \
146*eb60705aSEric Wollesen 							FERR_NF_SPD_PROTOCOL | \
147*eb60705aSEric Wollesen 							FERR_NF_NORTH_CRC | \
148*eb60705aSEric Wollesen 							FERR_NF_NON_RETRY)
149*eb60705aSEric Wollesen 
150*eb60705aSEric Wollesen #define		EMASK_FBD		0xA8
151*eb60705aSEric Wollesen #define			EMASK_FBD_M28ERR	0x08000000
152*eb60705aSEric Wollesen #define			EMASK_FBD_M27ERR	0x04000000
153*eb60705aSEric Wollesen #define			EMASK_FBD_M26ERR	0x02000000
154*eb60705aSEric Wollesen #define			EMASK_FBD_M25ERR	0x01000000
155*eb60705aSEric Wollesen #define			EMASK_FBD_M24ERR	0x00800000
156*eb60705aSEric Wollesen #define			EMASK_FBD_M23ERR	0x00400000
157*eb60705aSEric Wollesen #define			EMASK_FBD_M22ERR	0x00200000
158*eb60705aSEric Wollesen #define			EMASK_FBD_M21ERR	0x00100000
159*eb60705aSEric Wollesen #define			EMASK_FBD_M20ERR	0x00080000
160*eb60705aSEric Wollesen #define			EMASK_FBD_M19ERR	0x00040000
161*eb60705aSEric Wollesen #define			EMASK_FBD_M18ERR	0x00020000
162*eb60705aSEric Wollesen #define			EMASK_FBD_M17ERR	0x00010000
163*eb60705aSEric Wollesen 
164*eb60705aSEric Wollesen #define			EMASK_FBD_M15ERR	0x00004000
165*eb60705aSEric Wollesen #define			EMASK_FBD_M14ERR	0x00002000
166*eb60705aSEric Wollesen #define			EMASK_FBD_M13ERR	0x00001000
167*eb60705aSEric Wollesen #define			EMASK_FBD_M12ERR	0x00000800
168*eb60705aSEric Wollesen #define			EMASK_FBD_M11ERR	0x00000400
169*eb60705aSEric Wollesen #define			EMASK_FBD_M10ERR	0x00000200
170*eb60705aSEric Wollesen #define			EMASK_FBD_M9ERR		0x00000100
171*eb60705aSEric Wollesen #define			EMASK_FBD_M8ERR		0x00000080
172*eb60705aSEric Wollesen #define			EMASK_FBD_M7ERR		0x00000040
173*eb60705aSEric Wollesen #define			EMASK_FBD_M6ERR		0x00000020
174*eb60705aSEric Wollesen #define			EMASK_FBD_M5ERR		0x00000010
175*eb60705aSEric Wollesen #define			EMASK_FBD_M4ERR		0x00000008
176*eb60705aSEric Wollesen #define			EMASK_FBD_M3ERR		0x00000004
177*eb60705aSEric Wollesen #define			EMASK_FBD_M2ERR		0x00000002
178*eb60705aSEric Wollesen #define			EMASK_FBD_M1ERR		0x00000001
179*eb60705aSEric Wollesen 
180*eb60705aSEric Wollesen #define			ENABLE_EMASK_FBD_FATAL_ERRORS	(EMASK_FBD_M1ERR | \
181*eb60705aSEric Wollesen 							EMASK_FBD_M2ERR | \
182*eb60705aSEric Wollesen 							EMASK_FBD_M3ERR)
183*eb60705aSEric Wollesen 
184*eb60705aSEric Wollesen #define 		ENABLE_EMASK_FBD_UNCORRECTABLE	(EMASK_FBD_M4ERR | \
185*eb60705aSEric Wollesen 							EMASK_FBD_M5ERR | \
186*eb60705aSEric Wollesen 							EMASK_FBD_M6ERR | \
187*eb60705aSEric Wollesen 							EMASK_FBD_M7ERR | \
188*eb60705aSEric Wollesen 							EMASK_FBD_M8ERR | \
189*eb60705aSEric Wollesen 							EMASK_FBD_M9ERR | \
190*eb60705aSEric Wollesen 							EMASK_FBD_M10ERR | \
191*eb60705aSEric Wollesen 							EMASK_FBD_M11ERR | \
192*eb60705aSEric Wollesen 							EMASK_FBD_M12ERR)
193*eb60705aSEric Wollesen #define 		ENABLE_EMASK_FBD_CORRECTABLE	(EMASK_FBD_M17ERR | \
194*eb60705aSEric Wollesen 							EMASK_FBD_M18ERR | \
195*eb60705aSEric Wollesen 							EMASK_FBD_M19ERR | \
196*eb60705aSEric Wollesen 							EMASK_FBD_M20ERR)
197*eb60705aSEric Wollesen #define			ENABLE_EMASK_FBD_DIMM_SPARE	(EMASK_FBD_M27ERR | \
198*eb60705aSEric Wollesen 							EMASK_FBD_M28ERR)
199*eb60705aSEric Wollesen #define			ENABLE_EMASK_FBD_THERMALS	(EMASK_FBD_M26ERR | \
200*eb60705aSEric Wollesen 							EMASK_FBD_M25ERR | \
201*eb60705aSEric Wollesen 							EMASK_FBD_M24ERR | \
202*eb60705aSEric Wollesen 							EMASK_FBD_M23ERR)
203*eb60705aSEric Wollesen #define			ENABLE_EMASK_FBD_SPD_PROTOCOL	(EMASK_FBD_M22ERR)
204*eb60705aSEric Wollesen #define			ENABLE_EMASK_FBD_NORTH_CRC	(EMASK_FBD_M21ERR)
205*eb60705aSEric Wollesen #define			ENABLE_EMASK_FBD_NON_RETRY	(EMASK_FBD_M15ERR | \
206*eb60705aSEric Wollesen 							EMASK_FBD_M14ERR | \
207*eb60705aSEric Wollesen 							EMASK_FBD_M13ERR)
208*eb60705aSEric Wollesen 
209*eb60705aSEric Wollesen #define		ENABLE_EMASK_ALL	(ENABLE_EMASK_FBD_NON_RETRY | \
210*eb60705aSEric Wollesen 					ENABLE_EMASK_FBD_NORTH_CRC | \
211*eb60705aSEric Wollesen 					ENABLE_EMASK_FBD_SPD_PROTOCOL | \
212*eb60705aSEric Wollesen 					ENABLE_EMASK_FBD_THERMALS | \
213*eb60705aSEric Wollesen 					ENABLE_EMASK_FBD_DIMM_SPARE | \
214*eb60705aSEric Wollesen 					ENABLE_EMASK_FBD_FATAL_ERRORS | \
215*eb60705aSEric Wollesen 					ENABLE_EMASK_FBD_CORRECTABLE | \
216*eb60705aSEric Wollesen 					ENABLE_EMASK_FBD_UNCORRECTABLE)
217*eb60705aSEric Wollesen 
218*eb60705aSEric Wollesen #define		ERR0_FBD		0xAC
219*eb60705aSEric Wollesen #define		ERR1_FBD		0xB0
220*eb60705aSEric Wollesen #define		ERR2_FBD		0xB4
221*eb60705aSEric Wollesen #define		MCERR_FBD		0xB8
222*eb60705aSEric Wollesen #define		NRECMEMA		0xBE
223*eb60705aSEric Wollesen #define			NREC_BANK(x)		(((x)>>12) & 0x7)
224*eb60705aSEric Wollesen #define			NREC_RDWR(x)		(((x)>>11) & 1)
225*eb60705aSEric Wollesen #define			NREC_RANK(x)		(((x)>>8) & 0x7)
226*eb60705aSEric Wollesen #define		NRECMEMB		0xC0
227*eb60705aSEric Wollesen #define			NREC_CAS(x)		(((x)>>16) & 0xFFFFFF)
228*eb60705aSEric Wollesen #define			NREC_RAS(x)		((x) & 0x7FFF)
229*eb60705aSEric Wollesen #define		NRECFGLOG		0xC4
230*eb60705aSEric Wollesen #define		NREEECFBDA		0xC8
231*eb60705aSEric Wollesen #define		NREEECFBDB		0xCC
232*eb60705aSEric Wollesen #define		NREEECFBDC		0xD0
233*eb60705aSEric Wollesen #define		NREEECFBDD		0xD4
234*eb60705aSEric Wollesen #define		NREEECFBDE		0xD8
235*eb60705aSEric Wollesen #define		REDMEMA			0xDC
236*eb60705aSEric Wollesen #define		RECMEMA			0xE2
237*eb60705aSEric Wollesen #define			REC_BANK(x)		(((x)>>12) & 0x7)
238*eb60705aSEric Wollesen #define			REC_RDWR(x)		(((x)>>11) & 1)
239*eb60705aSEric Wollesen #define			REC_RANK(x)		(((x)>>8) & 0x7)
240*eb60705aSEric Wollesen #define		RECMEMB			0xE4
241*eb60705aSEric Wollesen #define			REC_CAS(x)		(((x)>>16) & 0xFFFFFF)
242*eb60705aSEric Wollesen #define			REC_RAS(x)		((x) & 0x7FFF)
243*eb60705aSEric Wollesen #define		RECFGLOG		0xE8
244*eb60705aSEric Wollesen #define		RECFBDA			0xEC
245*eb60705aSEric Wollesen #define		RECFBDB			0xF0
246*eb60705aSEric Wollesen #define		RECFBDC			0xF4
247*eb60705aSEric Wollesen #define		RECFBDD			0xF8
248*eb60705aSEric Wollesen #define		RECFBDE			0xFC
249*eb60705aSEric Wollesen 
250*eb60705aSEric Wollesen /* OFFSETS for Function 2 */
251*eb60705aSEric Wollesen 
252*eb60705aSEric Wollesen /*
253*eb60705aSEric Wollesen  * Device 21,
254*eb60705aSEric Wollesen  * Function 0: Memory Map Branch 0
255*eb60705aSEric Wollesen  *
256*eb60705aSEric Wollesen  * Device 22,
257*eb60705aSEric Wollesen  * Function 0: Memory Map Branch 1
258*eb60705aSEric Wollesen  */
259*eb60705aSEric Wollesen #define PCI_DEVICE_ID_I5000_BRANCH_0	0x25F5
260*eb60705aSEric Wollesen #define PCI_DEVICE_ID_I5000_BRANCH_1	0x25F6
261*eb60705aSEric Wollesen 
262*eb60705aSEric Wollesen #define AMB_PRESENT_0	0x64
263*eb60705aSEric Wollesen #define AMB_PRESENT_1	0x66
264*eb60705aSEric Wollesen #define MTR0		0x80
265*eb60705aSEric Wollesen #define MTR1		0x84
266*eb60705aSEric Wollesen #define MTR2		0x88
267*eb60705aSEric Wollesen #define MTR3		0x8C
268*eb60705aSEric Wollesen 
269*eb60705aSEric Wollesen #define NUM_MTRS		4
270*eb60705aSEric Wollesen #define CHANNELS_PER_BRANCH	(2)
271*eb60705aSEric Wollesen 
272*eb60705aSEric Wollesen /* Defines to extract the vaious fields from the
273*eb60705aSEric Wollesen  *	MTRx - Memory Technology Registers
274*eb60705aSEric Wollesen  */
275*eb60705aSEric Wollesen #define MTR_DIMMS_PRESENT(mtr)		((mtr) & (0x1 << 8))
276*eb60705aSEric Wollesen #define MTR_DRAM_WIDTH(mtr)		((((mtr) >> 6) & 0x1) ? 8 : 4)
277*eb60705aSEric Wollesen #define MTR_DRAM_BANKS(mtr)		((((mtr) >> 5) & 0x1) ? 8 : 4)
278*eb60705aSEric Wollesen #define MTR_DRAM_BANKS_ADDR_BITS(mtr)	((MTR_DRAM_BANKS(mtr) == 8) ? 3 : 2)
279*eb60705aSEric Wollesen #define MTR_DIMM_RANK(mtr)		(((mtr) >> 4) & 0x1)
280*eb60705aSEric Wollesen #define MTR_DIMM_RANK_ADDR_BITS(mtr)	(MTR_DIM_RANKS(mtr) ? 2 : 1)
281*eb60705aSEric Wollesen #define MTR_DIMM_ROWS(mtr)		(((mtr) >> 2) & 0x3)
282*eb60705aSEric Wollesen #define MTR_DIMM_ROWS_ADDR_BITS(mtr)	(MTR_DIMM_ROWS(mtr) + 13)
283*eb60705aSEric Wollesen #define MTR_DIMM_COLS(mtr)		((mtr) & 0x3)
284*eb60705aSEric Wollesen #define MTR_DIMM_COLS_ADDR_BITS(mtr)	(MTR_DIMM_COLS(mtr) + 10)
285*eb60705aSEric Wollesen 
286*eb60705aSEric Wollesen #ifdef CONFIG_EDAC_DEBUG
287*eb60705aSEric Wollesen static char *numrow_toString[] = {
288*eb60705aSEric Wollesen 	"8,192 - 13 rows",
289*eb60705aSEric Wollesen 	"16,384 - 14 rows",
290*eb60705aSEric Wollesen 	"32,768 - 15 rows",
291*eb60705aSEric Wollesen 	"reserved"
292*eb60705aSEric Wollesen };
293*eb60705aSEric Wollesen 
294*eb60705aSEric Wollesen static char *numcol_toString[] = {
295*eb60705aSEric Wollesen 	"1,024 - 10 columns",
296*eb60705aSEric Wollesen 	"2,048 - 11 columns",
297*eb60705aSEric Wollesen 	"4,096 - 12 columns",
298*eb60705aSEric Wollesen 	"reserved"
299*eb60705aSEric Wollesen };
300*eb60705aSEric Wollesen #endif
301*eb60705aSEric Wollesen 
302*eb60705aSEric Wollesen /* Enumeration of supported devices */
303*eb60705aSEric Wollesen enum i5000_chips {
304*eb60705aSEric Wollesen 	I5000P = 0,
305*eb60705aSEric Wollesen 	I5000V = 1,		/* future */
306*eb60705aSEric Wollesen 	I5000X = 2		/* future */
307*eb60705aSEric Wollesen };
308*eb60705aSEric Wollesen 
309*eb60705aSEric Wollesen /* Device name and register DID (Device ID) */
310*eb60705aSEric Wollesen struct i5000_dev_info {
311*eb60705aSEric Wollesen 	const char *ctl_name;	/* name for this device */
312*eb60705aSEric Wollesen 	u16 fsb_mapping_errors;	/* DID for the branchmap,control */
313*eb60705aSEric Wollesen };
314*eb60705aSEric Wollesen 
315*eb60705aSEric Wollesen /* Table of devices attributes supported by this driver */
316*eb60705aSEric Wollesen static const struct i5000_dev_info i5000_devs[] = {
317*eb60705aSEric Wollesen 	[I5000P] = {
318*eb60705aSEric Wollesen 		    .ctl_name = "I5000",
319*eb60705aSEric Wollesen 		    .fsb_mapping_errors = PCI_DEVICE_ID_INTEL_I5000_DEV16,
320*eb60705aSEric Wollesen 		    },
321*eb60705aSEric Wollesen };
322*eb60705aSEric Wollesen 
323*eb60705aSEric Wollesen struct i5000_dimm_info {
324*eb60705aSEric Wollesen 	int megabytes;		/* size, 0 means not present  */
325*eb60705aSEric Wollesen 	int dual_rank;
326*eb60705aSEric Wollesen };
327*eb60705aSEric Wollesen 
328*eb60705aSEric Wollesen #define	MAX_CHANNELS	6	/* max possible channels */
329*eb60705aSEric Wollesen #define MAX_CSROWS	(8*2)	/* max possible csrows per channel */
330*eb60705aSEric Wollesen 
331*eb60705aSEric Wollesen /* driver private data structure */
332*eb60705aSEric Wollesen struct i5000_pvt {
333*eb60705aSEric Wollesen 	struct pci_dev *system_address;	/* 16.0 */
334*eb60705aSEric Wollesen 	struct pci_dev *branchmap_werrors;	/* 16.1 */
335*eb60705aSEric Wollesen 	struct pci_dev *fsb_error_regs;	/* 16.2 */
336*eb60705aSEric Wollesen 	struct pci_dev *branch_0;	/* 21.0 */
337*eb60705aSEric Wollesen 	struct pci_dev *branch_1;	/* 22.0 */
338*eb60705aSEric Wollesen 
339*eb60705aSEric Wollesen 	int node_id;		/* ID of this node */
340*eb60705aSEric Wollesen 
341*eb60705aSEric Wollesen 	u16 tolm;		/* top of low memory */
342*eb60705aSEric Wollesen 	u64 ambase;		/* AMB BAR */
343*eb60705aSEric Wollesen 
344*eb60705aSEric Wollesen 	u16 mir0, mir1, mir2;
345*eb60705aSEric Wollesen 
346*eb60705aSEric Wollesen 	u16 b0_mtr[NUM_MTRS];	/* Memory Technlogy Reg */
347*eb60705aSEric Wollesen 	u16 b0_ambpresent0;	/* Branch 0, Channel 0 */
348*eb60705aSEric Wollesen 	u16 b0_ambpresent1;	/* Brnach 0, Channel 1 */
349*eb60705aSEric Wollesen 
350*eb60705aSEric Wollesen 	u16 b1_mtr[NUM_MTRS];	/* Memory Technlogy Reg */
351*eb60705aSEric Wollesen 	u16 b1_ambpresent0;	/* Branch 1, Channel 8 */
352*eb60705aSEric Wollesen 	u16 b1_ambpresent1;	/* Branch 1, Channel 1 */
353*eb60705aSEric Wollesen 
354*eb60705aSEric Wollesen 	/* DIMM infomation matrix, allocating architecture maximums */
355*eb60705aSEric Wollesen 	struct i5000_dimm_info dimm_info[MAX_CSROWS][MAX_CHANNELS];
356*eb60705aSEric Wollesen 
357*eb60705aSEric Wollesen 	/* Actual values for this controller */
358*eb60705aSEric Wollesen 	int maxch;		/* Max channels */
359*eb60705aSEric Wollesen 	int maxdimmperch;	/* Max DIMMs per channel */
360*eb60705aSEric Wollesen };
361*eb60705aSEric Wollesen 
362*eb60705aSEric Wollesen /* I5000 MCH error information retrieved from Hardware */
363*eb60705aSEric Wollesen struct i5000_error_info {
364*eb60705aSEric Wollesen 
365*eb60705aSEric Wollesen 	/* These registers are always read from the MC */
366*eb60705aSEric Wollesen 	u32 ferr_fat_fbd;	/* First Errors Fatal */
367*eb60705aSEric Wollesen 	u32 nerr_fat_fbd;	/* Next Errors Fatal */
368*eb60705aSEric Wollesen 	u32 ferr_nf_fbd;	/* First Errors Non-Fatal */
369*eb60705aSEric Wollesen 	u32 nerr_nf_fbd;	/* Next Errors Non-Fatal */
370*eb60705aSEric Wollesen 
371*eb60705aSEric Wollesen 	/* These registers are input ONLY if there was a Recoverable  Error */
372*eb60705aSEric Wollesen 	u32 redmemb;		/* Recoverable Mem Data Error log B */
373*eb60705aSEric Wollesen 	u16 recmema;		/* Recoverable Mem Error log A */
374*eb60705aSEric Wollesen 	u32 recmemb;		/* Recoverable Mem Error log B */
375*eb60705aSEric Wollesen 
376*eb60705aSEric Wollesen 	/* These registers are input ONLY if there was a
377*eb60705aSEric Wollesen 	 * Non-Recoverable Error */
378*eb60705aSEric Wollesen 	u16 nrecmema;		/* Non-Recoverable Mem log A */
379*eb60705aSEric Wollesen 	u16 nrecmemb;		/* Non-Recoverable Mem log B */
380*eb60705aSEric Wollesen 
381*eb60705aSEric Wollesen };
382*eb60705aSEric Wollesen 
383*eb60705aSEric Wollesen /******************************************************************************
384*eb60705aSEric Wollesen  *	i5000_get_error_info	Retrieve the hardware error information from
385*eb60705aSEric Wollesen  *				the hardware and cache it in the 'info'
386*eb60705aSEric Wollesen  *				structure
387*eb60705aSEric Wollesen  */
388*eb60705aSEric Wollesen static void i5000_get_error_info(struct mem_ctl_info *mci,
389*eb60705aSEric Wollesen 				 struct i5000_error_info * info)
390*eb60705aSEric Wollesen {
391*eb60705aSEric Wollesen 	struct i5000_pvt *pvt;
392*eb60705aSEric Wollesen 	u32 value;
393*eb60705aSEric Wollesen 
394*eb60705aSEric Wollesen 	pvt = (struct i5000_pvt *)mci->pvt_info;
395*eb60705aSEric Wollesen 
396*eb60705aSEric Wollesen 	/* read in the 1st FATAL error register */
397*eb60705aSEric Wollesen 	pci_read_config_dword(pvt->branchmap_werrors, FERR_FAT_FBD, &value);
398*eb60705aSEric Wollesen 
399*eb60705aSEric Wollesen 	/* Mask only the bits that the doc says are valid
400*eb60705aSEric Wollesen 	 */
401*eb60705aSEric Wollesen 	value &= (FERR_FAT_FBDCHAN | FERR_FAT_MASK);
402*eb60705aSEric Wollesen 
403*eb60705aSEric Wollesen 	/* If there is an error, then read in the */
404*eb60705aSEric Wollesen 	/* NEXT FATAL error register and the Memory Error Log Register A */
405*eb60705aSEric Wollesen 	if (value & FERR_FAT_MASK) {
406*eb60705aSEric Wollesen 		info->ferr_fat_fbd = value;
407*eb60705aSEric Wollesen 
408*eb60705aSEric Wollesen 		/* harvest the various error data we need */
409*eb60705aSEric Wollesen 		pci_read_config_dword(pvt->branchmap_werrors,
410*eb60705aSEric Wollesen 				      NERR_FAT_FBD, &info->nerr_fat_fbd);
411*eb60705aSEric Wollesen 		pci_read_config_word(pvt->branchmap_werrors,
412*eb60705aSEric Wollesen 				     NRECMEMA, &info->nrecmema);
413*eb60705aSEric Wollesen 		pci_read_config_word(pvt->branchmap_werrors,
414*eb60705aSEric Wollesen 				     NRECMEMB, &info->nrecmemb);
415*eb60705aSEric Wollesen 
416*eb60705aSEric Wollesen 		/* Clear the error bits, by writing them back */
417*eb60705aSEric Wollesen 		pci_write_config_dword(pvt->branchmap_werrors,
418*eb60705aSEric Wollesen 				       FERR_FAT_FBD, value);
419*eb60705aSEric Wollesen 	} else {
420*eb60705aSEric Wollesen 		info->ferr_fat_fbd = 0;
421*eb60705aSEric Wollesen 		info->nerr_fat_fbd = 0;
422*eb60705aSEric Wollesen 		info->nrecmema = 0;
423*eb60705aSEric Wollesen 		info->nrecmemb = 0;
424*eb60705aSEric Wollesen 	}
425*eb60705aSEric Wollesen 
426*eb60705aSEric Wollesen 	/* read in the 1st NON-FATAL error register */
427*eb60705aSEric Wollesen 	pci_read_config_dword(pvt->branchmap_werrors, FERR_NF_FBD, &value);
428*eb60705aSEric Wollesen 
429*eb60705aSEric Wollesen 	/* If there is an error, then read in the 1st NON-FATAL error
430*eb60705aSEric Wollesen 	 * register as well */
431*eb60705aSEric Wollesen 	if (value & FERR_NF_MASK) {
432*eb60705aSEric Wollesen 		info->ferr_nf_fbd = value;
433*eb60705aSEric Wollesen 
434*eb60705aSEric Wollesen 		/* harvest the various error data we need */
435*eb60705aSEric Wollesen 		pci_read_config_dword(pvt->branchmap_werrors,
436*eb60705aSEric Wollesen 				      NERR_NF_FBD, &info->nerr_nf_fbd);
437*eb60705aSEric Wollesen 		pci_read_config_word(pvt->branchmap_werrors,
438*eb60705aSEric Wollesen 				     RECMEMA, &info->recmema);
439*eb60705aSEric Wollesen 		pci_read_config_dword(pvt->branchmap_werrors,
440*eb60705aSEric Wollesen 				      RECMEMB, &info->recmemb);
441*eb60705aSEric Wollesen 		pci_read_config_dword(pvt->branchmap_werrors,
442*eb60705aSEric Wollesen 				      REDMEMB, &info->redmemb);
443*eb60705aSEric Wollesen 
444*eb60705aSEric Wollesen 		/* Clear the error bits, by writing them back */
445*eb60705aSEric Wollesen 		pci_write_config_dword(pvt->branchmap_werrors,
446*eb60705aSEric Wollesen 				       FERR_NF_FBD, value);
447*eb60705aSEric Wollesen 	} else {
448*eb60705aSEric Wollesen 		info->ferr_nf_fbd = 0;
449*eb60705aSEric Wollesen 		info->nerr_nf_fbd = 0;
450*eb60705aSEric Wollesen 		info->recmema = 0;
451*eb60705aSEric Wollesen 		info->recmemb = 0;
452*eb60705aSEric Wollesen 		info->redmemb = 0;
453*eb60705aSEric Wollesen 	}
454*eb60705aSEric Wollesen }
455*eb60705aSEric Wollesen 
456*eb60705aSEric Wollesen /******************************************************************************
457*eb60705aSEric Wollesen  * i5000_process_fatal_error_info(struct mem_ctl_info *mci,
458*eb60705aSEric Wollesen  * 					struct i5000_error_info *info,
459*eb60705aSEric Wollesen  * 					int handle_errors);
460*eb60705aSEric Wollesen  *
461*eb60705aSEric Wollesen  *	handle the Intel FATAL errors, if any
462*eb60705aSEric Wollesen  */
463*eb60705aSEric Wollesen static void i5000_process_fatal_error_info(struct mem_ctl_info *mci,
464*eb60705aSEric Wollesen 					   struct i5000_error_info * info,
465*eb60705aSEric Wollesen 					   int handle_errors)
466*eb60705aSEric Wollesen {
467*eb60705aSEric Wollesen 	char msg[EDAC_MC_LABEL_LEN + 1 + 90];
468*eb60705aSEric Wollesen 	u32 allErrors;
469*eb60705aSEric Wollesen 	int branch;
470*eb60705aSEric Wollesen 	int channel;
471*eb60705aSEric Wollesen 	int bank;
472*eb60705aSEric Wollesen 	int rank;
473*eb60705aSEric Wollesen 	int rdwr;
474*eb60705aSEric Wollesen 	int ras, cas;
475*eb60705aSEric Wollesen 
476*eb60705aSEric Wollesen 	/* mask off the Error bits that are possible */
477*eb60705aSEric Wollesen 	allErrors = (info->ferr_fat_fbd & FERR_FAT_MASK);
478*eb60705aSEric Wollesen 	if (!allErrors)
479*eb60705aSEric Wollesen 		return;		/* if no error, return now */
480*eb60705aSEric Wollesen 
481*eb60705aSEric Wollesen 	/* ONLY ONE of the possible error bits will be set, as per the docs */
482*eb60705aSEric Wollesen 	i5000_mc_printk(mci, KERN_ERR,
483*eb60705aSEric Wollesen 			"FATAL ERRORS Found!!! 1st FATAL Err Reg= 0x%x\n",
484*eb60705aSEric Wollesen 			allErrors);
485*eb60705aSEric Wollesen 
486*eb60705aSEric Wollesen 	branch = EXTRACT_FBDCHAN_INDX(info->ferr_fat_fbd);
487*eb60705aSEric Wollesen 	channel = branch;
488*eb60705aSEric Wollesen 
489*eb60705aSEric Wollesen 	/* Use the NON-Recoverable macros to extract data */
490*eb60705aSEric Wollesen 	bank = NREC_BANK(info->nrecmema);
491*eb60705aSEric Wollesen 	rank = NREC_RANK(info->nrecmema);
492*eb60705aSEric Wollesen 	rdwr = NREC_RDWR(info->nrecmema);
493*eb60705aSEric Wollesen 	ras = NREC_RAS(info->nrecmemb);
494*eb60705aSEric Wollesen 	cas = NREC_CAS(info->nrecmemb);
495*eb60705aSEric Wollesen 
496*eb60705aSEric Wollesen 	debugf0("\t\tCSROW= %d  Channels= %d,%d  (Branch= %d "
497*eb60705aSEric Wollesen 		"DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n",
498*eb60705aSEric Wollesen 		rank, channel, channel + 1, branch >> 1, bank,
499*eb60705aSEric Wollesen 		rdwr ? "Write" : "Read", ras, cas);
500*eb60705aSEric Wollesen 
501*eb60705aSEric Wollesen 	/* Only 1 bit will be on */
502*eb60705aSEric Wollesen 	if (allErrors & FERR_FAT_M1ERR) {
503*eb60705aSEric Wollesen 		i5000_mc_printk(mci, KERN_ERR,
504*eb60705aSEric Wollesen 				"Alert on non-redundant retry or fast "
505*eb60705aSEric Wollesen 				"reset timeout\n");
506*eb60705aSEric Wollesen 
507*eb60705aSEric Wollesen 	} else if (allErrors & FERR_FAT_M2ERR) {
508*eb60705aSEric Wollesen 		i5000_mc_printk(mci, KERN_ERR,
509*eb60705aSEric Wollesen 				"Northbound CRC error on non-redundant "
510*eb60705aSEric Wollesen 				"retry\n");
511*eb60705aSEric Wollesen 
512*eb60705aSEric Wollesen 	} else if (allErrors & FERR_FAT_M3ERR) {
513*eb60705aSEric Wollesen 		i5000_mc_printk(mci, KERN_ERR,
514*eb60705aSEric Wollesen 				">Tmid Thermal event with intelligent "
515*eb60705aSEric Wollesen 				"throttling disabled\n");
516*eb60705aSEric Wollesen 	}
517*eb60705aSEric Wollesen 
518*eb60705aSEric Wollesen 	/* Form out message */
519*eb60705aSEric Wollesen 	snprintf(msg, sizeof(msg),
520*eb60705aSEric Wollesen 		 "(Branch=%d DRAM-Bank=%d RDWR=%s RAS=%d CAS=%d "
521*eb60705aSEric Wollesen 		 "FATAL Err=0x%x)",
522*eb60705aSEric Wollesen 		 branch >> 1, bank, rdwr ? "Write" : "Read", ras, cas,
523*eb60705aSEric Wollesen 		 allErrors);
524*eb60705aSEric Wollesen 
525*eb60705aSEric Wollesen 	/* Call the helper to output message */
526*eb60705aSEric Wollesen 	edac_mc_handle_fbd_ue(mci, rank, channel, channel + 1, msg);
527*eb60705aSEric Wollesen }
528*eb60705aSEric Wollesen 
529*eb60705aSEric Wollesen /******************************************************************************
530*eb60705aSEric Wollesen  * i5000_process_fatal_error_info(struct mem_ctl_info *mci,
531*eb60705aSEric Wollesen  * 				  struct i5000_error_info *info,
532*eb60705aSEric Wollesen  * 				  int handle_errors);
533*eb60705aSEric Wollesen  *
534*eb60705aSEric Wollesen  *	handle the Intel NON-FATAL errors, if any
535*eb60705aSEric Wollesen  */
536*eb60705aSEric Wollesen static void i5000_process_nonfatal_error_info(struct mem_ctl_info *mci,
537*eb60705aSEric Wollesen 					      struct i5000_error_info * info,
538*eb60705aSEric Wollesen 					      int handle_errors)
539*eb60705aSEric Wollesen {
540*eb60705aSEric Wollesen 	char msg[EDAC_MC_LABEL_LEN + 1 + 90];
541*eb60705aSEric Wollesen 	u32 allErrors;
542*eb60705aSEric Wollesen 	u32 ue_errors;
543*eb60705aSEric Wollesen 	u32 ce_errors;
544*eb60705aSEric Wollesen 	u32 misc_errors;
545*eb60705aSEric Wollesen 	int branch;
546*eb60705aSEric Wollesen 	int channel;
547*eb60705aSEric Wollesen 	int bank;
548*eb60705aSEric Wollesen 	int rank;
549*eb60705aSEric Wollesen 	int rdwr;
550*eb60705aSEric Wollesen 	int ras, cas;
551*eb60705aSEric Wollesen 
552*eb60705aSEric Wollesen 	/* mask off the Error bits that are possible */
553*eb60705aSEric Wollesen 	allErrors = (info->ferr_nf_fbd & FERR_NF_MASK);
554*eb60705aSEric Wollesen 	if (!allErrors)
555*eb60705aSEric Wollesen 		return;		/* if no error, return now */
556*eb60705aSEric Wollesen 
557*eb60705aSEric Wollesen 	/* ONLY ONE of the possible error bits will be set, as per the docs */
558*eb60705aSEric Wollesen 	i5000_mc_printk(mci, KERN_WARNING,
559*eb60705aSEric Wollesen 			"NON-FATAL ERRORS Found!!! 1st NON-FATAL Err "
560*eb60705aSEric Wollesen 			"Reg= 0x%x\n", allErrors);
561*eb60705aSEric Wollesen 
562*eb60705aSEric Wollesen 	ue_errors = allErrors & FERR_NF_UNCORRECTABLE;
563*eb60705aSEric Wollesen 	if (ue_errors) {
564*eb60705aSEric Wollesen 		debugf0("\tUncorrected bits= 0x%x\n", ue_errors);
565*eb60705aSEric Wollesen 
566*eb60705aSEric Wollesen 		branch = EXTRACT_FBDCHAN_INDX(info->ferr_nf_fbd);
567*eb60705aSEric Wollesen 		channel = branch;
568*eb60705aSEric Wollesen 		bank = NREC_BANK(info->nrecmema);
569*eb60705aSEric Wollesen 		rank = NREC_RANK(info->nrecmema);
570*eb60705aSEric Wollesen 		rdwr = NREC_RDWR(info->nrecmema);
571*eb60705aSEric Wollesen 		ras = NREC_RAS(info->nrecmemb);
572*eb60705aSEric Wollesen 		cas = NREC_CAS(info->nrecmemb);
573*eb60705aSEric Wollesen 
574*eb60705aSEric Wollesen 		debugf0
575*eb60705aSEric Wollesen 		    ("\t\tCSROW= %d  Channels= %d,%d  (Branch= %d "
576*eb60705aSEric Wollesen 		     "DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n",
577*eb60705aSEric Wollesen 		     rank, channel, channel + 1, branch >> 1, bank,
578*eb60705aSEric Wollesen 		     rdwr ? "Write" : "Read", ras, cas);
579*eb60705aSEric Wollesen 
580*eb60705aSEric Wollesen 		/* Form out message */
581*eb60705aSEric Wollesen 		snprintf(msg, sizeof(msg),
582*eb60705aSEric Wollesen 			 "(Branch=%d DRAM-Bank=%d RDWR=%s RAS=%d "
583*eb60705aSEric Wollesen 			 "CAS=%d, UE Err=0x%x)",
584*eb60705aSEric Wollesen 			 branch >> 1, bank, rdwr ? "Write" : "Read", ras, cas,
585*eb60705aSEric Wollesen 			 ue_errors);
586*eb60705aSEric Wollesen 
587*eb60705aSEric Wollesen 		/* Call the helper to output message */
588*eb60705aSEric Wollesen 		edac_mc_handle_fbd_ue(mci, rank, channel, channel + 1, msg);
589*eb60705aSEric Wollesen 	}
590*eb60705aSEric Wollesen 
591*eb60705aSEric Wollesen 	/* Check correctable errors */
592*eb60705aSEric Wollesen 	ce_errors = allErrors & FERR_NF_CORRECTABLE;
593*eb60705aSEric Wollesen 	if (ce_errors) {
594*eb60705aSEric Wollesen 		debugf0("\tCorrected bits= 0x%x\n", ce_errors);
595*eb60705aSEric Wollesen 
596*eb60705aSEric Wollesen 		branch = EXTRACT_FBDCHAN_INDX(info->ferr_nf_fbd);
597*eb60705aSEric Wollesen 
598*eb60705aSEric Wollesen 		channel = 0;
599*eb60705aSEric Wollesen 		if (REC_ECC_LOCATOR_ODD(info->redmemb))
600*eb60705aSEric Wollesen 			channel = 1;
601*eb60705aSEric Wollesen 
602*eb60705aSEric Wollesen 		/* Convert channel to be based from zero, instead of
603*eb60705aSEric Wollesen 		 * from branch base of 0 */
604*eb60705aSEric Wollesen 		channel += branch;
605*eb60705aSEric Wollesen 
606*eb60705aSEric Wollesen 		bank = REC_BANK(info->recmema);
607*eb60705aSEric Wollesen 		rank = REC_RANK(info->recmema);
608*eb60705aSEric Wollesen 		rdwr = REC_RDWR(info->recmema);
609*eb60705aSEric Wollesen 		ras = REC_RAS(info->recmemb);
610*eb60705aSEric Wollesen 		cas = REC_CAS(info->recmemb);
611*eb60705aSEric Wollesen 
612*eb60705aSEric Wollesen 		debugf0("\t\tCSROW= %d Channel= %d  (Branch %d "
613*eb60705aSEric Wollesen 			"DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n",
614*eb60705aSEric Wollesen 			rank, channel, branch >> 1, bank,
615*eb60705aSEric Wollesen 			rdwr ? "Write" : "Read", ras, cas);
616*eb60705aSEric Wollesen 
617*eb60705aSEric Wollesen 		/* Form out message */
618*eb60705aSEric Wollesen 		snprintf(msg, sizeof(msg),
619*eb60705aSEric Wollesen 			 "(Branch=%d DRAM-Bank=%d RDWR=%s RAS=%d "
620*eb60705aSEric Wollesen 			 "CAS=%d, CE Err=0x%x)", branch >> 1, bank,
621*eb60705aSEric Wollesen 			 rdwr ? "Write" : "Read", ras, cas, ce_errors);
622*eb60705aSEric Wollesen 
623*eb60705aSEric Wollesen 		/* Call the helper to output message */
624*eb60705aSEric Wollesen 		edac_mc_handle_fbd_ce(mci, rank, channel, msg);
625*eb60705aSEric Wollesen 	}
626*eb60705aSEric Wollesen 
627*eb60705aSEric Wollesen 	/* See if any of the thermal errors have fired */
628*eb60705aSEric Wollesen 	misc_errors = allErrors & FERR_NF_THERMAL;
629*eb60705aSEric Wollesen 	if (misc_errors) {
630*eb60705aSEric Wollesen 		i5000_printk(KERN_WARNING, "\tTHERMAL Error, bits= 0x%x\n",
631*eb60705aSEric Wollesen 			     misc_errors);
632*eb60705aSEric Wollesen 	}
633*eb60705aSEric Wollesen 
634*eb60705aSEric Wollesen 	/* See if any of the thermal errors have fired */
635*eb60705aSEric Wollesen 	misc_errors = allErrors & FERR_NF_NON_RETRY;
636*eb60705aSEric Wollesen 	if (misc_errors) {
637*eb60705aSEric Wollesen 		i5000_printk(KERN_WARNING, "\tNON-Retry  Errors, bits= 0x%x\n",
638*eb60705aSEric Wollesen 			     misc_errors);
639*eb60705aSEric Wollesen 	}
640*eb60705aSEric Wollesen 
641*eb60705aSEric Wollesen 	/* See if any of the thermal errors have fired */
642*eb60705aSEric Wollesen 	misc_errors = allErrors & FERR_NF_NORTH_CRC;
643*eb60705aSEric Wollesen 	if (misc_errors) {
644*eb60705aSEric Wollesen 		i5000_printk(KERN_WARNING,
645*eb60705aSEric Wollesen 			     "\tNORTHBOUND CRC  Error, bits= 0x%x\n",
646*eb60705aSEric Wollesen 			     misc_errors);
647*eb60705aSEric Wollesen 	}
648*eb60705aSEric Wollesen 
649*eb60705aSEric Wollesen 	/* See if any of the thermal errors have fired */
650*eb60705aSEric Wollesen 	misc_errors = allErrors & FERR_NF_SPD_PROTOCOL;
651*eb60705aSEric Wollesen 	if (misc_errors) {
652*eb60705aSEric Wollesen 		i5000_printk(KERN_WARNING,
653*eb60705aSEric Wollesen 			     "\tSPD Protocol  Error, bits= 0x%x\n",
654*eb60705aSEric Wollesen 			     misc_errors);
655*eb60705aSEric Wollesen 	}
656*eb60705aSEric Wollesen 
657*eb60705aSEric Wollesen 	/* See if any of the thermal errors have fired */
658*eb60705aSEric Wollesen 	misc_errors = allErrors & FERR_NF_DIMM_SPARE;
659*eb60705aSEric Wollesen 	if (misc_errors) {
660*eb60705aSEric Wollesen 		i5000_printk(KERN_WARNING, "\tDIMM-Spare  Error, bits= 0x%x\n",
661*eb60705aSEric Wollesen 			     misc_errors);
662*eb60705aSEric Wollesen 	}
663*eb60705aSEric Wollesen }
664*eb60705aSEric Wollesen 
665*eb60705aSEric Wollesen /******************************************************************************
666*eb60705aSEric Wollesen  *	i5000_process_error_info	Process the error info that is
667*eb60705aSEric Wollesen  *	in the 'info' structure, previously retrieved from hardware
668*eb60705aSEric Wollesen  */
669*eb60705aSEric Wollesen static void i5000_process_error_info(struct mem_ctl_info *mci,
670*eb60705aSEric Wollesen 				     struct i5000_error_info * info,
671*eb60705aSEric Wollesen 				     int handle_errors)
672*eb60705aSEric Wollesen {
673*eb60705aSEric Wollesen 	/* First handle any fatal errors that occurred */
674*eb60705aSEric Wollesen 	i5000_process_fatal_error_info(mci, info, handle_errors);
675*eb60705aSEric Wollesen 
676*eb60705aSEric Wollesen 	/* now handle any non-fatal errors that occurred */
677*eb60705aSEric Wollesen 	i5000_process_nonfatal_error_info(mci, info, handle_errors);
678*eb60705aSEric Wollesen }
679*eb60705aSEric Wollesen 
680*eb60705aSEric Wollesen /******************************************************************************
681*eb60705aSEric Wollesen  *	i5000_clear_error	Retrieve any error from the hardware
682*eb60705aSEric Wollesen  *				but do NOT process that error.
683*eb60705aSEric Wollesen  *				Used for 'clearing' out of previous errors
684*eb60705aSEric Wollesen  *				Called by the Core module.
685*eb60705aSEric Wollesen  */
686*eb60705aSEric Wollesen static void i5000_clear_error(struct mem_ctl_info *mci)
687*eb60705aSEric Wollesen {
688*eb60705aSEric Wollesen 	struct i5000_error_info info;
689*eb60705aSEric Wollesen 
690*eb60705aSEric Wollesen 	i5000_get_error_info(mci, &info);
691*eb60705aSEric Wollesen }
692*eb60705aSEric Wollesen 
693*eb60705aSEric Wollesen /******************************************************************************
694*eb60705aSEric Wollesen  *	i5000_check_error	Retrieve and process errors reported by the
695*eb60705aSEric Wollesen  *				hardware. Called by the Core module.
696*eb60705aSEric Wollesen  */
697*eb60705aSEric Wollesen static void i5000_check_error(struct mem_ctl_info *mci)
698*eb60705aSEric Wollesen {
699*eb60705aSEric Wollesen 	struct i5000_error_info info;
700*eb60705aSEric Wollesen 	debugf4("MC%d: " __FILE__ ": %s()\n", mci->mc_idx, __func__);
701*eb60705aSEric Wollesen 	i5000_get_error_info(mci, &info);
702*eb60705aSEric Wollesen 	i5000_process_error_info(mci, &info, 1);
703*eb60705aSEric Wollesen }
704*eb60705aSEric Wollesen 
705*eb60705aSEric Wollesen /******************************************************************************
706*eb60705aSEric Wollesen  *	i5000_get_devices	Find and perform 'get' operation on the MCH's
707*eb60705aSEric Wollesen  *			device/functions we want to reference for this driver
708*eb60705aSEric Wollesen  *
709*eb60705aSEric Wollesen  *			Need to 'get' device 16 func 1 and func 2
710*eb60705aSEric Wollesen  */
711*eb60705aSEric Wollesen static int i5000_get_devices(struct mem_ctl_info *mci, int dev_idx)
712*eb60705aSEric Wollesen {
713*eb60705aSEric Wollesen 	//const struct i5000_dev_info *i5000_dev = &i5000_devs[dev_idx];
714*eb60705aSEric Wollesen 	struct i5000_pvt *pvt;
715*eb60705aSEric Wollesen 	struct pci_dev *pdev;
716*eb60705aSEric Wollesen 
717*eb60705aSEric Wollesen 	pvt = (struct i5000_pvt *)mci->pvt_info;
718*eb60705aSEric Wollesen 
719*eb60705aSEric Wollesen 	/* Attempt to 'get' the MCH register we want */
720*eb60705aSEric Wollesen 	pdev = NULL;
721*eb60705aSEric Wollesen 	while (1) {
722*eb60705aSEric Wollesen 		pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
723*eb60705aSEric Wollesen 				      PCI_DEVICE_ID_INTEL_I5000_DEV16, pdev);
724*eb60705aSEric Wollesen 
725*eb60705aSEric Wollesen 		/* End of list, leave */
726*eb60705aSEric Wollesen 		if (pdev == NULL) {
727*eb60705aSEric Wollesen 			i5000_printk(KERN_ERR,
728*eb60705aSEric Wollesen 				     "'system address,Process Bus' "
729*eb60705aSEric Wollesen 				     "device not found:"
730*eb60705aSEric Wollesen 				     "vendor 0x%x device 0x%x FUNC 1 "
731*eb60705aSEric Wollesen 				     "(broken BIOS?)\n",
732*eb60705aSEric Wollesen 				     PCI_VENDOR_ID_INTEL,
733*eb60705aSEric Wollesen 				     PCI_DEVICE_ID_INTEL_I5000_DEV16);
734*eb60705aSEric Wollesen 
735*eb60705aSEric Wollesen 			return 1;
736*eb60705aSEric Wollesen 		}
737*eb60705aSEric Wollesen 
738*eb60705aSEric Wollesen 		/* Scan for device 16 func 1 */
739*eb60705aSEric Wollesen 		if (PCI_FUNC(pdev->devfn) == 1)
740*eb60705aSEric Wollesen 			break;
741*eb60705aSEric Wollesen 	}
742*eb60705aSEric Wollesen 
743*eb60705aSEric Wollesen 	pvt->branchmap_werrors = pdev;
744*eb60705aSEric Wollesen 
745*eb60705aSEric Wollesen 	/* Attempt to 'get' the MCH register we want */
746*eb60705aSEric Wollesen 	pdev = NULL;
747*eb60705aSEric Wollesen 	while (1) {
748*eb60705aSEric Wollesen 		pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
749*eb60705aSEric Wollesen 				      PCI_DEVICE_ID_INTEL_I5000_DEV16, pdev);
750*eb60705aSEric Wollesen 
751*eb60705aSEric Wollesen 		if (pdev == NULL) {
752*eb60705aSEric Wollesen 			i5000_printk(KERN_ERR,
753*eb60705aSEric Wollesen 				     "MC: 'branchmap,control,errors' "
754*eb60705aSEric Wollesen 				     "device not found:"
755*eb60705aSEric Wollesen 				     "vendor 0x%x device 0x%x Func 2 "
756*eb60705aSEric Wollesen 				     "(broken BIOS?)\n",
757*eb60705aSEric Wollesen 				     PCI_VENDOR_ID_INTEL,
758*eb60705aSEric Wollesen 				     PCI_DEVICE_ID_INTEL_I5000_DEV16);
759*eb60705aSEric Wollesen 
760*eb60705aSEric Wollesen 			pci_dev_put(pvt->branchmap_werrors);
761*eb60705aSEric Wollesen 			return 1;
762*eb60705aSEric Wollesen 		}
763*eb60705aSEric Wollesen 
764*eb60705aSEric Wollesen 		/* Scan for device 16 func 1 */
765*eb60705aSEric Wollesen 		if (PCI_FUNC(pdev->devfn) == 2)
766*eb60705aSEric Wollesen 			break;
767*eb60705aSEric Wollesen 	}
768*eb60705aSEric Wollesen 
769*eb60705aSEric Wollesen 	pvt->fsb_error_regs = pdev;
770*eb60705aSEric Wollesen 
771*eb60705aSEric Wollesen 	debugf1("System Address, processor bus- PCI Bus ID: %s  %x:%x\n",
772*eb60705aSEric Wollesen 		pci_name(pvt->system_address),
773*eb60705aSEric Wollesen 		pvt->system_address->vendor, pvt->system_address->device);
774*eb60705aSEric Wollesen 	debugf1("Branchmap, control and errors - PCI Bus ID: %s  %x:%x\n",
775*eb60705aSEric Wollesen 		pci_name(pvt->branchmap_werrors),
776*eb60705aSEric Wollesen 		pvt->branchmap_werrors->vendor, pvt->branchmap_werrors->device);
777*eb60705aSEric Wollesen 	debugf1("FSB Error Regs - PCI Bus ID: %s  %x:%x\n",
778*eb60705aSEric Wollesen 		pci_name(pvt->fsb_error_regs),
779*eb60705aSEric Wollesen 		pvt->fsb_error_regs->vendor, pvt->fsb_error_regs->device);
780*eb60705aSEric Wollesen 
781*eb60705aSEric Wollesen 	pdev = NULL;
782*eb60705aSEric Wollesen 	pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
783*eb60705aSEric Wollesen 			      PCI_DEVICE_ID_I5000_BRANCH_0, pdev);
784*eb60705aSEric Wollesen 
785*eb60705aSEric Wollesen 	if (pdev == NULL) {
786*eb60705aSEric Wollesen 		i5000_printk(KERN_ERR,
787*eb60705aSEric Wollesen 			     "MC: 'BRANCH 0' device not found:"
788*eb60705aSEric Wollesen 			     "vendor 0x%x device 0x%x Func 0 (broken BIOS?)\n",
789*eb60705aSEric Wollesen 			     PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_I5000_BRANCH_0);
790*eb60705aSEric Wollesen 
791*eb60705aSEric Wollesen 		pci_dev_put(pvt->branchmap_werrors);
792*eb60705aSEric Wollesen 		pci_dev_put(pvt->fsb_error_regs);
793*eb60705aSEric Wollesen 		return 1;
794*eb60705aSEric Wollesen 	}
795*eb60705aSEric Wollesen 
796*eb60705aSEric Wollesen 	pvt->branch_0 = pdev;
797*eb60705aSEric Wollesen 
798*eb60705aSEric Wollesen 	/* If this device claims to have more than 2 channels then
799*eb60705aSEric Wollesen 	 * fetch Branch 1's information
800*eb60705aSEric Wollesen 	 */
801*eb60705aSEric Wollesen 	if (pvt->maxch >= CHANNELS_PER_BRANCH) {
802*eb60705aSEric Wollesen 		pdev = NULL;
803*eb60705aSEric Wollesen 		pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
804*eb60705aSEric Wollesen 				      PCI_DEVICE_ID_I5000_BRANCH_1, pdev);
805*eb60705aSEric Wollesen 
806*eb60705aSEric Wollesen 		if (pdev == NULL) {
807*eb60705aSEric Wollesen 			i5000_printk(KERN_ERR,
808*eb60705aSEric Wollesen 				     "MC: 'BRANCH 1' device not found:"
809*eb60705aSEric Wollesen 				     "vendor 0x%x device 0x%x Func 0 "
810*eb60705aSEric Wollesen 				     "(broken BIOS?)\n",
811*eb60705aSEric Wollesen 				     PCI_VENDOR_ID_INTEL,
812*eb60705aSEric Wollesen 				     PCI_DEVICE_ID_I5000_BRANCH_1);
813*eb60705aSEric Wollesen 
814*eb60705aSEric Wollesen 			pci_dev_put(pvt->branchmap_werrors);
815*eb60705aSEric Wollesen 			pci_dev_put(pvt->fsb_error_regs);
816*eb60705aSEric Wollesen 			pci_dev_put(pvt->branch_0);
817*eb60705aSEric Wollesen 			return 1;
818*eb60705aSEric Wollesen 		}
819*eb60705aSEric Wollesen 
820*eb60705aSEric Wollesen 		pvt->branch_1 = pdev;
821*eb60705aSEric Wollesen 	}
822*eb60705aSEric Wollesen 
823*eb60705aSEric Wollesen 	return 0;
824*eb60705aSEric Wollesen }
825*eb60705aSEric Wollesen 
826*eb60705aSEric Wollesen /******************************************************************************
827*eb60705aSEric Wollesen  *	i5000_put_devices	'put' all the devices that we have
828*eb60705aSEric Wollesen  *				reserved via 'get'
829*eb60705aSEric Wollesen  */
830*eb60705aSEric Wollesen static void i5000_put_devices(struct mem_ctl_info *mci)
831*eb60705aSEric Wollesen {
832*eb60705aSEric Wollesen 	struct i5000_pvt *pvt;
833*eb60705aSEric Wollesen 
834*eb60705aSEric Wollesen 	pvt = (struct i5000_pvt *)mci->pvt_info;
835*eb60705aSEric Wollesen 
836*eb60705aSEric Wollesen 	pci_dev_put(pvt->branchmap_werrors);	/* FUNC 1 */
837*eb60705aSEric Wollesen 	pci_dev_put(pvt->fsb_error_regs);	/* FUNC 2 */
838*eb60705aSEric Wollesen 	pci_dev_put(pvt->branch_0);	/* DEV 21 */
839*eb60705aSEric Wollesen 
840*eb60705aSEric Wollesen 	/* Only if more than 2 channels do we release the second branch */
841*eb60705aSEric Wollesen 	if (pvt->maxch >= CHANNELS_PER_BRANCH) {
842*eb60705aSEric Wollesen 		pci_dev_put(pvt->branch_1);	/* DEV 22 */
843*eb60705aSEric Wollesen 	}
844*eb60705aSEric Wollesen }
845*eb60705aSEric Wollesen 
846*eb60705aSEric Wollesen /******************************************************************************
847*eb60705aSEric Wollesen  *	determine_amb_resent
848*eb60705aSEric Wollesen  *
849*eb60705aSEric Wollesen  *		the information is contained in NUM_MTRS different registers
850*eb60705aSEric Wollesen  *		determineing which of the NUM_MTRS requires knowing
851*eb60705aSEric Wollesen  *		which channel is in question
852*eb60705aSEric Wollesen  *
853*eb60705aSEric Wollesen  *	2 branches, each with 2 channels
854*eb60705aSEric Wollesen  *		b0_ambpresent0 for channel '0'
855*eb60705aSEric Wollesen  *		b0_ambpresent1 for channel '1'
856*eb60705aSEric Wollesen  *		b1_ambpresent0 for channel '2'
857*eb60705aSEric Wollesen  *		b1_ambpresent1 for channel '3'
858*eb60705aSEric Wollesen  */
859*eb60705aSEric Wollesen static int determine_amb_present_reg(struct i5000_pvt *pvt, int channel)
860*eb60705aSEric Wollesen {
861*eb60705aSEric Wollesen 	int amb_present;
862*eb60705aSEric Wollesen 
863*eb60705aSEric Wollesen 	if (channel < CHANNELS_PER_BRANCH) {
864*eb60705aSEric Wollesen 		if (channel & 0x1)
865*eb60705aSEric Wollesen 			amb_present = pvt->b0_ambpresent1;
866*eb60705aSEric Wollesen 		else
867*eb60705aSEric Wollesen 			amb_present = pvt->b0_ambpresent0;
868*eb60705aSEric Wollesen 	} else {
869*eb60705aSEric Wollesen 		if (channel & 0x1)
870*eb60705aSEric Wollesen 			amb_present = pvt->b1_ambpresent1;
871*eb60705aSEric Wollesen 		else
872*eb60705aSEric Wollesen 			amb_present = pvt->b1_ambpresent0;
873*eb60705aSEric Wollesen 	}
874*eb60705aSEric Wollesen 
875*eb60705aSEric Wollesen 	return amb_present;
876*eb60705aSEric Wollesen }
877*eb60705aSEric Wollesen 
878*eb60705aSEric Wollesen /******************************************************************************
879*eb60705aSEric Wollesen  * determine_mtr(pvt, csrow, channel)
880*eb60705aSEric Wollesen  *
881*eb60705aSEric Wollesen  *	return the proper MTR register as determine by the csrow and channel desired
882*eb60705aSEric Wollesen  */
883*eb60705aSEric Wollesen static int determine_mtr(struct i5000_pvt *pvt, int csrow, int channel)
884*eb60705aSEric Wollesen {
885*eb60705aSEric Wollesen 	int mtr;
886*eb60705aSEric Wollesen 
887*eb60705aSEric Wollesen 	if (channel < CHANNELS_PER_BRANCH)
888*eb60705aSEric Wollesen 		mtr = pvt->b0_mtr[csrow >> 1];
889*eb60705aSEric Wollesen 	else
890*eb60705aSEric Wollesen 		mtr = pvt->b1_mtr[csrow >> 1];
891*eb60705aSEric Wollesen 
892*eb60705aSEric Wollesen 	return mtr;
893*eb60705aSEric Wollesen }
894*eb60705aSEric Wollesen 
895*eb60705aSEric Wollesen /******************************************************************************
896*eb60705aSEric Wollesen  */
897*eb60705aSEric Wollesen static void decode_mtr(int slot_row, u16 mtr)
898*eb60705aSEric Wollesen {
899*eb60705aSEric Wollesen 	int ans;
900*eb60705aSEric Wollesen 
901*eb60705aSEric Wollesen 	ans = MTR_DIMMS_PRESENT(mtr);
902*eb60705aSEric Wollesen 
903*eb60705aSEric Wollesen 	debugf2("\tMTR%d=0x%x:  DIMMs are %s\n", slot_row, mtr,
904*eb60705aSEric Wollesen 		ans ? "Present" : "NOT Present");
905*eb60705aSEric Wollesen 	if (!ans)
906*eb60705aSEric Wollesen 		return;
907*eb60705aSEric Wollesen 
908*eb60705aSEric Wollesen 	debugf2("\t\tWIDTH: x%d\n", MTR_DRAM_WIDTH(mtr));
909*eb60705aSEric Wollesen 	debugf2("\t\tNUMBANK: %d bank(s)\n", MTR_DRAM_BANKS(mtr));
910*eb60705aSEric Wollesen 	debugf2("\t\tNUMRANK: %s\n", MTR_DIMM_RANK(mtr) ? "double" : "single");
911*eb60705aSEric Wollesen 	debugf2("\t\tNUMROW: %s\n", numrow_toString[MTR_DIMM_ROWS(mtr)]);
912*eb60705aSEric Wollesen 	debugf2("\t\tNUMCOL: %s\n", numcol_toString[MTR_DIMM_COLS(mtr)]);
913*eb60705aSEric Wollesen }
914*eb60705aSEric Wollesen 
915*eb60705aSEric Wollesen static void handle_channel(struct i5000_pvt *pvt, int csrow, int channel,
916*eb60705aSEric Wollesen 			   struct i5000_dimm_info *dinfo)
917*eb60705aSEric Wollesen {
918*eb60705aSEric Wollesen 	int mtr;
919*eb60705aSEric Wollesen 	int amb_present_reg;
920*eb60705aSEric Wollesen 	int addrBits;
921*eb60705aSEric Wollesen 
922*eb60705aSEric Wollesen 	mtr = determine_mtr(pvt, csrow, channel);
923*eb60705aSEric Wollesen 	if (MTR_DIMMS_PRESENT(mtr)) {
924*eb60705aSEric Wollesen 		amb_present_reg = determine_amb_present_reg(pvt, channel);
925*eb60705aSEric Wollesen 
926*eb60705aSEric Wollesen 		/* Determine if there is  a  DIMM present in this DIMM slot */
927*eb60705aSEric Wollesen 		if (amb_present_reg & (1 << (csrow >> 1))) {
928*eb60705aSEric Wollesen 			dinfo->dual_rank = MTR_DIMM_RANK(mtr);
929*eb60705aSEric Wollesen 
930*eb60705aSEric Wollesen 			if (!((dinfo->dual_rank == 0) &&
931*eb60705aSEric Wollesen 			      ((csrow & 0x1) == 0x1))) {
932*eb60705aSEric Wollesen 				/* Start with the number of bits for a Bank
933*eb60705aSEric Wollesen 				 * on the DRAM */
934*eb60705aSEric Wollesen 				addrBits = MTR_DRAM_BANKS_ADDR_BITS(mtr);
935*eb60705aSEric Wollesen 				/* Add thenumber of ROW bits */
936*eb60705aSEric Wollesen 				addrBits += MTR_DIMM_ROWS_ADDR_BITS(mtr);
937*eb60705aSEric Wollesen 				/* add the number of COLUMN bits */
938*eb60705aSEric Wollesen 				addrBits += MTR_DIMM_COLS_ADDR_BITS(mtr);
939*eb60705aSEric Wollesen 
940*eb60705aSEric Wollesen 				addrBits += 6;	/* add 64 bits per DIMM */
941*eb60705aSEric Wollesen 				addrBits -= 20;	/* divide by 2^^20 */
942*eb60705aSEric Wollesen 				addrBits -= 3;	/* 8 bits per bytes */
943*eb60705aSEric Wollesen 
944*eb60705aSEric Wollesen 				dinfo->megabytes = 1 << addrBits;
945*eb60705aSEric Wollesen 			}
946*eb60705aSEric Wollesen 		}
947*eb60705aSEric Wollesen 	}
948*eb60705aSEric Wollesen }
949*eb60705aSEric Wollesen 
950*eb60705aSEric Wollesen /******************************************************************************
951*eb60705aSEric Wollesen  *	calculate_dimm_size
952*eb60705aSEric Wollesen  *
953*eb60705aSEric Wollesen  *	also will output a DIMM matrix map, if debug is enabled, for viewing
954*eb60705aSEric Wollesen  *	how the DIMMs are populated
955*eb60705aSEric Wollesen  */
956*eb60705aSEric Wollesen static void calculate_dimm_size(struct i5000_pvt *pvt)
957*eb60705aSEric Wollesen {
958*eb60705aSEric Wollesen 	struct i5000_dimm_info *dinfo;
959*eb60705aSEric Wollesen 	int csrow, max_csrows;
960*eb60705aSEric Wollesen 	char *p, *mem_buffer;
961*eb60705aSEric Wollesen 	int space, n;
962*eb60705aSEric Wollesen 	int channel;
963*eb60705aSEric Wollesen 
964*eb60705aSEric Wollesen 	/* ================= Generate some debug output ================= */
965*eb60705aSEric Wollesen 	space = PAGE_SIZE;
966*eb60705aSEric Wollesen 	mem_buffer = p = kmalloc(space, GFP_KERNEL);
967*eb60705aSEric Wollesen 	if (p == NULL) {
968*eb60705aSEric Wollesen 		i5000_printk(KERN_ERR, "MC: %s:%s() kmalloc() failed\n",
969*eb60705aSEric Wollesen 			    __FILE__, __func__);
970*eb60705aSEric Wollesen 		return;
971*eb60705aSEric Wollesen 	}
972*eb60705aSEric Wollesen 
973*eb60705aSEric Wollesen 	n = snprintf(p, space, "\n");
974*eb60705aSEric Wollesen 	p += n;
975*eb60705aSEric Wollesen 	space -= n;
976*eb60705aSEric Wollesen 
977*eb60705aSEric Wollesen 	/* Scan all the actual CSROWS (which is # of DIMMS * 2)
978*eb60705aSEric Wollesen 	 * and calculate the information for each DIMM
979*eb60705aSEric Wollesen 	 * Start with the highest csrow first, to display it first
980*eb60705aSEric Wollesen 	 * and work toward the 0th csrow
981*eb60705aSEric Wollesen 	 */
982*eb60705aSEric Wollesen 	max_csrows = pvt->maxdimmperch * 2;
983*eb60705aSEric Wollesen 	for (csrow = max_csrows - 1; csrow >= 0; csrow--) {
984*eb60705aSEric Wollesen 
985*eb60705aSEric Wollesen 		/* on an odd csrow, first output a 'boundary' marker,
986*eb60705aSEric Wollesen 		 * then reset the message buffer  */
987*eb60705aSEric Wollesen 		if (csrow & 0x1) {
988*eb60705aSEric Wollesen 			n = snprintf(p, space, "---------------------------"
989*eb60705aSEric Wollesen 				     "--------------------------------");
990*eb60705aSEric Wollesen 			p += n;
991*eb60705aSEric Wollesen 			space -= n;
992*eb60705aSEric Wollesen 			debugf2("%s\n", mem_buffer);
993*eb60705aSEric Wollesen 			p = mem_buffer;
994*eb60705aSEric Wollesen 			space = PAGE_SIZE;
995*eb60705aSEric Wollesen 		}
996*eb60705aSEric Wollesen 		n = snprintf(p, space, "csrow %2d    ", csrow);
997*eb60705aSEric Wollesen 		p += n;
998*eb60705aSEric Wollesen 		space -= n;
999*eb60705aSEric Wollesen 
1000*eb60705aSEric Wollesen 		for (channel = 0; channel < pvt->maxch; channel++) {
1001*eb60705aSEric Wollesen 			dinfo = &pvt->dimm_info[csrow][channel];
1002*eb60705aSEric Wollesen 			handle_channel(pvt, csrow, channel, dinfo);
1003*eb60705aSEric Wollesen 			n = snprintf(p, space, "%4d MB   | ", dinfo->megabytes);
1004*eb60705aSEric Wollesen 			p += n;
1005*eb60705aSEric Wollesen 			space -= n;
1006*eb60705aSEric Wollesen 		}
1007*eb60705aSEric Wollesen 		n = snprintf(p, space, "\n");
1008*eb60705aSEric Wollesen 		p += n;
1009*eb60705aSEric Wollesen 		space -= n;
1010*eb60705aSEric Wollesen 	}
1011*eb60705aSEric Wollesen 
1012*eb60705aSEric Wollesen 	/* Output the last bottom 'boundary' marker */
1013*eb60705aSEric Wollesen 	n = snprintf(p, space, "---------------------------"
1014*eb60705aSEric Wollesen 		     "--------------------------------\n");
1015*eb60705aSEric Wollesen 	p += n;
1016*eb60705aSEric Wollesen 	space -= n;
1017*eb60705aSEric Wollesen 
1018*eb60705aSEric Wollesen 	/* now output the 'channel' labels */
1019*eb60705aSEric Wollesen 	n = snprintf(p, space, "            ");
1020*eb60705aSEric Wollesen 	p += n;
1021*eb60705aSEric Wollesen 	space -= n;
1022*eb60705aSEric Wollesen 	for (channel = 0; channel < pvt->maxch; channel++) {
1023*eb60705aSEric Wollesen 		n = snprintf(p, space, "channel %d | ", channel);
1024*eb60705aSEric Wollesen 		p += n;
1025*eb60705aSEric Wollesen 		space -= n;
1026*eb60705aSEric Wollesen 	}
1027*eb60705aSEric Wollesen 	n = snprintf(p, space, "\n");
1028*eb60705aSEric Wollesen 	p += n;
1029*eb60705aSEric Wollesen 	space -= n;
1030*eb60705aSEric Wollesen 
1031*eb60705aSEric Wollesen 	/* output the last message and free buffer */
1032*eb60705aSEric Wollesen 	debugf2("%s\n", mem_buffer);
1033*eb60705aSEric Wollesen 	kfree(mem_buffer);
1034*eb60705aSEric Wollesen }
1035*eb60705aSEric Wollesen 
1036*eb60705aSEric Wollesen /******************************************************************************
1037*eb60705aSEric Wollesen  *	i5000_get_mc_regs	read in the necessary registers and
1038*eb60705aSEric Wollesen  *				cache locally
1039*eb60705aSEric Wollesen  *
1040*eb60705aSEric Wollesen  *			Fills in the private data members
1041*eb60705aSEric Wollesen  */
1042*eb60705aSEric Wollesen static void i5000_get_mc_regs(struct mem_ctl_info *mci)
1043*eb60705aSEric Wollesen {
1044*eb60705aSEric Wollesen 	struct i5000_pvt *pvt;
1045*eb60705aSEric Wollesen 	u32 actual_tolm;
1046*eb60705aSEric Wollesen 	u16 limit;
1047*eb60705aSEric Wollesen 	int slot_row;
1048*eb60705aSEric Wollesen 	int maxch;
1049*eb60705aSEric Wollesen 	int maxdimmperch;
1050*eb60705aSEric Wollesen 	int way0, way1;
1051*eb60705aSEric Wollesen 
1052*eb60705aSEric Wollesen 	pvt = (struct i5000_pvt *)mci->pvt_info;
1053*eb60705aSEric Wollesen 
1054*eb60705aSEric Wollesen 	pci_read_config_dword(pvt->system_address, AMBASE,
1055*eb60705aSEric Wollesen 			      (u32 *) & pvt->ambase);
1056*eb60705aSEric Wollesen 	pci_read_config_dword(pvt->system_address, AMBASE + sizeof(u32),
1057*eb60705aSEric Wollesen 			      ((u32 *) & pvt->ambase) + sizeof(u32));
1058*eb60705aSEric Wollesen 
1059*eb60705aSEric Wollesen 	maxdimmperch = pvt->maxdimmperch;
1060*eb60705aSEric Wollesen 	maxch = pvt->maxch;
1061*eb60705aSEric Wollesen 
1062*eb60705aSEric Wollesen 	debugf2("AMBASE= 0x%lx  MAXCH= %d  MAX-DIMM-Per-CH= %d\n",
1063*eb60705aSEric Wollesen 		(long unsigned int)pvt->ambase, pvt->maxch, pvt->maxdimmperch);
1064*eb60705aSEric Wollesen 
1065*eb60705aSEric Wollesen 	/* Get the Branch Map regs */
1066*eb60705aSEric Wollesen 	pci_read_config_word(pvt->branchmap_werrors, TOLM, &pvt->tolm);
1067*eb60705aSEric Wollesen 	pvt->tolm >>= 12;
1068*eb60705aSEric Wollesen 	debugf2("\nTOLM (number of 256M regions) =%u (0x%x)\n", pvt->tolm,
1069*eb60705aSEric Wollesen 		pvt->tolm);
1070*eb60705aSEric Wollesen 
1071*eb60705aSEric Wollesen 	actual_tolm = pvt->tolm << 28;
1072*eb60705aSEric Wollesen 	debugf2("Actual TOLM byte addr=%u (0x%x)\n", actual_tolm, actual_tolm);
1073*eb60705aSEric Wollesen 
1074*eb60705aSEric Wollesen 	pci_read_config_word(pvt->branchmap_werrors, MIR0, &pvt->mir0);
1075*eb60705aSEric Wollesen 	pci_read_config_word(pvt->branchmap_werrors, MIR1, &pvt->mir1);
1076*eb60705aSEric Wollesen 	pci_read_config_word(pvt->branchmap_werrors, MIR2, &pvt->mir2);
1077*eb60705aSEric Wollesen 
1078*eb60705aSEric Wollesen 	/* Get the MIR[0-2] regs */
1079*eb60705aSEric Wollesen 	limit = (pvt->mir0 >> 4) & 0x0FFF;
1080*eb60705aSEric Wollesen 	way0 = pvt->mir0 & 0x1;
1081*eb60705aSEric Wollesen 	way1 = pvt->mir0 & 0x2;
1082*eb60705aSEric Wollesen 	debugf2("MIR0: limit= 0x%x  WAY1= %u  WAY0= %x\n", limit, way1, way0);
1083*eb60705aSEric Wollesen 	limit = (pvt->mir1 >> 4) & 0x0FFF;
1084*eb60705aSEric Wollesen 	way0 = pvt->mir1 & 0x1;
1085*eb60705aSEric Wollesen 	way1 = pvt->mir1 & 0x2;
1086*eb60705aSEric Wollesen 	debugf2("MIR1: limit= 0x%x  WAY1= %u  WAY0= %x\n", limit, way1, way0);
1087*eb60705aSEric Wollesen 	limit = (pvt->mir2 >> 4) & 0x0FFF;
1088*eb60705aSEric Wollesen 	way0 = pvt->mir2 & 0x1;
1089*eb60705aSEric Wollesen 	way1 = pvt->mir2 & 0x2;
1090*eb60705aSEric Wollesen 	debugf2("MIR2: limit= 0x%x  WAY1= %u  WAY0= %x\n", limit, way1, way0);
1091*eb60705aSEric Wollesen 
1092*eb60705aSEric Wollesen 	/* Get the MTR[0-3] regs */
1093*eb60705aSEric Wollesen 	for (slot_row = 0; slot_row < NUM_MTRS; slot_row++) {
1094*eb60705aSEric Wollesen 		int where = MTR0 + (slot_row * sizeof(u32));
1095*eb60705aSEric Wollesen 
1096*eb60705aSEric Wollesen 		pci_read_config_word(pvt->branch_0, where,
1097*eb60705aSEric Wollesen 				     &pvt->b0_mtr[slot_row]);
1098*eb60705aSEric Wollesen 
1099*eb60705aSEric Wollesen 		debugf2("MTR%d where=0x%x B0 value=0x%x\n", slot_row, where,
1100*eb60705aSEric Wollesen 			pvt->b0_mtr[slot_row]);
1101*eb60705aSEric Wollesen 
1102*eb60705aSEric Wollesen 		if (pvt->maxch >= CHANNELS_PER_BRANCH) {
1103*eb60705aSEric Wollesen 			pci_read_config_word(pvt->branch_1, where,
1104*eb60705aSEric Wollesen 					     &pvt->b1_mtr[slot_row]);
1105*eb60705aSEric Wollesen 			debugf2("MTR%d where=0x%x B1 value=0x%x\n", slot_row,
1106*eb60705aSEric Wollesen 				where, pvt->b0_mtr[slot_row]);
1107*eb60705aSEric Wollesen 		} else {
1108*eb60705aSEric Wollesen 			pvt->b1_mtr[slot_row] = 0;
1109*eb60705aSEric Wollesen 		}
1110*eb60705aSEric Wollesen 	}
1111*eb60705aSEric Wollesen 
1112*eb60705aSEric Wollesen 	/* Read and dump branch 0's MTRs */
1113*eb60705aSEric Wollesen 	debugf2("\nMemory Technology Registers:\n");
1114*eb60705aSEric Wollesen 	debugf2("   Branch 0:\n");
1115*eb60705aSEric Wollesen 	for (slot_row = 0; slot_row < NUM_MTRS; slot_row++) {
1116*eb60705aSEric Wollesen 		decode_mtr(slot_row, pvt->b0_mtr[slot_row]);
1117*eb60705aSEric Wollesen 	}
1118*eb60705aSEric Wollesen 	pci_read_config_word(pvt->branch_0, AMB_PRESENT_0,
1119*eb60705aSEric Wollesen 			     &pvt->b0_ambpresent0);
1120*eb60705aSEric Wollesen 	debugf2("\t\tAMB-Branch 0-present0 0x%x:\n", pvt->b0_ambpresent0);
1121*eb60705aSEric Wollesen 	pci_read_config_word(pvt->branch_0, AMB_PRESENT_1,
1122*eb60705aSEric Wollesen 			     &pvt->b0_ambpresent1);
1123*eb60705aSEric Wollesen 	debugf2("\t\tAMB-Branch 0-present1 0x%x:\n", pvt->b0_ambpresent1);
1124*eb60705aSEric Wollesen 
1125*eb60705aSEric Wollesen 	/* Only if we have 2 branchs (4 channels) */
1126*eb60705aSEric Wollesen 	if (pvt->maxch < CHANNELS_PER_BRANCH) {
1127*eb60705aSEric Wollesen 		pvt->b1_ambpresent0 = 0;
1128*eb60705aSEric Wollesen 		pvt->b1_ambpresent1 = 0;
1129*eb60705aSEric Wollesen 	} else {
1130*eb60705aSEric Wollesen 		/* Read and dump  branch 1's MTRs */
1131*eb60705aSEric Wollesen 		debugf2("   Branch 1:\n");
1132*eb60705aSEric Wollesen 		for (slot_row = 0; slot_row < NUM_MTRS; slot_row++) {
1133*eb60705aSEric Wollesen 			decode_mtr(slot_row, pvt->b1_mtr[slot_row]);
1134*eb60705aSEric Wollesen 		}
1135*eb60705aSEric Wollesen 		pci_read_config_word(pvt->branch_1, AMB_PRESENT_0,
1136*eb60705aSEric Wollesen 				     &pvt->b1_ambpresent0);
1137*eb60705aSEric Wollesen 		debugf2("\t\tAMB-Branch 1-present0 0x%x:\n",
1138*eb60705aSEric Wollesen 			pvt->b1_ambpresent0);
1139*eb60705aSEric Wollesen 		pci_read_config_word(pvt->branch_1, AMB_PRESENT_1,
1140*eb60705aSEric Wollesen 				     &pvt->b1_ambpresent1);
1141*eb60705aSEric Wollesen 		debugf2("\t\tAMB-Branch 1-present1 0x%x:\n",
1142*eb60705aSEric Wollesen 			pvt->b1_ambpresent1);
1143*eb60705aSEric Wollesen 	}
1144*eb60705aSEric Wollesen 
1145*eb60705aSEric Wollesen 	/* Go and determine the size of each DIMM and place in an
1146*eb60705aSEric Wollesen 	 * orderly matrix */
1147*eb60705aSEric Wollesen 	calculate_dimm_size(pvt);
1148*eb60705aSEric Wollesen }
1149*eb60705aSEric Wollesen 
1150*eb60705aSEric Wollesen /******************************************************************************
1151*eb60705aSEric Wollesen  *	i5000_init_csrows	Initialize the 'csrows' table within
1152*eb60705aSEric Wollesen  *				the mci control	structure with the
1153*eb60705aSEric Wollesen  *				addressing of memory.
1154*eb60705aSEric Wollesen  *
1155*eb60705aSEric Wollesen  *	return:
1156*eb60705aSEric Wollesen  *		0	success
1157*eb60705aSEric Wollesen  *		1	no actual memory found on this MC
1158*eb60705aSEric Wollesen  */
1159*eb60705aSEric Wollesen static int i5000_init_csrows(struct mem_ctl_info *mci)
1160*eb60705aSEric Wollesen {
1161*eb60705aSEric Wollesen 	struct i5000_pvt *pvt;
1162*eb60705aSEric Wollesen 	struct csrow_info *p_csrow;
1163*eb60705aSEric Wollesen 	int empty, channel_count;
1164*eb60705aSEric Wollesen 	int max_csrows;
1165*eb60705aSEric Wollesen 	int mtr;
1166*eb60705aSEric Wollesen 	int csrow_megs;
1167*eb60705aSEric Wollesen 	int channel;
1168*eb60705aSEric Wollesen 	int csrow;
1169*eb60705aSEric Wollesen 
1170*eb60705aSEric Wollesen 	pvt = (struct i5000_pvt *)mci->pvt_info;
1171*eb60705aSEric Wollesen 
1172*eb60705aSEric Wollesen 	channel_count = pvt->maxch;
1173*eb60705aSEric Wollesen 	max_csrows = pvt->maxdimmperch * 2;
1174*eb60705aSEric Wollesen 
1175*eb60705aSEric Wollesen 	empty = 1;		/* Assume NO memory */
1176*eb60705aSEric Wollesen 
1177*eb60705aSEric Wollesen 	for (csrow = 0; csrow < max_csrows; csrow++) {
1178*eb60705aSEric Wollesen 		p_csrow = &mci->csrows[csrow];
1179*eb60705aSEric Wollesen 
1180*eb60705aSEric Wollesen 		p_csrow->csrow_idx = csrow;
1181*eb60705aSEric Wollesen 
1182*eb60705aSEric Wollesen 		/* use branch 0 for the basis */
1183*eb60705aSEric Wollesen 		mtr = pvt->b0_mtr[csrow >> 1];
1184*eb60705aSEric Wollesen 
1185*eb60705aSEric Wollesen 		/* if no DIMMS on this row, continue */
1186*eb60705aSEric Wollesen 		if (!MTR_DIMMS_PRESENT(mtr))
1187*eb60705aSEric Wollesen 			continue;
1188*eb60705aSEric Wollesen 
1189*eb60705aSEric Wollesen 		/* FAKE OUT VALUES, FIXME */
1190*eb60705aSEric Wollesen 		p_csrow->first_page = 0 + csrow * 20;
1191*eb60705aSEric Wollesen 		p_csrow->last_page = 9 + csrow * 20;
1192*eb60705aSEric Wollesen 		p_csrow->page_mask = 0xFFF;
1193*eb60705aSEric Wollesen 
1194*eb60705aSEric Wollesen 		p_csrow->grain = 8;
1195*eb60705aSEric Wollesen 
1196*eb60705aSEric Wollesen 		csrow_megs = 0;
1197*eb60705aSEric Wollesen 		for (channel = 0; channel < pvt->maxch; channel++) {
1198*eb60705aSEric Wollesen 			csrow_megs += pvt->dimm_info[csrow][channel].megabytes;
1199*eb60705aSEric Wollesen 		}
1200*eb60705aSEric Wollesen 
1201*eb60705aSEric Wollesen 		p_csrow->nr_pages = csrow_megs << 8;
1202*eb60705aSEric Wollesen 
1203*eb60705aSEric Wollesen 		/* Assume DDR2 for now */
1204*eb60705aSEric Wollesen 		p_csrow->mtype = MEM_FB_DDR2;
1205*eb60705aSEric Wollesen 
1206*eb60705aSEric Wollesen 		/* ask what device type on this row */
1207*eb60705aSEric Wollesen 		if (MTR_DRAM_WIDTH(mtr))
1208*eb60705aSEric Wollesen 			p_csrow->dtype = DEV_X8;
1209*eb60705aSEric Wollesen 		else
1210*eb60705aSEric Wollesen 			p_csrow->dtype = DEV_X4;
1211*eb60705aSEric Wollesen 
1212*eb60705aSEric Wollesen 		p_csrow->edac_mode = EDAC_S8ECD8ED;
1213*eb60705aSEric Wollesen 
1214*eb60705aSEric Wollesen 		empty = 0;
1215*eb60705aSEric Wollesen 	}
1216*eb60705aSEric Wollesen 
1217*eb60705aSEric Wollesen 	return empty;
1218*eb60705aSEric Wollesen }
1219*eb60705aSEric Wollesen 
1220*eb60705aSEric Wollesen /******************************************************************************
1221*eb60705aSEric Wollesen  *	i5000_enable_error_reporting
1222*eb60705aSEric Wollesen  *			Turn on the memory reporting features of the hardware
1223*eb60705aSEric Wollesen  */
1224*eb60705aSEric Wollesen static void i5000_enable_error_reporting(struct mem_ctl_info *mci)
1225*eb60705aSEric Wollesen {
1226*eb60705aSEric Wollesen 	struct i5000_pvt *pvt;
1227*eb60705aSEric Wollesen 	u32 fbd_error_mask;
1228*eb60705aSEric Wollesen 
1229*eb60705aSEric Wollesen 	pvt = (struct i5000_pvt *)mci->pvt_info;
1230*eb60705aSEric Wollesen 
1231*eb60705aSEric Wollesen 	/* Read the FBD Error Mask Register */
1232*eb60705aSEric Wollesen 	pci_read_config_dword(pvt->branchmap_werrors, EMASK_FBD,
1233*eb60705aSEric Wollesen 			      &fbd_error_mask);
1234*eb60705aSEric Wollesen 
1235*eb60705aSEric Wollesen 	/* Enable with a '0' */
1236*eb60705aSEric Wollesen 	fbd_error_mask &= ~(ENABLE_EMASK_ALL);
1237*eb60705aSEric Wollesen 
1238*eb60705aSEric Wollesen 	pci_write_config_dword(pvt->branchmap_werrors, EMASK_FBD,
1239*eb60705aSEric Wollesen 			       fbd_error_mask);
1240*eb60705aSEric Wollesen }
1241*eb60705aSEric Wollesen 
1242*eb60705aSEric Wollesen /******************************************************************************
1243*eb60705aSEric Wollesen  * i5000_get_dimm_and_channel_counts(pdev, &num_csrows, &num_channels)
1244*eb60705aSEric Wollesen  *
1245*eb60705aSEric Wollesen  *	ask the device how many channels are present and how many CSROWS
1246*eb60705aSEric Wollesen  *	 as well
1247*eb60705aSEric Wollesen  */
1248*eb60705aSEric Wollesen static void i5000_get_dimm_and_channel_counts(struct pci_dev *pdev,
1249*eb60705aSEric Wollesen 					      int *num_dimms_per_channel,
1250*eb60705aSEric Wollesen 					      int *num_channels)
1251*eb60705aSEric Wollesen {
1252*eb60705aSEric Wollesen 	u8 value;
1253*eb60705aSEric Wollesen 
1254*eb60705aSEric Wollesen 	/* Need to retrieve just how many channels and dimms per channel are
1255*eb60705aSEric Wollesen 	 * supported on this memory controller
1256*eb60705aSEric Wollesen 	 */
1257*eb60705aSEric Wollesen 	pci_read_config_byte(pdev, MAXDIMMPERCH, &value);
1258*eb60705aSEric Wollesen 	*num_dimms_per_channel = (int)value *2;
1259*eb60705aSEric Wollesen 
1260*eb60705aSEric Wollesen 	pci_read_config_byte(pdev, MAXCH, &value);
1261*eb60705aSEric Wollesen 	*num_channels = (int)value;
1262*eb60705aSEric Wollesen }
1263*eb60705aSEric Wollesen 
1264*eb60705aSEric Wollesen /******************************************************************************
1265*eb60705aSEric Wollesen  *	i5000_probe1	Probe for ONE instance of device to see if it is
1266*eb60705aSEric Wollesen  *			present.
1267*eb60705aSEric Wollesen  *	return:
1268*eb60705aSEric Wollesen  *		0 for FOUND a device
1269*eb60705aSEric Wollesen  *		< 0 for error code
1270*eb60705aSEric Wollesen  */
1271*eb60705aSEric Wollesen static int i5000_probe1(struct pci_dev *pdev, int dev_idx)
1272*eb60705aSEric Wollesen {
1273*eb60705aSEric Wollesen 	struct mem_ctl_info *mci;
1274*eb60705aSEric Wollesen 	struct i5000_pvt *pvt;
1275*eb60705aSEric Wollesen 	int num_channels;
1276*eb60705aSEric Wollesen 	int num_dimms_per_channel;
1277*eb60705aSEric Wollesen 	int num_csrows;
1278*eb60705aSEric Wollesen 
1279*eb60705aSEric Wollesen 	debugf0("MC: " __FILE__ ": %s(), pdev bus %u dev=0x%x fn=0x%x\n",
1280*eb60705aSEric Wollesen 		__func__,
1281*eb60705aSEric Wollesen 		pdev->bus->number,
1282*eb60705aSEric Wollesen 		PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
1283*eb60705aSEric Wollesen 
1284*eb60705aSEric Wollesen 	/* We only are looking for func 0 of the set */
1285*eb60705aSEric Wollesen 	if (PCI_FUNC(pdev->devfn) != 0)
1286*eb60705aSEric Wollesen 		return -ENODEV;
1287*eb60705aSEric Wollesen 
1288*eb60705aSEric Wollesen 	/* Ask the devices for the number of CSROWS and CHANNELS so
1289*eb60705aSEric Wollesen 	 * that we can calculate the memory resources, etc
1290*eb60705aSEric Wollesen 	 *
1291*eb60705aSEric Wollesen 	 * The Chipset will report what it can handle which will be greater
1292*eb60705aSEric Wollesen 	 * or equal to what the motherboard manufacturer will implement.
1293*eb60705aSEric Wollesen 	 *
1294*eb60705aSEric Wollesen 	 * As we don't have a motherboard identification routine to determine
1295*eb60705aSEric Wollesen 	 * actual number of slots/dimms per channel, we thus utilize the
1296*eb60705aSEric Wollesen 	 * resource as specified by the chipset. Thus, we might have
1297*eb60705aSEric Wollesen 	 * have more DIMMs per channel than actually on the mobo, but this
1298*eb60705aSEric Wollesen 	 * allows the driver to support upto the chipset max, without
1299*eb60705aSEric Wollesen 	 * some fancy mobo determination.
1300*eb60705aSEric Wollesen 	 */
1301*eb60705aSEric Wollesen 	i5000_get_dimm_and_channel_counts(pdev, &num_dimms_per_channel,
1302*eb60705aSEric Wollesen 					  &num_channels);
1303*eb60705aSEric Wollesen 	num_csrows = num_dimms_per_channel * 2;
1304*eb60705aSEric Wollesen 
1305*eb60705aSEric Wollesen 	debugf0("MC: %s(): Number of - Channels= %d  DIMMS= %d  CSROWS= %d\n",
1306*eb60705aSEric Wollesen 		__func__, num_channels, num_dimms_per_channel, num_csrows);
1307*eb60705aSEric Wollesen 
1308*eb60705aSEric Wollesen 	/* allocate a new MC control structure */
1309*eb60705aSEric Wollesen 	mci = edac_mc_alloc(sizeof(*pvt), num_csrows, num_channels);
1310*eb60705aSEric Wollesen 
1311*eb60705aSEric Wollesen 	if (mci == NULL)
1312*eb60705aSEric Wollesen 		return -ENOMEM;
1313*eb60705aSEric Wollesen 
1314*eb60705aSEric Wollesen 	debugf0("MC: " __FILE__ ": %s(): mci = %p\n", __func__, mci);
1315*eb60705aSEric Wollesen 
1316*eb60705aSEric Wollesen 	mci->dev = &pdev->dev;	/* record ptr  to the generic device */
1317*eb60705aSEric Wollesen 
1318*eb60705aSEric Wollesen 	pvt = (struct i5000_pvt *)mci->pvt_info;
1319*eb60705aSEric Wollesen 	pvt->system_address = pdev;	/* Record this device in our private */
1320*eb60705aSEric Wollesen 	pvt->maxch = num_channels;
1321*eb60705aSEric Wollesen 	pvt->maxdimmperch = num_dimms_per_channel;
1322*eb60705aSEric Wollesen 
1323*eb60705aSEric Wollesen 	/* 'get' the pci devices we want to reserve for our use */
1324*eb60705aSEric Wollesen 	if (i5000_get_devices(mci, dev_idx))
1325*eb60705aSEric Wollesen 		goto fail0;
1326*eb60705aSEric Wollesen 
1327*eb60705aSEric Wollesen 	/* Time to get serious */
1328*eb60705aSEric Wollesen 	i5000_get_mc_regs(mci);	/* retrieve the hardware registers */
1329*eb60705aSEric Wollesen 
1330*eb60705aSEric Wollesen 	mci->mc_idx = 0;
1331*eb60705aSEric Wollesen 	mci->mtype_cap = MEM_FLAG_FB_DDR2;
1332*eb60705aSEric Wollesen 	mci->edac_ctl_cap = EDAC_FLAG_NONE;
1333*eb60705aSEric Wollesen 	mci->edac_cap = EDAC_FLAG_NONE;
1334*eb60705aSEric Wollesen 	mci->mod_name = "i5000_edac.c";
1335*eb60705aSEric Wollesen 	mci->mod_ver = I5000_REVISION;
1336*eb60705aSEric Wollesen 	mci->ctl_name = i5000_devs[dev_idx].ctl_name;
1337*eb60705aSEric Wollesen 	mci->ctl_page_to_phys = NULL;
1338*eb60705aSEric Wollesen 
1339*eb60705aSEric Wollesen 	/* Set the function pointer to an actual operation function */
1340*eb60705aSEric Wollesen 	mci->edac_check = i5000_check_error;
1341*eb60705aSEric Wollesen 
1342*eb60705aSEric Wollesen 	/* initialize the MC control structure 'csrows' table
1343*eb60705aSEric Wollesen 	 * with the mapping and control information */
1344*eb60705aSEric Wollesen 	if (i5000_init_csrows(mci)) {
1345*eb60705aSEric Wollesen 		debugf0("MC: Setting mci->edac_cap to EDAC_FLAG_NONE\n"
1346*eb60705aSEric Wollesen 			"    because i5000_init_csrows() returned nonzero "
1347*eb60705aSEric Wollesen 			"value\n");
1348*eb60705aSEric Wollesen 		mci->edac_cap = EDAC_FLAG_NONE;	/* no csrows found */
1349*eb60705aSEric Wollesen 	} else {
1350*eb60705aSEric Wollesen 		debugf1("MC: Enable error reporting now\n");
1351*eb60705aSEric Wollesen 		i5000_enable_error_reporting(mci);
1352*eb60705aSEric Wollesen 	}
1353*eb60705aSEric Wollesen 
1354*eb60705aSEric Wollesen 	/* add this new MC control structure to EDAC's list of MCs */
1355*eb60705aSEric Wollesen 	if (edac_mc_add_mc(mci, pvt->node_id)) {
1356*eb60705aSEric Wollesen 		debugf0("MC: " __FILE__
1357*eb60705aSEric Wollesen 			": %s(): failed edac_mc_add_mc()\n", __func__);
1358*eb60705aSEric Wollesen 		/* FIXME: perhaps some code should go here that disables error
1359*eb60705aSEric Wollesen 		 * reporting if we just enabled it
1360*eb60705aSEric Wollesen 		 */
1361*eb60705aSEric Wollesen 		goto fail1;
1362*eb60705aSEric Wollesen 	}
1363*eb60705aSEric Wollesen 
1364*eb60705aSEric Wollesen 	i5000_clear_error(mci);
1365*eb60705aSEric Wollesen 
1366*eb60705aSEric Wollesen 	return 0;
1367*eb60705aSEric Wollesen 
1368*eb60705aSEric Wollesen 	/* Error exit unwinding stack */
1369*eb60705aSEric Wollesen       fail1:
1370*eb60705aSEric Wollesen 
1371*eb60705aSEric Wollesen 	i5000_put_devices(mci);
1372*eb60705aSEric Wollesen 
1373*eb60705aSEric Wollesen       fail0:
1374*eb60705aSEric Wollesen 	edac_mc_free(mci);
1375*eb60705aSEric Wollesen 	return -ENODEV;
1376*eb60705aSEric Wollesen }
1377*eb60705aSEric Wollesen 
1378*eb60705aSEric Wollesen /******************************************************************************
1379*eb60705aSEric Wollesen  *	i5000_init_one	constructor for one instance of device
1380*eb60705aSEric Wollesen  *
1381*eb60705aSEric Wollesen  * 	returns:
1382*eb60705aSEric Wollesen  *		negative on error
1383*eb60705aSEric Wollesen  *		count (>= 0)
1384*eb60705aSEric Wollesen  */
1385*eb60705aSEric Wollesen static int __devinit i5000_init_one(struct pci_dev *pdev,
1386*eb60705aSEric Wollesen 				    const struct pci_device_id *id)
1387*eb60705aSEric Wollesen {
1388*eb60705aSEric Wollesen 	int rc;
1389*eb60705aSEric Wollesen 
1390*eb60705aSEric Wollesen 	debugf0("MC: " __FILE__ ": %s()\n", __func__);
1391*eb60705aSEric Wollesen 
1392*eb60705aSEric Wollesen 	/* wake up device */
1393*eb60705aSEric Wollesen 	rc = pci_enable_device(pdev);
1394*eb60705aSEric Wollesen 	if (rc == -EIO)
1395*eb60705aSEric Wollesen 		return rc;
1396*eb60705aSEric Wollesen 
1397*eb60705aSEric Wollesen 	/* now probe and enable the device */
1398*eb60705aSEric Wollesen 	return i5000_probe1(pdev, id->driver_data);
1399*eb60705aSEric Wollesen }
1400*eb60705aSEric Wollesen 
1401*eb60705aSEric Wollesen /**************************************************************************
1402*eb60705aSEric Wollesen  *	i5000_remove_one	destructor for one instance of device
1403*eb60705aSEric Wollesen  *
1404*eb60705aSEric Wollesen  */
1405*eb60705aSEric Wollesen static void __devexit i5000_remove_one(struct pci_dev *pdev)
1406*eb60705aSEric Wollesen {
1407*eb60705aSEric Wollesen 	struct mem_ctl_info *mci;
1408*eb60705aSEric Wollesen 
1409*eb60705aSEric Wollesen 	debugf0(__FILE__ ": %s()\n", __func__);
1410*eb60705aSEric Wollesen 
1411*eb60705aSEric Wollesen 	if ((mci = edac_mc_del_mc(&pdev->dev)) == NULL)
1412*eb60705aSEric Wollesen 		return;
1413*eb60705aSEric Wollesen 
1414*eb60705aSEric Wollesen 	/* retrieve references to resources, and free those resources */
1415*eb60705aSEric Wollesen 	i5000_put_devices(mci);
1416*eb60705aSEric Wollesen 
1417*eb60705aSEric Wollesen 	edac_mc_free(mci);
1418*eb60705aSEric Wollesen }
1419*eb60705aSEric Wollesen 
1420*eb60705aSEric Wollesen /**************************************************************************
1421*eb60705aSEric Wollesen  *	pci_device_id	table for which devices we are looking for
1422*eb60705aSEric Wollesen  *
1423*eb60705aSEric Wollesen  *	The "E500P" device is the first device supported.
1424*eb60705aSEric Wollesen  */
1425*eb60705aSEric Wollesen static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
1426*eb60705aSEric Wollesen 	{PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
1427*eb60705aSEric Wollesen 	 .driver_data = I5000P},
1428*eb60705aSEric Wollesen 
1429*eb60705aSEric Wollesen 	{0,}			/* 0 terminated list. */
1430*eb60705aSEric Wollesen };
1431*eb60705aSEric Wollesen 
1432*eb60705aSEric Wollesen MODULE_DEVICE_TABLE(pci, i5000_pci_tbl);
1433*eb60705aSEric Wollesen 
1434*eb60705aSEric Wollesen /**************************************************************************
1435*eb60705aSEric Wollesen  *	i5000_driver	pci_driver structure for this module
1436*eb60705aSEric Wollesen  *
1437*eb60705aSEric Wollesen  */
1438*eb60705aSEric Wollesen static struct pci_driver i5000_driver = {
1439*eb60705aSEric Wollesen 	.name = __stringify(KBUILD_BASENAME),
1440*eb60705aSEric Wollesen 	.probe = i5000_init_one,
1441*eb60705aSEric Wollesen 	.remove = __devexit_p(i5000_remove_one),
1442*eb60705aSEric Wollesen 	.id_table = i5000_pci_tbl,
1443*eb60705aSEric Wollesen };
1444*eb60705aSEric Wollesen 
1445*eb60705aSEric Wollesen /**************************************************************************
1446*eb60705aSEric Wollesen  *	i5000_init		Module entry function
1447*eb60705aSEric Wollesen  *			Try to initialize this module for its devices
1448*eb60705aSEric Wollesen  */
1449*eb60705aSEric Wollesen static int __init i5000_init(void)
1450*eb60705aSEric Wollesen {
1451*eb60705aSEric Wollesen 	int pci_rc;
1452*eb60705aSEric Wollesen 
1453*eb60705aSEric Wollesen 	debugf2("MC: " __FILE__ ": %s()\n", __func__);
1454*eb60705aSEric Wollesen 
1455*eb60705aSEric Wollesen 	pci_rc = pci_register_driver(&i5000_driver);
1456*eb60705aSEric Wollesen 
1457*eb60705aSEric Wollesen 	return (pci_rc < 0) ? pci_rc : 0;
1458*eb60705aSEric Wollesen }
1459*eb60705aSEric Wollesen 
1460*eb60705aSEric Wollesen /**************************************************************************
1461*eb60705aSEric Wollesen  *	i5000_exit()	Module exit function
1462*eb60705aSEric Wollesen  *			Unregister the driver
1463*eb60705aSEric Wollesen  */
1464*eb60705aSEric Wollesen static void __exit i5000_exit(void)
1465*eb60705aSEric Wollesen {
1466*eb60705aSEric Wollesen 	debugf2("MC: " __FILE__ ": %s()\n", __func__);
1467*eb60705aSEric Wollesen 	pci_unregister_driver(&i5000_driver);
1468*eb60705aSEric Wollesen }
1469*eb60705aSEric Wollesen 
1470*eb60705aSEric Wollesen module_init(i5000_init);
1471*eb60705aSEric Wollesen module_exit(i5000_exit);
1472*eb60705aSEric Wollesen 
1473*eb60705aSEric Wollesen MODULE_LICENSE("GPL");
1474*eb60705aSEric Wollesen MODULE_AUTHOR
1475*eb60705aSEric Wollesen     ("Linux Networx (http://lnxi.com) Doug Thompson <norsk5@xmission.com>");
1476*eb60705aSEric Wollesen MODULE_DESCRIPTION("MC Driver for Intel I5000 memory controllers - "
1477*eb60705aSEric Wollesen 		   I5000_REVISION);
1478