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