blob: b5dbc2b8396169aff093c3fb1986f7db0e0ad61a [file] [log] [blame]
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -03001/* Intel 7 core Memory Controller kernel module (Nehalem)
2 *
3 * This file may be distributed under the terms of the
4 * GNU General Public License version 2 only.
5 *
6 * Copyright (c) 2009 by:
7 * Mauro Carvalho Chehab <mchehab@redhat.com>
8 *
9 * Red Hat Inc. http://www.redhat.com
10 *
11 * Forked and adapted from the i5400_edac driver
12 *
13 * Based on the following public Intel datasheets:
14 * Intel Core i7 Processor Extreme Edition and Intel Core i7 Processor
15 * Datasheet, Volume 2:
16 * http://download.intel.com/design/processor/datashts/320835.pdf
17 * Intel Xeon Processor 5500 Series Datasheet Volume 2
18 * http://www.intel.com/Assets/PDF/datasheet/321322.pdf
19 * also available at:
20 * http://www.arrownac.com/manufacturers/intel/s/nehalem/5500-datasheet-v2.pdf
21 */
22
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -030023#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/pci.h>
26#include <linux/pci_ids.h>
27#include <linux/slab.h>
28#include <linux/edac.h>
29#include <linux/mmzone.h>
30
31#include "edac_core.h"
32
Mauro Carvalho Chehab7b029d02009-06-22 22:48:29 -030033/* To use the new pci_[read/write]_config_qword instead of two dword */
34#define USE_QWORD 1
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -030035
36/*
37 * Alter this version for the module when modifications are made
38 */
39#define I7CORE_REVISION " Ver: 1.0.0 " __DATE__
40#define EDAC_MOD_STR "i7core_edac"
41
42/* HACK: temporary, just to enable all logs, for now */
43#undef debugf0
44#define debugf0(fmt, arg...) edac_printk(KERN_INFO, "i7core", fmt, ##arg)
45
46/*
47 * Debug macros
48 */
49#define i7core_printk(level, fmt, arg...) \
50 edac_printk(level, "i7core", fmt, ##arg)
51
52#define i7core_mc_printk(mci, level, fmt, arg...) \
53 edac_mc_chipset_printk(mci, level, "i7core", fmt, ##arg)
54
55/*
56 * i7core Memory Controller Registers
57 */
58
59 /* OFFSETS for Device 3 Function 0 */
60
61#define MC_CONTROL 0x48
62#define MC_STATUS 0x4c
63#define MC_MAX_DOD 0x64
64
Mauro Carvalho Chehab442305b2009-06-22 22:48:29 -030065/*
66 * OFFSETS for Device 3 Function 4, as inicated on Xeon 5500 datasheet:
67 * http://www.arrownac.com/manufacturers/intel/s/nehalem/5500-datasheet-v2.pdf
68 */
69
70#define MC_TEST_ERR_RCV1 0x60
71 #define DIMM2_COR_ERR(r) ((r) & 0x7fff)
72
73#define MC_TEST_ERR_RCV0 0x64
74 #define DIMM1_COR_ERR(r) (((r) >> 16) & 0x7fff)
75 #define DIMM0_COR_ERR(r) ((r) & 0x7fff)
76
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -030077 /* OFFSETS for Devices 4,5 and 6 Function 0 */
78
Mauro Carvalho Chehab0b2b7b72009-06-22 22:48:29 -030079#define MC_CHANNEL_DIMM_INIT_PARAMS 0x58
80 #define THREE_DIMMS_PRESENT (1 << 24)
81 #define SINGLE_QUAD_RANK_PRESENT (1 << 23)
82 #define QUAD_RANK_PRESENT (1 << 22)
83 #define REGISTERED_DIMM (1 << 15)
84
Mauro Carvalho Chehabf122a892009-06-22 22:48:29 -030085#define MC_CHANNEL_MAPPER 0x60
86 #define RDLCH(r, ch) ((((r) >> (3 + (ch * 6))) & 0x07) - 1)
87 #define WRLCH(r, ch) ((((r) >> (ch * 6)) & 0x07) - 1)
88
Mauro Carvalho Chehab0b2b7b72009-06-22 22:48:29 -030089#define MC_CHANNEL_RANK_PRESENT 0x7c
90 #define RANK_PRESENT_MASK 0xffff
91
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -030092#define MC_CHANNEL_ADDR_MATCH 0xf0
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -030093#define MC_CHANNEL_ERROR_MASK 0xf8
94#define MC_CHANNEL_ERROR_INJECT 0xfc
95 #define INJECT_ADDR_PARITY 0x10
96 #define INJECT_ECC 0x08
97 #define MASK_CACHELINE 0x06
98 #define MASK_FULL_CACHELINE 0x06
99 #define MASK_MSB32_CACHELINE 0x04
100 #define MASK_LSB32_CACHELINE 0x02
101 #define NO_MASK_CACHELINE 0x00
102 #define REPEAT_EN 0x01
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300103
Mauro Carvalho Chehab0b2b7b72009-06-22 22:48:29 -0300104 /* OFFSETS for Devices 4,5 and 6 Function 1 */
105#define MC_DOD_CH_DIMM0 0x48
106#define MC_DOD_CH_DIMM1 0x4c
107#define MC_DOD_CH_DIMM2 0x50
108 #define RANKOFFSET_MASK ((1 << 12) | (1 << 11) | (1 << 10))
109 #define RANKOFFSET(x) ((x & RANKOFFSET_MASK) >> 10)
110 #define DIMM_PRESENT_MASK (1 << 9)
111 #define DIMM_PRESENT(x) (((x) & DIMM_PRESENT_MASK) >> 9)
112 #define NUMBANK_MASK ((1 << 8) | (1 << 7))
113 #define NUMBANK(x) (((x) & NUMBANK_MASK) >> 7)
114 #define NUMRANK_MASK ((1 << 6) | (1 << 5))
115 #define NUMRANK(x) (((x) & NUMRANK_MASK) >> 5)
116 #define NUMROW_MASK ((1 << 4) | (1 << 3))
117 #define NUMROW(x) (((x) & NUMROW_MASK) >> 3)
118 #define NUMCOL_MASK 3
119 #define NUMCOL(x) ((x) & NUMCOL_MASK)
120
Mauro Carvalho Chehabf122a892009-06-22 22:48:29 -0300121#define MC_RANK_PRESENT 0x7c
122
Mauro Carvalho Chehab0b2b7b72009-06-22 22:48:29 -0300123#define MC_SAG_CH_0 0x80
124#define MC_SAG_CH_1 0x84
125#define MC_SAG_CH_2 0x88
126#define MC_SAG_CH_3 0x8c
127#define MC_SAG_CH_4 0x90
128#define MC_SAG_CH_5 0x94
129#define MC_SAG_CH_6 0x98
130#define MC_SAG_CH_7 0x9c
131
132#define MC_RIR_LIMIT_CH_0 0x40
133#define MC_RIR_LIMIT_CH_1 0x44
134#define MC_RIR_LIMIT_CH_2 0x48
135#define MC_RIR_LIMIT_CH_3 0x4C
136#define MC_RIR_LIMIT_CH_4 0x50
137#define MC_RIR_LIMIT_CH_5 0x54
138#define MC_RIR_LIMIT_CH_6 0x58
139#define MC_RIR_LIMIT_CH_7 0x5C
140#define MC_RIR_LIMIT_MASK ((1 << 10) - 1)
141
142#define MC_RIR_WAY_CH 0x80
143 #define MC_RIR_WAY_OFFSET_MASK (((1 << 14) - 1) & ~0x7)
144 #define MC_RIR_WAY_RANK_MASK 0x7
145
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300146/*
147 * i7core structs
148 */
149
150#define NUM_CHANS 3
Mauro Carvalho Chehab442305b2009-06-22 22:48:29 -0300151#define MAX_DIMMS 3 /* Max DIMMS per channel */
152#define MAX_MCR_FUNC 4
153#define MAX_CHAN_FUNC 3
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300154
155struct i7core_info {
156 u32 mc_control;
157 u32 mc_status;
158 u32 max_dod;
Mauro Carvalho Chehabf122a892009-06-22 22:48:29 -0300159 u32 ch_map;
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300160};
161
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300162
163struct i7core_inject {
164 int enable;
165
166 u32 section;
167 u32 type;
168 u32 eccmask;
169
170 /* Error address mask */
171 int channel, dimm, rank, bank, page, col;
172};
173
Mauro Carvalho Chehab0b2b7b72009-06-22 22:48:29 -0300174struct i7core_channel {
Mauro Carvalho Chehab442305b2009-06-22 22:48:29 -0300175 u32 ranks;
176 u32 dimms;
Mauro Carvalho Chehab0b2b7b72009-06-22 22:48:29 -0300177};
178
Mauro Carvalho Chehab8f331902009-06-22 22:48:29 -0300179struct pci_id_descr {
180 int dev;
181 int func;
182 int dev_id;
183 struct pci_dev *pdev;
184};
185
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300186struct i7core_pvt {
Mauro Carvalho Chehab442305b2009-06-22 22:48:29 -0300187 struct pci_dev *pci_mcr[MAX_MCR_FUNC + 1];
188 struct pci_dev *pci_ch[NUM_CHANS][MAX_CHAN_FUNC + 1];
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300189 struct i7core_info info;
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300190 struct i7core_inject inject;
Mauro Carvalho Chehab0b2b7b72009-06-22 22:48:29 -0300191 struct i7core_channel channel[NUM_CHANS];
Mauro Carvalho Chehab442305b2009-06-22 22:48:29 -0300192
193 int ce_count_available;
194 unsigned long ce_count[MAX_DIMMS]; /* ECC corrected errors counts per dimm */
195 int last_ce_count[MAX_DIMMS];
196
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300197};
198
199/* Device name and register DID (Device ID) */
200struct i7core_dev_info {
201 const char *ctl_name; /* name for this device */
202 u16 fsb_mapping_errors; /* DID for the branchmap,control */
203};
204
Mauro Carvalho Chehab8f331902009-06-22 22:48:29 -0300205#define PCI_DESCR(device, function, device_id) \
206 .dev = (device), \
207 .func = (function), \
208 .dev_id = (device_id)
209
210struct pci_id_descr pci_devs[] = {
211 /* Memory controller */
212 { PCI_DESCR(3, 0, PCI_DEVICE_ID_INTEL_I7_MCR) },
213 { PCI_DESCR(3, 1, PCI_DEVICE_ID_INTEL_I7_MC_TAD) },
214 { PCI_DESCR(3, 2, PCI_DEVICE_ID_INTEL_I7_MC_RAS) }, /* if RDIMM is supported */
215 { PCI_DESCR(3, 4, PCI_DEVICE_ID_INTEL_I7_MC_TEST) },
216
217 /* Channel 0 */
218 { PCI_DESCR(4, 0, PCI_DEVICE_ID_INTEL_I7_MC_CH0_CTRL) },
219 { PCI_DESCR(4, 1, PCI_DEVICE_ID_INTEL_I7_MC_CH0_ADDR) },
220 { PCI_DESCR(4, 2, PCI_DEVICE_ID_INTEL_I7_MC_CH0_RANK) },
221 { PCI_DESCR(4, 3, PCI_DEVICE_ID_INTEL_I7_MC_CH0_TC) },
222
223 /* Channel 1 */
224 { PCI_DESCR(5, 0, PCI_DEVICE_ID_INTEL_I7_MC_CH1_CTRL) },
225 { PCI_DESCR(5, 1, PCI_DEVICE_ID_INTEL_I7_MC_CH1_ADDR) },
226 { PCI_DESCR(5, 2, PCI_DEVICE_ID_INTEL_I7_MC_CH1_RANK) },
227 { PCI_DESCR(5, 3, PCI_DEVICE_ID_INTEL_I7_MC_CH1_TC) },
228
229 /* Channel 2 */
230 { PCI_DESCR(6, 0, PCI_DEVICE_ID_INTEL_I7_MC_CH2_CTRL) },
231 { PCI_DESCR(6, 1, PCI_DEVICE_ID_INTEL_I7_MC_CH2_ADDR) },
232 { PCI_DESCR(6, 2, PCI_DEVICE_ID_INTEL_I7_MC_CH2_RANK) },
233 { PCI_DESCR(6, 3, PCI_DEVICE_ID_INTEL_I7_MC_CH2_TC) },
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300234};
Mauro Carvalho Chehab8f331902009-06-22 22:48:29 -0300235#define N_DEVS ARRAY_SIZE(pci_devs)
236
237/*
238 * pci_device_id table for which devices we are looking for
239 * This should match the first device at pci_devs table
240 */
241static const struct pci_device_id i7core_pci_tbl[] __devinitdata = {
242 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7_MCR)},
243 {0,} /* 0 terminated list. */
244};
245
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300246
247/* Table of devices attributes supported by this driver */
248static const struct i7core_dev_info i7core_devs[] = {
249 {
250 .ctl_name = "i7 Core",
251 .fsb_mapping_errors = PCI_DEVICE_ID_INTEL_I7_MCR,
252 },
253};
254
255static struct edac_pci_ctl_info *i7core_pci;
256
257/****************************************************************************
258 Anciliary status routines
259 ****************************************************************************/
260
261 /* MC_CONTROL bits */
Mauro Carvalho Chehab0b2b7b72009-06-22 22:48:29 -0300262#define CH_ACTIVE(pvt, ch) ((pvt)->info.mc_control & 1 << (8 + ch))
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300263#define ECCx8(pvt) ((pvt)->info.mc_control & 1 << 1)
264
265 /* MC_STATUS bits */
266#define ECC_ENABLED(pvt) ((pvt)->info.mc_status & 1 << 3)
Mauro Carvalho Chehab0b2b7b72009-06-22 22:48:29 -0300267#define CH_DISABLED(pvt, ch) ((pvt)->info.mc_status & 1 << ch)
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300268
269 /* MC_MAX_DOD read functions */
270static inline int maxnumdimms(struct i7core_pvt *pvt)
271{
272 return (pvt->info.max_dod & 0x3) + 1;
273}
274
275static inline int maxnumrank(struct i7core_pvt *pvt)
276{
277 static int ranks[4] = { 1, 2, 4, -EINVAL };
278
279 return ranks[(pvt->info.max_dod >> 2) & 0x3];
280}
281
282static inline int maxnumbank(struct i7core_pvt *pvt)
283{
284 static int banks[4] = { 4, 8, 16, -EINVAL };
285
286 return banks[(pvt->info.max_dod >> 4) & 0x3];
287}
288
289static inline int maxnumrow(struct i7core_pvt *pvt)
290{
291 static int rows[8] = {
292 1 << 12, 1 << 13, 1 << 14, 1 << 15,
293 1 << 16, -EINVAL, -EINVAL, -EINVAL,
294 };
295
296 return rows[((pvt->info.max_dod >> 6) & 0x7)];
297}
298
299static inline int maxnumcol(struct i7core_pvt *pvt)
300{
301 static int cols[8] = {
302 1 << 10, 1 << 11, 1 << 12, -EINVAL,
303 };
304 return cols[((pvt->info.max_dod >> 9) & 0x3) << 12];
305}
306
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300307
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300308/****************************************************************************
309 Memory check routines
310 ****************************************************************************/
311static int get_dimm_config(struct mem_ctl_info *mci)
312{
313 struct i7core_pvt *pvt = mci->pvt_info;
Mauro Carvalho Chehab0b2b7b72009-06-22 22:48:29 -0300314 int i;
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300315
Mauro Carvalho Chehab8f331902009-06-22 22:48:29 -0300316 if (!pvt->pci_mcr[0])
317 return -ENODEV;
318
Mauro Carvalho Chehabf122a892009-06-22 22:48:29 -0300319 /* Device 3 function 0 reads */
320 pci_read_config_dword(pvt->pci_mcr[0], MC_CONTROL,
321 &pvt->info.mc_control);
322 pci_read_config_dword(pvt->pci_mcr[0], MC_STATUS,
323 &pvt->info.mc_status);
324 pci_read_config_dword(pvt->pci_mcr[0], MC_MAX_DOD,
325 &pvt->info.max_dod);
326 pci_read_config_dword(pvt->pci_mcr[0], MC_CHANNEL_MAPPER,
327 &pvt->info.ch_map);
328
329 debugf0("MC control=0x%08x status=0x%08x dod=0x%08x map=0x%08x\n",
330 pvt->info.mc_control, pvt->info.mc_status,
331 pvt->info.max_dod, pvt->info.ch_map);
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300332
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300333 if (ECC_ENABLED(pvt))
334 debugf0("ECC enabled with x%d SDCC\n", ECCx8(pvt)?8:4);
335 else
336 debugf0("ECC disabled\n");
337
338 /* FIXME: need to handle the error codes */
339 debugf0("DOD Maximum limits: DIMMS: %d, %d-ranked, %d-banked\n",
340 maxnumdimms(pvt), maxnumrank(pvt), maxnumbank(pvt));
341 debugf0("DOD Maximum rows x colums = 0x%x x 0x%x\n",
342 maxnumrow(pvt), maxnumcol(pvt));
343
Mauro Carvalho Chehab0b2b7b72009-06-22 22:48:29 -0300344 debugf0("Memory channel configuration:\n");
345
346 for (i = 0; i < NUM_CHANS; i++) {
347 u32 data;
348
349 if (!CH_ACTIVE(pvt, i)) {
350 debugf0("Channel %i is not active\n", i);
351 continue;
352 }
353 if (CH_DISABLED(pvt, i)) {
354 debugf0("Channel %i is disabled\n", i);
355 continue;
356 }
357
Mauro Carvalho Chehabf122a892009-06-22 22:48:29 -0300358 /* Devices 4-6 function 0 */
Mauro Carvalho Chehab0b2b7b72009-06-22 22:48:29 -0300359 pci_read_config_dword(pvt->pci_ch[i][0],
360 MC_CHANNEL_DIMM_INIT_PARAMS, &data);
361
362 pvt->channel[i].ranks = (data & QUAD_RANK_PRESENT)? 4 : 2;
363
364 if (data & THREE_DIMMS_PRESENT)
365 pvt->channel[i].dimms = 3;
366 else if (data & SINGLE_QUAD_RANK_PRESENT)
367 pvt->channel[i].dimms = 1;
368 else
369 pvt->channel[i].dimms = 2;
370
Mauro Carvalho Chehabf122a892009-06-22 22:48:29 -0300371 debugf0("Ch%d (0x%08x): rd ch %d, wr ch %d, "
372 "%d ranks, %d %cDIMMs\n",
373 i, data,
374 RDLCH(pvt->info.ch_map, i),
375 WRLCH(pvt->info.ch_map, i),
Mauro Carvalho Chehab0b2b7b72009-06-22 22:48:29 -0300376 pvt->channel[i].ranks, pvt->channel[i].dimms,
Mauro Carvalho Chehabf122a892009-06-22 22:48:29 -0300377 (data & REGISTERED_DIMM)? 'R' : 'U' );
Mauro Carvalho Chehab0b2b7b72009-06-22 22:48:29 -0300378 }
379
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300380 return 0;
381}
382
383/****************************************************************************
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300384 Error insertion routines
385 ****************************************************************************/
386
387/* The i7core has independent error injection features per channel.
388 However, to have a simpler code, we don't allow enabling error injection
389 on more than one channel.
390 Also, since a change at an inject parameter will be applied only at enable,
391 we're disabling error injection on all write calls to the sysfs nodes that
392 controls the error code injection.
393 */
Mauro Carvalho Chehab8f331902009-06-22 22:48:29 -0300394static int disable_inject(struct mem_ctl_info *mci)
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300395{
396 struct i7core_pvt *pvt = mci->pvt_info;
397
398 pvt->inject.enable = 0;
399
Mauro Carvalho Chehab8f331902009-06-22 22:48:29 -0300400 if (!pvt->pci_ch[pvt->inject.channel][0])
401 return -ENODEV;
402
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300403 pci_write_config_dword(pvt->pci_ch[pvt->inject.channel][0],
404 MC_CHANNEL_ERROR_MASK, 0);
Mauro Carvalho Chehab8f331902009-06-22 22:48:29 -0300405
406 return 0;
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300407}
408
409/*
410 * i7core inject inject.section
411 *
412 * accept and store error injection inject.section value
413 * bit 0 - refers to the lower 32-byte half cacheline
414 * bit 1 - refers to the upper 32-byte half cacheline
415 */
416static ssize_t i7core_inject_section_store(struct mem_ctl_info *mci,
417 const char *data, size_t count)
418{
419 struct i7core_pvt *pvt = mci->pvt_info;
420 unsigned long value;
421 int rc;
422
423 if (pvt->inject.enable)
424 disable_inject(mci);
425
426 rc = strict_strtoul(data, 10, &value);
427 if ((rc < 0) || (value > 3))
428 return 0;
429
430 pvt->inject.section = (u32) value;
431 return count;
432}
433
434static ssize_t i7core_inject_section_show(struct mem_ctl_info *mci,
435 char *data)
436{
437 struct i7core_pvt *pvt = mci->pvt_info;
438 return sprintf(data, "0x%08x\n", pvt->inject.section);
439}
440
441/*
442 * i7core inject.type
443 *
444 * accept and store error injection inject.section value
445 * bit 0 - repeat enable - Enable error repetition
446 * bit 1 - inject ECC error
447 * bit 2 - inject parity error
448 */
449static ssize_t i7core_inject_type_store(struct mem_ctl_info *mci,
450 const char *data, size_t count)
451{
452 struct i7core_pvt *pvt = mci->pvt_info;
453 unsigned long value;
454 int rc;
455
456 if (pvt->inject.enable)
457 disable_inject(mci);
458
459 rc = strict_strtoul(data, 10, &value);
460 if ((rc < 0) || (value > 7))
461 return 0;
462
463 pvt->inject.type = (u32) value;
464 return count;
465}
466
467static ssize_t i7core_inject_type_show(struct mem_ctl_info *mci,
468 char *data)
469{
470 struct i7core_pvt *pvt = mci->pvt_info;
471 return sprintf(data, "0x%08x\n", pvt->inject.type);
472}
473
474/*
475 * i7core_inject_inject.eccmask_store
476 *
477 * The type of error (UE/CE) will depend on the inject.eccmask value:
478 * Any bits set to a 1 will flip the corresponding ECC bit
479 * Correctable errors can be injected by flipping 1 bit or the bits within
480 * a symbol pair (2 consecutive aligned 8-bit pairs - i.e. 7:0 and 15:8 or
481 * 23:16 and 31:24). Flipping bits in two symbol pairs will cause an
482 * uncorrectable error to be injected.
483 */
484static ssize_t i7core_inject_eccmask_store(struct mem_ctl_info *mci,
485 const char *data, size_t count)
486{
487 struct i7core_pvt *pvt = mci->pvt_info;
488 unsigned long value;
489 int rc;
490
491 if (pvt->inject.enable)
492 disable_inject(mci);
493
494 rc = strict_strtoul(data, 10, &value);
495 if (rc < 0)
496 return 0;
497
498 pvt->inject.eccmask = (u32) value;
499 return count;
500}
501
502static ssize_t i7core_inject_eccmask_show(struct mem_ctl_info *mci,
503 char *data)
504{
505 struct i7core_pvt *pvt = mci->pvt_info;
506 return sprintf(data, "0x%08x\n", pvt->inject.eccmask);
507}
508
509/*
510 * i7core_addrmatch
511 *
512 * The type of error (UE/CE) will depend on the inject.eccmask value:
513 * Any bits set to a 1 will flip the corresponding ECC bit
514 * Correctable errors can be injected by flipping 1 bit or the bits within
515 * a symbol pair (2 consecutive aligned 8-bit pairs - i.e. 7:0 and 15:8 or
516 * 23:16 and 31:24). Flipping bits in two symbol pairs will cause an
517 * uncorrectable error to be injected.
518 */
519static ssize_t i7core_inject_addrmatch_store(struct mem_ctl_info *mci,
520 const char *data, size_t count)
521{
522 struct i7core_pvt *pvt = mci->pvt_info;
523 char *cmd, *val;
524 long value;
525 int rc;
526
527 if (pvt->inject.enable)
528 disable_inject(mci);
529
530 do {
531 cmd = strsep((char **) &data, ":");
532 if (!cmd)
533 break;
534 val = strsep((char **) &data, " \n\t");
535 if (!val)
536 return cmd - data;
537
538 if (!strcasecmp(val,"any"))
539 value = -1;
540 else {
541 rc = strict_strtol(val, 10, &value);
542 if ((rc < 0) || (value < 0))
543 return cmd - data;
544 }
545
546 if (!strcasecmp(cmd,"channel")) {
547 if (value < 3)
548 pvt->inject.channel = value;
549 else
550 return cmd - data;
551 } else if (!strcasecmp(cmd,"dimm")) {
552 if (value < 4)
553 pvt->inject.dimm = value;
554 else
555 return cmd - data;
556 } else if (!strcasecmp(cmd,"rank")) {
557 if (value < 4)
558 pvt->inject.rank = value;
559 else
560 return cmd - data;
561 } else if (!strcasecmp(cmd,"bank")) {
562 if (value < 4)
563 pvt->inject.bank = value;
564 else
565 return cmd - data;
566 } else if (!strcasecmp(cmd,"page")) {
567 if (value <= 0xffff)
568 pvt->inject.page = value;
569 else
570 return cmd - data;
571 } else if (!strcasecmp(cmd,"col") ||
572 !strcasecmp(cmd,"column")) {
573 if (value <= 0x3fff)
574 pvt->inject.col = value;
575 else
576 return cmd - data;
577 }
578 } while (1);
579
580 return count;
581}
582
583static ssize_t i7core_inject_addrmatch_show(struct mem_ctl_info *mci,
584 char *data)
585{
586 struct i7core_pvt *pvt = mci->pvt_info;
587 char channel[4], dimm[4], bank[4], rank[4], page[7], col[7];
588
589 if (pvt->inject.channel < 0)
590 sprintf(channel, "any");
591 else
592 sprintf(channel, "%d", pvt->inject.channel);
593 if (pvt->inject.dimm < 0)
594 sprintf(dimm, "any");
595 else
596 sprintf(dimm, "%d", pvt->inject.dimm);
597 if (pvt->inject.bank < 0)
598 sprintf(bank, "any");
599 else
600 sprintf(bank, "%d", pvt->inject.bank);
601 if (pvt->inject.rank < 0)
602 sprintf(rank, "any");
603 else
604 sprintf(rank, "%d", pvt->inject.rank);
605 if (pvt->inject.page < 0)
606 sprintf(page, "any");
607 else
608 sprintf(page, "0x%04x", pvt->inject.page);
609 if (pvt->inject.col < 0)
610 sprintf(col, "any");
611 else
612 sprintf(col, "0x%04x", pvt->inject.col);
613
614 return sprintf(data, "channel: %s\ndimm: %s\nbank: %s\n"
615 "rank: %s\npage: %s\ncolumn: %s\n",
616 channel, dimm, bank, rank, page, col);
617}
618
619/*
620 * This routine prepares the Memory Controller for error injection.
621 * The error will be injected when some process tries to write to the
622 * memory that matches the given criteria.
623 * The criteria can be set in terms of a mask where dimm, rank, bank, page
624 * and col can be specified.
625 * A -1 value for any of the mask items will make the MCU to ignore
626 * that matching criteria for error injection.
627 *
628 * It should be noticed that the error will only happen after a write operation
629 * on a memory that matches the condition. if REPEAT_EN is not enabled at
630 * inject mask, then it will produce just one error. Otherwise, it will repeat
631 * until the injectmask would be cleaned.
632 *
633 * FIXME: This routine assumes that MAXNUMDIMMS value of MC_MAX_DOD
634 * is reliable enough to check if the MC is using the
635 * three channels. However, this is not clear at the datasheet.
636 */
637static ssize_t i7core_inject_enable_store(struct mem_ctl_info *mci,
638 const char *data, size_t count)
639{
640 struct i7core_pvt *pvt = mci->pvt_info;
641 u32 injectmask;
642 u64 mask = 0;
643 int rc;
644 long enable;
645
Mauro Carvalho Chehab8f331902009-06-22 22:48:29 -0300646 if (!pvt->pci_ch[pvt->inject.channel][0])
647 return 0;
648
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300649 rc = strict_strtoul(data, 10, &enable);
650 if ((rc < 0))
651 return 0;
652
653 if (enable) {
654 pvt->inject.enable = 1;
655 } else {
656 disable_inject(mci);
657 return count;
658 }
659
660 /* Sets pvt->inject.dimm mask */
661 if (pvt->inject.dimm < 0)
Mauro Carvalho Chehab7b029d02009-06-22 22:48:29 -0300662 mask |= 1L << 41;
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300663 else {
Mauro Carvalho Chehab0b2b7b72009-06-22 22:48:29 -0300664 if (pvt->channel[pvt->inject.channel].dimms > 2)
Mauro Carvalho Chehab7b029d02009-06-22 22:48:29 -0300665 mask |= (pvt->inject.dimm & 0x3L) << 35;
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300666 else
Mauro Carvalho Chehab7b029d02009-06-22 22:48:29 -0300667 mask |= (pvt->inject.dimm & 0x1L) << 36;
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300668 }
669
670 /* Sets pvt->inject.rank mask */
671 if (pvt->inject.rank < 0)
Mauro Carvalho Chehab7b029d02009-06-22 22:48:29 -0300672 mask |= 1L << 40;
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300673 else {
Mauro Carvalho Chehab0b2b7b72009-06-22 22:48:29 -0300674 if (pvt->channel[pvt->inject.channel].dimms > 2)
Mauro Carvalho Chehab7b029d02009-06-22 22:48:29 -0300675 mask |= (pvt->inject.rank & 0x1L) << 34;
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300676 else
Mauro Carvalho Chehab7b029d02009-06-22 22:48:29 -0300677 mask |= (pvt->inject.rank & 0x3L) << 34;
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300678 }
679
680 /* Sets pvt->inject.bank mask */
681 if (pvt->inject.bank < 0)
Mauro Carvalho Chehab7b029d02009-06-22 22:48:29 -0300682 mask |= 1L << 39;
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300683 else
Mauro Carvalho Chehab7b029d02009-06-22 22:48:29 -0300684 mask |= (pvt->inject.bank & 0x15L) << 30;
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300685
686 /* Sets pvt->inject.page mask */
687 if (pvt->inject.page < 0)
Mauro Carvalho Chehab7b029d02009-06-22 22:48:29 -0300688 mask |= 1L << 38;
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300689 else
Mauro Carvalho Chehab7b029d02009-06-22 22:48:29 -0300690 mask |= (pvt->inject.page & 0xffffL) << 14;
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300691
692 /* Sets pvt->inject.column mask */
693 if (pvt->inject.col < 0)
Mauro Carvalho Chehab7b029d02009-06-22 22:48:29 -0300694 mask |= 1L << 37;
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300695 else
Mauro Carvalho Chehab7b029d02009-06-22 22:48:29 -0300696 mask |= (pvt->inject.col & 0x3fffL);
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300697
Mauro Carvalho Chehab7b029d02009-06-22 22:48:29 -0300698#if USE_QWORD
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300699 pci_write_config_qword(pvt->pci_ch[pvt->inject.channel][0],
700 MC_CHANNEL_ADDR_MATCH, mask);
Mauro Carvalho Chehab7b029d02009-06-22 22:48:29 -0300701#else
702 pci_write_config_dword(pvt->pci_ch[pvt->inject.channel][0],
703 MC_CHANNEL_ADDR_MATCH, mask);
704 pci_write_config_dword(pvt->pci_ch[pvt->inject.channel][0],
705 MC_CHANNEL_ADDR_MATCH + 4, mask >> 32L);
706#endif
707
708#if 1
709#if USE_QWORD
710 u64 rdmask;
711 pci_read_config_qword(pvt->pci_ch[pvt->inject.channel][0],
712 MC_CHANNEL_ADDR_MATCH, &rdmask);
713 debugf0("Inject addr match write 0x%016llx, read: 0x%016llx\n",
714 mask, rdmask);
715#else
716 u32 rdmask1, rdmask2;
717
718 pci_read_config_dword(pvt->pci_ch[pvt->inject.channel][0],
719 MC_CHANNEL_ADDR_MATCH, &rdmask1);
720 pci_read_config_dword(pvt->pci_ch[pvt->inject.channel][0],
721 MC_CHANNEL_ADDR_MATCH + 4, &rdmask2);
722
723 debugf0("Inject addr match write 0x%016llx, read: 0x%08x%08x\n",
724 mask, rdmask1, rdmask2);
725#endif
726#endif
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300727
728 pci_write_config_dword(pvt->pci_ch[pvt->inject.channel][0],
729 MC_CHANNEL_ERROR_MASK, pvt->inject.eccmask);
730
731 /*
732 * bit 0: REPEAT_EN
733 * bits 1-2: MASK_HALF_CACHELINE
734 * bit 3: INJECT_ECC
735 * bit 4: INJECT_ADDR_PARITY
736 */
737
Mauro Carvalho Chehab7b029d02009-06-22 22:48:29 -0300738 injectmask = (pvt->inject.type & 1) |
739 (pvt->inject.section & 0x3) << 1 |
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300740 (pvt->inject.type & 0x6) << (3 - 1);
741
742 pci_write_config_dword(pvt->pci_ch[pvt->inject.channel][0],
743 MC_CHANNEL_ERROR_MASK, injectmask);
744
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300745 debugf0("Error inject addr match 0x%016llx, ecc 0x%08x, inject 0x%08x\n",
746 mask, pvt->inject.eccmask, injectmask);
747
Mauro Carvalho Chehab7b029d02009-06-22 22:48:29 -0300748
749
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300750 return count;
751}
752
753static ssize_t i7core_inject_enable_show(struct mem_ctl_info *mci,
754 char *data)
755{
756 struct i7core_pvt *pvt = mci->pvt_info;
Mauro Carvalho Chehab7b029d02009-06-22 22:48:29 -0300757 u32 injectmask;
758
759 pci_read_config_dword(pvt->pci_ch[pvt->inject.channel][0],
760 MC_CHANNEL_ERROR_MASK, &injectmask);
761
762 debugf0("Inject error read: 0x%018x\n", injectmask);
763
764 if (injectmask & 0x0c)
765 pvt->inject.enable = 1;
766
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300767 return sprintf(data, "%d\n", pvt->inject.enable);
768}
769
Mauro Carvalho Chehab442305b2009-06-22 22:48:29 -0300770static ssize_t i7core_ce_regs_show(struct mem_ctl_info *mci, char *data)
771{
772 struct i7core_pvt *pvt = mci->pvt_info;
773
774 if (!pvt->ce_count_available)
775 return sprintf(data, "unavailable\n");
776
777 return sprintf(data, "dimm0: %lu\ndimm1: %lu\ndimm2: %lu\n",
778 pvt->ce_count[0],
779 pvt->ce_count[1],
780 pvt->ce_count[2]);
781}
782
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300783/*
784 * Sysfs struct
785 */
786static struct mcidev_sysfs_attribute i7core_inj_attrs[] = {
787
788 {
789 .attr = {
790 .name = "inject_section",
791 .mode = (S_IRUGO | S_IWUSR)
792 },
793 .show = i7core_inject_section_show,
794 .store = i7core_inject_section_store,
795 }, {
796 .attr = {
797 .name = "inject_type",
798 .mode = (S_IRUGO | S_IWUSR)
799 },
800 .show = i7core_inject_type_show,
801 .store = i7core_inject_type_store,
802 }, {
803 .attr = {
804 .name = "inject_eccmask",
805 .mode = (S_IRUGO | S_IWUSR)
806 },
807 .show = i7core_inject_eccmask_show,
808 .store = i7core_inject_eccmask_store,
809 }, {
810 .attr = {
811 .name = "inject_addrmatch",
812 .mode = (S_IRUGO | S_IWUSR)
813 },
814 .show = i7core_inject_addrmatch_show,
815 .store = i7core_inject_addrmatch_store,
816 }, {
817 .attr = {
818 .name = "inject_enable",
819 .mode = (S_IRUGO | S_IWUSR)
820 },
821 .show = i7core_inject_enable_show,
822 .store = i7core_inject_enable_store,
Mauro Carvalho Chehab442305b2009-06-22 22:48:29 -0300823 }, {
824 .attr = {
825 .name = "corrected_error_counts",
826 .mode = (S_IRUGO | S_IWUSR)
827 },
828 .show = i7core_ce_regs_show,
829 .store = NULL,
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -0300830 },
831};
832
833/****************************************************************************
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300834 Device initialization routines: put/get, init/exit
835 ****************************************************************************/
836
837/*
838 * i7core_put_devices 'put' all the devices that we have
839 * reserved via 'get'
840 */
Mauro Carvalho Chehab8f331902009-06-22 22:48:29 -0300841static void i7core_put_devices(void)
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300842{
Mauro Carvalho Chehab8f331902009-06-22 22:48:29 -0300843 int i;
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300844
Mauro Carvalho Chehab8f331902009-06-22 22:48:29 -0300845 for (i = 0; i < N_DEVS; i++)
846 pci_dev_put(pci_devs[i].pdev);
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300847}
848
849/*
850 * i7core_get_devices Find and perform 'get' operation on the MCH's
851 * device/functions we want to reference for this driver
852 *
853 * Need to 'get' device 16 func 1 and func 2
854 */
Mauro Carvalho Chehab8f331902009-06-22 22:48:29 -0300855static int i7core_get_devices(struct mem_ctl_info *mci, struct pci_dev *mcidev)
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300856{
Mauro Carvalho Chehab8f331902009-06-22 22:48:29 -0300857 struct i7core_pvt *pvt = mci->pvt_info;
858 int rc, i,func;
859 struct pci_dev *pdev = NULL;
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300860
861 pvt = mci->pvt_info;
862 memset(pvt, 0, sizeof(*pvt));
863
Mauro Carvalho Chehab8f331902009-06-22 22:48:29 -0300864 for (i = 0; i < N_DEVS; i++) {
865 pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
866 pci_devs[i].dev_id, NULL);
867 if (!pdev) {
868 /* End of list, leave */
869 i7core_printk(KERN_ERR,
870 "Device not found: PCI ID %04x:%04x "
871 "(dev %d, func %d)\n",
872 PCI_VENDOR_ID_INTEL, pci_devs[i].dev_id,
873 pci_devs[i].dev,pci_devs[i].func);
874 if ((pci_devs[i].dev == 3) && (pci_devs[i].func == 2))
875 continue; /* Only on chips with RDIMMs */
876 else
877 i7core_put_devices();
878 }
879 pci_devs[i].pdev = pdev;
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300880
Mauro Carvalho Chehab8f331902009-06-22 22:48:29 -0300881 rc = pci_enable_device(pdev);
882 if (rc < 0) {
883 i7core_printk(KERN_ERR,
884 "Couldn't enable PCI ID %04x:%04x "
885 "(dev %d, func %d)\n",
886 PCI_VENDOR_ID_INTEL, pci_devs[i].dev_id,
887 pci_devs[i].dev, pci_devs[i].func);
888 i7core_put_devices();
889 return rc;
890 }
891 /* Sanity check */
892 if (PCI_FUNC(pdev->devfn) != pci_devs[i].func) {
893 i7core_printk(KERN_ERR,
894 "Device PCI ID %04x:%04x "
895 "has function %d instead of %d\n",
896 PCI_VENDOR_ID_INTEL, pci_devs[i].dev_id,
897 PCI_FUNC(pdev->devfn), pci_devs[i].func);
898 i7core_put_devices();
899 return -EINVAL;
900 }
901
902 i7core_printk(KERN_INFO,
903 "Registered device %0x:%0x fn=%0x %0x\n",
904 PCI_VENDOR_ID_INTEL, pci_devs[i].dev_id,
905 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
906
907 func = PCI_FUNC(pdev->devfn);
908 if (pci_devs[i].dev < 4) {
909 pvt->pci_mcr[func] = pdev;
910 } else {
911 pvt->pci_ch[pci_devs[i].dev - 4][func] = pdev;
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300912 }
913 }
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300914
Mauro Carvalho Chehab8f331902009-06-22 22:48:29 -0300915 i7core_printk(KERN_INFO, "Driver loaded.\n");
Mauro Carvalho Chehab0b2b7b72009-06-22 22:48:29 -0300916
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300917 return 0;
918}
919
Mauro Carvalho Chehab442305b2009-06-22 22:48:29 -0300920/****************************************************************************
921 Error check routines
922 ****************************************************************************/
923
924/* This function is based on the device 3 function 4 registers as described on:
925 * Intel Xeon Processor 5500 Series Datasheet Volume 2
926 * http://www.intel.com/Assets/PDF/datasheet/321322.pdf
927 * also available at:
928 * http://www.arrownac.com/manufacturers/intel/s/nehalem/5500-datasheet-v2.pdf
929 */
930static void check_mc_test_err(struct mem_ctl_info *mci)
931{
932 struct i7core_pvt *pvt = mci->pvt_info;
933 u32 rcv1, rcv0;
934 int new0, new1, new2;
935
936 if (!pvt->pci_mcr[4]) {
937 debugf0("%s MCR registers not found\n",__func__);
938 return;
939 }
940
941 /* Corrected error reads */
942 pci_read_config_dword(pvt->pci_mcr[4], MC_TEST_ERR_RCV1, &rcv1);
943 pci_read_config_dword(pvt->pci_mcr[4], MC_TEST_ERR_RCV0, &rcv0);
944
945 /* Store the new values */
946 new2 = DIMM2_COR_ERR(rcv1);
947 new1 = DIMM1_COR_ERR(rcv0);
948 new0 = DIMM0_COR_ERR(rcv0);
949
950 debugf2("%s CE rcv1=0x%08x rcv0=0x%08x, %d %d %d\n",
951 (pvt->ce_count_available ? "UPDATE" : "READ"),
952 rcv1, rcv0, new0, new1, new2);
953
954 /* Updates CE counters if it is not the first time here */
955 if (pvt->ce_count_available) {
956 /* Updates CE counters */
957 int add0, add1, add2;
958
959 add2 = new2 - pvt->last_ce_count[2];
960 add1 = new1 - pvt->last_ce_count[1];
961 add0 = new0 - pvt->last_ce_count[0];
962
963 if (add2 < 0)
964 add2 += 0x7fff;
965 pvt->ce_count[2] += add2;
966
967 if (add1 < 0)
968 add1 += 0x7fff;
969 pvt->ce_count[1] += add1;
970
971 if (add0 < 0)
972 add0 += 0x7fff;
973 pvt->ce_count[0] += add0;
974 } else
975 pvt->ce_count_available = 1;
976
977 /* Store the new values */
978 pvt->last_ce_count[2] = new2;
979 pvt->last_ce_count[1] = new1;
980 pvt->last_ce_count[0] = new0;
981}
982
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300983/*
Mauro Carvalho Chehab87d1d272009-06-22 22:48:29 -0300984 * i7core_check_error Retrieve and process errors reported by the
985 * hardware. Called by the Core module.
986 */
987static void i7core_check_error(struct mem_ctl_info *mci)
988{
Mauro Carvalho Chehab442305b2009-06-22 22:48:29 -0300989 check_mc_test_err(mci);
Mauro Carvalho Chehab87d1d272009-06-22 22:48:29 -0300990}
991
992/*
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -0300993 * i7core_probe Probe for ONE instance of device to see if it is
994 * present.
995 * return:
996 * 0 for FOUND a device
997 * < 0 for error code
998 */
999static int __devinit i7core_probe(struct pci_dev *pdev,
1000 const struct pci_device_id *id)
1001{
1002 struct mem_ctl_info *mci;
1003 struct i7core_pvt *pvt;
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -03001004 int num_channels;
1005 int num_csrows;
1006 int num_dimms_per_channel;
1007 int dev_idx = id->driver_data;
1008
1009 if (dev_idx >= ARRAY_SIZE(i7core_devs))
1010 return -EINVAL;
1011
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -03001012 num_channels = NUM_CHANS;
1013
1014 /* FIXME: FAKE data, since we currently don't now how to get this */
1015 num_dimms_per_channel = 4;
1016 num_csrows = num_dimms_per_channel;
1017
1018 /* allocate a new MC control structure */
1019 mci = edac_mc_alloc(sizeof(*pvt), num_csrows, num_channels, 0);
1020 if (mci == NULL)
1021 return -ENOMEM;
1022
1023 debugf0("MC: " __FILE__ ": %s(): mci = %p\n", __func__, mci);
1024
Mauro Carvalho Chehab87d1d272009-06-22 22:48:29 -03001025 /* 'get' the pci devices we want to reserve for our use */
1026 if (i7core_get_devices(mci, pdev))
1027 goto fail0;
1028
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -03001029 mci->dev = &pdev->dev; /* record ptr to the generic device */
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -03001030
1031 pvt = mci->pvt_info;
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -03001032
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -03001033// pvt->system_address = pdev; /* Record this device in our private */
1034// pvt->maxch = num_channels;
1035// pvt->maxdimmperch = num_dimms_per_channel;
1036
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -03001037 mci->mc_idx = 0;
1038 mci->mtype_cap = MEM_FLAG_FB_DDR2; /* FIXME: it uses DDR3 */
1039 mci->edac_ctl_cap = EDAC_FLAG_NONE;
1040 mci->edac_cap = EDAC_FLAG_NONE;
1041 mci->mod_name = "i7core_edac.c";
1042 mci->mod_ver = I7CORE_REVISION;
1043 mci->ctl_name = i7core_devs[dev_idx].ctl_name;
1044 mci->dev_name = pci_name(pdev);
1045 mci->ctl_page_to_phys = NULL;
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -03001046 mci->mc_driver_sysfs_attributes = i7core_inj_attrs;
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -03001047
Mauro Carvalho Chehab87d1d272009-06-22 22:48:29 -03001048 /* Set the function pointer to an actual operation function */
1049 mci->edac_check = i7core_check_error;
Mauro Carvalho Chehab8f331902009-06-22 22:48:29 -03001050
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -03001051 /* add this new MC control structure to EDAC's list of MCs */
1052 if (edac_mc_add_mc(mci)) {
1053 debugf0("MC: " __FILE__
1054 ": %s(): failed edac_mc_add_mc()\n", __func__);
1055 /* FIXME: perhaps some code should go here that disables error
1056 * reporting if we just enabled it
1057 */
1058 goto fail1;
1059 }
1060
1061 /* allocating generic PCI control info */
1062 i7core_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
1063 if (!i7core_pci) {
1064 printk(KERN_WARNING
1065 "%s(): Unable to create PCI control\n",
1066 __func__);
1067 printk(KERN_WARNING
1068 "%s(): PCI error report via EDAC not setup\n",
1069 __func__);
1070 }
1071
Mauro Carvalho Chehab194a40f2009-06-22 22:48:28 -03001072 /* Default error mask is any memory */
1073 pvt->inject.channel = -1;
1074 pvt->inject.dimm = -1;
1075 pvt->inject.rank = -1;
1076 pvt->inject.bank = -1;
1077 pvt->inject.page = -1;
1078 pvt->inject.col = -1;
1079
Mauro Carvalho Chehab8f331902009-06-22 22:48:29 -03001080 /* Get dimm basic config */
1081 get_dimm_config(mci);
1082
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -03001083 return 0;
1084
1085fail1:
Mauro Carvalho Chehab8f331902009-06-22 22:48:29 -03001086 i7core_put_devices();
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -03001087
1088fail0:
1089 edac_mc_free(mci);
1090 return -ENODEV;
1091}
1092
1093/*
1094 * i7core_remove destructor for one instance of device
1095 *
1096 */
1097static void __devexit i7core_remove(struct pci_dev *pdev)
1098{
1099 struct mem_ctl_info *mci;
1100
1101 debugf0(__FILE__ ": %s()\n", __func__);
1102
1103 if (i7core_pci)
1104 edac_pci_release_generic_ctl(i7core_pci);
1105
1106 mci = edac_mc_del_mc(&pdev->dev);
Mauro Carvalho Chehab87d1d272009-06-22 22:48:29 -03001107
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -03001108 if (!mci)
1109 return;
1110
1111 /* retrieve references to resources, and free those resources */
Mauro Carvalho Chehab8f331902009-06-22 22:48:29 -03001112 i7core_put_devices();
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -03001113
1114 edac_mc_free(mci);
1115}
1116
Mauro Carvalho Chehaba0c36a12009-06-22 22:41:15 -03001117MODULE_DEVICE_TABLE(pci, i7core_pci_tbl);
1118
1119/*
1120 * i7core_driver pci_driver structure for this module
1121 *
1122 */
1123static struct pci_driver i7core_driver = {
1124 .name = "i7core_edac",
1125 .probe = i7core_probe,
1126 .remove = __devexit_p(i7core_remove),
1127 .id_table = i7core_pci_tbl,
1128};
1129
1130/*
1131 * i7core_init Module entry function
1132 * Try to initialize this module for its devices
1133 */
1134static int __init i7core_init(void)
1135{
1136 int pci_rc;
1137
1138 debugf2("MC: " __FILE__ ": %s()\n", __func__);
1139
1140 /* Ensure that the OPSTATE is set correctly for POLL or NMI */
1141 opstate_init();
1142
1143 pci_rc = pci_register_driver(&i7core_driver);
1144
1145 return (pci_rc < 0) ? pci_rc : 0;
1146}
1147
1148/*
1149 * i7core_exit() Module exit function
1150 * Unregister the driver
1151 */
1152static void __exit i7core_exit(void)
1153{
1154 debugf2("MC: " __FILE__ ": %s()\n", __func__);
1155 pci_unregister_driver(&i7core_driver);
1156}
1157
1158module_init(i7core_init);
1159module_exit(i7core_exit);
1160
1161MODULE_LICENSE("GPL");
1162MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
1163MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
1164MODULE_DESCRIPTION("MC Driver for Intel i7 Core memory controllers - "
1165 I7CORE_REVISION);
1166
1167module_param(edac_op_state, int, 0444);
1168MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");