xref: /openbmc/linux/drivers/edac/i7300_edac.c (revision 7e881856eee8b889b76cd1d8e04ce2fc79b72099)
1fcaf780bSMauro Carvalho Chehab /*
2fcaf780bSMauro Carvalho Chehab  * Intel 7300 class Memory Controllers kernel module (Clarksboro)
3fcaf780bSMauro Carvalho Chehab  *
4fcaf780bSMauro Carvalho Chehab  * This file may be distributed under the terms of the
5fcaf780bSMauro Carvalho Chehab  * GNU General Public License version 2 only.
6fcaf780bSMauro Carvalho Chehab  *
7fcaf780bSMauro Carvalho Chehab  * Copyright (c) 2010 by:
8fcaf780bSMauro Carvalho Chehab  *	 Mauro Carvalho Chehab <mchehab@redhat.com>
9fcaf780bSMauro Carvalho Chehab  *
10fcaf780bSMauro Carvalho Chehab  * Red Hat Inc. http://www.redhat.com
11fcaf780bSMauro Carvalho Chehab  *
12fcaf780bSMauro Carvalho Chehab  * Intel 7300 Chipset Memory Controller Hub (MCH) - Datasheet
13fcaf780bSMauro Carvalho Chehab  *	http://www.intel.com/Assets/PDF/datasheet/318082.pdf
14fcaf780bSMauro Carvalho Chehab  *
15fcaf780bSMauro Carvalho Chehab  * TODO: The chipset allow checking for PCI Express errors also. Currently,
16fcaf780bSMauro Carvalho Chehab  *	 the driver covers only memory error errors
17fcaf780bSMauro Carvalho Chehab  *
18fcaf780bSMauro Carvalho Chehab  * This driver uses "csrows" EDAC attribute to represent DIMM slot#
19fcaf780bSMauro Carvalho Chehab  */
20fcaf780bSMauro Carvalho Chehab 
21fcaf780bSMauro Carvalho Chehab #include <linux/module.h>
22fcaf780bSMauro Carvalho Chehab #include <linux/init.h>
23fcaf780bSMauro Carvalho Chehab #include <linux/pci.h>
24fcaf780bSMauro Carvalho Chehab #include <linux/pci_ids.h>
25fcaf780bSMauro Carvalho Chehab #include <linux/slab.h>
26fcaf780bSMauro Carvalho Chehab #include <linux/edac.h>
27fcaf780bSMauro Carvalho Chehab #include <linux/mmzone.h>
28fcaf780bSMauro Carvalho Chehab 
29fcaf780bSMauro Carvalho Chehab #include "edac_core.h"
30fcaf780bSMauro Carvalho Chehab 
31fcaf780bSMauro Carvalho Chehab /*
32fcaf780bSMauro Carvalho Chehab  * Alter this version for the I7300 module when modifications are made
33fcaf780bSMauro Carvalho Chehab  */
34152ba394SMichal Marek #define I7300_REVISION    " Ver: 1.0.0"
35fcaf780bSMauro Carvalho Chehab 
36fcaf780bSMauro Carvalho Chehab #define EDAC_MOD_STR      "i7300_edac"
37fcaf780bSMauro Carvalho Chehab 
38fcaf780bSMauro Carvalho Chehab #define i7300_printk(level, fmt, arg...) \
39fcaf780bSMauro Carvalho Chehab 	edac_printk(level, "i7300", fmt, ##arg)
40fcaf780bSMauro Carvalho Chehab 
41fcaf780bSMauro Carvalho Chehab #define i7300_mc_printk(mci, level, fmt, arg...) \
42fcaf780bSMauro Carvalho Chehab 	edac_mc_chipset_printk(mci, level, "i7300", fmt, ##arg)
43fcaf780bSMauro Carvalho Chehab 
44b4552aceSMauro Carvalho Chehab /***********************************************
45b4552aceSMauro Carvalho Chehab  * i7300 Limit constants Structs and static vars
46b4552aceSMauro Carvalho Chehab  ***********************************************/
47b4552aceSMauro Carvalho Chehab 
48fcaf780bSMauro Carvalho Chehab /*
49fcaf780bSMauro Carvalho Chehab  * Memory topology is organized as:
50fcaf780bSMauro Carvalho Chehab  *	Branch 0 - 2 channels: channels 0 and 1 (FDB0 PCI dev 21.0)
51fcaf780bSMauro Carvalho Chehab  *	Branch 1 - 2 channels: channels 2 and 3 (FDB1 PCI dev 22.0)
52fcaf780bSMauro Carvalho Chehab  * Each channel can have to 8 DIMM sets (called as SLOTS)
53fcaf780bSMauro Carvalho Chehab  * Slots should generally be filled in pairs
54fcaf780bSMauro Carvalho Chehab  *	Except on Single Channel mode of operation
55fcaf780bSMauro Carvalho Chehab  *		just slot 0/channel0 filled on this mode
56fcaf780bSMauro Carvalho Chehab  *	On normal operation mode, the two channels on a branch should be
57c3af2eafSMauro Carvalho Chehab  *		filled together for the same SLOT#
58fcaf780bSMauro Carvalho Chehab  * When in mirrored mode, Branch 1 replicate memory at Branch 0, so, the four
59fcaf780bSMauro Carvalho Chehab  *		channels on both branches should be filled
60fcaf780bSMauro Carvalho Chehab  */
61fcaf780bSMauro Carvalho Chehab 
62fcaf780bSMauro Carvalho Chehab /* Limits for i7300 */
63fcaf780bSMauro Carvalho Chehab #define MAX_SLOTS		8
64fcaf780bSMauro Carvalho Chehab #define MAX_BRANCHES		2
65fcaf780bSMauro Carvalho Chehab #define MAX_CH_PER_BRANCH	2
66fcaf780bSMauro Carvalho Chehab #define MAX_CHANNELS		(MAX_CH_PER_BRANCH * MAX_BRANCHES)
67fcaf780bSMauro Carvalho Chehab #define MAX_MIR			3
68fcaf780bSMauro Carvalho Chehab 
69fcaf780bSMauro Carvalho Chehab #define to_channel(ch, branch)	((((branch)) << 1) | (ch))
70fcaf780bSMauro Carvalho Chehab 
71fcaf780bSMauro Carvalho Chehab #define to_csrow(slot, ch, branch)					\
72fcaf780bSMauro Carvalho Chehab 		(to_channel(ch, branch) | ((slot) << 2))
73fcaf780bSMauro Carvalho Chehab 
74b4552aceSMauro Carvalho Chehab /* Device name and register DID (Device ID) */
75b4552aceSMauro Carvalho Chehab struct i7300_dev_info {
76b4552aceSMauro Carvalho Chehab 	const char *ctl_name;	/* name for this device */
77b4552aceSMauro Carvalho Chehab 	u16 fsb_mapping_errors;	/* DID for the branchmap,control */
78b4552aceSMauro Carvalho Chehab };
79fcaf780bSMauro Carvalho Chehab 
80b4552aceSMauro Carvalho Chehab /* Table of devices attributes supported by this driver */
81b4552aceSMauro Carvalho Chehab static const struct i7300_dev_info i7300_devs[] = {
82b4552aceSMauro Carvalho Chehab 	{
83b4552aceSMauro Carvalho Chehab 		.ctl_name = "I7300",
84b4552aceSMauro Carvalho Chehab 		.fsb_mapping_errors = PCI_DEVICE_ID_INTEL_I7300_MCH_ERR,
85b4552aceSMauro Carvalho Chehab 	},
86b4552aceSMauro Carvalho Chehab };
87b4552aceSMauro Carvalho Chehab 
88b4552aceSMauro Carvalho Chehab struct i7300_dimm_info {
89b4552aceSMauro Carvalho Chehab 	int megabytes;		/* size, 0 means not present  */
90b4552aceSMauro Carvalho Chehab };
91b4552aceSMauro Carvalho Chehab 
92b4552aceSMauro Carvalho Chehab /* driver private data structure */
93b4552aceSMauro Carvalho Chehab struct i7300_pvt {
94b4552aceSMauro Carvalho Chehab 	struct pci_dev *pci_dev_16_0_fsb_ctlr;		/* 16.0 */
95b4552aceSMauro Carvalho Chehab 	struct pci_dev *pci_dev_16_1_fsb_addr_map;	/* 16.1 */
96b4552aceSMauro Carvalho Chehab 	struct pci_dev *pci_dev_16_2_fsb_err_regs;	/* 16.2 */
97b4552aceSMauro Carvalho Chehab 	struct pci_dev *pci_dev_2x_0_fbd_branch[MAX_BRANCHES];	/* 21.0  and 22.0 */
98b4552aceSMauro Carvalho Chehab 
99b4552aceSMauro Carvalho Chehab 	u16 tolm;				/* top of low memory */
100b4552aceSMauro Carvalho Chehab 	u64 ambase;				/* AMB BAR */
101b4552aceSMauro Carvalho Chehab 
102b4552aceSMauro Carvalho Chehab 	u32 mc_settings;			/* Report several settings */
103b4552aceSMauro Carvalho Chehab 	u32 mc_settings_a;
104b4552aceSMauro Carvalho Chehab 
105b4552aceSMauro Carvalho Chehab 	u16 mir[MAX_MIR];			/* Memory Interleave Reg*/
106b4552aceSMauro Carvalho Chehab 
107b4552aceSMauro Carvalho Chehab 	u16 mtr[MAX_SLOTS][MAX_BRANCHES];	/* Memory Technlogy Reg */
108b4552aceSMauro Carvalho Chehab 	u16 ambpresent[MAX_CHANNELS];		/* AMB present regs */
109b4552aceSMauro Carvalho Chehab 
110b4552aceSMauro Carvalho Chehab 	/* DIMM information matrix, allocating architecture maximums */
111b4552aceSMauro Carvalho Chehab 	struct i7300_dimm_info dimm_info[MAX_SLOTS][MAX_CHANNELS];
112b4552aceSMauro Carvalho Chehab 
113b4552aceSMauro Carvalho Chehab 	/* Temporary buffer for use when preparing error messages */
114b4552aceSMauro Carvalho Chehab 	char *tmp_prt_buffer;
115b4552aceSMauro Carvalho Chehab };
116b4552aceSMauro Carvalho Chehab 
117b4552aceSMauro Carvalho Chehab /* FIXME: Why do we need to have this static? */
118b4552aceSMauro Carvalho Chehab static struct edac_pci_ctl_info *i7300_pci;
119b4552aceSMauro Carvalho Chehab 
120b4552aceSMauro Carvalho Chehab /***************************************************
121b4552aceSMauro Carvalho Chehab  * i7300 Register definitions for memory enumeration
122b4552aceSMauro Carvalho Chehab  ***************************************************/
123b4552aceSMauro Carvalho Chehab 
124b4552aceSMauro Carvalho Chehab /*
125c3af2eafSMauro Carvalho Chehab  * Device 16,
126c3af2eafSMauro Carvalho Chehab  * Function 0: System Address (not documented)
127c3af2eafSMauro Carvalho Chehab  * Function 1: Memory Branch Map, Control, Errors Register
128c3af2eafSMauro Carvalho Chehab  */
129c3af2eafSMauro Carvalho Chehab 
130fcaf780bSMauro Carvalho Chehab 	/* OFFSETS for Function 0 */
131fcaf780bSMauro Carvalho Chehab #define AMBASE			0x48 /* AMB Mem Mapped Reg Region Base */
132fcaf780bSMauro Carvalho Chehab #define MAXCH			0x56 /* Max Channel Number */
133fcaf780bSMauro Carvalho Chehab #define MAXDIMMPERCH		0x57 /* Max DIMM PER Channel Number */
134fcaf780bSMauro Carvalho Chehab 
135fcaf780bSMauro Carvalho Chehab 	/* OFFSETS for Function 1 */
136af3d8831SMauro Carvalho Chehab #define MC_SETTINGS		0x40
137d7de2bdbSMauro Carvalho Chehab   #define IS_MIRRORED(mc)		((mc) & (1 << 16))
138d7de2bdbSMauro Carvalho Chehab   #define IS_ECC_ENABLED(mc)		((mc) & (1 << 5))
139d7de2bdbSMauro Carvalho Chehab   #define IS_RETRY_ENABLED(mc)		((mc) & (1 << 31))
140d7de2bdbSMauro Carvalho Chehab   #define IS_SCRBALGO_ENHANCED(mc)	((mc) & (1 << 8))
141d7de2bdbSMauro Carvalho Chehab 
142bb81a216SMauro Carvalho Chehab #define MC_SETTINGS_A		0x58
143bb81a216SMauro Carvalho Chehab   #define IS_SINGLE_MODE(mca)		((mca) & (1 << 14))
144d7de2bdbSMauro Carvalho Chehab 
145fcaf780bSMauro Carvalho Chehab #define TOLM			0x6C
146fcaf780bSMauro Carvalho Chehab 
147fcaf780bSMauro Carvalho Chehab #define MIR0			0x80
148fcaf780bSMauro Carvalho Chehab #define MIR1			0x84
149fcaf780bSMauro Carvalho Chehab #define MIR2			0x88
150fcaf780bSMauro Carvalho Chehab 
151fcaf780bSMauro Carvalho Chehab /*
152fcaf780bSMauro Carvalho Chehab  * Note: Other Intel EDAC drivers use AMBPRESENT to identify if the available
153fcaf780bSMauro Carvalho Chehab  * memory. From datasheet item 7.3.1 (FB-DIMM technology & organization), it
154fcaf780bSMauro Carvalho Chehab  * seems that we cannot use this information directly for the same usage.
155fcaf780bSMauro Carvalho Chehab  * Each memory slot may have up to 2 AMB interfaces, one for income and another
156fcaf780bSMauro Carvalho Chehab  * for outcome interface to the next slot.
157fcaf780bSMauro Carvalho Chehab  * For now, the driver just stores the AMB present registers, but rely only at
158fcaf780bSMauro Carvalho Chehab  * the MTR info to detect memory.
159fcaf780bSMauro Carvalho Chehab  * Datasheet is also not clear about how to map each AMBPRESENT registers to
160fcaf780bSMauro Carvalho Chehab  * one of the 4 available channels.
161fcaf780bSMauro Carvalho Chehab  */
162fcaf780bSMauro Carvalho Chehab #define AMBPRESENT_0	0x64
163fcaf780bSMauro Carvalho Chehab #define AMBPRESENT_1	0x66
164fcaf780bSMauro Carvalho Chehab 
16542b16b3fSJesper Juhl static const u16 mtr_regs[MAX_SLOTS] = {
166fcaf780bSMauro Carvalho Chehab 	0x80, 0x84, 0x88, 0x8c,
167fcaf780bSMauro Carvalho Chehab 	0x82, 0x86, 0x8a, 0x8e
168fcaf780bSMauro Carvalho Chehab };
169fcaf780bSMauro Carvalho Chehab 
170b4552aceSMauro Carvalho Chehab /*
171b4552aceSMauro Carvalho Chehab  * Defines to extract the vaious fields from the
172fcaf780bSMauro Carvalho Chehab  *	MTRx - Memory Technology Registers
173fcaf780bSMauro Carvalho Chehab  */
174fcaf780bSMauro Carvalho Chehab #define MTR_DIMMS_PRESENT(mtr)		((mtr) & (1 << 8))
175fcaf780bSMauro Carvalho Chehab #define MTR_DIMMS_ETHROTTLE(mtr)	((mtr) & (1 << 7))
176fcaf780bSMauro Carvalho Chehab #define MTR_DRAM_WIDTH(mtr)		(((mtr) & (1 << 6)) ? 8 : 4)
177fcaf780bSMauro Carvalho Chehab #define MTR_DRAM_BANKS(mtr)		(((mtr) & (1 << 5)) ? 8 : 4)
178fcaf780bSMauro Carvalho Chehab #define MTR_DIMM_RANKS(mtr)		(((mtr) & (1 << 4)) ? 1 : 0)
179fcaf780bSMauro Carvalho Chehab #define MTR_DIMM_ROWS(mtr)		(((mtr) >> 2) & 0x3)
180fcaf780bSMauro Carvalho Chehab #define MTR_DRAM_BANKS_ADDR_BITS	2
181fcaf780bSMauro Carvalho Chehab #define MTR_DIMM_ROWS_ADDR_BITS(mtr)	(MTR_DIMM_ROWS(mtr) + 13)
182fcaf780bSMauro Carvalho Chehab #define MTR_DIMM_COLS(mtr)		((mtr) & 0x3)
183fcaf780bSMauro Carvalho Chehab #define MTR_DIMM_COLS_ADDR_BITS(mtr)	(MTR_DIMM_COLS(mtr) + 10)
184fcaf780bSMauro Carvalho Chehab 
185c3af2eafSMauro Carvalho Chehab /************************************************
186c3af2eafSMauro Carvalho Chehab  * i7300 Register definitions for error detection
187c3af2eafSMauro Carvalho Chehab  ************************************************/
18857021918SMauro Carvalho Chehab 
18957021918SMauro Carvalho Chehab /*
19057021918SMauro Carvalho Chehab  * Device 16.1: FBD Error Registers
19157021918SMauro Carvalho Chehab  */
19257021918SMauro Carvalho Chehab #define FERR_FAT_FBD	0x98
19357021918SMauro Carvalho Chehab static const char *ferr_fat_fbd_name[] = {
19457021918SMauro Carvalho Chehab 	[22] = "Non-Redundant Fast Reset Timeout",
19557021918SMauro Carvalho Chehab 	[2]  = ">Tmid Thermal event with intelligent throttling disabled",
19657021918SMauro Carvalho Chehab 	[1]  = "Memory or FBD configuration CRC read error",
19757021918SMauro Carvalho Chehab 	[0]  = "Memory Write error on non-redundant retry or "
19857021918SMauro Carvalho Chehab 	       "FBD configuration Write error on retry",
19957021918SMauro Carvalho Chehab };
20057021918SMauro Carvalho Chehab #define GET_FBD_FAT_IDX(fbderr)	(fbderr & (3 << 28))
20157021918SMauro Carvalho Chehab #define FERR_FAT_FBD_ERR_MASK ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3))
20257021918SMauro Carvalho Chehab 
20357021918SMauro Carvalho Chehab #define FERR_NF_FBD	0xa0
20457021918SMauro Carvalho Chehab static const char *ferr_nf_fbd_name[] = {
20557021918SMauro Carvalho Chehab 	[24] = "DIMM-Spare Copy Completed",
20657021918SMauro Carvalho Chehab 	[23] = "DIMM-Spare Copy Initiated",
20757021918SMauro Carvalho Chehab 	[22] = "Redundant Fast Reset Timeout",
20857021918SMauro Carvalho Chehab 	[21] = "Memory Write error on redundant retry",
20957021918SMauro Carvalho Chehab 	[18] = "SPD protocol Error",
21057021918SMauro Carvalho Chehab 	[17] = "FBD Northbound parity error on FBD Sync Status",
21157021918SMauro Carvalho Chehab 	[16] = "Correctable Patrol Data ECC",
21257021918SMauro Carvalho Chehab 	[15] = "Correctable Resilver- or Spare-Copy Data ECC",
21357021918SMauro Carvalho Chehab 	[14] = "Correctable Mirrored Demand Data ECC",
21457021918SMauro Carvalho Chehab 	[13] = "Correctable Non-Mirrored Demand Data ECC",
21557021918SMauro Carvalho Chehab 	[11] = "Memory or FBD configuration CRC read error",
21657021918SMauro Carvalho Chehab 	[10] = "FBD Configuration Write error on first attempt",
21757021918SMauro Carvalho Chehab 	[9]  = "Memory Write error on first attempt",
21857021918SMauro Carvalho Chehab 	[8]  = "Non-Aliased Uncorrectable Patrol Data ECC",
21957021918SMauro Carvalho Chehab 	[7]  = "Non-Aliased Uncorrectable Resilver- or Spare-Copy Data ECC",
22057021918SMauro Carvalho Chehab 	[6]  = "Non-Aliased Uncorrectable Mirrored Demand Data ECC",
22157021918SMauro Carvalho Chehab 	[5]  = "Non-Aliased Uncorrectable Non-Mirrored Demand Data ECC",
22257021918SMauro Carvalho Chehab 	[4]  = "Aliased Uncorrectable Patrol Data ECC",
22357021918SMauro Carvalho Chehab 	[3]  = "Aliased Uncorrectable Resilver- or Spare-Copy Data ECC",
22457021918SMauro Carvalho Chehab 	[2]  = "Aliased Uncorrectable Mirrored Demand Data ECC",
22557021918SMauro Carvalho Chehab 	[1]  = "Aliased Uncorrectable Non-Mirrored Demand Data ECC",
22657021918SMauro Carvalho Chehab 	[0]  = "Uncorrectable Data ECC on Replay",
22757021918SMauro Carvalho Chehab };
22857021918SMauro Carvalho Chehab #define GET_FBD_NF_IDX(fbderr)	(fbderr & (3 << 28))
22957021918SMauro Carvalho Chehab #define FERR_NF_FBD_ERR_MASK ((1 << 24) | (1 << 23) | (1 << 22) | (1 << 21) |\
23057021918SMauro Carvalho Chehab 			      (1 << 18) | (1 << 17) | (1 << 16) | (1 << 15) |\
23157021918SMauro Carvalho Chehab 			      (1 << 14) | (1 << 13) | (1 << 11) | (1 << 10) |\
23257021918SMauro Carvalho Chehab 			      (1 << 9)  | (1 << 8)  | (1 << 7)  | (1 << 6)  |\
23357021918SMauro Carvalho Chehab 			      (1 << 5)  | (1 << 4)  | (1 << 3)  | (1 << 2)  |\
23457021918SMauro Carvalho Chehab 			      (1 << 1)  | (1 << 0))
23557021918SMauro Carvalho Chehab 
23657021918SMauro Carvalho Chehab #define EMASK_FBD	0xa8
23757021918SMauro Carvalho Chehab #define EMASK_FBD_ERR_MASK ((1 << 27) | (1 << 26) | (1 << 25) | (1 << 24) |\
23857021918SMauro Carvalho Chehab 			    (1 << 22) | (1 << 21) | (1 << 20) | (1 << 19) |\
23957021918SMauro Carvalho Chehab 			    (1 << 18) | (1 << 17) | (1 << 16) | (1 << 14) |\
24057021918SMauro Carvalho Chehab 			    (1 << 13) | (1 << 12) | (1 << 11) | (1 << 10) |\
24157021918SMauro Carvalho Chehab 			    (1 << 9)  | (1 << 8)  | (1 << 7)  | (1 << 6)  |\
24257021918SMauro Carvalho Chehab 			    (1 << 5)  | (1 << 4)  | (1 << 3)  | (1 << 2)  |\
24357021918SMauro Carvalho Chehab 			    (1 << 1)  | (1 << 0))
24457021918SMauro Carvalho Chehab 
245c3af2eafSMauro Carvalho Chehab /*
246c3af2eafSMauro Carvalho Chehab  * Device 16.2: Global Error Registers
247c3af2eafSMauro Carvalho Chehab  */
248c3af2eafSMauro Carvalho Chehab 
2495de6e07eSMauro Carvalho Chehab #define FERR_GLOBAL_HI	0x48
2505de6e07eSMauro Carvalho Chehab static const char *ferr_global_hi_name[] = {
2515de6e07eSMauro Carvalho Chehab 	[3] = "FSB 3 Fatal Error",
2525de6e07eSMauro Carvalho Chehab 	[2] = "FSB 2 Fatal Error",
2535de6e07eSMauro Carvalho Chehab 	[1] = "FSB 1 Fatal Error",
2545de6e07eSMauro Carvalho Chehab 	[0] = "FSB 0 Fatal Error",
2555de6e07eSMauro Carvalho Chehab };
2565de6e07eSMauro Carvalho Chehab #define ferr_global_hi_is_fatal(errno)	1
2575de6e07eSMauro Carvalho Chehab 
258c3af2eafSMauro Carvalho Chehab #define FERR_GLOBAL_LO	0x40
2595de6e07eSMauro Carvalho Chehab static const char *ferr_global_lo_name[] = {
260c3af2eafSMauro Carvalho Chehab 	[31] = "Internal MCH Fatal Error",
261c3af2eafSMauro Carvalho Chehab 	[30] = "Intel QuickData Technology Device Fatal Error",
262c3af2eafSMauro Carvalho Chehab 	[29] = "FSB1 Fatal Error",
263c3af2eafSMauro Carvalho Chehab 	[28] = "FSB0 Fatal Error",
264c3af2eafSMauro Carvalho Chehab 	[27] = "FBD Channel 3 Fatal Error",
265c3af2eafSMauro Carvalho Chehab 	[26] = "FBD Channel 2 Fatal Error",
266c3af2eafSMauro Carvalho Chehab 	[25] = "FBD Channel 1 Fatal Error",
267c3af2eafSMauro Carvalho Chehab 	[24] = "FBD Channel 0 Fatal Error",
268c3af2eafSMauro Carvalho Chehab 	[23] = "PCI Express Device 7Fatal Error",
269c3af2eafSMauro Carvalho Chehab 	[22] = "PCI Express Device 6 Fatal Error",
270c3af2eafSMauro Carvalho Chehab 	[21] = "PCI Express Device 5 Fatal Error",
271c3af2eafSMauro Carvalho Chehab 	[20] = "PCI Express Device 4 Fatal Error",
272c3af2eafSMauro Carvalho Chehab 	[19] = "PCI Express Device 3 Fatal Error",
273c3af2eafSMauro Carvalho Chehab 	[18] = "PCI Express Device 2 Fatal Error",
274c3af2eafSMauro Carvalho Chehab 	[17] = "PCI Express Device 1 Fatal Error",
275c3af2eafSMauro Carvalho Chehab 	[16] = "ESI Fatal Error",
276c3af2eafSMauro Carvalho Chehab 	[15] = "Internal MCH Non-Fatal Error",
277c3af2eafSMauro Carvalho Chehab 	[14] = "Intel QuickData Technology Device Non Fatal Error",
278c3af2eafSMauro Carvalho Chehab 	[13] = "FSB1 Non-Fatal Error",
279c3af2eafSMauro Carvalho Chehab 	[12] = "FSB 0 Non-Fatal Error",
280c3af2eafSMauro Carvalho Chehab 	[11] = "FBD Channel 3 Non-Fatal Error",
281c3af2eafSMauro Carvalho Chehab 	[10] = "FBD Channel 2 Non-Fatal Error",
282c3af2eafSMauro Carvalho Chehab 	[9]  = "FBD Channel 1 Non-Fatal Error",
283c3af2eafSMauro Carvalho Chehab 	[8]  = "FBD Channel 0 Non-Fatal Error",
284c3af2eafSMauro Carvalho Chehab 	[7]  = "PCI Express Device 7 Non-Fatal Error",
285c3af2eafSMauro Carvalho Chehab 	[6]  = "PCI Express Device 6 Non-Fatal Error",
286c3af2eafSMauro Carvalho Chehab 	[5]  = "PCI Express Device 5 Non-Fatal Error",
287c3af2eafSMauro Carvalho Chehab 	[4]  = "PCI Express Device 4 Non-Fatal Error",
288c3af2eafSMauro Carvalho Chehab 	[3]  = "PCI Express Device 3 Non-Fatal Error",
289c3af2eafSMauro Carvalho Chehab 	[2]  = "PCI Express Device 2 Non-Fatal Error",
290c3af2eafSMauro Carvalho Chehab 	[1]  = "PCI Express Device 1 Non-Fatal Error",
291c3af2eafSMauro Carvalho Chehab 	[0]  = "ESI Non-Fatal Error",
292c3af2eafSMauro Carvalho Chehab };
2935de6e07eSMauro Carvalho Chehab #define ferr_global_lo_is_fatal(errno)	((errno < 16) ? 0 : 1)
294fcaf780bSMauro Carvalho Chehab 
2958199d8ccSMauro Carvalho Chehab #define NRECMEMA	0xbe
2968199d8ccSMauro Carvalho Chehab   #define NRECMEMA_BANK(v)	(((v) >> 12) & 7)
2978199d8ccSMauro Carvalho Chehab   #define NRECMEMA_RANK(v)	(((v) >> 8) & 15)
2988199d8ccSMauro Carvalho Chehab 
2998199d8ccSMauro Carvalho Chehab #define NRECMEMB	0xc0
3008199d8ccSMauro Carvalho Chehab   #define NRECMEMB_IS_WR(v)	((v) & (1 << 31))
3018199d8ccSMauro Carvalho Chehab   #define NRECMEMB_CAS(v)	(((v) >> 16) & 0x1fff)
3028199d8ccSMauro Carvalho Chehab   #define NRECMEMB_RAS(v)	((v) & 0xffff)
3038199d8ccSMauro Carvalho Chehab 
30432f94726SMauro Carvalho Chehab #define REDMEMA		0xdc
30532f94726SMauro Carvalho Chehab 
30637b69cf9SMauro Carvalho Chehab #define REDMEMB		0x7c
30737b69cf9SMauro Carvalho Chehab   #define IS_SECOND_CH(v)	((v) * (1 << 17))
30837b69cf9SMauro Carvalho Chehab 
30932f94726SMauro Carvalho Chehab #define RECMEMA		0xe0
31032f94726SMauro Carvalho Chehab   #define RECMEMA_BANK(v)	(((v) >> 12) & 7)
31132f94726SMauro Carvalho Chehab   #define RECMEMA_RANK(v)	(((v) >> 8) & 15)
31232f94726SMauro Carvalho Chehab 
31332f94726SMauro Carvalho Chehab #define RECMEMB		0xe4
31432f94726SMauro Carvalho Chehab   #define RECMEMB_IS_WR(v)	((v) & (1 << 31))
31532f94726SMauro Carvalho Chehab   #define RECMEMB_CAS(v)	(((v) >> 16) & 0x1fff)
31632f94726SMauro Carvalho Chehab   #define RECMEMB_RAS(v)	((v) & 0xffff)
31732f94726SMauro Carvalho Chehab 
3185de6e07eSMauro Carvalho Chehab /********************************************
3195de6e07eSMauro Carvalho Chehab  * i7300 Functions related to error detection
3205de6e07eSMauro Carvalho Chehab  ********************************************/
321fcaf780bSMauro Carvalho Chehab 
322d091a6ebSMauro Carvalho Chehab /**
323d091a6ebSMauro Carvalho Chehab  * get_err_from_table() - Gets the error message from a table
324d091a6ebSMauro Carvalho Chehab  * @table:	table name (array of char *)
325d091a6ebSMauro Carvalho Chehab  * @size:	number of elements at the table
326d091a6ebSMauro Carvalho Chehab  * @pos:	position of the element to be returned
327d091a6ebSMauro Carvalho Chehab  *
328d091a6ebSMauro Carvalho Chehab  * This is a small routine that gets the pos-th element of a table. If the
329d091a6ebSMauro Carvalho Chehab  * element doesn't exist (or it is empty), it returns "reserved".
330d091a6ebSMauro Carvalho Chehab  * Instead of calling it directly, the better is to call via the macro
331d091a6ebSMauro Carvalho Chehab  * GET_ERR_FROM_TABLE(), that automatically checks the table size via
332d091a6ebSMauro Carvalho Chehab  * ARRAY_SIZE() macro
333d091a6ebSMauro Carvalho Chehab  */
334d091a6ebSMauro Carvalho Chehab static const char *get_err_from_table(const char *table[], int size, int pos)
335fcaf780bSMauro Carvalho Chehab {
336d091a6ebSMauro Carvalho Chehab 	if (unlikely(pos >= size))
337d091a6ebSMauro Carvalho Chehab 		return "Reserved";
338d091a6ebSMauro Carvalho Chehab 
339d091a6ebSMauro Carvalho Chehab 	if (unlikely(!table[pos]))
3405de6e07eSMauro Carvalho Chehab 		return "Reserved";
3415de6e07eSMauro Carvalho Chehab 
3425de6e07eSMauro Carvalho Chehab 	return table[pos];
343fcaf780bSMauro Carvalho Chehab }
3445de6e07eSMauro Carvalho Chehab 
3455de6e07eSMauro Carvalho Chehab #define GET_ERR_FROM_TABLE(table, pos)				\
3465de6e07eSMauro Carvalho Chehab 	get_err_from_table(table, ARRAY_SIZE(table), pos)
347fcaf780bSMauro Carvalho Chehab 
348d091a6ebSMauro Carvalho Chehab /**
349d091a6ebSMauro Carvalho Chehab  * i7300_process_error_global() - Retrieve the hardware error information from
350d091a6ebSMauro Carvalho Chehab  *				  the hardware global error registers and
351d091a6ebSMauro Carvalho Chehab  *				  sends it to dmesg
352d091a6ebSMauro Carvalho Chehab  * @mci: struct mem_ctl_info pointer
3535de6e07eSMauro Carvalho Chehab  */
354f4277422SMauro Carvalho Chehab static void i7300_process_error_global(struct mem_ctl_info *mci)
3555de6e07eSMauro Carvalho Chehab {
356fcaf780bSMauro Carvalho Chehab 	struct i7300_pvt *pvt;
3575f032119SMauro Carvalho Chehab 	u32 errnum, error_reg;
3585de6e07eSMauro Carvalho Chehab 	unsigned long errors;
3595de6e07eSMauro Carvalho Chehab 	const char *specific;
3605de6e07eSMauro Carvalho Chehab 	bool is_fatal;
361fcaf780bSMauro Carvalho Chehab 
362fcaf780bSMauro Carvalho Chehab 	pvt = mci->pvt_info;
363fcaf780bSMauro Carvalho Chehab 
364fcaf780bSMauro Carvalho Chehab 	/* read in the 1st FATAL error register */
3655de6e07eSMauro Carvalho Chehab 	pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
3665f032119SMauro Carvalho Chehab 			      FERR_GLOBAL_HI, &error_reg);
3675f032119SMauro Carvalho Chehab 	if (unlikely(error_reg)) {
3685f032119SMauro Carvalho Chehab 		errors = error_reg;
3695de6e07eSMauro Carvalho Chehab 		errnum = find_first_bit(&errors,
3705de6e07eSMauro Carvalho Chehab 					ARRAY_SIZE(ferr_global_hi_name));
3715de6e07eSMauro Carvalho Chehab 		specific = GET_ERR_FROM_TABLE(ferr_global_hi_name, errnum);
3725de6e07eSMauro Carvalho Chehab 		is_fatal = ferr_global_hi_is_fatal(errnum);
37386002324SMauro Carvalho Chehab 
37486002324SMauro Carvalho Chehab 		/* Clear the error bit */
37586002324SMauro Carvalho Chehab 		pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
3765f032119SMauro Carvalho Chehab 				       FERR_GLOBAL_HI, error_reg);
37786002324SMauro Carvalho Chehab 
3785de6e07eSMauro Carvalho Chehab 		goto error_global;
379fcaf780bSMauro Carvalho Chehab 	}
380fcaf780bSMauro Carvalho Chehab 
3815de6e07eSMauro Carvalho Chehab 	pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
3825f032119SMauro Carvalho Chehab 			      FERR_GLOBAL_LO, &error_reg);
3835f032119SMauro Carvalho Chehab 	if (unlikely(error_reg)) {
3845f032119SMauro Carvalho Chehab 		errors = error_reg;
3855de6e07eSMauro Carvalho Chehab 		errnum = find_first_bit(&errors,
3865de6e07eSMauro Carvalho Chehab 					ARRAY_SIZE(ferr_global_lo_name));
3875de6e07eSMauro Carvalho Chehab 		specific = GET_ERR_FROM_TABLE(ferr_global_lo_name, errnum);
3885de6e07eSMauro Carvalho Chehab 		is_fatal = ferr_global_lo_is_fatal(errnum);
38986002324SMauro Carvalho Chehab 
39086002324SMauro Carvalho Chehab 		/* Clear the error bit */
39186002324SMauro Carvalho Chehab 		pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
3925f032119SMauro Carvalho Chehab 				       FERR_GLOBAL_LO, error_reg);
39386002324SMauro Carvalho Chehab 
3945de6e07eSMauro Carvalho Chehab 		goto error_global;
395fcaf780bSMauro Carvalho Chehab 	}
396fcaf780bSMauro Carvalho Chehab 	return;
397fcaf780bSMauro Carvalho Chehab 
3985de6e07eSMauro Carvalho Chehab error_global:
3995de6e07eSMauro Carvalho Chehab 	i7300_mc_printk(mci, KERN_EMERG, "%s misc error: %s\n",
4005de6e07eSMauro Carvalho Chehab 			is_fatal ? "Fatal" : "NOT fatal", specific);
401fcaf780bSMauro Carvalho Chehab }
402fcaf780bSMauro Carvalho Chehab 
403d091a6ebSMauro Carvalho Chehab /**
404d091a6ebSMauro Carvalho Chehab  * i7300_process_fbd_error() - Retrieve the hardware error information from
405d091a6ebSMauro Carvalho Chehab  *			       the FBD error registers and sends it via
406d091a6ebSMauro Carvalho Chehab  *			       EDAC error API calls
407d091a6ebSMauro Carvalho Chehab  * @mci: struct mem_ctl_info pointer
40857021918SMauro Carvalho Chehab  */
409f4277422SMauro Carvalho Chehab static void i7300_process_fbd_error(struct mem_ctl_info *mci)
41057021918SMauro Carvalho Chehab {
41157021918SMauro Carvalho Chehab 	struct i7300_pvt *pvt;
4125f032119SMauro Carvalho Chehab 	u32 errnum, value, error_reg;
4138199d8ccSMauro Carvalho Chehab 	u16 val16;
41437b69cf9SMauro Carvalho Chehab 	unsigned branch, channel, bank, rank, cas, ras;
41532f94726SMauro Carvalho Chehab 	u32 syndrome;
41632f94726SMauro Carvalho Chehab 
41757021918SMauro Carvalho Chehab 	unsigned long errors;
41857021918SMauro Carvalho Chehab 	const char *specific;
41932f94726SMauro Carvalho Chehab 	bool is_wr;
42057021918SMauro Carvalho Chehab 
42157021918SMauro Carvalho Chehab 	pvt = mci->pvt_info;
42257021918SMauro Carvalho Chehab 
42357021918SMauro Carvalho Chehab 	/* read in the 1st FATAL error register */
42457021918SMauro Carvalho Chehab 	pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
4255f032119SMauro Carvalho Chehab 			      FERR_FAT_FBD, &error_reg);
4265f032119SMauro Carvalho Chehab 	if (unlikely(error_reg & FERR_FAT_FBD_ERR_MASK)) {
4275f032119SMauro Carvalho Chehab 		errors = error_reg & FERR_FAT_FBD_ERR_MASK ;
42857021918SMauro Carvalho Chehab 		errnum = find_first_bit(&errors,
42957021918SMauro Carvalho Chehab 					ARRAY_SIZE(ferr_fat_fbd_name));
43057021918SMauro Carvalho Chehab 		specific = GET_ERR_FROM_TABLE(ferr_fat_fbd_name, errnum);
4315f032119SMauro Carvalho Chehab 		branch = (GET_FBD_FAT_IDX(error_reg) == 2) ? 1 : 0;
43257021918SMauro Carvalho Chehab 
4338199d8ccSMauro Carvalho Chehab 		pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map,
4348199d8ccSMauro Carvalho Chehab 				     NRECMEMA, &val16);
4358199d8ccSMauro Carvalho Chehab 		bank = NRECMEMA_BANK(val16);
4368199d8ccSMauro Carvalho Chehab 		rank = NRECMEMA_RANK(val16);
43757021918SMauro Carvalho Chehab 
4388199d8ccSMauro Carvalho Chehab 		pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
4398199d8ccSMauro Carvalho Chehab 				NRECMEMB, &value);
4408199d8ccSMauro Carvalho Chehab 		is_wr = NRECMEMB_IS_WR(value);
4418199d8ccSMauro Carvalho Chehab 		cas = NRECMEMB_CAS(value);
4428199d8ccSMauro Carvalho Chehab 		ras = NRECMEMB_RAS(value);
4438199d8ccSMauro Carvalho Chehab 
4445f032119SMauro Carvalho Chehab 		/* Clean the error register */
4455f032119SMauro Carvalho Chehab 		pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
4465f032119SMauro Carvalho Chehab 				FERR_FAT_FBD, error_reg);
4475f032119SMauro Carvalho Chehab 
4488199d8ccSMauro Carvalho Chehab 		snprintf(pvt->tmp_prt_buffer, PAGE_SIZE,
44970e2a837SMauro Carvalho Chehab 			 "Bank=%d RAS=%d CAS=%d Err=0x%lx (%s))",
45070e2a837SMauro Carvalho Chehab 			 bank, ras, cas, errors, specific);
4518199d8ccSMauro Carvalho Chehab 
45270e2a837SMauro Carvalho Chehab 		edac_mc_handle_error(HW_EVENT_ERR_FATAL, mci, 0, 0, 0,
45370e2a837SMauro Carvalho Chehab 				     branch, -1, rank,
45470e2a837SMauro Carvalho Chehab 				     is_wr ? "Write error" : "Read error",
45570e2a837SMauro Carvalho Chehab 				     pvt->tmp_prt_buffer, NULL);
45670e2a837SMauro Carvalho Chehab 
45757021918SMauro Carvalho Chehab 	}
45857021918SMauro Carvalho Chehab 
45957021918SMauro Carvalho Chehab 	/* read in the 1st NON-FATAL error register */
46057021918SMauro Carvalho Chehab 	pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
4615f032119SMauro Carvalho Chehab 			      FERR_NF_FBD, &error_reg);
4625f032119SMauro Carvalho Chehab 	if (unlikely(error_reg & FERR_NF_FBD_ERR_MASK)) {
4635f032119SMauro Carvalho Chehab 		errors = error_reg & FERR_NF_FBD_ERR_MASK;
46457021918SMauro Carvalho Chehab 		errnum = find_first_bit(&errors,
46557021918SMauro Carvalho Chehab 					ARRAY_SIZE(ferr_nf_fbd_name));
46657021918SMauro Carvalho Chehab 		specific = GET_ERR_FROM_TABLE(ferr_nf_fbd_name, errnum);
4675f032119SMauro Carvalho Chehab 		branch = (GET_FBD_FAT_IDX(error_reg) == 2) ? 1 : 0;
46857021918SMauro Carvalho Chehab 
46932f94726SMauro Carvalho Chehab 		pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
47032f94726SMauro Carvalho Chehab 			REDMEMA, &syndrome);
47132f94726SMauro Carvalho Chehab 
47232f94726SMauro Carvalho Chehab 		pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map,
47332f94726SMauro Carvalho Chehab 				     RECMEMA, &val16);
47432f94726SMauro Carvalho Chehab 		bank = RECMEMA_BANK(val16);
47532f94726SMauro Carvalho Chehab 		rank = RECMEMA_RANK(val16);
47632f94726SMauro Carvalho Chehab 
47732f94726SMauro Carvalho Chehab 		pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
47832f94726SMauro Carvalho Chehab 				RECMEMB, &value);
47932f94726SMauro Carvalho Chehab 		is_wr = RECMEMB_IS_WR(value);
48032f94726SMauro Carvalho Chehab 		cas = RECMEMB_CAS(value);
48132f94726SMauro Carvalho Chehab 		ras = RECMEMB_RAS(value);
48232f94726SMauro Carvalho Chehab 
48337b69cf9SMauro Carvalho Chehab 		pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
48437b69cf9SMauro Carvalho Chehab 				     REDMEMB, &value);
48537b69cf9SMauro Carvalho Chehab 		channel = (branch << 1);
48637b69cf9SMauro Carvalho Chehab 		if (IS_SECOND_CH(value))
48737b69cf9SMauro Carvalho Chehab 			channel++;
48837b69cf9SMauro Carvalho Chehab 
4895f032119SMauro Carvalho Chehab 		/* Clear the error bit */
4905f032119SMauro Carvalho Chehab 		pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
4915f032119SMauro Carvalho Chehab 				FERR_NF_FBD, error_reg);
4925f032119SMauro Carvalho Chehab 
49332f94726SMauro Carvalho Chehab 		/* Form out message */
49432f94726SMauro Carvalho Chehab 		snprintf(pvt->tmp_prt_buffer, PAGE_SIZE,
49570e2a837SMauro Carvalho Chehab 			 "DRAM-Bank=%d RAS=%d CAS=%d, Err=0x%lx (%s))",
49670e2a837SMauro Carvalho Chehab 			 bank, ras, cas, errors, specific);
49732f94726SMauro Carvalho Chehab 
49870e2a837SMauro Carvalho Chehab 		edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 0, 0,
49970e2a837SMauro Carvalho Chehab 				     syndrome,
50070e2a837SMauro Carvalho Chehab 				     branch >> 1, channel % 2, rank,
50170e2a837SMauro Carvalho Chehab 				     is_wr ? "Write error" : "Read error",
50270e2a837SMauro Carvalho Chehab 				     pvt->tmp_prt_buffer, NULL);
50357021918SMauro Carvalho Chehab 	}
50457021918SMauro Carvalho Chehab 	return;
50557021918SMauro Carvalho Chehab }
50657021918SMauro Carvalho Chehab 
507d091a6ebSMauro Carvalho Chehab /**
508d091a6ebSMauro Carvalho Chehab  * i7300_check_error() - Calls the error checking subroutines
509d091a6ebSMauro Carvalho Chehab  * @mci: struct mem_ctl_info pointer
510fcaf780bSMauro Carvalho Chehab  */
511f4277422SMauro Carvalho Chehab static void i7300_check_error(struct mem_ctl_info *mci)
5125de6e07eSMauro Carvalho Chehab {
513f4277422SMauro Carvalho Chehab 	i7300_process_error_global(mci);
514f4277422SMauro Carvalho Chehab 	i7300_process_fbd_error(mci);
5155de6e07eSMauro Carvalho Chehab };
516fcaf780bSMauro Carvalho Chehab 
517d091a6ebSMauro Carvalho Chehab /**
518d091a6ebSMauro Carvalho Chehab  * i7300_clear_error() - Clears the error registers
519d091a6ebSMauro Carvalho Chehab  * @mci: struct mem_ctl_info pointer
520fcaf780bSMauro Carvalho Chehab  */
521fcaf780bSMauro Carvalho Chehab static void i7300_clear_error(struct mem_ctl_info *mci)
522fcaf780bSMauro Carvalho Chehab {
523e4327605SMauro Carvalho Chehab 	struct i7300_pvt *pvt = mci->pvt_info;
524e4327605SMauro Carvalho Chehab 	u32 value;
525e4327605SMauro Carvalho Chehab 	/*
526e4327605SMauro Carvalho Chehab 	 * All error values are RWC - we need to read and write 1 to the
527e4327605SMauro Carvalho Chehab 	 * bit that we want to cleanup
528e4327605SMauro Carvalho Chehab 	 */
529fcaf780bSMauro Carvalho Chehab 
530e4327605SMauro Carvalho Chehab 	/* Clear global error registers */
531e4327605SMauro Carvalho Chehab 	pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
532e4327605SMauro Carvalho Chehab 			      FERR_GLOBAL_HI, &value);
533e4327605SMauro Carvalho Chehab 	pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
534e4327605SMauro Carvalho Chehab 			      FERR_GLOBAL_HI, value);
535e4327605SMauro Carvalho Chehab 
536e4327605SMauro Carvalho Chehab 	pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
537e4327605SMauro Carvalho Chehab 			      FERR_GLOBAL_LO, &value);
538e4327605SMauro Carvalho Chehab 	pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
539e4327605SMauro Carvalho Chehab 			      FERR_GLOBAL_LO, value);
540e4327605SMauro Carvalho Chehab 
541e4327605SMauro Carvalho Chehab 	/* Clear FBD error registers */
542e4327605SMauro Carvalho Chehab 	pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
543e4327605SMauro Carvalho Chehab 			      FERR_FAT_FBD, &value);
544e4327605SMauro Carvalho Chehab 	pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
545e4327605SMauro Carvalho Chehab 			      FERR_FAT_FBD, value);
546e4327605SMauro Carvalho Chehab 
547e4327605SMauro Carvalho Chehab 	pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
548e4327605SMauro Carvalho Chehab 			      FERR_NF_FBD, &value);
549e4327605SMauro Carvalho Chehab 	pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
550e4327605SMauro Carvalho Chehab 			      FERR_NF_FBD, value);
551fcaf780bSMauro Carvalho Chehab }
552fcaf780bSMauro Carvalho Chehab 
553d091a6ebSMauro Carvalho Chehab /**
554d091a6ebSMauro Carvalho Chehab  * i7300_enable_error_reporting() - Enable the memory reporting logic at the
555d091a6ebSMauro Carvalho Chehab  *				    hardware
556d091a6ebSMauro Carvalho Chehab  * @mci: struct mem_ctl_info pointer
557fcaf780bSMauro Carvalho Chehab  */
558fcaf780bSMauro Carvalho Chehab static void i7300_enable_error_reporting(struct mem_ctl_info *mci)
559fcaf780bSMauro Carvalho Chehab {
56057021918SMauro Carvalho Chehab 	struct i7300_pvt *pvt = mci->pvt_info;
56157021918SMauro Carvalho Chehab 	u32 fbd_error_mask;
56257021918SMauro Carvalho Chehab 
56357021918SMauro Carvalho Chehab 	/* Read the FBD Error Mask Register */
56457021918SMauro Carvalho Chehab 	pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
56557021918SMauro Carvalho Chehab 			      EMASK_FBD, &fbd_error_mask);
56657021918SMauro Carvalho Chehab 
56757021918SMauro Carvalho Chehab 	/* Enable with a '0' */
56857021918SMauro Carvalho Chehab 	fbd_error_mask &= ~(EMASK_FBD_ERR_MASK);
56957021918SMauro Carvalho Chehab 
57057021918SMauro Carvalho Chehab 	pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
57157021918SMauro Carvalho Chehab 			       EMASK_FBD, fbd_error_mask);
572fcaf780bSMauro Carvalho Chehab }
5735de6e07eSMauro Carvalho Chehab 
5745de6e07eSMauro Carvalho Chehab /************************************************
5755de6e07eSMauro Carvalho Chehab  * i7300 Functions related to memory enumberation
5765de6e07eSMauro Carvalho Chehab  ************************************************/
577fcaf780bSMauro Carvalho Chehab 
578d091a6ebSMauro Carvalho Chehab /**
579d091a6ebSMauro Carvalho Chehab  * decode_mtr() - Decodes the MTR descriptor, filling the edac structs
580d091a6ebSMauro Carvalho Chehab  * @pvt: pointer to the private data struct used by i7300 driver
581d091a6ebSMauro Carvalho Chehab  * @slot: DIMM slot (0 to 7)
582d091a6ebSMauro Carvalho Chehab  * @ch: Channel number within the branch (0 or 1)
583d091a6ebSMauro Carvalho Chehab  * @branch: Branch number (0 or 1)
584d091a6ebSMauro Carvalho Chehab  * @dinfo: Pointer to DIMM info where dimm size is stored
585d091a6ebSMauro Carvalho Chehab  * @p_csrow: Pointer to the struct csrow_info that corresponds to that element
586fcaf780bSMauro Carvalho Chehab  */
587fcaf780bSMauro Carvalho Chehab static int decode_mtr(struct i7300_pvt *pvt,
588fcaf780bSMauro Carvalho Chehab 		      int slot, int ch, int branch,
589fcaf780bSMauro Carvalho Chehab 		      struct i7300_dimm_info *dinfo,
590a895bf8bSMauro Carvalho Chehab 		      struct dimm_info *dimm)
591fcaf780bSMauro Carvalho Chehab {
592fcaf780bSMauro Carvalho Chehab 	int mtr, ans, addrBits, channel;
593fcaf780bSMauro Carvalho Chehab 
594fcaf780bSMauro Carvalho Chehab 	channel = to_channel(ch, branch);
595fcaf780bSMauro Carvalho Chehab 
596fcaf780bSMauro Carvalho Chehab 	mtr = pvt->mtr[slot][branch];
597fcaf780bSMauro Carvalho Chehab 	ans = MTR_DIMMS_PRESENT(mtr) ? 1 : 0;
598fcaf780bSMauro Carvalho Chehab 
599fcaf780bSMauro Carvalho Chehab 	debugf2("\tMTR%d CH%d: DIMMs are %s (mtr)\n",
600fcaf780bSMauro Carvalho Chehab 		slot, channel,
601fcaf780bSMauro Carvalho Chehab 		ans ? "Present" : "NOT Present");
602fcaf780bSMauro Carvalho Chehab 
603fcaf780bSMauro Carvalho Chehab 	/* Determine if there is a DIMM present in this DIMM slot */
604fcaf780bSMauro Carvalho Chehab 	if (!ans)
605fcaf780bSMauro Carvalho Chehab 		return 0;
606fcaf780bSMauro Carvalho Chehab 
607fcaf780bSMauro Carvalho Chehab 	/* Start with the number of bits for a Bank
608fcaf780bSMauro Carvalho Chehab 	* on the DRAM */
609fcaf780bSMauro Carvalho Chehab 	addrBits = MTR_DRAM_BANKS_ADDR_BITS;
610fcaf780bSMauro Carvalho Chehab 	/* Add thenumber of ROW bits */
611fcaf780bSMauro Carvalho Chehab 	addrBits += MTR_DIMM_ROWS_ADDR_BITS(mtr);
612fcaf780bSMauro Carvalho Chehab 	/* add the number of COLUMN bits */
613fcaf780bSMauro Carvalho Chehab 	addrBits += MTR_DIMM_COLS_ADDR_BITS(mtr);
614fcaf780bSMauro Carvalho Chehab 	/* add the number of RANK bits */
615fcaf780bSMauro Carvalho Chehab 	addrBits += MTR_DIMM_RANKS(mtr);
616fcaf780bSMauro Carvalho Chehab 
617fcaf780bSMauro Carvalho Chehab 	addrBits += 6;	/* add 64 bits per DIMM */
618fcaf780bSMauro Carvalho Chehab 	addrBits -= 20;	/* divide by 2^^20 */
619fcaf780bSMauro Carvalho Chehab 	addrBits -= 3;	/* 8 bits per bytes */
620fcaf780bSMauro Carvalho Chehab 
621fcaf780bSMauro Carvalho Chehab 	dinfo->megabytes = 1 << addrBits;
622fcaf780bSMauro Carvalho Chehab 
623fcaf780bSMauro Carvalho Chehab 	debugf2("\t\tWIDTH: x%d\n", MTR_DRAM_WIDTH(mtr));
624fcaf780bSMauro Carvalho Chehab 
625fcaf780bSMauro Carvalho Chehab 	debugf2("\t\tELECTRICAL THROTTLING is %s\n",
626fcaf780bSMauro Carvalho Chehab 		MTR_DIMMS_ETHROTTLE(mtr) ? "enabled" : "disabled");
627fcaf780bSMauro Carvalho Chehab 
628fcaf780bSMauro Carvalho Chehab 	debugf2("\t\tNUMBANK: %d bank(s)\n", MTR_DRAM_BANKS(mtr));
629fcaf780bSMauro Carvalho Chehab 	debugf2("\t\tNUMRANK: %s\n", MTR_DIMM_RANKS(mtr) ? "double" : "single");
630*7e881856SJoe Perches 	debugf2("\t\tNUMROW: %s\n",
631*7e881856SJoe Perches 		MTR_DIMM_ROWS(mtr) == 0 ? "8,192 - 13 rows" :
632*7e881856SJoe Perches 		MTR_DIMM_ROWS(mtr) == 1 ? "16,384 - 14 rows" :
633*7e881856SJoe Perches 		MTR_DIMM_ROWS(mtr) == 2 ? "32,768 - 15 rows" :
634*7e881856SJoe Perches 		"65,536 - 16 rows");
635*7e881856SJoe Perches 	debugf2("\t\tNUMCOL: %s\n",
636*7e881856SJoe Perches 		MTR_DIMM_COLS(mtr) == 0 ? "1,024 - 10 columns" :
637*7e881856SJoe Perches 		MTR_DIMM_COLS(mtr) == 1 ? "2,048 - 11 columns" :
638*7e881856SJoe Perches 		MTR_DIMM_COLS(mtr) == 2 ? "4,096 - 12 columns" :
639*7e881856SJoe Perches 		"reserved");
640fcaf780bSMauro Carvalho Chehab 	debugf2("\t\tSIZE: %d MB\n", dinfo->megabytes);
641fcaf780bSMauro Carvalho Chehab 
642116389edSMauro Carvalho Chehab 	/*
64315154c57SMauro Carvalho Chehab 	 * The type of error detection actually depends of the
644116389edSMauro Carvalho Chehab 	 * mode of operation. When it is just one single memory chip, at
645116389edSMauro Carvalho Chehab 	 * socket 0, channel 0, it uses 8-byte-over-32-byte SECDED+ code.
64615154c57SMauro Carvalho Chehab 	 * In normal or mirrored mode, it uses Lockstep mode,
647116389edSMauro Carvalho Chehab 	 * with the possibility of using an extended algorithm for x8 memories
648116389edSMauro Carvalho Chehab 	 * See datasheet Sections 7.3.6 to 7.3.8
649116389edSMauro Carvalho Chehab 	 */
65015154c57SMauro Carvalho Chehab 
651a895bf8bSMauro Carvalho Chehab 	dimm->nr_pages = MiB_TO_PAGES(dinfo->megabytes);
652084a4fccSMauro Carvalho Chehab 	dimm->grain = 8;
653084a4fccSMauro Carvalho Chehab 	dimm->mtype = MEM_FB_DDR2;
65415154c57SMauro Carvalho Chehab 	if (IS_SINGLE_MODE(pvt->mc_settings_a)) {
655084a4fccSMauro Carvalho Chehab 		dimm->edac_mode = EDAC_SECDED;
6563b330f67SMauro Carvalho Chehab 		debugf2("\t\tECC code is 8-byte-over-32-byte SECDED+ code\n");
65715154c57SMauro Carvalho Chehab 	} else {
6583b330f67SMauro Carvalho Chehab 		debugf2("\t\tECC code is on Lockstep mode\n");
65928c2ce7cSMauro Carvalho Chehab 		if (MTR_DRAM_WIDTH(mtr) == 8)
660084a4fccSMauro Carvalho Chehab 			dimm->edac_mode = EDAC_S8ECD8ED;
66115154c57SMauro Carvalho Chehab 		else
662084a4fccSMauro Carvalho Chehab 			dimm->edac_mode = EDAC_S4ECD4ED;
66315154c57SMauro Carvalho Chehab 	}
664fcaf780bSMauro Carvalho Chehab 
665fcaf780bSMauro Carvalho Chehab 	/* ask what device type on this row */
66628c2ce7cSMauro Carvalho Chehab 	if (MTR_DRAM_WIDTH(mtr) == 8) {
6673b330f67SMauro Carvalho Chehab 		debugf2("\t\tScrub algorithm for x8 is on %s mode\n",
668d7de2bdbSMauro Carvalho Chehab 			IS_SCRBALGO_ENHANCED(pvt->mc_settings) ?
669d7de2bdbSMauro Carvalho Chehab 					    "enhanced" : "normal");
670d7de2bdbSMauro Carvalho Chehab 
671084a4fccSMauro Carvalho Chehab 		dimm->dtype = DEV_X8;
672d7de2bdbSMauro Carvalho Chehab 	} else
673084a4fccSMauro Carvalho Chehab 		dimm->dtype = DEV_X4;
674fcaf780bSMauro Carvalho Chehab 
675fcaf780bSMauro Carvalho Chehab 	return mtr;
676fcaf780bSMauro Carvalho Chehab }
677fcaf780bSMauro Carvalho Chehab 
678d091a6ebSMauro Carvalho Chehab /**
679d091a6ebSMauro Carvalho Chehab  * print_dimm_size() - Prints dump of the memory organization
680d091a6ebSMauro Carvalho Chehab  * @pvt: pointer to the private data struct used by i7300 driver
681fcaf780bSMauro Carvalho Chehab  *
682d091a6ebSMauro Carvalho Chehab  * Useful for debug. If debug is disabled, this routine do nothing
683fcaf780bSMauro Carvalho Chehab  */
684fcaf780bSMauro Carvalho Chehab static void print_dimm_size(struct i7300_pvt *pvt)
685fcaf780bSMauro Carvalho Chehab {
686d091a6ebSMauro Carvalho Chehab #ifdef CONFIG_EDAC_DEBUG
687fcaf780bSMauro Carvalho Chehab 	struct i7300_dimm_info *dinfo;
68885580ea4SMauro Carvalho Chehab 	char *p;
689fcaf780bSMauro Carvalho Chehab 	int space, n;
690fcaf780bSMauro Carvalho Chehab 	int channel, slot;
691fcaf780bSMauro Carvalho Chehab 
692fcaf780bSMauro Carvalho Chehab 	space = PAGE_SIZE;
69385580ea4SMauro Carvalho Chehab 	p = pvt->tmp_prt_buffer;
694fcaf780bSMauro Carvalho Chehab 
695fcaf780bSMauro Carvalho Chehab 	n = snprintf(p, space, "              ");
696fcaf780bSMauro Carvalho Chehab 	p += n;
697fcaf780bSMauro Carvalho Chehab 	space -= n;
698fcaf780bSMauro Carvalho Chehab 	for (channel = 0; channel < MAX_CHANNELS; channel++) {
699fcaf780bSMauro Carvalho Chehab 		n = snprintf(p, space, "channel %d | ", channel);
700fcaf780bSMauro Carvalho Chehab 		p += n;
701fcaf780bSMauro Carvalho Chehab 		space -= n;
702fcaf780bSMauro Carvalho Chehab 	}
70385580ea4SMauro Carvalho Chehab 	debugf2("%s\n", pvt->tmp_prt_buffer);
70485580ea4SMauro Carvalho Chehab 	p = pvt->tmp_prt_buffer;
705fcaf780bSMauro Carvalho Chehab 	space = PAGE_SIZE;
706fcaf780bSMauro Carvalho Chehab 	n = snprintf(p, space, "-------------------------------"
707fcaf780bSMauro Carvalho Chehab 			       "------------------------------");
708fcaf780bSMauro Carvalho Chehab 	p += n;
709fcaf780bSMauro Carvalho Chehab 	space -= n;
71085580ea4SMauro Carvalho Chehab 	debugf2("%s\n", pvt->tmp_prt_buffer);
71185580ea4SMauro Carvalho Chehab 	p = pvt->tmp_prt_buffer;
712fcaf780bSMauro Carvalho Chehab 	space = PAGE_SIZE;
713fcaf780bSMauro Carvalho Chehab 
714fcaf780bSMauro Carvalho Chehab 	for (slot = 0; slot < MAX_SLOTS; slot++) {
715fcaf780bSMauro Carvalho Chehab 		n = snprintf(p, space, "csrow/SLOT %d  ", slot);
716fcaf780bSMauro Carvalho Chehab 		p += n;
717fcaf780bSMauro Carvalho Chehab 		space -= n;
718fcaf780bSMauro Carvalho Chehab 
719fcaf780bSMauro Carvalho Chehab 		for (channel = 0; channel < MAX_CHANNELS; channel++) {
720fcaf780bSMauro Carvalho Chehab 			dinfo = &pvt->dimm_info[slot][channel];
721fcaf780bSMauro Carvalho Chehab 			n = snprintf(p, space, "%4d MB   | ", dinfo->megabytes);
722fcaf780bSMauro Carvalho Chehab 			p += n;
723fcaf780bSMauro Carvalho Chehab 			space -= n;
724fcaf780bSMauro Carvalho Chehab 		}
725fcaf780bSMauro Carvalho Chehab 
72685580ea4SMauro Carvalho Chehab 		debugf2("%s\n", pvt->tmp_prt_buffer);
72785580ea4SMauro Carvalho Chehab 		p = pvt->tmp_prt_buffer;
728fcaf780bSMauro Carvalho Chehab 		space = PAGE_SIZE;
729fcaf780bSMauro Carvalho Chehab 	}
730fcaf780bSMauro Carvalho Chehab 
731fcaf780bSMauro Carvalho Chehab 	n = snprintf(p, space, "-------------------------------"
732fcaf780bSMauro Carvalho Chehab 			       "------------------------------");
733fcaf780bSMauro Carvalho Chehab 	p += n;
734fcaf780bSMauro Carvalho Chehab 	space -= n;
73585580ea4SMauro Carvalho Chehab 	debugf2("%s\n", pvt->tmp_prt_buffer);
73685580ea4SMauro Carvalho Chehab 	p = pvt->tmp_prt_buffer;
737fcaf780bSMauro Carvalho Chehab 	space = PAGE_SIZE;
738d091a6ebSMauro Carvalho Chehab #endif
739fcaf780bSMauro Carvalho Chehab }
740fcaf780bSMauro Carvalho Chehab 
741d091a6ebSMauro Carvalho Chehab /**
742d091a6ebSMauro Carvalho Chehab  * i7300_init_csrows() - Initialize the 'csrows' table within
743fcaf780bSMauro Carvalho Chehab  *			 the mci control structure with the
744fcaf780bSMauro Carvalho Chehab  *			 addressing of memory.
745d091a6ebSMauro Carvalho Chehab  * @mci: struct mem_ctl_info pointer
746fcaf780bSMauro Carvalho Chehab  */
747fcaf780bSMauro Carvalho Chehab static int i7300_init_csrows(struct mem_ctl_info *mci)
748fcaf780bSMauro Carvalho Chehab {
749fcaf780bSMauro Carvalho Chehab 	struct i7300_pvt *pvt;
750fcaf780bSMauro Carvalho Chehab 	struct i7300_dimm_info *dinfo;
751d091a6ebSMauro Carvalho Chehab 	int rc = -ENODEV;
752fcaf780bSMauro Carvalho Chehab 	int mtr;
753fcaf780bSMauro Carvalho Chehab 	int ch, branch, slot, channel;
754084a4fccSMauro Carvalho Chehab 	struct dimm_info *dimm;
755fcaf780bSMauro Carvalho Chehab 
756fcaf780bSMauro Carvalho Chehab 	pvt = mci->pvt_info;
757fcaf780bSMauro Carvalho Chehab 
758fcaf780bSMauro Carvalho Chehab 	debugf2("Memory Technology Registers:\n");
759fcaf780bSMauro Carvalho Chehab 
760fcaf780bSMauro Carvalho Chehab 	/* Get the AMB present registers for the four channels */
761fcaf780bSMauro Carvalho Chehab 	for (branch = 0; branch < MAX_BRANCHES; branch++) {
762fcaf780bSMauro Carvalho Chehab 		/* Read and dump branch 0's MTRs */
763fcaf780bSMauro Carvalho Chehab 		channel = to_channel(0, branch);
7649c6f6b65SMauro Carvalho Chehab 		pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch],
7659c6f6b65SMauro Carvalho Chehab 				     AMBPRESENT_0,
766fcaf780bSMauro Carvalho Chehab 				&pvt->ambpresent[channel]);
767fcaf780bSMauro Carvalho Chehab 		debugf2("\t\tAMB-present CH%d = 0x%x:\n",
768fcaf780bSMauro Carvalho Chehab 			channel, pvt->ambpresent[channel]);
769fcaf780bSMauro Carvalho Chehab 
770fcaf780bSMauro Carvalho Chehab 		channel = to_channel(1, branch);
7719c6f6b65SMauro Carvalho Chehab 		pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch],
7729c6f6b65SMauro Carvalho Chehab 				     AMBPRESENT_1,
773fcaf780bSMauro Carvalho Chehab 				&pvt->ambpresent[channel]);
774fcaf780bSMauro Carvalho Chehab 		debugf2("\t\tAMB-present CH%d = 0x%x:\n",
775fcaf780bSMauro Carvalho Chehab 			channel, pvt->ambpresent[channel]);
776fcaf780bSMauro Carvalho Chehab 	}
777fcaf780bSMauro Carvalho Chehab 
778fcaf780bSMauro Carvalho Chehab 	/* Get the set of MTR[0-7] regs by each branch */
779fcaf780bSMauro Carvalho Chehab 	for (slot = 0; slot < MAX_SLOTS; slot++) {
780fcaf780bSMauro Carvalho Chehab 		int where = mtr_regs[slot];
781fcaf780bSMauro Carvalho Chehab 		for (branch = 0; branch < MAX_BRANCHES; branch++) {
7823e57eef6SMauro Carvalho Chehab 			pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch],
783fcaf780bSMauro Carvalho Chehab 					where,
784fcaf780bSMauro Carvalho Chehab 					&pvt->mtr[slot][branch]);
785084a4fccSMauro Carvalho Chehab 			for (ch = 0; ch < MAX_CH_PER_BRANCH; ch++) {
786fcaf780bSMauro Carvalho Chehab 				int channel = to_channel(ch, branch);
787fcaf780bSMauro Carvalho Chehab 
78870e2a837SMauro Carvalho Chehab 				dimm = EDAC_DIMM_PTR(mci->layers, mci->dimms,
78970e2a837SMauro Carvalho Chehab 					       mci->n_layers, branch, ch, slot);
790fcaf780bSMauro Carvalho Chehab 
79170e2a837SMauro Carvalho Chehab 				dinfo = &pvt->dimm_info[slot][channel];
792084a4fccSMauro Carvalho Chehab 
793fcaf780bSMauro Carvalho Chehab 				mtr = decode_mtr(pvt, slot, ch, branch,
794a895bf8bSMauro Carvalho Chehab 						 dinfo, dimm);
795a895bf8bSMauro Carvalho Chehab 
796fcaf780bSMauro Carvalho Chehab 				/* if no DIMMS on this row, continue */
797fcaf780bSMauro Carvalho Chehab 				if (!MTR_DIMMS_PRESENT(mtr))
798fcaf780bSMauro Carvalho Chehab 					continue;
799fcaf780bSMauro Carvalho Chehab 
800d091a6ebSMauro Carvalho Chehab 				rc = 0;
801a895bf8bSMauro Carvalho Chehab 
802fcaf780bSMauro Carvalho Chehab 			}
803fcaf780bSMauro Carvalho Chehab 		}
804fcaf780bSMauro Carvalho Chehab 	}
805fcaf780bSMauro Carvalho Chehab 
806d091a6ebSMauro Carvalho Chehab 	return rc;
807fcaf780bSMauro Carvalho Chehab }
808fcaf780bSMauro Carvalho Chehab 
809d091a6ebSMauro Carvalho Chehab /**
810d091a6ebSMauro Carvalho Chehab  * decode_mir() - Decodes Memory Interleave Register (MIR) info
811d091a6ebSMauro Carvalho Chehab  * @int mir_no: number of the MIR register to decode
812d091a6ebSMauro Carvalho Chehab  * @mir: array with the MIR data cached on the driver
813d091a6ebSMauro Carvalho Chehab  */
814fcaf780bSMauro Carvalho Chehab static void decode_mir(int mir_no, u16 mir[MAX_MIR])
815fcaf780bSMauro Carvalho Chehab {
816fcaf780bSMauro Carvalho Chehab 	if (mir[mir_no] & 3)
8179c6f6b65SMauro Carvalho Chehab 		debugf2("MIR%d: limit= 0x%x Branch(es) that participate:"
8189c6f6b65SMauro Carvalho Chehab 			" %s %s\n",
819fcaf780bSMauro Carvalho Chehab 			mir_no,
820fcaf780bSMauro Carvalho Chehab 			(mir[mir_no] >> 4) & 0xfff,
821fcaf780bSMauro Carvalho Chehab 			(mir[mir_no] & 1) ? "B0" : "",
822fcaf780bSMauro Carvalho Chehab 			(mir[mir_no] & 2) ? "B1" : "");
823fcaf780bSMauro Carvalho Chehab }
824fcaf780bSMauro Carvalho Chehab 
825d091a6ebSMauro Carvalho Chehab /**
826d091a6ebSMauro Carvalho Chehab  * i7300_get_mc_regs() - Get the contents of the MC enumeration registers
827d091a6ebSMauro Carvalho Chehab  * @mci: struct mem_ctl_info pointer
828fcaf780bSMauro Carvalho Chehab  *
829d091a6ebSMauro Carvalho Chehab  * Data read is cached internally for its usage when needed
830fcaf780bSMauro Carvalho Chehab  */
831fcaf780bSMauro Carvalho Chehab static int i7300_get_mc_regs(struct mem_ctl_info *mci)
832fcaf780bSMauro Carvalho Chehab {
833fcaf780bSMauro Carvalho Chehab 	struct i7300_pvt *pvt;
834fcaf780bSMauro Carvalho Chehab 	u32 actual_tolm;
835fcaf780bSMauro Carvalho Chehab 	int i, rc;
836fcaf780bSMauro Carvalho Chehab 
837fcaf780bSMauro Carvalho Chehab 	pvt = mci->pvt_info;
838fcaf780bSMauro Carvalho Chehab 
8393e57eef6SMauro Carvalho Chehab 	pci_read_config_dword(pvt->pci_dev_16_0_fsb_ctlr, AMBASE,
840fcaf780bSMauro Carvalho Chehab 			(u32 *) &pvt->ambase);
841fcaf780bSMauro Carvalho Chehab 
842fcaf780bSMauro Carvalho Chehab 	debugf2("AMBASE= 0x%lx\n", (long unsigned int)pvt->ambase);
843fcaf780bSMauro Carvalho Chehab 
844fcaf780bSMauro Carvalho Chehab 	/* Get the Branch Map regs */
8453e57eef6SMauro Carvalho Chehab 	pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, TOLM, &pvt->tolm);
846fcaf780bSMauro Carvalho Chehab 	pvt->tolm >>= 12;
847fcaf780bSMauro Carvalho Chehab 	debugf2("TOLM (number of 256M regions) =%u (0x%x)\n", pvt->tolm,
848fcaf780bSMauro Carvalho Chehab 		pvt->tolm);
849fcaf780bSMauro Carvalho Chehab 
850fcaf780bSMauro Carvalho Chehab 	actual_tolm = (u32) ((1000l * pvt->tolm) >> (30 - 28));
851fcaf780bSMauro Carvalho Chehab 	debugf2("Actual TOLM byte addr=%u.%03u GB (0x%x)\n",
852fcaf780bSMauro Carvalho Chehab 		actual_tolm/1000, actual_tolm % 1000, pvt->tolm << 28);
853fcaf780bSMauro Carvalho Chehab 
854af3d8831SMauro Carvalho Chehab 	/* Get memory controller settings */
8553e57eef6SMauro Carvalho Chehab 	pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, MC_SETTINGS,
856af3d8831SMauro Carvalho Chehab 			     &pvt->mc_settings);
857bb81a216SMauro Carvalho Chehab 	pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, MC_SETTINGS_A,
858bb81a216SMauro Carvalho Chehab 			     &pvt->mc_settings_a);
859d7de2bdbSMauro Carvalho Chehab 
860bb81a216SMauro Carvalho Chehab 	if (IS_SINGLE_MODE(pvt->mc_settings_a))
861bb81a216SMauro Carvalho Chehab 		debugf0("Memory controller operating on single mode\n");
862bb81a216SMauro Carvalho Chehab 	else
863af3d8831SMauro Carvalho Chehab 		debugf0("Memory controller operating on %s mode\n",
864d7de2bdbSMauro Carvalho Chehab 		IS_MIRRORED(pvt->mc_settings) ? "mirrored" : "non-mirrored");
865bb81a216SMauro Carvalho Chehab 
866af3d8831SMauro Carvalho Chehab 	debugf0("Error detection is %s\n",
867d7de2bdbSMauro Carvalho Chehab 		IS_ECC_ENABLED(pvt->mc_settings) ? "enabled" : "disabled");
868d7de2bdbSMauro Carvalho Chehab 	debugf0("Retry is %s\n",
869d7de2bdbSMauro Carvalho Chehab 		IS_RETRY_ENABLED(pvt->mc_settings) ? "enabled" : "disabled");
870af3d8831SMauro Carvalho Chehab 
871af3d8831SMauro Carvalho Chehab 	/* Get Memory Interleave Range registers */
8729c6f6b65SMauro Carvalho Chehab 	pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR0,
8739c6f6b65SMauro Carvalho Chehab 			     &pvt->mir[0]);
8749c6f6b65SMauro Carvalho Chehab 	pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR1,
8759c6f6b65SMauro Carvalho Chehab 			     &pvt->mir[1]);
8769c6f6b65SMauro Carvalho Chehab 	pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR2,
8779c6f6b65SMauro Carvalho Chehab 			     &pvt->mir[2]);
878fcaf780bSMauro Carvalho Chehab 
879fcaf780bSMauro Carvalho Chehab 	/* Decode the MIR regs */
880fcaf780bSMauro Carvalho Chehab 	for (i = 0; i < MAX_MIR; i++)
881fcaf780bSMauro Carvalho Chehab 		decode_mir(i, pvt->mir);
882fcaf780bSMauro Carvalho Chehab 
883fcaf780bSMauro Carvalho Chehab 	rc = i7300_init_csrows(mci);
884fcaf780bSMauro Carvalho Chehab 	if (rc < 0)
885fcaf780bSMauro Carvalho Chehab 		return rc;
886fcaf780bSMauro Carvalho Chehab 
887fcaf780bSMauro Carvalho Chehab 	/* Go and determine the size of each DIMM and place in an
888fcaf780bSMauro Carvalho Chehab 	 * orderly matrix */
889fcaf780bSMauro Carvalho Chehab 	print_dimm_size(pvt);
890fcaf780bSMauro Carvalho Chehab 
891fcaf780bSMauro Carvalho Chehab 	return 0;
892fcaf780bSMauro Carvalho Chehab }
893fcaf780bSMauro Carvalho Chehab 
8945de6e07eSMauro Carvalho Chehab /*************************************************
8955de6e07eSMauro Carvalho Chehab  * i7300 Functions related to device probe/release
8965de6e07eSMauro Carvalho Chehab  *************************************************/
8975de6e07eSMauro Carvalho Chehab 
898d091a6ebSMauro Carvalho Chehab /**
899d091a6ebSMauro Carvalho Chehab  * i7300_put_devices() - Release the PCI devices
900d091a6ebSMauro Carvalho Chehab  * @mci: struct mem_ctl_info pointer
901fcaf780bSMauro Carvalho Chehab  */
902fcaf780bSMauro Carvalho Chehab static void i7300_put_devices(struct mem_ctl_info *mci)
903fcaf780bSMauro Carvalho Chehab {
904fcaf780bSMauro Carvalho Chehab 	struct i7300_pvt *pvt;
905fcaf780bSMauro Carvalho Chehab 	int branch;
906fcaf780bSMauro Carvalho Chehab 
907fcaf780bSMauro Carvalho Chehab 	pvt = mci->pvt_info;
908fcaf780bSMauro Carvalho Chehab 
909fcaf780bSMauro Carvalho Chehab 	/* Decrement usage count for devices */
910fcaf780bSMauro Carvalho Chehab 	for (branch = 0; branch < MAX_CH_PER_BRANCH; branch++)
9113e57eef6SMauro Carvalho Chehab 		pci_dev_put(pvt->pci_dev_2x_0_fbd_branch[branch]);
9123e57eef6SMauro Carvalho Chehab 	pci_dev_put(pvt->pci_dev_16_2_fsb_err_regs);
9133e57eef6SMauro Carvalho Chehab 	pci_dev_put(pvt->pci_dev_16_1_fsb_addr_map);
914fcaf780bSMauro Carvalho Chehab }
915fcaf780bSMauro Carvalho Chehab 
916d091a6ebSMauro Carvalho Chehab /**
917d091a6ebSMauro Carvalho Chehab  * i7300_get_devices() - Find and perform 'get' operation on the MCH's
918fcaf780bSMauro Carvalho Chehab  *			 device/functions we want to reference for this driver
919d091a6ebSMauro Carvalho Chehab  * @mci: struct mem_ctl_info pointer
920fcaf780bSMauro Carvalho Chehab  *
921d091a6ebSMauro Carvalho Chehab  * Access and prepare the several devices for usage:
922d091a6ebSMauro Carvalho Chehab  * I7300 devices used by this driver:
923d091a6ebSMauro Carvalho Chehab  *    Device 16, functions 0,1 and 2:	PCI_DEVICE_ID_INTEL_I7300_MCH_ERR
924d091a6ebSMauro Carvalho Chehab  *    Device 21 function 0:		PCI_DEVICE_ID_INTEL_I7300_MCH_FB0
925d091a6ebSMauro Carvalho Chehab  *    Device 22 function 0:		PCI_DEVICE_ID_INTEL_I7300_MCH_FB1
926fcaf780bSMauro Carvalho Chehab  */
927d091a6ebSMauro Carvalho Chehab static int __devinit i7300_get_devices(struct mem_ctl_info *mci)
928fcaf780bSMauro Carvalho Chehab {
929fcaf780bSMauro Carvalho Chehab 	struct i7300_pvt *pvt;
930fcaf780bSMauro Carvalho Chehab 	struct pci_dev *pdev;
931fcaf780bSMauro Carvalho Chehab 
932fcaf780bSMauro Carvalho Chehab 	pvt = mci->pvt_info;
933fcaf780bSMauro Carvalho Chehab 
934fcaf780bSMauro Carvalho Chehab 	/* Attempt to 'get' the MCH register we want */
935fcaf780bSMauro Carvalho Chehab 	pdev = NULL;
9369c6f6b65SMauro Carvalho Chehab 	while (!pvt->pci_dev_16_1_fsb_addr_map ||
9379c6f6b65SMauro Carvalho Chehab 	       !pvt->pci_dev_16_2_fsb_err_regs) {
938fcaf780bSMauro Carvalho Chehab 		pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
939fcaf780bSMauro Carvalho Chehab 				      PCI_DEVICE_ID_INTEL_I7300_MCH_ERR, pdev);
940fcaf780bSMauro Carvalho Chehab 		if (!pdev) {
941fcaf780bSMauro Carvalho Chehab 			/* End of list, leave */
942fcaf780bSMauro Carvalho Chehab 			i7300_printk(KERN_ERR,
943fcaf780bSMauro Carvalho Chehab 				"'system address,Process Bus' "
944fcaf780bSMauro Carvalho Chehab 				"device not found:"
945fcaf780bSMauro Carvalho Chehab 				"vendor 0x%x device 0x%x ERR funcs "
946fcaf780bSMauro Carvalho Chehab 				"(broken BIOS?)\n",
947fcaf780bSMauro Carvalho Chehab 				PCI_VENDOR_ID_INTEL,
948fcaf780bSMauro Carvalho Chehab 				PCI_DEVICE_ID_INTEL_I7300_MCH_ERR);
949fcaf780bSMauro Carvalho Chehab 			goto error;
950fcaf780bSMauro Carvalho Chehab 		}
951fcaf780bSMauro Carvalho Chehab 
952fcaf780bSMauro Carvalho Chehab 		/* Store device 16 funcs 1 and 2 */
953fcaf780bSMauro Carvalho Chehab 		switch (PCI_FUNC(pdev->devfn)) {
954fcaf780bSMauro Carvalho Chehab 		case 1:
9553e57eef6SMauro Carvalho Chehab 			pvt->pci_dev_16_1_fsb_addr_map = pdev;
956fcaf780bSMauro Carvalho Chehab 			break;
957fcaf780bSMauro Carvalho Chehab 		case 2:
9583e57eef6SMauro Carvalho Chehab 			pvt->pci_dev_16_2_fsb_err_regs = pdev;
959fcaf780bSMauro Carvalho Chehab 			break;
960fcaf780bSMauro Carvalho Chehab 		}
961fcaf780bSMauro Carvalho Chehab 	}
962fcaf780bSMauro Carvalho Chehab 
963fcaf780bSMauro Carvalho Chehab 	debugf1("System Address, processor bus- PCI Bus ID: %s  %x:%x\n",
9643e57eef6SMauro Carvalho Chehab 		pci_name(pvt->pci_dev_16_0_fsb_ctlr),
9659c6f6b65SMauro Carvalho Chehab 		pvt->pci_dev_16_0_fsb_ctlr->vendor,
9669c6f6b65SMauro Carvalho Chehab 		pvt->pci_dev_16_0_fsb_ctlr->device);
967fcaf780bSMauro Carvalho Chehab 	debugf1("Branchmap, control and errors - PCI Bus ID: %s  %x:%x\n",
9683e57eef6SMauro Carvalho Chehab 		pci_name(pvt->pci_dev_16_1_fsb_addr_map),
9699c6f6b65SMauro Carvalho Chehab 		pvt->pci_dev_16_1_fsb_addr_map->vendor,
9709c6f6b65SMauro Carvalho Chehab 		pvt->pci_dev_16_1_fsb_addr_map->device);
971fcaf780bSMauro Carvalho Chehab 	debugf1("FSB Error Regs - PCI Bus ID: %s  %x:%x\n",
9723e57eef6SMauro Carvalho Chehab 		pci_name(pvt->pci_dev_16_2_fsb_err_regs),
9739c6f6b65SMauro Carvalho Chehab 		pvt->pci_dev_16_2_fsb_err_regs->vendor,
9749c6f6b65SMauro Carvalho Chehab 		pvt->pci_dev_16_2_fsb_err_regs->device);
975fcaf780bSMauro Carvalho Chehab 
9763e57eef6SMauro Carvalho Chehab 	pvt->pci_dev_2x_0_fbd_branch[0] = pci_get_device(PCI_VENDOR_ID_INTEL,
977fcaf780bSMauro Carvalho Chehab 					    PCI_DEVICE_ID_INTEL_I7300_MCH_FB0,
978fcaf780bSMauro Carvalho Chehab 					    NULL);
9793e57eef6SMauro Carvalho Chehab 	if (!pvt->pci_dev_2x_0_fbd_branch[0]) {
980fcaf780bSMauro Carvalho Chehab 		i7300_printk(KERN_ERR,
981fcaf780bSMauro Carvalho Chehab 			"MC: 'BRANCH 0' device not found:"
982fcaf780bSMauro Carvalho Chehab 			"vendor 0x%x device 0x%x Func 0 (broken BIOS?)\n",
983fcaf780bSMauro Carvalho Chehab 			PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_FB0);
984fcaf780bSMauro Carvalho Chehab 		goto error;
985fcaf780bSMauro Carvalho Chehab 	}
986fcaf780bSMauro Carvalho Chehab 
9873e57eef6SMauro Carvalho Chehab 	pvt->pci_dev_2x_0_fbd_branch[1] = pci_get_device(PCI_VENDOR_ID_INTEL,
988fcaf780bSMauro Carvalho Chehab 					    PCI_DEVICE_ID_INTEL_I7300_MCH_FB1,
989fcaf780bSMauro Carvalho Chehab 					    NULL);
9903e57eef6SMauro Carvalho Chehab 	if (!pvt->pci_dev_2x_0_fbd_branch[1]) {
991fcaf780bSMauro Carvalho Chehab 		i7300_printk(KERN_ERR,
992fcaf780bSMauro Carvalho Chehab 			"MC: 'BRANCH 1' device not found:"
993fcaf780bSMauro Carvalho Chehab 			"vendor 0x%x device 0x%x Func 0 "
994fcaf780bSMauro Carvalho Chehab 			"(broken BIOS?)\n",
995fcaf780bSMauro Carvalho Chehab 			PCI_VENDOR_ID_INTEL,
996fcaf780bSMauro Carvalho Chehab 			PCI_DEVICE_ID_INTEL_I7300_MCH_FB1);
997fcaf780bSMauro Carvalho Chehab 		goto error;
998fcaf780bSMauro Carvalho Chehab 	}
999fcaf780bSMauro Carvalho Chehab 
1000fcaf780bSMauro Carvalho Chehab 	return 0;
1001fcaf780bSMauro Carvalho Chehab 
1002fcaf780bSMauro Carvalho Chehab error:
1003fcaf780bSMauro Carvalho Chehab 	i7300_put_devices(mci);
1004fcaf780bSMauro Carvalho Chehab 	return -ENODEV;
1005fcaf780bSMauro Carvalho Chehab }
1006fcaf780bSMauro Carvalho Chehab 
1007d091a6ebSMauro Carvalho Chehab /**
1008d091a6ebSMauro Carvalho Chehab  * i7300_init_one() - Probe for one instance of the device
1009d091a6ebSMauro Carvalho Chehab  * @pdev: struct pci_dev pointer
1010d091a6ebSMauro Carvalho Chehab  * @id: struct pci_device_id pointer - currently unused
1011fcaf780bSMauro Carvalho Chehab  */
1012d091a6ebSMauro Carvalho Chehab static int __devinit i7300_init_one(struct pci_dev *pdev,
1013d091a6ebSMauro Carvalho Chehab 				    const struct pci_device_id *id)
1014fcaf780bSMauro Carvalho Chehab {
1015fcaf780bSMauro Carvalho Chehab 	struct mem_ctl_info *mci;
101670e2a837SMauro Carvalho Chehab 	struct edac_mc_layer layers[3];
1017fcaf780bSMauro Carvalho Chehab 	struct i7300_pvt *pvt;
1018d091a6ebSMauro Carvalho Chehab 	int rc;
1019fcaf780bSMauro Carvalho Chehab 
1020d091a6ebSMauro Carvalho Chehab 	/* wake up device */
1021d091a6ebSMauro Carvalho Chehab 	rc = pci_enable_device(pdev);
1022d091a6ebSMauro Carvalho Chehab 	if (rc == -EIO)
1023d091a6ebSMauro Carvalho Chehab 		return rc;
1024fcaf780bSMauro Carvalho Chehab 
1025dd23cd6eSMauro Carvalho Chehab 	debugf0("MC: pdev bus %u dev=0x%x fn=0x%x\n",
1026fcaf780bSMauro Carvalho Chehab 		pdev->bus->number,
1027fcaf780bSMauro Carvalho Chehab 		PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
1028fcaf780bSMauro Carvalho Chehab 
1029fcaf780bSMauro Carvalho Chehab 	/* We only are looking for func 0 of the set */
1030fcaf780bSMauro Carvalho Chehab 	if (PCI_FUNC(pdev->devfn) != 0)
1031fcaf780bSMauro Carvalho Chehab 		return -ENODEV;
1032fcaf780bSMauro Carvalho Chehab 
1033fcaf780bSMauro Carvalho Chehab 	/* allocate a new MC control structure */
103470e2a837SMauro Carvalho Chehab 	layers[0].type = EDAC_MC_LAYER_BRANCH;
103570e2a837SMauro Carvalho Chehab 	layers[0].size = MAX_BRANCHES;
103670e2a837SMauro Carvalho Chehab 	layers[0].is_virt_csrow = false;
103770e2a837SMauro Carvalho Chehab 	layers[1].type = EDAC_MC_LAYER_CHANNEL;
103870e2a837SMauro Carvalho Chehab 	layers[1].size = MAX_CH_PER_BRANCH;
103970e2a837SMauro Carvalho Chehab 	layers[1].is_virt_csrow = true;
104070e2a837SMauro Carvalho Chehab 	layers[2].type = EDAC_MC_LAYER_SLOT;
104170e2a837SMauro Carvalho Chehab 	layers[2].size = MAX_SLOTS;
104270e2a837SMauro Carvalho Chehab 	layers[2].is_virt_csrow = true;
1043ca0907b9SMauro Carvalho Chehab 	mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, sizeof(*pvt));
1044fcaf780bSMauro Carvalho Chehab 	if (mci == NULL)
1045fcaf780bSMauro Carvalho Chehab 		return -ENOMEM;
1046fcaf780bSMauro Carvalho Chehab 
1047dd23cd6eSMauro Carvalho Chehab 	debugf0("MC: mci = %p\n", mci);
1048fcaf780bSMauro Carvalho Chehab 
1049fd687502SMauro Carvalho Chehab 	mci->pdev = &pdev->dev;	/* record ptr  to the generic device */
1050fcaf780bSMauro Carvalho Chehab 
1051fcaf780bSMauro Carvalho Chehab 	pvt = mci->pvt_info;
10523e57eef6SMauro Carvalho Chehab 	pvt->pci_dev_16_0_fsb_ctlr = pdev;	/* Record this device in our private */
1053fcaf780bSMauro Carvalho Chehab 
105485580ea4SMauro Carvalho Chehab 	pvt->tmp_prt_buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);
105585580ea4SMauro Carvalho Chehab 	if (!pvt->tmp_prt_buffer) {
105685580ea4SMauro Carvalho Chehab 		edac_mc_free(mci);
105785580ea4SMauro Carvalho Chehab 		return -ENOMEM;
105885580ea4SMauro Carvalho Chehab 	}
105985580ea4SMauro Carvalho Chehab 
1060fcaf780bSMauro Carvalho Chehab 	/* 'get' the pci devices we want to reserve for our use */
1061d091a6ebSMauro Carvalho Chehab 	if (i7300_get_devices(mci))
1062fcaf780bSMauro Carvalho Chehab 		goto fail0;
1063fcaf780bSMauro Carvalho Chehab 
1064fcaf780bSMauro Carvalho Chehab 	mci->mc_idx = 0;
1065fcaf780bSMauro Carvalho Chehab 	mci->mtype_cap = MEM_FLAG_FB_DDR2;
1066fcaf780bSMauro Carvalho Chehab 	mci->edac_ctl_cap = EDAC_FLAG_NONE;
1067fcaf780bSMauro Carvalho Chehab 	mci->edac_cap = EDAC_FLAG_NONE;
1068fcaf780bSMauro Carvalho Chehab 	mci->mod_name = "i7300_edac.c";
1069fcaf780bSMauro Carvalho Chehab 	mci->mod_ver = I7300_REVISION;
1070d091a6ebSMauro Carvalho Chehab 	mci->ctl_name = i7300_devs[0].ctl_name;
1071fcaf780bSMauro Carvalho Chehab 	mci->dev_name = pci_name(pdev);
1072fcaf780bSMauro Carvalho Chehab 	mci->ctl_page_to_phys = NULL;
1073fcaf780bSMauro Carvalho Chehab 
1074fcaf780bSMauro Carvalho Chehab 	/* Set the function pointer to an actual operation function */
1075fcaf780bSMauro Carvalho Chehab 	mci->edac_check = i7300_check_error;
1076fcaf780bSMauro Carvalho Chehab 
1077fcaf780bSMauro Carvalho Chehab 	/* initialize the MC control structure 'csrows' table
1078fcaf780bSMauro Carvalho Chehab 	 * with the mapping and control information */
1079fcaf780bSMauro Carvalho Chehab 	if (i7300_get_mc_regs(mci)) {
1080fcaf780bSMauro Carvalho Chehab 		debugf0("MC: Setting mci->edac_cap to EDAC_FLAG_NONE\n"
1081fcaf780bSMauro Carvalho Chehab 			"    because i7300_init_csrows() returned nonzero "
1082fcaf780bSMauro Carvalho Chehab 			"value\n");
1083fcaf780bSMauro Carvalho Chehab 		mci->edac_cap = EDAC_FLAG_NONE;	/* no csrows found */
1084fcaf780bSMauro Carvalho Chehab 	} else {
1085fcaf780bSMauro Carvalho Chehab 		debugf1("MC: Enable error reporting now\n");
1086fcaf780bSMauro Carvalho Chehab 		i7300_enable_error_reporting(mci);
1087fcaf780bSMauro Carvalho Chehab 	}
1088fcaf780bSMauro Carvalho Chehab 
1089fcaf780bSMauro Carvalho Chehab 	/* add this new MC control structure to EDAC's list of MCs */
1090fcaf780bSMauro Carvalho Chehab 	if (edac_mc_add_mc(mci)) {
1091dd23cd6eSMauro Carvalho Chehab 		debugf0("MC: failed edac_mc_add_mc()\n");
1092fcaf780bSMauro Carvalho Chehab 		/* FIXME: perhaps some code should go here that disables error
1093fcaf780bSMauro Carvalho Chehab 		 * reporting if we just enabled it
1094fcaf780bSMauro Carvalho Chehab 		 */
1095fcaf780bSMauro Carvalho Chehab 		goto fail1;
1096fcaf780bSMauro Carvalho Chehab 	}
1097fcaf780bSMauro Carvalho Chehab 
1098fcaf780bSMauro Carvalho Chehab 	i7300_clear_error(mci);
1099fcaf780bSMauro Carvalho Chehab 
1100fcaf780bSMauro Carvalho Chehab 	/* allocating generic PCI control info */
1101fcaf780bSMauro Carvalho Chehab 	i7300_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
1102fcaf780bSMauro Carvalho Chehab 	if (!i7300_pci) {
1103fcaf780bSMauro Carvalho Chehab 		printk(KERN_WARNING
1104fcaf780bSMauro Carvalho Chehab 			"%s(): Unable to create PCI control\n",
1105fcaf780bSMauro Carvalho Chehab 			__func__);
1106fcaf780bSMauro Carvalho Chehab 		printk(KERN_WARNING
1107fcaf780bSMauro Carvalho Chehab 			"%s(): PCI error report via EDAC not setup\n",
1108fcaf780bSMauro Carvalho Chehab 			__func__);
1109fcaf780bSMauro Carvalho Chehab 	}
1110fcaf780bSMauro Carvalho Chehab 
1111fcaf780bSMauro Carvalho Chehab 	return 0;
1112fcaf780bSMauro Carvalho Chehab 
1113fcaf780bSMauro Carvalho Chehab 	/* Error exit unwinding stack */
1114fcaf780bSMauro Carvalho Chehab fail1:
1115fcaf780bSMauro Carvalho Chehab 
1116fcaf780bSMauro Carvalho Chehab 	i7300_put_devices(mci);
1117fcaf780bSMauro Carvalho Chehab 
1118fcaf780bSMauro Carvalho Chehab fail0:
111985580ea4SMauro Carvalho Chehab 	kfree(pvt->tmp_prt_buffer);
1120fcaf780bSMauro Carvalho Chehab 	edac_mc_free(mci);
1121fcaf780bSMauro Carvalho Chehab 	return -ENODEV;
1122fcaf780bSMauro Carvalho Chehab }
1123fcaf780bSMauro Carvalho Chehab 
1124d091a6ebSMauro Carvalho Chehab /**
1125d091a6ebSMauro Carvalho Chehab  * i7300_remove_one() - Remove the driver
1126d091a6ebSMauro Carvalho Chehab  * @pdev: struct pci_dev pointer
1127fcaf780bSMauro Carvalho Chehab  */
1128fcaf780bSMauro Carvalho Chehab static void __devexit i7300_remove_one(struct pci_dev *pdev)
1129fcaf780bSMauro Carvalho Chehab {
1130fcaf780bSMauro Carvalho Chehab 	struct mem_ctl_info *mci;
113185580ea4SMauro Carvalho Chehab 	char *tmp;
1132fcaf780bSMauro Carvalho Chehab 
1133dd23cd6eSMauro Carvalho Chehab 	debugf0("\n");
1134fcaf780bSMauro Carvalho Chehab 
1135fcaf780bSMauro Carvalho Chehab 	if (i7300_pci)
1136fcaf780bSMauro Carvalho Chehab 		edac_pci_release_generic_ctl(i7300_pci);
1137fcaf780bSMauro Carvalho Chehab 
1138fcaf780bSMauro Carvalho Chehab 	mci = edac_mc_del_mc(&pdev->dev);
1139fcaf780bSMauro Carvalho Chehab 	if (!mci)
1140fcaf780bSMauro Carvalho Chehab 		return;
1141fcaf780bSMauro Carvalho Chehab 
114285580ea4SMauro Carvalho Chehab 	tmp = ((struct i7300_pvt *)mci->pvt_info)->tmp_prt_buffer;
114385580ea4SMauro Carvalho Chehab 
1144fcaf780bSMauro Carvalho Chehab 	/* retrieve references to resources, and free those resources */
1145fcaf780bSMauro Carvalho Chehab 	i7300_put_devices(mci);
1146fcaf780bSMauro Carvalho Chehab 
114785580ea4SMauro Carvalho Chehab 	kfree(tmp);
1148fcaf780bSMauro Carvalho Chehab 	edac_mc_free(mci);
1149fcaf780bSMauro Carvalho Chehab }
1150fcaf780bSMauro Carvalho Chehab 
1151fcaf780bSMauro Carvalho Chehab /*
1152d091a6ebSMauro Carvalho Chehab  * pci_device_id: table for which devices we are looking for
1153fcaf780bSMauro Carvalho Chehab  *
1154d091a6ebSMauro Carvalho Chehab  * Has only 8086:360c PCI ID
1155fcaf780bSMauro Carvalho Chehab  */
115636c46f31SLionel Debroux static DEFINE_PCI_DEVICE_TABLE(i7300_pci_tbl) = {
1157fcaf780bSMauro Carvalho Chehab 	{PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
1158fcaf780bSMauro Carvalho Chehab 	{0,}			/* 0 terminated list. */
1159fcaf780bSMauro Carvalho Chehab };
1160fcaf780bSMauro Carvalho Chehab 
1161fcaf780bSMauro Carvalho Chehab MODULE_DEVICE_TABLE(pci, i7300_pci_tbl);
1162fcaf780bSMauro Carvalho Chehab 
1163fcaf780bSMauro Carvalho Chehab /*
1164d091a6ebSMauro Carvalho Chehab  * i7300_driver: pci_driver structure for this module
1165fcaf780bSMauro Carvalho Chehab  */
1166fcaf780bSMauro Carvalho Chehab static struct pci_driver i7300_driver = {
1167fcaf780bSMauro Carvalho Chehab 	.name = "i7300_edac",
1168fcaf780bSMauro Carvalho Chehab 	.probe = i7300_init_one,
1169fcaf780bSMauro Carvalho Chehab 	.remove = __devexit_p(i7300_remove_one),
1170fcaf780bSMauro Carvalho Chehab 	.id_table = i7300_pci_tbl,
1171fcaf780bSMauro Carvalho Chehab };
1172fcaf780bSMauro Carvalho Chehab 
1173d091a6ebSMauro Carvalho Chehab /**
1174d091a6ebSMauro Carvalho Chehab  * i7300_init() - Registers the driver
1175fcaf780bSMauro Carvalho Chehab  */
1176fcaf780bSMauro Carvalho Chehab static int __init i7300_init(void)
1177fcaf780bSMauro Carvalho Chehab {
1178fcaf780bSMauro Carvalho Chehab 	int pci_rc;
1179fcaf780bSMauro Carvalho Chehab 
1180dd23cd6eSMauro Carvalho Chehab 	debugf2("\n");
1181fcaf780bSMauro Carvalho Chehab 
1182fcaf780bSMauro Carvalho Chehab 	/* Ensure that the OPSTATE is set correctly for POLL or NMI */
1183fcaf780bSMauro Carvalho Chehab 	opstate_init();
1184fcaf780bSMauro Carvalho Chehab 
1185fcaf780bSMauro Carvalho Chehab 	pci_rc = pci_register_driver(&i7300_driver);
1186fcaf780bSMauro Carvalho Chehab 
1187fcaf780bSMauro Carvalho Chehab 	return (pci_rc < 0) ? pci_rc : 0;
1188fcaf780bSMauro Carvalho Chehab }
1189fcaf780bSMauro Carvalho Chehab 
1190d091a6ebSMauro Carvalho Chehab /**
1191d091a6ebSMauro Carvalho Chehab  * i7300_init() - Unregisters the driver
1192fcaf780bSMauro Carvalho Chehab  */
1193fcaf780bSMauro Carvalho Chehab static void __exit i7300_exit(void)
1194fcaf780bSMauro Carvalho Chehab {
1195dd23cd6eSMauro Carvalho Chehab 	debugf2("\n");
1196fcaf780bSMauro Carvalho Chehab 	pci_unregister_driver(&i7300_driver);
1197fcaf780bSMauro Carvalho Chehab }
1198fcaf780bSMauro Carvalho Chehab 
1199fcaf780bSMauro Carvalho Chehab module_init(i7300_init);
1200fcaf780bSMauro Carvalho Chehab module_exit(i7300_exit);
1201fcaf780bSMauro Carvalho Chehab 
1202fcaf780bSMauro Carvalho Chehab MODULE_LICENSE("GPL");
1203fcaf780bSMauro Carvalho Chehab MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
1204fcaf780bSMauro Carvalho Chehab MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
1205fcaf780bSMauro Carvalho Chehab MODULE_DESCRIPTION("MC Driver for Intel I7300 memory controllers - "
1206fcaf780bSMauro Carvalho Chehab 		   I7300_REVISION);
1207fcaf780bSMauro Carvalho Chehab 
1208fcaf780bSMauro Carvalho Chehab module_param(edac_op_state, int, 0444);
1209fcaf780bSMauro Carvalho Chehab MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
1210