Mauro Carvalho Chehab | 52707f9 | 2010-05-18 20:43:52 -0300 | [diff] [blame] | 1 | /* Intel i7 core/Nehalem Memory Controller kernel module |
| 2 | * |
David Sterba | e7bf068 | 2010-12-27 16:51:15 +0100 | [diff] [blame] | 3 | * This driver supports the memory controllers found on the Intel |
Mauro Carvalho Chehab | 52707f9 | 2010-05-18 20:43:52 -0300 | [diff] [blame] | 4 | * processor families i7core, i7core 7xx/8xx, i5core, Xeon 35xx, |
| 5 | * Xeon 55xx and Xeon 56xx also known as Nehalem, Nehalem-EP, Lynnfield |
| 6 | * and Westmere-EP. |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 7 | * |
| 8 | * This file may be distributed under the terms of the |
| 9 | * GNU General Public License version 2 only. |
| 10 | * |
Mauro Carvalho Chehab | 52707f9 | 2010-05-18 20:43:52 -0300 | [diff] [blame] | 11 | * Copyright (c) 2009-2010 by: |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 12 | * Mauro Carvalho Chehab <mchehab@redhat.com> |
| 13 | * |
| 14 | * Red Hat Inc. http://www.redhat.com |
| 15 | * |
| 16 | * Forked and adapted from the i5400_edac driver |
| 17 | * |
| 18 | * Based on the following public Intel datasheets: |
| 19 | * Intel Core i7 Processor Extreme Edition and Intel Core i7 Processor |
| 20 | * Datasheet, Volume 2: |
| 21 | * http://download.intel.com/design/processor/datashts/320835.pdf |
| 22 | * Intel Xeon Processor 5500 Series Datasheet Volume 2 |
| 23 | * http://www.intel.com/Assets/PDF/datasheet/321322.pdf |
| 24 | * also available at: |
| 25 | * http://www.arrownac.com/manufacturers/intel/s/nehalem/5500-datasheet-v2.pdf |
| 26 | */ |
| 27 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 28 | #include <linux/module.h> |
| 29 | #include <linux/init.h> |
| 30 | #include <linux/pci.h> |
| 31 | #include <linux/pci_ids.h> |
| 32 | #include <linux/slab.h> |
Randy Dunlap | 3b918c1 | 2009-11-08 01:36:40 -0200 | [diff] [blame] | 33 | #include <linux/delay.h> |
Nils Carlson | 535e9c7 | 2011-08-08 06:21:26 -0300 | [diff] [blame^] | 34 | #include <linux/dmi.h> |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 35 | #include <linux/edac.h> |
| 36 | #include <linux/mmzone.h> |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 37 | #include <linux/smp.h> |
Borislav Petkov | 4140c54 | 2011-07-18 11:24:46 -0300 | [diff] [blame] | 38 | #include <asm/mce.h> |
Mauro Carvalho Chehab | 14d2c08 | 2009-09-02 23:52:36 -0300 | [diff] [blame] | 39 | #include <asm/processor.h> |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 40 | |
| 41 | #include "edac_core.h" |
| 42 | |
Mauro Carvalho Chehab | 18c2900 | 2010-08-10 18:33:27 -0300 | [diff] [blame] | 43 | /* Static vars */ |
| 44 | static LIST_HEAD(i7core_edac_list); |
| 45 | static DEFINE_MUTEX(i7core_edac_lock); |
| 46 | static int probed; |
| 47 | |
Mauro Carvalho Chehab | 54a08ab | 2010-08-19 15:51:00 -0300 | [diff] [blame] | 48 | static int use_pci_fixup; |
| 49 | module_param(use_pci_fixup, int, 0444); |
| 50 | MODULE_PARM_DESC(use_pci_fixup, "Enable PCI fixup to seek for hidden devices"); |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 51 | /* |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 52 | * This is used for Nehalem-EP and Nehalem-EX devices, where the non-core |
| 53 | * registers start at bus 255, and are not reported by BIOS. |
| 54 | * We currently find devices with only 2 sockets. In order to support more QPI |
| 55 | * Quick Path Interconnect, just increment this number. |
| 56 | */ |
| 57 | #define MAX_SOCKET_BUSES 2 |
| 58 | |
| 59 | |
| 60 | /* |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 61 | * Alter this version for the module when modifications are made |
| 62 | */ |
Michal Marek | 152ba39 | 2011-04-01 12:41:20 +0200 | [diff] [blame] | 63 | #define I7CORE_REVISION " Ver: 1.0.0" |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 64 | #define EDAC_MOD_STR "i7core_edac" |
| 65 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 66 | /* |
| 67 | * Debug macros |
| 68 | */ |
| 69 | #define i7core_printk(level, fmt, arg...) \ |
| 70 | edac_printk(level, "i7core", fmt, ##arg) |
| 71 | |
| 72 | #define i7core_mc_printk(mci, level, fmt, arg...) \ |
| 73 | edac_mc_chipset_printk(mci, level, "i7core", fmt, ##arg) |
| 74 | |
| 75 | /* |
| 76 | * i7core Memory Controller Registers |
| 77 | */ |
| 78 | |
Mauro Carvalho Chehab | e9bd2e7 | 2009-07-09 22:14:35 -0300 | [diff] [blame] | 79 | /* OFFSETS for Device 0 Function 0 */ |
| 80 | |
| 81 | #define MC_CFG_CONTROL 0x90 |
Samuel Gabrielsson | e8b6a12 | 2011-03-30 10:21:23 -0300 | [diff] [blame] | 82 | #define MC_CFG_UNLOCK 0x02 |
| 83 | #define MC_CFG_LOCK 0x00 |
Mauro Carvalho Chehab | e9bd2e7 | 2009-07-09 22:14:35 -0300 | [diff] [blame] | 84 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 85 | /* OFFSETS for Device 3 Function 0 */ |
| 86 | |
| 87 | #define MC_CONTROL 0x48 |
| 88 | #define MC_STATUS 0x4c |
| 89 | #define MC_MAX_DOD 0x64 |
| 90 | |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 91 | /* |
| 92 | * OFFSETS for Device 3 Function 4, as inicated on Xeon 5500 datasheet: |
| 93 | * http://www.arrownac.com/manufacturers/intel/s/nehalem/5500-datasheet-v2.pdf |
| 94 | */ |
| 95 | |
| 96 | #define MC_TEST_ERR_RCV1 0x60 |
| 97 | #define DIMM2_COR_ERR(r) ((r) & 0x7fff) |
| 98 | |
| 99 | #define MC_TEST_ERR_RCV0 0x64 |
| 100 | #define DIMM1_COR_ERR(r) (((r) >> 16) & 0x7fff) |
| 101 | #define DIMM0_COR_ERR(r) ((r) & 0x7fff) |
| 102 | |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 103 | /* OFFSETS for Device 3 Function 2, as inicated on Xeon 5500 datasheet */ |
Samuel Gabrielsson | e8b6a12 | 2011-03-30 10:21:23 -0300 | [diff] [blame] | 104 | #define MC_SSRCONTROL 0x48 |
| 105 | #define SSR_MODE_DISABLE 0x00 |
| 106 | #define SSR_MODE_ENABLE 0x01 |
| 107 | #define SSR_MODE_MASK 0x03 |
| 108 | |
| 109 | #define MC_SCRUB_CONTROL 0x4c |
| 110 | #define STARTSCRUB (1 << 24) |
Nils Carlson | 535e9c7 | 2011-08-08 06:21:26 -0300 | [diff] [blame^] | 111 | #define SCRUBINTERVAL_MASK 0xffffff |
Samuel Gabrielsson | e8b6a12 | 2011-03-30 10:21:23 -0300 | [diff] [blame] | 112 | |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 113 | #define MC_COR_ECC_CNT_0 0x80 |
| 114 | #define MC_COR_ECC_CNT_1 0x84 |
| 115 | #define MC_COR_ECC_CNT_2 0x88 |
| 116 | #define MC_COR_ECC_CNT_3 0x8c |
| 117 | #define MC_COR_ECC_CNT_4 0x90 |
| 118 | #define MC_COR_ECC_CNT_5 0x94 |
| 119 | |
| 120 | #define DIMM_TOP_COR_ERR(r) (((r) >> 16) & 0x7fff) |
| 121 | #define DIMM_BOT_COR_ERR(r) ((r) & 0x7fff) |
| 122 | |
| 123 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 124 | /* OFFSETS for Devices 4,5 and 6 Function 0 */ |
| 125 | |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 126 | #define MC_CHANNEL_DIMM_INIT_PARAMS 0x58 |
| 127 | #define THREE_DIMMS_PRESENT (1 << 24) |
| 128 | #define SINGLE_QUAD_RANK_PRESENT (1 << 23) |
| 129 | #define QUAD_RANK_PRESENT (1 << 22) |
| 130 | #define REGISTERED_DIMM (1 << 15) |
| 131 | |
Mauro Carvalho Chehab | f122a89 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 132 | #define MC_CHANNEL_MAPPER 0x60 |
| 133 | #define RDLCH(r, ch) ((((r) >> (3 + (ch * 6))) & 0x07) - 1) |
| 134 | #define WRLCH(r, ch) ((((r) >> (ch * 6)) & 0x07) - 1) |
| 135 | |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 136 | #define MC_CHANNEL_RANK_PRESENT 0x7c |
| 137 | #define RANK_PRESENT_MASK 0xffff |
| 138 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 139 | #define MC_CHANNEL_ADDR_MATCH 0xf0 |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 140 | #define MC_CHANNEL_ERROR_MASK 0xf8 |
| 141 | #define MC_CHANNEL_ERROR_INJECT 0xfc |
| 142 | #define INJECT_ADDR_PARITY 0x10 |
| 143 | #define INJECT_ECC 0x08 |
| 144 | #define MASK_CACHELINE 0x06 |
| 145 | #define MASK_FULL_CACHELINE 0x06 |
| 146 | #define MASK_MSB32_CACHELINE 0x04 |
| 147 | #define MASK_LSB32_CACHELINE 0x02 |
| 148 | #define NO_MASK_CACHELINE 0x00 |
| 149 | #define REPEAT_EN 0x01 |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 150 | |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 151 | /* OFFSETS for Devices 4,5 and 6 Function 1 */ |
Mauro Carvalho Chehab | b990538 | 2009-08-05 21:36:35 -0300 | [diff] [blame] | 152 | |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 153 | #define MC_DOD_CH_DIMM0 0x48 |
| 154 | #define MC_DOD_CH_DIMM1 0x4c |
| 155 | #define MC_DOD_CH_DIMM2 0x50 |
| 156 | #define RANKOFFSET_MASK ((1 << 12) | (1 << 11) | (1 << 10)) |
| 157 | #define RANKOFFSET(x) ((x & RANKOFFSET_MASK) >> 10) |
| 158 | #define DIMM_PRESENT_MASK (1 << 9) |
| 159 | #define DIMM_PRESENT(x) (((x) & DIMM_PRESENT_MASK) >> 9) |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 160 | #define MC_DOD_NUMBANK_MASK ((1 << 8) | (1 << 7)) |
| 161 | #define MC_DOD_NUMBANK(x) (((x) & MC_DOD_NUMBANK_MASK) >> 7) |
| 162 | #define MC_DOD_NUMRANK_MASK ((1 << 6) | (1 << 5)) |
| 163 | #define MC_DOD_NUMRANK(x) (((x) & MC_DOD_NUMRANK_MASK) >> 5) |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 164 | #define MC_DOD_NUMROW_MASK ((1 << 4) | (1 << 3) | (1 << 2)) |
Mauro Carvalho Chehab | 5566cb7 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 165 | #define MC_DOD_NUMROW(x) (((x) & MC_DOD_NUMROW_MASK) >> 2) |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 166 | #define MC_DOD_NUMCOL_MASK 3 |
| 167 | #define MC_DOD_NUMCOL(x) ((x) & MC_DOD_NUMCOL_MASK) |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 168 | |
Mauro Carvalho Chehab | f122a89 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 169 | #define MC_RANK_PRESENT 0x7c |
| 170 | |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 171 | #define MC_SAG_CH_0 0x80 |
| 172 | #define MC_SAG_CH_1 0x84 |
| 173 | #define MC_SAG_CH_2 0x88 |
| 174 | #define MC_SAG_CH_3 0x8c |
| 175 | #define MC_SAG_CH_4 0x90 |
| 176 | #define MC_SAG_CH_5 0x94 |
| 177 | #define MC_SAG_CH_6 0x98 |
| 178 | #define MC_SAG_CH_7 0x9c |
| 179 | |
| 180 | #define MC_RIR_LIMIT_CH_0 0x40 |
| 181 | #define MC_RIR_LIMIT_CH_1 0x44 |
| 182 | #define MC_RIR_LIMIT_CH_2 0x48 |
| 183 | #define MC_RIR_LIMIT_CH_3 0x4C |
| 184 | #define MC_RIR_LIMIT_CH_4 0x50 |
| 185 | #define MC_RIR_LIMIT_CH_5 0x54 |
| 186 | #define MC_RIR_LIMIT_CH_6 0x58 |
| 187 | #define MC_RIR_LIMIT_CH_7 0x5C |
| 188 | #define MC_RIR_LIMIT_MASK ((1 << 10) - 1) |
| 189 | |
| 190 | #define MC_RIR_WAY_CH 0x80 |
| 191 | #define MC_RIR_WAY_OFFSET_MASK (((1 << 14) - 1) & ~0x7) |
| 192 | #define MC_RIR_WAY_RANK_MASK 0x7 |
| 193 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 194 | /* |
| 195 | * i7core structs |
| 196 | */ |
| 197 | |
| 198 | #define NUM_CHANS 3 |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 199 | #define MAX_DIMMS 3 /* Max DIMMS per channel */ |
| 200 | #define MAX_MCR_FUNC 4 |
| 201 | #define MAX_CHAN_FUNC 3 |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 202 | |
| 203 | struct i7core_info { |
| 204 | u32 mc_control; |
| 205 | u32 mc_status; |
| 206 | u32 max_dod; |
Mauro Carvalho Chehab | f122a89 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 207 | u32 ch_map; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 208 | }; |
| 209 | |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 210 | |
| 211 | struct i7core_inject { |
| 212 | int enable; |
| 213 | |
| 214 | u32 section; |
| 215 | u32 type; |
| 216 | u32 eccmask; |
| 217 | |
| 218 | /* Error address mask */ |
| 219 | int channel, dimm, rank, bank, page, col; |
| 220 | }; |
| 221 | |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 222 | struct i7core_channel { |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 223 | u32 ranks; |
| 224 | u32 dimms; |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 225 | }; |
| 226 | |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 227 | struct pci_id_descr { |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 228 | int dev; |
| 229 | int func; |
| 230 | int dev_id; |
Mauro Carvalho Chehab | de06eee | 2009-10-14 08:02:40 -0300 | [diff] [blame] | 231 | int optional; |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 232 | }; |
| 233 | |
Vernon Mauery | bd9e19c | 2010-05-18 19:02:50 -0300 | [diff] [blame] | 234 | struct pci_id_table { |
Mauro Carvalho Chehab | 1288c18 | 2010-08-10 18:57:01 -0300 | [diff] [blame] | 235 | const struct pci_id_descr *descr; |
| 236 | int n_devs; |
Vernon Mauery | bd9e19c | 2010-05-18 19:02:50 -0300 | [diff] [blame] | 237 | }; |
| 238 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 239 | struct i7core_dev { |
| 240 | struct list_head list; |
| 241 | u8 socket; |
| 242 | struct pci_dev **pdev; |
Mauro Carvalho Chehab | de06eee | 2009-10-14 08:02:40 -0300 | [diff] [blame] | 243 | int n_devs; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 244 | struct mem_ctl_info *mci; |
| 245 | }; |
| 246 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 247 | struct i7core_pvt { |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 248 | struct pci_dev *pci_noncore; |
| 249 | struct pci_dev *pci_mcr[MAX_MCR_FUNC + 1]; |
| 250 | struct pci_dev *pci_ch[NUM_CHANS][MAX_CHAN_FUNC + 1]; |
| 251 | |
| 252 | struct i7core_dev *i7core_dev; |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 253 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 254 | struct i7core_info info; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 255 | struct i7core_inject inject; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 256 | struct i7core_channel channel[NUM_CHANS]; |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 257 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 258 | int ce_count_available; |
| 259 | int csrow_map[NUM_CHANS][MAX_DIMMS]; |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 260 | |
| 261 | /* ECC corrected errors counts per udimm */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 262 | unsigned long udimm_ce_count[MAX_DIMMS]; |
| 263 | int udimm_last_ce_count[MAX_DIMMS]; |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 264 | /* ECC corrected errors counts per rdimm */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 265 | unsigned long rdimm_ce_count[NUM_CHANS][MAX_DIMMS]; |
| 266 | int rdimm_last_ce_count[NUM_CHANS][MAX_DIMMS]; |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 267 | |
Mauro Carvalho Chehab | 27100db | 2011-08-04 21:35:27 -0300 | [diff] [blame] | 268 | bool is_registered, enable_scrub; |
Mauro Carvalho Chehab | 14d2c08 | 2009-09-02 23:52:36 -0300 | [diff] [blame] | 269 | |
Mauro Carvalho Chehab | ca9c90b | 2009-10-04 10:15:40 -0300 | [diff] [blame] | 270 | /* Fifo double buffers */ |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 271 | struct mce mce_entry[MCE_LOG_LEN]; |
Mauro Carvalho Chehab | ca9c90b | 2009-10-04 10:15:40 -0300 | [diff] [blame] | 272 | struct mce mce_outentry[MCE_LOG_LEN]; |
| 273 | |
| 274 | /* Fifo in/out counters */ |
| 275 | unsigned mce_in, mce_out; |
| 276 | |
| 277 | /* Count indicator to show errors not got */ |
| 278 | unsigned mce_overrun; |
Mauro Carvalho Chehab | 939747bd | 2010-08-10 11:22:01 -0300 | [diff] [blame] | 279 | |
Nils Carlson | 535e9c7 | 2011-08-08 06:21:26 -0300 | [diff] [blame^] | 280 | /* DCLK Frequency used for computing scrub rate */ |
| 281 | int dclk_freq; |
| 282 | |
Mauro Carvalho Chehab | 939747bd | 2010-08-10 11:22:01 -0300 | [diff] [blame] | 283 | /* Struct to control EDAC polling */ |
| 284 | struct edac_pci_ctl_info *i7core_pci; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 285 | }; |
| 286 | |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 287 | #define PCI_DESCR(device, function, device_id) \ |
| 288 | .dev = (device), \ |
| 289 | .func = (function), \ |
| 290 | .dev_id = (device_id) |
| 291 | |
Mauro Carvalho Chehab | 1288c18 | 2010-08-10 18:57:01 -0300 | [diff] [blame] | 292 | static const struct pci_id_descr pci_dev_descr_i7core_nehalem[] = { |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 293 | /* Memory controller */ |
| 294 | { PCI_DESCR(3, 0, PCI_DEVICE_ID_INTEL_I7_MCR) }, |
| 295 | { PCI_DESCR(3, 1, PCI_DEVICE_ID_INTEL_I7_MC_TAD) }, |
Mauro Carvalho Chehab | 224e871 | 2011-03-17 17:02:59 -0300 | [diff] [blame] | 296 | /* Exists only for RDIMM */ |
Mauro Carvalho Chehab | de06eee | 2009-10-14 08:02:40 -0300 | [diff] [blame] | 297 | { PCI_DESCR(3, 2, PCI_DEVICE_ID_INTEL_I7_MC_RAS), .optional = 1 }, |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 298 | { PCI_DESCR(3, 4, PCI_DEVICE_ID_INTEL_I7_MC_TEST) }, |
| 299 | |
| 300 | /* Channel 0 */ |
| 301 | { PCI_DESCR(4, 0, PCI_DEVICE_ID_INTEL_I7_MC_CH0_CTRL) }, |
| 302 | { PCI_DESCR(4, 1, PCI_DEVICE_ID_INTEL_I7_MC_CH0_ADDR) }, |
| 303 | { PCI_DESCR(4, 2, PCI_DEVICE_ID_INTEL_I7_MC_CH0_RANK) }, |
| 304 | { PCI_DESCR(4, 3, PCI_DEVICE_ID_INTEL_I7_MC_CH0_TC) }, |
| 305 | |
| 306 | /* Channel 1 */ |
| 307 | { PCI_DESCR(5, 0, PCI_DEVICE_ID_INTEL_I7_MC_CH1_CTRL) }, |
| 308 | { PCI_DESCR(5, 1, PCI_DEVICE_ID_INTEL_I7_MC_CH1_ADDR) }, |
| 309 | { PCI_DESCR(5, 2, PCI_DEVICE_ID_INTEL_I7_MC_CH1_RANK) }, |
| 310 | { PCI_DESCR(5, 3, PCI_DEVICE_ID_INTEL_I7_MC_CH1_TC) }, |
| 311 | |
| 312 | /* Channel 2 */ |
| 313 | { PCI_DESCR(6, 0, PCI_DEVICE_ID_INTEL_I7_MC_CH2_CTRL) }, |
| 314 | { PCI_DESCR(6, 1, PCI_DEVICE_ID_INTEL_I7_MC_CH2_ADDR) }, |
| 315 | { PCI_DESCR(6, 2, PCI_DEVICE_ID_INTEL_I7_MC_CH2_RANK) }, |
| 316 | { PCI_DESCR(6, 3, PCI_DEVICE_ID_INTEL_I7_MC_CH2_TC) }, |
Mauro Carvalho Chehab | 224e871 | 2011-03-17 17:02:59 -0300 | [diff] [blame] | 317 | |
| 318 | /* Generic Non-core registers */ |
| 319 | /* |
| 320 | * This is the PCI device on i7core and on Xeon 35xx (8086:2c41) |
| 321 | * On Xeon 55xx, however, it has a different id (8086:2c40). So, |
| 322 | * the probing code needs to test for the other address in case of |
| 323 | * failure of this one |
| 324 | */ |
| 325 | { PCI_DESCR(0, 0, PCI_DEVICE_ID_INTEL_I7_NONCORE) }, |
| 326 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 327 | }; |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 328 | |
Mauro Carvalho Chehab | 1288c18 | 2010-08-10 18:57:01 -0300 | [diff] [blame] | 329 | static const struct pci_id_descr pci_dev_descr_lynnfield[] = { |
Mauro Carvalho Chehab | 52a2e4fc | 2009-10-14 11:21:58 -0300 | [diff] [blame] | 330 | { PCI_DESCR( 3, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_MCR) }, |
| 331 | { PCI_DESCR( 3, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_TAD) }, |
| 332 | { PCI_DESCR( 3, 4, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_TEST) }, |
| 333 | |
| 334 | { PCI_DESCR( 4, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_CTRL) }, |
| 335 | { PCI_DESCR( 4, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_ADDR) }, |
| 336 | { PCI_DESCR( 4, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_RANK) }, |
| 337 | { PCI_DESCR( 4, 3, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_TC) }, |
| 338 | |
Mauro Carvalho Chehab | 508fa17 | 2009-10-14 13:44:37 -0300 | [diff] [blame] | 339 | { PCI_DESCR( 5, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_CTRL) }, |
| 340 | { PCI_DESCR( 5, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_ADDR) }, |
| 341 | { PCI_DESCR( 5, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_RANK) }, |
| 342 | { PCI_DESCR( 5, 3, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_TC) }, |
Mauro Carvalho Chehab | 224e871 | 2011-03-17 17:02:59 -0300 | [diff] [blame] | 343 | |
| 344 | /* |
| 345 | * This is the PCI device has an alternate address on some |
| 346 | * processors like Core i7 860 |
| 347 | */ |
| 348 | { PCI_DESCR( 0, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE) }, |
Mauro Carvalho Chehab | 52a2e4fc | 2009-10-14 11:21:58 -0300 | [diff] [blame] | 349 | }; |
| 350 | |
Mauro Carvalho Chehab | 1288c18 | 2010-08-10 18:57:01 -0300 | [diff] [blame] | 351 | static const struct pci_id_descr pci_dev_descr_i7core_westmere[] = { |
Vernon Mauery | bd9e19c | 2010-05-18 19:02:50 -0300 | [diff] [blame] | 352 | /* Memory controller */ |
| 353 | { PCI_DESCR(3, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_MCR_REV2) }, |
| 354 | { PCI_DESCR(3, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_TAD_REV2) }, |
| 355 | /* Exists only for RDIMM */ |
| 356 | { PCI_DESCR(3, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_RAS_REV2), .optional = 1 }, |
| 357 | { PCI_DESCR(3, 4, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_TEST_REV2) }, |
| 358 | |
| 359 | /* Channel 0 */ |
| 360 | { PCI_DESCR(4, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_CTRL_REV2) }, |
| 361 | { PCI_DESCR(4, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_ADDR_REV2) }, |
| 362 | { PCI_DESCR(4, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_RANK_REV2) }, |
| 363 | { PCI_DESCR(4, 3, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_TC_REV2) }, |
| 364 | |
| 365 | /* Channel 1 */ |
| 366 | { PCI_DESCR(5, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_CTRL_REV2) }, |
| 367 | { PCI_DESCR(5, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_ADDR_REV2) }, |
| 368 | { PCI_DESCR(5, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_RANK_REV2) }, |
| 369 | { PCI_DESCR(5, 3, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_TC_REV2) }, |
| 370 | |
| 371 | /* Channel 2 */ |
| 372 | { PCI_DESCR(6, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH2_CTRL_REV2) }, |
| 373 | { PCI_DESCR(6, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH2_ADDR_REV2) }, |
| 374 | { PCI_DESCR(6, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH2_RANK_REV2) }, |
| 375 | { PCI_DESCR(6, 3, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH2_TC_REV2) }, |
Mauro Carvalho Chehab | 224e871 | 2011-03-17 17:02:59 -0300 | [diff] [blame] | 376 | |
| 377 | /* Generic Non-core registers */ |
| 378 | { PCI_DESCR(0, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE_REV2) }, |
| 379 | |
Vernon Mauery | bd9e19c | 2010-05-18 19:02:50 -0300 | [diff] [blame] | 380 | }; |
| 381 | |
Mauro Carvalho Chehab | 1288c18 | 2010-08-10 18:57:01 -0300 | [diff] [blame] | 382 | #define PCI_ID_TABLE_ENTRY(A) { .descr=A, .n_devs = ARRAY_SIZE(A) } |
| 383 | static const struct pci_id_table pci_dev_table[] = { |
Vernon Mauery | bd9e19c | 2010-05-18 19:02:50 -0300 | [diff] [blame] | 384 | PCI_ID_TABLE_ENTRY(pci_dev_descr_i7core_nehalem), |
| 385 | PCI_ID_TABLE_ENTRY(pci_dev_descr_lynnfield), |
| 386 | PCI_ID_TABLE_ENTRY(pci_dev_descr_i7core_westmere), |
Mauro Carvalho Chehab | 3c52cc5 | 2010-10-24 11:12:28 -0200 | [diff] [blame] | 387 | {0,} /* 0 terminated list. */ |
Vernon Mauery | bd9e19c | 2010-05-18 19:02:50 -0300 | [diff] [blame] | 388 | }; |
| 389 | |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 390 | /* |
| 391 | * pci_device_id table for which devices we are looking for |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 392 | */ |
| 393 | static const struct pci_device_id i7core_pci_tbl[] __devinitdata = { |
Mauro Carvalho Chehab | d1fd4fb | 2009-07-10 18:39:53 -0300 | [diff] [blame] | 394 | {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58_HUB_MGMT)}, |
Mauro Carvalho Chehab | f05da2f | 2009-10-14 13:31:06 -0300 | [diff] [blame] | 395 | {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNNFIELD_QPI_LINK0)}, |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 396 | {0,} /* 0 terminated list. */ |
| 397 | }; |
| 398 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 399 | /**************************************************************************** |
| 400 | Anciliary status routines |
| 401 | ****************************************************************************/ |
| 402 | |
| 403 | /* MC_CONTROL bits */ |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 404 | #define CH_ACTIVE(pvt, ch) ((pvt)->info.mc_control & (1 << (8 + ch))) |
| 405 | #define ECCx8(pvt) ((pvt)->info.mc_control & (1 << 1)) |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 406 | |
| 407 | /* MC_STATUS bits */ |
Keith Mannthey | 61053fd | 2009-09-02 23:46:59 -0300 | [diff] [blame] | 408 | #define ECC_ENABLED(pvt) ((pvt)->info.mc_status & (1 << 4)) |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 409 | #define CH_DISABLED(pvt, ch) ((pvt)->info.mc_status & (1 << ch)) |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 410 | |
| 411 | /* MC_MAX_DOD read functions */ |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 412 | static inline int numdimms(u32 dimms) |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 413 | { |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 414 | return (dimms & 0x3) + 1; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 415 | } |
| 416 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 417 | static inline int numrank(u32 rank) |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 418 | { |
| 419 | static int ranks[4] = { 1, 2, 4, -EINVAL }; |
| 420 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 421 | return ranks[rank & 0x3]; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 422 | } |
| 423 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 424 | static inline int numbank(u32 bank) |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 425 | { |
| 426 | static int banks[4] = { 4, 8, 16, -EINVAL }; |
| 427 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 428 | return banks[bank & 0x3]; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 429 | } |
| 430 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 431 | static inline int numrow(u32 row) |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 432 | { |
| 433 | static int rows[8] = { |
| 434 | 1 << 12, 1 << 13, 1 << 14, 1 << 15, |
| 435 | 1 << 16, -EINVAL, -EINVAL, -EINVAL, |
| 436 | }; |
| 437 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 438 | return rows[row & 0x7]; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 439 | } |
| 440 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 441 | static inline int numcol(u32 col) |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 442 | { |
| 443 | static int cols[8] = { |
| 444 | 1 << 10, 1 << 11, 1 << 12, -EINVAL, |
| 445 | }; |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 446 | return cols[col & 0x3]; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 447 | } |
| 448 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 449 | static struct i7core_dev *get_i7core_dev(u8 socket) |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 450 | { |
| 451 | struct i7core_dev *i7core_dev; |
| 452 | |
| 453 | list_for_each_entry(i7core_dev, &i7core_edac_list, list) { |
| 454 | if (i7core_dev->socket == socket) |
| 455 | return i7core_dev; |
| 456 | } |
| 457 | |
| 458 | return NULL; |
| 459 | } |
| 460 | |
Hidetoshi Seto | 848b2f7 | 2010-08-20 04:24:44 -0300 | [diff] [blame] | 461 | static struct i7core_dev *alloc_i7core_dev(u8 socket, |
| 462 | const struct pci_id_table *table) |
| 463 | { |
| 464 | struct i7core_dev *i7core_dev; |
| 465 | |
| 466 | i7core_dev = kzalloc(sizeof(*i7core_dev), GFP_KERNEL); |
| 467 | if (!i7core_dev) |
| 468 | return NULL; |
| 469 | |
| 470 | i7core_dev->pdev = kzalloc(sizeof(*i7core_dev->pdev) * table->n_devs, |
| 471 | GFP_KERNEL); |
| 472 | if (!i7core_dev->pdev) { |
| 473 | kfree(i7core_dev); |
| 474 | return NULL; |
| 475 | } |
| 476 | |
| 477 | i7core_dev->socket = socket; |
| 478 | i7core_dev->n_devs = table->n_devs; |
| 479 | list_add_tail(&i7core_dev->list, &i7core_edac_list); |
| 480 | |
| 481 | return i7core_dev; |
| 482 | } |
| 483 | |
Hidetoshi Seto | 2aa9be4 | 2010-08-20 04:25:00 -0300 | [diff] [blame] | 484 | static void free_i7core_dev(struct i7core_dev *i7core_dev) |
| 485 | { |
| 486 | list_del(&i7core_dev->list); |
| 487 | kfree(i7core_dev->pdev); |
| 488 | kfree(i7core_dev); |
| 489 | } |
| 490 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 491 | /**************************************************************************** |
| 492 | Memory check routines |
| 493 | ****************************************************************************/ |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 494 | static struct pci_dev *get_pdev_slot_func(u8 socket, unsigned slot, |
| 495 | unsigned func) |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 496 | { |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 497 | struct i7core_dev *i7core_dev = get_i7core_dev(socket); |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 498 | int i; |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 499 | |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 500 | if (!i7core_dev) |
| 501 | return NULL; |
| 502 | |
Mauro Carvalho Chehab | de06eee | 2009-10-14 08:02:40 -0300 | [diff] [blame] | 503 | for (i = 0; i < i7core_dev->n_devs; i++) { |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 504 | if (!i7core_dev->pdev[i]) |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 505 | continue; |
| 506 | |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 507 | if (PCI_SLOT(i7core_dev->pdev[i]->devfn) == slot && |
| 508 | PCI_FUNC(i7core_dev->pdev[i]->devfn) == func) { |
| 509 | return i7core_dev->pdev[i]; |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | |
Mauro Carvalho Chehab | eb94fc4 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 513 | return NULL; |
| 514 | } |
| 515 | |
Mauro Carvalho Chehab | ec6df24 | 2009-07-18 10:44:30 -0300 | [diff] [blame] | 516 | /** |
| 517 | * i7core_get_active_channels() - gets the number of channels and csrows |
| 518 | * @socket: Quick Path Interconnect socket |
| 519 | * @channels: Number of channels that will be returned |
| 520 | * @csrows: Number of csrows found |
| 521 | * |
| 522 | * Since EDAC core needs to know in advance the number of available channels |
| 523 | * and csrows, in order to allocate memory for csrows/channels, it is needed |
| 524 | * to run two similar steps. At the first step, implemented on this function, |
| 525 | * it checks the number of csrows/channels present at one socket. |
| 526 | * this is used in order to properly allocate the size of mci components. |
| 527 | * |
| 528 | * It should be noticed that none of the current available datasheets explain |
| 529 | * or even mention how csrows are seen by the memory controller. So, we need |
| 530 | * to add a fake description for csrows. |
| 531 | * So, this driver is attributing one DIMM memory for one csrow. |
| 532 | */ |
Mauro Carvalho Chehab | 1288c18 | 2010-08-10 18:57:01 -0300 | [diff] [blame] | 533 | static int i7core_get_active_channels(const u8 socket, unsigned *channels, |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 534 | unsigned *csrows) |
Mauro Carvalho Chehab | eb94fc4 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 535 | { |
| 536 | struct pci_dev *pdev = NULL; |
| 537 | int i, j; |
| 538 | u32 status, control; |
| 539 | |
| 540 | *channels = 0; |
| 541 | *csrows = 0; |
| 542 | |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 543 | pdev = get_pdev_slot_func(socket, 3, 0); |
Mauro Carvalho Chehab | b7c7615 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 544 | if (!pdev) { |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 545 | i7core_printk(KERN_ERR, "Couldn't find socket %d fn 3.0!!!\n", |
| 546 | socket); |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 547 | return -ENODEV; |
Mauro Carvalho Chehab | b7c7615 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 548 | } |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 549 | |
| 550 | /* Device 3 function 0 reads */ |
| 551 | pci_read_config_dword(pdev, MC_STATUS, &status); |
| 552 | pci_read_config_dword(pdev, MC_CONTROL, &control); |
| 553 | |
| 554 | for (i = 0; i < NUM_CHANS; i++) { |
Mauro Carvalho Chehab | eb94fc4 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 555 | u32 dimm_dod[3]; |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 556 | /* Check if the channel is active */ |
| 557 | if (!(control & (1 << (8 + i)))) |
| 558 | continue; |
| 559 | |
| 560 | /* Check if the channel is disabled */ |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 561 | if (status & (1 << i)) |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 562 | continue; |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 563 | |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 564 | pdev = get_pdev_slot_func(socket, i + 4, 1); |
Mauro Carvalho Chehab | eb94fc4 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 565 | if (!pdev) { |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 566 | i7core_printk(KERN_ERR, "Couldn't find socket %d " |
| 567 | "fn %d.%d!!!\n", |
| 568 | socket, i + 4, 1); |
Mauro Carvalho Chehab | eb94fc4 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 569 | return -ENODEV; |
| 570 | } |
| 571 | /* Devices 4-6 function 1 */ |
| 572 | pci_read_config_dword(pdev, |
| 573 | MC_DOD_CH_DIMM0, &dimm_dod[0]); |
| 574 | pci_read_config_dword(pdev, |
| 575 | MC_DOD_CH_DIMM1, &dimm_dod[1]); |
| 576 | pci_read_config_dword(pdev, |
| 577 | MC_DOD_CH_DIMM2, &dimm_dod[2]); |
| 578 | |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 579 | (*channels)++; |
Mauro Carvalho Chehab | eb94fc4 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 580 | |
| 581 | for (j = 0; j < 3; j++) { |
| 582 | if (!DIMM_PRESENT(dimm_dod[j])) |
| 583 | continue; |
| 584 | (*csrows)++; |
| 585 | } |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 586 | } |
| 587 | |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 588 | debugf0("Number of active channels on socket %d: %d\n", |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 589 | socket, *channels); |
Mauro Carvalho Chehab | 1c6fed8 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 590 | |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 591 | return 0; |
| 592 | } |
| 593 | |
Hidetoshi Seto | 2e5185f | 2010-08-20 04:32:56 -0300 | [diff] [blame] | 594 | static int get_dimm_config(const struct mem_ctl_info *mci) |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 595 | { |
| 596 | struct i7core_pvt *pvt = mci->pvt_info; |
Mauro Carvalho Chehab | 1c6fed8 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 597 | struct csrow_info *csr; |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 598 | struct pci_dev *pdev; |
Mauro Carvalho Chehab | ba6c5c6 | 2009-07-15 09:02:32 -0300 | [diff] [blame] | 599 | int i, j; |
Hidetoshi Seto | 2e5185f | 2010-08-20 04:32:56 -0300 | [diff] [blame] | 600 | int csrow = 0; |
Mauro Carvalho Chehab | 5566cb7 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 601 | unsigned long last_page = 0; |
Mauro Carvalho Chehab | 1c6fed8 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 602 | enum edac_type mode; |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 603 | enum mem_type mtype; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 604 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 605 | /* Get data from the MC register, function 0 */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 606 | pdev = pvt->pci_mcr[0]; |
Mauro Carvalho Chehab | 7dd6953 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 607 | if (!pdev) |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 608 | return -ENODEV; |
| 609 | |
Mauro Carvalho Chehab | f122a89 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 610 | /* Device 3 function 0 reads */ |
Mauro Carvalho Chehab | 7dd6953 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 611 | pci_read_config_dword(pdev, MC_CONTROL, &pvt->info.mc_control); |
| 612 | pci_read_config_dword(pdev, MC_STATUS, &pvt->info.mc_status); |
| 613 | pci_read_config_dword(pdev, MC_MAX_DOD, &pvt->info.max_dod); |
| 614 | pci_read_config_dword(pdev, MC_CHANNEL_MAPPER, &pvt->info.ch_map); |
Mauro Carvalho Chehab | f122a89 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 615 | |
Mauro Carvalho Chehab | 17cb7b0 | 2009-07-20 18:48:18 -0300 | [diff] [blame] | 616 | debugf0("QPI %d control=0x%08x status=0x%08x dod=0x%08x map=0x%08x\n", |
Mauro Carvalho Chehab | 4af9188 | 2009-09-24 09:58:26 -0300 | [diff] [blame] | 617 | pvt->i7core_dev->socket, pvt->info.mc_control, pvt->info.mc_status, |
Mauro Carvalho Chehab | f122a89 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 618 | pvt->info.max_dod, pvt->info.ch_map); |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 619 | |
Mauro Carvalho Chehab | 1c6fed8 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 620 | if (ECC_ENABLED(pvt)) { |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 621 | debugf0("ECC enabled with x%d SDCC\n", ECCx8(pvt) ? 8 : 4); |
Mauro Carvalho Chehab | 1c6fed8 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 622 | if (ECCx8(pvt)) |
| 623 | mode = EDAC_S8ECD8ED; |
| 624 | else |
| 625 | mode = EDAC_S4ECD4ED; |
| 626 | } else { |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 627 | debugf0("ECC disabled\n"); |
Mauro Carvalho Chehab | 1c6fed8 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 628 | mode = EDAC_NONE; |
| 629 | } |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 630 | |
| 631 | /* FIXME: need to handle the error codes */ |
Mauro Carvalho Chehab | 17cb7b0 | 2009-07-20 18:48:18 -0300 | [diff] [blame] | 632 | debugf0("DOD Max limits: DIMMS: %d, %d-ranked, %d-banked " |
| 633 | "x%x x 0x%x\n", |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 634 | numdimms(pvt->info.max_dod), |
| 635 | numrank(pvt->info.max_dod >> 2), |
Mauro Carvalho Chehab | 276b824 | 2009-07-22 21:45:50 -0300 | [diff] [blame] | 636 | numbank(pvt->info.max_dod >> 4), |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 637 | numrow(pvt->info.max_dod >> 6), |
| 638 | numcol(pvt->info.max_dod >> 9)); |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 639 | |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 640 | for (i = 0; i < NUM_CHANS; i++) { |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 641 | u32 data, dimm_dod[3], value[8]; |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 642 | |
Mauro Carvalho Chehab | 52a2e4fc | 2009-10-14 11:21:58 -0300 | [diff] [blame] | 643 | if (!pvt->pci_ch[i][0]) |
| 644 | continue; |
| 645 | |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 646 | if (!CH_ACTIVE(pvt, i)) { |
| 647 | debugf0("Channel %i is not active\n", i); |
| 648 | continue; |
| 649 | } |
| 650 | if (CH_DISABLED(pvt, i)) { |
| 651 | debugf0("Channel %i is disabled\n", i); |
| 652 | continue; |
| 653 | } |
| 654 | |
Mauro Carvalho Chehab | f122a89 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 655 | /* Devices 4-6 function 0 */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 656 | pci_read_config_dword(pvt->pci_ch[i][0], |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 657 | MC_CHANNEL_DIMM_INIT_PARAMS, &data); |
| 658 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 659 | pvt->channel[i].ranks = (data & QUAD_RANK_PRESENT) ? |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 660 | 4 : 2; |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 661 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 662 | if (data & REGISTERED_DIMM) |
| 663 | mtype = MEM_RDDR3; |
Mauro Carvalho Chehab | 14d2c08 | 2009-09-02 23:52:36 -0300 | [diff] [blame] | 664 | else |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 665 | mtype = MEM_DDR3; |
| 666 | #if 0 |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 667 | if (data & THREE_DIMMS_PRESENT) |
| 668 | pvt->channel[i].dimms = 3; |
| 669 | else if (data & SINGLE_QUAD_RANK_PRESENT) |
| 670 | pvt->channel[i].dimms = 1; |
| 671 | else |
| 672 | pvt->channel[i].dimms = 2; |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 673 | #endif |
| 674 | |
| 675 | /* Devices 4-6 function 1 */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 676 | pci_read_config_dword(pvt->pci_ch[i][1], |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 677 | MC_DOD_CH_DIMM0, &dimm_dod[0]); |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 678 | pci_read_config_dword(pvt->pci_ch[i][1], |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 679 | MC_DOD_CH_DIMM1, &dimm_dod[1]); |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 680 | pci_read_config_dword(pvt->pci_ch[i][1], |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 681 | MC_DOD_CH_DIMM2, &dimm_dod[2]); |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 682 | |
Mauro Carvalho Chehab | 1c6fed8 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 683 | debugf0("Ch%d phy rd%d, wr%d (0x%08x): " |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 684 | "%d ranks, %cDIMMs\n", |
Mauro Carvalho Chehab | 1c6fed8 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 685 | i, |
| 686 | RDLCH(pvt->info.ch_map, i), WRLCH(pvt->info.ch_map, i), |
| 687 | data, |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 688 | pvt->channel[i].ranks, |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 689 | (data & REGISTERED_DIMM) ? 'R' : 'U'); |
Mauro Carvalho Chehab | 7dd6953 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 690 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 691 | for (j = 0; j < 3; j++) { |
| 692 | u32 banks, ranks, rows, cols; |
Mauro Carvalho Chehab | 5566cb7 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 693 | u32 size, npages; |
Mauro Carvalho Chehab | 1c6fed8 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 694 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 695 | if (!DIMM_PRESENT(dimm_dod[j])) |
| 696 | continue; |
Mauro Carvalho Chehab | 1c6fed8 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 697 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 698 | banks = numbank(MC_DOD_NUMBANK(dimm_dod[j])); |
| 699 | ranks = numrank(MC_DOD_NUMRANK(dimm_dod[j])); |
| 700 | rows = numrow(MC_DOD_NUMROW(dimm_dod[j])); |
| 701 | cols = numcol(MC_DOD_NUMCOL(dimm_dod[j])); |
Mauro Carvalho Chehab | 1c6fed8 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 702 | |
Mauro Carvalho Chehab | 5566cb7 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 703 | /* DDR3 has 8 I/O banks */ |
| 704 | size = (rows * cols * banks * ranks) >> (20 - 3); |
| 705 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 706 | pvt->channel[i].dimms++; |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 707 | |
Mauro Carvalho Chehab | 17cb7b0 | 2009-07-20 18:48:18 -0300 | [diff] [blame] | 708 | debugf0("\tdimm %d %d Mb offset: %x, " |
| 709 | "bank: %d, rank: %d, row: %#x, col: %#x\n", |
| 710 | j, size, |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 711 | RANKOFFSET(dimm_dod[j]), |
| 712 | banks, ranks, rows, cols); |
| 713 | |
Mauro Carvalho Chehab | e914460 | 2010-08-10 20:26:35 -0300 | [diff] [blame] | 714 | npages = MiB_TO_PAGES(size); |
Mauro Carvalho Chehab | 5566cb7 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 715 | |
Hidetoshi Seto | 2e5185f | 2010-08-20 04:32:56 -0300 | [diff] [blame] | 716 | csr = &mci->csrows[csrow]; |
Mauro Carvalho Chehab | 5566cb7 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 717 | csr->first_page = last_page + 1; |
| 718 | last_page += npages; |
| 719 | csr->last_page = last_page; |
| 720 | csr->nr_pages = npages; |
| 721 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 722 | csr->page_mask = 0; |
Mauro Carvalho Chehab | eb94fc4 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 723 | csr->grain = 8; |
Hidetoshi Seto | 2e5185f | 2010-08-20 04:32:56 -0300 | [diff] [blame] | 724 | csr->csrow_idx = csrow; |
Mauro Carvalho Chehab | eb94fc4 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 725 | csr->nr_channels = 1; |
| 726 | |
| 727 | csr->channels[0].chan_idx = i; |
| 728 | csr->channels[0].ce_count = 0; |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 729 | |
Hidetoshi Seto | 2e5185f | 2010-08-20 04:32:56 -0300 | [diff] [blame] | 730 | pvt->csrow_map[i][j] = csrow; |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 731 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 732 | switch (banks) { |
| 733 | case 4: |
| 734 | csr->dtype = DEV_X4; |
| 735 | break; |
| 736 | case 8: |
| 737 | csr->dtype = DEV_X8; |
| 738 | break; |
| 739 | case 16: |
| 740 | csr->dtype = DEV_X16; |
| 741 | break; |
| 742 | default: |
| 743 | csr->dtype = DEV_UNKNOWN; |
| 744 | } |
| 745 | |
| 746 | csr->edac_mode = mode; |
| 747 | csr->mtype = mtype; |
| 748 | |
Hidetoshi Seto | 2e5185f | 2010-08-20 04:32:56 -0300 | [diff] [blame] | 749 | csrow++; |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | pci_read_config_dword(pdev, MC_SAG_CH_0, &value[0]); |
| 753 | pci_read_config_dword(pdev, MC_SAG_CH_1, &value[1]); |
| 754 | pci_read_config_dword(pdev, MC_SAG_CH_2, &value[2]); |
| 755 | pci_read_config_dword(pdev, MC_SAG_CH_3, &value[3]); |
| 756 | pci_read_config_dword(pdev, MC_SAG_CH_4, &value[4]); |
| 757 | pci_read_config_dword(pdev, MC_SAG_CH_5, &value[5]); |
| 758 | pci_read_config_dword(pdev, MC_SAG_CH_6, &value[6]); |
| 759 | pci_read_config_dword(pdev, MC_SAG_CH_7, &value[7]); |
Mauro Carvalho Chehab | 17cb7b0 | 2009-07-20 18:48:18 -0300 | [diff] [blame] | 760 | debugf1("\t[%i] DIVBY3\tREMOVED\tOFFSET\n", i); |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 761 | for (j = 0; j < 8; j++) |
Mauro Carvalho Chehab | 17cb7b0 | 2009-07-20 18:48:18 -0300 | [diff] [blame] | 762 | debugf1("\t\t%#x\t%#x\t%#x\n", |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 763 | (value[j] >> 27) & 0x1, |
| 764 | (value[j] >> 24) & 0x7, |
David Sterba | 80b8ce8 | 2010-12-27 15:39:12 +0000 | [diff] [blame] | 765 | (value[j] & ((1 << 24) - 1))); |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 766 | } |
| 767 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 768 | return 0; |
| 769 | } |
| 770 | |
| 771 | /**************************************************************************** |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 772 | Error insertion routines |
| 773 | ****************************************************************************/ |
| 774 | |
| 775 | /* The i7core has independent error injection features per channel. |
| 776 | However, to have a simpler code, we don't allow enabling error injection |
| 777 | on more than one channel. |
| 778 | Also, since a change at an inject parameter will be applied only at enable, |
| 779 | we're disabling error injection on all write calls to the sysfs nodes that |
| 780 | controls the error code injection. |
| 781 | */ |
Mauro Carvalho Chehab | 1288c18 | 2010-08-10 18:57:01 -0300 | [diff] [blame] | 782 | static int disable_inject(const struct mem_ctl_info *mci) |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 783 | { |
| 784 | struct i7core_pvt *pvt = mci->pvt_info; |
| 785 | |
| 786 | pvt->inject.enable = 0; |
| 787 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 788 | if (!pvt->pci_ch[pvt->inject.channel][0]) |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 789 | return -ENODEV; |
| 790 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 791 | pci_write_config_dword(pvt->pci_ch[pvt->inject.channel][0], |
Mauro Carvalho Chehab | 4157d9f | 2009-08-05 20:27:15 -0300 | [diff] [blame] | 792 | MC_CHANNEL_ERROR_INJECT, 0); |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 793 | |
| 794 | return 0; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | /* |
| 798 | * i7core inject inject.section |
| 799 | * |
| 800 | * accept and store error injection inject.section value |
| 801 | * bit 0 - refers to the lower 32-byte half cacheline |
| 802 | * bit 1 - refers to the upper 32-byte half cacheline |
| 803 | */ |
| 804 | static ssize_t i7core_inject_section_store(struct mem_ctl_info *mci, |
| 805 | const char *data, size_t count) |
| 806 | { |
| 807 | struct i7core_pvt *pvt = mci->pvt_info; |
| 808 | unsigned long value; |
| 809 | int rc; |
| 810 | |
| 811 | if (pvt->inject.enable) |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 812 | disable_inject(mci); |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 813 | |
| 814 | rc = strict_strtoul(data, 10, &value); |
| 815 | if ((rc < 0) || (value > 3)) |
Mauro Carvalho Chehab | 2068def | 2009-08-05 19:28:27 -0300 | [diff] [blame] | 816 | return -EIO; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 817 | |
| 818 | pvt->inject.section = (u32) value; |
| 819 | return count; |
| 820 | } |
| 821 | |
| 822 | static ssize_t i7core_inject_section_show(struct mem_ctl_info *mci, |
| 823 | char *data) |
| 824 | { |
| 825 | struct i7core_pvt *pvt = mci->pvt_info; |
| 826 | return sprintf(data, "0x%08x\n", pvt->inject.section); |
| 827 | } |
| 828 | |
| 829 | /* |
| 830 | * i7core inject.type |
| 831 | * |
| 832 | * accept and store error injection inject.section value |
| 833 | * bit 0 - repeat enable - Enable error repetition |
| 834 | * bit 1 - inject ECC error |
| 835 | * bit 2 - inject parity error |
| 836 | */ |
| 837 | static ssize_t i7core_inject_type_store(struct mem_ctl_info *mci, |
| 838 | const char *data, size_t count) |
| 839 | { |
| 840 | struct i7core_pvt *pvt = mci->pvt_info; |
| 841 | unsigned long value; |
| 842 | int rc; |
| 843 | |
| 844 | if (pvt->inject.enable) |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 845 | disable_inject(mci); |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 846 | |
| 847 | rc = strict_strtoul(data, 10, &value); |
| 848 | if ((rc < 0) || (value > 7)) |
Mauro Carvalho Chehab | 2068def | 2009-08-05 19:28:27 -0300 | [diff] [blame] | 849 | return -EIO; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 850 | |
| 851 | pvt->inject.type = (u32) value; |
| 852 | return count; |
| 853 | } |
| 854 | |
| 855 | static ssize_t i7core_inject_type_show(struct mem_ctl_info *mci, |
| 856 | char *data) |
| 857 | { |
| 858 | struct i7core_pvt *pvt = mci->pvt_info; |
| 859 | return sprintf(data, "0x%08x\n", pvt->inject.type); |
| 860 | } |
| 861 | |
| 862 | /* |
| 863 | * i7core_inject_inject.eccmask_store |
| 864 | * |
| 865 | * The type of error (UE/CE) will depend on the inject.eccmask value: |
| 866 | * Any bits set to a 1 will flip the corresponding ECC bit |
| 867 | * Correctable errors can be injected by flipping 1 bit or the bits within |
| 868 | * a symbol pair (2 consecutive aligned 8-bit pairs - i.e. 7:0 and 15:8 or |
| 869 | * 23:16 and 31:24). Flipping bits in two symbol pairs will cause an |
| 870 | * uncorrectable error to be injected. |
| 871 | */ |
| 872 | static ssize_t i7core_inject_eccmask_store(struct mem_ctl_info *mci, |
| 873 | const char *data, size_t count) |
| 874 | { |
| 875 | struct i7core_pvt *pvt = mci->pvt_info; |
| 876 | unsigned long value; |
| 877 | int rc; |
| 878 | |
| 879 | if (pvt->inject.enable) |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 880 | disable_inject(mci); |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 881 | |
| 882 | rc = strict_strtoul(data, 10, &value); |
| 883 | if (rc < 0) |
Mauro Carvalho Chehab | 2068def | 2009-08-05 19:28:27 -0300 | [diff] [blame] | 884 | return -EIO; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 885 | |
| 886 | pvt->inject.eccmask = (u32) value; |
| 887 | return count; |
| 888 | } |
| 889 | |
| 890 | static ssize_t i7core_inject_eccmask_show(struct mem_ctl_info *mci, |
| 891 | char *data) |
| 892 | { |
| 893 | struct i7core_pvt *pvt = mci->pvt_info; |
| 894 | return sprintf(data, "0x%08x\n", pvt->inject.eccmask); |
| 895 | } |
| 896 | |
| 897 | /* |
| 898 | * i7core_addrmatch |
| 899 | * |
| 900 | * The type of error (UE/CE) will depend on the inject.eccmask value: |
| 901 | * Any bits set to a 1 will flip the corresponding ECC bit |
| 902 | * Correctable errors can be injected by flipping 1 bit or the bits within |
| 903 | * a symbol pair (2 consecutive aligned 8-bit pairs - i.e. 7:0 and 15:8 or |
| 904 | * 23:16 and 31:24). Flipping bits in two symbol pairs will cause an |
| 905 | * uncorrectable error to be injected. |
| 906 | */ |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 907 | |
Mauro Carvalho Chehab | a5538e5 | 2009-09-23 18:56:47 -0300 | [diff] [blame] | 908 | #define DECLARE_ADDR_MATCH(param, limit) \ |
| 909 | static ssize_t i7core_inject_store_##param( \ |
| 910 | struct mem_ctl_info *mci, \ |
| 911 | const char *data, size_t count) \ |
| 912 | { \ |
Mauro Carvalho Chehab | cc301b3 | 2009-09-24 16:23:42 -0300 | [diff] [blame] | 913 | struct i7core_pvt *pvt; \ |
Mauro Carvalho Chehab | a5538e5 | 2009-09-23 18:56:47 -0300 | [diff] [blame] | 914 | long value; \ |
| 915 | int rc; \ |
| 916 | \ |
Mauro Carvalho Chehab | cc301b3 | 2009-09-24 16:23:42 -0300 | [diff] [blame] | 917 | debugf1("%s()\n", __func__); \ |
| 918 | pvt = mci->pvt_info; \ |
| 919 | \ |
Mauro Carvalho Chehab | a5538e5 | 2009-09-23 18:56:47 -0300 | [diff] [blame] | 920 | if (pvt->inject.enable) \ |
| 921 | disable_inject(mci); \ |
| 922 | \ |
Mauro Carvalho Chehab | 4f87fad | 2009-10-04 11:54:56 -0300 | [diff] [blame] | 923 | if (!strcasecmp(data, "any") || !strcasecmp(data, "any\n"))\ |
Mauro Carvalho Chehab | a5538e5 | 2009-09-23 18:56:47 -0300 | [diff] [blame] | 924 | value = -1; \ |
| 925 | else { \ |
| 926 | rc = strict_strtoul(data, 10, &value); \ |
| 927 | if ((rc < 0) || (value >= limit)) \ |
| 928 | return -EIO; \ |
| 929 | } \ |
| 930 | \ |
| 931 | pvt->inject.param = value; \ |
| 932 | \ |
| 933 | return count; \ |
| 934 | } \ |
| 935 | \ |
| 936 | static ssize_t i7core_inject_show_##param( \ |
| 937 | struct mem_ctl_info *mci, \ |
| 938 | char *data) \ |
| 939 | { \ |
Mauro Carvalho Chehab | cc301b3 | 2009-09-24 16:23:42 -0300 | [diff] [blame] | 940 | struct i7core_pvt *pvt; \ |
| 941 | \ |
| 942 | pvt = mci->pvt_info; \ |
| 943 | debugf1("%s() pvt=%p\n", __func__, pvt); \ |
Mauro Carvalho Chehab | a5538e5 | 2009-09-23 18:56:47 -0300 | [diff] [blame] | 944 | if (pvt->inject.param < 0) \ |
| 945 | return sprintf(data, "any\n"); \ |
| 946 | else \ |
| 947 | return sprintf(data, "%d\n", pvt->inject.param);\ |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 948 | } |
| 949 | |
Mauro Carvalho Chehab | a5538e5 | 2009-09-23 18:56:47 -0300 | [diff] [blame] | 950 | #define ATTR_ADDR_MATCH(param) \ |
| 951 | { \ |
| 952 | .attr = { \ |
| 953 | .name = #param, \ |
| 954 | .mode = (S_IRUGO | S_IWUSR) \ |
| 955 | }, \ |
| 956 | .show = i7core_inject_show_##param, \ |
| 957 | .store = i7core_inject_store_##param, \ |
| 958 | } |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 959 | |
Mauro Carvalho Chehab | a5538e5 | 2009-09-23 18:56:47 -0300 | [diff] [blame] | 960 | DECLARE_ADDR_MATCH(channel, 3); |
| 961 | DECLARE_ADDR_MATCH(dimm, 3); |
| 962 | DECLARE_ADDR_MATCH(rank, 4); |
| 963 | DECLARE_ADDR_MATCH(bank, 32); |
| 964 | DECLARE_ADDR_MATCH(page, 0x10000); |
| 965 | DECLARE_ADDR_MATCH(col, 0x4000); |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 966 | |
Mauro Carvalho Chehab | 1288c18 | 2010-08-10 18:57:01 -0300 | [diff] [blame] | 967 | static int write_and_test(struct pci_dev *dev, const int where, const u32 val) |
Mauro Carvalho Chehab | 276b824 | 2009-07-22 21:45:50 -0300 | [diff] [blame] | 968 | { |
| 969 | u32 read; |
| 970 | int count; |
| 971 | |
Mauro Carvalho Chehab | 4157d9f | 2009-08-05 20:27:15 -0300 | [diff] [blame] | 972 | debugf0("setting pci %02x:%02x.%x reg=%02x value=%08x\n", |
| 973 | dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn), |
| 974 | where, val); |
| 975 | |
Mauro Carvalho Chehab | 276b824 | 2009-07-22 21:45:50 -0300 | [diff] [blame] | 976 | for (count = 0; count < 10; count++) { |
| 977 | if (count) |
Mauro Carvalho Chehab | b990538 | 2009-08-05 21:36:35 -0300 | [diff] [blame] | 978 | msleep(100); |
Mauro Carvalho Chehab | 276b824 | 2009-07-22 21:45:50 -0300 | [diff] [blame] | 979 | pci_write_config_dword(dev, where, val); |
| 980 | pci_read_config_dword(dev, where, &read); |
| 981 | |
| 982 | if (read == val) |
| 983 | return 0; |
| 984 | } |
| 985 | |
Mauro Carvalho Chehab | 4157d9f | 2009-08-05 20:27:15 -0300 | [diff] [blame] | 986 | i7core_printk(KERN_ERR, "Error during set pci %02x:%02x.%x reg=%02x " |
| 987 | "write=%08x. Read=%08x\n", |
| 988 | dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn), |
| 989 | where, val, read); |
Mauro Carvalho Chehab | 276b824 | 2009-07-22 21:45:50 -0300 | [diff] [blame] | 990 | |
| 991 | return -EINVAL; |
| 992 | } |
| 993 | |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 994 | /* |
| 995 | * This routine prepares the Memory Controller for error injection. |
| 996 | * The error will be injected when some process tries to write to the |
| 997 | * memory that matches the given criteria. |
| 998 | * The criteria can be set in terms of a mask where dimm, rank, bank, page |
| 999 | * and col can be specified. |
| 1000 | * A -1 value for any of the mask items will make the MCU to ignore |
| 1001 | * that matching criteria for error injection. |
| 1002 | * |
| 1003 | * It should be noticed that the error will only happen after a write operation |
| 1004 | * on a memory that matches the condition. if REPEAT_EN is not enabled at |
| 1005 | * inject mask, then it will produce just one error. Otherwise, it will repeat |
| 1006 | * until the injectmask would be cleaned. |
| 1007 | * |
| 1008 | * FIXME: This routine assumes that MAXNUMDIMMS value of MC_MAX_DOD |
| 1009 | * is reliable enough to check if the MC is using the |
| 1010 | * three channels. However, this is not clear at the datasheet. |
| 1011 | */ |
| 1012 | static ssize_t i7core_inject_enable_store(struct mem_ctl_info *mci, |
| 1013 | const char *data, size_t count) |
| 1014 | { |
| 1015 | struct i7core_pvt *pvt = mci->pvt_info; |
| 1016 | u32 injectmask; |
| 1017 | u64 mask = 0; |
| 1018 | int rc; |
| 1019 | long enable; |
| 1020 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1021 | if (!pvt->pci_ch[pvt->inject.channel][0]) |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1022 | return 0; |
| 1023 | |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1024 | rc = strict_strtoul(data, 10, &enable); |
| 1025 | if ((rc < 0)) |
| 1026 | return 0; |
| 1027 | |
| 1028 | if (enable) { |
| 1029 | pvt->inject.enable = 1; |
| 1030 | } else { |
| 1031 | disable_inject(mci); |
| 1032 | return count; |
| 1033 | } |
| 1034 | |
| 1035 | /* Sets pvt->inject.dimm mask */ |
| 1036 | if (pvt->inject.dimm < 0) |
Alan Cox | 486dd09 | 2009-11-08 01:34:27 -0200 | [diff] [blame] | 1037 | mask |= 1LL << 41; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1038 | else { |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1039 | if (pvt->channel[pvt->inject.channel].dimms > 2) |
Alan Cox | 486dd09 | 2009-11-08 01:34:27 -0200 | [diff] [blame] | 1040 | mask |= (pvt->inject.dimm & 0x3LL) << 35; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1041 | else |
Alan Cox | 486dd09 | 2009-11-08 01:34:27 -0200 | [diff] [blame] | 1042 | mask |= (pvt->inject.dimm & 0x1LL) << 36; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | /* Sets pvt->inject.rank mask */ |
| 1046 | if (pvt->inject.rank < 0) |
Alan Cox | 486dd09 | 2009-11-08 01:34:27 -0200 | [diff] [blame] | 1047 | mask |= 1LL << 40; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1048 | else { |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1049 | if (pvt->channel[pvt->inject.channel].dimms > 2) |
Alan Cox | 486dd09 | 2009-11-08 01:34:27 -0200 | [diff] [blame] | 1050 | mask |= (pvt->inject.rank & 0x1LL) << 34; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1051 | else |
Alan Cox | 486dd09 | 2009-11-08 01:34:27 -0200 | [diff] [blame] | 1052 | mask |= (pvt->inject.rank & 0x3LL) << 34; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | /* Sets pvt->inject.bank mask */ |
| 1056 | if (pvt->inject.bank < 0) |
Alan Cox | 486dd09 | 2009-11-08 01:34:27 -0200 | [diff] [blame] | 1057 | mask |= 1LL << 39; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1058 | else |
Alan Cox | 486dd09 | 2009-11-08 01:34:27 -0200 | [diff] [blame] | 1059 | mask |= (pvt->inject.bank & 0x15LL) << 30; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1060 | |
| 1061 | /* Sets pvt->inject.page mask */ |
| 1062 | if (pvt->inject.page < 0) |
Alan Cox | 486dd09 | 2009-11-08 01:34:27 -0200 | [diff] [blame] | 1063 | mask |= 1LL << 38; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1064 | else |
Alan Cox | 486dd09 | 2009-11-08 01:34:27 -0200 | [diff] [blame] | 1065 | mask |= (pvt->inject.page & 0xffff) << 14; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1066 | |
| 1067 | /* Sets pvt->inject.column mask */ |
| 1068 | if (pvt->inject.col < 0) |
Alan Cox | 486dd09 | 2009-11-08 01:34:27 -0200 | [diff] [blame] | 1069 | mask |= 1LL << 37; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1070 | else |
Alan Cox | 486dd09 | 2009-11-08 01:34:27 -0200 | [diff] [blame] | 1071 | mask |= (pvt->inject.col & 0x3fff); |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1072 | |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1073 | /* |
| 1074 | * bit 0: REPEAT_EN |
| 1075 | * bits 1-2: MASK_HALF_CACHELINE |
| 1076 | * bit 3: INJECT_ECC |
| 1077 | * bit 4: INJECT_ADDR_PARITY |
| 1078 | */ |
| 1079 | |
Mauro Carvalho Chehab | 7b029d0 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1080 | injectmask = (pvt->inject.type & 1) | |
| 1081 | (pvt->inject.section & 0x3) << 1 | |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1082 | (pvt->inject.type & 0x6) << (3 - 1); |
| 1083 | |
Mauro Carvalho Chehab | 276b824 | 2009-07-22 21:45:50 -0300 | [diff] [blame] | 1084 | /* Unlock writes to registers - this register is write only */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1085 | pci_write_config_dword(pvt->pci_noncore, |
Mauro Carvalho Chehab | 276b824 | 2009-07-22 21:45:50 -0300 | [diff] [blame] | 1086 | MC_CFG_CONTROL, 0x2); |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1087 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1088 | write_and_test(pvt->pci_ch[pvt->inject.channel][0], |
Mauro Carvalho Chehab | 276b824 | 2009-07-22 21:45:50 -0300 | [diff] [blame] | 1089 | MC_CHANNEL_ADDR_MATCH, mask); |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1090 | write_and_test(pvt->pci_ch[pvt->inject.channel][0], |
Mauro Carvalho Chehab | 276b824 | 2009-07-22 21:45:50 -0300 | [diff] [blame] | 1091 | MC_CHANNEL_ADDR_MATCH + 4, mask >> 32L); |
| 1092 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1093 | write_and_test(pvt->pci_ch[pvt->inject.channel][0], |
Mauro Carvalho Chehab | 276b824 | 2009-07-22 21:45:50 -0300 | [diff] [blame] | 1094 | MC_CHANNEL_ERROR_MASK, pvt->inject.eccmask); |
| 1095 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1096 | write_and_test(pvt->pci_ch[pvt->inject.channel][0], |
Mauro Carvalho Chehab | 4157d9f | 2009-08-05 20:27:15 -0300 | [diff] [blame] | 1097 | MC_CHANNEL_ERROR_INJECT, injectmask); |
Mauro Carvalho Chehab | 276b824 | 2009-07-22 21:45:50 -0300 | [diff] [blame] | 1098 | |
| 1099 | /* |
| 1100 | * This is something undocumented, based on my tests |
| 1101 | * Without writing 8 to this register, errors aren't injected. Not sure |
| 1102 | * why. |
| 1103 | */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1104 | pci_write_config_dword(pvt->pci_noncore, |
Mauro Carvalho Chehab | 276b824 | 2009-07-22 21:45:50 -0300 | [diff] [blame] | 1105 | MC_CFG_CONTROL, 8); |
| 1106 | |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 1107 | debugf0("Error inject addr match 0x%016llx, ecc 0x%08x," |
| 1108 | " inject 0x%08x\n", |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1109 | mask, pvt->inject.eccmask, injectmask); |
| 1110 | |
Mauro Carvalho Chehab | 7b029d0 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1111 | |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1112 | return count; |
| 1113 | } |
| 1114 | |
| 1115 | static ssize_t i7core_inject_enable_show(struct mem_ctl_info *mci, |
| 1116 | char *data) |
| 1117 | { |
| 1118 | struct i7core_pvt *pvt = mci->pvt_info; |
Mauro Carvalho Chehab | 7b029d0 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1119 | u32 injectmask; |
| 1120 | |
Mauro Carvalho Chehab | 52a2e4fc | 2009-10-14 11:21:58 -0300 | [diff] [blame] | 1121 | if (!pvt->pci_ch[pvt->inject.channel][0]) |
| 1122 | return 0; |
| 1123 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1124 | pci_read_config_dword(pvt->pci_ch[pvt->inject.channel][0], |
Mauro Carvalho Chehab | 4157d9f | 2009-08-05 20:27:15 -0300 | [diff] [blame] | 1125 | MC_CHANNEL_ERROR_INJECT, &injectmask); |
Mauro Carvalho Chehab | 7b029d0 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1126 | |
| 1127 | debugf0("Inject error read: 0x%018x\n", injectmask); |
| 1128 | |
| 1129 | if (injectmask & 0x0c) |
| 1130 | pvt->inject.enable = 1; |
| 1131 | |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1132 | return sprintf(data, "%d\n", pvt->inject.enable); |
| 1133 | } |
| 1134 | |
Mauro Carvalho Chehab | f338d73 | 2009-09-24 17:25:43 -0300 | [diff] [blame] | 1135 | #define DECLARE_COUNTER(param) \ |
| 1136 | static ssize_t i7core_show_counter_##param( \ |
| 1137 | struct mem_ctl_info *mci, \ |
| 1138 | char *data) \ |
| 1139 | { \ |
| 1140 | struct i7core_pvt *pvt = mci->pvt_info; \ |
| 1141 | \ |
| 1142 | debugf1("%s() \n", __func__); \ |
| 1143 | if (!pvt->ce_count_available || (pvt->is_registered)) \ |
| 1144 | return sprintf(data, "data unavailable\n"); \ |
| 1145 | return sprintf(data, "%lu\n", \ |
| 1146 | pvt->udimm_ce_count[param]); \ |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1147 | } |
| 1148 | |
Mauro Carvalho Chehab | f338d73 | 2009-09-24 17:25:43 -0300 | [diff] [blame] | 1149 | #define ATTR_COUNTER(param) \ |
| 1150 | { \ |
| 1151 | .attr = { \ |
| 1152 | .name = __stringify(udimm##param), \ |
| 1153 | .mode = (S_IRUGO | S_IWUSR) \ |
| 1154 | }, \ |
| 1155 | .show = i7core_show_counter_##param \ |
| 1156 | } |
| 1157 | |
| 1158 | DECLARE_COUNTER(0); |
| 1159 | DECLARE_COUNTER(1); |
| 1160 | DECLARE_COUNTER(2); |
| 1161 | |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1162 | /* |
| 1163 | * Sysfs struct |
| 1164 | */ |
Mauro Carvalho Chehab | a5538e5 | 2009-09-23 18:56:47 -0300 | [diff] [blame] | 1165 | |
Mauro Carvalho Chehab | 1288c18 | 2010-08-10 18:57:01 -0300 | [diff] [blame] | 1166 | static const struct mcidev_sysfs_attribute i7core_addrmatch_attrs[] = { |
Mauro Carvalho Chehab | a5538e5 | 2009-09-23 18:56:47 -0300 | [diff] [blame] | 1167 | ATTR_ADDR_MATCH(channel), |
| 1168 | ATTR_ADDR_MATCH(dimm), |
| 1169 | ATTR_ADDR_MATCH(rank), |
| 1170 | ATTR_ADDR_MATCH(bank), |
| 1171 | ATTR_ADDR_MATCH(page), |
| 1172 | ATTR_ADDR_MATCH(col), |
Mauro Carvalho Chehab | 1288c18 | 2010-08-10 18:57:01 -0300 | [diff] [blame] | 1173 | { } /* End of list */ |
Mauro Carvalho Chehab | a5538e5 | 2009-09-23 18:56:47 -0300 | [diff] [blame] | 1174 | }; |
| 1175 | |
Mauro Carvalho Chehab | 1288c18 | 2010-08-10 18:57:01 -0300 | [diff] [blame] | 1176 | static const struct mcidev_sysfs_group i7core_inject_addrmatch = { |
Mauro Carvalho Chehab | a5538e5 | 2009-09-23 18:56:47 -0300 | [diff] [blame] | 1177 | .name = "inject_addrmatch", |
| 1178 | .mcidev_attr = i7core_addrmatch_attrs, |
| 1179 | }; |
| 1180 | |
Mauro Carvalho Chehab | 1288c18 | 2010-08-10 18:57:01 -0300 | [diff] [blame] | 1181 | static const struct mcidev_sysfs_attribute i7core_udimm_counters_attrs[] = { |
Mauro Carvalho Chehab | f338d73 | 2009-09-24 17:25:43 -0300 | [diff] [blame] | 1182 | ATTR_COUNTER(0), |
| 1183 | ATTR_COUNTER(1), |
| 1184 | ATTR_COUNTER(2), |
Marcin Slusarz | 64aab72 | 2010-09-30 15:15:30 -0700 | [diff] [blame] | 1185 | { .attr = { .name = NULL } } |
Mauro Carvalho Chehab | f338d73 | 2009-09-24 17:25:43 -0300 | [diff] [blame] | 1186 | }; |
| 1187 | |
Mauro Carvalho Chehab | 1288c18 | 2010-08-10 18:57:01 -0300 | [diff] [blame] | 1188 | static const struct mcidev_sysfs_group i7core_udimm_counters = { |
Mauro Carvalho Chehab | f338d73 | 2009-09-24 17:25:43 -0300 | [diff] [blame] | 1189 | .name = "all_channel_counts", |
| 1190 | .mcidev_attr = i7core_udimm_counters_attrs, |
| 1191 | }; |
| 1192 | |
Mauro Carvalho Chehab | 1288c18 | 2010-08-10 18:57:01 -0300 | [diff] [blame] | 1193 | static const struct mcidev_sysfs_attribute i7core_sysfs_rdimm_attrs[] = { |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1194 | { |
| 1195 | .attr = { |
| 1196 | .name = "inject_section", |
| 1197 | .mode = (S_IRUGO | S_IWUSR) |
| 1198 | }, |
| 1199 | .show = i7core_inject_section_show, |
| 1200 | .store = i7core_inject_section_store, |
| 1201 | }, { |
| 1202 | .attr = { |
| 1203 | .name = "inject_type", |
| 1204 | .mode = (S_IRUGO | S_IWUSR) |
| 1205 | }, |
| 1206 | .show = i7core_inject_type_show, |
| 1207 | .store = i7core_inject_type_store, |
| 1208 | }, { |
| 1209 | .attr = { |
| 1210 | .name = "inject_eccmask", |
| 1211 | .mode = (S_IRUGO | S_IWUSR) |
| 1212 | }, |
| 1213 | .show = i7core_inject_eccmask_show, |
| 1214 | .store = i7core_inject_eccmask_store, |
| 1215 | }, { |
Mauro Carvalho Chehab | a5538e5 | 2009-09-23 18:56:47 -0300 | [diff] [blame] | 1216 | .grp = &i7core_inject_addrmatch, |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1217 | }, { |
| 1218 | .attr = { |
| 1219 | .name = "inject_enable", |
| 1220 | .mode = (S_IRUGO | S_IWUSR) |
| 1221 | }, |
| 1222 | .show = i7core_inject_enable_show, |
| 1223 | .store = i7core_inject_enable_store, |
| 1224 | }, |
Mauro Carvalho Chehab | 1288c18 | 2010-08-10 18:57:01 -0300 | [diff] [blame] | 1225 | { } /* End of list */ |
| 1226 | }; |
| 1227 | |
| 1228 | static const struct mcidev_sysfs_attribute i7core_sysfs_udimm_attrs[] = { |
| 1229 | { |
| 1230 | .attr = { |
| 1231 | .name = "inject_section", |
| 1232 | .mode = (S_IRUGO | S_IWUSR) |
| 1233 | }, |
| 1234 | .show = i7core_inject_section_show, |
| 1235 | .store = i7core_inject_section_store, |
| 1236 | }, { |
| 1237 | .attr = { |
| 1238 | .name = "inject_type", |
| 1239 | .mode = (S_IRUGO | S_IWUSR) |
| 1240 | }, |
| 1241 | .show = i7core_inject_type_show, |
| 1242 | .store = i7core_inject_type_store, |
| 1243 | }, { |
| 1244 | .attr = { |
| 1245 | .name = "inject_eccmask", |
| 1246 | .mode = (S_IRUGO | S_IWUSR) |
| 1247 | }, |
| 1248 | .show = i7core_inject_eccmask_show, |
| 1249 | .store = i7core_inject_eccmask_store, |
| 1250 | }, { |
| 1251 | .grp = &i7core_inject_addrmatch, |
| 1252 | }, { |
| 1253 | .attr = { |
| 1254 | .name = "inject_enable", |
| 1255 | .mode = (S_IRUGO | S_IWUSR) |
| 1256 | }, |
| 1257 | .show = i7core_inject_enable_show, |
| 1258 | .store = i7core_inject_enable_store, |
| 1259 | }, { |
| 1260 | .grp = &i7core_udimm_counters, |
| 1261 | }, |
| 1262 | { } /* End of list */ |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1263 | }; |
| 1264 | |
| 1265 | /**************************************************************************** |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1266 | Device initialization routines: put/get, init/exit |
| 1267 | ****************************************************************************/ |
| 1268 | |
| 1269 | /* |
Hidetoshi Seto | 64c10f6 | 2010-08-20 04:28:14 -0300 | [diff] [blame] | 1270 | * i7core_put_all_devices 'put' all the devices that we have |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1271 | * reserved via 'get' |
| 1272 | */ |
Mauro Carvalho Chehab | 13d6e9b | 2009-09-05 12:15:20 -0300 | [diff] [blame] | 1273 | static void i7core_put_devices(struct i7core_dev *i7core_dev) |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1274 | { |
Mauro Carvalho Chehab | 13d6e9b | 2009-09-05 12:15:20 -0300 | [diff] [blame] | 1275 | int i; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1276 | |
Mauro Carvalho Chehab | 22e6bcb | 2009-09-05 23:06:50 -0300 | [diff] [blame] | 1277 | debugf0(__FILE__ ": %s()\n", __func__); |
Mauro Carvalho Chehab | de06eee | 2009-10-14 08:02:40 -0300 | [diff] [blame] | 1278 | for (i = 0; i < i7core_dev->n_devs; i++) { |
Mauro Carvalho Chehab | 22e6bcb | 2009-09-05 23:06:50 -0300 | [diff] [blame] | 1279 | struct pci_dev *pdev = i7core_dev->pdev[i]; |
| 1280 | if (!pdev) |
| 1281 | continue; |
| 1282 | debugf0("Removing dev %02x:%02x.%d\n", |
| 1283 | pdev->bus->number, |
| 1284 | PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); |
| 1285 | pci_dev_put(pdev); |
| 1286 | } |
Mauro Carvalho Chehab | 13d6e9b | 2009-09-05 12:15:20 -0300 | [diff] [blame] | 1287 | } |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1288 | |
Mauro Carvalho Chehab | 13d6e9b | 2009-09-05 12:15:20 -0300 | [diff] [blame] | 1289 | static void i7core_put_all_devices(void) |
| 1290 | { |
Mauro Carvalho Chehab | 4253868 | 2009-09-24 09:59:13 -0300 | [diff] [blame] | 1291 | struct i7core_dev *i7core_dev, *tmp; |
Mauro Carvalho Chehab | 13d6e9b | 2009-09-05 12:15:20 -0300 | [diff] [blame] | 1292 | |
Mauro Carvalho Chehab | 39300e7 | 2010-08-11 23:40:15 -0300 | [diff] [blame] | 1293 | list_for_each_entry_safe(i7core_dev, tmp, &i7core_edac_list, list) { |
Mauro Carvalho Chehab | 13d6e9b | 2009-09-05 12:15:20 -0300 | [diff] [blame] | 1294 | i7core_put_devices(i7core_dev); |
Hidetoshi Seto | 2aa9be4 | 2010-08-20 04:25:00 -0300 | [diff] [blame] | 1295 | free_i7core_dev(i7core_dev); |
Mauro Carvalho Chehab | 39300e7 | 2010-08-11 23:40:15 -0300 | [diff] [blame] | 1296 | } |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1297 | } |
| 1298 | |
Mauro Carvalho Chehab | 1288c18 | 2010-08-10 18:57:01 -0300 | [diff] [blame] | 1299 | static void __init i7core_xeon_pci_fixup(const struct pci_id_table *table) |
Keith Mannthey | bc2d724 | 2009-09-03 00:05:05 -0300 | [diff] [blame] | 1300 | { |
| 1301 | struct pci_dev *pdev = NULL; |
| 1302 | int i; |
Mauro Carvalho Chehab | 54a08ab | 2010-08-19 15:51:00 -0300 | [diff] [blame] | 1303 | |
Keith Mannthey | bc2d724 | 2009-09-03 00:05:05 -0300 | [diff] [blame] | 1304 | /* |
David Sterba | e7bf068 | 2010-12-27 16:51:15 +0100 | [diff] [blame] | 1305 | * On Xeon 55xx, the Intel Quick Path Arch Generic Non-core pci buses |
Keith Mannthey | bc2d724 | 2009-09-03 00:05:05 -0300 | [diff] [blame] | 1306 | * aren't announced by acpi. So, we need to use a legacy scan probing |
| 1307 | * to detect them |
| 1308 | */ |
Vernon Mauery | bd9e19c | 2010-05-18 19:02:50 -0300 | [diff] [blame] | 1309 | while (table && table->descr) { |
| 1310 | pdev = pci_get_device(PCI_VENDOR_ID_INTEL, table->descr[0].dev_id, NULL); |
| 1311 | if (unlikely(!pdev)) { |
| 1312 | for (i = 0; i < MAX_SOCKET_BUSES; i++) |
| 1313 | pcibios_scan_specific_bus(255-i); |
| 1314 | } |
Mauro Carvalho Chehab | bda1428 | 2010-06-30 01:41:35 -0300 | [diff] [blame] | 1315 | pci_dev_put(pdev); |
Vernon Mauery | bd9e19c | 2010-05-18 19:02:50 -0300 | [diff] [blame] | 1316 | table++; |
Keith Mannthey | bc2d724 | 2009-09-03 00:05:05 -0300 | [diff] [blame] | 1317 | } |
| 1318 | } |
| 1319 | |
Mauro Carvalho Chehab | bda1428 | 2010-06-30 01:41:35 -0300 | [diff] [blame] | 1320 | static unsigned i7core_pci_lastbus(void) |
| 1321 | { |
| 1322 | int last_bus = 0, bus; |
| 1323 | struct pci_bus *b = NULL; |
| 1324 | |
| 1325 | while ((b = pci_find_next_bus(b)) != NULL) { |
| 1326 | bus = b->number; |
| 1327 | debugf0("Found bus %d\n", bus); |
| 1328 | if (bus > last_bus) |
| 1329 | last_bus = bus; |
| 1330 | } |
| 1331 | |
| 1332 | debugf0("Last bus %d\n", last_bus); |
| 1333 | |
| 1334 | return last_bus; |
| 1335 | } |
| 1336 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1337 | /* |
Hidetoshi Seto | 64c10f6 | 2010-08-20 04:28:14 -0300 | [diff] [blame] | 1338 | * i7core_get_all_devices Find and perform 'get' operation on the MCH's |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1339 | * device/functions we want to reference for this driver |
| 1340 | * |
| 1341 | * Need to 'get' device 16 func 1 and func 2 |
| 1342 | */ |
Hidetoshi Seto | b197cba | 2010-08-20 04:24:31 -0300 | [diff] [blame] | 1343 | static int i7core_get_onedevice(struct pci_dev **prev, |
| 1344 | const struct pci_id_table *table, |
| 1345 | const unsigned devno, |
| 1346 | const unsigned last_bus) |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1347 | { |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1348 | struct i7core_dev *i7core_dev; |
Hidetoshi Seto | b197cba | 2010-08-20 04:24:31 -0300 | [diff] [blame] | 1349 | const struct pci_id_descr *dev_descr = &table->descr[devno]; |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1350 | |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1351 | struct pci_dev *pdev = NULL; |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 1352 | u8 bus = 0; |
| 1353 | u8 socket = 0; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1354 | |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1355 | pdev = pci_get_device(PCI_VENDOR_ID_INTEL, |
Mauro Carvalho Chehab | de06eee | 2009-10-14 08:02:40 -0300 | [diff] [blame] | 1356 | dev_descr->dev_id, *prev); |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1357 | |
Mauro Carvalho Chehab | 224e871 | 2011-03-17 17:02:59 -0300 | [diff] [blame] | 1358 | /* |
| 1359 | * On Xeon 55xx, the Intel Quckpath Arch Generic Non-core regs |
| 1360 | * is at addr 8086:2c40, instead of 8086:2c41. So, we need |
| 1361 | * to probe for the alternate address in case of failure |
| 1362 | */ |
| 1363 | if (dev_descr->dev_id == PCI_DEVICE_ID_INTEL_I7_NONCORE && !pdev) |
| 1364 | pdev = pci_get_device(PCI_VENDOR_ID_INTEL, |
| 1365 | PCI_DEVICE_ID_INTEL_I7_NONCORE_ALT, *prev); |
| 1366 | |
| 1367 | if (dev_descr->dev_id == PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE && !pdev) |
| 1368 | pdev = pci_get_device(PCI_VENDOR_ID_INTEL, |
| 1369 | PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE_ALT, |
| 1370 | *prev); |
| 1371 | |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1372 | if (!pdev) { |
| 1373 | if (*prev) { |
| 1374 | *prev = pdev; |
| 1375 | return 0; |
Mauro Carvalho Chehab | d1fd4fb | 2009-07-10 18:39:53 -0300 | [diff] [blame] | 1376 | } |
| 1377 | |
Mauro Carvalho Chehab | de06eee | 2009-10-14 08:02:40 -0300 | [diff] [blame] | 1378 | if (dev_descr->optional) |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1379 | return 0; |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1380 | |
Vernon Mauery | bd9e19c | 2010-05-18 19:02:50 -0300 | [diff] [blame] | 1381 | if (devno == 0) |
| 1382 | return -ENODEV; |
| 1383 | |
Daniel J Blueman | ab08937 | 2010-07-23 23:16:52 +0100 | [diff] [blame] | 1384 | i7core_printk(KERN_INFO, |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1385 | "Device not found: dev %02x.%d PCI ID %04x:%04x\n", |
Mauro Carvalho Chehab | de06eee | 2009-10-14 08:02:40 -0300 | [diff] [blame] | 1386 | dev_descr->dev, dev_descr->func, |
| 1387 | PCI_VENDOR_ID_INTEL, dev_descr->dev_id); |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1388 | |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1389 | /* End of list, leave */ |
| 1390 | return -ENODEV; |
| 1391 | } |
| 1392 | bus = pdev->bus->number; |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1393 | |
Mauro Carvalho Chehab | bda1428 | 2010-06-30 01:41:35 -0300 | [diff] [blame] | 1394 | socket = last_bus - bus; |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1395 | |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1396 | i7core_dev = get_i7core_dev(socket); |
| 1397 | if (!i7core_dev) { |
Hidetoshi Seto | 848b2f7 | 2010-08-20 04:24:44 -0300 | [diff] [blame] | 1398 | i7core_dev = alloc_i7core_dev(socket, table); |
Hidetoshi Seto | 2896637 | 2010-08-20 04:28:51 -0300 | [diff] [blame] | 1399 | if (!i7core_dev) { |
| 1400 | pci_dev_put(pdev); |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1401 | return -ENOMEM; |
Hidetoshi Seto | 2896637 | 2010-08-20 04:28:51 -0300 | [diff] [blame] | 1402 | } |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1403 | } |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1404 | |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1405 | if (i7core_dev->pdev[devno]) { |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1406 | i7core_printk(KERN_ERR, |
| 1407 | "Duplicated device for " |
| 1408 | "dev %02x:%02x.%d PCI ID %04x:%04x\n", |
Mauro Carvalho Chehab | de06eee | 2009-10-14 08:02:40 -0300 | [diff] [blame] | 1409 | bus, dev_descr->dev, dev_descr->func, |
| 1410 | PCI_VENDOR_ID_INTEL, dev_descr->dev_id); |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1411 | pci_dev_put(pdev); |
| 1412 | return -ENODEV; |
| 1413 | } |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1414 | |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1415 | i7core_dev->pdev[devno] = pdev; |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1416 | |
| 1417 | /* Sanity check */ |
Mauro Carvalho Chehab | de06eee | 2009-10-14 08:02:40 -0300 | [diff] [blame] | 1418 | if (unlikely(PCI_SLOT(pdev->devfn) != dev_descr->dev || |
| 1419 | PCI_FUNC(pdev->devfn) != dev_descr->func)) { |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1420 | i7core_printk(KERN_ERR, |
| 1421 | "Device PCI ID %04x:%04x " |
| 1422 | "has dev %02x:%02x.%d instead of dev %02x:%02x.%d\n", |
Mauro Carvalho Chehab | de06eee | 2009-10-14 08:02:40 -0300 | [diff] [blame] | 1423 | PCI_VENDOR_ID_INTEL, dev_descr->dev_id, |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1424 | bus, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), |
Mauro Carvalho Chehab | de06eee | 2009-10-14 08:02:40 -0300 | [diff] [blame] | 1425 | bus, dev_descr->dev, dev_descr->func); |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1426 | return -ENODEV; |
| 1427 | } |
| 1428 | |
| 1429 | /* Be sure that the device is enabled */ |
| 1430 | if (unlikely(pci_enable_device(pdev) < 0)) { |
| 1431 | i7core_printk(KERN_ERR, |
| 1432 | "Couldn't enable " |
| 1433 | "dev %02x:%02x.%d PCI ID %04x:%04x\n", |
Mauro Carvalho Chehab | de06eee | 2009-10-14 08:02:40 -0300 | [diff] [blame] | 1434 | bus, dev_descr->dev, dev_descr->func, |
| 1435 | PCI_VENDOR_ID_INTEL, dev_descr->dev_id); |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1436 | return -ENODEV; |
| 1437 | } |
| 1438 | |
Mauro Carvalho Chehab | d4c2779 | 2009-09-05 04:12:02 -0300 | [diff] [blame] | 1439 | debugf0("Detected socket %d dev %02x:%02x.%d PCI ID %04x:%04x\n", |
Mauro Carvalho Chehab | de06eee | 2009-10-14 08:02:40 -0300 | [diff] [blame] | 1440 | socket, bus, dev_descr->dev, |
| 1441 | dev_descr->func, |
| 1442 | PCI_VENDOR_ID_INTEL, dev_descr->dev_id); |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1443 | |
Mauro Carvalho Chehab | a3e1541 | 2010-08-21 08:52:41 -0300 | [diff] [blame] | 1444 | /* |
| 1445 | * As stated on drivers/pci/search.c, the reference count for |
| 1446 | * @from is always decremented if it is not %NULL. So, as we need |
| 1447 | * to get all devices up to null, we need to do a get for the device |
| 1448 | */ |
| 1449 | pci_dev_get(pdev); |
| 1450 | |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1451 | *prev = pdev; |
| 1452 | |
| 1453 | return 0; |
| 1454 | } |
| 1455 | |
Hidetoshi Seto | 64c10f6 | 2010-08-20 04:28:14 -0300 | [diff] [blame] | 1456 | static int i7core_get_all_devices(void) |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1457 | { |
Mauro Carvalho Chehab | 3c52cc5 | 2010-10-24 11:12:28 -0200 | [diff] [blame] | 1458 | int i, rc, last_bus; |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1459 | struct pci_dev *pdev = NULL; |
Mauro Carvalho Chehab | 3c52cc5 | 2010-10-24 11:12:28 -0200 | [diff] [blame] | 1460 | const struct pci_id_table *table = pci_dev_table; |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1461 | |
Mauro Carvalho Chehab | bda1428 | 2010-06-30 01:41:35 -0300 | [diff] [blame] | 1462 | last_bus = i7core_pci_lastbus(); |
| 1463 | |
Mauro Carvalho Chehab | 3c52cc5 | 2010-10-24 11:12:28 -0200 | [diff] [blame] | 1464 | while (table && table->descr) { |
Vernon Mauery | bd9e19c | 2010-05-18 19:02:50 -0300 | [diff] [blame] | 1465 | for (i = 0; i < table->n_devs; i++) { |
| 1466 | pdev = NULL; |
| 1467 | do { |
Hidetoshi Seto | b197cba | 2010-08-20 04:24:31 -0300 | [diff] [blame] | 1468 | rc = i7core_get_onedevice(&pdev, table, i, |
Mauro Carvalho Chehab | bda1428 | 2010-06-30 01:41:35 -0300 | [diff] [blame] | 1469 | last_bus); |
Vernon Mauery | bd9e19c | 2010-05-18 19:02:50 -0300 | [diff] [blame] | 1470 | if (rc < 0) { |
| 1471 | if (i == 0) { |
| 1472 | i = table->n_devs; |
| 1473 | break; |
| 1474 | } |
| 1475 | i7core_put_all_devices(); |
| 1476 | return -ENODEV; |
| 1477 | } |
| 1478 | } while (pdev); |
| 1479 | } |
Mauro Carvalho Chehab | 3c52cc5 | 2010-10-24 11:12:28 -0200 | [diff] [blame] | 1480 | table++; |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1481 | } |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1482 | |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1483 | return 0; |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1484 | } |
| 1485 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1486 | static int mci_bind_devs(struct mem_ctl_info *mci, |
| 1487 | struct i7core_dev *i7core_dev) |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1488 | { |
| 1489 | struct i7core_pvt *pvt = mci->pvt_info; |
| 1490 | struct pci_dev *pdev; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1491 | int i, func, slot; |
Mauro Carvalho Chehab | 27100db | 2011-08-04 21:35:27 -0300 | [diff] [blame] | 1492 | char *family; |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1493 | |
Mauro Carvalho Chehab | 27100db | 2011-08-04 21:35:27 -0300 | [diff] [blame] | 1494 | pvt->is_registered = false; |
| 1495 | pvt->enable_scrub = false; |
Mauro Carvalho Chehab | de06eee | 2009-10-14 08:02:40 -0300 | [diff] [blame] | 1496 | for (i = 0; i < i7core_dev->n_devs; i++) { |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1497 | pdev = i7core_dev->pdev[i]; |
| 1498 | if (!pdev) |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1499 | continue; |
| 1500 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1501 | func = PCI_FUNC(pdev->devfn); |
| 1502 | slot = PCI_SLOT(pdev->devfn); |
| 1503 | if (slot == 3) { |
| 1504 | if (unlikely(func > MAX_MCR_FUNC)) |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1505 | goto error; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1506 | pvt->pci_mcr[func] = pdev; |
| 1507 | } else if (likely(slot >= 4 && slot < 4 + NUM_CHANS)) { |
| 1508 | if (unlikely(func > MAX_CHAN_FUNC)) |
| 1509 | goto error; |
| 1510 | pvt->pci_ch[slot - 4][func] = pdev; |
Mauro Carvalho Chehab | 27100db | 2011-08-04 21:35:27 -0300 | [diff] [blame] | 1511 | } else if (!slot && !func) { |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1512 | pvt->pci_noncore = pdev; |
Mauro Carvalho Chehab | 27100db | 2011-08-04 21:35:27 -0300 | [diff] [blame] | 1513 | |
| 1514 | /* Detect the processor family */ |
| 1515 | switch (pdev->device) { |
| 1516 | case PCI_DEVICE_ID_INTEL_I7_NONCORE: |
| 1517 | family = "Xeon 35xx/ i7core"; |
| 1518 | pvt->enable_scrub = false; |
| 1519 | break; |
| 1520 | case PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE_ALT: |
| 1521 | family = "i7-800/i5-700"; |
| 1522 | pvt->enable_scrub = false; |
| 1523 | break; |
| 1524 | case PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE: |
| 1525 | family = "Xeon 34xx"; |
| 1526 | pvt->enable_scrub = false; |
| 1527 | break; |
| 1528 | case PCI_DEVICE_ID_INTEL_I7_NONCORE_ALT: |
| 1529 | family = "Xeon 55xx"; |
| 1530 | pvt->enable_scrub = true; |
| 1531 | break; |
| 1532 | case PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE_REV2: |
| 1533 | family = "Xeon 56xx / i7-900"; |
| 1534 | pvt->enable_scrub = true; |
| 1535 | break; |
| 1536 | default: |
| 1537 | family = "unknown"; |
| 1538 | pvt->enable_scrub = false; |
| 1539 | } |
| 1540 | debugf0("Detected a processor type %s\n", family); |
| 1541 | } else |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1542 | goto error; |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1543 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1544 | debugf0("Associated fn %d.%d, dev = %p, socket %d\n", |
| 1545 | PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), |
| 1546 | pdev, i7core_dev->socket); |
Mauro Carvalho Chehab | 14d2c08 | 2009-09-02 23:52:36 -0300 | [diff] [blame] | 1547 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1548 | if (PCI_SLOT(pdev->devfn) == 3 && |
| 1549 | PCI_FUNC(pdev->devfn) == 2) |
Mauro Carvalho Chehab | 27100db | 2011-08-04 21:35:27 -0300 | [diff] [blame] | 1550 | pvt->is_registered = true; |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1551 | } |
Mauro Carvalho Chehab | e9bd2e7 | 2009-07-09 22:14:35 -0300 | [diff] [blame] | 1552 | |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1553 | return 0; |
| 1554 | |
| 1555 | error: |
| 1556 | i7core_printk(KERN_ERR, "Device %d, function %d " |
| 1557 | "is out of the expected range\n", |
| 1558 | slot, func); |
| 1559 | return -EINVAL; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1560 | } |
| 1561 | |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1562 | /**************************************************************************** |
| 1563 | Error check routines |
| 1564 | ****************************************************************************/ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1565 | static void i7core_rdimm_update_csrow(struct mem_ctl_info *mci, |
Mauro Carvalho Chehab | 1288c18 | 2010-08-10 18:57:01 -0300 | [diff] [blame] | 1566 | const int chan, |
| 1567 | const int dimm, |
| 1568 | const int add) |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1569 | { |
| 1570 | char *msg; |
| 1571 | struct i7core_pvt *pvt = mci->pvt_info; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1572 | int row = pvt->csrow_map[chan][dimm], i; |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1573 | |
| 1574 | for (i = 0; i < add; i++) { |
| 1575 | msg = kasprintf(GFP_KERNEL, "Corrected error " |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1576 | "(Socket=%d channel=%d dimm=%d)", |
| 1577 | pvt->i7core_dev->socket, chan, dimm); |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1578 | |
| 1579 | edac_mc_handle_fbd_ce(mci, row, 0, msg); |
| 1580 | kfree (msg); |
| 1581 | } |
| 1582 | } |
| 1583 | |
| 1584 | static void i7core_rdimm_update_ce_count(struct mem_ctl_info *mci, |
Mauro Carvalho Chehab | 1288c18 | 2010-08-10 18:57:01 -0300 | [diff] [blame] | 1585 | const int chan, |
| 1586 | const int new0, |
| 1587 | const int new1, |
| 1588 | const int new2) |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1589 | { |
| 1590 | struct i7core_pvt *pvt = mci->pvt_info; |
| 1591 | int add0 = 0, add1 = 0, add2 = 0; |
| 1592 | /* Updates CE counters if it is not the first time here */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1593 | if (pvt->ce_count_available) { |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1594 | /* Updates CE counters */ |
| 1595 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1596 | add2 = new2 - pvt->rdimm_last_ce_count[chan][2]; |
| 1597 | add1 = new1 - pvt->rdimm_last_ce_count[chan][1]; |
| 1598 | add0 = new0 - pvt->rdimm_last_ce_count[chan][0]; |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1599 | |
| 1600 | if (add2 < 0) |
| 1601 | add2 += 0x7fff; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1602 | pvt->rdimm_ce_count[chan][2] += add2; |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1603 | |
| 1604 | if (add1 < 0) |
| 1605 | add1 += 0x7fff; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1606 | pvt->rdimm_ce_count[chan][1] += add1; |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1607 | |
| 1608 | if (add0 < 0) |
| 1609 | add0 += 0x7fff; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1610 | pvt->rdimm_ce_count[chan][0] += add0; |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1611 | } else |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1612 | pvt->ce_count_available = 1; |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1613 | |
| 1614 | /* Store the new values */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1615 | pvt->rdimm_last_ce_count[chan][2] = new2; |
| 1616 | pvt->rdimm_last_ce_count[chan][1] = new1; |
| 1617 | pvt->rdimm_last_ce_count[chan][0] = new0; |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1618 | |
| 1619 | /*updated the edac core */ |
| 1620 | if (add0 != 0) |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1621 | i7core_rdimm_update_csrow(mci, chan, 0, add0); |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1622 | if (add1 != 0) |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1623 | i7core_rdimm_update_csrow(mci, chan, 1, add1); |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1624 | if (add2 != 0) |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1625 | i7core_rdimm_update_csrow(mci, chan, 2, add2); |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1626 | |
| 1627 | } |
| 1628 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1629 | static void i7core_rdimm_check_mc_ecc_err(struct mem_ctl_info *mci) |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1630 | { |
| 1631 | struct i7core_pvt *pvt = mci->pvt_info; |
| 1632 | u32 rcv[3][2]; |
| 1633 | int i, new0, new1, new2; |
| 1634 | |
| 1635 | /*Read DEV 3: FUN 2: MC_COR_ECC_CNT regs directly*/ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1636 | pci_read_config_dword(pvt->pci_mcr[2], MC_COR_ECC_CNT_0, |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1637 | &rcv[0][0]); |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1638 | pci_read_config_dword(pvt->pci_mcr[2], MC_COR_ECC_CNT_1, |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1639 | &rcv[0][1]); |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1640 | pci_read_config_dword(pvt->pci_mcr[2], MC_COR_ECC_CNT_2, |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1641 | &rcv[1][0]); |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1642 | pci_read_config_dword(pvt->pci_mcr[2], MC_COR_ECC_CNT_3, |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1643 | &rcv[1][1]); |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1644 | pci_read_config_dword(pvt->pci_mcr[2], MC_COR_ECC_CNT_4, |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1645 | &rcv[2][0]); |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1646 | pci_read_config_dword(pvt->pci_mcr[2], MC_COR_ECC_CNT_5, |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1647 | &rcv[2][1]); |
| 1648 | for (i = 0 ; i < 3; i++) { |
| 1649 | debugf3("MC_COR_ECC_CNT%d = 0x%x; MC_COR_ECC_CNT%d = 0x%x\n", |
| 1650 | (i * 2), rcv[i][0], (i * 2) + 1, rcv[i][1]); |
| 1651 | /*if the channel has 3 dimms*/ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1652 | if (pvt->channel[i].dimms > 2) { |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1653 | new0 = DIMM_BOT_COR_ERR(rcv[i][0]); |
| 1654 | new1 = DIMM_TOP_COR_ERR(rcv[i][0]); |
| 1655 | new2 = DIMM_BOT_COR_ERR(rcv[i][1]); |
| 1656 | } else { |
| 1657 | new0 = DIMM_TOP_COR_ERR(rcv[i][0]) + |
| 1658 | DIMM_BOT_COR_ERR(rcv[i][0]); |
| 1659 | new1 = DIMM_TOP_COR_ERR(rcv[i][1]) + |
| 1660 | DIMM_BOT_COR_ERR(rcv[i][1]); |
| 1661 | new2 = 0; |
| 1662 | } |
| 1663 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1664 | i7core_rdimm_update_ce_count(mci, i, new0, new1, new2); |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1665 | } |
| 1666 | } |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1667 | |
| 1668 | /* This function is based on the device 3 function 4 registers as described on: |
| 1669 | * Intel Xeon Processor 5500 Series Datasheet Volume 2 |
| 1670 | * http://www.intel.com/Assets/PDF/datasheet/321322.pdf |
| 1671 | * also available at: |
| 1672 | * http://www.arrownac.com/manufacturers/intel/s/nehalem/5500-datasheet-v2.pdf |
| 1673 | */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1674 | static void i7core_udimm_check_mc_ecc_err(struct mem_ctl_info *mci) |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1675 | { |
| 1676 | struct i7core_pvt *pvt = mci->pvt_info; |
| 1677 | u32 rcv1, rcv0; |
| 1678 | int new0, new1, new2; |
| 1679 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1680 | if (!pvt->pci_mcr[4]) { |
Mauro Carvalho Chehab | b990538 | 2009-08-05 21:36:35 -0300 | [diff] [blame] | 1681 | debugf0("%s MCR registers not found\n", __func__); |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1682 | return; |
| 1683 | } |
| 1684 | |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1685 | /* Corrected test errors */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1686 | pci_read_config_dword(pvt->pci_mcr[4], MC_TEST_ERR_RCV1, &rcv1); |
| 1687 | pci_read_config_dword(pvt->pci_mcr[4], MC_TEST_ERR_RCV0, &rcv0); |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1688 | |
| 1689 | /* Store the new values */ |
| 1690 | new2 = DIMM2_COR_ERR(rcv1); |
| 1691 | new1 = DIMM1_COR_ERR(rcv0); |
| 1692 | new0 = DIMM0_COR_ERR(rcv0); |
| 1693 | |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1694 | /* Updates CE counters if it is not the first time here */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1695 | if (pvt->ce_count_available) { |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1696 | /* Updates CE counters */ |
| 1697 | int add0, add1, add2; |
| 1698 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1699 | add2 = new2 - pvt->udimm_last_ce_count[2]; |
| 1700 | add1 = new1 - pvt->udimm_last_ce_count[1]; |
| 1701 | add0 = new0 - pvt->udimm_last_ce_count[0]; |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1702 | |
| 1703 | if (add2 < 0) |
| 1704 | add2 += 0x7fff; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1705 | pvt->udimm_ce_count[2] += add2; |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1706 | |
| 1707 | if (add1 < 0) |
| 1708 | add1 += 0x7fff; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1709 | pvt->udimm_ce_count[1] += add1; |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1710 | |
| 1711 | if (add0 < 0) |
| 1712 | add0 += 0x7fff; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1713 | pvt->udimm_ce_count[0] += add0; |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1714 | |
| 1715 | if (add0 | add1 | add2) |
| 1716 | i7core_printk(KERN_ERR, "New Corrected error(s): " |
| 1717 | "dimm0: +%d, dimm1: +%d, dimm2 +%d\n", |
| 1718 | add0, add1, add2); |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1719 | } else |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1720 | pvt->ce_count_available = 1; |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1721 | |
| 1722 | /* Store the new values */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1723 | pvt->udimm_last_ce_count[2] = new2; |
| 1724 | pvt->udimm_last_ce_count[1] = new1; |
| 1725 | pvt->udimm_last_ce_count[0] = new0; |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1726 | } |
| 1727 | |
Mauro Carvalho Chehab | 8a2f118 | 2009-07-15 19:01:08 -0300 | [diff] [blame] | 1728 | /* |
| 1729 | * According with tables E-11 and E-12 of chapter E.3.3 of Intel 64 and IA-32 |
| 1730 | * Architectures Software Developer’s Manual Volume 3B. |
Mauro Carvalho Chehab | f237fcf | 2009-07-15 19:53:24 -0300 | [diff] [blame] | 1731 | * Nehalem are defined as family 0x06, model 0x1a |
| 1732 | * |
| 1733 | * The MCA registers used here are the following ones: |
Mauro Carvalho Chehab | 8a2f118 | 2009-07-15 19:01:08 -0300 | [diff] [blame] | 1734 | * struct mce field MCA Register |
Mauro Carvalho Chehab | f237fcf | 2009-07-15 19:53:24 -0300 | [diff] [blame] | 1735 | * m->status MSR_IA32_MC8_STATUS |
| 1736 | * m->addr MSR_IA32_MC8_ADDR |
| 1737 | * m->misc MSR_IA32_MC8_MISC |
Mauro Carvalho Chehab | 8a2f118 | 2009-07-15 19:01:08 -0300 | [diff] [blame] | 1738 | * In the case of Nehalem, the error information is masked at .status and .misc |
| 1739 | * fields |
| 1740 | */ |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1741 | static void i7core_mce_output_error(struct mem_ctl_info *mci, |
Mauro Carvalho Chehab | 1288c18 | 2010-08-10 18:57:01 -0300 | [diff] [blame] | 1742 | const struct mce *m) |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1743 | { |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1744 | struct i7core_pvt *pvt = mci->pvt_info; |
Mauro Carvalho Chehab | a639539 | 2009-07-17 10:54:23 -0300 | [diff] [blame] | 1745 | char *type, *optype, *err, *msg; |
Mauro Carvalho Chehab | 8a2f118 | 2009-07-15 19:01:08 -0300 | [diff] [blame] | 1746 | unsigned long error = m->status & 0x1ff0000l; |
Mauro Carvalho Chehab | a639539 | 2009-07-17 10:54:23 -0300 | [diff] [blame] | 1747 | u32 optypenum = (m->status >> 4) & 0x07; |
Mathias Krause | 8cf2d23 | 2011-08-18 09:17:00 +0200 | [diff] [blame] | 1748 | u32 core_err_cnt = (m->status >> 38) & 0x7fff; |
Mauro Carvalho Chehab | 8a2f118 | 2009-07-15 19:01:08 -0300 | [diff] [blame] | 1749 | u32 dimm = (m->misc >> 16) & 0x3; |
| 1750 | u32 channel = (m->misc >> 18) & 0x3; |
| 1751 | u32 syndrome = m->misc >> 32; |
| 1752 | u32 errnum = find_first_bit(&error, 32); |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1753 | int csrow; |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1754 | |
Mauro Carvalho Chehab | c5d3452 | 2009-07-17 10:28:15 -0300 | [diff] [blame] | 1755 | if (m->mcgstatus & 1) |
| 1756 | type = "FATAL"; |
| 1757 | else |
| 1758 | type = "NON_FATAL"; |
| 1759 | |
Mauro Carvalho Chehab | a639539 | 2009-07-17 10:54:23 -0300 | [diff] [blame] | 1760 | switch (optypenum) { |
Mauro Carvalho Chehab | b990538 | 2009-08-05 21:36:35 -0300 | [diff] [blame] | 1761 | case 0: |
| 1762 | optype = "generic undef request"; |
| 1763 | break; |
| 1764 | case 1: |
| 1765 | optype = "read error"; |
| 1766 | break; |
| 1767 | case 2: |
| 1768 | optype = "write error"; |
| 1769 | break; |
| 1770 | case 3: |
| 1771 | optype = "addr/cmd error"; |
| 1772 | break; |
| 1773 | case 4: |
| 1774 | optype = "scrubbing error"; |
| 1775 | break; |
| 1776 | default: |
| 1777 | optype = "reserved"; |
| 1778 | break; |
Mauro Carvalho Chehab | a639539 | 2009-07-17 10:54:23 -0300 | [diff] [blame] | 1779 | } |
| 1780 | |
Mauro Carvalho Chehab | 8a2f118 | 2009-07-15 19:01:08 -0300 | [diff] [blame] | 1781 | switch (errnum) { |
| 1782 | case 16: |
| 1783 | err = "read ECC error"; |
| 1784 | break; |
| 1785 | case 17: |
| 1786 | err = "RAS ECC error"; |
| 1787 | break; |
| 1788 | case 18: |
| 1789 | err = "write parity error"; |
| 1790 | break; |
| 1791 | case 19: |
| 1792 | err = "redundacy loss"; |
| 1793 | break; |
| 1794 | case 20: |
| 1795 | err = "reserved"; |
| 1796 | break; |
| 1797 | case 21: |
| 1798 | err = "memory range error"; |
| 1799 | break; |
| 1800 | case 22: |
| 1801 | err = "RTID out of range"; |
| 1802 | break; |
| 1803 | case 23: |
| 1804 | err = "address parity error"; |
| 1805 | break; |
| 1806 | case 24: |
| 1807 | err = "byte enable parity error"; |
| 1808 | break; |
| 1809 | default: |
| 1810 | err = "unknown"; |
| 1811 | } |
| 1812 | |
Mauro Carvalho Chehab | f237fcf | 2009-07-15 19:53:24 -0300 | [diff] [blame] | 1813 | /* FIXME: should convert addr into bank and rank information */ |
Mauro Carvalho Chehab | 8a2f118 | 2009-07-15 19:01:08 -0300 | [diff] [blame] | 1814 | msg = kasprintf(GFP_ATOMIC, |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1815 | "%s (addr = 0x%08llx, cpu=%d, Dimm=%d, Channel=%d, " |
Mauro Carvalho Chehab | a639539 | 2009-07-17 10:54:23 -0300 | [diff] [blame] | 1816 | "syndrome=0x%08x, count=%d, Err=%08llx:%08llx (%s: %s))\n", |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1817 | type, (long long) m->addr, m->cpu, dimm, channel, |
Mauro Carvalho Chehab | a639539 | 2009-07-17 10:54:23 -0300 | [diff] [blame] | 1818 | syndrome, core_err_cnt, (long long)m->status, |
| 1819 | (long long)m->misc, optype, err); |
Mauro Carvalho Chehab | 8a2f118 | 2009-07-15 19:01:08 -0300 | [diff] [blame] | 1820 | |
| 1821 | debugf0("%s", msg); |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1822 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1823 | csrow = pvt->csrow_map[channel][dimm]; |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1824 | |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1825 | /* Call the helper to output message */ |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1826 | if (m->mcgstatus & 1) |
| 1827 | edac_mc_handle_fbd_ue(mci, csrow, 0, |
| 1828 | 0 /* FIXME: should be channel here */, msg); |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1829 | else if (!pvt->is_registered) |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1830 | edac_mc_handle_fbd_ce(mci, csrow, |
| 1831 | 0 /* FIXME: should be channel here */, msg); |
Mauro Carvalho Chehab | 8a2f118 | 2009-07-15 19:01:08 -0300 | [diff] [blame] | 1832 | |
| 1833 | kfree(msg); |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1834 | } |
| 1835 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1836 | /* |
Mauro Carvalho Chehab | 87d1d27 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1837 | * i7core_check_error Retrieve and process errors reported by the |
| 1838 | * hardware. Called by the Core module. |
| 1839 | */ |
| 1840 | static void i7core_check_error(struct mem_ctl_info *mci) |
| 1841 | { |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1842 | struct i7core_pvt *pvt = mci->pvt_info; |
| 1843 | int i; |
| 1844 | unsigned count = 0; |
Mauro Carvalho Chehab | ca9c90b | 2009-10-04 10:15:40 -0300 | [diff] [blame] | 1845 | struct mce *m; |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1846 | |
Mauro Carvalho Chehab | ca9c90b | 2009-10-04 10:15:40 -0300 | [diff] [blame] | 1847 | /* |
| 1848 | * MCE first step: Copy all mce errors into a temporary buffer |
| 1849 | * We use a double buffering here, to reduce the risk of |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1850 | * losing an error. |
Mauro Carvalho Chehab | ca9c90b | 2009-10-04 10:15:40 -0300 | [diff] [blame] | 1851 | */ |
| 1852 | smp_rmb(); |
Mauro Carvalho Chehab | 321ece4 | 2009-10-08 13:11:08 -0300 | [diff] [blame] | 1853 | count = (pvt->mce_out + MCE_LOG_LEN - pvt->mce_in) |
| 1854 | % MCE_LOG_LEN; |
Mauro Carvalho Chehab | ca9c90b | 2009-10-04 10:15:40 -0300 | [diff] [blame] | 1855 | if (!count) |
Vernon Mauery | 8a311e1 | 2010-04-16 19:40:19 -0300 | [diff] [blame] | 1856 | goto check_ce_error; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1857 | |
Mauro Carvalho Chehab | ca9c90b | 2009-10-04 10:15:40 -0300 | [diff] [blame] | 1858 | m = pvt->mce_outentry; |
Mauro Carvalho Chehab | 321ece4 | 2009-10-08 13:11:08 -0300 | [diff] [blame] | 1859 | if (pvt->mce_in + count > MCE_LOG_LEN) { |
| 1860 | unsigned l = MCE_LOG_LEN - pvt->mce_in; |
Mauro Carvalho Chehab | ca9c90b | 2009-10-04 10:15:40 -0300 | [diff] [blame] | 1861 | |
| 1862 | memcpy(m, &pvt->mce_entry[pvt->mce_in], sizeof(*m) * l); |
| 1863 | smp_wmb(); |
| 1864 | pvt->mce_in = 0; |
| 1865 | count -= l; |
| 1866 | m += l; |
| 1867 | } |
| 1868 | memcpy(m, &pvt->mce_entry[pvt->mce_in], sizeof(*m) * count); |
| 1869 | smp_wmb(); |
| 1870 | pvt->mce_in += count; |
| 1871 | |
| 1872 | smp_rmb(); |
| 1873 | if (pvt->mce_overrun) { |
| 1874 | i7core_printk(KERN_ERR, "Lost %d memory errors\n", |
| 1875 | pvt->mce_overrun); |
| 1876 | smp_wmb(); |
| 1877 | pvt->mce_overrun = 0; |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1878 | } |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1879 | |
Mauro Carvalho Chehab | ca9c90b | 2009-10-04 10:15:40 -0300 | [diff] [blame] | 1880 | /* |
| 1881 | * MCE second step: parse errors and display |
| 1882 | */ |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1883 | for (i = 0; i < count; i++) |
Mauro Carvalho Chehab | ca9c90b | 2009-10-04 10:15:40 -0300 | [diff] [blame] | 1884 | i7core_mce_output_error(mci, &pvt->mce_outentry[i]); |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1885 | |
Mauro Carvalho Chehab | ca9c90b | 2009-10-04 10:15:40 -0300 | [diff] [blame] | 1886 | /* |
| 1887 | * Now, let's increment CE error counts |
| 1888 | */ |
Vernon Mauery | 8a311e1 | 2010-04-16 19:40:19 -0300 | [diff] [blame] | 1889 | check_ce_error: |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1890 | if (!pvt->is_registered) |
| 1891 | i7core_udimm_check_mc_ecc_err(mci); |
| 1892 | else |
| 1893 | i7core_rdimm_check_mc_ecc_err(mci); |
Mauro Carvalho Chehab | 87d1d27 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1894 | } |
| 1895 | |
| 1896 | /* |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1897 | * i7core_mce_check_error Replicates mcelog routine to get errors |
| 1898 | * This routine simply queues mcelog errors, and |
| 1899 | * return. The error itself should be handled later |
| 1900 | * by i7core_check_error. |
Mauro Carvalho Chehab | 6e103be | 2009-10-05 09:40:09 -0300 | [diff] [blame] | 1901 | * WARNING: As this routine should be called at NMI time, extra care should |
| 1902 | * be taken to avoid deadlocks, and to be as fast as possible. |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1903 | */ |
Borislav Petkov | 4140c54 | 2011-07-18 11:24:46 -0300 | [diff] [blame] | 1904 | static int i7core_mce_check_error(struct notifier_block *nb, unsigned long val, |
| 1905 | void *data) |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1906 | { |
Borislav Petkov | 4140c54 | 2011-07-18 11:24:46 -0300 | [diff] [blame] | 1907 | struct mce *mce = (struct mce *)data; |
| 1908 | struct i7core_dev *i7_dev; |
| 1909 | struct mem_ctl_info *mci; |
| 1910 | struct i7core_pvt *pvt; |
| 1911 | |
| 1912 | i7_dev = get_i7core_dev(mce->socketid); |
| 1913 | if (!i7_dev) |
| 1914 | return NOTIFY_BAD; |
| 1915 | |
| 1916 | mci = i7_dev->mci; |
| 1917 | pvt = mci->pvt_info; |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1918 | |
Mauro Carvalho Chehab | 8a2f118 | 2009-07-15 19:01:08 -0300 | [diff] [blame] | 1919 | /* |
| 1920 | * Just let mcelog handle it if the error is |
| 1921 | * outside the memory controller |
| 1922 | */ |
| 1923 | if (((mce->status & 0xffff) >> 7) != 1) |
Borislav Petkov | 4140c54 | 2011-07-18 11:24:46 -0300 | [diff] [blame] | 1924 | return NOTIFY_DONE; |
Mauro Carvalho Chehab | 8a2f118 | 2009-07-15 19:01:08 -0300 | [diff] [blame] | 1925 | |
Mauro Carvalho Chehab | f237fcf | 2009-07-15 19:53:24 -0300 | [diff] [blame] | 1926 | /* Bank 8 registers are the only ones that we know how to handle */ |
| 1927 | if (mce->bank != 8) |
Borislav Petkov | 4140c54 | 2011-07-18 11:24:46 -0300 | [diff] [blame] | 1928 | return NOTIFY_DONE; |
Mauro Carvalho Chehab | f237fcf | 2009-07-15 19:53:24 -0300 | [diff] [blame] | 1929 | |
Randy Dunlap | 3b918c1 | 2009-11-08 01:36:40 -0200 | [diff] [blame] | 1930 | #ifdef CONFIG_SMP |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1931 | /* Only handle if it is the right mc controller */ |
Thomas Renninger | 5034086 | 2011-06-22 05:40:06 -0300 | [diff] [blame] | 1932 | if (mce->socketid != pvt->i7core_dev->socket) |
Borislav Petkov | 4140c54 | 2011-07-18 11:24:46 -0300 | [diff] [blame] | 1933 | return NOTIFY_DONE; |
Randy Dunlap | 3b918c1 | 2009-11-08 01:36:40 -0200 | [diff] [blame] | 1934 | #endif |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 1935 | |
Mauro Carvalho Chehab | ca9c90b | 2009-10-04 10:15:40 -0300 | [diff] [blame] | 1936 | smp_rmb(); |
Mauro Carvalho Chehab | 321ece4 | 2009-10-08 13:11:08 -0300 | [diff] [blame] | 1937 | if ((pvt->mce_out + 1) % MCE_LOG_LEN == pvt->mce_in) { |
Mauro Carvalho Chehab | ca9c90b | 2009-10-04 10:15:40 -0300 | [diff] [blame] | 1938 | smp_wmb(); |
| 1939 | pvt->mce_overrun++; |
Borislav Petkov | 4140c54 | 2011-07-18 11:24:46 -0300 | [diff] [blame] | 1940 | return NOTIFY_DONE; |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1941 | } |
Mauro Carvalho Chehab | 6e103be | 2009-10-05 09:40:09 -0300 | [diff] [blame] | 1942 | |
| 1943 | /* Copy memory error at the ringbuffer */ |
| 1944 | memcpy(&pvt->mce_entry[pvt->mce_out], mce, sizeof(*mce)); |
Mauro Carvalho Chehab | ca9c90b | 2009-10-04 10:15:40 -0300 | [diff] [blame] | 1945 | smp_wmb(); |
Mauro Carvalho Chehab | 321ece4 | 2009-10-08 13:11:08 -0300 | [diff] [blame] | 1946 | pvt->mce_out = (pvt->mce_out + 1) % MCE_LOG_LEN; |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1947 | |
Mauro Carvalho Chehab | c5d3452 | 2009-07-17 10:28:15 -0300 | [diff] [blame] | 1948 | /* Handle fatal errors immediately */ |
| 1949 | if (mce->mcgstatus & 1) |
| 1950 | i7core_check_error(mci); |
| 1951 | |
David Sterba | e7bf068 | 2010-12-27 16:51:15 +0100 | [diff] [blame] | 1952 | /* Advise mcelog that the errors were handled */ |
Borislav Petkov | 4140c54 | 2011-07-18 11:24:46 -0300 | [diff] [blame] | 1953 | return NOTIFY_STOP; |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1954 | } |
| 1955 | |
Borislav Petkov | 4140c54 | 2011-07-18 11:24:46 -0300 | [diff] [blame] | 1956 | static struct notifier_block i7_mce_dec = { |
| 1957 | .notifier_call = i7core_mce_check_error, |
| 1958 | }; |
| 1959 | |
Nils Carlson | 535e9c7 | 2011-08-08 06:21:26 -0300 | [diff] [blame^] | 1960 | struct memdev_dmi_entry { |
| 1961 | u8 type; |
| 1962 | u8 length; |
| 1963 | u16 handle; |
| 1964 | u16 phys_mem_array_handle; |
| 1965 | u16 mem_err_info_handle; |
| 1966 | u16 total_width; |
| 1967 | u16 data_width; |
| 1968 | u16 size; |
| 1969 | u8 form; |
| 1970 | u8 device_set; |
| 1971 | u8 device_locator; |
| 1972 | u8 bank_locator; |
| 1973 | u8 memory_type; |
| 1974 | u16 type_detail; |
| 1975 | u16 speed; |
| 1976 | u8 manufacturer; |
| 1977 | u8 serial_number; |
| 1978 | u8 asset_tag; |
| 1979 | u8 part_number; |
| 1980 | u8 attributes; |
| 1981 | u32 extended_size; |
| 1982 | u16 conf_mem_clk_speed; |
| 1983 | } __attribute__((__packed__)); |
| 1984 | |
| 1985 | |
| 1986 | /* |
| 1987 | * Decode the DRAM Clock Frequency, be paranoid, make sure that all |
| 1988 | * memory devices show the same speed, and if they don't then consider |
| 1989 | * all speeds to be invalid. |
| 1990 | */ |
| 1991 | static void decode_dclk(const struct dmi_header *dh, void *_dclk_freq) |
| 1992 | { |
| 1993 | int *dclk_freq = _dclk_freq; |
| 1994 | u16 dmi_mem_clk_speed; |
| 1995 | |
| 1996 | if (*dclk_freq == -1) |
| 1997 | return; |
| 1998 | |
| 1999 | if (dh->type == DMI_ENTRY_MEM_DEVICE) { |
| 2000 | struct memdev_dmi_entry *memdev_dmi_entry = |
| 2001 | (struct memdev_dmi_entry *)dh; |
| 2002 | unsigned long conf_mem_clk_speed_offset = |
| 2003 | (unsigned long)&memdev_dmi_entry->conf_mem_clk_speed - |
| 2004 | (unsigned long)&memdev_dmi_entry->type; |
| 2005 | unsigned long speed_offset = |
| 2006 | (unsigned long)&memdev_dmi_entry->speed - |
| 2007 | (unsigned long)&memdev_dmi_entry->type; |
| 2008 | |
| 2009 | /* Check that a DIMM is present */ |
| 2010 | if (memdev_dmi_entry->size == 0) |
| 2011 | return; |
| 2012 | |
| 2013 | /* |
| 2014 | * Pick the configured speed if it's available, otherwise |
| 2015 | * pick the DIMM speed, or we don't have a speed. |
| 2016 | */ |
| 2017 | if (memdev_dmi_entry->length > conf_mem_clk_speed_offset) { |
| 2018 | dmi_mem_clk_speed = |
| 2019 | memdev_dmi_entry->conf_mem_clk_speed; |
| 2020 | } else if (memdev_dmi_entry->length > speed_offset) { |
| 2021 | dmi_mem_clk_speed = memdev_dmi_entry->speed; |
| 2022 | } else { |
| 2023 | *dclk_freq = -1; |
| 2024 | return; |
| 2025 | } |
| 2026 | |
| 2027 | if (*dclk_freq == 0) { |
| 2028 | /* First pass, speed was 0 */ |
| 2029 | if (dmi_mem_clk_speed > 0) { |
| 2030 | /* Set speed if a valid speed is read */ |
| 2031 | *dclk_freq = dmi_mem_clk_speed; |
| 2032 | } else { |
| 2033 | /* Otherwise we don't have a valid speed */ |
| 2034 | *dclk_freq = -1; |
| 2035 | } |
| 2036 | } else if (*dclk_freq > 0 && |
| 2037 | *dclk_freq != dmi_mem_clk_speed) { |
| 2038 | /* |
| 2039 | * If we have a speed, check that all DIMMS are the same |
| 2040 | * speed, otherwise set the speed as invalid. |
| 2041 | */ |
| 2042 | *dclk_freq = -1; |
| 2043 | } |
| 2044 | } |
| 2045 | } |
| 2046 | |
| 2047 | /* |
| 2048 | * The default DCLK frequency is used as a fallback if we |
| 2049 | * fail to find anything reliable in the DMI. The value |
| 2050 | * is taken straight from the datasheet. |
| 2051 | */ |
| 2052 | #define DEFAULT_DCLK_FREQ 800 |
| 2053 | |
| 2054 | static int get_dclk_freq(void) |
| 2055 | { |
| 2056 | int dclk_freq = 0; |
| 2057 | |
| 2058 | dmi_walk(decode_dclk, (void *)&dclk_freq); |
| 2059 | |
| 2060 | if (dclk_freq < 1) |
| 2061 | return DEFAULT_DCLK_FREQ; |
| 2062 | |
| 2063 | return dclk_freq; |
| 2064 | } |
| 2065 | |
Samuel Gabrielsson | e8b6a12 | 2011-03-30 10:21:23 -0300 | [diff] [blame] | 2066 | /* |
| 2067 | * set_sdram_scrub_rate This routine sets byte/sec bandwidth scrub rate |
| 2068 | * to hardware according to SCRUBINTERVAL formula |
| 2069 | * found in datasheet. |
| 2070 | */ |
| 2071 | static int set_sdram_scrub_rate(struct mem_ctl_info *mci, u32 new_bw) |
| 2072 | { |
| 2073 | struct i7core_pvt *pvt = mci->pvt_info; |
| 2074 | struct pci_dev *pdev; |
Samuel Gabrielsson | e8b6a12 | 2011-03-30 10:21:23 -0300 | [diff] [blame] | 2075 | u32 dw_scrub; |
| 2076 | u32 dw_ssr; |
| 2077 | |
| 2078 | /* Get data from the MC register, function 2 */ |
| 2079 | pdev = pvt->pci_mcr[2]; |
| 2080 | if (!pdev) |
| 2081 | return -ENODEV; |
| 2082 | |
| 2083 | pci_read_config_dword(pdev, MC_SCRUB_CONTROL, &dw_scrub); |
| 2084 | |
| 2085 | if (new_bw == 0) { |
| 2086 | /* Prepare to disable petrol scrub */ |
| 2087 | dw_scrub &= ~STARTSCRUB; |
| 2088 | /* Stop the patrol scrub engine */ |
Nils Carlson | 535e9c7 | 2011-08-08 06:21:26 -0300 | [diff] [blame^] | 2089 | write_and_test(pdev, MC_SCRUB_CONTROL, |
| 2090 | dw_scrub & ~SCRUBINTERVAL_MASK); |
Samuel Gabrielsson | e8b6a12 | 2011-03-30 10:21:23 -0300 | [diff] [blame] | 2091 | |
| 2092 | /* Get current status of scrub rate and set bit to disable */ |
| 2093 | pci_read_config_dword(pdev, MC_SSRCONTROL, &dw_ssr); |
| 2094 | dw_ssr &= ~SSR_MODE_MASK; |
| 2095 | dw_ssr |= SSR_MODE_DISABLE; |
| 2096 | } else { |
Nils Carlson | 535e9c7 | 2011-08-08 06:21:26 -0300 | [diff] [blame^] | 2097 | const int cache_line_size = 64; |
| 2098 | const u32 freq_dclk_mhz = pvt->dclk_freq; |
| 2099 | unsigned long long scrub_interval; |
Samuel Gabrielsson | e8b6a12 | 2011-03-30 10:21:23 -0300 | [diff] [blame] | 2100 | /* |
| 2101 | * Translate the desired scrub rate to a register value and |
Nils Carlson | 535e9c7 | 2011-08-08 06:21:26 -0300 | [diff] [blame^] | 2102 | * program the corresponding register value. |
Samuel Gabrielsson | e8b6a12 | 2011-03-30 10:21:23 -0300 | [diff] [blame] | 2103 | */ |
Nils Carlson | 535e9c7 | 2011-08-08 06:21:26 -0300 | [diff] [blame^] | 2104 | scrub_interval = (unsigned long long)freq_dclk_mhz * |
| 2105 | cache_line_size * 1000000 / new_bw; |
| 2106 | |
| 2107 | if (!scrub_interval || scrub_interval > SCRUBINTERVAL_MASK) |
| 2108 | return -EINVAL; |
| 2109 | |
| 2110 | dw_scrub = SCRUBINTERVAL_MASK & scrub_interval; |
Samuel Gabrielsson | e8b6a12 | 2011-03-30 10:21:23 -0300 | [diff] [blame] | 2111 | |
| 2112 | /* Start the patrol scrub engine */ |
| 2113 | pci_write_config_dword(pdev, MC_SCRUB_CONTROL, |
| 2114 | STARTSCRUB | dw_scrub); |
| 2115 | |
| 2116 | /* Get current status of scrub rate and set bit to enable */ |
| 2117 | pci_read_config_dword(pdev, MC_SSRCONTROL, &dw_ssr); |
| 2118 | dw_ssr &= ~SSR_MODE_MASK; |
| 2119 | dw_ssr |= SSR_MODE_ENABLE; |
| 2120 | } |
| 2121 | /* Disable or enable scrubbing */ |
| 2122 | pci_write_config_dword(pdev, MC_SSRCONTROL, dw_ssr); |
| 2123 | |
| 2124 | return new_bw; |
| 2125 | } |
| 2126 | |
| 2127 | /* |
| 2128 | * get_sdram_scrub_rate This routine convert current scrub rate value |
| 2129 | * into byte/sec bandwidth accourding to |
| 2130 | * SCRUBINTERVAL formula found in datasheet. |
| 2131 | */ |
| 2132 | static int get_sdram_scrub_rate(struct mem_ctl_info *mci) |
| 2133 | { |
| 2134 | struct i7core_pvt *pvt = mci->pvt_info; |
| 2135 | struct pci_dev *pdev; |
| 2136 | const u32 cache_line_size = 64; |
Nils Carlson | 535e9c7 | 2011-08-08 06:21:26 -0300 | [diff] [blame^] | 2137 | const u32 freq_dclk_mhz = pvt->dclk_freq; |
| 2138 | unsigned long long scrub_rate; |
Samuel Gabrielsson | e8b6a12 | 2011-03-30 10:21:23 -0300 | [diff] [blame] | 2139 | u32 scrubval; |
| 2140 | |
| 2141 | /* Get data from the MC register, function 2 */ |
| 2142 | pdev = pvt->pci_mcr[2]; |
| 2143 | if (!pdev) |
| 2144 | return -ENODEV; |
| 2145 | |
| 2146 | /* Get current scrub control data */ |
| 2147 | pci_read_config_dword(pdev, MC_SCRUB_CONTROL, &scrubval); |
| 2148 | |
| 2149 | /* Mask highest 8-bits to 0 */ |
Nils Carlson | 535e9c7 | 2011-08-08 06:21:26 -0300 | [diff] [blame^] | 2150 | scrubval &= SCRUBINTERVAL_MASK; |
Samuel Gabrielsson | e8b6a12 | 2011-03-30 10:21:23 -0300 | [diff] [blame] | 2151 | if (!scrubval) |
| 2152 | return 0; |
| 2153 | |
| 2154 | /* Calculate scrub rate value into byte/sec bandwidth */ |
Nils Carlson | 535e9c7 | 2011-08-08 06:21:26 -0300 | [diff] [blame^] | 2155 | scrub_rate = (unsigned long long)freq_dclk_mhz * |
| 2156 | 1000000 * cache_line_size / scrubval; |
| 2157 | return (int)scrub_rate; |
Samuel Gabrielsson | e8b6a12 | 2011-03-30 10:21:23 -0300 | [diff] [blame] | 2158 | } |
| 2159 | |
| 2160 | static void enable_sdram_scrub_setting(struct mem_ctl_info *mci) |
| 2161 | { |
| 2162 | struct i7core_pvt *pvt = mci->pvt_info; |
| 2163 | u32 pci_lock; |
| 2164 | |
| 2165 | /* Unlock writes to pci registers */ |
| 2166 | pci_read_config_dword(pvt->pci_noncore, MC_CFG_CONTROL, &pci_lock); |
| 2167 | pci_lock &= ~0x3; |
| 2168 | pci_write_config_dword(pvt->pci_noncore, MC_CFG_CONTROL, |
| 2169 | pci_lock | MC_CFG_UNLOCK); |
| 2170 | |
| 2171 | mci->set_sdram_scrub_rate = set_sdram_scrub_rate; |
| 2172 | mci->get_sdram_scrub_rate = get_sdram_scrub_rate; |
| 2173 | } |
| 2174 | |
| 2175 | static void disable_sdram_scrub_setting(struct mem_ctl_info *mci) |
| 2176 | { |
| 2177 | struct i7core_pvt *pvt = mci->pvt_info; |
| 2178 | u32 pci_lock; |
| 2179 | |
| 2180 | /* Lock writes to pci registers */ |
| 2181 | pci_read_config_dword(pvt->pci_noncore, MC_CFG_CONTROL, &pci_lock); |
| 2182 | pci_lock &= ~0x3; |
| 2183 | pci_write_config_dword(pvt->pci_noncore, MC_CFG_CONTROL, |
| 2184 | pci_lock | MC_CFG_LOCK); |
| 2185 | } |
| 2186 | |
Hidetoshi Seto | a3aa0a4 | 2010-08-20 04:25:18 -0300 | [diff] [blame] | 2187 | static void i7core_pci_ctl_create(struct i7core_pvt *pvt) |
| 2188 | { |
| 2189 | pvt->i7core_pci = edac_pci_create_generic_ctl( |
| 2190 | &pvt->i7core_dev->pdev[0]->dev, |
| 2191 | EDAC_MOD_STR); |
| 2192 | if (unlikely(!pvt->i7core_pci)) |
Mauro Carvalho Chehab | f9902f2 | 2010-08-21 09:42:05 -0300 | [diff] [blame] | 2193 | i7core_printk(KERN_WARNING, |
| 2194 | "Unable to setup PCI error report via EDAC\n"); |
Hidetoshi Seto | a3aa0a4 | 2010-08-20 04:25:18 -0300 | [diff] [blame] | 2195 | } |
| 2196 | |
| 2197 | static void i7core_pci_ctl_release(struct i7core_pvt *pvt) |
| 2198 | { |
| 2199 | if (likely(pvt->i7core_pci)) |
| 2200 | edac_pci_release_generic_ctl(pvt->i7core_pci); |
| 2201 | else |
| 2202 | i7core_printk(KERN_ERR, |
| 2203 | "Couldn't find mem_ctl_info for socket %d\n", |
| 2204 | pvt->i7core_dev->socket); |
| 2205 | pvt->i7core_pci = NULL; |
| 2206 | } |
| 2207 | |
Hidetoshi Seto | 1c6edbb | 2010-08-20 04:32:33 -0300 | [diff] [blame] | 2208 | static void i7core_unregister_mci(struct i7core_dev *i7core_dev) |
| 2209 | { |
| 2210 | struct mem_ctl_info *mci = i7core_dev->mci; |
| 2211 | struct i7core_pvt *pvt; |
| 2212 | |
| 2213 | if (unlikely(!mci || !mci->pvt_info)) { |
| 2214 | debugf0("MC: " __FILE__ ": %s(): dev = %p\n", |
| 2215 | __func__, &i7core_dev->pdev[0]->dev); |
| 2216 | |
| 2217 | i7core_printk(KERN_ERR, "Couldn't find mci handler\n"); |
| 2218 | return; |
| 2219 | } |
| 2220 | |
| 2221 | pvt = mci->pvt_info; |
| 2222 | |
| 2223 | debugf0("MC: " __FILE__ ": %s(): mci = %p, dev = %p\n", |
| 2224 | __func__, mci, &i7core_dev->pdev[0]->dev); |
| 2225 | |
Samuel Gabrielsson | e8b6a12 | 2011-03-30 10:21:23 -0300 | [diff] [blame] | 2226 | /* Disable scrubrate setting */ |
Mauro Carvalho Chehab | 27100db | 2011-08-04 21:35:27 -0300 | [diff] [blame] | 2227 | if (pvt->enable_scrub) |
| 2228 | disable_sdram_scrub_setting(mci); |
Samuel Gabrielsson | e8b6a12 | 2011-03-30 10:21:23 -0300 | [diff] [blame] | 2229 | |
Borislav Petkov | 4140c54 | 2011-07-18 11:24:46 -0300 | [diff] [blame] | 2230 | atomic_notifier_chain_unregister(&x86_mce_decoder_chain, &i7_mce_dec); |
Hidetoshi Seto | 1c6edbb | 2010-08-20 04:32:33 -0300 | [diff] [blame] | 2231 | |
| 2232 | /* Disable EDAC polling */ |
| 2233 | i7core_pci_ctl_release(pvt); |
| 2234 | |
| 2235 | /* Remove MC sysfs nodes */ |
| 2236 | edac_mc_del_mc(mci->dev); |
| 2237 | |
| 2238 | debugf1("%s: free mci struct\n", mci->ctl_name); |
| 2239 | kfree(mci->ctl_name); |
| 2240 | edac_mc_free(mci); |
| 2241 | i7core_dev->mci = NULL; |
| 2242 | } |
| 2243 | |
Hidetoshi Seto | aace428 | 2010-08-20 04:32:45 -0300 | [diff] [blame] | 2244 | static int i7core_register_mci(struct i7core_dev *i7core_dev) |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 2245 | { |
| 2246 | struct mem_ctl_info *mci; |
| 2247 | struct i7core_pvt *pvt; |
Hidetoshi Seto | aace428 | 2010-08-20 04:32:45 -0300 | [diff] [blame] | 2248 | int rc, channels, csrows; |
| 2249 | |
| 2250 | /* Check the number of active and not disabled channels */ |
| 2251 | rc = i7core_get_active_channels(i7core_dev->socket, &channels, &csrows); |
| 2252 | if (unlikely(rc < 0)) |
| 2253 | return rc; |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 2254 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 2255 | /* allocate a new MC control structure */ |
Hidetoshi Seto | aace428 | 2010-08-20 04:32:45 -0300 | [diff] [blame] | 2256 | mci = edac_mc_alloc(sizeof(*pvt), csrows, channels, i7core_dev->socket); |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 2257 | if (unlikely(!mci)) |
| 2258 | return -ENOMEM; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 2259 | |
Mauro Carvalho Chehab | 3cfd014 | 2010-08-10 23:23:46 -0300 | [diff] [blame] | 2260 | debugf0("MC: " __FILE__ ": %s(): mci = %p, dev = %p\n", |
| 2261 | __func__, mci, &i7core_dev->pdev[0]->dev); |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 2262 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 2263 | pvt = mci->pvt_info; |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 2264 | memset(pvt, 0, sizeof(*pvt)); |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 2265 | |
Mauro Carvalho Chehab | 6d37d24 | 2010-08-20 12:48:26 -0300 | [diff] [blame] | 2266 | /* Associates i7core_dev and mci for future usage */ |
| 2267 | pvt->i7core_dev = i7core_dev; |
| 2268 | i7core_dev->mci = mci; |
| 2269 | |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 2270 | /* |
| 2271 | * FIXME: how to handle RDDR3 at MCI level? It is possible to have |
| 2272 | * Mixed RDDR3/UDDR3 with Nehalem, provided that they are on different |
| 2273 | * memory channels |
| 2274 | */ |
| 2275 | mci->mtype_cap = MEM_FLAG_DDR3; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 2276 | mci->edac_ctl_cap = EDAC_FLAG_NONE; |
| 2277 | mci->edac_cap = EDAC_FLAG_NONE; |
| 2278 | mci->mod_name = "i7core_edac.c"; |
| 2279 | mci->mod_ver = I7CORE_REVISION; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 2280 | mci->ctl_name = kasprintf(GFP_KERNEL, "i7 core #%d", |
| 2281 | i7core_dev->socket); |
| 2282 | mci->dev_name = pci_name(i7core_dev->pdev[0]); |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 2283 | mci->ctl_page_to_phys = NULL; |
Mauro Carvalho Chehab | 1288c18 | 2010-08-10 18:57:01 -0300 | [diff] [blame] | 2284 | |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 2285 | /* Store pci devices at mci for faster access */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 2286 | rc = mci_bind_devs(mci, i7core_dev); |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 2287 | if (unlikely(rc < 0)) |
Hidetoshi Seto | 628c5dd | 2010-08-20 04:28:40 -0300 | [diff] [blame] | 2288 | goto fail0; |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 2289 | |
Hidetoshi Seto | 5939813 | 2010-08-20 04:28:25 -0300 | [diff] [blame] | 2290 | if (pvt->is_registered) |
| 2291 | mci->mc_driver_sysfs_attributes = i7core_sysfs_rdimm_attrs; |
| 2292 | else |
| 2293 | mci->mc_driver_sysfs_attributes = i7core_sysfs_udimm_attrs; |
| 2294 | |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 2295 | /* Get dimm basic config */ |
Hidetoshi Seto | 2e5185f | 2010-08-20 04:32:56 -0300 | [diff] [blame] | 2296 | get_dimm_config(mci); |
Hidetoshi Seto | 5939813 | 2010-08-20 04:28:25 -0300 | [diff] [blame] | 2297 | /* record ptr to the generic device */ |
| 2298 | mci->dev = &i7core_dev->pdev[0]->dev; |
| 2299 | /* Set the function pointer to an actual operation function */ |
| 2300 | mci->edac_check = i7core_check_error; |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 2301 | |
Samuel Gabrielsson | e8b6a12 | 2011-03-30 10:21:23 -0300 | [diff] [blame] | 2302 | /* Enable scrubrate setting */ |
Mauro Carvalho Chehab | 27100db | 2011-08-04 21:35:27 -0300 | [diff] [blame] | 2303 | if (pvt->enable_scrub) |
| 2304 | enable_sdram_scrub_setting(mci); |
Samuel Gabrielsson | e8b6a12 | 2011-03-30 10:21:23 -0300 | [diff] [blame] | 2305 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 2306 | /* add this new MC control structure to EDAC's list of MCs */ |
Mauro Carvalho Chehab | b7c7615 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 2307 | if (unlikely(edac_mc_add_mc(mci))) { |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 2308 | debugf0("MC: " __FILE__ |
| 2309 | ": %s(): failed edac_mc_add_mc()\n", __func__); |
| 2310 | /* FIXME: perhaps some code should go here that disables error |
| 2311 | * reporting if we just enabled it |
| 2312 | */ |
Mauro Carvalho Chehab | b7c7615 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 2313 | |
| 2314 | rc = -EINVAL; |
Hidetoshi Seto | 628c5dd | 2010-08-20 04:28:40 -0300 | [diff] [blame] | 2315 | goto fail0; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 2316 | } |
| 2317 | |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 2318 | /* Default error mask is any memory */ |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 2319 | pvt->inject.channel = 0; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 2320 | pvt->inject.dimm = -1; |
| 2321 | pvt->inject.rank = -1; |
| 2322 | pvt->inject.bank = -1; |
| 2323 | pvt->inject.page = -1; |
| 2324 | pvt->inject.col = -1; |
| 2325 | |
Hidetoshi Seto | a3aa0a4 | 2010-08-20 04:25:18 -0300 | [diff] [blame] | 2326 | /* allocating generic PCI control info */ |
| 2327 | i7core_pci_ctl_create(pvt); |
| 2328 | |
Nils Carlson | 535e9c7 | 2011-08-08 06:21:26 -0300 | [diff] [blame^] | 2329 | /* DCLK for scrub rate setting */ |
| 2330 | pvt->dclk_freq = get_dclk_freq(); |
| 2331 | |
Borislav Petkov | 4140c54 | 2011-07-18 11:24:46 -0300 | [diff] [blame] | 2332 | atomic_notifier_chain_register(&x86_mce_decoder_chain, &i7_mce_dec); |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 2333 | |
Hidetoshi Seto | 628c5dd | 2010-08-20 04:28:40 -0300 | [diff] [blame] | 2334 | return 0; |
| 2335 | |
Hidetoshi Seto | 628c5dd | 2010-08-20 04:28:40 -0300 | [diff] [blame] | 2336 | fail0: |
| 2337 | kfree(mci->ctl_name); |
| 2338 | edac_mc_free(mci); |
Hidetoshi Seto | 1c6edbb | 2010-08-20 04:32:33 -0300 | [diff] [blame] | 2339 | i7core_dev->mci = NULL; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 2340 | return rc; |
| 2341 | } |
| 2342 | |
| 2343 | /* |
| 2344 | * i7core_probe Probe for ONE instance of device to see if it is |
| 2345 | * present. |
| 2346 | * return: |
| 2347 | * 0 for FOUND a device |
| 2348 | * < 0 for error code |
| 2349 | */ |
Mauro Carvalho Chehab | 2d95d81 | 2010-06-30 01:42:21 -0300 | [diff] [blame] | 2350 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 2351 | static int __devinit i7core_probe(struct pci_dev *pdev, |
| 2352 | const struct pci_device_id *id) |
| 2353 | { |
Mauro Carvalho Chehab | 4055759 | 2010-11-30 08:14:30 -0200 | [diff] [blame] | 2354 | int rc, count = 0; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 2355 | struct i7core_dev *i7core_dev; |
| 2356 | |
Mauro Carvalho Chehab | 2d95d81 | 2010-06-30 01:42:21 -0300 | [diff] [blame] | 2357 | /* get the pci devices we want to reserve for our use */ |
| 2358 | mutex_lock(&i7core_edac_lock); |
| 2359 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 2360 | /* |
Mauro Carvalho Chehab | d4c2779 | 2009-09-05 04:12:02 -0300 | [diff] [blame] | 2361 | * All memory controllers are allocated at the first pass. |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 2362 | */ |
Mauro Carvalho Chehab | 2d95d81 | 2010-06-30 01:42:21 -0300 | [diff] [blame] | 2363 | if (unlikely(probed >= 1)) { |
| 2364 | mutex_unlock(&i7core_edac_lock); |
Mauro Carvalho Chehab | 76a7bd8 | 2010-10-24 11:36:19 -0200 | [diff] [blame] | 2365 | return -ENODEV; |
Mauro Carvalho Chehab | 2d95d81 | 2010-06-30 01:42:21 -0300 | [diff] [blame] | 2366 | } |
| 2367 | probed++; |
Mauro Carvalho Chehab | de06eee | 2009-10-14 08:02:40 -0300 | [diff] [blame] | 2368 | |
Hidetoshi Seto | 64c10f6 | 2010-08-20 04:28:14 -0300 | [diff] [blame] | 2369 | rc = i7core_get_all_devices(); |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame] | 2370 | if (unlikely(rc < 0)) |
| 2371 | goto fail0; |
| 2372 | |
| 2373 | list_for_each_entry(i7core_dev, &i7core_edac_list, list) { |
Mauro Carvalho Chehab | 4055759 | 2010-11-30 08:14:30 -0200 | [diff] [blame] | 2374 | count++; |
Hidetoshi Seto | aace428 | 2010-08-20 04:32:45 -0300 | [diff] [blame] | 2375 | rc = i7core_register_mci(i7core_dev); |
Mauro Carvalho Chehab | d4c2779 | 2009-09-05 04:12:02 -0300 | [diff] [blame] | 2376 | if (unlikely(rc < 0)) |
| 2377 | goto fail1; |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 2378 | } |
| 2379 | |
Mauro Carvalho Chehab | 4055759 | 2010-11-30 08:14:30 -0200 | [diff] [blame] | 2380 | /* |
| 2381 | * Nehalem-EX uses a different memory controller. However, as the |
| 2382 | * memory controller is not visible on some Nehalem/Nehalem-EP, we |
| 2383 | * need to indirectly probe via a X58 PCI device. The same devices |
| 2384 | * are found on (some) Nehalem-EX. So, on those machines, the |
| 2385 | * probe routine needs to return -ENODEV, as the actual Memory |
| 2386 | * Controller registers won't be detected. |
| 2387 | */ |
| 2388 | if (!count) { |
| 2389 | rc = -ENODEV; |
| 2390 | goto fail1; |
| 2391 | } |
| 2392 | |
| 2393 | i7core_printk(KERN_INFO, |
| 2394 | "Driver loaded, %d memory controller(s) found.\n", |
| 2395 | count); |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 2396 | |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 2397 | mutex_unlock(&i7core_edac_lock); |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 2398 | return 0; |
| 2399 | |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 2400 | fail1: |
Mauro Carvalho Chehab | 88ef5ea | 2010-08-20 15:39:38 -0300 | [diff] [blame] | 2401 | list_for_each_entry(i7core_dev, &i7core_edac_list, list) |
| 2402 | i7core_unregister_mci(i7core_dev); |
| 2403 | |
Mauro Carvalho Chehab | 13d6e9b | 2009-09-05 12:15:20 -0300 | [diff] [blame] | 2404 | i7core_put_all_devices(); |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 2405 | fail0: |
| 2406 | mutex_unlock(&i7core_edac_lock); |
Mauro Carvalho Chehab | b7c7615 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 2407 | return rc; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 2408 | } |
| 2409 | |
| 2410 | /* |
| 2411 | * i7core_remove destructor for one instance of device |
| 2412 | * |
| 2413 | */ |
| 2414 | static void __devexit i7core_remove(struct pci_dev *pdev) |
| 2415 | { |
Hidetoshi Seto | 64c10f6 | 2010-08-20 04:28:14 -0300 | [diff] [blame] | 2416 | struct i7core_dev *i7core_dev; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 2417 | |
| 2418 | debugf0(__FILE__ ": %s()\n", __func__); |
| 2419 | |
Mauro Carvalho Chehab | 22e6bcb | 2009-09-05 23:06:50 -0300 | [diff] [blame] | 2420 | /* |
| 2421 | * we have a trouble here: pdev value for removal will be wrong, since |
| 2422 | * it will point to the X58 register used to detect that the machine |
| 2423 | * is a Nehalem or upper design. However, due to the way several PCI |
| 2424 | * devices are grouped together to provide MC functionality, we need |
| 2425 | * to use a different method for releasing the devices |
| 2426 | */ |
Mauro Carvalho Chehab | 87d1d27 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 2427 | |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 2428 | mutex_lock(&i7core_edac_lock); |
Hidetoshi Seto | 71fe017 | 2010-08-20 04:29:47 -0300 | [diff] [blame] | 2429 | |
| 2430 | if (unlikely(!probed)) { |
| 2431 | mutex_unlock(&i7core_edac_lock); |
| 2432 | return; |
| 2433 | } |
| 2434 | |
Mauro Carvalho Chehab | 88ef5ea | 2010-08-20 15:39:38 -0300 | [diff] [blame] | 2435 | list_for_each_entry(i7core_dev, &i7core_edac_list, list) |
| 2436 | i7core_unregister_mci(i7core_dev); |
Hidetoshi Seto | 64c10f6 | 2010-08-20 04:28:14 -0300 | [diff] [blame] | 2437 | |
| 2438 | /* Release PCI resources */ |
| 2439 | i7core_put_all_devices(); |
| 2440 | |
Mauro Carvalho Chehab | 2d95d81 | 2010-06-30 01:42:21 -0300 | [diff] [blame] | 2441 | probed--; |
| 2442 | |
Mauro Carvalho Chehab | 22e6bcb | 2009-09-05 23:06:50 -0300 | [diff] [blame] | 2443 | mutex_unlock(&i7core_edac_lock); |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 2444 | } |
| 2445 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 2446 | MODULE_DEVICE_TABLE(pci, i7core_pci_tbl); |
| 2447 | |
| 2448 | /* |
| 2449 | * i7core_driver pci_driver structure for this module |
| 2450 | * |
| 2451 | */ |
| 2452 | static struct pci_driver i7core_driver = { |
| 2453 | .name = "i7core_edac", |
| 2454 | .probe = i7core_probe, |
| 2455 | .remove = __devexit_p(i7core_remove), |
| 2456 | .id_table = i7core_pci_tbl, |
| 2457 | }; |
| 2458 | |
| 2459 | /* |
| 2460 | * i7core_init Module entry function |
| 2461 | * Try to initialize this module for its devices |
| 2462 | */ |
| 2463 | static int __init i7core_init(void) |
| 2464 | { |
| 2465 | int pci_rc; |
| 2466 | |
| 2467 | debugf2("MC: " __FILE__ ": %s()\n", __func__); |
| 2468 | |
| 2469 | /* Ensure that the OPSTATE is set correctly for POLL or NMI */ |
| 2470 | opstate_init(); |
| 2471 | |
Mauro Carvalho Chehab | 54a08ab | 2010-08-19 15:51:00 -0300 | [diff] [blame] | 2472 | if (use_pci_fixup) |
| 2473 | i7core_xeon_pci_fixup(pci_dev_table); |
Keith Mannthey | bc2d724 | 2009-09-03 00:05:05 -0300 | [diff] [blame] | 2474 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 2475 | pci_rc = pci_register_driver(&i7core_driver); |
| 2476 | |
Mauro Carvalho Chehab | 3ef288a | 2009-09-02 23:43:33 -0300 | [diff] [blame] | 2477 | if (pci_rc >= 0) |
| 2478 | return 0; |
| 2479 | |
| 2480 | i7core_printk(KERN_ERR, "Failed to register device with error %d.\n", |
| 2481 | pci_rc); |
| 2482 | |
| 2483 | return pci_rc; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 2484 | } |
| 2485 | |
| 2486 | /* |
| 2487 | * i7core_exit() Module exit function |
| 2488 | * Unregister the driver |
| 2489 | */ |
| 2490 | static void __exit i7core_exit(void) |
| 2491 | { |
| 2492 | debugf2("MC: " __FILE__ ": %s()\n", __func__); |
| 2493 | pci_unregister_driver(&i7core_driver); |
| 2494 | } |
| 2495 | |
| 2496 | module_init(i7core_init); |
| 2497 | module_exit(i7core_exit); |
| 2498 | |
| 2499 | MODULE_LICENSE("GPL"); |
| 2500 | MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>"); |
| 2501 | MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)"); |
| 2502 | MODULE_DESCRIPTION("MC Driver for Intel i7 Core memory controllers - " |
| 2503 | I7CORE_REVISION); |
| 2504 | |
| 2505 | module_param(edac_op_state, int, 0444); |
| 2506 | MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI"); |