blob: 3b6da20de4e5adc236e62af99769b0fdc424f349 [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
44/*
45 * Memory topology is organized as:
46 * Branch 0 - 2 channels: channels 0 and 1 (FDB0 PCI dev 21.0)
47 * Branch 1 - 2 channels: channels 2 and 3 (FDB1 PCI dev 22.0)
48 * Each channel can have to 8 DIMM sets (called as SLOTS)
49 * Slots should generally be filled in pairs
50 * Except on Single Channel mode of operation
51 * just slot 0/channel0 filled on this mode
52 * On normal operation mode, the two channels on a branch should be
Mauro Carvalho Chehabc3af2ea2010-08-26 19:54:51 -030053 * filled together for the same SLOT#
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -030054 * When in mirrored mode, Branch 1 replicate memory at Branch 0, so, the four
55 * channels on both branches should be filled
56 */
57
58/* Limits for i7300 */
59#define MAX_SLOTS 8
60#define MAX_BRANCHES 2
61#define MAX_CH_PER_BRANCH 2
62#define MAX_CHANNELS (MAX_CH_PER_BRANCH * MAX_BRANCHES)
63#define MAX_MIR 3
64
65#define to_channel(ch, branch) ((((branch)) << 1) | (ch))
66
67#define to_csrow(slot, ch, branch) \
68 (to_channel(ch, branch) | ((slot) << 2))
69
Mauro Carvalho Chehabc3af2ea2010-08-26 19:54:51 -030070/*
71 * I7300 devices
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -030072 * All 3 functions of Device 16 (0,1,2) share the SAME DID and
73 * uses PCI_DEVICE_ID_INTEL_I7300_MCH_ERR for device 16 (0,1,2),
74 * PCI_DEVICE_ID_INTEL_I7300_MCH_FB0 and PCI_DEVICE_ID_INTEL_I7300_MCH_FB1
75 * for device 21 (0,1).
76 */
77
Mauro Carvalho Chehabc3af2ea2010-08-26 19:54:51 -030078/****************************************************
79 * i7300 Register definitions for memory enumberation
80 ****************************************************/
81
82/*
83 * Device 16,
84 * Function 0: System Address (not documented)
85 * Function 1: Memory Branch Map, Control, Errors Register
86 */
87
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -030088 /* OFFSETS for Function 0 */
Mauro Carvalho Chehabaf3d8832010-08-26 20:58:45 -030089#define AMBASE 0x48 /* AMB Mem Mapped Reg Region Base */
90#define MAXCH 0x56 /* Max Channel Number */
91#define MAXDIMMPERCH 0x57 /* Max DIMM PER Channel Number */
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -030092
93 /* OFFSETS for Function 1 */
Mauro Carvalho Chehabaf3d8832010-08-26 20:58:45 -030094#define MC_SETTINGS 0x40
Mauro Carvalho Chehabbb81a212010-08-27 09:04:11 -030095 #define IS_MIRRORED(mc) ((mc) & (1 << 16))
96 #define IS_ECC_ENABLED(mc) ((mc) & (1 << 5))
97 #define IS_RETRY_ENABLED(mc) ((mc) & (1 << 31))
98 #define IS_SCRBALGO_ENHANCED(mc) ((mc) & (1 << 8))
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -030099
Mauro Carvalho Chehabbb81a212010-08-27 09:04:11 -0300100#define MC_SETTINGS_A 0x58
101 #define IS_SINGLE_MODE(mca) ((mca) & (1 << 14))
Mauro Carvalho Chehabd7de2bd2010-08-27 08:56:48 -0300102
Mauro Carvalho Chehabaf3d8832010-08-26 20:58:45 -0300103#define TOLM 0x6C
104#define REDMEMB 0x7C
105
106#define MIR0 0x80
107#define MIR1 0x84
108#define MIR2 0x88
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300109
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300110/*
111 * Note: Other Intel EDAC drivers use AMBPRESENT to identify if the available
112 * memory. From datasheet item 7.3.1 (FB-DIMM technology & organization), it
113 * seems that we cannot use this information directly for the same usage.
114 * Each memory slot may have up to 2 AMB interfaces, one for income and another
115 * for outcome interface to the next slot.
116 * For now, the driver just stores the AMB present registers, but rely only at
117 * the MTR info to detect memory.
118 * Datasheet is also not clear about how to map each AMBPRESENT registers to
119 * one of the 4 available channels.
120 */
121#define AMBPRESENT_0 0x64
122#define AMBPRESENT_1 0x66
123
124const static u16 mtr_regs [MAX_SLOTS] = {
125 0x80, 0x84, 0x88, 0x8c,
126 0x82, 0x86, 0x8a, 0x8e
127};
128
129/* Defines to extract the vaious fields from the
130 * MTRx - Memory Technology Registers
131 */
132#define MTR_DIMMS_PRESENT(mtr) ((mtr) & (1 << 8))
133#define MTR_DIMMS_ETHROTTLE(mtr) ((mtr) & (1 << 7))
134#define MTR_DRAM_WIDTH(mtr) (((mtr) & (1 << 6)) ? 8 : 4)
135#define MTR_DRAM_BANKS(mtr) (((mtr) & (1 << 5)) ? 8 : 4)
136#define MTR_DIMM_RANKS(mtr) (((mtr) & (1 << 4)) ? 1 : 0)
137#define MTR_DIMM_ROWS(mtr) (((mtr) >> 2) & 0x3)
138#define MTR_DRAM_BANKS_ADDR_BITS 2
139#define MTR_DIMM_ROWS_ADDR_BITS(mtr) (MTR_DIMM_ROWS(mtr) + 13)
140#define MTR_DIMM_COLS(mtr) ((mtr) & 0x3)
141#define MTR_DIMM_COLS_ADDR_BITS(mtr) (MTR_DIMM_COLS(mtr) + 10)
142
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300143#ifdef CONFIG_EDAC_DEBUG
144/* MTR NUMROW */
145static const char *numrow_toString[] = {
146 "8,192 - 13 rows",
147 "16,384 - 14 rows",
148 "32,768 - 15 rows",
149 "65,536 - 16 rows"
150};
151
152/* MTR NUMCOL */
153static const char *numcol_toString[] = {
154 "1,024 - 10 columns",
155 "2,048 - 11 columns",
156 "4,096 - 12 columns",
157 "reserved"
158};
159#endif
160
Mauro Carvalho Chehabc3af2ea2010-08-26 19:54:51 -0300161/************************************************
162 * i7300 Register definitions for error detection
163 ************************************************/
Mauro Carvalho Chehab57021912010-08-27 10:22:36 -0300164
165/*
166 * Device 16.1: FBD Error Registers
167 */
168#define FERR_FAT_FBD 0x98
169static const char *ferr_fat_fbd_name[] = {
170 [22] = "Non-Redundant Fast Reset Timeout",
171 [2] = ">Tmid Thermal event with intelligent throttling disabled",
172 [1] = "Memory or FBD configuration CRC read error",
173 [0] = "Memory Write error on non-redundant retry or "
174 "FBD configuration Write error on retry",
175};
176#define GET_FBD_FAT_IDX(fbderr) (fbderr & (3 << 28))
177#define FERR_FAT_FBD_ERR_MASK ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3))
178
179#define FERR_NF_FBD 0xa0
180static const char *ferr_nf_fbd_name[] = {
181 [24] = "DIMM-Spare Copy Completed",
182 [23] = "DIMM-Spare Copy Initiated",
183 [22] = "Redundant Fast Reset Timeout",
184 [21] = "Memory Write error on redundant retry",
185 [18] = "SPD protocol Error",
186 [17] = "FBD Northbound parity error on FBD Sync Status",
187 [16] = "Correctable Patrol Data ECC",
188 [15] = "Correctable Resilver- or Spare-Copy Data ECC",
189 [14] = "Correctable Mirrored Demand Data ECC",
190 [13] = "Correctable Non-Mirrored Demand Data ECC",
191 [11] = "Memory or FBD configuration CRC read error",
192 [10] = "FBD Configuration Write error on first attempt",
193 [9] = "Memory Write error on first attempt",
194 [8] = "Non-Aliased Uncorrectable Patrol Data ECC",
195 [7] = "Non-Aliased Uncorrectable Resilver- or Spare-Copy Data ECC",
196 [6] = "Non-Aliased Uncorrectable Mirrored Demand Data ECC",
197 [5] = "Non-Aliased Uncorrectable Non-Mirrored Demand Data ECC",
198 [4] = "Aliased Uncorrectable Patrol Data ECC",
199 [3] = "Aliased Uncorrectable Resilver- or Spare-Copy Data ECC",
200 [2] = "Aliased Uncorrectable Mirrored Demand Data ECC",
201 [1] = "Aliased Uncorrectable Non-Mirrored Demand Data ECC",
202 [0] = "Uncorrectable Data ECC on Replay",
203};
204#define GET_FBD_NF_IDX(fbderr) (fbderr & (3 << 28))
205#define FERR_NF_FBD_ERR_MASK ((1 << 24) | (1 << 23) | (1 << 22) | (1 << 21) |\
206 (1 << 18) | (1 << 17) | (1 << 16) | (1 << 15) |\
207 (1 << 14) | (1 << 13) | (1 << 11) | (1 << 10) |\
208 (1 << 9) | (1 << 8) | (1 << 7) | (1 << 6) |\
209 (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2) |\
210 (1 << 1) | (1 << 0))
211
212#define EMASK_FBD 0xa8
213#define EMASK_FBD_ERR_MASK ((1 << 27) | (1 << 26) | (1 << 25) | (1 << 24) |\
214 (1 << 22) | (1 << 21) | (1 << 20) | (1 << 19) |\
215 (1 << 18) | (1 << 17) | (1 << 16) | (1 << 14) |\
216 (1 << 13) | (1 << 12) | (1 << 11) | (1 << 10) |\
217 (1 << 9) | (1 << 8) | (1 << 7) | (1 << 6) |\
218 (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2) |\
219 (1 << 1) | (1 << 0))
220
Mauro Carvalho Chehabc3af2ea2010-08-26 19:54:51 -0300221/*
222 * Device 16.2: Global Error Registers
223 */
224
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300225#define FERR_GLOBAL_HI 0x48
226static const char *ferr_global_hi_name[] = {
227 [3] = "FSB 3 Fatal Error",
228 [2] = "FSB 2 Fatal Error",
229 [1] = "FSB 1 Fatal Error",
230 [0] = "FSB 0 Fatal Error",
231};
232#define ferr_global_hi_is_fatal(errno) 1
233
Mauro Carvalho Chehabc3af2ea2010-08-26 19:54:51 -0300234#define FERR_GLOBAL_LO 0x40
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300235static const char *ferr_global_lo_name[] = {
Mauro Carvalho Chehabc3af2ea2010-08-26 19:54:51 -0300236 [31] = "Internal MCH Fatal Error",
237 [30] = "Intel QuickData Technology Device Fatal Error",
238 [29] = "FSB1 Fatal Error",
239 [28] = "FSB0 Fatal Error",
240 [27] = "FBD Channel 3 Fatal Error",
241 [26] = "FBD Channel 2 Fatal Error",
242 [25] = "FBD Channel 1 Fatal Error",
243 [24] = "FBD Channel 0 Fatal Error",
244 [23] = "PCI Express Device 7Fatal Error",
245 [22] = "PCI Express Device 6 Fatal Error",
246 [21] = "PCI Express Device 5 Fatal Error",
247 [20] = "PCI Express Device 4 Fatal Error",
248 [19] = "PCI Express Device 3 Fatal Error",
249 [18] = "PCI Express Device 2 Fatal Error",
250 [17] = "PCI Express Device 1 Fatal Error",
251 [16] = "ESI Fatal Error",
252 [15] = "Internal MCH Non-Fatal Error",
253 [14] = "Intel QuickData Technology Device Non Fatal Error",
254 [13] = "FSB1 Non-Fatal Error",
255 [12] = "FSB 0 Non-Fatal Error",
256 [11] = "FBD Channel 3 Non-Fatal Error",
257 [10] = "FBD Channel 2 Non-Fatal Error",
258 [9] = "FBD Channel 1 Non-Fatal Error",
259 [8] = "FBD Channel 0 Non-Fatal Error",
260 [7] = "PCI Express Device 7 Non-Fatal Error",
261 [6] = "PCI Express Device 6 Non-Fatal Error",
262 [5] = "PCI Express Device 5 Non-Fatal Error",
263 [4] = "PCI Express Device 4 Non-Fatal Error",
264 [3] = "PCI Express Device 3 Non-Fatal Error",
265 [2] = "PCI Express Device 2 Non-Fatal Error",
266 [1] = "PCI Express Device 1 Non-Fatal Error",
267 [0] = "ESI Non-Fatal Error",
268};
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300269#define ferr_global_lo_is_fatal(errno) ((errno < 16) ? 0 : 1)
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300270
271/* Device name and register DID (Device ID) */
272struct i7300_dev_info {
273 const char *ctl_name; /* name for this device */
274 u16 fsb_mapping_errors; /* DID for the branchmap,control */
275};
276
277/* Table of devices attributes supported by this driver */
278static const struct i7300_dev_info i7300_devs[] = {
279 {
280 .ctl_name = "I7300",
281 .fsb_mapping_errors = PCI_DEVICE_ID_INTEL_I7300_MCH_ERR,
282 },
283};
284
285struct i7300_dimm_info {
286 int megabytes; /* size, 0 means not present */
287};
288
289/* driver private data structure */
290struct i7300_pvt {
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300291 struct pci_dev *pci_dev_16_0_fsb_ctlr; /* 16.0 */
292 struct pci_dev *pci_dev_16_1_fsb_addr_map; /* 16.1 */
293 struct pci_dev *pci_dev_16_2_fsb_err_regs; /* 16.2 */
294 struct pci_dev *pci_dev_2x_0_fbd_branch[MAX_BRANCHES]; /* 21.0 and 22.0 */
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300295
296 u16 tolm; /* top of low memory */
297 u64 ambase; /* AMB BAR */
298
Mauro Carvalho Chehabbb81a212010-08-27 09:04:11 -0300299 u32 mc_settings; /* Report several settings */
300 u32 mc_settings_a;
301
302 u16 mir[MAX_MIR]; /* Memory Interleave Reg*/
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300303
304 u16 mtr[MAX_SLOTS][MAX_BRANCHES]; /* Memory Technlogy Reg */
305 u16 ambpresent[MAX_CHANNELS]; /* AMB present regs */
306
307 /* DIMM information matrix, allocating architecture maximums */
308 struct i7300_dimm_info dimm_info[MAX_SLOTS][MAX_CHANNELS];
309};
310
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300311/* FIXME: Why do we need to have this static? */
312static struct edac_pci_ctl_info *i7300_pci;
313
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300314/********************************************
315 * i7300 Functions related to error detection
316 ********************************************/
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300317
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300318struct i7300_error_info {
319 int dummy; /* FIXME */
320};
321
322const char *get_err_from_table(const char *table[], int size, int pos)
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300323{
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300324 if (pos >= size)
325 return "Reserved";
326
327 return table[pos];
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300328}
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300329
330#define GET_ERR_FROM_TABLE(table, pos) \
331 get_err_from_table(table, ARRAY_SIZE(table), pos)
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300332
333/*
334 * i7300_get_error_info Retrieve the hardware error information from
335 * the hardware and cache it in the 'info'
336 * structure
337 */
338static void i7300_get_error_info(struct mem_ctl_info *mci,
339 struct i7300_error_info *info)
340{
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300341}
342
343/*
344 * i7300_process_error_global Retrieve the hardware error information from
345 * the hardware and cache it in the 'info'
346 * structure
347 */
348static void i7300_process_error_global(struct mem_ctl_info *mci,
349 struct i7300_error_info *info)
350{
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300351 struct i7300_pvt *pvt;
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300352 u32 errnum, value;
353 unsigned long errors;
354 const char *specific;
355 bool is_fatal;
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300356
357 pvt = mci->pvt_info;
358
359 /* read in the 1st FATAL error register */
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300360 pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
361 FERR_GLOBAL_HI, &value);
362 if (unlikely(value)) {
363 errors = value;
364 errnum = find_first_bit(&errors,
365 ARRAY_SIZE(ferr_global_hi_name));
366 specific = GET_ERR_FROM_TABLE(ferr_global_hi_name, errnum);
367 is_fatal = ferr_global_hi_is_fatal(errnum);
Mauro Carvalho Chehab86002322010-08-27 00:46:57 -0300368
369 /* Clear the error bit */
370 pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
371 FERR_GLOBAL_HI, value);
372
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300373 goto error_global;
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300374 }
375
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300376 pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
377 FERR_GLOBAL_LO, &value);
378 if (unlikely(value)) {
379 errors = value;
380 errnum = find_first_bit(&errors,
381 ARRAY_SIZE(ferr_global_lo_name));
382 specific = GET_ERR_FROM_TABLE(ferr_global_lo_name, errnum);
383 is_fatal = ferr_global_lo_is_fatal(errnum);
Mauro Carvalho Chehab86002322010-08-27 00:46:57 -0300384
385 /* Clear the error bit */
386 pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
387 FERR_GLOBAL_LO, value);
388
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300389 goto error_global;
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300390 }
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300391 return;
392
393error_global:
394 i7300_mc_printk(mci, KERN_EMERG, "%s misc error: %s\n",
395 is_fatal ? "Fatal" : "NOT fatal", specific);
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300396}
397
398/*
Mauro Carvalho Chehab57021912010-08-27 10:22:36 -0300399 * i7300_process_fbd_error Retrieve the hardware error information from
400 * the hardware and cache it in the 'info'
401 * structure
402 */
403static void i7300_process_fbd_error(struct mem_ctl_info *mci,
404 struct i7300_error_info *info)
405{
406 struct i7300_pvt *pvt;
407 u32 errnum, value;
408 int branch;
409 unsigned long errors;
410 const char *specific;
411 bool is_fatal;
412
413 pvt = mci->pvt_info;
414
415 /* read in the 1st FATAL error register */
416 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
417 FERR_FAT_FBD, &value);
418 if (unlikely(value & FERR_FAT_FBD_ERR_MASK)) {
419 errors = value & FERR_FAT_FBD_ERR_MASK ;
420 errnum = find_first_bit(&errors,
421 ARRAY_SIZE(ferr_fat_fbd_name));
422 specific = GET_ERR_FROM_TABLE(ferr_fat_fbd_name, errnum);
423 is_fatal = 1;
424
425 branch = (GET_FBD_FAT_IDX(value) == 2) ? 1 : 0;
426
427 goto error_fbd;
428 }
429
430 /* read in the 1st NON-FATAL error register */
431 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
432 FERR_NF_FBD, &value);
433 if (unlikely(value & FERR_NF_FBD_ERR_MASK)) {
434 errors = value & FERR_NF_FBD_ERR_MASK;
435 errnum = find_first_bit(&errors,
436 ARRAY_SIZE(ferr_nf_fbd_name));
437 specific = GET_ERR_FROM_TABLE(ferr_nf_fbd_name, errnum);
438 is_fatal = 0;
439
440 /* Clear the error bit */
441 pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
442 FERR_GLOBAL_LO, value);
443
444 goto error_fbd;
445 }
446 return;
447
448error_fbd:
449 i7300_mc_printk(mci, KERN_EMERG, "%s FBD error on branch %d: %s\n",
450 is_fatal ? "Fatal" : "NOT fatal", branch, specific);
451}
452
453/*
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300454 * i7300_process_error_info Retrieve the hardware error information from
455 * the hardware and cache it in the 'info'
456 * structure
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300457 */
458static void i7300_process_error_info(struct mem_ctl_info *mci,
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300459 struct i7300_error_info *info)
460{
461 i7300_process_error_global(mci, info);
Mauro Carvalho Chehab57021912010-08-27 10:22:36 -0300462 i7300_process_fbd_error(mci, info);
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300463};
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300464
465/*
466 * i7300_clear_error Retrieve any error from the hardware
467 * but do NOT process that error.
468 * Used for 'clearing' out of previous errors
469 * Called by the Core module.
470 */
471static void i7300_clear_error(struct mem_ctl_info *mci)
472{
Mauro Carvalho Chehabe4327602010-08-27 10:30:18 -0300473 struct i7300_pvt *pvt = mci->pvt_info;
474 u32 value;
475 /*
476 * All error values are RWC - we need to read and write 1 to the
477 * bit that we want to cleanup
478 */
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300479
Mauro Carvalho Chehabe4327602010-08-27 10:30:18 -0300480 /* Clear global error registers */
481 pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
482 FERR_GLOBAL_HI, &value);
483 pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
484 FERR_GLOBAL_HI, value);
485
486 pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
487 FERR_GLOBAL_LO, &value);
488 pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
489 FERR_GLOBAL_LO, value);
490
491 /* Clear FBD error registers */
492 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
493 FERR_FAT_FBD, &value);
494 pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
495 FERR_FAT_FBD, value);
496
497 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
498 FERR_NF_FBD, &value);
499 pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
500 FERR_NF_FBD, value);
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300501}
502
503/*
504 * i7300_check_error Retrieve and process errors reported by the
505 * hardware. Called by the Core module.
506 */
507static void i7300_check_error(struct mem_ctl_info *mci)
508{
509 struct i7300_error_info info;
510 debugf4("MC%d: " __FILE__ ": %s()\n", mci->mc_idx, __func__);
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300511
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300512 i7300_get_error_info(mci, &info);
513 i7300_process_error_info(mci, &info);
514}
515
516/*
517 * i7300_enable_error_reporting
518 * Turn on the memory reporting features of the hardware
519 */
520static void i7300_enable_error_reporting(struct mem_ctl_info *mci)
521{
Mauro Carvalho Chehab57021912010-08-27 10:22:36 -0300522 struct i7300_pvt *pvt = mci->pvt_info;
523 u32 fbd_error_mask;
524
525 /* Read the FBD Error Mask Register */
526 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
527 EMASK_FBD, &fbd_error_mask);
528
529 /* Enable with a '0' */
530 fbd_error_mask &= ~(EMASK_FBD_ERR_MASK);
531
532 pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
533 EMASK_FBD, fbd_error_mask);
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300534}
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300535
536/************************************************
537 * i7300 Functions related to memory enumberation
538 ************************************************/
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300539
540/*
541 * determine_mtr(pvt, csrow, channel)
542 *
543 * return the proper MTR register as determine by the csrow and desired channel
544 */
545static int decode_mtr(struct i7300_pvt *pvt,
546 int slot, int ch, int branch,
547 struct i7300_dimm_info *dinfo,
548 struct csrow_info *p_csrow)
549{
550 int mtr, ans, addrBits, channel;
551
552 channel = to_channel(ch, branch);
553
554 mtr = pvt->mtr[slot][branch];
555 ans = MTR_DIMMS_PRESENT(mtr) ? 1 : 0;
556
557 debugf2("\tMTR%d CH%d: DIMMs are %s (mtr)\n",
558 slot, channel,
559 ans ? "Present" : "NOT Present");
560
561 /* Determine if there is a DIMM present in this DIMM slot */
562
563#if 0
564 if (!amb_present || !ans)
565 return 0;
566#else
567 if (!ans)
568 return 0;
569#endif
570
571 /* Start with the number of bits for a Bank
572 * on the DRAM */
573 addrBits = MTR_DRAM_BANKS_ADDR_BITS;
574 /* Add thenumber of ROW bits */
575 addrBits += MTR_DIMM_ROWS_ADDR_BITS(mtr);
576 /* add the number of COLUMN bits */
577 addrBits += MTR_DIMM_COLS_ADDR_BITS(mtr);
578 /* add the number of RANK bits */
579 addrBits += MTR_DIMM_RANKS(mtr);
580
581 addrBits += 6; /* add 64 bits per DIMM */
582 addrBits -= 20; /* divide by 2^^20 */
583 addrBits -= 3; /* 8 bits per bytes */
584
585 dinfo->megabytes = 1 << addrBits;
586
587 debugf2("\t\tWIDTH: x%d\n", MTR_DRAM_WIDTH(mtr));
588
589 debugf2("\t\tELECTRICAL THROTTLING is %s\n",
590 MTR_DIMMS_ETHROTTLE(mtr) ? "enabled" : "disabled");
591
592 debugf2("\t\tNUMBANK: %d bank(s)\n", MTR_DRAM_BANKS(mtr));
593 debugf2("\t\tNUMRANK: %s\n", MTR_DIMM_RANKS(mtr) ? "double" : "single");
594 debugf2("\t\tNUMROW: %s\n", numrow_toString[MTR_DIMM_ROWS(mtr)]);
595 debugf2("\t\tNUMCOL: %s\n", numcol_toString[MTR_DIMM_COLS(mtr)]);
596 debugf2("\t\tSIZE: %d MB\n", dinfo->megabytes);
597
598 p_csrow->grain = 8;
599 p_csrow->nr_pages = dinfo->megabytes << 8;
600 p_csrow->mtype = MEM_FB_DDR2;
Mauro Carvalho Chehab116389e2010-08-26 23:19:54 -0300601
602 /*
Mauro Carvalho Chehab15154c52010-08-27 09:16:06 -0300603 * The type of error detection actually depends of the
Mauro Carvalho Chehab116389e2010-08-26 23:19:54 -0300604 * mode of operation. When it is just one single memory chip, at
Mauro Carvalho Chehab15154c52010-08-27 09:16:06 -0300605 * socket 0, channel 0, it uses 8-byte-over-32-byte SECDED+ code.
606 * In normal or mirrored mode, it uses Lockstep mode,
Mauro Carvalho Chehab116389e2010-08-26 23:19:54 -0300607 * with the possibility of using an extended algorithm for x8 memories
608 * See datasheet Sections 7.3.6 to 7.3.8
609 */
Mauro Carvalho Chehab15154c52010-08-27 09:16:06 -0300610
611 if (IS_SINGLE_MODE(pvt->mc_settings_a)) {
612 p_csrow->edac_mode = EDAC_SECDED;
613 debugf0("ECC code is 8-byte-over-32-byte SECDED+ code\n");
614 } else {
615 debugf0("ECC code is on Lockstep mode\n");
616 if (MTR_DRAM_WIDTH(mtr))
617 p_csrow->edac_mode = EDAC_S8ECD8ED;
618 else
619 p_csrow->edac_mode = EDAC_S4ECD4ED;
620 }
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300621
622 /* ask what device type on this row */
Mauro Carvalho Chehabd7de2bd2010-08-27 08:56:48 -0300623 if (MTR_DRAM_WIDTH(mtr)) {
624 debugf0("Scrub algorithm for x8 is on %s mode\n",
625 IS_SCRBALGO_ENHANCED(pvt->mc_settings) ?
626 "enhanced" : "normal");
627
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300628 p_csrow->dtype = DEV_X8;
Mauro Carvalho Chehabd7de2bd2010-08-27 08:56:48 -0300629 } else
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300630 p_csrow->dtype = DEV_X4;
631
632 return mtr;
633}
634
635/*
636 * print_dimm_size
637 *
638 * also will output a DIMM matrix map, if debug is enabled, for viewing
639 * how the DIMMs are populated
640 */
641static void print_dimm_size(struct i7300_pvt *pvt)
642{
643 struct i7300_dimm_info *dinfo;
644 char *p, *mem_buffer;
645 int space, n;
646 int channel, slot;
647
648 space = PAGE_SIZE;
649 mem_buffer = p = kmalloc(space, GFP_KERNEL);
650 if (p == NULL) {
651 i7300_printk(KERN_ERR, "MC: %s:%s() kmalloc() failed\n",
652 __FILE__, __func__);
653 return;
654 }
655
656 n = snprintf(p, space, " ");
657 p += n;
658 space -= n;
659 for (channel = 0; channel < MAX_CHANNELS; channel++) {
660 n = snprintf(p, space, "channel %d | ", channel);
661 p += n;
662 space -= n;
663 }
664 debugf2("%s\n", mem_buffer);
665 p = mem_buffer;
666 space = PAGE_SIZE;
667 n = snprintf(p, space, "-------------------------------"
668 "------------------------------");
669 p += n;
670 space -= n;
671 debugf2("%s\n", mem_buffer);
672 p = mem_buffer;
673 space = PAGE_SIZE;
674
675 for (slot = 0; slot < MAX_SLOTS; slot++) {
676 n = snprintf(p, space, "csrow/SLOT %d ", slot);
677 p += n;
678 space -= n;
679
680 for (channel = 0; channel < MAX_CHANNELS; channel++) {
681 dinfo = &pvt->dimm_info[slot][channel];
682 n = snprintf(p, space, "%4d MB | ", dinfo->megabytes);
683 p += n;
684 space -= n;
685 }
686
687 debugf2("%s\n", mem_buffer);
688 p = mem_buffer;
689 space = PAGE_SIZE;
690 }
691
692 n = snprintf(p, space, "-------------------------------"
693 "------------------------------");
694 p += n;
695 space -= n;
696 debugf2("%s\n", mem_buffer);
697 p = mem_buffer;
698 space = PAGE_SIZE;
699
700 kfree(mem_buffer);
701}
702
703/*
704 * i7300_init_csrows Initialize the 'csrows' table within
705 * the mci control structure with the
706 * addressing of memory.
707 *
708 * return:
709 * 0 success
710 * 1 no actual memory found on this MC
711 */
712static int i7300_init_csrows(struct mem_ctl_info *mci)
713{
714 struct i7300_pvt *pvt;
715 struct i7300_dimm_info *dinfo;
716 struct csrow_info *p_csrow;
717 int empty;
718 int mtr;
719 int ch, branch, slot, channel;
720
721 pvt = mci->pvt_info;
722
723 empty = 1; /* Assume NO memory */
724
725 debugf2("Memory Technology Registers:\n");
726
727 /* Get the AMB present registers for the four channels */
728 for (branch = 0; branch < MAX_BRANCHES; branch++) {
729 /* Read and dump branch 0's MTRs */
730 channel = to_channel(0, branch);
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300731 pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch], AMBPRESENT_0,
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300732 &pvt->ambpresent[channel]);
733 debugf2("\t\tAMB-present CH%d = 0x%x:\n",
734 channel, pvt->ambpresent[channel]);
735
736 channel = to_channel(1, branch);
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300737 pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch], AMBPRESENT_1,
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300738 &pvt->ambpresent[channel]);
739 debugf2("\t\tAMB-present CH%d = 0x%x:\n",
740 channel, pvt->ambpresent[channel]);
741 }
742
743 /* Get the set of MTR[0-7] regs by each branch */
744 for (slot = 0; slot < MAX_SLOTS; slot++) {
745 int where = mtr_regs[slot];
746 for (branch = 0; branch < MAX_BRANCHES; branch++) {
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300747 pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch],
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300748 where,
749 &pvt->mtr[slot][branch]);
750 for (ch = 0; ch < MAX_BRANCHES; ch++) {
751 int channel = to_channel(ch, branch);
752
753 dinfo = &pvt->dimm_info[slot][channel];
754 p_csrow = &mci->csrows[slot];
755
756 mtr = decode_mtr(pvt, slot, ch, branch,
757 dinfo, p_csrow);
758 /* if no DIMMS on this row, continue */
759 if (!MTR_DIMMS_PRESENT(mtr))
760 continue;
761
762 p_csrow->csrow_idx = slot;
763
764 /* FAKE OUT VALUES, FIXME */
765 p_csrow->first_page = 0 + slot * 20;
766 p_csrow->last_page = 9 + slot * 20;
767 p_csrow->page_mask = 0xfff;
768
769 empty = 0;
770 }
771 }
772 }
773
774 return empty;
775}
776
777static void decode_mir(int mir_no, u16 mir[MAX_MIR])
778{
779 if (mir[mir_no] & 3)
780 debugf2("MIR%d: limit= 0x%x Branch(es) that participate: %s %s\n",
781 mir_no,
782 (mir[mir_no] >> 4) & 0xfff,
783 (mir[mir_no] & 1) ? "B0" : "",
784 (mir[mir_no] & 2) ? "B1": "");
785}
786
787/*
788 * i7300_get_mc_regs read in the necessary registers and
789 * cache locally
790 *
791 * Fills in the private data members
792 */
793static int i7300_get_mc_regs(struct mem_ctl_info *mci)
794{
795 struct i7300_pvt *pvt;
796 u32 actual_tolm;
797 int i, rc;
798
799 pvt = mci->pvt_info;
800
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300801 pci_read_config_dword(pvt->pci_dev_16_0_fsb_ctlr, AMBASE,
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300802 (u32 *) &pvt->ambase);
803
804 debugf2("AMBASE= 0x%lx\n", (long unsigned int)pvt->ambase);
805
806 /* Get the Branch Map regs */
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300807 pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, TOLM, &pvt->tolm);
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300808 pvt->tolm >>= 12;
809 debugf2("TOLM (number of 256M regions) =%u (0x%x)\n", pvt->tolm,
810 pvt->tolm);
811
812 actual_tolm = (u32) ((1000l * pvt->tolm) >> (30 - 28));
813 debugf2("Actual TOLM byte addr=%u.%03u GB (0x%x)\n",
814 actual_tolm/1000, actual_tolm % 1000, pvt->tolm << 28);
815
Mauro Carvalho Chehabaf3d8832010-08-26 20:58:45 -0300816 /* Get memory controller settings */
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300817 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, MC_SETTINGS,
Mauro Carvalho Chehabaf3d8832010-08-26 20:58:45 -0300818 &pvt->mc_settings);
Mauro Carvalho Chehabbb81a212010-08-27 09:04:11 -0300819 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, MC_SETTINGS_A,
820 &pvt->mc_settings_a);
Mauro Carvalho Chehabd7de2bd2010-08-27 08:56:48 -0300821
Mauro Carvalho Chehabbb81a212010-08-27 09:04:11 -0300822 if (IS_SINGLE_MODE(pvt->mc_settings_a))
823 debugf0("Memory controller operating on single mode\n");
824 else
825 debugf0("Memory controller operating on %s mode\n",
Mauro Carvalho Chehabd7de2bd2010-08-27 08:56:48 -0300826 IS_MIRRORED(pvt->mc_settings) ? "mirrored" : "non-mirrored");
Mauro Carvalho Chehabbb81a212010-08-27 09:04:11 -0300827
Mauro Carvalho Chehabaf3d8832010-08-26 20:58:45 -0300828 debugf0("Error detection is %s\n",
Mauro Carvalho Chehabd7de2bd2010-08-27 08:56:48 -0300829 IS_ECC_ENABLED(pvt->mc_settings) ? "enabled" : "disabled");
830 debugf0("Retry is %s\n",
831 IS_RETRY_ENABLED(pvt->mc_settings) ? "enabled" : "disabled");
Mauro Carvalho Chehabaf3d8832010-08-26 20:58:45 -0300832
833 /* Get Memory Interleave Range registers */
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300834 pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR0, &pvt->mir[0]);
835 pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR1, &pvt->mir[1]);
836 pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR2, &pvt->mir[2]);
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300837
838 /* Decode the MIR regs */
839 for (i = 0; i < MAX_MIR; i++)
840 decode_mir(i, pvt->mir);
841
842 rc = i7300_init_csrows(mci);
843 if (rc < 0)
844 return rc;
845
846 /* Go and determine the size of each DIMM and place in an
847 * orderly matrix */
848 print_dimm_size(pvt);
849
850 return 0;
851}
852
Mauro Carvalho Chehab5de6e072010-08-27 00:16:12 -0300853/*************************************************
854 * i7300 Functions related to device probe/release
855 *************************************************/
856
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300857/*
858 * i7300_put_devices 'put' all the devices that we have
859 * reserved via 'get'
860 */
861static void i7300_put_devices(struct mem_ctl_info *mci)
862{
863 struct i7300_pvt *pvt;
864 int branch;
865
866 pvt = mci->pvt_info;
867
868 /* Decrement usage count for devices */
869 for (branch = 0; branch < MAX_CH_PER_BRANCH; branch++)
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300870 pci_dev_put(pvt->pci_dev_2x_0_fbd_branch[branch]);
871 pci_dev_put(pvt->pci_dev_16_2_fsb_err_regs);
872 pci_dev_put(pvt->pci_dev_16_1_fsb_addr_map);
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300873}
874
875/*
876 * i7300_get_devices Find and perform 'get' operation on the MCH's
877 * device/functions we want to reference for this driver
878 *
879 * Need to 'get' device 16 func 1 and func 2
880 */
881static int i7300_get_devices(struct mem_ctl_info *mci, int dev_idx)
882{
883 struct i7300_pvt *pvt;
884 struct pci_dev *pdev;
885
886 pvt = mci->pvt_info;
887
888 /* Attempt to 'get' the MCH register we want */
889 pdev = NULL;
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300890 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 -0300891 pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
892 PCI_DEVICE_ID_INTEL_I7300_MCH_ERR, pdev);
893 if (!pdev) {
894 /* End of list, leave */
895 i7300_printk(KERN_ERR,
896 "'system address,Process Bus' "
897 "device not found:"
898 "vendor 0x%x device 0x%x ERR funcs "
899 "(broken BIOS?)\n",
900 PCI_VENDOR_ID_INTEL,
901 PCI_DEVICE_ID_INTEL_I7300_MCH_ERR);
902 goto error;
903 }
904
905 /* Store device 16 funcs 1 and 2 */
906 switch (PCI_FUNC(pdev->devfn)) {
907 case 1:
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300908 pvt->pci_dev_16_1_fsb_addr_map = pdev;
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300909 break;
910 case 2:
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300911 pvt->pci_dev_16_2_fsb_err_regs = pdev;
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300912 break;
913 }
914 }
915
916 debugf1("System Address, processor bus- PCI Bus ID: %s %x:%x\n",
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300917 pci_name(pvt->pci_dev_16_0_fsb_ctlr),
918 pvt->pci_dev_16_0_fsb_ctlr->vendor, pvt->pci_dev_16_0_fsb_ctlr->device);
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300919 debugf1("Branchmap, control and errors - PCI Bus ID: %s %x:%x\n",
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300920 pci_name(pvt->pci_dev_16_1_fsb_addr_map),
921 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 -0300922 debugf1("FSB Error Regs - PCI Bus ID: %s %x:%x\n",
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300923 pci_name(pvt->pci_dev_16_2_fsb_err_regs),
924 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 -0300925
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300926 pvt->pci_dev_2x_0_fbd_branch[0] = pci_get_device(PCI_VENDOR_ID_INTEL,
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300927 PCI_DEVICE_ID_INTEL_I7300_MCH_FB0,
928 NULL);
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300929 if (!pvt->pci_dev_2x_0_fbd_branch[0]) {
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300930 i7300_printk(KERN_ERR,
931 "MC: 'BRANCH 0' device not found:"
932 "vendor 0x%x device 0x%x Func 0 (broken BIOS?)\n",
933 PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_FB0);
934 goto error;
935 }
936
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300937 pvt->pci_dev_2x_0_fbd_branch[1] = pci_get_device(PCI_VENDOR_ID_INTEL,
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300938 PCI_DEVICE_ID_INTEL_I7300_MCH_FB1,
939 NULL);
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -0300940 if (!pvt->pci_dev_2x_0_fbd_branch[1]) {
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -0300941 i7300_printk(KERN_ERR,
942 "MC: 'BRANCH 1' device not found:"
943 "vendor 0x%x device 0x%x Func 0 "
944 "(broken BIOS?)\n",
945 PCI_VENDOR_ID_INTEL,
946 PCI_DEVICE_ID_INTEL_I7300_MCH_FB1);
947 goto error;
948 }
949
950 return 0;
951
952error:
953 i7300_put_devices(mci);
954 return -ENODEV;
955}
956
957/*
958 * i7300_probe1 Probe for ONE instance of device to see if it is
959 * present.
960 * return:
961 * 0 for FOUND a device
962 * < 0 for error code
963 */
964static int i7300_probe1(struct pci_dev *pdev, int dev_idx)
965{
966 struct mem_ctl_info *mci;
967 struct i7300_pvt *pvt;
968 int num_channels;
969 int num_dimms_per_channel;
970 int num_csrows;
971
972 if (dev_idx >= ARRAY_SIZE(i7300_devs))
973 return -EINVAL;
974
975 debugf0("MC: " __FILE__ ": %s(), pdev bus %u dev=0x%x fn=0x%x\n",
976 __func__,
977 pdev->bus->number,
978 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
979
980 /* We only are looking for func 0 of the set */
981 if (PCI_FUNC(pdev->devfn) != 0)
982 return -ENODEV;
983
984 /* As we don't have a motherboard identification routine to determine
985 * actual number of slots/dimms per channel, we thus utilize the
986 * resource as specified by the chipset. Thus, we might have
987 * have more DIMMs per channel than actually on the mobo, but this
988 * allows the driver to support upto the chipset max, without
989 * some fancy mobo determination.
990 */
991 num_dimms_per_channel = MAX_SLOTS;
992 num_channels = MAX_CHANNELS;
993 num_csrows = MAX_SLOTS * MAX_CHANNELS;
994
995 debugf0("MC: %s(): Number of - Channels= %d DIMMS= %d CSROWS= %d\n",
996 __func__, num_channels, num_dimms_per_channel, num_csrows);
997
998 /* allocate a new MC control structure */
999 mci = edac_mc_alloc(sizeof(*pvt), num_csrows, num_channels, 0);
1000
1001 if (mci == NULL)
1002 return -ENOMEM;
1003
1004 debugf0("MC: " __FILE__ ": %s(): mci = %p\n", __func__, mci);
1005
1006 mci->dev = &pdev->dev; /* record ptr to the generic device */
1007
1008 pvt = mci->pvt_info;
Mauro Carvalho Chehab3e57eef2010-08-26 23:38:11 -03001009 pvt->pci_dev_16_0_fsb_ctlr = pdev; /* Record this device in our private */
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -03001010
1011 /* 'get' the pci devices we want to reserve for our use */
1012 if (i7300_get_devices(mci, dev_idx))
1013 goto fail0;
1014
1015 mci->mc_idx = 0;
1016 mci->mtype_cap = MEM_FLAG_FB_DDR2;
1017 mci->edac_ctl_cap = EDAC_FLAG_NONE;
1018 mci->edac_cap = EDAC_FLAG_NONE;
1019 mci->mod_name = "i7300_edac.c";
1020 mci->mod_ver = I7300_REVISION;
1021 mci->ctl_name = i7300_devs[dev_idx].ctl_name;
1022 mci->dev_name = pci_name(pdev);
1023 mci->ctl_page_to_phys = NULL;
1024
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -03001025 /* Set the function pointer to an actual operation function */
1026 mci->edac_check = i7300_check_error;
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -03001027
1028 /* initialize the MC control structure 'csrows' table
1029 * with the mapping and control information */
1030 if (i7300_get_mc_regs(mci)) {
1031 debugf0("MC: Setting mci->edac_cap to EDAC_FLAG_NONE\n"
1032 " because i7300_init_csrows() returned nonzero "
1033 "value\n");
1034 mci->edac_cap = EDAC_FLAG_NONE; /* no csrows found */
1035 } else {
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -03001036 debugf1("MC: Enable error reporting now\n");
1037 i7300_enable_error_reporting(mci);
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -03001038 }
1039
1040 /* add this new MC control structure to EDAC's list of MCs */
1041 if (edac_mc_add_mc(mci)) {
1042 debugf0("MC: " __FILE__
1043 ": %s(): failed edac_mc_add_mc()\n", __func__);
1044 /* FIXME: perhaps some code should go here that disables error
1045 * reporting if we just enabled it
1046 */
1047 goto fail1;
1048 }
1049
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -03001050 i7300_clear_error(mci);
Mauro Carvalho Chehabfcaf7802010-08-24 23:22:57 -03001051
1052 /* allocating generic PCI control info */
1053 i7300_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
1054 if (!i7300_pci) {
1055 printk(KERN_WARNING
1056 "%s(): Unable to create PCI control\n",
1057 __func__);
1058 printk(KERN_WARNING
1059 "%s(): PCI error report via EDAC not setup\n",
1060 __func__);
1061 }
1062
1063 return 0;
1064
1065 /* Error exit unwinding stack */
1066fail1:
1067
1068 i7300_put_devices(mci);
1069
1070fail0:
1071 edac_mc_free(mci);
1072 return -ENODEV;
1073}
1074
1075/*
1076 * i7300_init_one constructor for one instance of device
1077 *
1078 * returns:
1079 * negative on error
1080 * count (>= 0)
1081 */
1082static int __devinit i7300_init_one(struct pci_dev *pdev,
1083 const struct pci_device_id *id)
1084{
1085 int rc;
1086
1087 debugf0("MC: " __FILE__ ": %s()\n", __func__);
1088
1089 /* wake up device */
1090 rc = pci_enable_device(pdev);
1091 if (rc == -EIO)
1092 return rc;
1093
1094 /* now probe and enable the device */
1095 return i7300_probe1(pdev, id->driver_data);
1096}
1097
1098/*
1099 * i7300_remove_one destructor for one instance of device
1100 *
1101 */
1102static void __devexit i7300_remove_one(struct pci_dev *pdev)
1103{
1104 struct mem_ctl_info *mci;
1105
1106 debugf0(__FILE__ ": %s()\n", __func__);
1107
1108 if (i7300_pci)
1109 edac_pci_release_generic_ctl(i7300_pci);
1110
1111 mci = edac_mc_del_mc(&pdev->dev);
1112 if (!mci)
1113 return;
1114
1115 /* retrieve references to resources, and free those resources */
1116 i7300_put_devices(mci);
1117
1118 edac_mc_free(mci);
1119}
1120
1121/*
1122 * pci_device_id table for which devices we are looking for
1123 *
1124 * The "E500P" device is the first device supported.
1125 */
1126static const struct pci_device_id i7300_pci_tbl[] __devinitdata = {
1127 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
1128 {0,} /* 0 terminated list. */
1129};
1130
1131MODULE_DEVICE_TABLE(pci, i7300_pci_tbl);
1132
1133/*
1134 * i7300_driver pci_driver structure for this module
1135 *
1136 */
1137static struct pci_driver i7300_driver = {
1138 .name = "i7300_edac",
1139 .probe = i7300_init_one,
1140 .remove = __devexit_p(i7300_remove_one),
1141 .id_table = i7300_pci_tbl,
1142};
1143
1144/*
1145 * i7300_init Module entry function
1146 * Try to initialize this module for its devices
1147 */
1148static int __init i7300_init(void)
1149{
1150 int pci_rc;
1151
1152 debugf2("MC: " __FILE__ ": %s()\n", __func__);
1153
1154 /* Ensure that the OPSTATE is set correctly for POLL or NMI */
1155 opstate_init();
1156
1157 pci_rc = pci_register_driver(&i7300_driver);
1158
1159 return (pci_rc < 0) ? pci_rc : 0;
1160}
1161
1162/*
1163 * i7300_exit() Module exit function
1164 * Unregister the driver
1165 */
1166static void __exit i7300_exit(void)
1167{
1168 debugf2("MC: " __FILE__ ": %s()\n", __func__);
1169 pci_unregister_driver(&i7300_driver);
1170}
1171
1172module_init(i7300_init);
1173module_exit(i7300_exit);
1174
1175MODULE_LICENSE("GPL");
1176MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
1177MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
1178MODULE_DESCRIPTION("MC Driver for Intel I7300 memory controllers - "
1179 I7300_REVISION);
1180
1181module_param(edac_op_state, int, 0444);
1182MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");