Merge branch 'drm-fixes' of git://people.freedesktop.org/~airlied/linux
[deliverable/linux.git] / drivers / edac / i7300_edac.c
CommitLineData
fcaf780b
MCC
1/*
2 * Intel 7300 class Memory Controllers kernel module (Clarksboro)
3 *
4 * This file may be distributed under the terms of the
5 * GNU General Public License version 2 only.
6 *
7 * Copyright (c) 2010 by:
8 * Mauro Carvalho Chehab <mchehab@redhat.com>
9 *
10 * Red Hat Inc. http://www.redhat.com
11 *
12 * Intel 7300 Chipset Memory Controller Hub (MCH) - Datasheet
13 * http://www.intel.com/Assets/PDF/datasheet/318082.pdf
14 *
15 * TODO: The chipset allow checking for PCI Express errors also. Currently,
16 * the driver covers only memory error errors
17 *
18 * This driver uses "csrows" EDAC attribute to represent DIMM slot#
19 */
20
21#include <linux/module.h>
22#include <linux/init.h>
23#include <linux/pci.h>
24#include <linux/pci_ids.h>
25#include <linux/slab.h>
26#include <linux/edac.h>
27#include <linux/mmzone.h>
28
29#include "edac_core.h"
30
31/*
32 * Alter this version for the I7300 module when modifications are made
33 */
152ba394 34#define I7300_REVISION " Ver: 1.0.0"
fcaf780b
MCC
35
36#define EDAC_MOD_STR "i7300_edac"
37
38#define i7300_printk(level, fmt, arg...) \
39 edac_printk(level, "i7300", fmt, ##arg)
40
41#define i7300_mc_printk(mci, level, fmt, arg...) \
42 edac_mc_chipset_printk(mci, level, "i7300", fmt, ##arg)
43
b4552ace
MCC
44/***********************************************
45 * i7300 Limit constants Structs and static vars
46 ***********************************************/
47
fcaf780b
MCC
48/*
49 * Memory topology is organized as:
50 * Branch 0 - 2 channels: channels 0 and 1 (FDB0 PCI dev 21.0)
51 * Branch 1 - 2 channels: channels 2 and 3 (FDB1 PCI dev 22.0)
52 * Each channel can have to 8 DIMM sets (called as SLOTS)
53 * Slots should generally be filled in pairs
54 * Except on Single Channel mode of operation
55 * just slot 0/channel0 filled on this mode
56 * On normal operation mode, the two channels on a branch should be
c3af2eaf 57 * filled together for the same SLOT#
fcaf780b
MCC
58 * When in mirrored mode, Branch 1 replicate memory at Branch 0, so, the four
59 * channels on both branches should be filled
60 */
61
62/* Limits for i7300 */
63#define MAX_SLOTS 8
64#define MAX_BRANCHES 2
65#define MAX_CH_PER_BRANCH 2
66#define MAX_CHANNELS (MAX_CH_PER_BRANCH * MAX_BRANCHES)
67#define MAX_MIR 3
68
69#define to_channel(ch, branch) ((((branch)) << 1) | (ch))
70
71#define to_csrow(slot, ch, branch) \
72 (to_channel(ch, branch) | ((slot) << 2))
73
b4552ace
MCC
74/* Device name and register DID (Device ID) */
75struct i7300_dev_info {
76 const char *ctl_name; /* name for this device */
77 u16 fsb_mapping_errors; /* DID for the branchmap,control */
78};
79
80/* Table of devices attributes supported by this driver */
81static const struct i7300_dev_info i7300_devs[] = {
82 {
83 .ctl_name = "I7300",
84 .fsb_mapping_errors = PCI_DEVICE_ID_INTEL_I7300_MCH_ERR,
85 },
86};
87
88struct i7300_dimm_info {
89 int megabytes; /* size, 0 means not present */
90};
91
92/* driver private data structure */
93struct i7300_pvt {
94 struct pci_dev *pci_dev_16_0_fsb_ctlr; /* 16.0 */
95 struct pci_dev *pci_dev_16_1_fsb_addr_map; /* 16.1 */
96 struct pci_dev *pci_dev_16_2_fsb_err_regs; /* 16.2 */
97 struct pci_dev *pci_dev_2x_0_fbd_branch[MAX_BRANCHES]; /* 21.0 and 22.0 */
98
99 u16 tolm; /* top of low memory */
100 u64 ambase; /* AMB BAR */
101
102 u32 mc_settings; /* Report several settings */
103 u32 mc_settings_a;
104
105 u16 mir[MAX_MIR]; /* Memory Interleave Reg*/
106
9c6f6b65 107 u16 mtr[MAX_SLOTS][MAX_BRANCHES]; /* Memory Technlogy Reg */
b4552ace
MCC
108 u16 ambpresent[MAX_CHANNELS]; /* AMB present regs */
109
110 /* DIMM information matrix, allocating architecture maximums */
111 struct i7300_dimm_info dimm_info[MAX_SLOTS][MAX_CHANNELS];
112
113 /* Temporary buffer for use when preparing error messages */
114 char *tmp_prt_buffer;
115};
116
117/* FIXME: Why do we need to have this static? */
118static struct edac_pci_ctl_info *i7300_pci;
119
120/***************************************************
121 * i7300 Register definitions for memory enumeration
122 ***************************************************/
123
c3af2eaf
MCC
124/*
125 * Device 16,
126 * Function 0: System Address (not documented)
127 * Function 1: Memory Branch Map, Control, Errors Register
fcaf780b
MCC
128 */
129
130 /* OFFSETS for Function 0 */
af3d8831
MCC
131#define AMBASE 0x48 /* AMB Mem Mapped Reg Region Base */
132#define MAXCH 0x56 /* Max Channel Number */
133#define MAXDIMMPERCH 0x57 /* Max DIMM PER Channel Number */
fcaf780b
MCC
134
135 /* OFFSETS for Function 1 */
af3d8831 136#define MC_SETTINGS 0x40
bb81a216
MCC
137 #define IS_MIRRORED(mc) ((mc) & (1 << 16))
138 #define IS_ECC_ENABLED(mc) ((mc) & (1 << 5))
139 #define IS_RETRY_ENABLED(mc) ((mc) & (1 << 31))
140 #define IS_SCRBALGO_ENHANCED(mc) ((mc) & (1 << 8))
fcaf780b 141
bb81a216
MCC
142#define MC_SETTINGS_A 0x58
143 #define IS_SINGLE_MODE(mca) ((mca) & (1 << 14))
d7de2bdb 144
af3d8831 145#define TOLM 0x6C
af3d8831
MCC
146
147#define MIR0 0x80
148#define MIR1 0x84
149#define MIR2 0x88
fcaf780b 150
fcaf780b
MCC
151/*
152 * Note: Other Intel EDAC drivers use AMBPRESENT to identify if the available
153 * memory. From datasheet item 7.3.1 (FB-DIMM technology & organization), it
154 * seems that we cannot use this information directly for the same usage.
155 * Each memory slot may have up to 2 AMB interfaces, one for income and another
156 * for outcome interface to the next slot.
157 * For now, the driver just stores the AMB present registers, but rely only at
158 * the MTR info to detect memory.
159 * Datasheet is also not clear about how to map each AMBPRESENT registers to
160 * one of the 4 available channels.
161 */
162#define AMBPRESENT_0 0x64
163#define AMBPRESENT_1 0x66
164
42b16b3f 165static const u16 mtr_regs[MAX_SLOTS] = {
fcaf780b
MCC
166 0x80, 0x84, 0x88, 0x8c,
167 0x82, 0x86, 0x8a, 0x8e
168};
169
b4552ace
MCC
170/*
171 * Defines to extract the vaious fields from the
fcaf780b
MCC
172 * MTRx - Memory Technology Registers
173 */
174#define MTR_DIMMS_PRESENT(mtr) ((mtr) & (1 << 8))
175#define MTR_DIMMS_ETHROTTLE(mtr) ((mtr) & (1 << 7))
176#define MTR_DRAM_WIDTH(mtr) (((mtr) & (1 << 6)) ? 8 : 4)
177#define MTR_DRAM_BANKS(mtr) (((mtr) & (1 << 5)) ? 8 : 4)
178#define MTR_DIMM_RANKS(mtr) (((mtr) & (1 << 4)) ? 1 : 0)
179#define MTR_DIMM_ROWS(mtr) (((mtr) >> 2) & 0x3)
180#define MTR_DRAM_BANKS_ADDR_BITS 2
181#define MTR_DIMM_ROWS_ADDR_BITS(mtr) (MTR_DIMM_ROWS(mtr) + 13)
182#define MTR_DIMM_COLS(mtr) ((mtr) & 0x3)
183#define MTR_DIMM_COLS_ADDR_BITS(mtr) (MTR_DIMM_COLS(mtr) + 10)
184
fcaf780b
MCC
185#ifdef CONFIG_EDAC_DEBUG
186/* MTR NUMROW */
187static const char *numrow_toString[] = {
188 "8,192 - 13 rows",
189 "16,384 - 14 rows",
190 "32,768 - 15 rows",
191 "65,536 - 16 rows"
192};
193
194/* MTR NUMCOL */
195static const char *numcol_toString[] = {
196 "1,024 - 10 columns",
197 "2,048 - 11 columns",
198 "4,096 - 12 columns",
199 "reserved"
200};
201#endif
202
c3af2eaf
MCC
203/************************************************
204 * i7300 Register definitions for error detection
205 ************************************************/
57021918
MCC
206
207/*
208 * Device 16.1: FBD Error Registers
209 */
210#define FERR_FAT_FBD 0x98
211static const char *ferr_fat_fbd_name[] = {
212 [22] = "Non-Redundant Fast Reset Timeout",
213 [2] = ">Tmid Thermal event with intelligent throttling disabled",
214 [1] = "Memory or FBD configuration CRC read error",
215 [0] = "Memory Write error on non-redundant retry or "
216 "FBD configuration Write error on retry",
217};
218#define GET_FBD_FAT_IDX(fbderr) (fbderr & (3 << 28))
219#define FERR_FAT_FBD_ERR_MASK ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3))
220
221#define FERR_NF_FBD 0xa0
222static const char *ferr_nf_fbd_name[] = {
223 [24] = "DIMM-Spare Copy Completed",
224 [23] = "DIMM-Spare Copy Initiated",
225 [22] = "Redundant Fast Reset Timeout",
226 [21] = "Memory Write error on redundant retry",
227 [18] = "SPD protocol Error",
228 [17] = "FBD Northbound parity error on FBD Sync Status",
229 [16] = "Correctable Patrol Data ECC",
230 [15] = "Correctable Resilver- or Spare-Copy Data ECC",
231 [14] = "Correctable Mirrored Demand Data ECC",
232 [13] = "Correctable Non-Mirrored Demand Data ECC",
233 [11] = "Memory or FBD configuration CRC read error",
234 [10] = "FBD Configuration Write error on first attempt",
235 [9] = "Memory Write error on first attempt",
236 [8] = "Non-Aliased Uncorrectable Patrol Data ECC",
237 [7] = "Non-Aliased Uncorrectable Resilver- or Spare-Copy Data ECC",
238 [6] = "Non-Aliased Uncorrectable Mirrored Demand Data ECC",
239 [5] = "Non-Aliased Uncorrectable Non-Mirrored Demand Data ECC",
240 [4] = "Aliased Uncorrectable Patrol Data ECC",
241 [3] = "Aliased Uncorrectable Resilver- or Spare-Copy Data ECC",
242 [2] = "Aliased Uncorrectable Mirrored Demand Data ECC",
243 [1] = "Aliased Uncorrectable Non-Mirrored Demand Data ECC",
244 [0] = "Uncorrectable Data ECC on Replay",
245};
246#define GET_FBD_NF_IDX(fbderr) (fbderr & (3 << 28))
247#define FERR_NF_FBD_ERR_MASK ((1 << 24) | (1 << 23) | (1 << 22) | (1 << 21) |\
248 (1 << 18) | (1 << 17) | (1 << 16) | (1 << 15) |\
249 (1 << 14) | (1 << 13) | (1 << 11) | (1 << 10) |\
250 (1 << 9) | (1 << 8) | (1 << 7) | (1 << 6) |\
251 (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2) |\
252 (1 << 1) | (1 << 0))
253
254#define EMASK_FBD 0xa8
255#define EMASK_FBD_ERR_MASK ((1 << 27) | (1 << 26) | (1 << 25) | (1 << 24) |\
256 (1 << 22) | (1 << 21) | (1 << 20) | (1 << 19) |\
257 (1 << 18) | (1 << 17) | (1 << 16) | (1 << 14) |\
258 (1 << 13) | (1 << 12) | (1 << 11) | (1 << 10) |\
259 (1 << 9) | (1 << 8) | (1 << 7) | (1 << 6) |\
260 (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2) |\
261 (1 << 1) | (1 << 0))
262
c3af2eaf
MCC
263/*
264 * Device 16.2: Global Error Registers
265 */
266
5de6e07e
MCC
267#define FERR_GLOBAL_HI 0x48
268static const char *ferr_global_hi_name[] = {
269 [3] = "FSB 3 Fatal Error",
270 [2] = "FSB 2 Fatal Error",
271 [1] = "FSB 1 Fatal Error",
272 [0] = "FSB 0 Fatal Error",
273};
274#define ferr_global_hi_is_fatal(errno) 1
275
c3af2eaf 276#define FERR_GLOBAL_LO 0x40
5de6e07e 277static const char *ferr_global_lo_name[] = {
c3af2eaf
MCC
278 [31] = "Internal MCH Fatal Error",
279 [30] = "Intel QuickData Technology Device Fatal Error",
280 [29] = "FSB1 Fatal Error",
281 [28] = "FSB0 Fatal Error",
282 [27] = "FBD Channel 3 Fatal Error",
283 [26] = "FBD Channel 2 Fatal Error",
284 [25] = "FBD Channel 1 Fatal Error",
285 [24] = "FBD Channel 0 Fatal Error",
286 [23] = "PCI Express Device 7Fatal Error",
287 [22] = "PCI Express Device 6 Fatal Error",
288 [21] = "PCI Express Device 5 Fatal Error",
289 [20] = "PCI Express Device 4 Fatal Error",
290 [19] = "PCI Express Device 3 Fatal Error",
291 [18] = "PCI Express Device 2 Fatal Error",
292 [17] = "PCI Express Device 1 Fatal Error",
293 [16] = "ESI Fatal Error",
294 [15] = "Internal MCH Non-Fatal Error",
295 [14] = "Intel QuickData Technology Device Non Fatal Error",
296 [13] = "FSB1 Non-Fatal Error",
297 [12] = "FSB 0 Non-Fatal Error",
298 [11] = "FBD Channel 3 Non-Fatal Error",
299 [10] = "FBD Channel 2 Non-Fatal Error",
300 [9] = "FBD Channel 1 Non-Fatal Error",
301 [8] = "FBD Channel 0 Non-Fatal Error",
302 [7] = "PCI Express Device 7 Non-Fatal Error",
303 [6] = "PCI Express Device 6 Non-Fatal Error",
304 [5] = "PCI Express Device 5 Non-Fatal Error",
305 [4] = "PCI Express Device 4 Non-Fatal Error",
306 [3] = "PCI Express Device 3 Non-Fatal Error",
307 [2] = "PCI Express Device 2 Non-Fatal Error",
308 [1] = "PCI Express Device 1 Non-Fatal Error",
309 [0] = "ESI Non-Fatal Error",
310};
5de6e07e 311#define ferr_global_lo_is_fatal(errno) ((errno < 16) ? 0 : 1)
fcaf780b 312
8199d8cc
MCC
313#define NRECMEMA 0xbe
314 #define NRECMEMA_BANK(v) (((v) >> 12) & 7)
315 #define NRECMEMA_RANK(v) (((v) >> 8) & 15)
316
317#define NRECMEMB 0xc0
318 #define NRECMEMB_IS_WR(v) ((v) & (1 << 31))
319 #define NRECMEMB_CAS(v) (((v) >> 16) & 0x1fff)
320 #define NRECMEMB_RAS(v) ((v) & 0xffff)
321
32f94726
MCC
322#define REDMEMA 0xdc
323
37b69cf9
MCC
324#define REDMEMB 0x7c
325 #define IS_SECOND_CH(v) ((v) * (1 << 17))
326
32f94726
MCC
327#define RECMEMA 0xe0
328 #define RECMEMA_BANK(v) (((v) >> 12) & 7)
329 #define RECMEMA_RANK(v) (((v) >> 8) & 15)
330
331#define RECMEMB 0xe4
332 #define RECMEMB_IS_WR(v) ((v) & (1 << 31))
333 #define RECMEMB_CAS(v) (((v) >> 16) & 0x1fff)
334 #define RECMEMB_RAS(v) ((v) & 0xffff)
335
5de6e07e
MCC
336/********************************************
337 * i7300 Functions related to error detection
338 ********************************************/
fcaf780b 339
d091a6eb
MCC
340/**
341 * get_err_from_table() - Gets the error message from a table
342 * @table: table name (array of char *)
343 * @size: number of elements at the table
344 * @pos: position of the element to be returned
345 *
346 * This is a small routine that gets the pos-th element of a table. If the
347 * element doesn't exist (or it is empty), it returns "reserved".
348 * Instead of calling it directly, the better is to call via the macro
349 * GET_ERR_FROM_TABLE(), that automatically checks the table size via
350 * ARRAY_SIZE() macro
351 */
352static const char *get_err_from_table(const char *table[], int size, int pos)
fcaf780b 353{
d091a6eb
MCC
354 if (unlikely(pos >= size))
355 return "Reserved";
356
357 if (unlikely(!table[pos]))
5de6e07e
MCC
358 return "Reserved";
359
360 return table[pos];
fcaf780b
MCC
361}
362
5de6e07e
MCC
363#define GET_ERR_FROM_TABLE(table, pos) \
364 get_err_from_table(table, ARRAY_SIZE(table), pos)
365
d091a6eb
MCC
366/**
367 * i7300_process_error_global() - Retrieve the hardware error information from
368 * the hardware global error registers and
369 * sends it to dmesg
370 * @mci: struct mem_ctl_info pointer
fcaf780b 371 */
f4277422 372static void i7300_process_error_global(struct mem_ctl_info *mci)
fcaf780b 373{
5de6e07e 374 struct i7300_pvt *pvt;
5f032119 375 u32 errnum, error_reg;
5de6e07e
MCC
376 unsigned long errors;
377 const char *specific;
378 bool is_fatal;
fcaf780b 379
5de6e07e 380 pvt = mci->pvt_info;
fcaf780b 381
5de6e07e
MCC
382 /* read in the 1st FATAL error register */
383 pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
5f032119
MCC
384 FERR_GLOBAL_HI, &error_reg);
385 if (unlikely(error_reg)) {
386 errors = error_reg;
5de6e07e
MCC
387 errnum = find_first_bit(&errors,
388 ARRAY_SIZE(ferr_global_hi_name));
389 specific = GET_ERR_FROM_TABLE(ferr_global_hi_name, errnum);
390 is_fatal = ferr_global_hi_is_fatal(errnum);
86002324
MCC
391
392 /* Clear the error bit */
393 pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
5f032119 394 FERR_GLOBAL_HI, error_reg);
86002324 395
5de6e07e 396 goto error_global;
fcaf780b
MCC
397 }
398
5de6e07e 399 pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
5f032119
MCC
400 FERR_GLOBAL_LO, &error_reg);
401 if (unlikely(error_reg)) {
402 errors = error_reg;
5de6e07e
MCC
403 errnum = find_first_bit(&errors,
404 ARRAY_SIZE(ferr_global_lo_name));
405 specific = GET_ERR_FROM_TABLE(ferr_global_lo_name, errnum);
406 is_fatal = ferr_global_lo_is_fatal(errnum);
86002324
MCC
407
408 /* Clear the error bit */
409 pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
5f032119 410 FERR_GLOBAL_LO, error_reg);
86002324 411
5de6e07e
MCC
412 goto error_global;
413 }
414 return;
fcaf780b 415
5de6e07e
MCC
416error_global:
417 i7300_mc_printk(mci, KERN_EMERG, "%s misc error: %s\n",
418 is_fatal ? "Fatal" : "NOT fatal", specific);
fcaf780b
MCC
419}
420
d091a6eb
MCC
421/**
422 * i7300_process_fbd_error() - Retrieve the hardware error information from
423 * the FBD error registers and sends it via
424 * EDAC error API calls
425 * @mci: struct mem_ctl_info pointer
57021918 426 */
f4277422 427static void i7300_process_fbd_error(struct mem_ctl_info *mci)
57021918
MCC
428{
429 struct i7300_pvt *pvt;
5f032119 430 u32 errnum, value, error_reg;
8199d8cc 431 u16 val16;
37b69cf9 432 unsigned branch, channel, bank, rank, cas, ras;
32f94726
MCC
433 u32 syndrome;
434
57021918
MCC
435 unsigned long errors;
436 const char *specific;
32f94726 437 bool is_wr;
57021918
MCC
438
439 pvt = mci->pvt_info;
440
441 /* read in the 1st FATAL error register */
442 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
5f032119
MCC
443 FERR_FAT_FBD, &error_reg);
444 if (unlikely(error_reg & FERR_FAT_FBD_ERR_MASK)) {
445 errors = error_reg & FERR_FAT_FBD_ERR_MASK ;
57021918
MCC
446 errnum = find_first_bit(&errors,
447 ARRAY_SIZE(ferr_fat_fbd_name));
448 specific = GET_ERR_FROM_TABLE(ferr_fat_fbd_name, errnum);
5f032119 449 branch = (GET_FBD_FAT_IDX(error_reg) == 2) ? 1 : 0;
57021918 450
8199d8cc
MCC
451 pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map,
452 NRECMEMA, &val16);
453 bank = NRECMEMA_BANK(val16);
454 rank = NRECMEMA_RANK(val16);
455
456 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
457 NRECMEMB, &value);
8199d8cc
MCC
458 is_wr = NRECMEMB_IS_WR(value);
459 cas = NRECMEMB_CAS(value);
460 ras = NRECMEMB_RAS(value);
461
5f032119
MCC
462 /* Clean the error register */
463 pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
464 FERR_FAT_FBD, error_reg);
465
8199d8cc
MCC
466 snprintf(pvt->tmp_prt_buffer, PAGE_SIZE,
467 "FATAL (Branch=%d DRAM-Bank=%d %s "
468 "RAS=%d CAS=%d Err=0x%lx (%s))",
32f94726 469 branch, bank,
8199d8cc
MCC
470 is_wr ? "RDWR" : "RD",
471 ras, cas,
472 errors, specific);
473
474 /* Call the helper to output message */
475 edac_mc_handle_fbd_ue(mci, rank, branch << 1,
476 (branch << 1) + 1,
477 pvt->tmp_prt_buffer);
57021918
MCC
478 }
479
480 /* read in the 1st NON-FATAL error register */
481 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
5f032119
MCC
482 FERR_NF_FBD, &error_reg);
483 if (unlikely(error_reg & FERR_NF_FBD_ERR_MASK)) {
484 errors = error_reg & FERR_NF_FBD_ERR_MASK;
57021918
MCC
485 errnum = find_first_bit(&errors,
486 ARRAY_SIZE(ferr_nf_fbd_name));
487 specific = GET_ERR_FROM_TABLE(ferr_nf_fbd_name, errnum);
5f032119 488 branch = (GET_FBD_FAT_IDX(error_reg) == 2) ? 1 : 0;
57021918 489
32f94726
MCC
490 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
491 REDMEMA, &syndrome);
492
32f94726
MCC
493 pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map,
494 RECMEMA, &val16);
495 bank = RECMEMA_BANK(val16);
496 rank = RECMEMA_RANK(val16);
497
498 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
499 RECMEMB, &value);
32f94726
MCC
500 is_wr = RECMEMB_IS_WR(value);
501 cas = RECMEMB_CAS(value);
502 ras = RECMEMB_RAS(value);
8199d8cc 503
37b69cf9
MCC
504 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
505 REDMEMB, &value);
37b69cf9
MCC
506 channel = (branch << 1);
507 if (IS_SECOND_CH(value))
508 channel++;
509
5f032119
MCC
510 /* Clear the error bit */
511 pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
512 FERR_NF_FBD, error_reg);
513
32f94726
MCC
514 /* Form out message */
515 snprintf(pvt->tmp_prt_buffer, PAGE_SIZE,
37b69cf9 516 "Corrected error (Branch=%d, Channel %d), "
32f94726
MCC
517 " DRAM-Bank=%d %s "
518 "RAS=%d CAS=%d, CE Err=0x%lx, Syndrome=0x%08x(%s))",
37b69cf9 519 branch, channel,
32f94726
MCC
520 bank,
521 is_wr ? "RDWR" : "RD",
522 ras, cas,
523 errors, syndrome, specific);
524
525 /*
526 * Call the helper to output message
527 * NOTE: Errors are reported per-branch, and not per-channel
528 * Currently, we don't know how to identify the right
529 * channel.
530 */
37b69cf9 531 edac_mc_handle_fbd_ce(mci, rank, channel,
32f94726
MCC
532 pvt->tmp_prt_buffer);
533 }
534 return;
57021918
MCC
535}
536
d091a6eb
MCC
537/**
538 * i7300_check_error() - Calls the error checking subroutines
539 * @mci: struct mem_ctl_info pointer
fcaf780b 540 */
f4277422 541static void i7300_check_error(struct mem_ctl_info *mci)
5de6e07e 542{
f4277422
MCC
543 i7300_process_error_global(mci);
544 i7300_process_fbd_error(mci);
5de6e07e 545};
fcaf780b 546
d091a6eb
MCC
547/**
548 * i7300_clear_error() - Clears the error registers
549 * @mci: struct mem_ctl_info pointer
fcaf780b
MCC
550 */
551static void i7300_clear_error(struct mem_ctl_info *mci)
552{
e4327605
MCC
553 struct i7300_pvt *pvt = mci->pvt_info;
554 u32 value;
555 /*
556 * All error values are RWC - we need to read and write 1 to the
557 * bit that we want to cleanup
558 */
fcaf780b 559
e4327605
MCC
560 /* Clear global error registers */
561 pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
562 FERR_GLOBAL_HI, &value);
563 pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
564 FERR_GLOBAL_HI, value);
565
566 pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
567 FERR_GLOBAL_LO, &value);
568 pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
569 FERR_GLOBAL_LO, value);
570
571 /* Clear FBD error registers */
572 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
573 FERR_FAT_FBD, &value);
574 pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
575 FERR_FAT_FBD, value);
576
577 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
578 FERR_NF_FBD, &value);
579 pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
580 FERR_NF_FBD, value);
fcaf780b
MCC
581}
582
d091a6eb
MCC
583/**
584 * i7300_enable_error_reporting() - Enable the memory reporting logic at the
585 * hardware
586 * @mci: struct mem_ctl_info pointer
fcaf780b
MCC
587 */
588static void i7300_enable_error_reporting(struct mem_ctl_info *mci)
589{
57021918
MCC
590 struct i7300_pvt *pvt = mci->pvt_info;
591 u32 fbd_error_mask;
592
593 /* Read the FBD Error Mask Register */
594 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
595 EMASK_FBD, &fbd_error_mask);
596
597 /* Enable with a '0' */
598 fbd_error_mask &= ~(EMASK_FBD_ERR_MASK);
599
600 pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
601 EMASK_FBD, fbd_error_mask);
fcaf780b 602}
5de6e07e
MCC
603
604/************************************************
605 * i7300 Functions related to memory enumberation
606 ************************************************/
fcaf780b 607
d091a6eb
MCC
608/**
609 * decode_mtr() - Decodes the MTR descriptor, filling the edac structs
610 * @pvt: pointer to the private data struct used by i7300 driver
611 * @slot: DIMM slot (0 to 7)
612 * @ch: Channel number within the branch (0 or 1)
613 * @branch: Branch number (0 or 1)
614 * @dinfo: Pointer to DIMM info where dimm size is stored
615 * @p_csrow: Pointer to the struct csrow_info that corresponds to that element
fcaf780b
MCC
616 */
617static int decode_mtr(struct i7300_pvt *pvt,
618 int slot, int ch, int branch,
619 struct i7300_dimm_info *dinfo,
1aa4a7b6 620 struct csrow_info *p_csrow,
e6649cc6 621 u32 *nr_pages)
fcaf780b
MCC
622{
623 int mtr, ans, addrBits, channel;
624
625 channel = to_channel(ch, branch);
626
627 mtr = pvt->mtr[slot][branch];
628 ans = MTR_DIMMS_PRESENT(mtr) ? 1 : 0;
629
630 debugf2("\tMTR%d CH%d: DIMMs are %s (mtr)\n",
631 slot, channel,
632 ans ? "Present" : "NOT Present");
633
634 /* Determine if there is a DIMM present in this DIMM slot */
fcaf780b
MCC
635 if (!ans)
636 return 0;
fcaf780b
MCC
637
638 /* Start with the number of bits for a Bank
639 * on the DRAM */
640 addrBits = MTR_DRAM_BANKS_ADDR_BITS;
641 /* Add thenumber of ROW bits */
642 addrBits += MTR_DIMM_ROWS_ADDR_BITS(mtr);
643 /* add the number of COLUMN bits */
644 addrBits += MTR_DIMM_COLS_ADDR_BITS(mtr);
645 /* add the number of RANK bits */
646 addrBits += MTR_DIMM_RANKS(mtr);
647
648 addrBits += 6; /* add 64 bits per DIMM */
649 addrBits -= 20; /* divide by 2^^20 */
650 addrBits -= 3; /* 8 bits per bytes */
651
652 dinfo->megabytes = 1 << addrBits;
e6649cc6 653 *nr_pages = dinfo->megabytes << 8;
fcaf780b
MCC
654
655 debugf2("\t\tWIDTH: x%d\n", MTR_DRAM_WIDTH(mtr));
656
657 debugf2("\t\tELECTRICAL THROTTLING is %s\n",
658 MTR_DIMMS_ETHROTTLE(mtr) ? "enabled" : "disabled");
659
660 debugf2("\t\tNUMBANK: %d bank(s)\n", MTR_DRAM_BANKS(mtr));
661 debugf2("\t\tNUMRANK: %s\n", MTR_DIMM_RANKS(mtr) ? "double" : "single");
662 debugf2("\t\tNUMROW: %s\n", numrow_toString[MTR_DIMM_ROWS(mtr)]);
663 debugf2("\t\tNUMCOL: %s\n", numcol_toString[MTR_DIMM_COLS(mtr)]);
664 debugf2("\t\tSIZE: %d MB\n", dinfo->megabytes);
665
666 p_csrow->grain = 8;
fcaf780b 667 p_csrow->mtype = MEM_FB_DDR2;
1aa4a7b6 668 p_csrow->csrow_idx = slot;
1aa4a7b6 669 p_csrow->page_mask = 0;
116389ed
MCC
670
671 /*
15154c57 672 * The type of error detection actually depends of the
116389ed 673 * mode of operation. When it is just one single memory chip, at
15154c57
MCC
674 * socket 0, channel 0, it uses 8-byte-over-32-byte SECDED+ code.
675 * In normal or mirrored mode, it uses Lockstep mode,
116389ed
MCC
676 * with the possibility of using an extended algorithm for x8 memories
677 * See datasheet Sections 7.3.6 to 7.3.8
678 */
15154c57
MCC
679
680 if (IS_SINGLE_MODE(pvt->mc_settings_a)) {
681 p_csrow->edac_mode = EDAC_SECDED;
3b330f67 682 debugf2("\t\tECC code is 8-byte-over-32-byte SECDED+ code\n");
15154c57 683 } else {
3b330f67 684 debugf2("\t\tECC code is on Lockstep mode\n");
28c2ce7c 685 if (MTR_DRAM_WIDTH(mtr) == 8)
15154c57
MCC
686 p_csrow->edac_mode = EDAC_S8ECD8ED;
687 else
688 p_csrow->edac_mode = EDAC_S4ECD4ED;
689 }
fcaf780b
MCC
690
691 /* ask what device type on this row */
28c2ce7c 692 if (MTR_DRAM_WIDTH(mtr) == 8) {
3b330f67 693 debugf2("\t\tScrub algorithm for x8 is on %s mode\n",
d7de2bdb
MCC
694 IS_SCRBALGO_ENHANCED(pvt->mc_settings) ?
695 "enhanced" : "normal");
696
fcaf780b 697 p_csrow->dtype = DEV_X8;
d7de2bdb 698 } else
fcaf780b
MCC
699 p_csrow->dtype = DEV_X4;
700
701 return mtr;
702}
703
d091a6eb
MCC
704/**
705 * print_dimm_size() - Prints dump of the memory organization
706 * @pvt: pointer to the private data struct used by i7300 driver
fcaf780b 707 *
d091a6eb 708 * Useful for debug. If debug is disabled, this routine do nothing
fcaf780b
MCC
709 */
710static void print_dimm_size(struct i7300_pvt *pvt)
711{
d091a6eb 712#ifdef CONFIG_EDAC_DEBUG
fcaf780b 713 struct i7300_dimm_info *dinfo;
85580ea4 714 char *p;
fcaf780b
MCC
715 int space, n;
716 int channel, slot;
717
718 space = PAGE_SIZE;
85580ea4 719 p = pvt->tmp_prt_buffer;
fcaf780b
MCC
720
721 n = snprintf(p, space, " ");
722 p += n;
723 space -= n;
724 for (channel = 0; channel < MAX_CHANNELS; channel++) {
725 n = snprintf(p, space, "channel %d | ", channel);
726 p += n;
727 space -= n;
728 }
85580ea4
MCC
729 debugf2("%s\n", pvt->tmp_prt_buffer);
730 p = pvt->tmp_prt_buffer;
fcaf780b
MCC
731 space = PAGE_SIZE;
732 n = snprintf(p, space, "-------------------------------"
9c6f6b65 733 "------------------------------");
fcaf780b
MCC
734 p += n;
735 space -= n;
85580ea4
MCC
736 debugf2("%s\n", pvt->tmp_prt_buffer);
737 p = pvt->tmp_prt_buffer;
fcaf780b
MCC
738 space = PAGE_SIZE;
739
740 for (slot = 0; slot < MAX_SLOTS; slot++) {
741 n = snprintf(p, space, "csrow/SLOT %d ", slot);
742 p += n;
743 space -= n;
744
745 for (channel = 0; channel < MAX_CHANNELS; channel++) {
746 dinfo = &pvt->dimm_info[slot][channel];
747 n = snprintf(p, space, "%4d MB | ", dinfo->megabytes);
748 p += n;
749 space -= n;
750 }
751
85580ea4
MCC
752 debugf2("%s\n", pvt->tmp_prt_buffer);
753 p = pvt->tmp_prt_buffer;
fcaf780b
MCC
754 space = PAGE_SIZE;
755 }
756
757 n = snprintf(p, space, "-------------------------------"
9c6f6b65 758 "------------------------------");
fcaf780b
MCC
759 p += n;
760 space -= n;
85580ea4
MCC
761 debugf2("%s\n", pvt->tmp_prt_buffer);
762 p = pvt->tmp_prt_buffer;
fcaf780b 763 space = PAGE_SIZE;
d091a6eb 764#endif
fcaf780b
MCC
765}
766
d091a6eb
MCC
767/**
768 * i7300_init_csrows() - Initialize the 'csrows' table within
769 * the mci control structure with the
770 * addressing of memory.
771 * @mci: struct mem_ctl_info pointer
fcaf780b
MCC
772 */
773static int i7300_init_csrows(struct mem_ctl_info *mci)
774{
775 struct i7300_pvt *pvt;
776 struct i7300_dimm_info *dinfo;
777 struct csrow_info *p_csrow;
d091a6eb 778 int rc = -ENODEV;
fcaf780b
MCC
779 int mtr;
780 int ch, branch, slot, channel;
e6649cc6 781 u32 last_page = 0, nr_pages;
fcaf780b
MCC
782
783 pvt = mci->pvt_info;
784
fcaf780b
MCC
785 debugf2("Memory Technology Registers:\n");
786
787 /* Get the AMB present registers for the four channels */
788 for (branch = 0; branch < MAX_BRANCHES; branch++) {
789 /* Read and dump branch 0's MTRs */
790 channel = to_channel(0, branch);
9c6f6b65
MCC
791 pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch],
792 AMBPRESENT_0,
fcaf780b
MCC
793 &pvt->ambpresent[channel]);
794 debugf2("\t\tAMB-present CH%d = 0x%x:\n",
795 channel, pvt->ambpresent[channel]);
796
797 channel = to_channel(1, branch);
9c6f6b65
MCC
798 pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch],
799 AMBPRESENT_1,
fcaf780b
MCC
800 &pvt->ambpresent[channel]);
801 debugf2("\t\tAMB-present CH%d = 0x%x:\n",
802 channel, pvt->ambpresent[channel]);
803 }
804
805 /* Get the set of MTR[0-7] regs by each branch */
806 for (slot = 0; slot < MAX_SLOTS; slot++) {
807 int where = mtr_regs[slot];
808 for (branch = 0; branch < MAX_BRANCHES; branch++) {
3e57eef6 809 pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch],
fcaf780b
MCC
810 where,
811 &pvt->mtr[slot][branch]);
812 for (ch = 0; ch < MAX_BRANCHES; ch++) {
813 int channel = to_channel(ch, branch);
814
815 dinfo = &pvt->dimm_info[slot][channel];
816 p_csrow = &mci->csrows[slot];
817
818 mtr = decode_mtr(pvt, slot, ch, branch,
e6649cc6 819 dinfo, p_csrow, &nr_pages);
fcaf780b
MCC
820 /* if no DIMMS on this row, continue */
821 if (!MTR_DIMMS_PRESENT(mtr))
822 continue;
823
e6649cc6
MCC
824 /* Update per_csrow memory count */
825 p_csrow->nr_pages += nr_pages;
826 p_csrow->first_page = last_page;
827 last_page += nr_pages;
828 p_csrow->last_page = last_page;
829
d091a6eb 830 rc = 0;
fcaf780b
MCC
831 }
832 }
833 }
834
d091a6eb 835 return rc;
fcaf780b
MCC
836}
837
d091a6eb
MCC
838/**
839 * decode_mir() - Decodes Memory Interleave Register (MIR) info
840 * @int mir_no: number of the MIR register to decode
841 * @mir: array with the MIR data cached on the driver
842 */
fcaf780b
MCC
843static void decode_mir(int mir_no, u16 mir[MAX_MIR])
844{
845 if (mir[mir_no] & 3)
9c6f6b65
MCC
846 debugf2("MIR%d: limit= 0x%x Branch(es) that participate:"
847 " %s %s\n",
fcaf780b
MCC
848 mir_no,
849 (mir[mir_no] >> 4) & 0xfff,
850 (mir[mir_no] & 1) ? "B0" : "",
9c6f6b65 851 (mir[mir_no] & 2) ? "B1" : "");
fcaf780b
MCC
852}
853
d091a6eb
MCC
854/**
855 * i7300_get_mc_regs() - Get the contents of the MC enumeration registers
856 * @mci: struct mem_ctl_info pointer
fcaf780b 857 *
d091a6eb 858 * Data read is cached internally for its usage when needed
fcaf780b
MCC
859 */
860static int i7300_get_mc_regs(struct mem_ctl_info *mci)
861{
862 struct i7300_pvt *pvt;
863 u32 actual_tolm;
864 int i, rc;
865
866 pvt = mci->pvt_info;
867
3e57eef6 868 pci_read_config_dword(pvt->pci_dev_16_0_fsb_ctlr, AMBASE,
fcaf780b
MCC
869 (u32 *) &pvt->ambase);
870
871 debugf2("AMBASE= 0x%lx\n", (long unsigned int)pvt->ambase);
872
873 /* Get the Branch Map regs */
3e57eef6 874 pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, TOLM, &pvt->tolm);
fcaf780b
MCC
875 pvt->tolm >>= 12;
876 debugf2("TOLM (number of 256M regions) =%u (0x%x)\n", pvt->tolm,
877 pvt->tolm);
878
879 actual_tolm = (u32) ((1000l * pvt->tolm) >> (30 - 28));
880 debugf2("Actual TOLM byte addr=%u.%03u GB (0x%x)\n",
881 actual_tolm/1000, actual_tolm % 1000, pvt->tolm << 28);
882
af3d8831 883 /* Get memory controller settings */
3e57eef6 884 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, MC_SETTINGS,
af3d8831 885 &pvt->mc_settings);
bb81a216
MCC
886 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, MC_SETTINGS_A,
887 &pvt->mc_settings_a);
d7de2bdb 888
bb81a216
MCC
889 if (IS_SINGLE_MODE(pvt->mc_settings_a))
890 debugf0("Memory controller operating on single mode\n");
891 else
892 debugf0("Memory controller operating on %s mode\n",
d7de2bdb 893 IS_MIRRORED(pvt->mc_settings) ? "mirrored" : "non-mirrored");
bb81a216 894
af3d8831 895 debugf0("Error detection is %s\n",
d7de2bdb
MCC
896 IS_ECC_ENABLED(pvt->mc_settings) ? "enabled" : "disabled");
897 debugf0("Retry is %s\n",
898 IS_RETRY_ENABLED(pvt->mc_settings) ? "enabled" : "disabled");
af3d8831
MCC
899
900 /* Get Memory Interleave Range registers */
9c6f6b65
MCC
901 pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR0,
902 &pvt->mir[0]);
903 pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR1,
904 &pvt->mir[1]);
905 pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR2,
906 &pvt->mir[2]);
fcaf780b
MCC
907
908 /* Decode the MIR regs */
909 for (i = 0; i < MAX_MIR; i++)
910 decode_mir(i, pvt->mir);
911
912 rc = i7300_init_csrows(mci);
913 if (rc < 0)
914 return rc;
915
916 /* Go and determine the size of each DIMM and place in an
917 * orderly matrix */
918 print_dimm_size(pvt);
919
920 return 0;
921}
922
5de6e07e
MCC
923/*************************************************
924 * i7300 Functions related to device probe/release
925 *************************************************/
926
d091a6eb
MCC
927/**
928 * i7300_put_devices() - Release the PCI devices
929 * @mci: struct mem_ctl_info pointer
fcaf780b
MCC
930 */
931static void i7300_put_devices(struct mem_ctl_info *mci)
932{
933 struct i7300_pvt *pvt;
934 int branch;
935
936 pvt = mci->pvt_info;
937
938 /* Decrement usage count for devices */
939 for (branch = 0; branch < MAX_CH_PER_BRANCH; branch++)
3e57eef6
MCC
940 pci_dev_put(pvt->pci_dev_2x_0_fbd_branch[branch]);
941 pci_dev_put(pvt->pci_dev_16_2_fsb_err_regs);
942 pci_dev_put(pvt->pci_dev_16_1_fsb_addr_map);
fcaf780b
MCC
943}
944
d091a6eb
MCC
945/**
946 * i7300_get_devices() - Find and perform 'get' operation on the MCH's
947 * device/functions we want to reference for this driver
948 * @mci: struct mem_ctl_info pointer
fcaf780b 949 *
d091a6eb
MCC
950 * Access and prepare the several devices for usage:
951 * I7300 devices used by this driver:
952 * Device 16, functions 0,1 and 2: PCI_DEVICE_ID_INTEL_I7300_MCH_ERR
953 * Device 21 function 0: PCI_DEVICE_ID_INTEL_I7300_MCH_FB0
954 * Device 22 function 0: PCI_DEVICE_ID_INTEL_I7300_MCH_FB1
fcaf780b 955 */
d091a6eb 956static int __devinit i7300_get_devices(struct mem_ctl_info *mci)
fcaf780b
MCC
957{
958 struct i7300_pvt *pvt;
959 struct pci_dev *pdev;
960
961 pvt = mci->pvt_info;
962
963 /* Attempt to 'get' the MCH register we want */
964 pdev = NULL;
9c6f6b65
MCC
965 while (!pvt->pci_dev_16_1_fsb_addr_map ||
966 !pvt->pci_dev_16_2_fsb_err_regs) {
fcaf780b
MCC
967 pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
968 PCI_DEVICE_ID_INTEL_I7300_MCH_ERR, pdev);
969 if (!pdev) {
970 /* End of list, leave */
971 i7300_printk(KERN_ERR,
972 "'system address,Process Bus' "
973 "device not found:"
974 "vendor 0x%x device 0x%x ERR funcs "
975 "(broken BIOS?)\n",
976 PCI_VENDOR_ID_INTEL,
977 PCI_DEVICE_ID_INTEL_I7300_MCH_ERR);
978 goto error;
979 }
980
981 /* Store device 16 funcs 1 and 2 */
982 switch (PCI_FUNC(pdev->devfn)) {
983 case 1:
3e57eef6 984 pvt->pci_dev_16_1_fsb_addr_map = pdev;
fcaf780b
MCC
985 break;
986 case 2:
3e57eef6 987 pvt->pci_dev_16_2_fsb_err_regs = pdev;
fcaf780b
MCC
988 break;
989 }
990 }
991
992 debugf1("System Address, processor bus- PCI Bus ID: %s %x:%x\n",
3e57eef6 993 pci_name(pvt->pci_dev_16_0_fsb_ctlr),
9c6f6b65
MCC
994 pvt->pci_dev_16_0_fsb_ctlr->vendor,
995 pvt->pci_dev_16_0_fsb_ctlr->device);
fcaf780b 996 debugf1("Branchmap, control and errors - PCI Bus ID: %s %x:%x\n",
3e57eef6 997 pci_name(pvt->pci_dev_16_1_fsb_addr_map),
9c6f6b65
MCC
998 pvt->pci_dev_16_1_fsb_addr_map->vendor,
999 pvt->pci_dev_16_1_fsb_addr_map->device);
fcaf780b 1000 debugf1("FSB Error Regs - PCI Bus ID: %s %x:%x\n",
3e57eef6 1001 pci_name(pvt->pci_dev_16_2_fsb_err_regs),
9c6f6b65
MCC
1002 pvt->pci_dev_16_2_fsb_err_regs->vendor,
1003 pvt->pci_dev_16_2_fsb_err_regs->device);
fcaf780b 1004
3e57eef6 1005 pvt->pci_dev_2x_0_fbd_branch[0] = pci_get_device(PCI_VENDOR_ID_INTEL,
9c6f6b65 1006 PCI_DEVICE_ID_INTEL_I7300_MCH_FB0,
fcaf780b 1007 NULL);
3e57eef6 1008 if (!pvt->pci_dev_2x_0_fbd_branch[0]) {
fcaf780b
MCC
1009 i7300_printk(KERN_ERR,
1010 "MC: 'BRANCH 0' device not found:"
1011 "vendor 0x%x device 0x%x Func 0 (broken BIOS?)\n",
1012 PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_FB0);
1013 goto error;
1014 }
1015
3e57eef6 1016 pvt->pci_dev_2x_0_fbd_branch[1] = pci_get_device(PCI_VENDOR_ID_INTEL,
fcaf780b
MCC
1017 PCI_DEVICE_ID_INTEL_I7300_MCH_FB1,
1018 NULL);
3e57eef6 1019 if (!pvt->pci_dev_2x_0_fbd_branch[1]) {
fcaf780b
MCC
1020 i7300_printk(KERN_ERR,
1021 "MC: 'BRANCH 1' device not found:"
1022 "vendor 0x%x device 0x%x Func 0 "
1023 "(broken BIOS?)\n",
1024 PCI_VENDOR_ID_INTEL,
1025 PCI_DEVICE_ID_INTEL_I7300_MCH_FB1);
1026 goto error;
1027 }
1028
1029 return 0;
1030
1031error:
1032 i7300_put_devices(mci);
1033 return -ENODEV;
1034}
1035
d091a6eb
MCC
1036/**
1037 * i7300_init_one() - Probe for one instance of the device
1038 * @pdev: struct pci_dev pointer
1039 * @id: struct pci_device_id pointer - currently unused
fcaf780b 1040 */
d091a6eb
MCC
1041static int __devinit i7300_init_one(struct pci_dev *pdev,
1042 const struct pci_device_id *id)
fcaf780b
MCC
1043{
1044 struct mem_ctl_info *mci;
1045 struct i7300_pvt *pvt;
1046 int num_channels;
1047 int num_dimms_per_channel;
1048 int num_csrows;
d091a6eb 1049 int rc;
fcaf780b 1050
d091a6eb
MCC
1051 /* wake up device */
1052 rc = pci_enable_device(pdev);
1053 if (rc == -EIO)
1054 return rc;
fcaf780b
MCC
1055
1056 debugf0("MC: " __FILE__ ": %s(), pdev bus %u dev=0x%x fn=0x%x\n",
1057 __func__,
1058 pdev->bus->number,
1059 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
1060
1061 /* We only are looking for func 0 of the set */
1062 if (PCI_FUNC(pdev->devfn) != 0)
1063 return -ENODEV;
1064
1065 /* As we don't have a motherboard identification routine to determine
1066 * actual number of slots/dimms per channel, we thus utilize the
1067 * resource as specified by the chipset. Thus, we might have
1068 * have more DIMMs per channel than actually on the mobo, but this
25985edc 1069 * allows the driver to support up to the chipset max, without
fcaf780b
MCC
1070 * some fancy mobo determination.
1071 */
1072 num_dimms_per_channel = MAX_SLOTS;
1073 num_channels = MAX_CHANNELS;
1074 num_csrows = MAX_SLOTS * MAX_CHANNELS;
1075
1076 debugf0("MC: %s(): Number of - Channels= %d DIMMS= %d CSROWS= %d\n",
1077 __func__, num_channels, num_dimms_per_channel, num_csrows);
1078
1079 /* allocate a new MC control structure */
1080 mci = edac_mc_alloc(sizeof(*pvt), num_csrows, num_channels, 0);
1081
1082 if (mci == NULL)
1083 return -ENOMEM;
1084
1085 debugf0("MC: " __FILE__ ": %s(): mci = %p\n", __func__, mci);
1086
1087 mci->dev = &pdev->dev; /* record ptr to the generic device */
1088
1089 pvt = mci->pvt_info;
3e57eef6 1090 pvt->pci_dev_16_0_fsb_ctlr = pdev; /* Record this device in our private */
fcaf780b 1091
85580ea4
MCC
1092 pvt->tmp_prt_buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);
1093 if (!pvt->tmp_prt_buffer) {
1094 edac_mc_free(mci);
1095 return -ENOMEM;
1096 }
1097
fcaf780b 1098 /* 'get' the pci devices we want to reserve for our use */
d091a6eb 1099 if (i7300_get_devices(mci))
fcaf780b
MCC
1100 goto fail0;
1101
1102 mci->mc_idx = 0;
1103 mci->mtype_cap = MEM_FLAG_FB_DDR2;
1104 mci->edac_ctl_cap = EDAC_FLAG_NONE;
1105 mci->edac_cap = EDAC_FLAG_NONE;
1106 mci->mod_name = "i7300_edac.c";
1107 mci->mod_ver = I7300_REVISION;
d091a6eb 1108 mci->ctl_name = i7300_devs[0].ctl_name;
fcaf780b
MCC
1109 mci->dev_name = pci_name(pdev);
1110 mci->ctl_page_to_phys = NULL;
1111
fcaf780b
MCC
1112 /* Set the function pointer to an actual operation function */
1113 mci->edac_check = i7300_check_error;
fcaf780b
MCC
1114
1115 /* initialize the MC control structure 'csrows' table
1116 * with the mapping and control information */
1117 if (i7300_get_mc_regs(mci)) {
1118 debugf0("MC: Setting mci->edac_cap to EDAC_FLAG_NONE\n"
1119 " because i7300_init_csrows() returned nonzero "
1120 "value\n");
1121 mci->edac_cap = EDAC_FLAG_NONE; /* no csrows found */
1122 } else {
fcaf780b
MCC
1123 debugf1("MC: Enable error reporting now\n");
1124 i7300_enable_error_reporting(mci);
fcaf780b
MCC
1125 }
1126
1127 /* add this new MC control structure to EDAC's list of MCs */
1128 if (edac_mc_add_mc(mci)) {
1129 debugf0("MC: " __FILE__
1130 ": %s(): failed edac_mc_add_mc()\n", __func__);
1131 /* FIXME: perhaps some code should go here that disables error
1132 * reporting if we just enabled it
1133 */
1134 goto fail1;
1135 }
1136
fcaf780b 1137 i7300_clear_error(mci);
fcaf780b
MCC
1138
1139 /* allocating generic PCI control info */
1140 i7300_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
1141 if (!i7300_pci) {
1142 printk(KERN_WARNING
1143 "%s(): Unable to create PCI control\n",
1144 __func__);
1145 printk(KERN_WARNING
1146 "%s(): PCI error report via EDAC not setup\n",
1147 __func__);
1148 }
1149
1150 return 0;
1151
1152 /* Error exit unwinding stack */
1153fail1:
1154
1155 i7300_put_devices(mci);
1156
1157fail0:
85580ea4 1158 kfree(pvt->tmp_prt_buffer);
fcaf780b
MCC
1159 edac_mc_free(mci);
1160 return -ENODEV;
1161}
1162
d091a6eb
MCC
1163/**
1164 * i7300_remove_one() - Remove the driver
1165 * @pdev: struct pci_dev pointer
fcaf780b
MCC
1166 */
1167static void __devexit i7300_remove_one(struct pci_dev *pdev)
1168{
1169 struct mem_ctl_info *mci;
85580ea4 1170 char *tmp;
fcaf780b
MCC
1171
1172 debugf0(__FILE__ ": %s()\n", __func__);
1173
1174 if (i7300_pci)
1175 edac_pci_release_generic_ctl(i7300_pci);
1176
1177 mci = edac_mc_del_mc(&pdev->dev);
1178 if (!mci)
1179 return;
1180
85580ea4
MCC
1181 tmp = ((struct i7300_pvt *)mci->pvt_info)->tmp_prt_buffer;
1182
fcaf780b
MCC
1183 /* retrieve references to resources, and free those resources */
1184 i7300_put_devices(mci);
1185
85580ea4 1186 kfree(tmp);
fcaf780b
MCC
1187 edac_mc_free(mci);
1188}
1189
1190/*
d091a6eb 1191 * pci_device_id: table for which devices we are looking for
fcaf780b 1192 *
d091a6eb 1193 * Has only 8086:360c PCI ID
fcaf780b
MCC
1194 */
1195static const struct pci_device_id i7300_pci_tbl[] __devinitdata = {
1196 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
1197 {0,} /* 0 terminated list. */
1198};
1199
1200MODULE_DEVICE_TABLE(pci, i7300_pci_tbl);
1201
1202/*
d091a6eb 1203 * i7300_driver: pci_driver structure for this module
fcaf780b
MCC
1204 */
1205static struct pci_driver i7300_driver = {
1206 .name = "i7300_edac",
1207 .probe = i7300_init_one,
1208 .remove = __devexit_p(i7300_remove_one),
1209 .id_table = i7300_pci_tbl,
1210};
1211
d091a6eb
MCC
1212/**
1213 * i7300_init() - Registers the driver
fcaf780b
MCC
1214 */
1215static int __init i7300_init(void)
1216{
1217 int pci_rc;
1218
1219 debugf2("MC: " __FILE__ ": %s()\n", __func__);
1220
1221 /* Ensure that the OPSTATE is set correctly for POLL or NMI */
1222 opstate_init();
1223
1224 pci_rc = pci_register_driver(&i7300_driver);
1225
1226 return (pci_rc < 0) ? pci_rc : 0;
1227}
1228
d091a6eb
MCC
1229/**
1230 * i7300_init() - Unregisters the driver
fcaf780b
MCC
1231 */
1232static void __exit i7300_exit(void)
1233{
1234 debugf2("MC: " __FILE__ ": %s()\n", __func__);
1235 pci_unregister_driver(&i7300_driver);
1236}
1237
1238module_init(i7300_init);
1239module_exit(i7300_exit);
1240
1241MODULE_LICENSE("GPL");
1242MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
1243MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
1244MODULE_DESCRIPTION("MC Driver for Intel I7300 memory controllers - "
1245 I7300_REVISION);
1246
1247module_param(edac_op_state, int, 0444);
1248MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
This page took 0.145105 seconds and 5 git commands to generate.