blob: 6278209fec07c0cf29591c32248aa2212f2e00c9 [file] [log] [blame]
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -03001/*
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 */
34#define I7300_REVISION " Ver: 1.0.0 " __DATE__
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
Mauro Carvalho Chehabb4552ac2010-08-27 16:43:01 -030044/***********************************************
45 * i7300 Limit constants Structs and static vars
46 ***********************************************/
47
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -030048/*
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
Mauro Carvalho Chehabc3af2ea2010-08-26 19:54:51 -030057 * filled together for the same SLOT#
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -030058 * 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
Mauro Carvalho Chehabb4552ac2010-08-27 16:43:01 -030074/* 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};
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -030079
Mauro Carvalho Chehabb4552ac2010-08-27 16:43:01 -030080/* 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
107 u16 mtr[MAX_SLOTS][MAX_BRANCHES]; /* Memory Technlogy Reg */
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
124/*
125 * I7300 devices:
126 * All 3 functions of Device 16 (0,1,2) share the SAME DID and
127 * uses PCI_DEVICE_ID_INTEL_I7300_MCH_ERR for device 16 (0,1,2).
128 * PCI_DEVICE_ID_INTEL_I7300_MCH_FB0 is used for device 21 (0,1)
129 * and PCI_DEVICE_ID_INTEL_I7300_MCH_FB1 is used for device 21 (0,1).
130 */
Mauro Carvalho Chehabc3af2ea2010-08-26 19:54:51 -0300131
132/*
133 * Device 16,
134 * Function 0: System Address (not documented)
135 * Function 1: Memory Branch Map, Control, Errors Register
136 */
137
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300138 /* OFFSETS for Function 0 */
Mauro Carvalho Chehabaf3d8832010-08-26 20:58:45 -0300139#define AMBASE 0x48 /* AMB Mem Mapped Reg Region Base */
140#define MAXCH 0x56 /* Max Channel Number */
141#define MAXDIMMPERCH 0x57 /* Max DIMM PER Channel Number */
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300142
143 /* OFFSETS for Function 1 */
Mauro Carvalho Chehabaf3d8832010-08-26 20:58:45 -0300144#define MC_SETTINGS 0x40
Mauro Carvalho Chehabbb81a212010-08-27 09:04:11 -0300145 #define IS_MIRRORED(mc) ((mc) & (1 << 16))
146 #define IS_ECC_ENABLED(mc) ((mc) & (1 << 5))
147 #define IS_RETRY_ENABLED(mc) ((mc) & (1 << 31))
148 #define IS_SCRBALGO_ENHANCED(mc) ((mc) & (1 << 8))
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300149
Mauro Carvalho Chehabbb81a212010-08-27 09:04:11 -0300150#define MC_SETTINGS_A 0x58
151 #define IS_SINGLE_MODE(mca) ((mca) & (1 << 14))
Mauro Carvalho Chehabd7de2bd2010-08-27 08:56:48 -0300152
Mauro Carvalho Chehabaf3d8832010-08-26 20:58:45 -0300153#define TOLM 0x6C
Mauro Carvalho Chehabaf3d8832010-08-26 20:58:45 -0300154
155#define MIR0 0x80
156#define MIR1 0x84
157#define MIR2 0x88
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300158
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300159/*
160 * Note: Other Intel EDAC drivers use AMBPRESENT to identify if the available
161 * memory. From datasheet item 7.3.1 (FB-DIMM technology & organization), it
162 * seems that we cannot use this information directly for the same usage.
163 * Each memory slot may have up to 2 AMB interfaces, one for income and another
164 * for outcome interface to the next slot.
165 * For now, the driver just stores the AMB present registers, but rely only at
166 * the MTR info to detect memory.
167 * Datasheet is also not clear about how to map each AMBPRESENT registers to
168 * one of the 4 available channels.
169 */
170#define AMBPRESENT_0 0x64
171#define AMBPRESENT_1 0x66
172
173const static u16 mtr_regs [MAX_SLOTS] = {
174 0x80, 0x84, 0x88, 0x8c,
175 0x82, 0x86, 0x8a, 0x8e
176};
177
Mauro Carvalho Chehabb4552ac2010-08-27 16:43:01 -0300178/*
179 * Defines to extract the vaious fields from the
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300180 * MTRx - Memory Technology Registers
181 */
182#define MTR_DIMMS_PRESENT(mtr) ((mtr) & (1 << 8))
183#define MTR_DIMMS_ETHROTTLE(mtr) ((mtr) & (1 << 7))
184#define MTR_DRAM_WIDTH(mtr) (((mtr) & (1 << 6)) ? 8 : 4)
185#define MTR_DRAM_BANKS(mtr) (((mtr) & (1 << 5)) ? 8 : 4)
186#define MTR_DIMM_RANKS(mtr) (((mtr) & (1 << 4)) ? 1 : 0)
187#define MTR_DIMM_ROWS(mtr) (((mtr) >> 2) & 0x3)
188#define MTR_DRAM_BANKS_ADDR_BITS 2
189#define MTR_DIMM_ROWS_ADDR_BITS(mtr) (MTR_DIMM_ROWS(mtr) + 13)
190#define MTR_DIMM_COLS(mtr) ((mtr) & 0x3)
191#define MTR_DIMM_COLS_ADDR_BITS(mtr) (MTR_DIMM_COLS(mtr) + 10)
192
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300193#ifdef CONFIG_EDAC_DEBUG
194/* MTR NUMROW */
195static const char *numrow_toString[] = {
196 "8,192 - 13 rows",
197 "16,384 - 14 rows",
198 "32,768 - 15 rows",
199 "65,536 - 16 rows"
200};
201
202/* MTR NUMCOL */
203static const char *numcol_toString[] = {
204 "1,024 - 10 columns",
205 "2,048 - 11 columns",
206 "4,096 - 12 columns",
207 "reserved"
208};
209#endif
210
Mauro Carvalho Chehabc3af2ea2010-08-26 19:54:51 -0300211/************************************************
212 * i7300 Register definitions for error detection
213 ************************************************/
Mauro Carvalho Chehab57021912010-08-27 10:22:36 -0300214
215/*
216 * Device 16.1: FBD Error Registers
217 */
218#define FERR_FAT_FBD 0x98
219static const char *ferr_fat_fbd_name[] = {
220 [22] = "Non-Redundant Fast Reset Timeout",
221 [2] = ">Tmid Thermal event with intelligent throttling disabled",
222 [1] = "Memory or FBD configuration CRC read error",
223 [0] = "Memory Write error on non-redundant retry or "
224 "FBD configuration Write error on retry",
225};
226#define GET_FBD_FAT_IDX(fbderr) (fbderr & (3 << 28))
227#define FERR_FAT_FBD_ERR_MASK ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3))
228
229#define FERR_NF_FBD 0xa0
230static const char *ferr_nf_fbd_name[] = {
231 [24] = "DIMM-Spare Copy Completed",
232 [23] = "DIMM-Spare Copy Initiated",
233 [22] = "Redundant Fast Reset Timeout",
234 [21] = "Memory Write error on redundant retry",
235 [18] = "SPD protocol Error",
236 [17] = "FBD Northbound parity error on FBD Sync Status",
237 [16] = "Correctable Patrol Data ECC",
238 [15] = "Correctable Resilver- or Spare-Copy Data ECC",
239 [14] = "Correctable Mirrored Demand Data ECC",
240 [13] = "Correctable Non-Mirrored Demand Data ECC",
241 [11] = "Memory or FBD configuration CRC read error",
242 [10] = "FBD Configuration Write error on first attempt",
243 [9] = "Memory Write error on first attempt",
244 [8] = "Non-Aliased Uncorrectable Patrol Data ECC",
245 [7] = "Non-Aliased Uncorrectable Resilver- or Spare-Copy Data ECC",
246 [6] = "Non-Aliased Uncorrectable Mirrored Demand Data ECC",
247 [5] = "Non-Aliased Uncorrectable Non-Mirrored Demand Data ECC",
248 [4] = "Aliased Uncorrectable Patrol Data ECC",
249 [3] = "Aliased Uncorrectable Resilver- or Spare-Copy Data ECC",
250 [2] = "Aliased Uncorrectable Mirrored Demand Data ECC",
251 [1] = "Aliased Uncorrectable Non-Mirrored Demand Data ECC",
252 [0] = "Uncorrectable Data ECC on Replay",
253};
254#define GET_FBD_NF_IDX(fbderr) (fbderr & (3 << 28))
255#define FERR_NF_FBD_ERR_MASK ((1 << 24) | (1 << 23) | (1 << 22) | (1 << 21) |\
256 (1 << 18) | (1 << 17) | (1 << 16) | (1 << 15) |\
257 (1 << 14) | (1 << 13) | (1 << 11) | (1 << 10) |\
258 (1 << 9) | (1 << 8) | (1 << 7) | (1 << 6) |\
259 (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2) |\
260 (1 << 1) | (1 << 0))
261
262#define EMASK_FBD 0xa8
263#define EMASK_FBD_ERR_MASK ((1 << 27) | (1 << 26) | (1 << 25) | (1 << 24) |\
264 (1 << 22) | (1 << 21) | (1 << 20) | (1 << 19) |\
265 (1 << 18) | (1 << 17) | (1 << 16) | (1 << 14) |\
266 (1 << 13) | (1 << 12) | (1 << 11) | (1 << 10) |\
267 (1 << 9) | (1 << 8) | (1 << 7) | (1 << 6) |\
268 (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2) |\
269 (1 << 1) | (1 << 0))
270
Mauro Carvalho Chehabc3af2ea2010-08-26 19:54:51 -0300271/*
272 * Device 16.2: Global Error Registers
273 */
274
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300275#define FERR_GLOBAL_HI 0x48
276static const char *ferr_global_hi_name[] = {
277 [3] = "FSB 3 Fatal Error",
278 [2] = "FSB 2 Fatal Error",
279 [1] = "FSB 1 Fatal Error",
280 [0] = "FSB 0 Fatal Error",
281};
282#define ferr_global_hi_is_fatal(errno) 1
283
Mauro Carvalho Chehabc3af2ea2010-08-26 19:54:51 -0300284#define FERR_GLOBAL_LO 0x40
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300285static const char *ferr_global_lo_name[] = {
Mauro Carvalho Chehabc3af2ea2010-08-26 19:54:51 -0300286 [31] = "Internal MCH Fatal Error",
287 [30] = "Intel QuickData Technology Device Fatal Error",
288 [29] = "FSB1 Fatal Error",
289 [28] = "FSB0 Fatal Error",
290 [27] = "FBD Channel 3 Fatal Error",
291 [26] = "FBD Channel 2 Fatal Error",
292 [25] = "FBD Channel 1 Fatal Error",
293 [24] = "FBD Channel 0 Fatal Error",
294 [23] = "PCI Express Device 7Fatal Error",
295 [22] = "PCI Express Device 6 Fatal Error",
296 [21] = "PCI Express Device 5 Fatal Error",
297 [20] = "PCI Express Device 4 Fatal Error",
298 [19] = "PCI Express Device 3 Fatal Error",
299 [18] = "PCI Express Device 2 Fatal Error",
300 [17] = "PCI Express Device 1 Fatal Error",
301 [16] = "ESI Fatal Error",
302 [15] = "Internal MCH Non-Fatal Error",
303 [14] = "Intel QuickData Technology Device Non Fatal Error",
304 [13] = "FSB1 Non-Fatal Error",
305 [12] = "FSB 0 Non-Fatal Error",
306 [11] = "FBD Channel 3 Non-Fatal Error",
307 [10] = "FBD Channel 2 Non-Fatal Error",
308 [9] = "FBD Channel 1 Non-Fatal Error",
309 [8] = "FBD Channel 0 Non-Fatal Error",
310 [7] = "PCI Express Device 7 Non-Fatal Error",
311 [6] = "PCI Express Device 6 Non-Fatal Error",
312 [5] = "PCI Express Device 5 Non-Fatal Error",
313 [4] = "PCI Express Device 4 Non-Fatal Error",
314 [3] = "PCI Express Device 3 Non-Fatal Error",
315 [2] = "PCI Express Device 2 Non-Fatal Error",
316 [1] = "PCI Express Device 1 Non-Fatal Error",
317 [0] = "ESI Non-Fatal Error",
318};
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300319#define ferr_global_lo_is_fatal(errno) ((errno < 16) ? 0 : 1)
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300320
Mauro Carvalho Chehab8199d8c2010-08-27 11:51:48 -0300321#define NRECMEMA 0xbe
322 #define NRECMEMA_BANK(v) (((v) >> 12) & 7)
323 #define NRECMEMA_RANK(v) (((v) >> 8) & 15)
324
325#define NRECMEMB 0xc0
326 #define NRECMEMB_IS_WR(v) ((v) & (1 << 31))
327 #define NRECMEMB_CAS(v) (((v) >> 16) & 0x1fff)
328 #define NRECMEMB_RAS(v) ((v) & 0xffff)
329
Mauro Carvalho Chehab32f94722010-08-27 12:13:05 -0300330#define REDMEMA 0xdc
331
Mauro Carvalho Chehab37b69cf2010-08-27 15:44:43 -0300332#define REDMEMB 0x7c
333 #define IS_SECOND_CH(v) ((v) * (1 << 17))
334
Mauro Carvalho Chehab32f94722010-08-27 12:13:05 -0300335#define RECMEMA 0xe0
336 #define RECMEMA_BANK(v) (((v) >> 12) & 7)
337 #define RECMEMA_RANK(v) (((v) >> 8) & 15)
338
339#define RECMEMB 0xe4
340 #define RECMEMB_IS_WR(v) ((v) & (1 << 31))
341 #define RECMEMB_CAS(v) (((v) >> 16) & 0x1fff)
342 #define RECMEMB_RAS(v) ((v) & 0xffff)
343
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300344/********************************************
345 * i7300 Functions related to error detection
346 ********************************************/
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300347
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300348const char *get_err_from_table(const char *table[], int size, int pos)
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300349{
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300350 if (pos >= size)
351 return "Reserved";
352
353 return table[pos];
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300354}
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300355
356#define GET_ERR_FROM_TABLE(table, pos) \
357 get_err_from_table(table, ARRAY_SIZE(table), pos)
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300358
359/*
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300360 * i7300_process_error_global Retrieve the hardware error information from
361 * the hardware and cache it in the 'info'
362 * structure
363 */
Mauro Carvalho Chehabf4277422010-08-27 10:33:25 -0300364static void i7300_process_error_global(struct mem_ctl_info *mci)
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300365{
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300366 struct i7300_pvt *pvt;
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300367 u32 errnum, value;
368 unsigned long errors;
369 const char *specific;
370 bool is_fatal;
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300371
372 pvt = mci->pvt_info;
373
374 /* read in the 1st FATAL error register */
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300375 pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
376 FERR_GLOBAL_HI, &value);
377 if (unlikely(value)) {
378 errors = value;
379 errnum = find_first_bit(&errors,
380 ARRAY_SIZE(ferr_global_hi_name));
381 specific = GET_ERR_FROM_TABLE(ferr_global_hi_name, errnum);
382 is_fatal = ferr_global_hi_is_fatal(errnum);
Mauro Carvalho Chehab86002322010-08-27 00:46:57 -0300383
384 /* Clear the error bit */
385 pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
386 FERR_GLOBAL_HI, value);
387
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300388 goto error_global;
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300389 }
390
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300391 pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
392 FERR_GLOBAL_LO, &value);
393 if (unlikely(value)) {
394 errors = value;
395 errnum = find_first_bit(&errors,
396 ARRAY_SIZE(ferr_global_lo_name));
397 specific = GET_ERR_FROM_TABLE(ferr_global_lo_name, errnum);
398 is_fatal = ferr_global_lo_is_fatal(errnum);
Mauro Carvalho Chehab86002322010-08-27 00:46:57 -0300399
400 /* Clear the error bit */
401 pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
402 FERR_GLOBAL_LO, value);
403
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300404 goto error_global;
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300405 }
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300406 return;
407
408error_global:
409 i7300_mc_printk(mci, KERN_EMERG, "%s misc error: %s\n",
410 is_fatal ? "Fatal" : "NOT fatal", specific);
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300411}
412
413/*
Mauro Carvalho Chehab57021912010-08-27 10:22:36 -0300414 * i7300_process_fbd_error Retrieve the hardware error information from
415 * the hardware and cache it in the 'info'
416 * structure
417 */
Mauro Carvalho Chehabf4277422010-08-27 10:33:25 -0300418static void i7300_process_fbd_error(struct mem_ctl_info *mci)
Mauro Carvalho Chehab57021912010-08-27 10:22:36 -0300419{
420 struct i7300_pvt *pvt;
421 u32 errnum, value;
Mauro Carvalho Chehab8199d8c2010-08-27 11:51:48 -0300422 u16 val16;
Mauro Carvalho Chehab37b69cf2010-08-27 15:44:43 -0300423 unsigned branch, channel, bank, rank, cas, ras;
Mauro Carvalho Chehab32f94722010-08-27 12:13:05 -0300424 u32 syndrome;
425
Mauro Carvalho Chehab57021912010-08-27 10:22:36 -0300426 unsigned long errors;
427 const char *specific;
Mauro Carvalho Chehab32f94722010-08-27 12:13:05 -0300428 bool is_wr;
Mauro Carvalho Chehab57021912010-08-27 10:22:36 -0300429
430 pvt = mci->pvt_info;
431
432 /* read in the 1st FATAL error register */
433 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
434 FERR_FAT_FBD, &value);
435 if (unlikely(value & FERR_FAT_FBD_ERR_MASK)) {
436 errors = value & FERR_FAT_FBD_ERR_MASK ;
437 errnum = find_first_bit(&errors,
438 ARRAY_SIZE(ferr_fat_fbd_name));
439 specific = GET_ERR_FROM_TABLE(ferr_fat_fbd_name, errnum);
Mauro Carvalho Chehab57021912010-08-27 10:22:36 -0300440
441 branch = (GET_FBD_FAT_IDX(value) == 2) ? 1 : 0;
Mauro Carvalho Chehab8199d8c2010-08-27 11:51:48 -0300442 pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map,
443 NRECMEMA, &val16);
444 bank = NRECMEMA_BANK(val16);
445 rank = NRECMEMA_RANK(val16);
Mauro Carvalho Chehab57021912010-08-27 10:22:36 -0300446
Mauro Carvalho Chehab8199d8c2010-08-27 11:51:48 -0300447 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
448 NRECMEMB, &value);
449
450 is_wr = NRECMEMB_IS_WR(value);
451 cas = NRECMEMB_CAS(value);
452 ras = NRECMEMB_RAS(value);
453
454 snprintf(pvt->tmp_prt_buffer, PAGE_SIZE,
455 "FATAL (Branch=%d DRAM-Bank=%d %s "
456 "RAS=%d CAS=%d Err=0x%lx (%s))",
Mauro Carvalho Chehab32f94722010-08-27 12:13:05 -0300457 branch, bank,
Mauro Carvalho Chehab8199d8c2010-08-27 11:51:48 -0300458 is_wr ? "RDWR" : "RD",
459 ras, cas,
460 errors, specific);
461
462 /* Call the helper to output message */
463 edac_mc_handle_fbd_ue(mci, rank, branch << 1,
464 (branch << 1) + 1,
465 pvt->tmp_prt_buffer);
Mauro Carvalho Chehab57021912010-08-27 10:22:36 -0300466 }
467
468 /* read in the 1st NON-FATAL error register */
469 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
470 FERR_NF_FBD, &value);
471 if (unlikely(value & FERR_NF_FBD_ERR_MASK)) {
472 errors = value & FERR_NF_FBD_ERR_MASK;
473 errnum = find_first_bit(&errors,
474 ARRAY_SIZE(ferr_nf_fbd_name));
475 specific = GET_ERR_FROM_TABLE(ferr_nf_fbd_name, errnum);
Mauro Carvalho Chehab57021912010-08-27 10:22:36 -0300476
477 /* Clear the error bit */
478 pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
479 FERR_GLOBAL_LO, value);
480
Mauro Carvalho Chehab32f94722010-08-27 12:13:05 -0300481 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
482 REDMEMA, &syndrome);
483
484 branch = (GET_FBD_FAT_IDX(value) == 2) ? 1 : 0;
485 pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map,
486 RECMEMA, &val16);
487 bank = RECMEMA_BANK(val16);
488 rank = RECMEMA_RANK(val16);
489
490 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
491 RECMEMB, &value);
492
493 is_wr = RECMEMB_IS_WR(value);
494 cas = RECMEMB_CAS(value);
495 ras = RECMEMB_RAS(value);
496
Mauro Carvalho Chehab37b69cf2010-08-27 15:44:43 -0300497 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
498 REDMEMB, &value);
499
500 channel = (branch << 1);
501 if (IS_SECOND_CH(value))
502 channel++;
503
Mauro Carvalho Chehab32f94722010-08-27 12:13:05 -0300504 /* Form out message */
505 snprintf(pvt->tmp_prt_buffer, PAGE_SIZE,
Mauro Carvalho Chehab37b69cf2010-08-27 15:44:43 -0300506 "Corrected error (Branch=%d, Channel %d), "
Mauro Carvalho Chehab32f94722010-08-27 12:13:05 -0300507 " DRAM-Bank=%d %s "
508 "RAS=%d CAS=%d, CE Err=0x%lx, Syndrome=0x%08x(%s))",
Mauro Carvalho Chehab37b69cf2010-08-27 15:44:43 -0300509 branch, channel,
Mauro Carvalho Chehab32f94722010-08-27 12:13:05 -0300510 bank,
511 is_wr ? "RDWR" : "RD",
512 ras, cas,
513 errors, syndrome, specific);
514
515 /*
516 * Call the helper to output message
517 * NOTE: Errors are reported per-branch, and not per-channel
518 * Currently, we don't know how to identify the right
519 * channel.
520 */
Mauro Carvalho Chehab37b69cf2010-08-27 15:44:43 -0300521 edac_mc_handle_fbd_ce(mci, rank, channel,
Mauro Carvalho Chehab32f94722010-08-27 12:13:05 -0300522 pvt->tmp_prt_buffer);
Mauro Carvalho Chehab57021912010-08-27 10:22:36 -0300523 }
524 return;
Mauro Carvalho Chehab57021912010-08-27 10:22:36 -0300525}
526
527/*
Mauro Carvalho Chehabf4277422010-08-27 10:33:25 -0300528 * i7300_check_error Retrieve the hardware error information from
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300529 * the hardware and cache it in the 'info'
530 * structure
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300531 */
Mauro Carvalho Chehabf4277422010-08-27 10:33:25 -0300532static void i7300_check_error(struct mem_ctl_info *mci)
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300533{
Mauro Carvalho Chehabf4277422010-08-27 10:33:25 -0300534 i7300_process_error_global(mci);
535 i7300_process_fbd_error(mci);
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300536};
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300537
538/*
539 * i7300_clear_error Retrieve any error from the hardware
540 * but do NOT process that error.
541 * Used for 'clearing' out of previous errors
542 * Called by the Core module.
543 */
544static void i7300_clear_error(struct mem_ctl_info *mci)
545{
Mauro Carvalho Chehabe4327602010-08-27 10:30:18 -0300546 struct i7300_pvt *pvt = mci->pvt_info;
547 u32 value;
548 /*
549 * All error values are RWC - we need to read and write 1 to the
550 * bit that we want to cleanup
551 */
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300552
Mauro Carvalho Chehabe4327602010-08-27 10:30:18 -0300553 /* Clear global error registers */
554 pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
555 FERR_GLOBAL_HI, &value);
556 pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
557 FERR_GLOBAL_HI, value);
558
559 pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
560 FERR_GLOBAL_LO, &value);
561 pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
562 FERR_GLOBAL_LO, value);
563
564 /* Clear FBD error registers */
565 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
566 FERR_FAT_FBD, &value);
567 pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
568 FERR_FAT_FBD, value);
569
570 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
571 FERR_NF_FBD, &value);
572 pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
573 FERR_NF_FBD, value);
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300574}
575
576/*
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300577 * i7300_enable_error_reporting
578 * Turn on the memory reporting features of the hardware
579 */
580static void i7300_enable_error_reporting(struct mem_ctl_info *mci)
581{
Mauro Carvalho Chehab57021912010-08-27 10:22:36 -0300582 struct i7300_pvt *pvt = mci->pvt_info;
583 u32 fbd_error_mask;
584
585 /* Read the FBD Error Mask Register */
586 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
587 EMASK_FBD, &fbd_error_mask);
588
589 /* Enable with a '0' */
590 fbd_error_mask &= ~(EMASK_FBD_ERR_MASK);
591
592 pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
593 EMASK_FBD, fbd_error_mask);
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300594}
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300595
596/************************************************
597 * i7300 Functions related to memory enumberation
598 ************************************************/
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300599
600/*
601 * determine_mtr(pvt, csrow, channel)
602 *
603 * return the proper MTR register as determine by the csrow and desired channel
604 */
605static int decode_mtr(struct i7300_pvt *pvt,
606 int slot, int ch, int branch,
607 struct i7300_dimm_info *dinfo,
608 struct csrow_info *p_csrow)
609{
610 int mtr, ans, addrBits, channel;
611
612 channel = to_channel(ch, branch);
613
614 mtr = pvt->mtr[slot][branch];
615 ans = MTR_DIMMS_PRESENT(mtr) ? 1 : 0;
616
617 debugf2("\tMTR%d CH%d: DIMMs are %s (mtr)\n",
618 slot, channel,
619 ans ? "Present" : "NOT Present");
620
621 /* Determine if there is a DIMM present in this DIMM slot */
622
623#if 0
624 if (!amb_present || !ans)
625 return 0;
626#else
627 if (!ans)
628 return 0;
629#endif
630
631 /* Start with the number of bits for a Bank
632 * on the DRAM */
633 addrBits = MTR_DRAM_BANKS_ADDR_BITS;
634 /* Add thenumber of ROW bits */
635 addrBits += MTR_DIMM_ROWS_ADDR_BITS(mtr);
636 /* add the number of COLUMN bits */
637 addrBits += MTR_DIMM_COLS_ADDR_BITS(mtr);
638 /* add the number of RANK bits */
639 addrBits += MTR_DIMM_RANKS(mtr);
640
641 addrBits += 6; /* add 64 bits per DIMM */
642 addrBits -= 20; /* divide by 2^^20 */
643 addrBits -= 3; /* 8 bits per bytes */
644
645 dinfo->megabytes = 1 << addrBits;
646
647 debugf2("\t\tWIDTH: x%d\n", MTR_DRAM_WIDTH(mtr));
648
649 debugf2("\t\tELECTRICAL THROTTLING is %s\n",
650 MTR_DIMMS_ETHROTTLE(mtr) ? "enabled" : "disabled");
651
652 debugf2("\t\tNUMBANK: %d bank(s)\n", MTR_DRAM_BANKS(mtr));
653 debugf2("\t\tNUMRANK: %s\n", MTR_DIMM_RANKS(mtr) ? "double" : "single");
654 debugf2("\t\tNUMROW: %s\n", numrow_toString[MTR_DIMM_ROWS(mtr)]);
655 debugf2("\t\tNUMCOL: %s\n", numcol_toString[MTR_DIMM_COLS(mtr)]);
656 debugf2("\t\tSIZE: %d MB\n", dinfo->megabytes);
657
658 p_csrow->grain = 8;
659 p_csrow->nr_pages = dinfo->megabytes << 8;
660 p_csrow->mtype = MEM_FB_DDR2;
Mauro Carvalho Chehab116389e2010-08-26 23:19:54 -0300661
662 /*
Mauro Carvalho Chehab15154c52010-08-27 09:16:06 -0300663 * The type of error detection actually depends of the
Mauro Carvalho Chehab116389e2010-08-26 23:19:54 -0300664 * mode of operation. When it is just one single memory chip, at
Mauro Carvalho Chehab15154c52010-08-27 09:16:06 -0300665 * socket 0, channel 0, it uses 8-byte-over-32-byte SECDED+ code.
666 * In normal or mirrored mode, it uses Lockstep mode,
Mauro Carvalho Chehab116389e2010-08-26 23:19:54 -0300667 * with the possibility of using an extended algorithm for x8 memories
668 * See datasheet Sections 7.3.6 to 7.3.8
669 */
Mauro Carvalho Chehab15154c52010-08-27 09:16:06 -0300670
671 if (IS_SINGLE_MODE(pvt->mc_settings_a)) {
672 p_csrow->edac_mode = EDAC_SECDED;
Mauro Carvalho Chehab3b330f62010-08-27 10:39:35 -0300673 debugf2("\t\tECC code is 8-byte-over-32-byte SECDED+ code\n");
Mauro Carvalho Chehab15154c52010-08-27 09:16:06 -0300674 } else {
Mauro Carvalho Chehab3b330f62010-08-27 10:39:35 -0300675 debugf2("\t\tECC code is on Lockstep mode\n");
Mauro Carvalho Chehab28c2ce72010-08-27 11:20:38 -0300676 if (MTR_DRAM_WIDTH(mtr) == 8)
Mauro Carvalho Chehab15154c52010-08-27 09:16:06 -0300677 p_csrow->edac_mode = EDAC_S8ECD8ED;
678 else
679 p_csrow->edac_mode = EDAC_S4ECD4ED;
680 }
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300681
682 /* ask what device type on this row */
Mauro Carvalho Chehab28c2ce72010-08-27 11:20:38 -0300683 if (MTR_DRAM_WIDTH(mtr) == 8) {
Mauro Carvalho Chehab3b330f62010-08-27 10:39:35 -0300684 debugf2("\t\tScrub algorithm for x8 is on %s mode\n",
Mauro Carvalho Chehabd7de2bd2010-08-27 08:56:48 -0300685 IS_SCRBALGO_ENHANCED(pvt->mc_settings) ?
686 "enhanced" : "normal");
687
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300688 p_csrow->dtype = DEV_X8;
Mauro Carvalho Chehabd7de2bd2010-08-27 08:56:48 -0300689 } else
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300690 p_csrow->dtype = DEV_X4;
691
692 return mtr;
693}
694
695/*
696 * print_dimm_size
697 *
698 * also will output a DIMM matrix map, if debug is enabled, for viewing
699 * how the DIMMs are populated
700 */
701static void print_dimm_size(struct i7300_pvt *pvt)
702{
703 struct i7300_dimm_info *dinfo;
Mauro Carvalho Chehab85580ea2010-08-27 11:36:23 -0300704 char *p;
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300705 int space, n;
706 int channel, slot;
707
708 space = PAGE_SIZE;
Mauro Carvalho Chehab85580ea2010-08-27 11:36:23 -0300709 p = pvt->tmp_prt_buffer;
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300710
711 n = snprintf(p, space, " ");
712 p += n;
713 space -= n;
714 for (channel = 0; channel < MAX_CHANNELS; channel++) {
715 n = snprintf(p, space, "channel %d | ", channel);
716 p += n;
717 space -= n;
718 }
Mauro Carvalho Chehab85580ea2010-08-27 11:36:23 -0300719 debugf2("%s\n", pvt->tmp_prt_buffer);
720 p = pvt->tmp_prt_buffer;
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300721 space = PAGE_SIZE;
722 n = snprintf(p, space, "-------------------------------"
723 "------------------------------");
724 p += n;
725 space -= n;
Mauro Carvalho Chehab85580ea2010-08-27 11:36:23 -0300726 debugf2("%s\n", pvt->tmp_prt_buffer);
727 p = pvt->tmp_prt_buffer;
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300728 space = PAGE_SIZE;
729
730 for (slot = 0; slot < MAX_SLOTS; slot++) {
731 n = snprintf(p, space, "csrow/SLOT %d ", slot);
732 p += n;
733 space -= n;
734
735 for (channel = 0; channel < MAX_CHANNELS; channel++) {
736 dinfo = &pvt->dimm_info[slot][channel];
737 n = snprintf(p, space, "%4d MB | ", dinfo->megabytes);
738 p += n;
739 space -= n;
740 }
741
Mauro Carvalho Chehab85580ea2010-08-27 11:36:23 -0300742 debugf2("%s\n", pvt->tmp_prt_buffer);
743 p = pvt->tmp_prt_buffer;
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300744 space = PAGE_SIZE;
745 }
746
747 n = snprintf(p, space, "-------------------------------"
748 "------------------------------");
749 p += n;
750 space -= n;
Mauro Carvalho Chehab85580ea2010-08-27 11:36:23 -0300751 debugf2("%s\n", pvt->tmp_prt_buffer);
752 p = pvt->tmp_prt_buffer;
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300753 space = PAGE_SIZE;
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300754}
755
756/*
757 * i7300_init_csrows Initialize the 'csrows' table within
758 * the mci control structure with the
759 * addressing of memory.
760 *
761 * return:
762 * 0 success
763 * 1 no actual memory found on this MC
764 */
765static int i7300_init_csrows(struct mem_ctl_info *mci)
766{
767 struct i7300_pvt *pvt;
768 struct i7300_dimm_info *dinfo;
769 struct csrow_info *p_csrow;
770 int empty;
771 int mtr;
772 int ch, branch, slot, channel;
773
774 pvt = mci->pvt_info;
775
776 empty = 1; /* Assume NO memory */
777
778 debugf2("Memory Technology Registers:\n");
779
780 /* Get the AMB present registers for the four channels */
781 for (branch = 0; branch < MAX_BRANCHES; branch++) {
782 /* Read and dump branch 0's MTRs */
783 channel = to_channel(0, branch);
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300784 pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch], AMBPRESENT_0,
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300785 &pvt->ambpresent[channel]);
786 debugf2("\t\tAMB-present CH%d = 0x%x:\n",
787 channel, pvt->ambpresent[channel]);
788
789 channel = to_channel(1, branch);
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300790 pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch], AMBPRESENT_1,
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300791 &pvt->ambpresent[channel]);
792 debugf2("\t\tAMB-present CH%d = 0x%x:\n",
793 channel, pvt->ambpresent[channel]);
794 }
795
796 /* Get the set of MTR[0-7] regs by each branch */
797 for (slot = 0; slot < MAX_SLOTS; slot++) {
798 int where = mtr_regs[slot];
799 for (branch = 0; branch < MAX_BRANCHES; branch++) {
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300800 pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch],
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300801 where,
802 &pvt->mtr[slot][branch]);
803 for (ch = 0; ch < MAX_BRANCHES; ch++) {
804 int channel = to_channel(ch, branch);
805
806 dinfo = &pvt->dimm_info[slot][channel];
807 p_csrow = &mci->csrows[slot];
808
809 mtr = decode_mtr(pvt, slot, ch, branch,
810 dinfo, p_csrow);
811 /* if no DIMMS on this row, continue */
812 if (!MTR_DIMMS_PRESENT(mtr))
813 continue;
814
815 p_csrow->csrow_idx = slot;
816
817 /* FAKE OUT VALUES, FIXME */
818 p_csrow->first_page = 0 + slot * 20;
819 p_csrow->last_page = 9 + slot * 20;
820 p_csrow->page_mask = 0xfff;
821
822 empty = 0;
823 }
824 }
825 }
826
827 return empty;
828}
829
830static void decode_mir(int mir_no, u16 mir[MAX_MIR])
831{
832 if (mir[mir_no] & 3)
833 debugf2("MIR%d: limit= 0x%x Branch(es) that participate: %s %s\n",
834 mir_no,
835 (mir[mir_no] >> 4) & 0xfff,
836 (mir[mir_no] & 1) ? "B0" : "",
837 (mir[mir_no] & 2) ? "B1": "");
838}
839
840/*
841 * i7300_get_mc_regs read in the necessary registers and
842 * cache locally
843 *
844 * Fills in the private data members
845 */
846static int i7300_get_mc_regs(struct mem_ctl_info *mci)
847{
848 struct i7300_pvt *pvt;
849 u32 actual_tolm;
850 int i, rc;
851
852 pvt = mci->pvt_info;
853
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300854 pci_read_config_dword(pvt->pci_dev_16_0_fsb_ctlr, AMBASE,
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300855 (u32 *) &pvt->ambase);
856
857 debugf2("AMBASE= 0x%lx\n", (long unsigned int)pvt->ambase);
858
859 /* Get the Branch Map regs */
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300860 pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, TOLM, &pvt->tolm);
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300861 pvt->tolm >>= 12;
862 debugf2("TOLM (number of 256M regions) =%u (0x%x)\n", pvt->tolm,
863 pvt->tolm);
864
865 actual_tolm = (u32) ((1000l * pvt->tolm) >> (30 - 28));
866 debugf2("Actual TOLM byte addr=%u.%03u GB (0x%x)\n",
867 actual_tolm/1000, actual_tolm % 1000, pvt->tolm << 28);
868
Mauro Carvalho Chehabaf3d8832010-08-26 20:58:45 -0300869 /* Get memory controller settings */
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300870 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, MC_SETTINGS,
Mauro Carvalho Chehabaf3d8832010-08-26 20:58:45 -0300871 &pvt->mc_settings);
Mauro Carvalho Chehabbb81a212010-08-27 09:04:11 -0300872 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, MC_SETTINGS_A,
873 &pvt->mc_settings_a);
Mauro Carvalho Chehabd7de2bd2010-08-27 08:56:48 -0300874
Mauro Carvalho Chehabbb81a212010-08-27 09:04:11 -0300875 if (IS_SINGLE_MODE(pvt->mc_settings_a))
876 debugf0("Memory controller operating on single mode\n");
877 else
878 debugf0("Memory controller operating on %s mode\n",
Mauro Carvalho Chehabd7de2bd2010-08-27 08:56:48 -0300879 IS_MIRRORED(pvt->mc_settings) ? "mirrored" : "non-mirrored");
Mauro Carvalho Chehabbb81a212010-08-27 09:04:11 -0300880
Mauro Carvalho Chehabaf3d8832010-08-26 20:58:45 -0300881 debugf0("Error detection is %s\n",
Mauro Carvalho Chehabd7de2bd2010-08-27 08:56:48 -0300882 IS_ECC_ENABLED(pvt->mc_settings) ? "enabled" : "disabled");
883 debugf0("Retry is %s\n",
884 IS_RETRY_ENABLED(pvt->mc_settings) ? "enabled" : "disabled");
Mauro Carvalho Chehabaf3d8832010-08-26 20:58:45 -0300885
886 /* Get Memory Interleave Range registers */
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300887 pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR0, &pvt->mir[0]);
888 pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR1, &pvt->mir[1]);
889 pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR2, &pvt->mir[2]);
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300890
891 /* Decode the MIR regs */
892 for (i = 0; i < MAX_MIR; i++)
893 decode_mir(i, pvt->mir);
894
895 rc = i7300_init_csrows(mci);
896 if (rc < 0)
897 return rc;
898
899 /* Go and determine the size of each DIMM and place in an
900 * orderly matrix */
901 print_dimm_size(pvt);
902
903 return 0;
904}
905
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300906/*************************************************
907 * i7300 Functions related to device probe/release
908 *************************************************/
909
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300910/*
911 * i7300_put_devices 'put' all the devices that we have
912 * reserved via 'get'
913 */
914static void i7300_put_devices(struct mem_ctl_info *mci)
915{
916 struct i7300_pvt *pvt;
917 int branch;
918
919 pvt = mci->pvt_info;
920
921 /* Decrement usage count for devices */
922 for (branch = 0; branch < MAX_CH_PER_BRANCH; branch++)
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300923 pci_dev_put(pvt->pci_dev_2x_0_fbd_branch[branch]);
924 pci_dev_put(pvt->pci_dev_16_2_fsb_err_regs);
925 pci_dev_put(pvt->pci_dev_16_1_fsb_addr_map);
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300926}
927
928/*
929 * i7300_get_devices Find and perform 'get' operation on the MCH's
930 * device/functions we want to reference for this driver
931 *
932 * Need to 'get' device 16 func 1 and func 2
933 */
934static int i7300_get_devices(struct mem_ctl_info *mci, int dev_idx)
935{
936 struct i7300_pvt *pvt;
937 struct pci_dev *pdev;
938
939 pvt = mci->pvt_info;
940
941 /* Attempt to 'get' the MCH register we want */
942 pdev = NULL;
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300943 while (!pvt->pci_dev_16_1_fsb_addr_map || !pvt->pci_dev_16_2_fsb_err_regs) {
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300944 pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
945 PCI_DEVICE_ID_INTEL_I7300_MCH_ERR, pdev);
946 if (!pdev) {
947 /* End of list, leave */
948 i7300_printk(KERN_ERR,
949 "'system address,Process Bus' "
950 "device not found:"
951 "vendor 0x%x device 0x%x ERR funcs "
952 "(broken BIOS?)\n",
953 PCI_VENDOR_ID_INTEL,
954 PCI_DEVICE_ID_INTEL_I7300_MCH_ERR);
955 goto error;
956 }
957
958 /* Store device 16 funcs 1 and 2 */
959 switch (PCI_FUNC(pdev->devfn)) {
960 case 1:
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300961 pvt->pci_dev_16_1_fsb_addr_map = pdev;
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300962 break;
963 case 2:
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300964 pvt->pci_dev_16_2_fsb_err_regs = pdev;
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300965 break;
966 }
967 }
968
969 debugf1("System Address, processor bus- PCI Bus ID: %s %x:%x\n",
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300970 pci_name(pvt->pci_dev_16_0_fsb_ctlr),
971 pvt->pci_dev_16_0_fsb_ctlr->vendor, pvt->pci_dev_16_0_fsb_ctlr->device);
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300972 debugf1("Branchmap, control and errors - PCI Bus ID: %s %x:%x\n",
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300973 pci_name(pvt->pci_dev_16_1_fsb_addr_map),
974 pvt->pci_dev_16_1_fsb_addr_map->vendor, pvt->pci_dev_16_1_fsb_addr_map->device);
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300975 debugf1("FSB Error Regs - PCI Bus ID: %s %x:%x\n",
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300976 pci_name(pvt->pci_dev_16_2_fsb_err_regs),
977 pvt->pci_dev_16_2_fsb_err_regs->vendor, pvt->pci_dev_16_2_fsb_err_regs->device);
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300978
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300979 pvt->pci_dev_2x_0_fbd_branch[0] = pci_get_device(PCI_VENDOR_ID_INTEL,
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300980 PCI_DEVICE_ID_INTEL_I7300_MCH_FB0,
981 NULL);
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300982 if (!pvt->pci_dev_2x_0_fbd_branch[0]) {
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300983 i7300_printk(KERN_ERR,
984 "MC: 'BRANCH 0' device not found:"
985 "vendor 0x%x device 0x%x Func 0 (broken BIOS?)\n",
986 PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_FB0);
987 goto error;
988 }
989
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300990 pvt->pci_dev_2x_0_fbd_branch[1] = pci_get_device(PCI_VENDOR_ID_INTEL,
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300991 PCI_DEVICE_ID_INTEL_I7300_MCH_FB1,
992 NULL);
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300993 if (!pvt->pci_dev_2x_0_fbd_branch[1]) {
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300994 i7300_printk(KERN_ERR,
995 "MC: 'BRANCH 1' device not found:"
996 "vendor 0x%x device 0x%x Func 0 "
997 "(broken BIOS?)\n",
998 PCI_VENDOR_ID_INTEL,
999 PCI_DEVICE_ID_INTEL_I7300_MCH_FB1);
1000 goto error;
1001 }
1002
1003 return 0;
1004
1005error:
1006 i7300_put_devices(mci);
1007 return -ENODEV;
1008}
1009
1010/*
1011 * i7300_probe1 Probe for ONE instance of device to see if it is
1012 * present.
1013 * return:
1014 * 0 for FOUND a device
1015 * < 0 for error code
1016 */
1017static int i7300_probe1(struct pci_dev *pdev, int dev_idx)
1018{
1019 struct mem_ctl_info *mci;
1020 struct i7300_pvt *pvt;
1021 int num_channels;
1022 int num_dimms_per_channel;
1023 int num_csrows;
1024
1025 if (dev_idx >= ARRAY_SIZE(i7300_devs))
1026 return -EINVAL;
1027
1028 debugf0("MC: " __FILE__ ": %s(), pdev bus %u dev=0x%x fn=0x%x\n",
1029 __func__,
1030 pdev->bus->number,
1031 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
1032
1033 /* We only are looking for func 0 of the set */
1034 if (PCI_FUNC(pdev->devfn) != 0)
1035 return -ENODEV;
1036
1037 /* As we don't have a motherboard identification routine to determine
1038 * actual number of slots/dimms per channel, we thus utilize the
1039 * resource as specified by the chipset. Thus, we might have
1040 * have more DIMMs per channel than actually on the mobo, but this
1041 * allows the driver to support upto the chipset max, without
1042 * some fancy mobo determination.
1043 */
1044 num_dimms_per_channel = MAX_SLOTS;
1045 num_channels = MAX_CHANNELS;
1046 num_csrows = MAX_SLOTS * MAX_CHANNELS;
1047
1048 debugf0("MC: %s(): Number of - Channels= %d DIMMS= %d CSROWS= %d\n",
1049 __func__, num_channels, num_dimms_per_channel, num_csrows);
1050
1051 /* allocate a new MC control structure */
1052 mci = edac_mc_alloc(sizeof(*pvt), num_csrows, num_channels, 0);
1053
1054 if (mci == NULL)
1055 return -ENOMEM;
1056
1057 debugf0("MC: " __FILE__ ": %s(): mci = %p\n", __func__, mci);
1058
1059 mci->dev = &pdev->dev; /* record ptr to the generic device */
1060
1061 pvt = mci->pvt_info;
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -03001062 pvt->pci_dev_16_0_fsb_ctlr = pdev; /* Record this device in our private */
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -03001063
Mauro Carvalho Chehab85580ea2010-08-27 11:36:23 -03001064 pvt->tmp_prt_buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);
1065 if (!pvt->tmp_prt_buffer) {
1066 edac_mc_free(mci);
1067 return -ENOMEM;
1068 }
1069
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -03001070 /* 'get' the pci devices we want to reserve for our use */
1071 if (i7300_get_devices(mci, dev_idx))
1072 goto fail0;
1073
1074 mci->mc_idx = 0;
1075 mci->mtype_cap = MEM_FLAG_FB_DDR2;
1076 mci->edac_ctl_cap = EDAC_FLAG_NONE;
1077 mci->edac_cap = EDAC_FLAG_NONE;
1078 mci->mod_name = "i7300_edac.c";
1079 mci->mod_ver = I7300_REVISION;
1080 mci->ctl_name = i7300_devs[dev_idx].ctl_name;
1081 mci->dev_name = pci_name(pdev);
1082 mci->ctl_page_to_phys = NULL;
1083
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -03001084 /* Set the function pointer to an actual operation function */
1085 mci->edac_check = i7300_check_error;
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -03001086
1087 /* initialize the MC control structure 'csrows' table
1088 * with the mapping and control information */
1089 if (i7300_get_mc_regs(mci)) {
1090 debugf0("MC: Setting mci->edac_cap to EDAC_FLAG_NONE\n"
1091 " because i7300_init_csrows() returned nonzero "
1092 "value\n");
1093 mci->edac_cap = EDAC_FLAG_NONE; /* no csrows found */
1094 } else {
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -03001095 debugf1("MC: Enable error reporting now\n");
1096 i7300_enable_error_reporting(mci);
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -03001097 }
1098
1099 /* add this new MC control structure to EDAC's list of MCs */
1100 if (edac_mc_add_mc(mci)) {
1101 debugf0("MC: " __FILE__
1102 ": %s(): failed edac_mc_add_mc()\n", __func__);
1103 /* FIXME: perhaps some code should go here that disables error
1104 * reporting if we just enabled it
1105 */
1106 goto fail1;
1107 }
1108
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -03001109 i7300_clear_error(mci);
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -03001110
1111 /* allocating generic PCI control info */
1112 i7300_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
1113 if (!i7300_pci) {
1114 printk(KERN_WARNING
1115 "%s(): Unable to create PCI control\n",
1116 __func__);
1117 printk(KERN_WARNING
1118 "%s(): PCI error report via EDAC not setup\n",
1119 __func__);
1120 }
1121
1122 return 0;
1123
1124 /* Error exit unwinding stack */
1125fail1:
1126
1127 i7300_put_devices(mci);
1128
1129fail0:
Mauro Carvalho Chehab85580ea2010-08-27 11:36:23 -03001130 kfree(pvt->tmp_prt_buffer);
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -03001131 edac_mc_free(mci);
1132 return -ENODEV;
1133}
1134
1135/*
1136 * i7300_init_one constructor for one instance of device
1137 *
1138 * returns:
1139 * negative on error
1140 * count (>= 0)
1141 */
1142static int __devinit i7300_init_one(struct pci_dev *pdev,
1143 const struct pci_device_id *id)
1144{
1145 int rc;
1146
1147 debugf0("MC: " __FILE__ ": %s()\n", __func__);
1148
1149 /* wake up device */
1150 rc = pci_enable_device(pdev);
1151 if (rc == -EIO)
1152 return rc;
1153
1154 /* now probe and enable the device */
1155 return i7300_probe1(pdev, id->driver_data);
1156}
1157
1158/*
1159 * i7300_remove_one destructor for one instance of device
1160 *
1161 */
1162static void __devexit i7300_remove_one(struct pci_dev *pdev)
1163{
1164 struct mem_ctl_info *mci;
Mauro Carvalho Chehab85580ea2010-08-27 11:36:23 -03001165 char *tmp;
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -03001166
1167 debugf0(__FILE__ ": %s()\n", __func__);
1168
1169 if (i7300_pci)
1170 edac_pci_release_generic_ctl(i7300_pci);
1171
1172 mci = edac_mc_del_mc(&pdev->dev);
1173 if (!mci)
1174 return;
1175
Mauro Carvalho Chehab85580ea2010-08-27 11:36:23 -03001176 tmp = ((struct i7300_pvt *)mci->pvt_info)->tmp_prt_buffer;
1177
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -03001178 /* retrieve references to resources, and free those resources */
1179 i7300_put_devices(mci);
1180
Mauro Carvalho Chehab85580ea2010-08-27 11:36:23 -03001181 kfree(tmp);
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -03001182 edac_mc_free(mci);
1183}
1184
1185/*
1186 * pci_device_id table for which devices we are looking for
1187 *
1188 * The "E500P" device is the first device supported.
1189 */
1190static const struct pci_device_id i7300_pci_tbl[] __devinitdata = {
1191 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
1192 {0,} /* 0 terminated list. */
1193};
1194
1195MODULE_DEVICE_TABLE(pci, i7300_pci_tbl);
1196
1197/*
1198 * i7300_driver pci_driver structure for this module
1199 *
1200 */
1201static struct pci_driver i7300_driver = {
1202 .name = "i7300_edac",
1203 .probe = i7300_init_one,
1204 .remove = __devexit_p(i7300_remove_one),
1205 .id_table = i7300_pci_tbl,
1206};
1207
1208/*
1209 * i7300_init Module entry function
1210 * Try to initialize this module for its devices
1211 */
1212static int __init i7300_init(void)
1213{
1214 int pci_rc;
1215
1216 debugf2("MC: " __FILE__ ": %s()\n", __func__);
1217
1218 /* Ensure that the OPSTATE is set correctly for POLL or NMI */
1219 opstate_init();
1220
1221 pci_rc = pci_register_driver(&i7300_driver);
1222
1223 return (pci_rc < 0) ? pci_rc : 0;
1224}
1225
1226/*
1227 * i7300_exit() Module exit function
1228 * Unregister the driver
1229 */
1230static void __exit i7300_exit(void)
1231{
1232 debugf2("MC: " __FILE__ ": %s()\n", __func__);
1233 pci_unregister_driver(&i7300_driver);
1234}
1235
1236module_init(i7300_init);
1237module_exit(i7300_exit);
1238
1239MODULE_LICENSE("GPL");
1240MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
1241MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
1242MODULE_DESCRIPTION("MC Driver for Intel I7300 memory controllers - "
1243 I7300_REVISION);
1244
1245module_param(edac_op_state, int, 0444);
1246MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");