Commit | Line | Data |
---|---|---|
fcaf780b MCC |
1 | /* |
2 | * Intel 7300 class Memory Controllers kernel module (Clarksboro) | |
3 | * | |
4 | * This file may be distributed under the terms of the | |
5 | * GNU General Public License version 2 only. | |
6 | * | |
7 | * Copyright (c) 2010 by: | |
8 | * Mauro Carvalho Chehab <mchehab@redhat.com> | |
9 | * | |
10 | * Red Hat Inc. http://www.redhat.com | |
11 | * | |
12 | * Intel 7300 Chipset Memory Controller Hub (MCH) - Datasheet | |
13 | * http://www.intel.com/Assets/PDF/datasheet/318082.pdf | |
14 | * | |
15 | * TODO: The chipset allow checking for PCI Express errors also. Currently, | |
16 | * the driver covers only memory error errors | |
17 | * | |
18 | * This driver uses "csrows" EDAC attribute to represent DIMM slot# | |
19 | */ | |
20 | ||
21 | #include <linux/module.h> | |
22 | #include <linux/init.h> | |
23 | #include <linux/pci.h> | |
24 | #include <linux/pci_ids.h> | |
25 | #include <linux/slab.h> | |
26 | #include <linux/edac.h> | |
27 | #include <linux/mmzone.h> | |
28 | ||
29 | #include "edac_core.h" | |
30 | ||
31 | /* | |
32 | * Alter this version for the I7300 module when modifications are made | |
33 | */ | |
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 | ||
b4552ace MCC |
44 | /*********************************************** |
45 | * i7300 Limit constants Structs and static vars | |
46 | ***********************************************/ | |
47 | ||
fcaf780b MCC |
48 | /* |
49 | * Memory topology is organized as: | |
50 | * Branch 0 - 2 channels: channels 0 and 1 (FDB0 PCI dev 21.0) | |
51 | * Branch 1 - 2 channels: channels 2 and 3 (FDB1 PCI dev 22.0) | |
52 | * Each channel can have to 8 DIMM sets (called as SLOTS) | |
53 | * Slots should generally be filled in pairs | |
54 | * Except on Single Channel mode of operation | |
55 | * just slot 0/channel0 filled on this mode | |
56 | * On normal operation mode, the two channels on a branch should be | |
c3af2eaf | 57 | * filled together for the same SLOT# |
fcaf780b MCC |
58 | * When in mirrored mode, Branch 1 replicate memory at Branch 0, so, the four |
59 | * channels on both branches should be filled | |
60 | */ | |
61 | ||
62 | /* Limits for i7300 */ | |
63 | #define MAX_SLOTS 8 | |
64 | #define MAX_BRANCHES 2 | |
65 | #define MAX_CH_PER_BRANCH 2 | |
66 | #define MAX_CHANNELS (MAX_CH_PER_BRANCH * MAX_BRANCHES) | |
67 | #define MAX_MIR 3 | |
68 | ||
69 | #define to_channel(ch, branch) ((((branch)) << 1) | (ch)) | |
70 | ||
71 | #define to_csrow(slot, ch, branch) \ | |
72 | (to_channel(ch, branch) | ((slot) << 2)) | |
73 | ||
b4552ace MCC |
74 | /* Device name and register DID (Device ID) */ |
75 | struct i7300_dev_info { | |
76 | const char *ctl_name; /* name for this device */ | |
77 | u16 fsb_mapping_errors; /* DID for the branchmap,control */ | |
78 | }; | |
79 | ||
80 | /* Table of devices attributes supported by this driver */ | |
81 | static 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 | ||
88 | struct i7300_dimm_info { | |
89 | int megabytes; /* size, 0 means not present */ | |
90 | }; | |
91 | ||
92 | /* driver private data structure */ | |
93 | struct 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? */ | |
118 | static struct edac_pci_ctl_info *i7300_pci; | |
119 | ||
120 | /*************************************************** | |
121 | * i7300 Register definitions for memory enumeration | |
122 | ***************************************************/ | |
123 | ||
c3af2eaf | 124 | /* |
b4552ace | 125 | * I7300 devices: |
fcaf780b | 126 | * All 3 functions of Device 16 (0,1,2) share the SAME DID and |
b4552ace MCC |
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). | |
c3af2eaf MCC |
130 | */ |
131 | ||
c3af2eaf MCC |
132 | /* |
133 | * Device 16, | |
134 | * Function 0: System Address (not documented) | |
135 | * Function 1: Memory Branch Map, Control, Errors Register | |
fcaf780b MCC |
136 | */ |
137 | ||
138 | /* OFFSETS for Function 0 */ | |
af3d8831 MCC |
139 | #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 */ | |
fcaf780b MCC |
142 | |
143 | /* OFFSETS for Function 1 */ | |
af3d8831 | 144 | #define MC_SETTINGS 0x40 |
bb81a216 MCC |
145 | #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)) | |
fcaf780b | 149 | |
bb81a216 MCC |
150 | #define MC_SETTINGS_A 0x58 |
151 | #define IS_SINGLE_MODE(mca) ((mca) & (1 << 14)) | |
d7de2bdb | 152 | |
af3d8831 | 153 | #define TOLM 0x6C |
af3d8831 MCC |
154 | |
155 | #define MIR0 0x80 | |
156 | #define MIR1 0x84 | |
157 | #define MIR2 0x88 | |
fcaf780b | 158 | |
fcaf780b MCC |
159 | /* |
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 | ||
173 | const static u16 mtr_regs [MAX_SLOTS] = { | |
174 | 0x80, 0x84, 0x88, 0x8c, | |
175 | 0x82, 0x86, 0x8a, 0x8e | |
176 | }; | |
177 | ||
b4552ace MCC |
178 | /* |
179 | * Defines to extract the vaious fields from the | |
fcaf780b MCC |
180 | * 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 | ||
fcaf780b MCC |
193 | #ifdef CONFIG_EDAC_DEBUG |
194 | /* MTR NUMROW */ | |
195 | static 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 */ | |
203 | static 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 | ||
c3af2eaf MCC |
211 | /************************************************ |
212 | * i7300 Register definitions for error detection | |
213 | ************************************************/ | |
57021918 MCC |
214 | |
215 | /* | |
216 | * Device 16.1: FBD Error Registers | |
217 | */ | |
218 | #define FERR_FAT_FBD 0x98 | |
219 | static 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 | |
230 | static 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 | ||
c3af2eaf MCC |
271 | /* |
272 | * Device 16.2: Global Error Registers | |
273 | */ | |
274 | ||
5de6e07e MCC |
275 | #define FERR_GLOBAL_HI 0x48 |
276 | static 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 | ||
c3af2eaf | 284 | #define FERR_GLOBAL_LO 0x40 |
5de6e07e | 285 | static const char *ferr_global_lo_name[] = { |
c3af2eaf MCC |
286 | [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 | }; | |
5de6e07e | 319 | #define ferr_global_lo_is_fatal(errno) ((errno < 16) ? 0 : 1) |
fcaf780b | 320 | |
8199d8cc MCC |
321 | #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 | ||
32f94726 MCC |
330 | #define REDMEMA 0xdc |
331 | ||
37b69cf9 MCC |
332 | #define REDMEMB 0x7c |
333 | #define IS_SECOND_CH(v) ((v) * (1 << 17)) | |
334 | ||
32f94726 MCC |
335 | #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 | ||
5de6e07e MCC |
344 | /******************************************** |
345 | * i7300 Functions related to error detection | |
346 | ********************************************/ | |
fcaf780b | 347 | |
5de6e07e | 348 | const char *get_err_from_table(const char *table[], int size, int pos) |
fcaf780b | 349 | { |
5de6e07e MCC |
350 | if (pos >= size) |
351 | return "Reserved"; | |
352 | ||
353 | return table[pos]; | |
fcaf780b MCC |
354 | } |
355 | ||
5de6e07e MCC |
356 | #define GET_ERR_FROM_TABLE(table, pos) \ |
357 | get_err_from_table(table, ARRAY_SIZE(table), pos) | |
358 | ||
fcaf780b | 359 | /* |
5de6e07e MCC |
360 | * i7300_process_error_global Retrieve the hardware error information from |
361 | * the hardware and cache it in the 'info' | |
362 | * structure | |
fcaf780b | 363 | */ |
f4277422 | 364 | static void i7300_process_error_global(struct mem_ctl_info *mci) |
fcaf780b | 365 | { |
5de6e07e MCC |
366 | struct i7300_pvt *pvt; |
367 | u32 errnum, value; | |
368 | unsigned long errors; | |
369 | const char *specific; | |
370 | bool is_fatal; | |
fcaf780b | 371 | |
5de6e07e | 372 | pvt = mci->pvt_info; |
fcaf780b | 373 | |
5de6e07e MCC |
374 | /* read in the 1st FATAL error register */ |
375 | 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); | |
86002324 MCC |
383 | |
384 | /* Clear the error bit */ | |
385 | pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs, | |
386 | FERR_GLOBAL_HI, value); | |
387 | ||
5de6e07e | 388 | goto error_global; |
fcaf780b MCC |
389 | } |
390 | ||
5de6e07e MCC |
391 | 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); | |
86002324 MCC |
399 | |
400 | /* Clear the error bit */ | |
401 | pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs, | |
402 | FERR_GLOBAL_LO, value); | |
403 | ||
5de6e07e MCC |
404 | goto error_global; |
405 | } | |
406 | return; | |
fcaf780b | 407 | |
5de6e07e MCC |
408 | error_global: |
409 | i7300_mc_printk(mci, KERN_EMERG, "%s misc error: %s\n", | |
410 | is_fatal ? "Fatal" : "NOT fatal", specific); | |
fcaf780b MCC |
411 | } |
412 | ||
57021918 MCC |
413 | /* |
414 | * i7300_process_fbd_error Retrieve the hardware error information from | |
415 | * the hardware and cache it in the 'info' | |
416 | * structure | |
417 | */ | |
f4277422 | 418 | static void i7300_process_fbd_error(struct mem_ctl_info *mci) |
57021918 MCC |
419 | { |
420 | struct i7300_pvt *pvt; | |
421 | u32 errnum, value; | |
8199d8cc | 422 | u16 val16; |
37b69cf9 | 423 | unsigned branch, channel, bank, rank, cas, ras; |
32f94726 MCC |
424 | u32 syndrome; |
425 | ||
57021918 MCC |
426 | unsigned long errors; |
427 | const char *specific; | |
32f94726 | 428 | bool is_wr; |
57021918 MCC |
429 | |
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); | |
57021918 MCC |
440 | |
441 | branch = (GET_FBD_FAT_IDX(value) == 2) ? 1 : 0; | |
8199d8cc MCC |
442 | 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); | |
446 | ||
447 | 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))", | |
32f94726 | 457 | branch, bank, |
8199d8cc MCC |
458 | 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); | |
57021918 MCC |
466 | } |
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); | |
57021918 MCC |
476 | |
477 | /* Clear the error bit */ | |
478 | pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs, | |
479 | FERR_GLOBAL_LO, value); | |
480 | ||
32f94726 MCC |
481 | 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); | |
57021918 | 492 | |
32f94726 MCC |
493 | is_wr = RECMEMB_IS_WR(value); |
494 | cas = RECMEMB_CAS(value); | |
495 | ras = RECMEMB_RAS(value); | |
8199d8cc | 496 | |
37b69cf9 MCC |
497 | 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 | ||
32f94726 MCC |
504 | /* Form out message */ |
505 | snprintf(pvt->tmp_prt_buffer, PAGE_SIZE, | |
37b69cf9 | 506 | "Corrected error (Branch=%d, Channel %d), " |
32f94726 MCC |
507 | " DRAM-Bank=%d %s " |
508 | "RAS=%d CAS=%d, CE Err=0x%lx, Syndrome=0x%08x(%s))", | |
37b69cf9 | 509 | branch, channel, |
32f94726 MCC |
510 | 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 | */ | |
37b69cf9 | 521 | edac_mc_handle_fbd_ce(mci, rank, channel, |
32f94726 MCC |
522 | pvt->tmp_prt_buffer); |
523 | } | |
524 | return; | |
57021918 MCC |
525 | } |
526 | ||
fcaf780b | 527 | /* |
f4277422 | 528 | * i7300_check_error Retrieve the hardware error information from |
5de6e07e MCC |
529 | * the hardware and cache it in the 'info' |
530 | * structure | |
fcaf780b | 531 | */ |
f4277422 | 532 | static void i7300_check_error(struct mem_ctl_info *mci) |
5de6e07e | 533 | { |
f4277422 MCC |
534 | i7300_process_error_global(mci); |
535 | i7300_process_fbd_error(mci); | |
5de6e07e | 536 | }; |
fcaf780b MCC |
537 | |
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 | */ | |
544 | static void i7300_clear_error(struct mem_ctl_info *mci) | |
545 | { | |
e4327605 MCC |
546 | 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 | */ | |
fcaf780b | 552 | |
e4327605 MCC |
553 | /* 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); | |
fcaf780b MCC |
574 | } |
575 | ||
fcaf780b MCC |
576 | /* |
577 | * i7300_enable_error_reporting | |
578 | * Turn on the memory reporting features of the hardware | |
579 | */ | |
580 | static void i7300_enable_error_reporting(struct mem_ctl_info *mci) | |
581 | { | |
57021918 MCC |
582 | 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); | |
fcaf780b | 594 | } |
5de6e07e MCC |
595 | |
596 | /************************************************ | |
597 | * i7300 Functions related to memory enumberation | |
598 | ************************************************/ | |
fcaf780b MCC |
599 | |
600 | /* | |
601 | * determine_mtr(pvt, csrow, channel) | |
602 | * | |
603 | * return the proper MTR register as determine by the csrow and desired channel | |
604 | */ | |
605 | static 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; | |
116389ed MCC |
661 | |
662 | /* | |
15154c57 | 663 | * The type of error detection actually depends of the |
116389ed | 664 | * mode of operation. When it is just one single memory chip, at |
15154c57 MCC |
665 | * socket 0, channel 0, it uses 8-byte-over-32-byte SECDED+ code. |
666 | * In normal or mirrored mode, it uses Lockstep mode, | |
116389ed MCC |
667 | * with the possibility of using an extended algorithm for x8 memories |
668 | * See datasheet Sections 7.3.6 to 7.3.8 | |
669 | */ | |
15154c57 MCC |
670 | |
671 | if (IS_SINGLE_MODE(pvt->mc_settings_a)) { | |
672 | p_csrow->edac_mode = EDAC_SECDED; | |
3b330f67 | 673 | debugf2("\t\tECC code is 8-byte-over-32-byte SECDED+ code\n"); |
15154c57 | 674 | } else { |
3b330f67 | 675 | debugf2("\t\tECC code is on Lockstep mode\n"); |
28c2ce7c | 676 | if (MTR_DRAM_WIDTH(mtr) == 8) |
15154c57 MCC |
677 | p_csrow->edac_mode = EDAC_S8ECD8ED; |
678 | else | |
679 | p_csrow->edac_mode = EDAC_S4ECD4ED; | |
680 | } | |
fcaf780b MCC |
681 | |
682 | /* ask what device type on this row */ | |
28c2ce7c | 683 | if (MTR_DRAM_WIDTH(mtr) == 8) { |
3b330f67 | 684 | debugf2("\t\tScrub algorithm for x8 is on %s mode\n", |
d7de2bdb MCC |
685 | IS_SCRBALGO_ENHANCED(pvt->mc_settings) ? |
686 | "enhanced" : "normal"); | |
687 | ||
fcaf780b | 688 | p_csrow->dtype = DEV_X8; |
d7de2bdb | 689 | } else |
fcaf780b MCC |
690 | 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 | */ | |
701 | static void print_dimm_size(struct i7300_pvt *pvt) | |
702 | { | |
703 | struct i7300_dimm_info *dinfo; | |
85580ea4 | 704 | char *p; |
fcaf780b MCC |
705 | int space, n; |
706 | int channel, slot; | |
707 | ||
708 | space = PAGE_SIZE; | |
85580ea4 | 709 | p = pvt->tmp_prt_buffer; |
fcaf780b MCC |
710 | |
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 | } | |
85580ea4 MCC |
719 | debugf2("%s\n", pvt->tmp_prt_buffer); |
720 | p = pvt->tmp_prt_buffer; | |
fcaf780b MCC |
721 | space = PAGE_SIZE; |
722 | n = snprintf(p, space, "-------------------------------" | |
723 | "------------------------------"); | |
724 | p += n; | |
725 | space -= n; | |
85580ea4 MCC |
726 | debugf2("%s\n", pvt->tmp_prt_buffer); |
727 | p = pvt->tmp_prt_buffer; | |
fcaf780b MCC |
728 | 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 | ||
85580ea4 MCC |
742 | debugf2("%s\n", pvt->tmp_prt_buffer); |
743 | p = pvt->tmp_prt_buffer; | |
fcaf780b MCC |
744 | space = PAGE_SIZE; |
745 | } | |
746 | ||
747 | n = snprintf(p, space, "-------------------------------" | |
748 | "------------------------------"); | |
749 | p += n; | |
750 | space -= n; | |
85580ea4 MCC |
751 | debugf2("%s\n", pvt->tmp_prt_buffer); |
752 | p = pvt->tmp_prt_buffer; | |
fcaf780b | 753 | space = PAGE_SIZE; |
fcaf780b MCC |
754 | } |
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 | */ | |
765 | static 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); | |
3e57eef6 | 784 | pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch], AMBPRESENT_0, |
fcaf780b MCC |
785 | &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); | |
3e57eef6 | 790 | pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch], AMBPRESENT_1, |
fcaf780b MCC |
791 | &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++) { | |
3e57eef6 | 800 | pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch], |
fcaf780b MCC |
801 | 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 | ||
830 | static 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 | */ | |
846 | static 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 | ||
3e57eef6 | 854 | pci_read_config_dword(pvt->pci_dev_16_0_fsb_ctlr, AMBASE, |
fcaf780b MCC |
855 | (u32 *) &pvt->ambase); |
856 | ||
857 | debugf2("AMBASE= 0x%lx\n", (long unsigned int)pvt->ambase); | |
858 | ||
859 | /* Get the Branch Map regs */ | |
3e57eef6 | 860 | pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, TOLM, &pvt->tolm); |
fcaf780b MCC |
861 | 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 | ||
af3d8831 | 869 | /* Get memory controller settings */ |
3e57eef6 | 870 | pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, MC_SETTINGS, |
af3d8831 | 871 | &pvt->mc_settings); |
bb81a216 MCC |
872 | pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, MC_SETTINGS_A, |
873 | &pvt->mc_settings_a); | |
d7de2bdb | 874 | |
bb81a216 MCC |
875 | 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", | |
d7de2bdb | 879 | IS_MIRRORED(pvt->mc_settings) ? "mirrored" : "non-mirrored"); |
bb81a216 | 880 | |
af3d8831 | 881 | debugf0("Error detection is %s\n", |
d7de2bdb MCC |
882 | IS_ECC_ENABLED(pvt->mc_settings) ? "enabled" : "disabled"); |
883 | debugf0("Retry is %s\n", | |
884 | IS_RETRY_ENABLED(pvt->mc_settings) ? "enabled" : "disabled"); | |
af3d8831 MCC |
885 | |
886 | /* Get Memory Interleave Range registers */ | |
3e57eef6 MCC |
887 | 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]); | |
fcaf780b MCC |
890 | |
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 | ||
5de6e07e MCC |
906 | /************************************************* |
907 | * i7300 Functions related to device probe/release | |
908 | *************************************************/ | |
909 | ||
fcaf780b MCC |
910 | /* |
911 | * i7300_put_devices 'put' all the devices that we have | |
912 | * reserved via 'get' | |
913 | */ | |
914 | static 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++) | |
3e57eef6 MCC |
923 | 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); | |
fcaf780b MCC |
926 | } |
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 | */ | |
934 | static 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; | |
3e57eef6 | 943 | while (!pvt->pci_dev_16_1_fsb_addr_map || !pvt->pci_dev_16_2_fsb_err_regs) { |
fcaf780b MCC |
944 | 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: | |
3e57eef6 | 961 | pvt->pci_dev_16_1_fsb_addr_map = pdev; |
fcaf780b MCC |
962 | break; |
963 | case 2: | |
3e57eef6 | 964 | pvt->pci_dev_16_2_fsb_err_regs = pdev; |
fcaf780b MCC |
965 | break; |
966 | } | |
967 | } | |
968 | ||
969 | debugf1("System Address, processor bus- PCI Bus ID: %s %x:%x\n", | |
3e57eef6 MCC |
970 | 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); | |
fcaf780b | 972 | debugf1("Branchmap, control and errors - PCI Bus ID: %s %x:%x\n", |
3e57eef6 MCC |
973 | 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); | |
fcaf780b | 975 | debugf1("FSB Error Regs - PCI Bus ID: %s %x:%x\n", |
3e57eef6 MCC |
976 | 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); | |
fcaf780b | 978 | |
3e57eef6 | 979 | pvt->pci_dev_2x_0_fbd_branch[0] = pci_get_device(PCI_VENDOR_ID_INTEL, |
fcaf780b MCC |
980 | PCI_DEVICE_ID_INTEL_I7300_MCH_FB0, |
981 | NULL); | |
3e57eef6 | 982 | if (!pvt->pci_dev_2x_0_fbd_branch[0]) { |
fcaf780b MCC |
983 | 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 | ||
3e57eef6 | 990 | pvt->pci_dev_2x_0_fbd_branch[1] = pci_get_device(PCI_VENDOR_ID_INTEL, |
fcaf780b MCC |
991 | PCI_DEVICE_ID_INTEL_I7300_MCH_FB1, |
992 | NULL); | |
3e57eef6 | 993 | if (!pvt->pci_dev_2x_0_fbd_branch[1]) { |
fcaf780b MCC |
994 | 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 | ||
1005 | error: | |
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 | */ | |
1017 | static 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; | |
3e57eef6 | 1062 | pvt->pci_dev_16_0_fsb_ctlr = pdev; /* Record this device in our private */ |
fcaf780b | 1063 | |
85580ea4 MCC |
1064 | 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 | ||
fcaf780b MCC |
1070 | /* '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 | ||
fcaf780b MCC |
1084 | /* Set the function pointer to an actual operation function */ |
1085 | mci->edac_check = i7300_check_error; | |
fcaf780b MCC |
1086 | |
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 { | |
fcaf780b MCC |
1095 | debugf1("MC: Enable error reporting now\n"); |
1096 | i7300_enable_error_reporting(mci); | |
fcaf780b MCC |
1097 | } |
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 | ||
fcaf780b | 1109 | i7300_clear_error(mci); |
fcaf780b MCC |
1110 | |
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 */ | |
1125 | fail1: | |
1126 | ||
1127 | i7300_put_devices(mci); | |
1128 | ||
1129 | fail0: | |
85580ea4 | 1130 | kfree(pvt->tmp_prt_buffer); |
fcaf780b MCC |
1131 | 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 | */ | |
1142 | static 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 | */ | |
1162 | static void __devexit i7300_remove_one(struct pci_dev *pdev) | |
1163 | { | |
1164 | struct mem_ctl_info *mci; | |
85580ea4 | 1165 | char *tmp; |
fcaf780b MCC |
1166 | |
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 | ||
85580ea4 MCC |
1176 | tmp = ((struct i7300_pvt *)mci->pvt_info)->tmp_prt_buffer; |
1177 | ||
fcaf780b MCC |
1178 | /* retrieve references to resources, and free those resources */ |
1179 | i7300_put_devices(mci); | |
1180 | ||
85580ea4 | 1181 | kfree(tmp); |
fcaf780b MCC |
1182 | 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 | */ | |
1190 | static 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 | ||
1195 | MODULE_DEVICE_TABLE(pci, i7300_pci_tbl); | |
1196 | ||
1197 | /* | |
1198 | * i7300_driver pci_driver structure for this module | |
1199 | * | |
1200 | */ | |
1201 | static 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 | */ | |
1212 | static 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 | */ | |
1230 | static void __exit i7300_exit(void) | |
1231 | { | |
1232 | debugf2("MC: " __FILE__ ": %s()\n", __func__); | |
1233 | pci_unregister_driver(&i7300_driver); | |
1234 | } | |
1235 | ||
1236 | module_init(i7300_init); | |
1237 | module_exit(i7300_exit); | |
1238 | ||
1239 | MODULE_LICENSE("GPL"); | |
1240 | MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>"); | |
1241 | MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)"); | |
1242 | MODULE_DESCRIPTION("MC Driver for Intel I7300 memory controllers - " | |
1243 | I7300_REVISION); | |
1244 | ||
1245 | module_param(edac_op_state, int, 0444); | |
1246 | MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI"); |