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