blob: 1c1aa7a23c3ca88cfe531349345fdc1daa7dce86 [file] [log] [blame]
Eric Wolleseneb607052007-07-19 01:49:39 -07001/*
2 * Intel 5000(P/V/X) class Memory Controllers kernel module
3 *
4 * This file may be distributed under the terms of the
5 * GNU General Public License.
6 *
7 * Written by Douglas Thompson Linux Networx (http://lnxi.com)
8 * norsk5@xmission.com
9 *
10 * This module is based on the following document:
11 *
12 * Intel 5000X Chipset Memory Controller Hub (MCH) - Datasheet
13 * http://developer.intel.com/design/chipsets/datashts/313070.htm
14 *
15 */
16
17#include <linux/module.h>
18#include <linux/init.h>
19#include <linux/pci.h>
20#include <linux/pci_ids.h>
21#include <linux/slab.h>
Dave Jiangc0d12172007-07-19 01:49:46 -070022#include <linux/edac.h>
Eric Wolleseneb607052007-07-19 01:49:39 -070023#include <asm/mmzone.h>
24
Douglas Thompson20bcb7a2007-07-19 01:49:47 -070025#include "edac_core.h"
Eric Wolleseneb607052007-07-19 01:49:39 -070026
27/*
28 * Alter this version for the I5000 module when modifications are made
29 */
Michal Marek152ba392011-04-01 12:41:20 +020030#define I5000_REVISION " Ver: 2.0.12"
Dave Jiang456a2f92007-07-19 01:50:10 -070031#define EDAC_MOD_STR "i5000_edac"
Eric Wolleseneb607052007-07-19 01:49:39 -070032
33#define i5000_printk(level, fmt, arg...) \
34 edac_printk(level, "i5000", fmt, ##arg)
35
36#define i5000_mc_printk(mci, level, fmt, arg...) \
37 edac_mc_chipset_printk(mci, level, "i5000", fmt, ##arg)
38
39#ifndef PCI_DEVICE_ID_INTEL_FBD_0
40#define PCI_DEVICE_ID_INTEL_FBD_0 0x25F5
41#endif
42#ifndef PCI_DEVICE_ID_INTEL_FBD_1
43#define PCI_DEVICE_ID_INTEL_FBD_1 0x25F6
44#endif
45
46/* Device 16,
47 * Function 0: System Address
48 * Function 1: Memory Branch Map, Control, Errors Register
49 * Function 2: FSB Error Registers
50 *
51 * All 3 functions of Device 16 (0,1,2) share the SAME DID
52 */
53#define PCI_DEVICE_ID_INTEL_I5000_DEV16 0x25F0
54
55/* OFFSETS for Function 0 */
56
57/* OFFSETS for Function 1 */
58#define AMBASE 0x48
59#define MAXCH 0x56
60#define MAXDIMMPERCH 0x57
61#define TOLM 0x6C
62#define REDMEMB 0x7C
63#define RED_ECC_LOCATOR(x) ((x) & 0x3FFFF)
64#define REC_ECC_LOCATOR_EVEN(x) ((x) & 0x001FF)
65#define REC_ECC_LOCATOR_ODD(x) ((x) & 0x3FE00)
66#define MIR0 0x80
67#define MIR1 0x84
68#define MIR2 0x88
69#define AMIR0 0x8C
70#define AMIR1 0x90
71#define AMIR2 0x94
72
73#define FERR_FAT_FBD 0x98
74#define NERR_FAT_FBD 0x9C
75#define EXTRACT_FBDCHAN_INDX(x) (((x)>>28) & 0x3)
76#define FERR_FAT_FBDCHAN 0x30000000
77#define FERR_FAT_M3ERR 0x00000004
78#define FERR_FAT_M2ERR 0x00000002
79#define FERR_FAT_M1ERR 0x00000001
Douglas Thompson052dfb42007-07-19 01:50:13 -070080#define FERR_FAT_MASK (FERR_FAT_M1ERR | \
Eric Wolleseneb607052007-07-19 01:49:39 -070081 FERR_FAT_M2ERR | \
82 FERR_FAT_M3ERR)
83
84#define FERR_NF_FBD 0xA0
85
86/* Thermal and SPD or BFD errors */
87#define FERR_NF_M28ERR 0x01000000
88#define FERR_NF_M27ERR 0x00800000
89#define FERR_NF_M26ERR 0x00400000
90#define FERR_NF_M25ERR 0x00200000
91#define FERR_NF_M24ERR 0x00100000
92#define FERR_NF_M23ERR 0x00080000
93#define FERR_NF_M22ERR 0x00040000
94#define FERR_NF_M21ERR 0x00020000
95
96/* Correctable errors */
97#define FERR_NF_M20ERR 0x00010000
98#define FERR_NF_M19ERR 0x00008000
99#define FERR_NF_M18ERR 0x00004000
100#define FERR_NF_M17ERR 0x00002000
101
102/* Non-Retry or redundant Retry errors */
103#define FERR_NF_M16ERR 0x00001000
104#define FERR_NF_M15ERR 0x00000800
105#define FERR_NF_M14ERR 0x00000400
106#define FERR_NF_M13ERR 0x00000200
107
108/* Uncorrectable errors */
109#define FERR_NF_M12ERR 0x00000100
110#define FERR_NF_M11ERR 0x00000080
111#define FERR_NF_M10ERR 0x00000040
112#define FERR_NF_M9ERR 0x00000020
113#define FERR_NF_M8ERR 0x00000010
114#define FERR_NF_M7ERR 0x00000008
115#define FERR_NF_M6ERR 0x00000004
116#define FERR_NF_M5ERR 0x00000002
117#define FERR_NF_M4ERR 0x00000001
118
119#define FERR_NF_UNCORRECTABLE (FERR_NF_M12ERR | \
120 FERR_NF_M11ERR | \
121 FERR_NF_M10ERR | \
Aristeu Rozanskic0667402008-10-15 22:04:31 -0700122 FERR_NF_M9ERR | \
Douglas Thompson052dfb42007-07-19 01:50:13 -0700123 FERR_NF_M8ERR | \
Eric Wolleseneb607052007-07-19 01:49:39 -0700124 FERR_NF_M7ERR | \
125 FERR_NF_M6ERR | \
126 FERR_NF_M5ERR | \
127 FERR_NF_M4ERR)
128#define FERR_NF_CORRECTABLE (FERR_NF_M20ERR | \
129 FERR_NF_M19ERR | \
130 FERR_NF_M18ERR | \
131 FERR_NF_M17ERR)
132#define FERR_NF_DIMM_SPARE (FERR_NF_M27ERR | \
133 FERR_NF_M28ERR)
134#define FERR_NF_THERMAL (FERR_NF_M26ERR | \
Douglas Thompson052dfb42007-07-19 01:50:13 -0700135 FERR_NF_M25ERR | \
Eric Wolleseneb607052007-07-19 01:49:39 -0700136 FERR_NF_M24ERR | \
137 FERR_NF_M23ERR)
138#define FERR_NF_SPD_PROTOCOL (FERR_NF_M22ERR)
139#define FERR_NF_NORTH_CRC (FERR_NF_M21ERR)
140#define FERR_NF_NON_RETRY (FERR_NF_M13ERR | \
141 FERR_NF_M14ERR | \
142 FERR_NF_M15ERR)
143
144#define NERR_NF_FBD 0xA4
145#define FERR_NF_MASK (FERR_NF_UNCORRECTABLE | \
146 FERR_NF_CORRECTABLE | \
147 FERR_NF_DIMM_SPARE | \
148 FERR_NF_THERMAL | \
149 FERR_NF_SPD_PROTOCOL | \
150 FERR_NF_NORTH_CRC | \
151 FERR_NF_NON_RETRY)
152
153#define EMASK_FBD 0xA8
154#define EMASK_FBD_M28ERR 0x08000000
155#define EMASK_FBD_M27ERR 0x04000000
156#define EMASK_FBD_M26ERR 0x02000000
157#define EMASK_FBD_M25ERR 0x01000000
158#define EMASK_FBD_M24ERR 0x00800000
159#define EMASK_FBD_M23ERR 0x00400000
160#define EMASK_FBD_M22ERR 0x00200000
161#define EMASK_FBD_M21ERR 0x00100000
162#define EMASK_FBD_M20ERR 0x00080000
163#define EMASK_FBD_M19ERR 0x00040000
164#define EMASK_FBD_M18ERR 0x00020000
165#define EMASK_FBD_M17ERR 0x00010000
166
167#define EMASK_FBD_M15ERR 0x00004000
168#define EMASK_FBD_M14ERR 0x00002000
169#define EMASK_FBD_M13ERR 0x00001000
170#define EMASK_FBD_M12ERR 0x00000800
171#define EMASK_FBD_M11ERR 0x00000400
172#define EMASK_FBD_M10ERR 0x00000200
173#define EMASK_FBD_M9ERR 0x00000100
174#define EMASK_FBD_M8ERR 0x00000080
175#define EMASK_FBD_M7ERR 0x00000040
176#define EMASK_FBD_M6ERR 0x00000020
177#define EMASK_FBD_M5ERR 0x00000010
178#define EMASK_FBD_M4ERR 0x00000008
179#define EMASK_FBD_M3ERR 0x00000004
180#define EMASK_FBD_M2ERR 0x00000002
181#define EMASK_FBD_M1ERR 0x00000001
182
183#define ENABLE_EMASK_FBD_FATAL_ERRORS (EMASK_FBD_M1ERR | \
184 EMASK_FBD_M2ERR | \
185 EMASK_FBD_M3ERR)
186
187#define ENABLE_EMASK_FBD_UNCORRECTABLE (EMASK_FBD_M4ERR | \
188 EMASK_FBD_M5ERR | \
189 EMASK_FBD_M6ERR | \
190 EMASK_FBD_M7ERR | \
191 EMASK_FBD_M8ERR | \
192 EMASK_FBD_M9ERR | \
193 EMASK_FBD_M10ERR | \
194 EMASK_FBD_M11ERR | \
195 EMASK_FBD_M12ERR)
196#define ENABLE_EMASK_FBD_CORRECTABLE (EMASK_FBD_M17ERR | \
197 EMASK_FBD_M18ERR | \
198 EMASK_FBD_M19ERR | \
199 EMASK_FBD_M20ERR)
200#define ENABLE_EMASK_FBD_DIMM_SPARE (EMASK_FBD_M27ERR | \
201 EMASK_FBD_M28ERR)
202#define ENABLE_EMASK_FBD_THERMALS (EMASK_FBD_M26ERR | \
203 EMASK_FBD_M25ERR | \
204 EMASK_FBD_M24ERR | \
205 EMASK_FBD_M23ERR)
206#define ENABLE_EMASK_FBD_SPD_PROTOCOL (EMASK_FBD_M22ERR)
207#define ENABLE_EMASK_FBD_NORTH_CRC (EMASK_FBD_M21ERR)
208#define ENABLE_EMASK_FBD_NON_RETRY (EMASK_FBD_M15ERR | \
209 EMASK_FBD_M14ERR | \
210 EMASK_FBD_M13ERR)
211
212#define ENABLE_EMASK_ALL (ENABLE_EMASK_FBD_NON_RETRY | \
213 ENABLE_EMASK_FBD_NORTH_CRC | \
214 ENABLE_EMASK_FBD_SPD_PROTOCOL | \
215 ENABLE_EMASK_FBD_THERMALS | \
216 ENABLE_EMASK_FBD_DIMM_SPARE | \
217 ENABLE_EMASK_FBD_FATAL_ERRORS | \
218 ENABLE_EMASK_FBD_CORRECTABLE | \
219 ENABLE_EMASK_FBD_UNCORRECTABLE)
220
221#define ERR0_FBD 0xAC
222#define ERR1_FBD 0xB0
223#define ERR2_FBD 0xB4
224#define MCERR_FBD 0xB8
225#define NRECMEMA 0xBE
226#define NREC_BANK(x) (((x)>>12) & 0x7)
227#define NREC_RDWR(x) (((x)>>11) & 1)
228#define NREC_RANK(x) (((x)>>8) & 0x7)
229#define NRECMEMB 0xC0
230#define NREC_CAS(x) (((x)>>16) & 0xFFFFFF)
231#define NREC_RAS(x) ((x) & 0x7FFF)
232#define NRECFGLOG 0xC4
233#define NREEECFBDA 0xC8
234#define NREEECFBDB 0xCC
235#define NREEECFBDC 0xD0
236#define NREEECFBDD 0xD4
237#define NREEECFBDE 0xD8
238#define REDMEMA 0xDC
239#define RECMEMA 0xE2
240#define REC_BANK(x) (((x)>>12) & 0x7)
241#define REC_RDWR(x) (((x)>>11) & 1)
242#define REC_RANK(x) (((x)>>8) & 0x7)
243#define RECMEMB 0xE4
244#define REC_CAS(x) (((x)>>16) & 0xFFFFFF)
245#define REC_RAS(x) ((x) & 0x7FFF)
246#define RECFGLOG 0xE8
247#define RECFBDA 0xEC
248#define RECFBDB 0xF0
249#define RECFBDC 0xF4
250#define RECFBDD 0xF8
251#define RECFBDE 0xFC
252
253/* OFFSETS for Function 2 */
254
255/*
256 * Device 21,
257 * Function 0: Memory Map Branch 0
258 *
259 * Device 22,
260 * Function 0: Memory Map Branch 1
261 */
262#define PCI_DEVICE_ID_I5000_BRANCH_0 0x25F5
263#define PCI_DEVICE_ID_I5000_BRANCH_1 0x25F6
264
265#define AMB_PRESENT_0 0x64
266#define AMB_PRESENT_1 0x66
267#define MTR0 0x80
268#define MTR1 0x84
269#define MTR2 0x88
270#define MTR3 0x8C
271
272#define NUM_MTRS 4
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -0300273#define CHANNELS_PER_BRANCH 2
274#define MAX_BRANCHES 2
Eric Wolleseneb607052007-07-19 01:49:39 -0700275
276/* Defines to extract the vaious fields from the
277 * MTRx - Memory Technology Registers
278 */
279#define MTR_DIMMS_PRESENT(mtr) ((mtr) & (0x1 << 8))
280#define MTR_DRAM_WIDTH(mtr) ((((mtr) >> 6) & 0x1) ? 8 : 4)
281#define MTR_DRAM_BANKS(mtr) ((((mtr) >> 5) & 0x1) ? 8 : 4)
282#define MTR_DRAM_BANKS_ADDR_BITS(mtr) ((MTR_DRAM_BANKS(mtr) == 8) ? 3 : 2)
283#define MTR_DIMM_RANK(mtr) (((mtr) >> 4) & 0x1)
Marisuz Kozlowski977c76b2007-07-19 01:50:18 -0700284#define MTR_DIMM_RANK_ADDR_BITS(mtr) (MTR_DIMM_RANK(mtr) ? 2 : 1)
Eric Wolleseneb607052007-07-19 01:49:39 -0700285#define MTR_DIMM_ROWS(mtr) (((mtr) >> 2) & 0x3)
286#define MTR_DIMM_ROWS_ADDR_BITS(mtr) (MTR_DIMM_ROWS(mtr) + 13)
287#define MTR_DIMM_COLS(mtr) ((mtr) & 0x3)
288#define MTR_DIMM_COLS_ADDR_BITS(mtr) (MTR_DIMM_COLS(mtr) + 10)
289
290#ifdef CONFIG_EDAC_DEBUG
291static char *numrow_toString[] = {
292 "8,192 - 13 rows",
293 "16,384 - 14 rows",
294 "32,768 - 15 rows",
295 "reserved"
296};
297
298static char *numcol_toString[] = {
299 "1,024 - 10 columns",
300 "2,048 - 11 columns",
301 "4,096 - 12 columns",
302 "reserved"
303};
304#endif
305
Aristeu Rozanskic0667402008-10-15 22:04:31 -0700306/* enables the report of miscellaneous messages as CE errors - default off */
307static int misc_messages;
308
Eric Wolleseneb607052007-07-19 01:49:39 -0700309/* Enumeration of supported devices */
310enum i5000_chips {
311 I5000P = 0,
312 I5000V = 1, /* future */
313 I5000X = 2 /* future */
314};
315
316/* Device name and register DID (Device ID) */
317struct i5000_dev_info {
318 const char *ctl_name; /* name for this device */
319 u16 fsb_mapping_errors; /* DID for the branchmap,control */
320};
321
322/* Table of devices attributes supported by this driver */
323static const struct i5000_dev_info i5000_devs[] = {
324 [I5000P] = {
Douglas Thompson052dfb42007-07-19 01:50:13 -0700325 .ctl_name = "I5000",
326 .fsb_mapping_errors = PCI_DEVICE_ID_INTEL_I5000_DEV16,
327 },
Eric Wolleseneb607052007-07-19 01:49:39 -0700328};
329
330struct i5000_dimm_info {
331 int megabytes; /* size, 0 means not present */
332 int dual_rank;
333};
334
335#define MAX_CHANNELS 6 /* max possible channels */
336#define MAX_CSROWS (8*2) /* max possible csrows per channel */
337
338/* driver private data structure */
339struct i5000_pvt {
340 struct pci_dev *system_address; /* 16.0 */
341 struct pci_dev *branchmap_werrors; /* 16.1 */
342 struct pci_dev *fsb_error_regs; /* 16.2 */
343 struct pci_dev *branch_0; /* 21.0 */
344 struct pci_dev *branch_1; /* 22.0 */
345
Eric Wolleseneb607052007-07-19 01:49:39 -0700346 u16 tolm; /* top of low memory */
347 u64 ambase; /* AMB BAR */
348
349 u16 mir0, mir1, mir2;
350
351 u16 b0_mtr[NUM_MTRS]; /* Memory Technlogy Reg */
352 u16 b0_ambpresent0; /* Branch 0, Channel 0 */
353 u16 b0_ambpresent1; /* Brnach 0, Channel 1 */
354
355 u16 b1_mtr[NUM_MTRS]; /* Memory Technlogy Reg */
356 u16 b1_ambpresent0; /* Branch 1, Channel 8 */
357 u16 b1_ambpresent1; /* Branch 1, Channel 1 */
358
Joe Perches6f042b52008-02-03 17:12:34 +0200359 /* DIMM information matrix, allocating architecture maximums */
Eric Wolleseneb607052007-07-19 01:49:39 -0700360 struct i5000_dimm_info dimm_info[MAX_CSROWS][MAX_CHANNELS];
361
362 /* Actual values for this controller */
363 int maxch; /* Max channels */
364 int maxdimmperch; /* Max DIMMs per channel */
365};
366
367/* I5000 MCH error information retrieved from Hardware */
368struct i5000_error_info {
369
370 /* These registers are always read from the MC */
371 u32 ferr_fat_fbd; /* First Errors Fatal */
372 u32 nerr_fat_fbd; /* Next Errors Fatal */
373 u32 ferr_nf_fbd; /* First Errors Non-Fatal */
374 u32 nerr_nf_fbd; /* Next Errors Non-Fatal */
375
376 /* These registers are input ONLY if there was a Recoverable Error */
377 u32 redmemb; /* Recoverable Mem Data Error log B */
378 u16 recmema; /* Recoverable Mem Error log A */
379 u32 recmemb; /* Recoverable Mem Error log B */
380
381 /* These registers are input ONLY if there was a
382 * Non-Recoverable Error */
383 u16 nrecmema; /* Non-Recoverable Mem log A */
384 u16 nrecmemb; /* Non-Recoverable Mem log B */
385
386};
387
Dave Jiang456a2f92007-07-19 01:50:10 -0700388static struct edac_pci_ctl_info *i5000_pci;
389
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -0700390/*
Eric Wolleseneb607052007-07-19 01:49:39 -0700391 * i5000_get_error_info Retrieve the hardware error information from
392 * the hardware and cache it in the 'info'
393 * structure
394 */
395static void i5000_get_error_info(struct mem_ctl_info *mci,
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -0700396 struct i5000_error_info *info)
Eric Wolleseneb607052007-07-19 01:49:39 -0700397{
398 struct i5000_pvt *pvt;
399 u32 value;
400
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -0700401 pvt = mci->pvt_info;
Eric Wolleseneb607052007-07-19 01:49:39 -0700402
403 /* read in the 1st FATAL error register */
404 pci_read_config_dword(pvt->branchmap_werrors, FERR_FAT_FBD, &value);
405
406 /* Mask only the bits that the doc says are valid
407 */
408 value &= (FERR_FAT_FBDCHAN | FERR_FAT_MASK);
409
410 /* If there is an error, then read in the */
411 /* NEXT FATAL error register and the Memory Error Log Register A */
412 if (value & FERR_FAT_MASK) {
413 info->ferr_fat_fbd = value;
414
415 /* harvest the various error data we need */
416 pci_read_config_dword(pvt->branchmap_werrors,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700417 NERR_FAT_FBD, &info->nerr_fat_fbd);
Eric Wolleseneb607052007-07-19 01:49:39 -0700418 pci_read_config_word(pvt->branchmap_werrors,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700419 NRECMEMA, &info->nrecmema);
Eric Wolleseneb607052007-07-19 01:49:39 -0700420 pci_read_config_word(pvt->branchmap_werrors,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700421 NRECMEMB, &info->nrecmemb);
Eric Wolleseneb607052007-07-19 01:49:39 -0700422
423 /* Clear the error bits, by writing them back */
424 pci_write_config_dword(pvt->branchmap_werrors,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700425 FERR_FAT_FBD, value);
Eric Wolleseneb607052007-07-19 01:49:39 -0700426 } else {
427 info->ferr_fat_fbd = 0;
428 info->nerr_fat_fbd = 0;
429 info->nrecmema = 0;
430 info->nrecmemb = 0;
431 }
432
433 /* read in the 1st NON-FATAL error register */
434 pci_read_config_dword(pvt->branchmap_werrors, FERR_NF_FBD, &value);
435
436 /* If there is an error, then read in the 1st NON-FATAL error
437 * register as well */
438 if (value & FERR_NF_MASK) {
439 info->ferr_nf_fbd = value;
440
441 /* harvest the various error data we need */
442 pci_read_config_dword(pvt->branchmap_werrors,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700443 NERR_NF_FBD, &info->nerr_nf_fbd);
Eric Wolleseneb607052007-07-19 01:49:39 -0700444 pci_read_config_word(pvt->branchmap_werrors,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700445 RECMEMA, &info->recmema);
Eric Wolleseneb607052007-07-19 01:49:39 -0700446 pci_read_config_dword(pvt->branchmap_werrors,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700447 RECMEMB, &info->recmemb);
Eric Wolleseneb607052007-07-19 01:49:39 -0700448 pci_read_config_dword(pvt->branchmap_werrors,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700449 REDMEMB, &info->redmemb);
Eric Wolleseneb607052007-07-19 01:49:39 -0700450
451 /* Clear the error bits, by writing them back */
452 pci_write_config_dword(pvt->branchmap_werrors,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700453 FERR_NF_FBD, value);
Eric Wolleseneb607052007-07-19 01:49:39 -0700454 } else {
455 info->ferr_nf_fbd = 0;
456 info->nerr_nf_fbd = 0;
457 info->recmema = 0;
458 info->recmemb = 0;
459 info->redmemb = 0;
460 }
461}
462
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -0700463/*
Eric Wolleseneb607052007-07-19 01:49:39 -0700464 * i5000_process_fatal_error_info(struct mem_ctl_info *mci,
465 * struct i5000_error_info *info,
466 * int handle_errors);
467 *
468 * handle the Intel FATAL errors, if any
469 */
470static void i5000_process_fatal_error_info(struct mem_ctl_info *mci,
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -0700471 struct i5000_error_info *info,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700472 int handle_errors)
Eric Wolleseneb607052007-07-19 01:49:39 -0700473{
Aristeu Rozanskic0667402008-10-15 22:04:31 -0700474 char msg[EDAC_MC_LABEL_LEN + 1 + 160];
475 char *specific = NULL;
Eric Wolleseneb607052007-07-19 01:49:39 -0700476 u32 allErrors;
477 int branch;
478 int channel;
479 int bank;
480 int rank;
481 int rdwr;
482 int ras, cas;
483
484 /* mask off the Error bits that are possible */
485 allErrors = (info->ferr_fat_fbd & FERR_FAT_MASK);
486 if (!allErrors)
487 return; /* if no error, return now */
488
Eric Wolleseneb607052007-07-19 01:49:39 -0700489 branch = EXTRACT_FBDCHAN_INDX(info->ferr_fat_fbd);
490 channel = branch;
491
492 /* Use the NON-Recoverable macros to extract data */
493 bank = NREC_BANK(info->nrecmema);
494 rank = NREC_RANK(info->nrecmema);
495 rdwr = NREC_RDWR(info->nrecmema);
496 ras = NREC_RAS(info->nrecmemb);
497 cas = NREC_CAS(info->nrecmemb);
498
499 debugf0("\t\tCSROW= %d Channels= %d,%d (Branch= %d "
500 "DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n",
501 rank, channel, channel + 1, branch >> 1, bank,
502 rdwr ? "Write" : "Read", ras, cas);
503
504 /* Only 1 bit will be on */
Aristeu Rozanskic0667402008-10-15 22:04:31 -0700505 switch (allErrors) {
506 case FERR_FAT_M1ERR:
507 specific = "Alert on non-redundant retry or fast "
508 "reset timeout";
509 break;
510 case FERR_FAT_M2ERR:
511 specific = "Northbound CRC error on non-redundant "
512 "retry";
513 break;
514 case FERR_FAT_M3ERR:
Aristeu Rozanski8360e812008-10-15 22:04:32 -0700515 {
516 static int done;
517
518 /*
519 * This error is generated to inform that the intelligent
520 * throttling is disabled and the temperature passed the
521 * specified middle point. Since this is something the BIOS
522 * should take care of, we'll warn only once to avoid
523 * worthlessly flooding the log.
524 */
525 if (done)
526 return;
527 done++;
528
Aristeu Rozanskic0667402008-10-15 22:04:31 -0700529 specific = ">Tmid Thermal event with intelligent "
Aristeu Rozanski8360e812008-10-15 22:04:32 -0700530 "throttling disabled";
531 }
Aristeu Rozanskic0667402008-10-15 22:04:31 -0700532 break;
Eric Wolleseneb607052007-07-19 01:49:39 -0700533 }
534
535 /* Form out message */
536 snprintf(msg, sizeof(msg),
Mauro Carvalho Chehab702df642012-04-16 15:09:46 -0300537 "Bank=%d RAS=%d CAS=%d FATAL Err=0x%x (%s)",
538 bank, ras, cas, allErrors, specific);
Eric Wolleseneb607052007-07-19 01:49:39 -0700539
540 /* Call the helper to output message */
Mauro Carvalho Chehab702df642012-04-16 15:09:46 -0300541 edac_mc_handle_error(HW_EVENT_ERR_FATAL, mci, 0, 0, 0,
542 branch >> 1, -1, rank,
543 rdwr ? "Write error" : "Read error",
544 msg, NULL);
Eric Wolleseneb607052007-07-19 01:49:39 -0700545}
546
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -0700547/*
Eric Wolleseneb607052007-07-19 01:49:39 -0700548 * i5000_process_fatal_error_info(struct mem_ctl_info *mci,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700549 * struct i5000_error_info *info,
550 * int handle_errors);
Eric Wolleseneb607052007-07-19 01:49:39 -0700551 *
552 * handle the Intel NON-FATAL errors, if any
553 */
554static void i5000_process_nonfatal_error_info(struct mem_ctl_info *mci,
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -0700555 struct i5000_error_info *info,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700556 int handle_errors)
Eric Wolleseneb607052007-07-19 01:49:39 -0700557{
Aristeu Rozanskic0667402008-10-15 22:04:31 -0700558 char msg[EDAC_MC_LABEL_LEN + 1 + 170];
559 char *specific = NULL;
Eric Wolleseneb607052007-07-19 01:49:39 -0700560 u32 allErrors;
561 u32 ue_errors;
562 u32 ce_errors;
563 u32 misc_errors;
564 int branch;
565 int channel;
566 int bank;
567 int rank;
568 int rdwr;
569 int ras, cas;
570
571 /* mask off the Error bits that are possible */
572 allErrors = (info->ferr_nf_fbd & FERR_NF_MASK);
573 if (!allErrors)
574 return; /* if no error, return now */
575
576 /* ONLY ONE of the possible error bits will be set, as per the docs */
Eric Wolleseneb607052007-07-19 01:49:39 -0700577 ue_errors = allErrors & FERR_NF_UNCORRECTABLE;
578 if (ue_errors) {
579 debugf0("\tUncorrected bits= 0x%x\n", ue_errors);
580
581 branch = EXTRACT_FBDCHAN_INDX(info->ferr_nf_fbd);
Tamas Vincze118f3e12010-01-15 17:01:10 -0800582
583 /*
584 * According with i5000 datasheet, bit 28 has no significance
585 * for errors M4Err-M12Err and M17Err-M21Err, on FERR_NF_FBD
586 */
587 channel = branch & 2;
588
Eric Wolleseneb607052007-07-19 01:49:39 -0700589 bank = NREC_BANK(info->nrecmema);
590 rank = NREC_RANK(info->nrecmema);
591 rdwr = NREC_RDWR(info->nrecmema);
592 ras = NREC_RAS(info->nrecmemb);
593 cas = NREC_CAS(info->nrecmemb);
594
595 debugf0
Douglas Thompson052dfb42007-07-19 01:50:13 -0700596 ("\t\tCSROW= %d Channels= %d,%d (Branch= %d "
597 "DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n",
598 rank, channel, channel + 1, branch >> 1, bank,
599 rdwr ? "Write" : "Read", ras, cas);
Eric Wolleseneb607052007-07-19 01:49:39 -0700600
Aristeu Rozanskic0667402008-10-15 22:04:31 -0700601 switch (ue_errors) {
602 case FERR_NF_M12ERR:
603 specific = "Non-Aliased Uncorrectable Patrol Data ECC";
604 break;
605 case FERR_NF_M11ERR:
606 specific = "Non-Aliased Uncorrectable Spare-Copy "
607 "Data ECC";
608 break;
609 case FERR_NF_M10ERR:
610 specific = "Non-Aliased Uncorrectable Mirrored Demand "
611 "Data ECC";
612 break;
613 case FERR_NF_M9ERR:
614 specific = "Non-Aliased Uncorrectable Non-Mirrored "
615 "Demand Data ECC";
616 break;
617 case FERR_NF_M8ERR:
618 specific = "Aliased Uncorrectable Patrol Data ECC";
619 break;
620 case FERR_NF_M7ERR:
621 specific = "Aliased Uncorrectable Spare-Copy Data ECC";
622 break;
623 case FERR_NF_M6ERR:
624 specific = "Aliased Uncorrectable Mirrored Demand "
625 "Data ECC";
626 break;
627 case FERR_NF_M5ERR:
628 specific = "Aliased Uncorrectable Non-Mirrored Demand "
629 "Data ECC";
630 break;
631 case FERR_NF_M4ERR:
632 specific = "Uncorrectable Data ECC on Replay";
633 break;
634 }
635
Eric Wolleseneb607052007-07-19 01:49:39 -0700636 /* Form out message */
637 snprintf(msg, sizeof(msg),
Mauro Carvalho Chehab702df642012-04-16 15:09:46 -0300638 "Rank=%d Bank=%d RAS=%d CAS=%d, UE Err=0x%x (%s)",
639 rank, bank, ras, cas, ue_errors, specific);
Eric Wolleseneb607052007-07-19 01:49:39 -0700640
641 /* Call the helper to output message */
Mauro Carvalho Chehab702df642012-04-16 15:09:46 -0300642 edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 0, 0, 0,
643 channel >> 1, -1, rank,
644 rdwr ? "Write error" : "Read error",
645 msg, NULL);
Eric Wolleseneb607052007-07-19 01:49:39 -0700646 }
647
648 /* Check correctable errors */
649 ce_errors = allErrors & FERR_NF_CORRECTABLE;
650 if (ce_errors) {
651 debugf0("\tCorrected bits= 0x%x\n", ce_errors);
652
653 branch = EXTRACT_FBDCHAN_INDX(info->ferr_nf_fbd);
654
655 channel = 0;
656 if (REC_ECC_LOCATOR_ODD(info->redmemb))
657 channel = 1;
658
659 /* Convert channel to be based from zero, instead of
660 * from branch base of 0 */
661 channel += branch;
662
663 bank = REC_BANK(info->recmema);
664 rank = REC_RANK(info->recmema);
665 rdwr = REC_RDWR(info->recmema);
666 ras = REC_RAS(info->recmemb);
667 cas = REC_CAS(info->recmemb);
668
669 debugf0("\t\tCSROW= %d Channel= %d (Branch %d "
670 "DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n",
671 rank, channel, branch >> 1, bank,
672 rdwr ? "Write" : "Read", ras, cas);
673
Aristeu Rozanskic0667402008-10-15 22:04:31 -0700674 switch (ce_errors) {
675 case FERR_NF_M17ERR:
676 specific = "Correctable Non-Mirrored Demand Data ECC";
677 break;
678 case FERR_NF_M18ERR:
679 specific = "Correctable Mirrored Demand Data ECC";
680 break;
681 case FERR_NF_M19ERR:
682 specific = "Correctable Spare-Copy Data ECC";
683 break;
684 case FERR_NF_M20ERR:
685 specific = "Correctable Patrol Data ECC";
686 break;
687 }
688
Eric Wolleseneb607052007-07-19 01:49:39 -0700689 /* Form out message */
690 snprintf(msg, sizeof(msg),
Mauro Carvalho Chehab702df642012-04-16 15:09:46 -0300691 "Rank=%d Bank=%d RDWR=%s RAS=%d "
Aristeu Rozanskic0667402008-10-15 22:04:31 -0700692 "CAS=%d, CE Err=0x%x (%s))", branch >> 1, bank,
693 rdwr ? "Write" : "Read", ras, cas, ce_errors,
694 specific);
Eric Wolleseneb607052007-07-19 01:49:39 -0700695
696 /* Call the helper to output message */
Mauro Carvalho Chehab702df642012-04-16 15:09:46 -0300697 edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 0, 0, 0,
698 channel >> 1, channel % 2, rank,
699 rdwr ? "Write error" : "Read error",
700 msg, NULL);
Eric Wolleseneb607052007-07-19 01:49:39 -0700701 }
702
Aristeu Rozanskic0667402008-10-15 22:04:31 -0700703 if (!misc_messages)
704 return;
Eric Wolleseneb607052007-07-19 01:49:39 -0700705
Aristeu Rozanskic0667402008-10-15 22:04:31 -0700706 misc_errors = allErrors & (FERR_NF_NON_RETRY | FERR_NF_NORTH_CRC |
707 FERR_NF_SPD_PROTOCOL | FERR_NF_DIMM_SPARE);
Eric Wolleseneb607052007-07-19 01:49:39 -0700708 if (misc_errors) {
Aristeu Rozanskic0667402008-10-15 22:04:31 -0700709 switch (misc_errors) {
710 case FERR_NF_M13ERR:
711 specific = "Non-Retry or Redundant Retry FBD Memory "
712 "Alert or Redundant Fast Reset Timeout";
713 break;
714 case FERR_NF_M14ERR:
715 specific = "Non-Retry or Redundant Retry FBD "
716 "Configuration Alert";
717 break;
718 case FERR_NF_M15ERR:
719 specific = "Non-Retry or Redundant Retry FBD "
720 "Northbound CRC error on read data";
721 break;
722 case FERR_NF_M21ERR:
723 specific = "FBD Northbound CRC error on "
724 "FBD Sync Status";
725 break;
726 case FERR_NF_M22ERR:
727 specific = "SPD protocol error";
728 break;
729 case FERR_NF_M27ERR:
730 specific = "DIMM-spare copy started";
731 break;
732 case FERR_NF_M28ERR:
733 specific = "DIMM-spare copy completed";
734 break;
735 }
736 branch = EXTRACT_FBDCHAN_INDX(info->ferr_nf_fbd);
Eric Wolleseneb607052007-07-19 01:49:39 -0700737
Aristeu Rozanskic0667402008-10-15 22:04:31 -0700738 /* Form out message */
739 snprintf(msg, sizeof(msg),
Mauro Carvalho Chehab702df642012-04-16 15:09:46 -0300740 "Err=%#x (%s)", misc_errors, specific);
Eric Wolleseneb607052007-07-19 01:49:39 -0700741
Aristeu Rozanskic0667402008-10-15 22:04:31 -0700742 /* Call the helper to output message */
Mauro Carvalho Chehab702df642012-04-16 15:09:46 -0300743 edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 0, 0, 0,
744 branch >> 1, -1, -1,
745 "Misc error", msg, NULL);
Eric Wolleseneb607052007-07-19 01:49:39 -0700746 }
747}
748
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -0700749/*
Eric Wolleseneb607052007-07-19 01:49:39 -0700750 * i5000_process_error_info Process the error info that is
751 * in the 'info' structure, previously retrieved from hardware
752 */
753static void i5000_process_error_info(struct mem_ctl_info *mci,
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -0700754 struct i5000_error_info *info,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700755 int handle_errors)
Eric Wolleseneb607052007-07-19 01:49:39 -0700756{
757 /* First handle any fatal errors that occurred */
758 i5000_process_fatal_error_info(mci, info, handle_errors);
759
760 /* now handle any non-fatal errors that occurred */
761 i5000_process_nonfatal_error_info(mci, info, handle_errors);
762}
763
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -0700764/*
Eric Wolleseneb607052007-07-19 01:49:39 -0700765 * i5000_clear_error Retrieve any error from the hardware
766 * but do NOT process that error.
767 * Used for 'clearing' out of previous errors
768 * Called by the Core module.
769 */
770static void i5000_clear_error(struct mem_ctl_info *mci)
771{
772 struct i5000_error_info info;
773
774 i5000_get_error_info(mci, &info);
775}
776
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -0700777/*
Eric Wolleseneb607052007-07-19 01:49:39 -0700778 * i5000_check_error Retrieve and process errors reported by the
779 * hardware. Called by the Core module.
780 */
781static void i5000_check_error(struct mem_ctl_info *mci)
782{
783 struct i5000_error_info info;
Joe Perches63ae96b2010-05-26 14:44:14 -0700784 debugf4("MC%d: %s: %s()\n", mci->mc_idx, __FILE__, __func__);
Eric Wolleseneb607052007-07-19 01:49:39 -0700785 i5000_get_error_info(mci, &info);
786 i5000_process_error_info(mci, &info, 1);
787}
788
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -0700789/*
Eric Wolleseneb607052007-07-19 01:49:39 -0700790 * i5000_get_devices Find and perform 'get' operation on the MCH's
791 * device/functions we want to reference for this driver
792 *
793 * Need to 'get' device 16 func 1 and func 2
794 */
795static int i5000_get_devices(struct mem_ctl_info *mci, int dev_idx)
796{
797 //const struct i5000_dev_info *i5000_dev = &i5000_devs[dev_idx];
798 struct i5000_pvt *pvt;
799 struct pci_dev *pdev;
800
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -0700801 pvt = mci->pvt_info;
Eric Wolleseneb607052007-07-19 01:49:39 -0700802
803 /* Attempt to 'get' the MCH register we want */
804 pdev = NULL;
805 while (1) {
806 pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700807 PCI_DEVICE_ID_INTEL_I5000_DEV16, pdev);
Eric Wolleseneb607052007-07-19 01:49:39 -0700808
809 /* End of list, leave */
810 if (pdev == NULL) {
811 i5000_printk(KERN_ERR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700812 "'system address,Process Bus' "
813 "device not found:"
814 "vendor 0x%x device 0x%x FUNC 1 "
815 "(broken BIOS?)\n",
816 PCI_VENDOR_ID_INTEL,
817 PCI_DEVICE_ID_INTEL_I5000_DEV16);
Eric Wolleseneb607052007-07-19 01:49:39 -0700818
819 return 1;
820 }
821
822 /* Scan for device 16 func 1 */
823 if (PCI_FUNC(pdev->devfn) == 1)
824 break;
825 }
826
827 pvt->branchmap_werrors = pdev;
828
829 /* Attempt to 'get' the MCH register we want */
830 pdev = NULL;
831 while (1) {
832 pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700833 PCI_DEVICE_ID_INTEL_I5000_DEV16, pdev);
Eric Wolleseneb607052007-07-19 01:49:39 -0700834
835 if (pdev == NULL) {
836 i5000_printk(KERN_ERR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700837 "MC: 'branchmap,control,errors' "
838 "device not found:"
839 "vendor 0x%x device 0x%x Func 2 "
840 "(broken BIOS?)\n",
841 PCI_VENDOR_ID_INTEL,
842 PCI_DEVICE_ID_INTEL_I5000_DEV16);
Eric Wolleseneb607052007-07-19 01:49:39 -0700843
844 pci_dev_put(pvt->branchmap_werrors);
845 return 1;
846 }
847
848 /* Scan for device 16 func 1 */
849 if (PCI_FUNC(pdev->devfn) == 2)
850 break;
851 }
852
853 pvt->fsb_error_regs = pdev;
854
855 debugf1("System Address, processor bus- PCI Bus ID: %s %x:%x\n",
856 pci_name(pvt->system_address),
857 pvt->system_address->vendor, pvt->system_address->device);
858 debugf1("Branchmap, control and errors - PCI Bus ID: %s %x:%x\n",
859 pci_name(pvt->branchmap_werrors),
860 pvt->branchmap_werrors->vendor, pvt->branchmap_werrors->device);
861 debugf1("FSB Error Regs - PCI Bus ID: %s %x:%x\n",
862 pci_name(pvt->fsb_error_regs),
863 pvt->fsb_error_regs->vendor, pvt->fsb_error_regs->device);
864
865 pdev = NULL;
866 pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700867 PCI_DEVICE_ID_I5000_BRANCH_0, pdev);
Eric Wolleseneb607052007-07-19 01:49:39 -0700868
869 if (pdev == NULL) {
870 i5000_printk(KERN_ERR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700871 "MC: 'BRANCH 0' device not found:"
872 "vendor 0x%x device 0x%x Func 0 (broken BIOS?)\n",
873 PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_I5000_BRANCH_0);
Eric Wolleseneb607052007-07-19 01:49:39 -0700874
875 pci_dev_put(pvt->branchmap_werrors);
876 pci_dev_put(pvt->fsb_error_regs);
877 return 1;
878 }
879
880 pvt->branch_0 = pdev;
881
882 /* If this device claims to have more than 2 channels then
883 * fetch Branch 1's information
884 */
885 if (pvt->maxch >= CHANNELS_PER_BRANCH) {
886 pdev = NULL;
887 pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700888 PCI_DEVICE_ID_I5000_BRANCH_1, pdev);
Eric Wolleseneb607052007-07-19 01:49:39 -0700889
890 if (pdev == NULL) {
891 i5000_printk(KERN_ERR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700892 "MC: 'BRANCH 1' device not found:"
893 "vendor 0x%x device 0x%x Func 0 "
894 "(broken BIOS?)\n",
895 PCI_VENDOR_ID_INTEL,
896 PCI_DEVICE_ID_I5000_BRANCH_1);
Eric Wolleseneb607052007-07-19 01:49:39 -0700897
898 pci_dev_put(pvt->branchmap_werrors);
899 pci_dev_put(pvt->fsb_error_regs);
900 pci_dev_put(pvt->branch_0);
901 return 1;
902 }
903
904 pvt->branch_1 = pdev;
905 }
906
907 return 0;
908}
909
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -0700910/*
Eric Wolleseneb607052007-07-19 01:49:39 -0700911 * i5000_put_devices 'put' all the devices that we have
912 * reserved via 'get'
913 */
914static void i5000_put_devices(struct mem_ctl_info *mci)
915{
916 struct i5000_pvt *pvt;
917
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -0700918 pvt = mci->pvt_info;
Eric Wolleseneb607052007-07-19 01:49:39 -0700919
920 pci_dev_put(pvt->branchmap_werrors); /* FUNC 1 */
921 pci_dev_put(pvt->fsb_error_regs); /* FUNC 2 */
922 pci_dev_put(pvt->branch_0); /* DEV 21 */
923
924 /* Only if more than 2 channels do we release the second branch */
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -0700925 if (pvt->maxch >= CHANNELS_PER_BRANCH)
Eric Wolleseneb607052007-07-19 01:49:39 -0700926 pci_dev_put(pvt->branch_1); /* DEV 22 */
Eric Wolleseneb607052007-07-19 01:49:39 -0700927}
928
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -0700929/*
Eric Wolleseneb607052007-07-19 01:49:39 -0700930 * determine_amb_resent
931 *
932 * the information is contained in NUM_MTRS different registers
933 * determineing which of the NUM_MTRS requires knowing
934 * which channel is in question
935 *
936 * 2 branches, each with 2 channels
937 * b0_ambpresent0 for channel '0'
938 * b0_ambpresent1 for channel '1'
939 * b1_ambpresent0 for channel '2'
940 * b1_ambpresent1 for channel '3'
941 */
942static int determine_amb_present_reg(struct i5000_pvt *pvt, int channel)
943{
944 int amb_present;
945
946 if (channel < CHANNELS_PER_BRANCH) {
947 if (channel & 0x1)
948 amb_present = pvt->b0_ambpresent1;
949 else
950 amb_present = pvt->b0_ambpresent0;
951 } else {
952 if (channel & 0x1)
953 amb_present = pvt->b1_ambpresent1;
954 else
955 amb_present = pvt->b1_ambpresent0;
956 }
957
958 return amb_present;
959}
960
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -0700961/*
Eric Wolleseneb607052007-07-19 01:49:39 -0700962 * determine_mtr(pvt, csrow, channel)
963 *
964 * return the proper MTR register as determine by the csrow and channel desired
965 */
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -0300966static int determine_mtr(struct i5000_pvt *pvt, int slot, int channel)
Eric Wolleseneb607052007-07-19 01:49:39 -0700967{
968 int mtr;
969
970 if (channel < CHANNELS_PER_BRANCH)
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -0300971 mtr = pvt->b0_mtr[slot];
Eric Wolleseneb607052007-07-19 01:49:39 -0700972 else
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -0300973 mtr = pvt->b1_mtr[slot];
Eric Wolleseneb607052007-07-19 01:49:39 -0700974
975 return mtr;
976}
977
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -0700978/*
Eric Wolleseneb607052007-07-19 01:49:39 -0700979 */
980static void decode_mtr(int slot_row, u16 mtr)
981{
982 int ans;
983
984 ans = MTR_DIMMS_PRESENT(mtr);
985
986 debugf2("\tMTR%d=0x%x: DIMMs are %s\n", slot_row, mtr,
987 ans ? "Present" : "NOT Present");
988 if (!ans)
989 return;
990
991 debugf2("\t\tWIDTH: x%d\n", MTR_DRAM_WIDTH(mtr));
992 debugf2("\t\tNUMBANK: %d bank(s)\n", MTR_DRAM_BANKS(mtr));
993 debugf2("\t\tNUMRANK: %s\n", MTR_DIMM_RANK(mtr) ? "double" : "single");
994 debugf2("\t\tNUMROW: %s\n", numrow_toString[MTR_DIMM_ROWS(mtr)]);
995 debugf2("\t\tNUMCOL: %s\n", numcol_toString[MTR_DIMM_COLS(mtr)]);
996}
997
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -0300998static void handle_channel(struct i5000_pvt *pvt, int slot, int channel,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700999 struct i5000_dimm_info *dinfo)
Eric Wolleseneb607052007-07-19 01:49:39 -07001000{
1001 int mtr;
1002 int amb_present_reg;
1003 int addrBits;
1004
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001005 mtr = determine_mtr(pvt, slot, channel);
Eric Wolleseneb607052007-07-19 01:49:39 -07001006 if (MTR_DIMMS_PRESENT(mtr)) {
1007 amb_present_reg = determine_amb_present_reg(pvt, channel);
1008
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001009 /* Determine if there is a DIMM present in this DIMM slot */
1010 if (amb_present_reg) {
Eric Wolleseneb607052007-07-19 01:49:39 -07001011 dinfo->dual_rank = MTR_DIMM_RANK(mtr);
1012
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001013 /* Start with the number of bits for a Bank
1014 * on the DRAM */
1015 addrBits = MTR_DRAM_BANKS_ADDR_BITS(mtr);
1016 /* Add the number of ROW bits */
1017 addrBits += MTR_DIMM_ROWS_ADDR_BITS(mtr);
1018 /* add the number of COLUMN bits */
1019 addrBits += MTR_DIMM_COLS_ADDR_BITS(mtr);
Eric Wolleseneb607052007-07-19 01:49:39 -07001020
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001021 addrBits += 6; /* add 64 bits per DIMM */
1022 addrBits -= 20; /* divide by 2^^20 */
1023 addrBits -= 3; /* 8 bits per bytes */
Eric Wolleseneb607052007-07-19 01:49:39 -07001024
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001025 dinfo->megabytes = 1 << addrBits;
Eric Wolleseneb607052007-07-19 01:49:39 -07001026 }
1027 }
1028}
1029
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -07001030/*
Eric Wolleseneb607052007-07-19 01:49:39 -07001031 * calculate_dimm_size
1032 *
1033 * also will output a DIMM matrix map, if debug is enabled, for viewing
1034 * how the DIMMs are populated
1035 */
1036static void calculate_dimm_size(struct i5000_pvt *pvt)
1037{
1038 struct i5000_dimm_info *dinfo;
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001039 int slot, channel, branch;
Eric Wolleseneb607052007-07-19 01:49:39 -07001040 char *p, *mem_buffer;
1041 int space, n;
Eric Wolleseneb607052007-07-19 01:49:39 -07001042
1043 /* ================= Generate some debug output ================= */
1044 space = PAGE_SIZE;
1045 mem_buffer = p = kmalloc(space, GFP_KERNEL);
1046 if (p == NULL) {
1047 i5000_printk(KERN_ERR, "MC: %s:%s() kmalloc() failed\n",
Douglas Thompson052dfb42007-07-19 01:50:13 -07001048 __FILE__, __func__);
Eric Wolleseneb607052007-07-19 01:49:39 -07001049 return;
1050 }
1051
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001052 /* Scan all the actual slots
Eric Wolleseneb607052007-07-19 01:49:39 -07001053 * and calculate the information for each DIMM
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001054 * Start with the highest slot first, to display it first
1055 * and work toward the 0th slot
Eric Wolleseneb607052007-07-19 01:49:39 -07001056 */
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001057 for (slot = pvt->maxdimmperch - 1; slot >= 0; slot--) {
Eric Wolleseneb607052007-07-19 01:49:39 -07001058
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001059 /* on an odd slot, first output a 'boundary' marker,
Eric Wolleseneb607052007-07-19 01:49:39 -07001060 * then reset the message buffer */
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001061 if (slot & 0x1) {
1062 n = snprintf(p, space, "--------------------------"
Douglas Thompson052dfb42007-07-19 01:50:13 -07001063 "--------------------------------");
Eric Wolleseneb607052007-07-19 01:49:39 -07001064 p += n;
1065 space -= n;
1066 debugf2("%s\n", mem_buffer);
1067 p = mem_buffer;
1068 space = PAGE_SIZE;
1069 }
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001070 n = snprintf(p, space, "slot %2d ", slot);
Eric Wolleseneb607052007-07-19 01:49:39 -07001071 p += n;
1072 space -= n;
1073
1074 for (channel = 0; channel < pvt->maxch; channel++) {
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001075 dinfo = &pvt->dimm_info[slot][channel];
1076 handle_channel(pvt, slot, channel, dinfo);
1077 if (dinfo->megabytes)
1078 n = snprintf(p, space, "%4d MB %dR| ",
1079 dinfo->megabytes, dinfo->dual_rank + 1);
1080 else
1081 n = snprintf(p, space, "%4d MB | ", 0);
Eric Wolleseneb607052007-07-19 01:49:39 -07001082 p += n;
1083 space -= n;
1084 }
Eric Wolleseneb607052007-07-19 01:49:39 -07001085 p += n;
1086 space -= n;
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001087 debugf2("%s\n", mem_buffer);
1088 p = mem_buffer;
1089 space = PAGE_SIZE;
Eric Wolleseneb607052007-07-19 01:49:39 -07001090 }
1091
1092 /* Output the last bottom 'boundary' marker */
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001093 n = snprintf(p, space, "--------------------------"
1094 "--------------------------------");
Eric Wolleseneb607052007-07-19 01:49:39 -07001095 p += n;
1096 space -= n;
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001097 debugf2("%s\n", mem_buffer);
1098 p = mem_buffer;
1099 space = PAGE_SIZE;
Eric Wolleseneb607052007-07-19 01:49:39 -07001100
1101 /* now output the 'channel' labels */
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001102 n = snprintf(p, space, " ");
Eric Wolleseneb607052007-07-19 01:49:39 -07001103 p += n;
1104 space -= n;
1105 for (channel = 0; channel < pvt->maxch; channel++) {
1106 n = snprintf(p, space, "channel %d | ", channel);
1107 p += n;
1108 space -= n;
1109 }
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001110 debugf2("%s\n", mem_buffer);
1111 p = mem_buffer;
1112 space = PAGE_SIZE;
1113
1114 n = snprintf(p, space, " ");
Eric Wolleseneb607052007-07-19 01:49:39 -07001115 p += n;
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001116 for (branch = 0; branch < MAX_BRANCHES; branch++) {
1117 n = snprintf(p, space, " branch %d | ", branch);
1118 p += n;
1119 space -= n;
1120 }
Eric Wolleseneb607052007-07-19 01:49:39 -07001121
1122 /* output the last message and free buffer */
1123 debugf2("%s\n", mem_buffer);
1124 kfree(mem_buffer);
1125}
1126
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -07001127/*
Eric Wolleseneb607052007-07-19 01:49:39 -07001128 * i5000_get_mc_regs read in the necessary registers and
1129 * cache locally
1130 *
1131 * Fills in the private data members
1132 */
1133static void i5000_get_mc_regs(struct mem_ctl_info *mci)
1134{
1135 struct i5000_pvt *pvt;
1136 u32 actual_tolm;
1137 u16 limit;
1138 int slot_row;
1139 int maxch;
1140 int maxdimmperch;
1141 int way0, way1;
1142
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -07001143 pvt = mci->pvt_info;
Eric Wolleseneb607052007-07-19 01:49:39 -07001144
1145 pci_read_config_dword(pvt->system_address, AMBASE,
Douglas Thompson052dfb42007-07-19 01:50:13 -07001146 (u32 *) & pvt->ambase);
Eric Wolleseneb607052007-07-19 01:49:39 -07001147 pci_read_config_dword(pvt->system_address, AMBASE + sizeof(u32),
Douglas Thompson052dfb42007-07-19 01:50:13 -07001148 ((u32 *) & pvt->ambase) + sizeof(u32));
Eric Wolleseneb607052007-07-19 01:49:39 -07001149
1150 maxdimmperch = pvt->maxdimmperch;
1151 maxch = pvt->maxch;
1152
1153 debugf2("AMBASE= 0x%lx MAXCH= %d MAX-DIMM-Per-CH= %d\n",
1154 (long unsigned int)pvt->ambase, pvt->maxch, pvt->maxdimmperch);
1155
1156 /* Get the Branch Map regs */
1157 pci_read_config_word(pvt->branchmap_werrors, TOLM, &pvt->tolm);
1158 pvt->tolm >>= 12;
1159 debugf2("\nTOLM (number of 256M regions) =%u (0x%x)\n", pvt->tolm,
1160 pvt->tolm);
1161
1162 actual_tolm = pvt->tolm << 28;
1163 debugf2("Actual TOLM byte addr=%u (0x%x)\n", actual_tolm, actual_tolm);
1164
1165 pci_read_config_word(pvt->branchmap_werrors, MIR0, &pvt->mir0);
1166 pci_read_config_word(pvt->branchmap_werrors, MIR1, &pvt->mir1);
1167 pci_read_config_word(pvt->branchmap_werrors, MIR2, &pvt->mir2);
1168
1169 /* Get the MIR[0-2] regs */
1170 limit = (pvt->mir0 >> 4) & 0x0FFF;
1171 way0 = pvt->mir0 & 0x1;
1172 way1 = pvt->mir0 & 0x2;
1173 debugf2("MIR0: limit= 0x%x WAY1= %u WAY0= %x\n", limit, way1, way0);
1174 limit = (pvt->mir1 >> 4) & 0x0FFF;
1175 way0 = pvt->mir1 & 0x1;
1176 way1 = pvt->mir1 & 0x2;
1177 debugf2("MIR1: limit= 0x%x WAY1= %u WAY0= %x\n", limit, way1, way0);
1178 limit = (pvt->mir2 >> 4) & 0x0FFF;
1179 way0 = pvt->mir2 & 0x1;
1180 way1 = pvt->mir2 & 0x2;
1181 debugf2("MIR2: limit= 0x%x WAY1= %u WAY0= %x\n", limit, way1, way0);
1182
1183 /* Get the MTR[0-3] regs */
1184 for (slot_row = 0; slot_row < NUM_MTRS; slot_row++) {
1185 int where = MTR0 + (slot_row * sizeof(u32));
1186
1187 pci_read_config_word(pvt->branch_0, where,
Douglas Thompson052dfb42007-07-19 01:50:13 -07001188 &pvt->b0_mtr[slot_row]);
Eric Wolleseneb607052007-07-19 01:49:39 -07001189
1190 debugf2("MTR%d where=0x%x B0 value=0x%x\n", slot_row, where,
1191 pvt->b0_mtr[slot_row]);
1192
1193 if (pvt->maxch >= CHANNELS_PER_BRANCH) {
1194 pci_read_config_word(pvt->branch_1, where,
Douglas Thompson052dfb42007-07-19 01:50:13 -07001195 &pvt->b1_mtr[slot_row]);
Eric Wolleseneb607052007-07-19 01:49:39 -07001196 debugf2("MTR%d where=0x%x B1 value=0x%x\n", slot_row,
Keith Manntheyc2494ac2009-10-26 16:50:11 -07001197 where, pvt->b1_mtr[slot_row]);
Eric Wolleseneb607052007-07-19 01:49:39 -07001198 } else {
1199 pvt->b1_mtr[slot_row] = 0;
1200 }
1201 }
1202
1203 /* Read and dump branch 0's MTRs */
1204 debugf2("\nMemory Technology Registers:\n");
1205 debugf2(" Branch 0:\n");
1206 for (slot_row = 0; slot_row < NUM_MTRS; slot_row++) {
1207 decode_mtr(slot_row, pvt->b0_mtr[slot_row]);
1208 }
1209 pci_read_config_word(pvt->branch_0, AMB_PRESENT_0,
Douglas Thompson052dfb42007-07-19 01:50:13 -07001210 &pvt->b0_ambpresent0);
Eric Wolleseneb607052007-07-19 01:49:39 -07001211 debugf2("\t\tAMB-Branch 0-present0 0x%x:\n", pvt->b0_ambpresent0);
1212 pci_read_config_word(pvt->branch_0, AMB_PRESENT_1,
Douglas Thompson052dfb42007-07-19 01:50:13 -07001213 &pvt->b0_ambpresent1);
Eric Wolleseneb607052007-07-19 01:49:39 -07001214 debugf2("\t\tAMB-Branch 0-present1 0x%x:\n", pvt->b0_ambpresent1);
1215
1216 /* Only if we have 2 branchs (4 channels) */
1217 if (pvt->maxch < CHANNELS_PER_BRANCH) {
1218 pvt->b1_ambpresent0 = 0;
1219 pvt->b1_ambpresent1 = 0;
1220 } else {
1221 /* Read and dump branch 1's MTRs */
1222 debugf2(" Branch 1:\n");
1223 for (slot_row = 0; slot_row < NUM_MTRS; slot_row++) {
1224 decode_mtr(slot_row, pvt->b1_mtr[slot_row]);
1225 }
1226 pci_read_config_word(pvt->branch_1, AMB_PRESENT_0,
Douglas Thompson052dfb42007-07-19 01:50:13 -07001227 &pvt->b1_ambpresent0);
Eric Wolleseneb607052007-07-19 01:49:39 -07001228 debugf2("\t\tAMB-Branch 1-present0 0x%x:\n",
1229 pvt->b1_ambpresent0);
1230 pci_read_config_word(pvt->branch_1, AMB_PRESENT_1,
Douglas Thompson052dfb42007-07-19 01:50:13 -07001231 &pvt->b1_ambpresent1);
Eric Wolleseneb607052007-07-19 01:49:39 -07001232 debugf2("\t\tAMB-Branch 1-present1 0x%x:\n",
1233 pvt->b1_ambpresent1);
1234 }
1235
1236 /* Go and determine the size of each DIMM and place in an
1237 * orderly matrix */
1238 calculate_dimm_size(pvt);
1239}
1240
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -07001241/*
Eric Wolleseneb607052007-07-19 01:49:39 -07001242 * i5000_init_csrows Initialize the 'csrows' table within
1243 * the mci control structure with the
1244 * addressing of memory.
1245 *
1246 * return:
1247 * 0 success
1248 * 1 no actual memory found on this MC
1249 */
1250static int i5000_init_csrows(struct mem_ctl_info *mci)
1251{
1252 struct i5000_pvt *pvt;
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -03001253 struct dimm_info *dimm;
Eric Wolleseneb607052007-07-19 01:49:39 -07001254 int empty, channel_count;
1255 int max_csrows;
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001256 int mtr;
Eric Wolleseneb607052007-07-19 01:49:39 -07001257 int csrow_megs;
1258 int channel;
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001259 int slot;
Eric Wolleseneb607052007-07-19 01:49:39 -07001260
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -07001261 pvt = mci->pvt_info;
Eric Wolleseneb607052007-07-19 01:49:39 -07001262
1263 channel_count = pvt->maxch;
1264 max_csrows = pvt->maxdimmperch * 2;
1265
1266 empty = 1; /* Assume NO memory */
1267
Mauro Carvalho Chehab702df642012-04-16 15:09:46 -03001268 /*
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001269 * FIXME: The memory layout used to map slot/channel into the
1270 * real memory architecture is weird: branch+slot are "csrows"
1271 * and channel is channel. That required an extra array (dimm_info)
1272 * to map the dimms. A good cleanup would be to remove this array,
1273 * and do a loop here with branch, channel, slot
Mauro Carvalho Chehab702df642012-04-16 15:09:46 -03001274 */
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001275 for (slot = 0; slot < max_csrows; slot++) {
Eric Wolleseneb607052007-07-19 01:49:39 -07001276 for (channel = 0; channel < pvt->maxch; channel++) {
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001277
1278 mtr = determine_mtr(pvt, slot, channel);
1279
1280 if (!MTR_DIMMS_PRESENT(mtr))
1281 continue;
1282
1283 dimm = EDAC_DIMM_PTR(mci->layers, mci->dimms, mci->n_layers,
1284 channel / MAX_BRANCHES,
1285 channel % MAX_BRANCHES, slot);
1286
1287 csrow_megs = pvt->dimm_info[slot][channel].megabytes;
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -03001288 dimm->grain = 8;
Mauro Carvalho Chehab084a4fc2012-01-27 18:38:08 -03001289
1290 /* Assume DDR2 for now */
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -03001291 dimm->mtype = MEM_FB_DDR2;
Mauro Carvalho Chehab084a4fc2012-01-27 18:38:08 -03001292
1293 /* ask what device type on this row */
1294 if (MTR_DRAM_WIDTH(mtr))
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -03001295 dimm->dtype = DEV_X8;
Mauro Carvalho Chehab084a4fc2012-01-27 18:38:08 -03001296 else
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -03001297 dimm->dtype = DEV_X4;
Mauro Carvalho Chehab084a4fc2012-01-27 18:38:08 -03001298
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -03001299 dimm->edac_mode = EDAC_S8ECD8ED;
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001300 dimm->nr_pages = csrow_megs << 8;
Eric Wolleseneb607052007-07-19 01:49:39 -07001301 }
Eric Wolleseneb607052007-07-19 01:49:39 -07001302
Eric Wolleseneb607052007-07-19 01:49:39 -07001303 empty = 0;
1304 }
1305
1306 return empty;
1307}
1308
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -07001309/*
Eric Wolleseneb607052007-07-19 01:49:39 -07001310 * i5000_enable_error_reporting
1311 * Turn on the memory reporting features of the hardware
1312 */
1313static void i5000_enable_error_reporting(struct mem_ctl_info *mci)
1314{
1315 struct i5000_pvt *pvt;
1316 u32 fbd_error_mask;
1317
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -07001318 pvt = mci->pvt_info;
Eric Wolleseneb607052007-07-19 01:49:39 -07001319
1320 /* Read the FBD Error Mask Register */
1321 pci_read_config_dword(pvt->branchmap_werrors, EMASK_FBD,
Douglas Thompson052dfb42007-07-19 01:50:13 -07001322 &fbd_error_mask);
Eric Wolleseneb607052007-07-19 01:49:39 -07001323
1324 /* Enable with a '0' */
1325 fbd_error_mask &= ~(ENABLE_EMASK_ALL);
1326
1327 pci_write_config_dword(pvt->branchmap_werrors, EMASK_FBD,
Douglas Thompson052dfb42007-07-19 01:50:13 -07001328 fbd_error_mask);
Eric Wolleseneb607052007-07-19 01:49:39 -07001329}
1330
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -07001331/*
Mauro Carvalho Chehab702df642012-04-16 15:09:46 -03001332 * i5000_get_dimm_and_channel_counts(pdev, &nr_csrows, &num_channels)
Eric Wolleseneb607052007-07-19 01:49:39 -07001333 *
1334 * ask the device how many channels are present and how many CSROWS
1335 * as well
1336 */
1337static void i5000_get_dimm_and_channel_counts(struct pci_dev *pdev,
Douglas Thompson052dfb42007-07-19 01:50:13 -07001338 int *num_dimms_per_channel,
1339 int *num_channels)
Eric Wolleseneb607052007-07-19 01:49:39 -07001340{
1341 u8 value;
1342
1343 /* Need to retrieve just how many channels and dimms per channel are
1344 * supported on this memory controller
1345 */
1346 pci_read_config_byte(pdev, MAXDIMMPERCH, &value);
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001347 *num_dimms_per_channel = (int)value;
Eric Wolleseneb607052007-07-19 01:49:39 -07001348
1349 pci_read_config_byte(pdev, MAXCH, &value);
1350 *num_channels = (int)value;
1351}
1352
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -07001353/*
Eric Wolleseneb607052007-07-19 01:49:39 -07001354 * i5000_probe1 Probe for ONE instance of device to see if it is
1355 * present.
1356 * return:
1357 * 0 for FOUND a device
1358 * < 0 for error code
1359 */
1360static int i5000_probe1(struct pci_dev *pdev, int dev_idx)
1361{
1362 struct mem_ctl_info *mci;
Mauro Carvalho Chehab702df642012-04-16 15:09:46 -03001363 struct edac_mc_layer layers[3];
Eric Wolleseneb607052007-07-19 01:49:39 -07001364 struct i5000_pvt *pvt;
1365 int num_channels;
1366 int num_dimms_per_channel;
Eric Wolleseneb607052007-07-19 01:49:39 -07001367
Joe Perches63ae96b2010-05-26 14:44:14 -07001368 debugf0("MC: %s: %s(), pdev bus %u dev=0x%x fn=0x%x\n",
1369 __FILE__, __func__,
Eric Wolleseneb607052007-07-19 01:49:39 -07001370 pdev->bus->number,
1371 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
1372
1373 /* We only are looking for func 0 of the set */
1374 if (PCI_FUNC(pdev->devfn) != 0)
1375 return -ENODEV;
1376
1377 /* Ask the devices for the number of CSROWS and CHANNELS so
1378 * that we can calculate the memory resources, etc
1379 *
1380 * The Chipset will report what it can handle which will be greater
1381 * or equal to what the motherboard manufacturer will implement.
1382 *
1383 * As we don't have a motherboard identification routine to determine
1384 * actual number of slots/dimms per channel, we thus utilize the
1385 * resource as specified by the chipset. Thus, we might have
1386 * have more DIMMs per channel than actually on the mobo, but this
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001387 * allows the driver to support up to the chipset max, without
Eric Wolleseneb607052007-07-19 01:49:39 -07001388 * some fancy mobo determination.
1389 */
1390 i5000_get_dimm_and_channel_counts(pdev, &num_dimms_per_channel,
Douglas Thompson052dfb42007-07-19 01:50:13 -07001391 &num_channels);
Eric Wolleseneb607052007-07-19 01:49:39 -07001392
Mauro Carvalho Chehab702df642012-04-16 15:09:46 -03001393 debugf0("MC: %s(): Number of Branches=2 Channels= %d DIMMS= %d\n",
1394 __func__, num_channels, num_dimms_per_channel);
Eric Wolleseneb607052007-07-19 01:49:39 -07001395
1396 /* allocate a new MC control structure */
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001397
Mauro Carvalho Chehab702df642012-04-16 15:09:46 -03001398 layers[0].type = EDAC_MC_LAYER_BRANCH;
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001399 layers[0].size = MAX_BRANCHES;
1400 layers[0].is_virt_csrow = false;
Mauro Carvalho Chehab702df642012-04-16 15:09:46 -03001401 layers[1].type = EDAC_MC_LAYER_CHANNEL;
Mauro Carvalho Chehab64e1fda2012-02-24 09:34:54 -03001402 layers[1].size = num_channels / MAX_BRANCHES;
Mauro Carvalho Chehab702df642012-04-16 15:09:46 -03001403 layers[1].is_virt_csrow = false;
1404 layers[2].type = EDAC_MC_LAYER_SLOT;
1405 layers[2].size = num_dimms_per_channel;
1406 layers[2].is_virt_csrow = true;
Mauro Carvalho Chehabca0907b2012-05-02 14:37:00 -03001407 mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, sizeof(*pvt));
Eric Wolleseneb607052007-07-19 01:49:39 -07001408 if (mci == NULL)
1409 return -ENOMEM;
1410
Darrick J. Wongf0f7e0d2008-11-12 13:25:36 -08001411 kobject_get(&mci->edac_mci_kobj);
Joe Perches63ae96b2010-05-26 14:44:14 -07001412 debugf0("MC: %s: %s(): mci = %p\n", __FILE__, __func__, mci);
Eric Wolleseneb607052007-07-19 01:49:39 -07001413
1414 mci->dev = &pdev->dev; /* record ptr to the generic device */
1415
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -07001416 pvt = mci->pvt_info;
Eric Wolleseneb607052007-07-19 01:49:39 -07001417 pvt->system_address = pdev; /* Record this device in our private */
1418 pvt->maxch = num_channels;
1419 pvt->maxdimmperch = num_dimms_per_channel;
1420
1421 /* 'get' the pci devices we want to reserve for our use */
1422 if (i5000_get_devices(mci, dev_idx))
1423 goto fail0;
1424
1425 /* Time to get serious */
1426 i5000_get_mc_regs(mci); /* retrieve the hardware registers */
1427
1428 mci->mc_idx = 0;
1429 mci->mtype_cap = MEM_FLAG_FB_DDR2;
1430 mci->edac_ctl_cap = EDAC_FLAG_NONE;
1431 mci->edac_cap = EDAC_FLAG_NONE;
1432 mci->mod_name = "i5000_edac.c";
1433 mci->mod_ver = I5000_REVISION;
1434 mci->ctl_name = i5000_devs[dev_idx].ctl_name;
Dave Jiangc4192702007-07-19 01:49:47 -07001435 mci->dev_name = pci_name(pdev);
Eric Wolleseneb607052007-07-19 01:49:39 -07001436 mci->ctl_page_to_phys = NULL;
1437
1438 /* Set the function pointer to an actual operation function */
1439 mci->edac_check = i5000_check_error;
1440
1441 /* initialize the MC control structure 'csrows' table
1442 * with the mapping and control information */
1443 if (i5000_init_csrows(mci)) {
1444 debugf0("MC: Setting mci->edac_cap to EDAC_FLAG_NONE\n"
1445 " because i5000_init_csrows() returned nonzero "
1446 "value\n");
1447 mci->edac_cap = EDAC_FLAG_NONE; /* no csrows found */
1448 } else {
1449 debugf1("MC: Enable error reporting now\n");
1450 i5000_enable_error_reporting(mci);
1451 }
1452
1453 /* add this new MC control structure to EDAC's list of MCs */
Doug Thompsonb8f6f972007-07-19 01:50:26 -07001454 if (edac_mc_add_mc(mci)) {
Joe Perches63ae96b2010-05-26 14:44:14 -07001455 debugf0("MC: %s: %s(): failed edac_mc_add_mc()\n",
1456 __FILE__, __func__);
Eric Wolleseneb607052007-07-19 01:49:39 -07001457 /* FIXME: perhaps some code should go here that disables error
1458 * reporting if we just enabled it
1459 */
1460 goto fail1;
1461 }
1462
1463 i5000_clear_error(mci);
1464
Dave Jiang456a2f92007-07-19 01:50:10 -07001465 /* allocating generic PCI control info */
1466 i5000_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
1467 if (!i5000_pci) {
1468 printk(KERN_WARNING
1469 "%s(): Unable to create PCI control\n",
1470 __func__);
1471 printk(KERN_WARNING
1472 "%s(): PCI error report via EDAC not setup\n",
1473 __func__);
1474 }
1475
Eric Wolleseneb607052007-07-19 01:49:39 -07001476 return 0;
1477
1478 /* Error exit unwinding stack */
Douglas Thompson052dfb42007-07-19 01:50:13 -07001479fail1:
Eric Wolleseneb607052007-07-19 01:49:39 -07001480
1481 i5000_put_devices(mci);
1482
Douglas Thompson052dfb42007-07-19 01:50:13 -07001483fail0:
Darrick J. Wongf0f7e0d2008-11-12 13:25:36 -08001484 kobject_put(&mci->edac_mci_kobj);
Eric Wolleseneb607052007-07-19 01:49:39 -07001485 edac_mc_free(mci);
1486 return -ENODEV;
1487}
1488
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -07001489/*
Eric Wolleseneb607052007-07-19 01:49:39 -07001490 * i5000_init_one constructor for one instance of device
1491 *
1492 * returns:
1493 * negative on error
1494 * count (>= 0)
1495 */
1496static int __devinit i5000_init_one(struct pci_dev *pdev,
Douglas Thompson052dfb42007-07-19 01:50:13 -07001497 const struct pci_device_id *id)
Eric Wolleseneb607052007-07-19 01:49:39 -07001498{
1499 int rc;
1500
Joe Perches63ae96b2010-05-26 14:44:14 -07001501 debugf0("MC: %s: %s()\n", __FILE__, __func__);
Eric Wolleseneb607052007-07-19 01:49:39 -07001502
1503 /* wake up device */
1504 rc = pci_enable_device(pdev);
Kulikov Vasiliy44aa80f2010-08-10 18:03:19 -07001505 if (rc)
Eric Wolleseneb607052007-07-19 01:49:39 -07001506 return rc;
1507
1508 /* now probe and enable the device */
1509 return i5000_probe1(pdev, id->driver_data);
1510}
1511
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -07001512/*
Eric Wolleseneb607052007-07-19 01:49:39 -07001513 * i5000_remove_one destructor for one instance of device
1514 *
1515 */
1516static void __devexit i5000_remove_one(struct pci_dev *pdev)
1517{
1518 struct mem_ctl_info *mci;
1519
Joe Perches63ae96b2010-05-26 14:44:14 -07001520 debugf0("%s: %s()\n", __FILE__, __func__);
Eric Wolleseneb607052007-07-19 01:49:39 -07001521
Dave Jiang456a2f92007-07-19 01:50:10 -07001522 if (i5000_pci)
1523 edac_pci_release_generic_ctl(i5000_pci);
1524
Eric Wolleseneb607052007-07-19 01:49:39 -07001525 if ((mci = edac_mc_del_mc(&pdev->dev)) == NULL)
1526 return;
1527
1528 /* retrieve references to resources, and free those resources */
1529 i5000_put_devices(mci);
Darrick J. Wongf0f7e0d2008-11-12 13:25:36 -08001530 kobject_put(&mci->edac_mci_kobj);
Eric Wolleseneb607052007-07-19 01:49:39 -07001531 edac_mc_free(mci);
1532}
1533
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -07001534/*
Eric Wolleseneb607052007-07-19 01:49:39 -07001535 * pci_device_id table for which devices we are looking for
1536 *
1537 * The "E500P" device is the first device supported.
1538 */
Lionel Debroux36c46f32012-02-27 07:41:47 +01001539static DEFINE_PCI_DEVICE_TABLE(i5000_pci_tbl) = {
Eric Wolleseneb607052007-07-19 01:49:39 -07001540 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
1541 .driver_data = I5000P},
1542
1543 {0,} /* 0 terminated list. */
1544};
1545
1546MODULE_DEVICE_TABLE(pci, i5000_pci_tbl);
1547
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -07001548/*
Eric Wolleseneb607052007-07-19 01:49:39 -07001549 * i5000_driver pci_driver structure for this module
1550 *
1551 */
1552static struct pci_driver i5000_driver = {
Darrick J. Wong57510c22007-11-14 16:59:58 -08001553 .name = KBUILD_BASENAME,
Eric Wolleseneb607052007-07-19 01:49:39 -07001554 .probe = i5000_init_one,
1555 .remove = __devexit_p(i5000_remove_one),
1556 .id_table = i5000_pci_tbl,
1557};
1558
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -07001559/*
Eric Wolleseneb607052007-07-19 01:49:39 -07001560 * i5000_init Module entry function
1561 * Try to initialize this module for its devices
1562 */
1563static int __init i5000_init(void)
1564{
1565 int pci_rc;
1566
Joe Perches63ae96b2010-05-26 14:44:14 -07001567 debugf2("MC: %s: %s()\n", __FILE__, __func__);
Eric Wolleseneb607052007-07-19 01:49:39 -07001568
Hitoshi Mitakec3c52bc2008-04-29 01:03:18 -07001569 /* Ensure that the OPSTATE is set correctly for POLL or NMI */
1570 opstate_init();
1571
Eric Wolleseneb607052007-07-19 01:49:39 -07001572 pci_rc = pci_register_driver(&i5000_driver);
1573
1574 return (pci_rc < 0) ? pci_rc : 0;
1575}
1576
Douglas Thompsonb2ccaec2007-07-19 01:50:19 -07001577/*
Eric Wolleseneb607052007-07-19 01:49:39 -07001578 * i5000_exit() Module exit function
1579 * Unregister the driver
1580 */
1581static void __exit i5000_exit(void)
1582{
Joe Perches63ae96b2010-05-26 14:44:14 -07001583 debugf2("MC: %s: %s()\n", __FILE__, __func__);
Eric Wolleseneb607052007-07-19 01:49:39 -07001584 pci_unregister_driver(&i5000_driver);
1585}
1586
1587module_init(i5000_init);
1588module_exit(i5000_exit);
1589
1590MODULE_LICENSE("GPL");
1591MODULE_AUTHOR
1592 ("Linux Networx (http://lnxi.com) Doug Thompson <norsk5@xmission.com>");
1593MODULE_DESCRIPTION("MC Driver for Intel I5000 memory controllers - "
Douglas Thompson052dfb42007-07-19 01:50:13 -07001594 I5000_REVISION);
Hitoshi Mitakec3c52bc2008-04-29 01:03:18 -07001595
Dave Jiangc0d12172007-07-19 01:49:46 -07001596module_param(edac_op_state, int, 0444);
1597MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
Aristeu Rozanskic0667402008-10-15 22:04:31 -07001598module_param(misc_messages, int, 0444);
1599MODULE_PARM_DESC(misc_messages, "Log miscellaneous non fatal messages");
1600