xref: /openbmc/linux/drivers/edac/i5000_edac.c (revision 486dfb16)
1eb60705aSEric Wollesen /*
2eb60705aSEric Wollesen  * Intel 5000(P/V/X) class Memory Controllers kernel module
3eb60705aSEric Wollesen  *
4eb60705aSEric Wollesen  * This file may be distributed under the terms of the
5eb60705aSEric Wollesen  * GNU General Public License.
6eb60705aSEric Wollesen  *
7eb60705aSEric Wollesen  * Written by Douglas Thompson Linux Networx (http://lnxi.com)
8eb60705aSEric Wollesen  *	norsk5@xmission.com
9eb60705aSEric Wollesen  *
10eb60705aSEric Wollesen  * This module is based on the following document:
11eb60705aSEric Wollesen  *
12eb60705aSEric Wollesen  * Intel 5000X Chipset Memory Controller Hub (MCH) - Datasheet
13eb60705aSEric Wollesen  * 	http://developer.intel.com/design/chipsets/datashts/313070.htm
14eb60705aSEric Wollesen  *
15eb60705aSEric Wollesen  */
16eb60705aSEric Wollesen 
17eb60705aSEric Wollesen #include <linux/module.h>
18eb60705aSEric Wollesen #include <linux/init.h>
19eb60705aSEric Wollesen #include <linux/pci.h>
20eb60705aSEric Wollesen #include <linux/pci_ids.h>
21eb60705aSEric Wollesen #include <linux/slab.h>
22c0d12172SDave Jiang #include <linux/edac.h>
23eb60705aSEric Wollesen #include <asm/mmzone.h>
24eb60705aSEric Wollesen 
2520bcb7a8SDouglas Thompson #include "edac_core.h"
26eb60705aSEric Wollesen 
27eb60705aSEric Wollesen /*
28eb60705aSEric Wollesen  * Alter this version for the I5000 module when modifications are made
29eb60705aSEric Wollesen  */
30152ba394SMichal Marek #define I5000_REVISION    " Ver: 2.0.12"
31456a2f95SDave Jiang #define EDAC_MOD_STR      "i5000_edac"
32eb60705aSEric Wollesen 
33eb60705aSEric Wollesen #define i5000_printk(level, fmt, arg...) \
34eb60705aSEric Wollesen         edac_printk(level, "i5000", fmt, ##arg)
35eb60705aSEric Wollesen 
36eb60705aSEric Wollesen #define i5000_mc_printk(mci, level, fmt, arg...) \
37eb60705aSEric Wollesen         edac_mc_chipset_printk(mci, level, "i5000", fmt, ##arg)
38eb60705aSEric Wollesen 
39eb60705aSEric Wollesen #ifndef PCI_DEVICE_ID_INTEL_FBD_0
40eb60705aSEric Wollesen #define PCI_DEVICE_ID_INTEL_FBD_0	0x25F5
41eb60705aSEric Wollesen #endif
42eb60705aSEric Wollesen #ifndef PCI_DEVICE_ID_INTEL_FBD_1
43eb60705aSEric Wollesen #define PCI_DEVICE_ID_INTEL_FBD_1	0x25F6
44eb60705aSEric Wollesen #endif
45eb60705aSEric Wollesen 
46eb60705aSEric Wollesen /* Device 16,
47eb60705aSEric Wollesen  * Function 0: System Address
48eb60705aSEric Wollesen  * Function 1: Memory Branch Map, Control, Errors Register
49eb60705aSEric Wollesen  * Function 2: FSB Error Registers
50eb60705aSEric Wollesen  *
51eb60705aSEric Wollesen  * All 3 functions of Device 16 (0,1,2) share the SAME DID
52eb60705aSEric Wollesen  */
53eb60705aSEric Wollesen #define	PCI_DEVICE_ID_INTEL_I5000_DEV16	0x25F0
54eb60705aSEric Wollesen 
55eb60705aSEric Wollesen /* OFFSETS for Function 0 */
56eb60705aSEric Wollesen 
57eb60705aSEric Wollesen /* OFFSETS for Function 1 */
58eb60705aSEric Wollesen #define		AMBASE			0x48
59eb60705aSEric Wollesen #define		MAXCH			0x56
60eb60705aSEric Wollesen #define		MAXDIMMPERCH		0x57
61eb60705aSEric Wollesen #define		TOLM			0x6C
62eb60705aSEric Wollesen #define		REDMEMB			0x7C
63eb60705aSEric Wollesen #define			RED_ECC_LOCATOR(x)	((x) & 0x3FFFF)
64eb60705aSEric Wollesen #define			REC_ECC_LOCATOR_EVEN(x)	((x) & 0x001FF)
65eb60705aSEric Wollesen #define			REC_ECC_LOCATOR_ODD(x)	((x) & 0x3FE00)
66eb60705aSEric Wollesen #define		MIR0			0x80
67eb60705aSEric Wollesen #define		MIR1			0x84
68eb60705aSEric Wollesen #define		MIR2			0x88
69eb60705aSEric Wollesen #define		AMIR0			0x8C
70eb60705aSEric Wollesen #define		AMIR1			0x90
71eb60705aSEric Wollesen #define		AMIR2			0x94
72eb60705aSEric Wollesen 
73eb60705aSEric Wollesen #define		FERR_FAT_FBD		0x98
74eb60705aSEric Wollesen #define		NERR_FAT_FBD		0x9C
75eb60705aSEric Wollesen #define			EXTRACT_FBDCHAN_INDX(x)	(((x)>>28) & 0x3)
76eb60705aSEric Wollesen #define			FERR_FAT_FBDCHAN 0x30000000
77eb60705aSEric Wollesen #define			FERR_FAT_M3ERR	0x00000004
78eb60705aSEric Wollesen #define			FERR_FAT_M2ERR	0x00000002
79eb60705aSEric Wollesen #define			FERR_FAT_M1ERR	0x00000001
80eb60705aSEric Wollesen #define			FERR_FAT_MASK	(FERR_FAT_M1ERR | \
81eb60705aSEric Wollesen 						FERR_FAT_M2ERR | \
82eb60705aSEric Wollesen 						FERR_FAT_M3ERR)
83eb60705aSEric Wollesen 
84eb60705aSEric Wollesen #define		FERR_NF_FBD		0xA0
85eb60705aSEric Wollesen 
86eb60705aSEric Wollesen /* Thermal and SPD or BFD errors */
87eb60705aSEric Wollesen #define			FERR_NF_M28ERR	0x01000000
88eb60705aSEric Wollesen #define			FERR_NF_M27ERR	0x00800000
89eb60705aSEric Wollesen #define			FERR_NF_M26ERR	0x00400000
90eb60705aSEric Wollesen #define			FERR_NF_M25ERR	0x00200000
91eb60705aSEric Wollesen #define			FERR_NF_M24ERR	0x00100000
92eb60705aSEric Wollesen #define			FERR_NF_M23ERR	0x00080000
93eb60705aSEric Wollesen #define			FERR_NF_M22ERR	0x00040000
94eb60705aSEric Wollesen #define			FERR_NF_M21ERR	0x00020000
95eb60705aSEric Wollesen 
96eb60705aSEric Wollesen /* Correctable errors */
97eb60705aSEric Wollesen #define			FERR_NF_M20ERR	0x00010000
98eb60705aSEric Wollesen #define			FERR_NF_M19ERR	0x00008000
99eb60705aSEric Wollesen #define			FERR_NF_M18ERR	0x00004000
100eb60705aSEric Wollesen #define			FERR_NF_M17ERR	0x00002000
101eb60705aSEric Wollesen 
102eb60705aSEric Wollesen /* Non-Retry or redundant Retry errors */
103eb60705aSEric Wollesen #define			FERR_NF_M16ERR	0x00001000
104eb60705aSEric Wollesen #define			FERR_NF_M15ERR	0x00000800
105eb60705aSEric Wollesen #define			FERR_NF_M14ERR	0x00000400
106eb60705aSEric Wollesen #define			FERR_NF_M13ERR	0x00000200
107eb60705aSEric Wollesen 
108eb60705aSEric Wollesen /* Uncorrectable errors */
109eb60705aSEric Wollesen #define			FERR_NF_M12ERR	0x00000100
110eb60705aSEric Wollesen #define			FERR_NF_M11ERR	0x00000080
111eb60705aSEric Wollesen #define			FERR_NF_M10ERR	0x00000040
112eb60705aSEric Wollesen #define			FERR_NF_M9ERR	0x00000020
113eb60705aSEric Wollesen #define			FERR_NF_M8ERR	0x00000010
114eb60705aSEric Wollesen #define			FERR_NF_M7ERR	0x00000008
115eb60705aSEric Wollesen #define			FERR_NF_M6ERR	0x00000004
116eb60705aSEric Wollesen #define			FERR_NF_M5ERR	0x00000002
117eb60705aSEric Wollesen #define			FERR_NF_M4ERR	0x00000001
118eb60705aSEric Wollesen 
119eb60705aSEric Wollesen #define			FERR_NF_UNCORRECTABLE	(FERR_NF_M12ERR | \
120eb60705aSEric Wollesen 							FERR_NF_M11ERR | \
121eb60705aSEric Wollesen 							FERR_NF_M10ERR | \
122c0667407SAristeu Rozanski 							FERR_NF_M9ERR | \
123eb60705aSEric Wollesen 							FERR_NF_M8ERR | \
124eb60705aSEric Wollesen 							FERR_NF_M7ERR | \
125eb60705aSEric Wollesen 							FERR_NF_M6ERR | \
126eb60705aSEric Wollesen 							FERR_NF_M5ERR | \
127eb60705aSEric Wollesen 							FERR_NF_M4ERR)
128eb60705aSEric Wollesen #define			FERR_NF_CORRECTABLE	(FERR_NF_M20ERR | \
129eb60705aSEric Wollesen 							FERR_NF_M19ERR | \
130eb60705aSEric Wollesen 							FERR_NF_M18ERR | \
131eb60705aSEric Wollesen 							FERR_NF_M17ERR)
132eb60705aSEric Wollesen #define			FERR_NF_DIMM_SPARE	(FERR_NF_M27ERR | \
133eb60705aSEric Wollesen 							FERR_NF_M28ERR)
134eb60705aSEric Wollesen #define			FERR_NF_THERMAL		(FERR_NF_M26ERR | \
135eb60705aSEric Wollesen 							FERR_NF_M25ERR | \
136eb60705aSEric Wollesen 							FERR_NF_M24ERR | \
137eb60705aSEric Wollesen 							FERR_NF_M23ERR)
138eb60705aSEric Wollesen #define			FERR_NF_SPD_PROTOCOL	(FERR_NF_M22ERR)
139eb60705aSEric Wollesen #define			FERR_NF_NORTH_CRC	(FERR_NF_M21ERR)
140eb60705aSEric Wollesen #define			FERR_NF_NON_RETRY	(FERR_NF_M13ERR | \
141eb60705aSEric Wollesen 							FERR_NF_M14ERR | \
142eb60705aSEric Wollesen 							FERR_NF_M15ERR)
143eb60705aSEric Wollesen 
144eb60705aSEric Wollesen #define		NERR_NF_FBD		0xA4
145eb60705aSEric Wollesen #define			FERR_NF_MASK		(FERR_NF_UNCORRECTABLE | \
146eb60705aSEric Wollesen 							FERR_NF_CORRECTABLE | \
147eb60705aSEric Wollesen 							FERR_NF_DIMM_SPARE | \
148eb60705aSEric Wollesen 							FERR_NF_THERMAL | \
149eb60705aSEric Wollesen 							FERR_NF_SPD_PROTOCOL | \
150eb60705aSEric Wollesen 							FERR_NF_NORTH_CRC | \
151eb60705aSEric Wollesen 							FERR_NF_NON_RETRY)
152eb60705aSEric Wollesen 
153eb60705aSEric Wollesen #define		EMASK_FBD		0xA8
154eb60705aSEric Wollesen #define			EMASK_FBD_M28ERR	0x08000000
155eb60705aSEric Wollesen #define			EMASK_FBD_M27ERR	0x04000000
156eb60705aSEric Wollesen #define			EMASK_FBD_M26ERR	0x02000000
157eb60705aSEric Wollesen #define			EMASK_FBD_M25ERR	0x01000000
158eb60705aSEric Wollesen #define			EMASK_FBD_M24ERR	0x00800000
159eb60705aSEric Wollesen #define			EMASK_FBD_M23ERR	0x00400000
160eb60705aSEric Wollesen #define			EMASK_FBD_M22ERR	0x00200000
161eb60705aSEric Wollesen #define			EMASK_FBD_M21ERR	0x00100000
162eb60705aSEric Wollesen #define			EMASK_FBD_M20ERR	0x00080000
163eb60705aSEric Wollesen #define			EMASK_FBD_M19ERR	0x00040000
164eb60705aSEric Wollesen #define			EMASK_FBD_M18ERR	0x00020000
165eb60705aSEric Wollesen #define			EMASK_FBD_M17ERR	0x00010000
166eb60705aSEric Wollesen 
167eb60705aSEric Wollesen #define			EMASK_FBD_M15ERR	0x00004000
168eb60705aSEric Wollesen #define			EMASK_FBD_M14ERR	0x00002000
169eb60705aSEric Wollesen #define			EMASK_FBD_M13ERR	0x00001000
170eb60705aSEric Wollesen #define			EMASK_FBD_M12ERR	0x00000800
171eb60705aSEric Wollesen #define			EMASK_FBD_M11ERR	0x00000400
172eb60705aSEric Wollesen #define			EMASK_FBD_M10ERR	0x00000200
173eb60705aSEric Wollesen #define			EMASK_FBD_M9ERR		0x00000100
174eb60705aSEric Wollesen #define			EMASK_FBD_M8ERR		0x00000080
175eb60705aSEric Wollesen #define			EMASK_FBD_M7ERR		0x00000040
176eb60705aSEric Wollesen #define			EMASK_FBD_M6ERR		0x00000020
177eb60705aSEric Wollesen #define			EMASK_FBD_M5ERR		0x00000010
178eb60705aSEric Wollesen #define			EMASK_FBD_M4ERR		0x00000008
179eb60705aSEric Wollesen #define			EMASK_FBD_M3ERR		0x00000004
180eb60705aSEric Wollesen #define			EMASK_FBD_M2ERR		0x00000002
181eb60705aSEric Wollesen #define			EMASK_FBD_M1ERR		0x00000001
182eb60705aSEric Wollesen 
183eb60705aSEric Wollesen #define			ENABLE_EMASK_FBD_FATAL_ERRORS	(EMASK_FBD_M1ERR | \
184eb60705aSEric Wollesen 							EMASK_FBD_M2ERR | \
185eb60705aSEric Wollesen 							EMASK_FBD_M3ERR)
186eb60705aSEric Wollesen 
187eb60705aSEric Wollesen #define 		ENABLE_EMASK_FBD_UNCORRECTABLE	(EMASK_FBD_M4ERR | \
188eb60705aSEric Wollesen 							EMASK_FBD_M5ERR | \
189eb60705aSEric Wollesen 							EMASK_FBD_M6ERR | \
190eb60705aSEric Wollesen 							EMASK_FBD_M7ERR | \
191eb60705aSEric Wollesen 							EMASK_FBD_M8ERR | \
192eb60705aSEric Wollesen 							EMASK_FBD_M9ERR | \
193eb60705aSEric Wollesen 							EMASK_FBD_M10ERR | \
194eb60705aSEric Wollesen 							EMASK_FBD_M11ERR | \
195eb60705aSEric Wollesen 							EMASK_FBD_M12ERR)
196eb60705aSEric Wollesen #define 		ENABLE_EMASK_FBD_CORRECTABLE	(EMASK_FBD_M17ERR | \
197eb60705aSEric Wollesen 							EMASK_FBD_M18ERR | \
198eb60705aSEric Wollesen 							EMASK_FBD_M19ERR | \
199eb60705aSEric Wollesen 							EMASK_FBD_M20ERR)
200eb60705aSEric Wollesen #define			ENABLE_EMASK_FBD_DIMM_SPARE	(EMASK_FBD_M27ERR | \
201eb60705aSEric Wollesen 							EMASK_FBD_M28ERR)
202eb60705aSEric Wollesen #define			ENABLE_EMASK_FBD_THERMALS	(EMASK_FBD_M26ERR | \
203eb60705aSEric Wollesen 							EMASK_FBD_M25ERR | \
204eb60705aSEric Wollesen 							EMASK_FBD_M24ERR | \
205eb60705aSEric Wollesen 							EMASK_FBD_M23ERR)
206eb60705aSEric Wollesen #define			ENABLE_EMASK_FBD_SPD_PROTOCOL	(EMASK_FBD_M22ERR)
207eb60705aSEric Wollesen #define			ENABLE_EMASK_FBD_NORTH_CRC	(EMASK_FBD_M21ERR)
208eb60705aSEric Wollesen #define			ENABLE_EMASK_FBD_NON_RETRY	(EMASK_FBD_M15ERR | \
209eb60705aSEric Wollesen 							EMASK_FBD_M14ERR | \
210eb60705aSEric Wollesen 							EMASK_FBD_M13ERR)
211eb60705aSEric Wollesen 
212eb60705aSEric Wollesen #define		ENABLE_EMASK_ALL	(ENABLE_EMASK_FBD_NON_RETRY | \
213eb60705aSEric Wollesen 					ENABLE_EMASK_FBD_NORTH_CRC | \
214eb60705aSEric Wollesen 					ENABLE_EMASK_FBD_SPD_PROTOCOL | \
215eb60705aSEric Wollesen 					ENABLE_EMASK_FBD_THERMALS | \
216eb60705aSEric Wollesen 					ENABLE_EMASK_FBD_DIMM_SPARE | \
217eb60705aSEric Wollesen 					ENABLE_EMASK_FBD_FATAL_ERRORS | \
218eb60705aSEric Wollesen 					ENABLE_EMASK_FBD_CORRECTABLE | \
219eb60705aSEric Wollesen 					ENABLE_EMASK_FBD_UNCORRECTABLE)
220eb60705aSEric Wollesen 
221eb60705aSEric Wollesen #define		ERR0_FBD		0xAC
222eb60705aSEric Wollesen #define		ERR1_FBD		0xB0
223eb60705aSEric Wollesen #define		ERR2_FBD		0xB4
224eb60705aSEric Wollesen #define		MCERR_FBD		0xB8
225eb60705aSEric Wollesen #define		NRECMEMA		0xBE
226eb60705aSEric Wollesen #define			NREC_BANK(x)		(((x)>>12) & 0x7)
227eb60705aSEric Wollesen #define			NREC_RDWR(x)		(((x)>>11) & 1)
228eb60705aSEric Wollesen #define			NREC_RANK(x)		(((x)>>8) & 0x7)
229eb60705aSEric Wollesen #define		NRECMEMB		0xC0
230eb60705aSEric Wollesen #define			NREC_CAS(x)		(((x)>>16) & 0xFFFFFF)
231eb60705aSEric Wollesen #define			NREC_RAS(x)		((x) & 0x7FFF)
232eb60705aSEric Wollesen #define		NRECFGLOG		0xC4
233eb60705aSEric Wollesen #define		NREEECFBDA		0xC8
234eb60705aSEric Wollesen #define		NREEECFBDB		0xCC
235eb60705aSEric Wollesen #define		NREEECFBDC		0xD0
236eb60705aSEric Wollesen #define		NREEECFBDD		0xD4
237eb60705aSEric Wollesen #define		NREEECFBDE		0xD8
238eb60705aSEric Wollesen #define		REDMEMA			0xDC
239eb60705aSEric Wollesen #define		RECMEMA			0xE2
240eb60705aSEric Wollesen #define			REC_BANK(x)		(((x)>>12) & 0x7)
241eb60705aSEric Wollesen #define			REC_RDWR(x)		(((x)>>11) & 1)
242eb60705aSEric Wollesen #define			REC_RANK(x)		(((x)>>8) & 0x7)
243eb60705aSEric Wollesen #define		RECMEMB			0xE4
244eb60705aSEric Wollesen #define			REC_CAS(x)		(((x)>>16) & 0xFFFFFF)
245eb60705aSEric Wollesen #define			REC_RAS(x)		((x) & 0x7FFF)
246eb60705aSEric Wollesen #define		RECFGLOG		0xE8
247eb60705aSEric Wollesen #define		RECFBDA			0xEC
248eb60705aSEric Wollesen #define		RECFBDB			0xF0
249eb60705aSEric Wollesen #define		RECFBDC			0xF4
250eb60705aSEric Wollesen #define		RECFBDD			0xF8
251eb60705aSEric Wollesen #define		RECFBDE			0xFC
252eb60705aSEric Wollesen 
253eb60705aSEric Wollesen /* OFFSETS for Function 2 */
254eb60705aSEric Wollesen 
255eb60705aSEric Wollesen /*
256eb60705aSEric Wollesen  * Device 21,
257eb60705aSEric Wollesen  * Function 0: Memory Map Branch 0
258eb60705aSEric Wollesen  *
259eb60705aSEric Wollesen  * Device 22,
260eb60705aSEric Wollesen  * Function 0: Memory Map Branch 1
261eb60705aSEric Wollesen  */
262eb60705aSEric Wollesen #define PCI_DEVICE_ID_I5000_BRANCH_0	0x25F5
263eb60705aSEric Wollesen #define PCI_DEVICE_ID_I5000_BRANCH_1	0x25F6
264eb60705aSEric Wollesen 
265eb60705aSEric Wollesen #define AMB_PRESENT_0	0x64
266eb60705aSEric Wollesen #define AMB_PRESENT_1	0x66
267eb60705aSEric Wollesen #define MTR0		0x80
268eb60705aSEric Wollesen #define MTR1		0x84
269eb60705aSEric Wollesen #define MTR2		0x88
270eb60705aSEric Wollesen #define MTR3		0x8C
271eb60705aSEric Wollesen 
272eb60705aSEric Wollesen #define NUM_MTRS		4
27364e1fdafSMauro Carvalho Chehab #define CHANNELS_PER_BRANCH	2
27464e1fdafSMauro Carvalho Chehab #define MAX_BRANCHES		2
275eb60705aSEric Wollesen 
276eb60705aSEric Wollesen /* Defines to extract the vaious fields from the
277eb60705aSEric Wollesen  *	MTRx - Memory Technology Registers
278eb60705aSEric Wollesen  */
279eb60705aSEric Wollesen #define MTR_DIMMS_PRESENT(mtr)		((mtr) & (0x1 << 8))
280eb60705aSEric Wollesen #define MTR_DRAM_WIDTH(mtr)		((((mtr) >> 6) & 0x1) ? 8 : 4)
281eb60705aSEric Wollesen #define MTR_DRAM_BANKS(mtr)		((((mtr) >> 5) & 0x1) ? 8 : 4)
282eb60705aSEric Wollesen #define MTR_DRAM_BANKS_ADDR_BITS(mtr)	((MTR_DRAM_BANKS(mtr) == 8) ? 3 : 2)
283eb60705aSEric Wollesen #define MTR_DIMM_RANK(mtr)		(((mtr) >> 4) & 0x1)
284977c76bdSMarisuz Kozlowski #define MTR_DIMM_RANK_ADDR_BITS(mtr)	(MTR_DIMM_RANK(mtr) ? 2 : 1)
285eb60705aSEric Wollesen #define MTR_DIMM_ROWS(mtr)		(((mtr) >> 2) & 0x3)
286eb60705aSEric Wollesen #define MTR_DIMM_ROWS_ADDR_BITS(mtr)	(MTR_DIMM_ROWS(mtr) + 13)
287eb60705aSEric Wollesen #define MTR_DIMM_COLS(mtr)		((mtr) & 0x3)
288eb60705aSEric Wollesen #define MTR_DIMM_COLS_ADDR_BITS(mtr)	(MTR_DIMM_COLS(mtr) + 10)
289eb60705aSEric Wollesen 
290eb60705aSEric Wollesen #ifdef CONFIG_EDAC_DEBUG
291eb60705aSEric Wollesen static char *numrow_toString[] = {
292eb60705aSEric Wollesen 	"8,192 - 13 rows",
293eb60705aSEric Wollesen 	"16,384 - 14 rows",
294eb60705aSEric Wollesen 	"32,768 - 15 rows",
295eb60705aSEric Wollesen 	"reserved"
296eb60705aSEric Wollesen };
297eb60705aSEric Wollesen 
298eb60705aSEric Wollesen static char *numcol_toString[] = {
299eb60705aSEric Wollesen 	"1,024 - 10 columns",
300eb60705aSEric Wollesen 	"2,048 - 11 columns",
301eb60705aSEric Wollesen 	"4,096 - 12 columns",
302eb60705aSEric Wollesen 	"reserved"
303eb60705aSEric Wollesen };
304eb60705aSEric Wollesen #endif
305eb60705aSEric Wollesen 
306c0667407SAristeu Rozanski /* enables the report of miscellaneous messages as CE errors - default off */
307c0667407SAristeu Rozanski static int misc_messages;
308c0667407SAristeu Rozanski 
309eb60705aSEric Wollesen /* Enumeration of supported devices */
310eb60705aSEric Wollesen enum i5000_chips {
311eb60705aSEric Wollesen 	I5000P = 0,
312eb60705aSEric Wollesen 	I5000V = 1,		/* future */
313eb60705aSEric Wollesen 	I5000X = 2		/* future */
314eb60705aSEric Wollesen };
315eb60705aSEric Wollesen 
316eb60705aSEric Wollesen /* Device name and register DID (Device ID) */
317eb60705aSEric Wollesen struct i5000_dev_info {
318eb60705aSEric Wollesen 	const char *ctl_name;	/* name for this device */
319eb60705aSEric Wollesen 	u16 fsb_mapping_errors;	/* DID for the branchmap,control */
320eb60705aSEric Wollesen };
321eb60705aSEric Wollesen 
322eb60705aSEric Wollesen /* Table of devices attributes supported by this driver */
323eb60705aSEric Wollesen static const struct i5000_dev_info i5000_devs[] = {
324eb60705aSEric Wollesen 	[I5000P] = {
325eb60705aSEric Wollesen 		.ctl_name = "I5000",
326eb60705aSEric Wollesen 		.fsb_mapping_errors = PCI_DEVICE_ID_INTEL_I5000_DEV16,
327eb60705aSEric Wollesen 	},
328eb60705aSEric Wollesen };
329eb60705aSEric Wollesen 
330eb60705aSEric Wollesen struct i5000_dimm_info {
331eb60705aSEric Wollesen 	int megabytes;		/* size, 0 means not present  */
332eb60705aSEric Wollesen 	int dual_rank;
333eb60705aSEric Wollesen };
334eb60705aSEric Wollesen 
335eb60705aSEric Wollesen #define	MAX_CHANNELS	6	/* max possible channels */
336eb60705aSEric Wollesen #define MAX_CSROWS	(8*2)	/* max possible csrows per channel */
337eb60705aSEric Wollesen 
338eb60705aSEric Wollesen /* driver private data structure */
339eb60705aSEric Wollesen struct i5000_pvt {
340eb60705aSEric Wollesen 	struct pci_dev *system_address;	/* 16.0 */
341eb60705aSEric Wollesen 	struct pci_dev *branchmap_werrors;	/* 16.1 */
342eb60705aSEric Wollesen 	struct pci_dev *fsb_error_regs;	/* 16.2 */
343eb60705aSEric Wollesen 	struct pci_dev *branch_0;	/* 21.0 */
344eb60705aSEric Wollesen 	struct pci_dev *branch_1;	/* 22.0 */
345eb60705aSEric Wollesen 
346eb60705aSEric Wollesen 	u16 tolm;		/* top of low memory */
347eb60705aSEric Wollesen 	u64 ambase;		/* AMB BAR */
348eb60705aSEric Wollesen 
349eb60705aSEric Wollesen 	u16 mir0, mir1, mir2;
350eb60705aSEric Wollesen 
351eb60705aSEric Wollesen 	u16 b0_mtr[NUM_MTRS];	/* Memory Technlogy Reg */
352eb60705aSEric Wollesen 	u16 b0_ambpresent0;	/* Branch 0, Channel 0 */
353eb60705aSEric Wollesen 	u16 b0_ambpresent1;	/* Brnach 0, Channel 1 */
354eb60705aSEric Wollesen 
355eb60705aSEric Wollesen 	u16 b1_mtr[NUM_MTRS];	/* Memory Technlogy Reg */
356eb60705aSEric Wollesen 	u16 b1_ambpresent0;	/* Branch 1, Channel 8 */
357eb60705aSEric Wollesen 	u16 b1_ambpresent1;	/* Branch 1, Channel 1 */
358eb60705aSEric Wollesen 
3596f042b50SJoe Perches 	/* DIMM information matrix, allocating architecture maximums */
360eb60705aSEric Wollesen 	struct i5000_dimm_info dimm_info[MAX_CSROWS][MAX_CHANNELS];
361eb60705aSEric Wollesen 
362eb60705aSEric Wollesen 	/* Actual values for this controller */
363eb60705aSEric Wollesen 	int maxch;		/* Max channels */
364eb60705aSEric Wollesen 	int maxdimmperch;	/* Max DIMMs per channel */
365eb60705aSEric Wollesen };
366eb60705aSEric Wollesen 
367eb60705aSEric Wollesen /* I5000 MCH error information retrieved from Hardware */
368eb60705aSEric Wollesen struct i5000_error_info {
369eb60705aSEric Wollesen 
370eb60705aSEric Wollesen 	/* These registers are always read from the MC */
371eb60705aSEric Wollesen 	u32 ferr_fat_fbd;	/* First Errors Fatal */
372eb60705aSEric Wollesen 	u32 nerr_fat_fbd;	/* Next Errors Fatal */
373eb60705aSEric Wollesen 	u32 ferr_nf_fbd;	/* First Errors Non-Fatal */
374eb60705aSEric Wollesen 	u32 nerr_nf_fbd;	/* Next Errors Non-Fatal */
375eb60705aSEric Wollesen 
376eb60705aSEric Wollesen 	/* These registers are input ONLY if there was a Recoverable  Error */
377eb60705aSEric Wollesen 	u32 redmemb;		/* Recoverable Mem Data Error log B */
378eb60705aSEric Wollesen 	u16 recmema;		/* Recoverable Mem Error log A */
379eb60705aSEric Wollesen 	u32 recmemb;		/* Recoverable Mem Error log B */
380eb60705aSEric Wollesen 
381eb60705aSEric Wollesen 	/* These registers are input ONLY if there was a
382eb60705aSEric Wollesen 	 * Non-Recoverable Error */
383eb60705aSEric Wollesen 	u16 nrecmema;		/* Non-Recoverable Mem log A */
384eb60705aSEric Wollesen 	u16 nrecmemb;		/* Non-Recoverable Mem log B */
385eb60705aSEric Wollesen 
386eb60705aSEric Wollesen };
387eb60705aSEric Wollesen 
388456a2f95SDave Jiang static struct edac_pci_ctl_info *i5000_pci;
389456a2f95SDave Jiang 
390b2ccaecaSDouglas Thompson /*
391eb60705aSEric Wollesen  *	i5000_get_error_info	Retrieve the hardware error information from
392eb60705aSEric Wollesen  *				the hardware and cache it in the 'info'
393eb60705aSEric Wollesen  *				structure
394eb60705aSEric Wollesen  */
395eb60705aSEric Wollesen static void i5000_get_error_info(struct mem_ctl_info *mci,
396eb60705aSEric Wollesen 				 struct i5000_error_info *info)
397eb60705aSEric Wollesen {
398eb60705aSEric Wollesen 	struct i5000_pvt *pvt;
399eb60705aSEric Wollesen 	u32 value;
400eb60705aSEric Wollesen 
401b2ccaecaSDouglas Thompson 	pvt = mci->pvt_info;
402eb60705aSEric Wollesen 
403eb60705aSEric Wollesen 	/* read in the 1st FATAL error register */
404eb60705aSEric Wollesen 	pci_read_config_dword(pvt->branchmap_werrors, FERR_FAT_FBD, &value);
405eb60705aSEric Wollesen 
406eb60705aSEric Wollesen 	/* Mask only the bits that the doc says are valid
407eb60705aSEric Wollesen 	 */
408eb60705aSEric Wollesen 	value &= (FERR_FAT_FBDCHAN | FERR_FAT_MASK);
409eb60705aSEric Wollesen 
410eb60705aSEric Wollesen 	/* If there is an error, then read in the */
411eb60705aSEric Wollesen 	/* NEXT FATAL error register and the Memory Error Log Register A */
412eb60705aSEric Wollesen 	if (value & FERR_FAT_MASK) {
413eb60705aSEric Wollesen 		info->ferr_fat_fbd = value;
414eb60705aSEric Wollesen 
415eb60705aSEric Wollesen 		/* harvest the various error data we need */
416eb60705aSEric Wollesen 		pci_read_config_dword(pvt->branchmap_werrors,
417eb60705aSEric Wollesen 				NERR_FAT_FBD, &info->nerr_fat_fbd);
418eb60705aSEric Wollesen 		pci_read_config_word(pvt->branchmap_werrors,
419eb60705aSEric Wollesen 				NRECMEMA, &info->nrecmema);
420eb60705aSEric Wollesen 		pci_read_config_word(pvt->branchmap_werrors,
421eb60705aSEric Wollesen 				NRECMEMB, &info->nrecmemb);
422eb60705aSEric Wollesen 
423eb60705aSEric Wollesen 		/* Clear the error bits, by writing them back */
424eb60705aSEric Wollesen 		pci_write_config_dword(pvt->branchmap_werrors,
425eb60705aSEric Wollesen 				FERR_FAT_FBD, value);
426eb60705aSEric Wollesen 	} else {
427eb60705aSEric Wollesen 		info->ferr_fat_fbd = 0;
428eb60705aSEric Wollesen 		info->nerr_fat_fbd = 0;
429eb60705aSEric Wollesen 		info->nrecmema = 0;
430eb60705aSEric Wollesen 		info->nrecmemb = 0;
431eb60705aSEric Wollesen 	}
432eb60705aSEric Wollesen 
433eb60705aSEric Wollesen 	/* read in the 1st NON-FATAL error register */
434eb60705aSEric Wollesen 	pci_read_config_dword(pvt->branchmap_werrors, FERR_NF_FBD, &value);
435eb60705aSEric Wollesen 
436eb60705aSEric Wollesen 	/* If there is an error, then read in the 1st NON-FATAL error
437eb60705aSEric Wollesen 	 * register as well */
438eb60705aSEric Wollesen 	if (value & FERR_NF_MASK) {
439eb60705aSEric Wollesen 		info->ferr_nf_fbd = value;
440eb60705aSEric Wollesen 
441eb60705aSEric Wollesen 		/* harvest the various error data we need */
442eb60705aSEric Wollesen 		pci_read_config_dword(pvt->branchmap_werrors,
443eb60705aSEric Wollesen 				NERR_NF_FBD, &info->nerr_nf_fbd);
444eb60705aSEric Wollesen 		pci_read_config_word(pvt->branchmap_werrors,
445eb60705aSEric Wollesen 				RECMEMA, &info->recmema);
446eb60705aSEric Wollesen 		pci_read_config_dword(pvt->branchmap_werrors,
447eb60705aSEric Wollesen 				RECMEMB, &info->recmemb);
448eb60705aSEric Wollesen 		pci_read_config_dword(pvt->branchmap_werrors,
449eb60705aSEric Wollesen 				REDMEMB, &info->redmemb);
450eb60705aSEric Wollesen 
451eb60705aSEric Wollesen 		/* Clear the error bits, by writing them back */
452eb60705aSEric Wollesen 		pci_write_config_dword(pvt->branchmap_werrors,
453eb60705aSEric Wollesen 				FERR_NF_FBD, value);
454eb60705aSEric Wollesen 	} else {
455eb60705aSEric Wollesen 		info->ferr_nf_fbd = 0;
456eb60705aSEric Wollesen 		info->nerr_nf_fbd = 0;
457eb60705aSEric Wollesen 		info->recmema = 0;
458eb60705aSEric Wollesen 		info->recmemb = 0;
459eb60705aSEric Wollesen 		info->redmemb = 0;
460eb60705aSEric Wollesen 	}
461eb60705aSEric Wollesen }
462eb60705aSEric Wollesen 
463b2ccaecaSDouglas Thompson /*
464eb60705aSEric Wollesen  * i5000_process_fatal_error_info(struct mem_ctl_info *mci,
465eb60705aSEric Wollesen  * 					struct i5000_error_info *info,
466eb60705aSEric Wollesen  * 					int handle_errors);
467eb60705aSEric Wollesen  *
468eb60705aSEric Wollesen  *	handle the Intel FATAL errors, if any
469eb60705aSEric Wollesen  */
470eb60705aSEric Wollesen static void i5000_process_fatal_error_info(struct mem_ctl_info *mci,
471eb60705aSEric Wollesen 					struct i5000_error_info *info,
472eb60705aSEric Wollesen 					int handle_errors)
473eb60705aSEric Wollesen {
474c0667407SAristeu Rozanski 	char msg[EDAC_MC_LABEL_LEN + 1 + 160];
475c0667407SAristeu Rozanski 	char *specific = NULL;
476eb60705aSEric Wollesen 	u32 allErrors;
477eb60705aSEric Wollesen 	int channel;
478eb60705aSEric Wollesen 	int bank;
479eb60705aSEric Wollesen 	int rank;
480eb60705aSEric Wollesen 	int rdwr;
481eb60705aSEric Wollesen 	int ras, cas;
482eb60705aSEric Wollesen 
483eb60705aSEric Wollesen 	/* mask off the Error bits that are possible */
484eb60705aSEric Wollesen 	allErrors = (info->ferr_fat_fbd & FERR_FAT_MASK);
485eb60705aSEric Wollesen 	if (!allErrors)
486eb60705aSEric Wollesen 		return;		/* if no error, return now */
487eb60705aSEric Wollesen 
488486dfb16SMauro Carvalho Chehab 	channel = EXTRACT_FBDCHAN_INDX(info->ferr_fat_fbd);
489eb60705aSEric Wollesen 
490eb60705aSEric Wollesen 	/* Use the NON-Recoverable macros to extract data */
491eb60705aSEric Wollesen 	bank = NREC_BANK(info->nrecmema);
492eb60705aSEric Wollesen 	rank = NREC_RANK(info->nrecmema);
493eb60705aSEric Wollesen 	rdwr = NREC_RDWR(info->nrecmema);
494eb60705aSEric Wollesen 	ras = NREC_RAS(info->nrecmemb);
495eb60705aSEric Wollesen 	cas = NREC_CAS(info->nrecmemb);
496eb60705aSEric Wollesen 
497486dfb16SMauro Carvalho Chehab 	debugf0("\t\tCSROW= %d  Channel= %d "
498486dfb16SMauro Carvalho Chehab 		"(DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n",
499486dfb16SMauro Carvalho Chehab 		rank, channel, bank,
500eb60705aSEric Wollesen 		rdwr ? "Write" : "Read", ras, cas);
501eb60705aSEric Wollesen 
502eb60705aSEric Wollesen 	/* Only 1 bit will be on */
503c0667407SAristeu Rozanski 	switch (allErrors) {
504c0667407SAristeu Rozanski 	case FERR_FAT_M1ERR:
505c0667407SAristeu Rozanski 		specific = "Alert on non-redundant retry or fast "
506c0667407SAristeu Rozanski 				"reset timeout";
507c0667407SAristeu Rozanski 		break;
508c0667407SAristeu Rozanski 	case FERR_FAT_M2ERR:
509c0667407SAristeu Rozanski 		specific = "Northbound CRC error on non-redundant "
510c0667407SAristeu Rozanski 				"retry";
511c0667407SAristeu Rozanski 		break;
512c0667407SAristeu Rozanski 	case FERR_FAT_M3ERR:
5138360e81bSAristeu Rozanski 		{
5148360e81bSAristeu Rozanski 		static int done;
5158360e81bSAristeu Rozanski 
5168360e81bSAristeu Rozanski 		/*
5178360e81bSAristeu Rozanski 		 * This error is generated to inform that the intelligent
5188360e81bSAristeu Rozanski 		 * throttling is disabled and the temperature passed the
5198360e81bSAristeu Rozanski 		 * specified middle point. Since this is something the BIOS
5208360e81bSAristeu Rozanski 		 * should take care of, we'll warn only once to avoid
5218360e81bSAristeu Rozanski 		 * worthlessly flooding the log.
5228360e81bSAristeu Rozanski 		 */
5238360e81bSAristeu Rozanski 		if (done)
5248360e81bSAristeu Rozanski 			return;
5258360e81bSAristeu Rozanski 		done++;
5268360e81bSAristeu Rozanski 
527c0667407SAristeu Rozanski 		specific = ">Tmid Thermal event with intelligent "
528c0667407SAristeu Rozanski 			   "throttling disabled";
5298360e81bSAristeu Rozanski 		}
530c0667407SAristeu Rozanski 		break;
531eb60705aSEric Wollesen 	}
532eb60705aSEric Wollesen 
533eb60705aSEric Wollesen 	/* Form out message */
534eb60705aSEric Wollesen 	snprintf(msg, sizeof(msg),
535702df640SMauro Carvalho Chehab 		 "Bank=%d RAS=%d CAS=%d FATAL Err=0x%x (%s)",
536702df640SMauro Carvalho Chehab 		 bank, ras, cas, allErrors, specific);
537eb60705aSEric Wollesen 
538eb60705aSEric Wollesen 	/* Call the helper to output message */
539702df640SMauro Carvalho Chehab 	edac_mc_handle_error(HW_EVENT_ERR_FATAL, mci, 0, 0, 0,
540486dfb16SMauro Carvalho Chehab 			     channel >> 1, channel & 1, rank,
541702df640SMauro Carvalho Chehab 			     rdwr ? "Write error" : "Read error",
542702df640SMauro Carvalho Chehab 			     msg, NULL);
543eb60705aSEric Wollesen }
544eb60705aSEric Wollesen 
545b2ccaecaSDouglas Thompson /*
546eb60705aSEric Wollesen  * i5000_process_fatal_error_info(struct mem_ctl_info *mci,
547eb60705aSEric Wollesen  * 				struct i5000_error_info *info,
548eb60705aSEric Wollesen  * 				int handle_errors);
549eb60705aSEric Wollesen  *
550eb60705aSEric Wollesen  *	handle the Intel NON-FATAL errors, if any
551eb60705aSEric Wollesen  */
552eb60705aSEric Wollesen static void i5000_process_nonfatal_error_info(struct mem_ctl_info *mci,
553eb60705aSEric Wollesen 					struct i5000_error_info *info,
554eb60705aSEric Wollesen 					int handle_errors)
555eb60705aSEric Wollesen {
556c0667407SAristeu Rozanski 	char msg[EDAC_MC_LABEL_LEN + 1 + 170];
557c0667407SAristeu Rozanski 	char *specific = NULL;
558eb60705aSEric Wollesen 	u32 allErrors;
559eb60705aSEric Wollesen 	u32 ue_errors;
560eb60705aSEric Wollesen 	u32 ce_errors;
561eb60705aSEric Wollesen 	u32 misc_errors;
562eb60705aSEric Wollesen 	int branch;
563eb60705aSEric Wollesen 	int channel;
564eb60705aSEric Wollesen 	int bank;
565eb60705aSEric Wollesen 	int rank;
566eb60705aSEric Wollesen 	int rdwr;
567eb60705aSEric Wollesen 	int ras, cas;
568eb60705aSEric Wollesen 
569eb60705aSEric Wollesen 	/* mask off the Error bits that are possible */
570eb60705aSEric Wollesen 	allErrors = (info->ferr_nf_fbd & FERR_NF_MASK);
571eb60705aSEric Wollesen 	if (!allErrors)
572eb60705aSEric Wollesen 		return;		/* if no error, return now */
573eb60705aSEric Wollesen 
574eb60705aSEric Wollesen 	/* ONLY ONE of the possible error bits will be set, as per the docs */
575eb60705aSEric Wollesen 	ue_errors = allErrors & FERR_NF_UNCORRECTABLE;
576eb60705aSEric Wollesen 	if (ue_errors) {
577eb60705aSEric Wollesen 		debugf0("\tUncorrected bits= 0x%x\n", ue_errors);
578eb60705aSEric Wollesen 
579eb60705aSEric Wollesen 		branch = EXTRACT_FBDCHAN_INDX(info->ferr_nf_fbd);
580118f3e1aSTamas Vincze 
581118f3e1aSTamas Vincze 		/*
582118f3e1aSTamas Vincze 		 * According with i5000 datasheet, bit 28 has no significance
583118f3e1aSTamas Vincze 		 * for errors M4Err-M12Err and M17Err-M21Err, on FERR_NF_FBD
584118f3e1aSTamas Vincze 		 */
585118f3e1aSTamas Vincze 		channel = branch & 2;
586118f3e1aSTamas Vincze 
587eb60705aSEric Wollesen 		bank = NREC_BANK(info->nrecmema);
588eb60705aSEric Wollesen 		rank = NREC_RANK(info->nrecmema);
589eb60705aSEric Wollesen 		rdwr = NREC_RDWR(info->nrecmema);
590eb60705aSEric Wollesen 		ras = NREC_RAS(info->nrecmemb);
591eb60705aSEric Wollesen 		cas = NREC_CAS(info->nrecmemb);
592eb60705aSEric Wollesen 
593eb60705aSEric Wollesen 		debugf0
594eb60705aSEric Wollesen 			("\t\tCSROW= %d  Channels= %d,%d  (Branch= %d "
595eb60705aSEric Wollesen 			"DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n",
596eb60705aSEric Wollesen 			rank, channel, channel + 1, branch >> 1, bank,
597eb60705aSEric Wollesen 			rdwr ? "Write" : "Read", ras, cas);
598eb60705aSEric Wollesen 
599c0667407SAristeu Rozanski 		switch (ue_errors) {
600c0667407SAristeu Rozanski 		case FERR_NF_M12ERR:
601c0667407SAristeu Rozanski 			specific = "Non-Aliased Uncorrectable Patrol Data ECC";
602c0667407SAristeu Rozanski 			break;
603c0667407SAristeu Rozanski 		case FERR_NF_M11ERR:
604c0667407SAristeu Rozanski 			specific = "Non-Aliased Uncorrectable Spare-Copy "
605c0667407SAristeu Rozanski 					"Data ECC";
606c0667407SAristeu Rozanski 			break;
607c0667407SAristeu Rozanski 		case FERR_NF_M10ERR:
608c0667407SAristeu Rozanski 			specific = "Non-Aliased Uncorrectable Mirrored Demand "
609c0667407SAristeu Rozanski 					"Data ECC";
610c0667407SAristeu Rozanski 			break;
611c0667407SAristeu Rozanski 		case FERR_NF_M9ERR:
612c0667407SAristeu Rozanski 			specific = "Non-Aliased Uncorrectable Non-Mirrored "
613c0667407SAristeu Rozanski 					"Demand Data ECC";
614c0667407SAristeu Rozanski 			break;
615c0667407SAristeu Rozanski 		case FERR_NF_M8ERR:
616c0667407SAristeu Rozanski 			specific = "Aliased Uncorrectable Patrol Data ECC";
617c0667407SAristeu Rozanski 			break;
618c0667407SAristeu Rozanski 		case FERR_NF_M7ERR:
619c0667407SAristeu Rozanski 			specific = "Aliased Uncorrectable Spare-Copy Data ECC";
620c0667407SAristeu Rozanski 			break;
621c0667407SAristeu Rozanski 		case FERR_NF_M6ERR:
622c0667407SAristeu Rozanski 			specific = "Aliased Uncorrectable Mirrored Demand "
623c0667407SAristeu Rozanski 					"Data ECC";
624c0667407SAristeu Rozanski 			break;
625c0667407SAristeu Rozanski 		case FERR_NF_M5ERR:
626c0667407SAristeu Rozanski 			specific = "Aliased Uncorrectable Non-Mirrored Demand "
627c0667407SAristeu Rozanski 					"Data ECC";
628c0667407SAristeu Rozanski 			break;
629c0667407SAristeu Rozanski 		case FERR_NF_M4ERR:
630c0667407SAristeu Rozanski 			specific = "Uncorrectable Data ECC on Replay";
631c0667407SAristeu Rozanski 			break;
632c0667407SAristeu Rozanski 		}
633c0667407SAristeu Rozanski 
634eb60705aSEric Wollesen 		/* Form out message */
635eb60705aSEric Wollesen 		snprintf(msg, sizeof(msg),
636702df640SMauro Carvalho Chehab 			 "Rank=%d Bank=%d RAS=%d CAS=%d, UE Err=0x%x (%s)",
637702df640SMauro Carvalho Chehab 			 rank, bank, ras, cas, ue_errors, specific);
638eb60705aSEric Wollesen 
639eb60705aSEric Wollesen 		/* Call the helper to output message */
640702df640SMauro Carvalho Chehab 		edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 0, 0, 0,
641702df640SMauro Carvalho Chehab 				channel >> 1, -1, rank,
642702df640SMauro Carvalho Chehab 				rdwr ? "Write error" : "Read error",
643702df640SMauro Carvalho Chehab 				msg, NULL);
644eb60705aSEric Wollesen 	}
645eb60705aSEric Wollesen 
646eb60705aSEric Wollesen 	/* Check correctable errors */
647eb60705aSEric Wollesen 	ce_errors = allErrors & FERR_NF_CORRECTABLE;
648eb60705aSEric Wollesen 	if (ce_errors) {
649eb60705aSEric Wollesen 		debugf0("\tCorrected bits= 0x%x\n", ce_errors);
650eb60705aSEric Wollesen 
651eb60705aSEric Wollesen 		branch = EXTRACT_FBDCHAN_INDX(info->ferr_nf_fbd);
652eb60705aSEric Wollesen 
653eb60705aSEric Wollesen 		channel = 0;
654eb60705aSEric Wollesen 		if (REC_ECC_LOCATOR_ODD(info->redmemb))
655eb60705aSEric Wollesen 			channel = 1;
656eb60705aSEric Wollesen 
657eb60705aSEric Wollesen 		/* Convert channel to be based from zero, instead of
658eb60705aSEric Wollesen 		 * from branch base of 0 */
659eb60705aSEric Wollesen 		channel += branch;
660eb60705aSEric Wollesen 
661eb60705aSEric Wollesen 		bank = REC_BANK(info->recmema);
662eb60705aSEric Wollesen 		rank = REC_RANK(info->recmema);
663eb60705aSEric Wollesen 		rdwr = REC_RDWR(info->recmema);
664eb60705aSEric Wollesen 		ras = REC_RAS(info->recmemb);
665eb60705aSEric Wollesen 		cas = REC_CAS(info->recmemb);
666eb60705aSEric Wollesen 
667eb60705aSEric Wollesen 		debugf0("\t\tCSROW= %d Channel= %d  (Branch %d "
668eb60705aSEric Wollesen 			"DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n",
669eb60705aSEric Wollesen 			rank, channel, branch >> 1, bank,
670eb60705aSEric Wollesen 			rdwr ? "Write" : "Read", ras, cas);
671eb60705aSEric Wollesen 
672c0667407SAristeu Rozanski 		switch (ce_errors) {
673c0667407SAristeu Rozanski 		case FERR_NF_M17ERR:
674c0667407SAristeu Rozanski 			specific = "Correctable Non-Mirrored Demand Data ECC";
675c0667407SAristeu Rozanski 			break;
676c0667407SAristeu Rozanski 		case FERR_NF_M18ERR:
677c0667407SAristeu Rozanski 			specific = "Correctable Mirrored Demand Data ECC";
678c0667407SAristeu Rozanski 			break;
679c0667407SAristeu Rozanski 		case FERR_NF_M19ERR:
680c0667407SAristeu Rozanski 			specific = "Correctable Spare-Copy Data ECC";
681c0667407SAristeu Rozanski 			break;
682c0667407SAristeu Rozanski 		case FERR_NF_M20ERR:
683c0667407SAristeu Rozanski 			specific = "Correctable Patrol Data ECC";
684c0667407SAristeu Rozanski 			break;
685c0667407SAristeu Rozanski 		}
686c0667407SAristeu Rozanski 
687eb60705aSEric Wollesen 		/* Form out message */
688eb60705aSEric Wollesen 		snprintf(msg, sizeof(msg),
689702df640SMauro Carvalho Chehab 			 "Rank=%d Bank=%d RDWR=%s RAS=%d "
690c0667407SAristeu Rozanski 			 "CAS=%d, CE Err=0x%x (%s))", branch >> 1, bank,
691c0667407SAristeu Rozanski 			 rdwr ? "Write" : "Read", ras, cas, ce_errors,
692c0667407SAristeu Rozanski 			 specific);
693eb60705aSEric Wollesen 
694eb60705aSEric Wollesen 		/* Call the helper to output message */
695702df640SMauro Carvalho Chehab 		edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 0, 0, 0,
696702df640SMauro Carvalho Chehab 				channel >> 1, channel % 2, rank,
697702df640SMauro Carvalho Chehab 				rdwr ? "Write error" : "Read error",
698702df640SMauro Carvalho Chehab 				msg, NULL);
699eb60705aSEric Wollesen 	}
700eb60705aSEric Wollesen 
701c0667407SAristeu Rozanski 	if (!misc_messages)
702c0667407SAristeu Rozanski 		return;
703eb60705aSEric Wollesen 
704c0667407SAristeu Rozanski 	misc_errors = allErrors & (FERR_NF_NON_RETRY | FERR_NF_NORTH_CRC |
705c0667407SAristeu Rozanski 				   FERR_NF_SPD_PROTOCOL | FERR_NF_DIMM_SPARE);
706eb60705aSEric Wollesen 	if (misc_errors) {
707c0667407SAristeu Rozanski 		switch (misc_errors) {
708c0667407SAristeu Rozanski 		case FERR_NF_M13ERR:
709c0667407SAristeu Rozanski 			specific = "Non-Retry or Redundant Retry FBD Memory "
710c0667407SAristeu Rozanski 					"Alert or Redundant Fast Reset Timeout";
711c0667407SAristeu Rozanski 			break;
712c0667407SAristeu Rozanski 		case FERR_NF_M14ERR:
713c0667407SAristeu Rozanski 			specific = "Non-Retry or Redundant Retry FBD "
714c0667407SAristeu Rozanski 					"Configuration Alert";
715c0667407SAristeu Rozanski 			break;
716c0667407SAristeu Rozanski 		case FERR_NF_M15ERR:
717c0667407SAristeu Rozanski 			specific = "Non-Retry or Redundant Retry FBD "
718c0667407SAristeu Rozanski 					"Northbound CRC error on read data";
719c0667407SAristeu Rozanski 			break;
720c0667407SAristeu Rozanski 		case FERR_NF_M21ERR:
721c0667407SAristeu Rozanski 			specific = "FBD Northbound CRC error on "
722c0667407SAristeu Rozanski 					"FBD Sync Status";
723c0667407SAristeu Rozanski 			break;
724c0667407SAristeu Rozanski 		case FERR_NF_M22ERR:
725c0667407SAristeu Rozanski 			specific = "SPD protocol error";
726c0667407SAristeu Rozanski 			break;
727c0667407SAristeu Rozanski 		case FERR_NF_M27ERR:
728c0667407SAristeu Rozanski 			specific = "DIMM-spare copy started";
729c0667407SAristeu Rozanski 			break;
730c0667407SAristeu Rozanski 		case FERR_NF_M28ERR:
731c0667407SAristeu Rozanski 			specific = "DIMM-spare copy completed";
732c0667407SAristeu Rozanski 			break;
733eb60705aSEric Wollesen 		}
734c0667407SAristeu Rozanski 		branch = EXTRACT_FBDCHAN_INDX(info->ferr_nf_fbd);
735eb60705aSEric Wollesen 
736c0667407SAristeu Rozanski 		/* Form out message */
737c0667407SAristeu Rozanski 		snprintf(msg, sizeof(msg),
738702df640SMauro Carvalho Chehab 			 "Err=%#x (%s)", misc_errors, specific);
739eb60705aSEric Wollesen 
740c0667407SAristeu Rozanski 		/* Call the helper to output message */
741702df640SMauro Carvalho Chehab 		edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 0, 0, 0,
742702df640SMauro Carvalho Chehab 				branch >> 1, -1, -1,
743702df640SMauro Carvalho Chehab 				"Misc error", msg, NULL);
744eb60705aSEric Wollesen 	}
745eb60705aSEric Wollesen }
746eb60705aSEric Wollesen 
747b2ccaecaSDouglas Thompson /*
748eb60705aSEric Wollesen  *	i5000_process_error_info	Process the error info that is
749eb60705aSEric Wollesen  *	in the 'info' structure, previously retrieved from hardware
750eb60705aSEric Wollesen  */
751eb60705aSEric Wollesen static void i5000_process_error_info(struct mem_ctl_info *mci,
752eb60705aSEric Wollesen 				struct i5000_error_info *info,
753eb60705aSEric Wollesen 				int handle_errors)
754eb60705aSEric Wollesen {
755eb60705aSEric Wollesen 	/* First handle any fatal errors that occurred */
756eb60705aSEric Wollesen 	i5000_process_fatal_error_info(mci, info, handle_errors);
757eb60705aSEric Wollesen 
758eb60705aSEric Wollesen 	/* now handle any non-fatal errors that occurred */
759eb60705aSEric Wollesen 	i5000_process_nonfatal_error_info(mci, info, handle_errors);
760eb60705aSEric Wollesen }
761eb60705aSEric Wollesen 
762b2ccaecaSDouglas Thompson /*
763eb60705aSEric Wollesen  *	i5000_clear_error	Retrieve any error from the hardware
764eb60705aSEric Wollesen  *				but do NOT process that error.
765eb60705aSEric Wollesen  *				Used for 'clearing' out of previous errors
766eb60705aSEric Wollesen  *				Called by the Core module.
767eb60705aSEric Wollesen  */
768eb60705aSEric Wollesen static void i5000_clear_error(struct mem_ctl_info *mci)
769eb60705aSEric Wollesen {
770eb60705aSEric Wollesen 	struct i5000_error_info info;
771eb60705aSEric Wollesen 
772eb60705aSEric Wollesen 	i5000_get_error_info(mci, &info);
773eb60705aSEric Wollesen }
774eb60705aSEric Wollesen 
775b2ccaecaSDouglas Thompson /*
776eb60705aSEric Wollesen  *	i5000_check_error	Retrieve and process errors reported by the
777eb60705aSEric Wollesen  *				hardware. Called by the Core module.
778eb60705aSEric Wollesen  */
779eb60705aSEric Wollesen static void i5000_check_error(struct mem_ctl_info *mci)
780eb60705aSEric Wollesen {
781eb60705aSEric Wollesen 	struct i5000_error_info info;
78263ae96beSJoe Perches 	debugf4("MC%d: %s: %s()\n", mci->mc_idx, __FILE__, __func__);
783eb60705aSEric Wollesen 	i5000_get_error_info(mci, &info);
784eb60705aSEric Wollesen 	i5000_process_error_info(mci, &info, 1);
785eb60705aSEric Wollesen }
786eb60705aSEric Wollesen 
787b2ccaecaSDouglas Thompson /*
788eb60705aSEric Wollesen  *	i5000_get_devices	Find and perform 'get' operation on the MCH's
789eb60705aSEric Wollesen  *			device/functions we want to reference for this driver
790eb60705aSEric Wollesen  *
791eb60705aSEric Wollesen  *			Need to 'get' device 16 func 1 and func 2
792eb60705aSEric Wollesen  */
793eb60705aSEric Wollesen static int i5000_get_devices(struct mem_ctl_info *mci, int dev_idx)
794eb60705aSEric Wollesen {
795eb60705aSEric Wollesen 	//const struct i5000_dev_info *i5000_dev = &i5000_devs[dev_idx];
796eb60705aSEric Wollesen 	struct i5000_pvt *pvt;
797eb60705aSEric Wollesen 	struct pci_dev *pdev;
798eb60705aSEric Wollesen 
799b2ccaecaSDouglas Thompson 	pvt = mci->pvt_info;
800eb60705aSEric Wollesen 
801eb60705aSEric Wollesen 	/* Attempt to 'get' the MCH register we want */
802eb60705aSEric Wollesen 	pdev = NULL;
803eb60705aSEric Wollesen 	while (1) {
804eb60705aSEric Wollesen 		pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
805eb60705aSEric Wollesen 				PCI_DEVICE_ID_INTEL_I5000_DEV16, pdev);
806eb60705aSEric Wollesen 
807eb60705aSEric Wollesen 		/* End of list, leave */
808eb60705aSEric Wollesen 		if (pdev == NULL) {
809eb60705aSEric Wollesen 			i5000_printk(KERN_ERR,
810eb60705aSEric Wollesen 				"'system address,Process Bus' "
811eb60705aSEric Wollesen 				"device not found:"
812eb60705aSEric Wollesen 				"vendor 0x%x device 0x%x FUNC 1 "
813eb60705aSEric Wollesen 				"(broken BIOS?)\n",
814eb60705aSEric Wollesen 				PCI_VENDOR_ID_INTEL,
815eb60705aSEric Wollesen 				PCI_DEVICE_ID_INTEL_I5000_DEV16);
816eb60705aSEric Wollesen 
817eb60705aSEric Wollesen 			return 1;
818eb60705aSEric Wollesen 		}
819eb60705aSEric Wollesen 
820eb60705aSEric Wollesen 		/* Scan for device 16 func 1 */
821eb60705aSEric Wollesen 		if (PCI_FUNC(pdev->devfn) == 1)
822eb60705aSEric Wollesen 			break;
823eb60705aSEric Wollesen 	}
824eb60705aSEric Wollesen 
825eb60705aSEric Wollesen 	pvt->branchmap_werrors = pdev;
826eb60705aSEric Wollesen 
827eb60705aSEric Wollesen 	/* Attempt to 'get' the MCH register we want */
828eb60705aSEric Wollesen 	pdev = NULL;
829eb60705aSEric Wollesen 	while (1) {
830eb60705aSEric Wollesen 		pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
831eb60705aSEric Wollesen 				PCI_DEVICE_ID_INTEL_I5000_DEV16, pdev);
832eb60705aSEric Wollesen 
833eb60705aSEric Wollesen 		if (pdev == NULL) {
834eb60705aSEric Wollesen 			i5000_printk(KERN_ERR,
835eb60705aSEric Wollesen 				"MC: 'branchmap,control,errors' "
836eb60705aSEric Wollesen 				"device not found:"
837eb60705aSEric Wollesen 				"vendor 0x%x device 0x%x Func 2 "
838eb60705aSEric Wollesen 				"(broken BIOS?)\n",
839eb60705aSEric Wollesen 				PCI_VENDOR_ID_INTEL,
840eb60705aSEric Wollesen 				PCI_DEVICE_ID_INTEL_I5000_DEV16);
841eb60705aSEric Wollesen 
842eb60705aSEric Wollesen 			pci_dev_put(pvt->branchmap_werrors);
843eb60705aSEric Wollesen 			return 1;
844eb60705aSEric Wollesen 		}
845eb60705aSEric Wollesen 
846eb60705aSEric Wollesen 		/* Scan for device 16 func 1 */
847eb60705aSEric Wollesen 		if (PCI_FUNC(pdev->devfn) == 2)
848eb60705aSEric Wollesen 			break;
849eb60705aSEric Wollesen 	}
850eb60705aSEric Wollesen 
851eb60705aSEric Wollesen 	pvt->fsb_error_regs = pdev;
852eb60705aSEric Wollesen 
853eb60705aSEric Wollesen 	debugf1("System Address, processor bus- PCI Bus ID: %s  %x:%x\n",
854eb60705aSEric Wollesen 		pci_name(pvt->system_address),
855eb60705aSEric Wollesen 		pvt->system_address->vendor, pvt->system_address->device);
856eb60705aSEric Wollesen 	debugf1("Branchmap, control and errors - PCI Bus ID: %s  %x:%x\n",
857eb60705aSEric Wollesen 		pci_name(pvt->branchmap_werrors),
858eb60705aSEric Wollesen 		pvt->branchmap_werrors->vendor, pvt->branchmap_werrors->device);
859eb60705aSEric Wollesen 	debugf1("FSB Error Regs - PCI Bus ID: %s  %x:%x\n",
860eb60705aSEric Wollesen 		pci_name(pvt->fsb_error_regs),
861eb60705aSEric Wollesen 		pvt->fsb_error_regs->vendor, pvt->fsb_error_regs->device);
862eb60705aSEric Wollesen 
863eb60705aSEric Wollesen 	pdev = NULL;
864eb60705aSEric Wollesen 	pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
865eb60705aSEric Wollesen 			PCI_DEVICE_ID_I5000_BRANCH_0, pdev);
866eb60705aSEric Wollesen 
867eb60705aSEric Wollesen 	if (pdev == NULL) {
868eb60705aSEric Wollesen 		i5000_printk(KERN_ERR,
869eb60705aSEric Wollesen 			"MC: 'BRANCH 0' device not found:"
870eb60705aSEric Wollesen 			"vendor 0x%x device 0x%x Func 0 (broken BIOS?)\n",
871eb60705aSEric Wollesen 			PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_I5000_BRANCH_0);
872eb60705aSEric Wollesen 
873eb60705aSEric Wollesen 		pci_dev_put(pvt->branchmap_werrors);
874eb60705aSEric Wollesen 		pci_dev_put(pvt->fsb_error_regs);
875eb60705aSEric Wollesen 		return 1;
876eb60705aSEric Wollesen 	}
877eb60705aSEric Wollesen 
878eb60705aSEric Wollesen 	pvt->branch_0 = pdev;
879eb60705aSEric Wollesen 
880eb60705aSEric Wollesen 	/* If this device claims to have more than 2 channels then
881eb60705aSEric Wollesen 	 * fetch Branch 1's information
882eb60705aSEric Wollesen 	 */
883eb60705aSEric Wollesen 	if (pvt->maxch >= CHANNELS_PER_BRANCH) {
884eb60705aSEric Wollesen 		pdev = NULL;
885eb60705aSEric Wollesen 		pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
886eb60705aSEric Wollesen 				PCI_DEVICE_ID_I5000_BRANCH_1, pdev);
887eb60705aSEric Wollesen 
888eb60705aSEric Wollesen 		if (pdev == NULL) {
889eb60705aSEric Wollesen 			i5000_printk(KERN_ERR,
890eb60705aSEric Wollesen 				"MC: 'BRANCH 1' device not found:"
891eb60705aSEric Wollesen 				"vendor 0x%x device 0x%x Func 0 "
892eb60705aSEric Wollesen 				"(broken BIOS?)\n",
893eb60705aSEric Wollesen 				PCI_VENDOR_ID_INTEL,
894eb60705aSEric Wollesen 				PCI_DEVICE_ID_I5000_BRANCH_1);
895eb60705aSEric Wollesen 
896eb60705aSEric Wollesen 			pci_dev_put(pvt->branchmap_werrors);
897eb60705aSEric Wollesen 			pci_dev_put(pvt->fsb_error_regs);
898eb60705aSEric Wollesen 			pci_dev_put(pvt->branch_0);
899eb60705aSEric Wollesen 			return 1;
900eb60705aSEric Wollesen 		}
901eb60705aSEric Wollesen 
902eb60705aSEric Wollesen 		pvt->branch_1 = pdev;
903eb60705aSEric Wollesen 	}
904eb60705aSEric Wollesen 
905eb60705aSEric Wollesen 	return 0;
906eb60705aSEric Wollesen }
907eb60705aSEric Wollesen 
908b2ccaecaSDouglas Thompson /*
909eb60705aSEric Wollesen  *	i5000_put_devices	'put' all the devices that we have
910eb60705aSEric Wollesen  *				reserved via 'get'
911eb60705aSEric Wollesen  */
912eb60705aSEric Wollesen static void i5000_put_devices(struct mem_ctl_info *mci)
913eb60705aSEric Wollesen {
914eb60705aSEric Wollesen 	struct i5000_pvt *pvt;
915eb60705aSEric Wollesen 
916b2ccaecaSDouglas Thompson 	pvt = mci->pvt_info;
917eb60705aSEric Wollesen 
918eb60705aSEric Wollesen 	pci_dev_put(pvt->branchmap_werrors);	/* FUNC 1 */
919eb60705aSEric Wollesen 	pci_dev_put(pvt->fsb_error_regs);	/* FUNC 2 */
920eb60705aSEric Wollesen 	pci_dev_put(pvt->branch_0);	/* DEV 21 */
921eb60705aSEric Wollesen 
922eb60705aSEric Wollesen 	/* Only if more than 2 channels do we release the second branch */
923b2ccaecaSDouglas Thompson 	if (pvt->maxch >= CHANNELS_PER_BRANCH)
924eb60705aSEric Wollesen 		pci_dev_put(pvt->branch_1);	/* DEV 22 */
925eb60705aSEric Wollesen }
926eb60705aSEric Wollesen 
927b2ccaecaSDouglas Thompson /*
928eb60705aSEric Wollesen  *	determine_amb_resent
929eb60705aSEric Wollesen  *
930eb60705aSEric Wollesen  *		the information is contained in NUM_MTRS different registers
931eb60705aSEric Wollesen  *		determineing which of the NUM_MTRS requires knowing
932eb60705aSEric Wollesen  *		which channel is in question
933eb60705aSEric Wollesen  *
934eb60705aSEric Wollesen  *	2 branches, each with 2 channels
935eb60705aSEric Wollesen  *		b0_ambpresent0 for channel '0'
936eb60705aSEric Wollesen  *		b0_ambpresent1 for channel '1'
937eb60705aSEric Wollesen  *		b1_ambpresent0 for channel '2'
938eb60705aSEric Wollesen  *		b1_ambpresent1 for channel '3'
939eb60705aSEric Wollesen  */
940eb60705aSEric Wollesen static int determine_amb_present_reg(struct i5000_pvt *pvt, int channel)
941eb60705aSEric Wollesen {
942eb60705aSEric Wollesen 	int amb_present;
943eb60705aSEric Wollesen 
944eb60705aSEric Wollesen 	if (channel < CHANNELS_PER_BRANCH) {
945eb60705aSEric Wollesen 		if (channel & 0x1)
946eb60705aSEric Wollesen 			amb_present = pvt->b0_ambpresent1;
947eb60705aSEric Wollesen 		else
948eb60705aSEric Wollesen 			amb_present = pvt->b0_ambpresent0;
949eb60705aSEric Wollesen 	} else {
950eb60705aSEric Wollesen 		if (channel & 0x1)
951eb60705aSEric Wollesen 			amb_present = pvt->b1_ambpresent1;
952eb60705aSEric Wollesen 		else
953eb60705aSEric Wollesen 			amb_present = pvt->b1_ambpresent0;
954eb60705aSEric Wollesen 	}
955eb60705aSEric Wollesen 
956eb60705aSEric Wollesen 	return amb_present;
957eb60705aSEric Wollesen }
958eb60705aSEric Wollesen 
959b2ccaecaSDouglas Thompson /*
960eb60705aSEric Wollesen  * determine_mtr(pvt, csrow, channel)
961eb60705aSEric Wollesen  *
962eb60705aSEric Wollesen  *	return the proper MTR register as determine by the csrow and channel desired
963eb60705aSEric Wollesen  */
96464e1fdafSMauro Carvalho Chehab static int determine_mtr(struct i5000_pvt *pvt, int slot, int channel)
965eb60705aSEric Wollesen {
966eb60705aSEric Wollesen 	int mtr;
967eb60705aSEric Wollesen 
968eb60705aSEric Wollesen 	if (channel < CHANNELS_PER_BRANCH)
96964e1fdafSMauro Carvalho Chehab 		mtr = pvt->b0_mtr[slot];
970eb60705aSEric Wollesen 	else
97164e1fdafSMauro Carvalho Chehab 		mtr = pvt->b1_mtr[slot];
972eb60705aSEric Wollesen 
973eb60705aSEric Wollesen 	return mtr;
974eb60705aSEric Wollesen }
975eb60705aSEric Wollesen 
976b2ccaecaSDouglas Thompson /*
977eb60705aSEric Wollesen  */
978eb60705aSEric Wollesen static void decode_mtr(int slot_row, u16 mtr)
979eb60705aSEric Wollesen {
980eb60705aSEric Wollesen 	int ans;
981eb60705aSEric Wollesen 
982eb60705aSEric Wollesen 	ans = MTR_DIMMS_PRESENT(mtr);
983eb60705aSEric Wollesen 
984eb60705aSEric Wollesen 	debugf2("\tMTR%d=0x%x:  DIMMs are %s\n", slot_row, mtr,
985eb60705aSEric Wollesen 		ans ? "Present" : "NOT Present");
986eb60705aSEric Wollesen 	if (!ans)
987eb60705aSEric Wollesen 		return;
988eb60705aSEric Wollesen 
989eb60705aSEric Wollesen 	debugf2("\t\tWIDTH: x%d\n", MTR_DRAM_WIDTH(mtr));
990eb60705aSEric Wollesen 	debugf2("\t\tNUMBANK: %d bank(s)\n", MTR_DRAM_BANKS(mtr));
991eb60705aSEric Wollesen 	debugf2("\t\tNUMRANK: %s\n", MTR_DIMM_RANK(mtr) ? "double" : "single");
992eb60705aSEric Wollesen 	debugf2("\t\tNUMROW: %s\n", numrow_toString[MTR_DIMM_ROWS(mtr)]);
993eb60705aSEric Wollesen 	debugf2("\t\tNUMCOL: %s\n", numcol_toString[MTR_DIMM_COLS(mtr)]);
994eb60705aSEric Wollesen }
995eb60705aSEric Wollesen 
99664e1fdafSMauro Carvalho Chehab static void handle_channel(struct i5000_pvt *pvt, int slot, int channel,
997eb60705aSEric Wollesen 			struct i5000_dimm_info *dinfo)
998eb60705aSEric Wollesen {
999eb60705aSEric Wollesen 	int mtr;
1000eb60705aSEric Wollesen 	int amb_present_reg;
1001eb60705aSEric Wollesen 	int addrBits;
1002eb60705aSEric Wollesen 
100364e1fdafSMauro Carvalho Chehab 	mtr = determine_mtr(pvt, slot, channel);
1004eb60705aSEric Wollesen 	if (MTR_DIMMS_PRESENT(mtr)) {
1005eb60705aSEric Wollesen 		amb_present_reg = determine_amb_present_reg(pvt, channel);
1006eb60705aSEric Wollesen 
1007eb60705aSEric Wollesen 		/* Determine if there is a DIMM present in this DIMM slot */
100864e1fdafSMauro Carvalho Chehab 		if (amb_present_reg) {
1009eb60705aSEric Wollesen 			dinfo->dual_rank = MTR_DIMM_RANK(mtr);
1010eb60705aSEric Wollesen 
1011eb60705aSEric Wollesen 			/* Start with the number of bits for a Bank
1012eb60705aSEric Wollesen 				* on the DRAM */
1013eb60705aSEric Wollesen 			addrBits = MTR_DRAM_BANKS_ADDR_BITS(mtr);
1014eb60705aSEric Wollesen 			/* Add the number of ROW bits */
1015eb60705aSEric Wollesen 			addrBits += MTR_DIMM_ROWS_ADDR_BITS(mtr);
1016eb60705aSEric Wollesen 			/* add the number of COLUMN bits */
1017eb60705aSEric Wollesen 			addrBits += MTR_DIMM_COLS_ADDR_BITS(mtr);
1018eb60705aSEric Wollesen 
1019eb60705aSEric Wollesen 			addrBits += 6;	/* add 64 bits per DIMM */
1020eb60705aSEric Wollesen 			addrBits -= 20;	/* divide by 2^^20 */
1021eb60705aSEric Wollesen 			addrBits -= 3;	/* 8 bits per bytes */
1022eb60705aSEric Wollesen 
1023eb60705aSEric Wollesen 			dinfo->megabytes = 1 << addrBits;
1024eb60705aSEric Wollesen 		}
1025eb60705aSEric Wollesen 	}
1026eb60705aSEric Wollesen }
1027eb60705aSEric Wollesen 
1028b2ccaecaSDouglas Thompson /*
1029eb60705aSEric Wollesen  *	calculate_dimm_size
1030eb60705aSEric Wollesen  *
1031eb60705aSEric Wollesen  *	also will output a DIMM matrix map, if debug is enabled, for viewing
1032eb60705aSEric Wollesen  *	how the DIMMs are populated
1033eb60705aSEric Wollesen  */
1034eb60705aSEric Wollesen static void calculate_dimm_size(struct i5000_pvt *pvt)
1035eb60705aSEric Wollesen {
1036eb60705aSEric Wollesen 	struct i5000_dimm_info *dinfo;
103764e1fdafSMauro Carvalho Chehab 	int slot, channel, branch;
1038eb60705aSEric Wollesen 	char *p, *mem_buffer;
1039eb60705aSEric Wollesen 	int space, n;
1040eb60705aSEric Wollesen 
1041eb60705aSEric Wollesen 	/* ================= Generate some debug output ================= */
1042eb60705aSEric Wollesen 	space = PAGE_SIZE;
1043eb60705aSEric Wollesen 	mem_buffer = p = kmalloc(space, GFP_KERNEL);
1044eb60705aSEric Wollesen 	if (p == NULL) {
1045eb60705aSEric Wollesen 		i5000_printk(KERN_ERR, "MC: %s:%s() kmalloc() failed\n",
1046eb60705aSEric Wollesen 			__FILE__, __func__);
1047eb60705aSEric Wollesen 		return;
1048eb60705aSEric Wollesen 	}
1049eb60705aSEric Wollesen 
105064e1fdafSMauro Carvalho Chehab 	/* Scan all the actual slots
1051eb60705aSEric Wollesen 	 * and calculate the information for each DIMM
105264e1fdafSMauro Carvalho Chehab 	 * Start with the highest slot first, to display it first
105364e1fdafSMauro Carvalho Chehab 	 * and work toward the 0th slot
1054eb60705aSEric Wollesen 	 */
105564e1fdafSMauro Carvalho Chehab 	for (slot = pvt->maxdimmperch - 1; slot >= 0; slot--) {
1056eb60705aSEric Wollesen 
105764e1fdafSMauro Carvalho Chehab 		/* on an odd slot, first output a 'boundary' marker,
1058eb60705aSEric Wollesen 		 * then reset the message buffer  */
105964e1fdafSMauro Carvalho Chehab 		if (slot & 0x1) {
106064e1fdafSMauro Carvalho Chehab 			n = snprintf(p, space, "--------------------------"
1061eb60705aSEric Wollesen 				"--------------------------------");
1062eb60705aSEric Wollesen 			p += n;
1063eb60705aSEric Wollesen 			space -= n;
1064eb60705aSEric Wollesen 			debugf2("%s\n", mem_buffer);
1065eb60705aSEric Wollesen 			p = mem_buffer;
1066eb60705aSEric Wollesen 			space = PAGE_SIZE;
1067eb60705aSEric Wollesen 		}
106864e1fdafSMauro Carvalho Chehab 		n = snprintf(p, space, "slot %2d    ", slot);
1069eb60705aSEric Wollesen 		p += n;
1070eb60705aSEric Wollesen 		space -= n;
1071eb60705aSEric Wollesen 
1072eb60705aSEric Wollesen 		for (channel = 0; channel < pvt->maxch; channel++) {
107364e1fdafSMauro Carvalho Chehab 			dinfo = &pvt->dimm_info[slot][channel];
107464e1fdafSMauro Carvalho Chehab 			handle_channel(pvt, slot, channel, dinfo);
107564e1fdafSMauro Carvalho Chehab 			if (dinfo->megabytes)
107664e1fdafSMauro Carvalho Chehab 				n = snprintf(p, space, "%4d MB %dR| ",
107764e1fdafSMauro Carvalho Chehab 					     dinfo->megabytes, dinfo->dual_rank + 1);
107864e1fdafSMauro Carvalho Chehab 			else
107964e1fdafSMauro Carvalho Chehab 				n = snprintf(p, space, "%4d MB   | ", 0);
1080eb60705aSEric Wollesen 			p += n;
1081eb60705aSEric Wollesen 			space -= n;
1082eb60705aSEric Wollesen 		}
1083eb60705aSEric Wollesen 		p += n;
1084eb60705aSEric Wollesen 		space -= n;
108564e1fdafSMauro Carvalho Chehab 		debugf2("%s\n", mem_buffer);
108664e1fdafSMauro Carvalho Chehab 		p = mem_buffer;
108764e1fdafSMauro Carvalho Chehab 		space = PAGE_SIZE;
1088eb60705aSEric Wollesen 	}
1089eb60705aSEric Wollesen 
1090eb60705aSEric Wollesen 	/* Output the last bottom 'boundary' marker */
109164e1fdafSMauro Carvalho Chehab 	n = snprintf(p, space, "--------------------------"
109264e1fdafSMauro Carvalho Chehab 		"--------------------------------");
1093eb60705aSEric Wollesen 	p += n;
1094eb60705aSEric Wollesen 	space -= n;
109564e1fdafSMauro Carvalho Chehab 	debugf2("%s\n", mem_buffer);
109664e1fdafSMauro Carvalho Chehab 	p = mem_buffer;
109764e1fdafSMauro Carvalho Chehab 	space = PAGE_SIZE;
1098eb60705aSEric Wollesen 
1099eb60705aSEric Wollesen 	/* now output the 'channel' labels */
1100eb60705aSEric Wollesen 	n = snprintf(p, space, "           ");
1101eb60705aSEric Wollesen 	p += n;
1102eb60705aSEric Wollesen 	space -= n;
1103eb60705aSEric Wollesen 	for (channel = 0; channel < pvt->maxch; channel++) {
1104eb60705aSEric Wollesen 		n = snprintf(p, space, "channel %d | ", channel);
1105eb60705aSEric Wollesen 		p += n;
1106eb60705aSEric Wollesen 		space -= n;
1107eb60705aSEric Wollesen 	}
110864e1fdafSMauro Carvalho Chehab 	debugf2("%s\n", mem_buffer);
110964e1fdafSMauro Carvalho Chehab 	p = mem_buffer;
111064e1fdafSMauro Carvalho Chehab 	space = PAGE_SIZE;
111164e1fdafSMauro Carvalho Chehab 
111264e1fdafSMauro Carvalho Chehab 	n = snprintf(p, space, "           ");
111364e1fdafSMauro Carvalho Chehab 	p += n;
111464e1fdafSMauro Carvalho Chehab 	for (branch = 0; branch < MAX_BRANCHES; branch++) {
111564e1fdafSMauro Carvalho Chehab 		n = snprintf(p, space, "       branch %d       | ", branch);
1116eb60705aSEric Wollesen 		p += n;
1117eb60705aSEric Wollesen 		space -= n;
111864e1fdafSMauro Carvalho Chehab 	}
1119eb60705aSEric Wollesen 
1120eb60705aSEric Wollesen 	/* output the last message and free buffer */
1121eb60705aSEric Wollesen 	debugf2("%s\n", mem_buffer);
1122eb60705aSEric Wollesen 	kfree(mem_buffer);
1123eb60705aSEric Wollesen }
1124eb60705aSEric Wollesen 
1125b2ccaecaSDouglas Thompson /*
1126eb60705aSEric Wollesen  *	i5000_get_mc_regs	read in the necessary registers and
1127eb60705aSEric Wollesen  *				cache locally
1128eb60705aSEric Wollesen  *
1129eb60705aSEric Wollesen  *			Fills in the private data members
1130eb60705aSEric Wollesen  */
1131eb60705aSEric Wollesen static void i5000_get_mc_regs(struct mem_ctl_info *mci)
1132eb60705aSEric Wollesen {
1133eb60705aSEric Wollesen 	struct i5000_pvt *pvt;
1134eb60705aSEric Wollesen 	u32 actual_tolm;
1135eb60705aSEric Wollesen 	u16 limit;
1136eb60705aSEric Wollesen 	int slot_row;
1137eb60705aSEric Wollesen 	int maxch;
1138eb60705aSEric Wollesen 	int maxdimmperch;
1139eb60705aSEric Wollesen 	int way0, way1;
1140eb60705aSEric Wollesen 
1141b2ccaecaSDouglas Thompson 	pvt = mci->pvt_info;
1142eb60705aSEric Wollesen 
1143eb60705aSEric Wollesen 	pci_read_config_dword(pvt->system_address, AMBASE,
1144eb60705aSEric Wollesen 			(u32 *) & pvt->ambase);
1145eb60705aSEric Wollesen 	pci_read_config_dword(pvt->system_address, AMBASE + sizeof(u32),
1146eb60705aSEric Wollesen 			((u32 *) & pvt->ambase) + sizeof(u32));
1147eb60705aSEric Wollesen 
1148eb60705aSEric Wollesen 	maxdimmperch = pvt->maxdimmperch;
1149eb60705aSEric Wollesen 	maxch = pvt->maxch;
1150eb60705aSEric Wollesen 
1151eb60705aSEric Wollesen 	debugf2("AMBASE= 0x%lx  MAXCH= %d  MAX-DIMM-Per-CH= %d\n",
1152eb60705aSEric Wollesen 		(long unsigned int)pvt->ambase, pvt->maxch, pvt->maxdimmperch);
1153eb60705aSEric Wollesen 
1154eb60705aSEric Wollesen 	/* Get the Branch Map regs */
1155eb60705aSEric Wollesen 	pci_read_config_word(pvt->branchmap_werrors, TOLM, &pvt->tolm);
1156eb60705aSEric Wollesen 	pvt->tolm >>= 12;
1157eb60705aSEric Wollesen 	debugf2("\nTOLM (number of 256M regions) =%u (0x%x)\n", pvt->tolm,
1158eb60705aSEric Wollesen 		pvt->tolm);
1159eb60705aSEric Wollesen 
1160eb60705aSEric Wollesen 	actual_tolm = pvt->tolm << 28;
1161eb60705aSEric Wollesen 	debugf2("Actual TOLM byte addr=%u (0x%x)\n", actual_tolm, actual_tolm);
1162eb60705aSEric Wollesen 
1163eb60705aSEric Wollesen 	pci_read_config_word(pvt->branchmap_werrors, MIR0, &pvt->mir0);
1164eb60705aSEric Wollesen 	pci_read_config_word(pvt->branchmap_werrors, MIR1, &pvt->mir1);
1165eb60705aSEric Wollesen 	pci_read_config_word(pvt->branchmap_werrors, MIR2, &pvt->mir2);
1166eb60705aSEric Wollesen 
1167eb60705aSEric Wollesen 	/* Get the MIR[0-2] regs */
1168eb60705aSEric Wollesen 	limit = (pvt->mir0 >> 4) & 0x0FFF;
1169eb60705aSEric Wollesen 	way0 = pvt->mir0 & 0x1;
1170eb60705aSEric Wollesen 	way1 = pvt->mir0 & 0x2;
1171eb60705aSEric Wollesen 	debugf2("MIR0: limit= 0x%x  WAY1= %u  WAY0= %x\n", limit, way1, way0);
1172eb60705aSEric Wollesen 	limit = (pvt->mir1 >> 4) & 0x0FFF;
1173eb60705aSEric Wollesen 	way0 = pvt->mir1 & 0x1;
1174eb60705aSEric Wollesen 	way1 = pvt->mir1 & 0x2;
1175eb60705aSEric Wollesen 	debugf2("MIR1: limit= 0x%x  WAY1= %u  WAY0= %x\n", limit, way1, way0);
1176eb60705aSEric Wollesen 	limit = (pvt->mir2 >> 4) & 0x0FFF;
1177eb60705aSEric Wollesen 	way0 = pvt->mir2 & 0x1;
1178eb60705aSEric Wollesen 	way1 = pvt->mir2 & 0x2;
1179eb60705aSEric Wollesen 	debugf2("MIR2: limit= 0x%x  WAY1= %u  WAY0= %x\n", limit, way1, way0);
1180eb60705aSEric Wollesen 
1181eb60705aSEric Wollesen 	/* Get the MTR[0-3] regs */
1182eb60705aSEric Wollesen 	for (slot_row = 0; slot_row < NUM_MTRS; slot_row++) {
1183eb60705aSEric Wollesen 		int where = MTR0 + (slot_row * sizeof(u32));
1184eb60705aSEric Wollesen 
1185eb60705aSEric Wollesen 		pci_read_config_word(pvt->branch_0, where,
1186eb60705aSEric Wollesen 				&pvt->b0_mtr[slot_row]);
1187eb60705aSEric Wollesen 
1188eb60705aSEric Wollesen 		debugf2("MTR%d where=0x%x B0 value=0x%x\n", slot_row, where,
1189eb60705aSEric Wollesen 			pvt->b0_mtr[slot_row]);
1190eb60705aSEric Wollesen 
1191eb60705aSEric Wollesen 		if (pvt->maxch >= CHANNELS_PER_BRANCH) {
1192eb60705aSEric Wollesen 			pci_read_config_word(pvt->branch_1, where,
1193eb60705aSEric Wollesen 					&pvt->b1_mtr[slot_row]);
1194eb60705aSEric Wollesen 			debugf2("MTR%d where=0x%x B1 value=0x%x\n", slot_row,
1195c2494aceSKeith Mannthey 				where, pvt->b1_mtr[slot_row]);
1196eb60705aSEric Wollesen 		} else {
1197eb60705aSEric Wollesen 			pvt->b1_mtr[slot_row] = 0;
1198eb60705aSEric Wollesen 		}
1199eb60705aSEric Wollesen 	}
1200eb60705aSEric Wollesen 
1201eb60705aSEric Wollesen 	/* Read and dump branch 0's MTRs */
1202eb60705aSEric Wollesen 	debugf2("\nMemory Technology Registers:\n");
1203eb60705aSEric Wollesen 	debugf2("   Branch 0:\n");
1204eb60705aSEric Wollesen 	for (slot_row = 0; slot_row < NUM_MTRS; slot_row++) {
1205eb60705aSEric Wollesen 		decode_mtr(slot_row, pvt->b0_mtr[slot_row]);
1206eb60705aSEric Wollesen 	}
1207eb60705aSEric Wollesen 	pci_read_config_word(pvt->branch_0, AMB_PRESENT_0,
1208eb60705aSEric Wollesen 			&pvt->b0_ambpresent0);
1209eb60705aSEric Wollesen 	debugf2("\t\tAMB-Branch 0-present0 0x%x:\n", pvt->b0_ambpresent0);
1210eb60705aSEric Wollesen 	pci_read_config_word(pvt->branch_0, AMB_PRESENT_1,
1211eb60705aSEric Wollesen 			&pvt->b0_ambpresent1);
1212eb60705aSEric Wollesen 	debugf2("\t\tAMB-Branch 0-present1 0x%x:\n", pvt->b0_ambpresent1);
1213eb60705aSEric Wollesen 
1214eb60705aSEric Wollesen 	/* Only if we have 2 branchs (4 channels) */
1215eb60705aSEric Wollesen 	if (pvt->maxch < CHANNELS_PER_BRANCH) {
1216eb60705aSEric Wollesen 		pvt->b1_ambpresent0 = 0;
1217eb60705aSEric Wollesen 		pvt->b1_ambpresent1 = 0;
1218eb60705aSEric Wollesen 	} else {
1219eb60705aSEric Wollesen 		/* Read and dump  branch 1's MTRs */
1220eb60705aSEric Wollesen 		debugf2("   Branch 1:\n");
1221eb60705aSEric Wollesen 		for (slot_row = 0; slot_row < NUM_MTRS; slot_row++) {
1222eb60705aSEric Wollesen 			decode_mtr(slot_row, pvt->b1_mtr[slot_row]);
1223eb60705aSEric Wollesen 		}
1224eb60705aSEric Wollesen 		pci_read_config_word(pvt->branch_1, AMB_PRESENT_0,
1225eb60705aSEric Wollesen 				&pvt->b1_ambpresent0);
1226eb60705aSEric Wollesen 		debugf2("\t\tAMB-Branch 1-present0 0x%x:\n",
1227eb60705aSEric Wollesen 			pvt->b1_ambpresent0);
1228eb60705aSEric Wollesen 		pci_read_config_word(pvt->branch_1, AMB_PRESENT_1,
1229eb60705aSEric Wollesen 				&pvt->b1_ambpresent1);
1230eb60705aSEric Wollesen 		debugf2("\t\tAMB-Branch 1-present1 0x%x:\n",
1231eb60705aSEric Wollesen 			pvt->b1_ambpresent1);
1232eb60705aSEric Wollesen 	}
1233eb60705aSEric Wollesen 
1234eb60705aSEric Wollesen 	/* Go and determine the size of each DIMM and place in an
1235eb60705aSEric Wollesen 	 * orderly matrix */
1236eb60705aSEric Wollesen 	calculate_dimm_size(pvt);
1237eb60705aSEric Wollesen }
1238eb60705aSEric Wollesen 
1239b2ccaecaSDouglas Thompson /*
1240eb60705aSEric Wollesen  *	i5000_init_csrows	Initialize the 'csrows' table within
1241eb60705aSEric Wollesen  *				the mci control	structure with the
1242eb60705aSEric Wollesen  *				addressing of memory.
1243eb60705aSEric Wollesen  *
1244eb60705aSEric Wollesen  *	return:
1245eb60705aSEric Wollesen  *		0	success
1246eb60705aSEric Wollesen  *		1	no actual memory found on this MC
1247eb60705aSEric Wollesen  */
1248eb60705aSEric Wollesen static int i5000_init_csrows(struct mem_ctl_info *mci)
1249eb60705aSEric Wollesen {
1250eb60705aSEric Wollesen 	struct i5000_pvt *pvt;
1251a895bf8bSMauro Carvalho Chehab 	struct dimm_info *dimm;
1252eb60705aSEric Wollesen 	int empty, channel_count;
1253eb60705aSEric Wollesen 	int max_csrows;
125464e1fdafSMauro Carvalho Chehab 	int mtr;
1255eb60705aSEric Wollesen 	int csrow_megs;
1256eb60705aSEric Wollesen 	int channel;
125764e1fdafSMauro Carvalho Chehab 	int slot;
1258eb60705aSEric Wollesen 
1259b2ccaecaSDouglas Thompson 	pvt = mci->pvt_info;
1260eb60705aSEric Wollesen 
1261eb60705aSEric Wollesen 	channel_count = pvt->maxch;
1262eb60705aSEric Wollesen 	max_csrows = pvt->maxdimmperch * 2;
1263eb60705aSEric Wollesen 
1264eb60705aSEric Wollesen 	empty = 1;		/* Assume NO memory */
1265eb60705aSEric Wollesen 
1266702df640SMauro Carvalho Chehab 	/*
126764e1fdafSMauro Carvalho Chehab 	 * FIXME: The memory layout used to map slot/channel into the
126864e1fdafSMauro Carvalho Chehab 	 * real memory architecture is weird: branch+slot are "csrows"
126964e1fdafSMauro Carvalho Chehab 	 * and channel is channel. That required an extra array (dimm_info)
127064e1fdafSMauro Carvalho Chehab 	 * to map the dimms. A good cleanup would be to remove this array,
127164e1fdafSMauro Carvalho Chehab 	 * and do a loop here with branch, channel, slot
1272702df640SMauro Carvalho Chehab 	 */
127364e1fdafSMauro Carvalho Chehab 	for (slot = 0; slot < max_csrows; slot++) {
127464e1fdafSMauro Carvalho Chehab 		for (channel = 0; channel < pvt->maxch; channel++) {
1275eb60705aSEric Wollesen 
127664e1fdafSMauro Carvalho Chehab 			mtr = determine_mtr(pvt, slot, channel);
1277eb60705aSEric Wollesen 
127864e1fdafSMauro Carvalho Chehab 			if (!MTR_DIMMS_PRESENT(mtr))
1279eb60705aSEric Wollesen 				continue;
1280eb60705aSEric Wollesen 
128164e1fdafSMauro Carvalho Chehab 			dimm = EDAC_DIMM_PTR(mci->layers, mci->dimms, mci->n_layers,
128264e1fdafSMauro Carvalho Chehab 				       channel / MAX_BRANCHES,
128364e1fdafSMauro Carvalho Chehab 				       channel % MAX_BRANCHES, slot);
128464e1fdafSMauro Carvalho Chehab 
128564e1fdafSMauro Carvalho Chehab 			csrow_megs = pvt->dimm_info[slot][channel].megabytes;
1286a895bf8bSMauro Carvalho Chehab 			dimm->grain = 8;
1287eb60705aSEric Wollesen 
1288eb60705aSEric Wollesen 			/* Assume DDR2 for now */
1289a895bf8bSMauro Carvalho Chehab 			dimm->mtype = MEM_FB_DDR2;
1290eb60705aSEric Wollesen 
1291eb60705aSEric Wollesen 			/* ask what device type on this row */
1292eb60705aSEric Wollesen 			if (MTR_DRAM_WIDTH(mtr))
1293a895bf8bSMauro Carvalho Chehab 				dimm->dtype = DEV_X8;
1294eb60705aSEric Wollesen 			else
1295a895bf8bSMauro Carvalho Chehab 				dimm->dtype = DEV_X4;
1296eb60705aSEric Wollesen 
1297a895bf8bSMauro Carvalho Chehab 			dimm->edac_mode = EDAC_S8ECD8ED;
129864e1fdafSMauro Carvalho Chehab 			dimm->nr_pages = csrow_megs << 8;
1299084a4fccSMauro Carvalho Chehab 		}
1300eb60705aSEric Wollesen 
1301eb60705aSEric Wollesen 		empty = 0;
1302eb60705aSEric Wollesen 	}
1303eb60705aSEric Wollesen 
1304eb60705aSEric Wollesen 	return empty;
1305eb60705aSEric Wollesen }
1306eb60705aSEric Wollesen 
1307b2ccaecaSDouglas Thompson /*
1308eb60705aSEric Wollesen  *	i5000_enable_error_reporting
1309eb60705aSEric Wollesen  *			Turn on the memory reporting features of the hardware
1310eb60705aSEric Wollesen  */
1311eb60705aSEric Wollesen static void i5000_enable_error_reporting(struct mem_ctl_info *mci)
1312eb60705aSEric Wollesen {
1313eb60705aSEric Wollesen 	struct i5000_pvt *pvt;
1314eb60705aSEric Wollesen 	u32 fbd_error_mask;
1315eb60705aSEric Wollesen 
1316b2ccaecaSDouglas Thompson 	pvt = mci->pvt_info;
1317eb60705aSEric Wollesen 
1318eb60705aSEric Wollesen 	/* Read the FBD Error Mask Register */
1319eb60705aSEric Wollesen 	pci_read_config_dword(pvt->branchmap_werrors, EMASK_FBD,
1320eb60705aSEric Wollesen 			&fbd_error_mask);
1321eb60705aSEric Wollesen 
1322eb60705aSEric Wollesen 	/* Enable with a '0' */
1323eb60705aSEric Wollesen 	fbd_error_mask &= ~(ENABLE_EMASK_ALL);
1324eb60705aSEric Wollesen 
1325eb60705aSEric Wollesen 	pci_write_config_dword(pvt->branchmap_werrors, EMASK_FBD,
1326eb60705aSEric Wollesen 			fbd_error_mask);
1327eb60705aSEric Wollesen }
1328eb60705aSEric Wollesen 
1329b2ccaecaSDouglas Thompson /*
1330702df640SMauro Carvalho Chehab  * i5000_get_dimm_and_channel_counts(pdev, &nr_csrows, &num_channels)
1331eb60705aSEric Wollesen  *
1332eb60705aSEric Wollesen  *	ask the device how many channels are present and how many CSROWS
1333eb60705aSEric Wollesen  *	 as well
1334eb60705aSEric Wollesen  */
1335eb60705aSEric Wollesen static void i5000_get_dimm_and_channel_counts(struct pci_dev *pdev,
1336eb60705aSEric Wollesen 					int *num_dimms_per_channel,
1337eb60705aSEric Wollesen 					int *num_channels)
1338eb60705aSEric Wollesen {
1339eb60705aSEric Wollesen 	u8 value;
1340eb60705aSEric Wollesen 
1341eb60705aSEric Wollesen 	/* Need to retrieve just how many channels and dimms per channel are
1342eb60705aSEric Wollesen 	 * supported on this memory controller
1343eb60705aSEric Wollesen 	 */
1344eb60705aSEric Wollesen 	pci_read_config_byte(pdev, MAXDIMMPERCH, &value);
134564e1fdafSMauro Carvalho Chehab 	*num_dimms_per_channel = (int)value;
1346eb60705aSEric Wollesen 
1347eb60705aSEric Wollesen 	pci_read_config_byte(pdev, MAXCH, &value);
1348eb60705aSEric Wollesen 	*num_channels = (int)value;
1349eb60705aSEric Wollesen }
1350eb60705aSEric Wollesen 
1351b2ccaecaSDouglas Thompson /*
1352eb60705aSEric Wollesen  *	i5000_probe1	Probe for ONE instance of device to see if it is
1353eb60705aSEric Wollesen  *			present.
1354eb60705aSEric Wollesen  *	return:
1355eb60705aSEric Wollesen  *		0 for FOUND a device
1356eb60705aSEric Wollesen  *		< 0 for error code
1357eb60705aSEric Wollesen  */
1358eb60705aSEric Wollesen static int i5000_probe1(struct pci_dev *pdev, int dev_idx)
1359eb60705aSEric Wollesen {
1360eb60705aSEric Wollesen 	struct mem_ctl_info *mci;
1361702df640SMauro Carvalho Chehab 	struct edac_mc_layer layers[3];
1362eb60705aSEric Wollesen 	struct i5000_pvt *pvt;
1363eb60705aSEric Wollesen 	int num_channels;
1364eb60705aSEric Wollesen 	int num_dimms_per_channel;
1365eb60705aSEric Wollesen 
136663ae96beSJoe Perches 	debugf0("MC: %s: %s(), pdev bus %u dev=0x%x fn=0x%x\n",
136763ae96beSJoe Perches 		__FILE__, __func__,
1368eb60705aSEric Wollesen 		pdev->bus->number,
1369eb60705aSEric Wollesen 		PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
1370eb60705aSEric Wollesen 
1371eb60705aSEric Wollesen 	/* We only are looking for func 0 of the set */
1372eb60705aSEric Wollesen 	if (PCI_FUNC(pdev->devfn) != 0)
1373eb60705aSEric Wollesen 		return -ENODEV;
1374eb60705aSEric Wollesen 
1375eb60705aSEric Wollesen 	/* Ask the devices for the number of CSROWS and CHANNELS so
1376eb60705aSEric Wollesen 	 * that we can calculate the memory resources, etc
1377eb60705aSEric Wollesen 	 *
1378eb60705aSEric Wollesen 	 * The Chipset will report what it can handle which will be greater
1379eb60705aSEric Wollesen 	 * or equal to what the motherboard manufacturer will implement.
1380eb60705aSEric Wollesen 	 *
1381eb60705aSEric Wollesen 	 * As we don't have a motherboard identification routine to determine
1382eb60705aSEric Wollesen 	 * actual number of slots/dimms per channel, we thus utilize the
1383eb60705aSEric Wollesen 	 * resource as specified by the chipset. Thus, we might have
1384eb60705aSEric Wollesen 	 * have more DIMMs per channel than actually on the mobo, but this
1385eb60705aSEric Wollesen 	 * allows the driver to support up to the chipset max, without
1386eb60705aSEric Wollesen 	 * some fancy mobo determination.
1387eb60705aSEric Wollesen 	 */
1388eb60705aSEric Wollesen 	i5000_get_dimm_and_channel_counts(pdev, &num_dimms_per_channel,
1389eb60705aSEric Wollesen 					&num_channels);
1390eb60705aSEric Wollesen 
1391702df640SMauro Carvalho Chehab 	debugf0("MC: %s(): Number of Branches=2 Channels= %d  DIMMS= %d\n",
1392702df640SMauro Carvalho Chehab 		__func__, num_channels, num_dimms_per_channel);
1393eb60705aSEric Wollesen 
1394eb60705aSEric Wollesen 	/* allocate a new MC control structure */
139564e1fdafSMauro Carvalho Chehab 
1396702df640SMauro Carvalho Chehab 	layers[0].type = EDAC_MC_LAYER_BRANCH;
139764e1fdafSMauro Carvalho Chehab 	layers[0].size = MAX_BRANCHES;
139864e1fdafSMauro Carvalho Chehab 	layers[0].is_virt_csrow = false;
1399702df640SMauro Carvalho Chehab 	layers[1].type = EDAC_MC_LAYER_CHANNEL;
140064e1fdafSMauro Carvalho Chehab 	layers[1].size = num_channels / MAX_BRANCHES;
1401702df640SMauro Carvalho Chehab 	layers[1].is_virt_csrow = false;
1402702df640SMauro Carvalho Chehab 	layers[2].type = EDAC_MC_LAYER_SLOT;
1403702df640SMauro Carvalho Chehab 	layers[2].size = num_dimms_per_channel;
1404702df640SMauro Carvalho Chehab 	layers[2].is_virt_csrow = true;
1405ca0907b9SMauro Carvalho Chehab 	mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, sizeof(*pvt));
1406eb60705aSEric Wollesen 	if (mci == NULL)
1407eb60705aSEric Wollesen 		return -ENOMEM;
1408eb60705aSEric Wollesen 
1409f0f7e0dcSDarrick J. Wong 	kobject_get(&mci->edac_mci_kobj);
141063ae96beSJoe Perches 	debugf0("MC: %s: %s(): mci = %p\n", __FILE__, __func__, mci);
1411eb60705aSEric Wollesen 
1412eb60705aSEric Wollesen 	mci->dev = &pdev->dev;	/* record ptr  to the generic device */
1413eb60705aSEric Wollesen 
1414b2ccaecaSDouglas Thompson 	pvt = mci->pvt_info;
1415eb60705aSEric Wollesen 	pvt->system_address = pdev;	/* Record this device in our private */
1416eb60705aSEric Wollesen 	pvt->maxch = num_channels;
1417eb60705aSEric Wollesen 	pvt->maxdimmperch = num_dimms_per_channel;
1418eb60705aSEric Wollesen 
1419eb60705aSEric Wollesen 	/* 'get' the pci devices we want to reserve for our use */
1420eb60705aSEric Wollesen 	if (i5000_get_devices(mci, dev_idx))
1421eb60705aSEric Wollesen 		goto fail0;
1422eb60705aSEric Wollesen 
1423eb60705aSEric Wollesen 	/* Time to get serious */
1424eb60705aSEric Wollesen 	i5000_get_mc_regs(mci);	/* retrieve the hardware registers */
1425eb60705aSEric Wollesen 
1426eb60705aSEric Wollesen 	mci->mc_idx = 0;
1427eb60705aSEric Wollesen 	mci->mtype_cap = MEM_FLAG_FB_DDR2;
1428eb60705aSEric Wollesen 	mci->edac_ctl_cap = EDAC_FLAG_NONE;
1429eb60705aSEric Wollesen 	mci->edac_cap = EDAC_FLAG_NONE;
1430eb60705aSEric Wollesen 	mci->mod_name = "i5000_edac.c";
1431eb60705aSEric Wollesen 	mci->mod_ver = I5000_REVISION;
1432eb60705aSEric Wollesen 	mci->ctl_name = i5000_devs[dev_idx].ctl_name;
1433c4192705SDave Jiang 	mci->dev_name = pci_name(pdev);
1434eb60705aSEric Wollesen 	mci->ctl_page_to_phys = NULL;
1435eb60705aSEric Wollesen 
1436eb60705aSEric Wollesen 	/* Set the function pointer to an actual operation function */
1437eb60705aSEric Wollesen 	mci->edac_check = i5000_check_error;
1438eb60705aSEric Wollesen 
1439eb60705aSEric Wollesen 	/* initialize the MC control structure 'csrows' table
1440eb60705aSEric Wollesen 	 * with the mapping and control information */
1441eb60705aSEric Wollesen 	if (i5000_init_csrows(mci)) {
1442eb60705aSEric Wollesen 		debugf0("MC: Setting mci->edac_cap to EDAC_FLAG_NONE\n"
1443eb60705aSEric Wollesen 			"    because i5000_init_csrows() returned nonzero "
1444eb60705aSEric Wollesen 			"value\n");
1445eb60705aSEric Wollesen 		mci->edac_cap = EDAC_FLAG_NONE;	/* no csrows found */
1446eb60705aSEric Wollesen 	} else {
1447eb60705aSEric Wollesen 		debugf1("MC: Enable error reporting now\n");
1448eb60705aSEric Wollesen 		i5000_enable_error_reporting(mci);
1449eb60705aSEric Wollesen 	}
1450eb60705aSEric Wollesen 
1451eb60705aSEric Wollesen 	/* add this new MC control structure to EDAC's list of MCs */
1452b8f6f975SDoug Thompson 	if (edac_mc_add_mc(mci)) {
145363ae96beSJoe Perches 		debugf0("MC: %s: %s(): failed edac_mc_add_mc()\n",
145463ae96beSJoe Perches 			__FILE__, __func__);
1455eb60705aSEric Wollesen 		/* FIXME: perhaps some code should go here that disables error
1456eb60705aSEric Wollesen 		 * reporting if we just enabled it
1457eb60705aSEric Wollesen 		 */
1458eb60705aSEric Wollesen 		goto fail1;
1459eb60705aSEric Wollesen 	}
1460eb60705aSEric Wollesen 
1461eb60705aSEric Wollesen 	i5000_clear_error(mci);
1462eb60705aSEric Wollesen 
1463456a2f95SDave Jiang 	/* allocating generic PCI control info */
1464456a2f95SDave Jiang 	i5000_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
1465456a2f95SDave Jiang 	if (!i5000_pci) {
1466456a2f95SDave Jiang 		printk(KERN_WARNING
1467456a2f95SDave Jiang 			"%s(): Unable to create PCI control\n",
1468456a2f95SDave Jiang 			__func__);
1469456a2f95SDave Jiang 		printk(KERN_WARNING
1470456a2f95SDave Jiang 			"%s(): PCI error report via EDAC not setup\n",
1471456a2f95SDave Jiang 			__func__);
1472456a2f95SDave Jiang 	}
1473456a2f95SDave Jiang 
1474eb60705aSEric Wollesen 	return 0;
1475eb60705aSEric Wollesen 
1476eb60705aSEric Wollesen 	/* Error exit unwinding stack */
1477eb60705aSEric Wollesen fail1:
1478eb60705aSEric Wollesen 
1479eb60705aSEric Wollesen 	i5000_put_devices(mci);
1480eb60705aSEric Wollesen 
1481eb60705aSEric Wollesen fail0:
1482f0f7e0dcSDarrick J. Wong 	kobject_put(&mci->edac_mci_kobj);
1483eb60705aSEric Wollesen 	edac_mc_free(mci);
1484eb60705aSEric Wollesen 	return -ENODEV;
1485eb60705aSEric Wollesen }
1486eb60705aSEric Wollesen 
1487b2ccaecaSDouglas Thompson /*
1488eb60705aSEric Wollesen  *	i5000_init_one	constructor for one instance of device
1489eb60705aSEric Wollesen  *
1490eb60705aSEric Wollesen  * 	returns:
1491eb60705aSEric Wollesen  *		negative on error
1492eb60705aSEric Wollesen  *		count (>= 0)
1493eb60705aSEric Wollesen  */
1494eb60705aSEric Wollesen static int __devinit i5000_init_one(struct pci_dev *pdev,
1495eb60705aSEric Wollesen 				const struct pci_device_id *id)
1496eb60705aSEric Wollesen {
1497eb60705aSEric Wollesen 	int rc;
1498eb60705aSEric Wollesen 
149963ae96beSJoe Perches 	debugf0("MC: %s: %s()\n", __FILE__, __func__);
1500eb60705aSEric Wollesen 
1501eb60705aSEric Wollesen 	/* wake up device */
1502eb60705aSEric Wollesen 	rc = pci_enable_device(pdev);
150344aa80f0SKulikov Vasiliy 	if (rc)
1504eb60705aSEric Wollesen 		return rc;
1505eb60705aSEric Wollesen 
1506eb60705aSEric Wollesen 	/* now probe and enable the device */
1507eb60705aSEric Wollesen 	return i5000_probe1(pdev, id->driver_data);
1508eb60705aSEric Wollesen }
1509eb60705aSEric Wollesen 
1510b2ccaecaSDouglas Thompson /*
1511eb60705aSEric Wollesen  *	i5000_remove_one	destructor for one instance of device
1512eb60705aSEric Wollesen  *
1513eb60705aSEric Wollesen  */
1514eb60705aSEric Wollesen static void __devexit i5000_remove_one(struct pci_dev *pdev)
1515eb60705aSEric Wollesen {
1516eb60705aSEric Wollesen 	struct mem_ctl_info *mci;
1517eb60705aSEric Wollesen 
151863ae96beSJoe Perches 	debugf0("%s: %s()\n", __FILE__, __func__);
1519eb60705aSEric Wollesen 
1520456a2f95SDave Jiang 	if (i5000_pci)
1521456a2f95SDave Jiang 		edac_pci_release_generic_ctl(i5000_pci);
1522456a2f95SDave Jiang 
1523eb60705aSEric Wollesen 	if ((mci = edac_mc_del_mc(&pdev->dev)) == NULL)
1524eb60705aSEric Wollesen 		return;
1525eb60705aSEric Wollesen 
1526eb60705aSEric Wollesen 	/* retrieve references to resources, and free those resources */
1527eb60705aSEric Wollesen 	i5000_put_devices(mci);
1528f0f7e0dcSDarrick J. Wong 	kobject_put(&mci->edac_mci_kobj);
1529eb60705aSEric Wollesen 	edac_mc_free(mci);
1530eb60705aSEric Wollesen }
1531eb60705aSEric Wollesen 
1532b2ccaecaSDouglas Thompson /*
1533eb60705aSEric Wollesen  *	pci_device_id	table for which devices we are looking for
1534eb60705aSEric Wollesen  *
1535eb60705aSEric Wollesen  *	The "E500P" device is the first device supported.
1536eb60705aSEric Wollesen  */
153736c46f31SLionel Debroux static DEFINE_PCI_DEVICE_TABLE(i5000_pci_tbl) = {
1538eb60705aSEric Wollesen 	{PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
1539eb60705aSEric Wollesen 	 .driver_data = I5000P},
1540eb60705aSEric Wollesen 
1541eb60705aSEric Wollesen 	{0,}			/* 0 terminated list. */
1542eb60705aSEric Wollesen };
1543eb60705aSEric Wollesen 
1544eb60705aSEric Wollesen MODULE_DEVICE_TABLE(pci, i5000_pci_tbl);
1545eb60705aSEric Wollesen 
1546b2ccaecaSDouglas Thompson /*
1547eb60705aSEric Wollesen  *	i5000_driver	pci_driver structure for this module
1548eb60705aSEric Wollesen  *
1549eb60705aSEric Wollesen  */
1550eb60705aSEric Wollesen static struct pci_driver i5000_driver = {
155157510c2fSDarrick J. Wong 	.name = KBUILD_BASENAME,
1552eb60705aSEric Wollesen 	.probe = i5000_init_one,
1553eb60705aSEric Wollesen 	.remove = __devexit_p(i5000_remove_one),
1554eb60705aSEric Wollesen 	.id_table = i5000_pci_tbl,
1555eb60705aSEric Wollesen };
1556eb60705aSEric Wollesen 
1557b2ccaecaSDouglas Thompson /*
1558eb60705aSEric Wollesen  *	i5000_init		Module entry function
1559eb60705aSEric Wollesen  *			Try to initialize this module for its devices
1560eb60705aSEric Wollesen  */
1561eb60705aSEric Wollesen static int __init i5000_init(void)
1562eb60705aSEric Wollesen {
1563eb60705aSEric Wollesen 	int pci_rc;
1564eb60705aSEric Wollesen 
156563ae96beSJoe Perches 	debugf2("MC: %s: %s()\n", __FILE__, __func__);
1566eb60705aSEric Wollesen 
1567c3c52bceSHitoshi Mitake        /* Ensure that the OPSTATE is set correctly for POLL or NMI */
1568c3c52bceSHitoshi Mitake        opstate_init();
1569c3c52bceSHitoshi Mitake 
1570eb60705aSEric Wollesen 	pci_rc = pci_register_driver(&i5000_driver);
1571eb60705aSEric Wollesen 
1572eb60705aSEric Wollesen 	return (pci_rc < 0) ? pci_rc : 0;
1573eb60705aSEric Wollesen }
1574eb60705aSEric Wollesen 
1575b2ccaecaSDouglas Thompson /*
1576eb60705aSEric Wollesen  *	i5000_exit()	Module exit function
1577eb60705aSEric Wollesen  *			Unregister the driver
1578eb60705aSEric Wollesen  */
1579eb60705aSEric Wollesen static void __exit i5000_exit(void)
1580eb60705aSEric Wollesen {
158163ae96beSJoe Perches 	debugf2("MC: %s: %s()\n", __FILE__, __func__);
1582eb60705aSEric Wollesen 	pci_unregister_driver(&i5000_driver);
1583eb60705aSEric Wollesen }
1584eb60705aSEric Wollesen 
1585eb60705aSEric Wollesen module_init(i5000_init);
1586eb60705aSEric Wollesen module_exit(i5000_exit);
1587eb60705aSEric Wollesen 
1588eb60705aSEric Wollesen MODULE_LICENSE("GPL");
1589eb60705aSEric Wollesen MODULE_AUTHOR
1590eb60705aSEric Wollesen     ("Linux Networx (http://lnxi.com) Doug Thompson <norsk5@xmission.com>");
1591eb60705aSEric Wollesen MODULE_DESCRIPTION("MC Driver for Intel I5000 memory controllers - "
1592eb60705aSEric Wollesen 		I5000_REVISION);
1593c3c52bceSHitoshi Mitake 
1594c0d12172SDave Jiang module_param(edac_op_state, int, 0444);
1595c0d12172SDave Jiang MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
1596c0667407SAristeu Rozanski module_param(misc_messages, int, 0444);
1597c0667407SAristeu Rozanski MODULE_PARM_DESC(misc_messages, "Log miscellaneous non fatal messages");
1598c0667407SAristeu Rozanski 
1599