Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1 | /* Intel 7 core Memory Controller kernel module (Nehalem) |
| 2 | * |
| 3 | * This file may be distributed under the terms of the |
| 4 | * GNU General Public License version 2 only. |
| 5 | * |
| 6 | * Copyright (c) 2009 by: |
| 7 | * Mauro Carvalho Chehab <mchehab@redhat.com> |
| 8 | * |
| 9 | * Red Hat Inc. http://www.redhat.com |
| 10 | * |
| 11 | * Forked and adapted from the i5400_edac driver |
| 12 | * |
| 13 | * Based on the following public Intel datasheets: |
| 14 | * Intel Core i7 Processor Extreme Edition and Intel Core i7 Processor |
| 15 | * Datasheet, Volume 2: |
| 16 | * http://download.intel.com/design/processor/datashts/320835.pdf |
| 17 | * Intel Xeon Processor 5500 Series Datasheet Volume 2 |
| 18 | * http://www.intel.com/Assets/PDF/datasheet/321322.pdf |
| 19 | * also available at: |
| 20 | * http://www.arrownac.com/manufacturers/intel/s/nehalem/5500-datasheet-v2.pdf |
| 21 | */ |
| 22 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 23 | #include <linux/module.h> |
| 24 | #include <linux/init.h> |
| 25 | #include <linux/pci.h> |
| 26 | #include <linux/pci_ids.h> |
| 27 | #include <linux/slab.h> |
| 28 | #include <linux/edac.h> |
| 29 | #include <linux/mmzone.h> |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 30 | #include <linux/edac_mce.h> |
| 31 | #include <linux/spinlock.h> |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 32 | #include <linux/smp.h> |
Mauro Carvalho Chehab | 14d2c08 | 2009-09-02 23:52:36 -0300 | [diff] [blame] | 33 | #include <asm/processor.h> |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 34 | |
| 35 | #include "edac_core.h" |
| 36 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 37 | /* |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 38 | * This is used for Nehalem-EP and Nehalem-EX devices, where the non-core |
| 39 | * registers start at bus 255, and are not reported by BIOS. |
| 40 | * We currently find devices with only 2 sockets. In order to support more QPI |
| 41 | * Quick Path Interconnect, just increment this number. |
| 42 | */ |
| 43 | #define MAX_SOCKET_BUSES 2 |
| 44 | |
| 45 | |
| 46 | /* |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 47 | * Alter this version for the module when modifications are made |
| 48 | */ |
| 49 | #define I7CORE_REVISION " Ver: 1.0.0 " __DATE__ |
| 50 | #define EDAC_MOD_STR "i7core_edac" |
| 51 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 52 | /* |
| 53 | * Debug macros |
| 54 | */ |
| 55 | #define i7core_printk(level, fmt, arg...) \ |
| 56 | edac_printk(level, "i7core", fmt, ##arg) |
| 57 | |
| 58 | #define i7core_mc_printk(mci, level, fmt, arg...) \ |
| 59 | edac_mc_chipset_printk(mci, level, "i7core", fmt, ##arg) |
| 60 | |
| 61 | /* |
| 62 | * i7core Memory Controller Registers |
| 63 | */ |
| 64 | |
Mauro Carvalho Chehab | e9bd2e7 | 2009-07-09 22:14:35 -0300 | [diff] [blame] | 65 | /* OFFSETS for Device 0 Function 0 */ |
| 66 | |
| 67 | #define MC_CFG_CONTROL 0x90 |
| 68 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 69 | /* OFFSETS for Device 3 Function 0 */ |
| 70 | |
| 71 | #define MC_CONTROL 0x48 |
| 72 | #define MC_STATUS 0x4c |
| 73 | #define MC_MAX_DOD 0x64 |
| 74 | |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 75 | /* |
| 76 | * OFFSETS for Device 3 Function 4, as inicated on Xeon 5500 datasheet: |
| 77 | * http://www.arrownac.com/manufacturers/intel/s/nehalem/5500-datasheet-v2.pdf |
| 78 | */ |
| 79 | |
| 80 | #define MC_TEST_ERR_RCV1 0x60 |
| 81 | #define DIMM2_COR_ERR(r) ((r) & 0x7fff) |
| 82 | |
| 83 | #define MC_TEST_ERR_RCV0 0x64 |
| 84 | #define DIMM1_COR_ERR(r) (((r) >> 16) & 0x7fff) |
| 85 | #define DIMM0_COR_ERR(r) ((r) & 0x7fff) |
| 86 | |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 87 | /* OFFSETS for Device 3 Function 2, as inicated on Xeon 5500 datasheet */ |
| 88 | #define MC_COR_ECC_CNT_0 0x80 |
| 89 | #define MC_COR_ECC_CNT_1 0x84 |
| 90 | #define MC_COR_ECC_CNT_2 0x88 |
| 91 | #define MC_COR_ECC_CNT_3 0x8c |
| 92 | #define MC_COR_ECC_CNT_4 0x90 |
| 93 | #define MC_COR_ECC_CNT_5 0x94 |
| 94 | |
| 95 | #define DIMM_TOP_COR_ERR(r) (((r) >> 16) & 0x7fff) |
| 96 | #define DIMM_BOT_COR_ERR(r) ((r) & 0x7fff) |
| 97 | |
| 98 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 99 | /* OFFSETS for Devices 4,5 and 6 Function 0 */ |
| 100 | |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 101 | #define MC_CHANNEL_DIMM_INIT_PARAMS 0x58 |
| 102 | #define THREE_DIMMS_PRESENT (1 << 24) |
| 103 | #define SINGLE_QUAD_RANK_PRESENT (1 << 23) |
| 104 | #define QUAD_RANK_PRESENT (1 << 22) |
| 105 | #define REGISTERED_DIMM (1 << 15) |
| 106 | |
Mauro Carvalho Chehab | f122a89 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 107 | #define MC_CHANNEL_MAPPER 0x60 |
| 108 | #define RDLCH(r, ch) ((((r) >> (3 + (ch * 6))) & 0x07) - 1) |
| 109 | #define WRLCH(r, ch) ((((r) >> (ch * 6)) & 0x07) - 1) |
| 110 | |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 111 | #define MC_CHANNEL_RANK_PRESENT 0x7c |
| 112 | #define RANK_PRESENT_MASK 0xffff |
| 113 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 114 | #define MC_CHANNEL_ADDR_MATCH 0xf0 |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 115 | #define MC_CHANNEL_ERROR_MASK 0xf8 |
| 116 | #define MC_CHANNEL_ERROR_INJECT 0xfc |
| 117 | #define INJECT_ADDR_PARITY 0x10 |
| 118 | #define INJECT_ECC 0x08 |
| 119 | #define MASK_CACHELINE 0x06 |
| 120 | #define MASK_FULL_CACHELINE 0x06 |
| 121 | #define MASK_MSB32_CACHELINE 0x04 |
| 122 | #define MASK_LSB32_CACHELINE 0x02 |
| 123 | #define NO_MASK_CACHELINE 0x00 |
| 124 | #define REPEAT_EN 0x01 |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 125 | |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 126 | /* OFFSETS for Devices 4,5 and 6 Function 1 */ |
Mauro Carvalho Chehab | b990538 | 2009-08-05 21:36:35 -0300 | [diff] [blame] | 127 | |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 128 | #define MC_DOD_CH_DIMM0 0x48 |
| 129 | #define MC_DOD_CH_DIMM1 0x4c |
| 130 | #define MC_DOD_CH_DIMM2 0x50 |
| 131 | #define RANKOFFSET_MASK ((1 << 12) | (1 << 11) | (1 << 10)) |
| 132 | #define RANKOFFSET(x) ((x & RANKOFFSET_MASK) >> 10) |
| 133 | #define DIMM_PRESENT_MASK (1 << 9) |
| 134 | #define DIMM_PRESENT(x) (((x) & DIMM_PRESENT_MASK) >> 9) |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 135 | #define MC_DOD_NUMBANK_MASK ((1 << 8) | (1 << 7)) |
| 136 | #define MC_DOD_NUMBANK(x) (((x) & MC_DOD_NUMBANK_MASK) >> 7) |
| 137 | #define MC_DOD_NUMRANK_MASK ((1 << 6) | (1 << 5)) |
| 138 | #define MC_DOD_NUMRANK(x) (((x) & MC_DOD_NUMRANK_MASK) >> 5) |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 139 | #define MC_DOD_NUMROW_MASK ((1 << 4) | (1 << 3) | (1 << 2)) |
Mauro Carvalho Chehab | 5566cb7 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 140 | #define MC_DOD_NUMROW(x) (((x) & MC_DOD_NUMROW_MASK) >> 2) |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 141 | #define MC_DOD_NUMCOL_MASK 3 |
| 142 | #define MC_DOD_NUMCOL(x) ((x) & MC_DOD_NUMCOL_MASK) |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 143 | |
Mauro Carvalho Chehab | f122a89 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 144 | #define MC_RANK_PRESENT 0x7c |
| 145 | |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 146 | #define MC_SAG_CH_0 0x80 |
| 147 | #define MC_SAG_CH_1 0x84 |
| 148 | #define MC_SAG_CH_2 0x88 |
| 149 | #define MC_SAG_CH_3 0x8c |
| 150 | #define MC_SAG_CH_4 0x90 |
| 151 | #define MC_SAG_CH_5 0x94 |
| 152 | #define MC_SAG_CH_6 0x98 |
| 153 | #define MC_SAG_CH_7 0x9c |
| 154 | |
| 155 | #define MC_RIR_LIMIT_CH_0 0x40 |
| 156 | #define MC_RIR_LIMIT_CH_1 0x44 |
| 157 | #define MC_RIR_LIMIT_CH_2 0x48 |
| 158 | #define MC_RIR_LIMIT_CH_3 0x4C |
| 159 | #define MC_RIR_LIMIT_CH_4 0x50 |
| 160 | #define MC_RIR_LIMIT_CH_5 0x54 |
| 161 | #define MC_RIR_LIMIT_CH_6 0x58 |
| 162 | #define MC_RIR_LIMIT_CH_7 0x5C |
| 163 | #define MC_RIR_LIMIT_MASK ((1 << 10) - 1) |
| 164 | |
| 165 | #define MC_RIR_WAY_CH 0x80 |
| 166 | #define MC_RIR_WAY_OFFSET_MASK (((1 << 14) - 1) & ~0x7) |
| 167 | #define MC_RIR_WAY_RANK_MASK 0x7 |
| 168 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 169 | /* |
| 170 | * i7core structs |
| 171 | */ |
| 172 | |
| 173 | #define NUM_CHANS 3 |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 174 | #define MAX_DIMMS 3 /* Max DIMMS per channel */ |
| 175 | #define MAX_MCR_FUNC 4 |
| 176 | #define MAX_CHAN_FUNC 3 |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 177 | |
| 178 | struct i7core_info { |
| 179 | u32 mc_control; |
| 180 | u32 mc_status; |
| 181 | u32 max_dod; |
Mauro Carvalho Chehab | f122a89 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 182 | u32 ch_map; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 183 | }; |
| 184 | |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 185 | |
| 186 | struct i7core_inject { |
| 187 | int enable; |
| 188 | |
| 189 | u32 section; |
| 190 | u32 type; |
| 191 | u32 eccmask; |
| 192 | |
| 193 | /* Error address mask */ |
| 194 | int channel, dimm, rank, bank, page, col; |
| 195 | }; |
| 196 | |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 197 | struct i7core_channel { |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 198 | u32 ranks; |
| 199 | u32 dimms; |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 200 | }; |
| 201 | |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 202 | struct pci_id_descr { |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 203 | int dev; |
| 204 | int func; |
| 205 | int dev_id; |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 206 | }; |
| 207 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 208 | struct i7core_dev { |
| 209 | struct list_head list; |
| 210 | u8 socket; |
| 211 | struct pci_dev **pdev; |
| 212 | struct mem_ctl_info *mci; |
| 213 | }; |
| 214 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 215 | struct i7core_pvt { |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 216 | struct pci_dev *pci_noncore; |
| 217 | struct pci_dev *pci_mcr[MAX_MCR_FUNC + 1]; |
| 218 | struct pci_dev *pci_ch[NUM_CHANS][MAX_CHAN_FUNC + 1]; |
| 219 | |
| 220 | struct i7core_dev *i7core_dev; |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 221 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 222 | struct i7core_info info; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 223 | struct i7core_inject inject; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 224 | struct i7core_channel channel[NUM_CHANS]; |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 225 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 226 | int channels; /* Number of active channels */ |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 227 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 228 | int ce_count_available; |
| 229 | int csrow_map[NUM_CHANS][MAX_DIMMS]; |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 230 | |
| 231 | /* ECC corrected errors counts per udimm */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 232 | unsigned long udimm_ce_count[MAX_DIMMS]; |
| 233 | int udimm_last_ce_count[MAX_DIMMS]; |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 234 | /* ECC corrected errors counts per rdimm */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 235 | unsigned long rdimm_ce_count[NUM_CHANS][MAX_DIMMS]; |
| 236 | int rdimm_last_ce_count[NUM_CHANS][MAX_DIMMS]; |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 237 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 238 | unsigned int is_registered; |
Mauro Carvalho Chehab | 14d2c08 | 2009-09-02 23:52:36 -0300 | [diff] [blame] | 239 | |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 240 | /* mcelog glue */ |
| 241 | struct edac_mce edac_mce; |
| 242 | struct mce mce_entry[MCE_LOG_LEN]; |
| 243 | unsigned mce_count; |
| 244 | spinlock_t mce_lock; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 245 | }; |
| 246 | |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 247 | /* Static vars */ |
| 248 | static LIST_HEAD(i7core_edac_list); |
| 249 | static DEFINE_MUTEX(i7core_edac_lock); |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 250 | static u8 max_num_sockets; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 251 | |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 252 | #define PCI_DESCR(device, function, device_id) \ |
| 253 | .dev = (device), \ |
| 254 | .func = (function), \ |
| 255 | .dev_id = (device_id) |
| 256 | |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 257 | struct pci_id_descr pci_dev_descr[] = { |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 258 | /* Memory controller */ |
| 259 | { PCI_DESCR(3, 0, PCI_DEVICE_ID_INTEL_I7_MCR) }, |
| 260 | { PCI_DESCR(3, 1, PCI_DEVICE_ID_INTEL_I7_MC_TAD) }, |
Mauro Carvalho Chehab | b990538 | 2009-08-05 21:36:35 -0300 | [diff] [blame] | 261 | { PCI_DESCR(3, 2, PCI_DEVICE_ID_INTEL_I7_MC_RAS) }, /* if RDIMM */ |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 262 | { PCI_DESCR(3, 4, PCI_DEVICE_ID_INTEL_I7_MC_TEST) }, |
| 263 | |
| 264 | /* Channel 0 */ |
| 265 | { PCI_DESCR(4, 0, PCI_DEVICE_ID_INTEL_I7_MC_CH0_CTRL) }, |
| 266 | { PCI_DESCR(4, 1, PCI_DEVICE_ID_INTEL_I7_MC_CH0_ADDR) }, |
| 267 | { PCI_DESCR(4, 2, PCI_DEVICE_ID_INTEL_I7_MC_CH0_RANK) }, |
| 268 | { PCI_DESCR(4, 3, PCI_DEVICE_ID_INTEL_I7_MC_CH0_TC) }, |
| 269 | |
| 270 | /* Channel 1 */ |
| 271 | { PCI_DESCR(5, 0, PCI_DEVICE_ID_INTEL_I7_MC_CH1_CTRL) }, |
| 272 | { PCI_DESCR(5, 1, PCI_DEVICE_ID_INTEL_I7_MC_CH1_ADDR) }, |
| 273 | { PCI_DESCR(5, 2, PCI_DEVICE_ID_INTEL_I7_MC_CH1_RANK) }, |
| 274 | { PCI_DESCR(5, 3, PCI_DEVICE_ID_INTEL_I7_MC_CH1_TC) }, |
| 275 | |
| 276 | /* Channel 2 */ |
| 277 | { PCI_DESCR(6, 0, PCI_DEVICE_ID_INTEL_I7_MC_CH2_CTRL) }, |
| 278 | { PCI_DESCR(6, 1, PCI_DEVICE_ID_INTEL_I7_MC_CH2_ADDR) }, |
| 279 | { PCI_DESCR(6, 2, PCI_DEVICE_ID_INTEL_I7_MC_CH2_RANK) }, |
| 280 | { PCI_DESCR(6, 3, PCI_DEVICE_ID_INTEL_I7_MC_CH2_TC) }, |
Mauro Carvalho Chehab | 310cbb7 | 2009-07-17 00:09:10 -0300 | [diff] [blame] | 281 | |
| 282 | /* Generic Non-core registers */ |
| 283 | /* |
| 284 | * This is the PCI device on i7core and on Xeon 35xx (8086:2c41) |
| 285 | * On Xeon 55xx, however, it has a different id (8086:2c40). So, |
| 286 | * the probing code needs to test for the other address in case of |
| 287 | * failure of this one |
| 288 | */ |
| 289 | { PCI_DESCR(0, 0, PCI_DEVICE_ID_INTEL_I7_NOCORE) }, |
| 290 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 291 | }; |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 292 | #define N_DEVS ARRAY_SIZE(pci_dev_descr) |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 293 | |
| 294 | /* |
| 295 | * pci_device_id table for which devices we are looking for |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 296 | */ |
| 297 | static const struct pci_device_id i7core_pci_tbl[] __devinitdata = { |
Mauro Carvalho Chehab | d1fd4fb | 2009-07-10 18:39:53 -0300 | [diff] [blame] | 298 | {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58_HUB_MGMT)}, |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 299 | {0,} /* 0 terminated list. */ |
| 300 | }; |
| 301 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 302 | static struct edac_pci_ctl_info *i7core_pci; |
| 303 | |
| 304 | /**************************************************************************** |
| 305 | Anciliary status routines |
| 306 | ****************************************************************************/ |
| 307 | |
| 308 | /* MC_CONTROL bits */ |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 309 | #define CH_ACTIVE(pvt, ch) ((pvt)->info.mc_control & (1 << (8 + ch))) |
| 310 | #define ECCx8(pvt) ((pvt)->info.mc_control & (1 << 1)) |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 311 | |
| 312 | /* MC_STATUS bits */ |
Keith Mannthey | 61053fd | 2009-09-02 23:46:59 -0300 | [diff] [blame] | 313 | #define ECC_ENABLED(pvt) ((pvt)->info.mc_status & (1 << 4)) |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 314 | #define CH_DISABLED(pvt, ch) ((pvt)->info.mc_status & (1 << ch)) |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 315 | |
| 316 | /* MC_MAX_DOD read functions */ |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 317 | static inline int numdimms(u32 dimms) |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 318 | { |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 319 | return (dimms & 0x3) + 1; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 320 | } |
| 321 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 322 | static inline int numrank(u32 rank) |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 323 | { |
| 324 | static int ranks[4] = { 1, 2, 4, -EINVAL }; |
| 325 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 326 | return ranks[rank & 0x3]; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 327 | } |
| 328 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 329 | static inline int numbank(u32 bank) |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 330 | { |
| 331 | static int banks[4] = { 4, 8, 16, -EINVAL }; |
| 332 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 333 | return banks[bank & 0x3]; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 334 | } |
| 335 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 336 | static inline int numrow(u32 row) |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 337 | { |
| 338 | static int rows[8] = { |
| 339 | 1 << 12, 1 << 13, 1 << 14, 1 << 15, |
| 340 | 1 << 16, -EINVAL, -EINVAL, -EINVAL, |
| 341 | }; |
| 342 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 343 | return rows[row & 0x7]; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 344 | } |
| 345 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 346 | static inline int numcol(u32 col) |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 347 | { |
| 348 | static int cols[8] = { |
| 349 | 1 << 10, 1 << 11, 1 << 12, -EINVAL, |
| 350 | }; |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 351 | return cols[col & 0x3]; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 352 | } |
| 353 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 354 | static struct i7core_dev *get_i7core_dev(u8 socket) |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 355 | { |
| 356 | struct i7core_dev *i7core_dev; |
| 357 | |
| 358 | list_for_each_entry(i7core_dev, &i7core_edac_list, list) { |
| 359 | if (i7core_dev->socket == socket) |
| 360 | return i7core_dev; |
| 361 | } |
| 362 | |
| 363 | return NULL; |
| 364 | } |
| 365 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 366 | /**************************************************************************** |
| 367 | Memory check routines |
| 368 | ****************************************************************************/ |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 369 | static struct pci_dev *get_pdev_slot_func(u8 socket, unsigned slot, |
| 370 | unsigned func) |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 371 | { |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 372 | struct i7core_dev *i7core_dev = get_i7core_dev(socket); |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 373 | int i; |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 374 | |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 375 | if (!i7core_dev) |
| 376 | return NULL; |
| 377 | |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 378 | for (i = 0; i < N_DEVS; i++) { |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 379 | if (!i7core_dev->pdev[i]) |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 380 | continue; |
| 381 | |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 382 | if (PCI_SLOT(i7core_dev->pdev[i]->devfn) == slot && |
| 383 | PCI_FUNC(i7core_dev->pdev[i]->devfn) == func) { |
| 384 | return i7core_dev->pdev[i]; |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | |
Mauro Carvalho Chehab | eb94fc4 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 388 | return NULL; |
| 389 | } |
| 390 | |
Mauro Carvalho Chehab | ec6df24 | 2009-07-18 10:44:30 -0300 | [diff] [blame] | 391 | /** |
| 392 | * i7core_get_active_channels() - gets the number of channels and csrows |
| 393 | * @socket: Quick Path Interconnect socket |
| 394 | * @channels: Number of channels that will be returned |
| 395 | * @csrows: Number of csrows found |
| 396 | * |
| 397 | * Since EDAC core needs to know in advance the number of available channels |
| 398 | * and csrows, in order to allocate memory for csrows/channels, it is needed |
| 399 | * to run two similar steps. At the first step, implemented on this function, |
| 400 | * it checks the number of csrows/channels present at one socket. |
| 401 | * this is used in order to properly allocate the size of mci components. |
| 402 | * |
| 403 | * It should be noticed that none of the current available datasheets explain |
| 404 | * or even mention how csrows are seen by the memory controller. So, we need |
| 405 | * to add a fake description for csrows. |
| 406 | * So, this driver is attributing one DIMM memory for one csrow. |
| 407 | */ |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 408 | static int i7core_get_active_channels(u8 socket, unsigned *channels, |
| 409 | unsigned *csrows) |
Mauro Carvalho Chehab | eb94fc4 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 410 | { |
| 411 | struct pci_dev *pdev = NULL; |
| 412 | int i, j; |
| 413 | u32 status, control; |
| 414 | |
| 415 | *channels = 0; |
| 416 | *csrows = 0; |
| 417 | |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 418 | pdev = get_pdev_slot_func(socket, 3, 0); |
Mauro Carvalho Chehab | b7c7615 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 419 | if (!pdev) { |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 420 | i7core_printk(KERN_ERR, "Couldn't find socket %d fn 3.0!!!\n", |
| 421 | socket); |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 422 | return -ENODEV; |
Mauro Carvalho Chehab | b7c7615 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 423 | } |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 424 | |
| 425 | /* Device 3 function 0 reads */ |
| 426 | pci_read_config_dword(pdev, MC_STATUS, &status); |
| 427 | pci_read_config_dword(pdev, MC_CONTROL, &control); |
| 428 | |
| 429 | for (i = 0; i < NUM_CHANS; i++) { |
Mauro Carvalho Chehab | eb94fc4 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 430 | u32 dimm_dod[3]; |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 431 | /* Check if the channel is active */ |
| 432 | if (!(control & (1 << (8 + i)))) |
| 433 | continue; |
| 434 | |
| 435 | /* Check if the channel is disabled */ |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 436 | if (status & (1 << i)) |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 437 | continue; |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 438 | |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 439 | pdev = get_pdev_slot_func(socket, i + 4, 1); |
Mauro Carvalho Chehab | eb94fc4 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 440 | if (!pdev) { |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 441 | i7core_printk(KERN_ERR, "Couldn't find socket %d " |
| 442 | "fn %d.%d!!!\n", |
| 443 | socket, i + 4, 1); |
Mauro Carvalho Chehab | eb94fc4 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 444 | return -ENODEV; |
| 445 | } |
| 446 | /* Devices 4-6 function 1 */ |
| 447 | pci_read_config_dword(pdev, |
| 448 | MC_DOD_CH_DIMM0, &dimm_dod[0]); |
| 449 | pci_read_config_dword(pdev, |
| 450 | MC_DOD_CH_DIMM1, &dimm_dod[1]); |
| 451 | pci_read_config_dword(pdev, |
| 452 | MC_DOD_CH_DIMM2, &dimm_dod[2]); |
| 453 | |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 454 | (*channels)++; |
Mauro Carvalho Chehab | eb94fc4 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 455 | |
| 456 | for (j = 0; j < 3; j++) { |
| 457 | if (!DIMM_PRESENT(dimm_dod[j])) |
| 458 | continue; |
| 459 | (*csrows)++; |
| 460 | } |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 461 | } |
| 462 | |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 463 | debugf0("Number of active channels on socket %d: %d\n", |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 464 | socket, *channels); |
Mauro Carvalho Chehab | 1c6fed8 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 465 | |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 466 | return 0; |
| 467 | } |
| 468 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 469 | static int get_dimm_config(struct mem_ctl_info *mci, int *csrow) |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 470 | { |
| 471 | struct i7core_pvt *pvt = mci->pvt_info; |
Mauro Carvalho Chehab | 1c6fed8 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 472 | struct csrow_info *csr; |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 473 | struct pci_dev *pdev; |
Mauro Carvalho Chehab | ba6c5c6 | 2009-07-15 09:02:32 -0300 | [diff] [blame] | 474 | int i, j; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 475 | u8 socket = pvt->i7core_dev->socket; |
Mauro Carvalho Chehab | 5566cb7 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 476 | unsigned long last_page = 0; |
Mauro Carvalho Chehab | 1c6fed8 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 477 | enum edac_type mode; |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 478 | enum mem_type mtype; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 479 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 480 | /* Get data from the MC register, function 0 */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 481 | pdev = pvt->pci_mcr[0]; |
Mauro Carvalho Chehab | 7dd6953 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 482 | if (!pdev) |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 483 | return -ENODEV; |
| 484 | |
Mauro Carvalho Chehab | f122a89 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 485 | /* Device 3 function 0 reads */ |
Mauro Carvalho Chehab | 7dd6953 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 486 | pci_read_config_dword(pdev, MC_CONTROL, &pvt->info.mc_control); |
| 487 | pci_read_config_dword(pdev, MC_STATUS, &pvt->info.mc_status); |
| 488 | pci_read_config_dword(pdev, MC_MAX_DOD, &pvt->info.max_dod); |
| 489 | 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] | 490 | |
Mauro Carvalho Chehab | 17cb7b0 | 2009-07-20 18:48:18 -0300 | [diff] [blame] | 491 | debugf0("QPI %d control=0x%08x status=0x%08x dod=0x%08x map=0x%08x\n", |
| 492 | socket, pvt->info.mc_control, pvt->info.mc_status, |
Mauro Carvalho Chehab | f122a89 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 493 | pvt->info.max_dod, pvt->info.ch_map); |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 494 | |
Mauro Carvalho Chehab | 1c6fed8 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 495 | if (ECC_ENABLED(pvt)) { |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 496 | 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] | 497 | if (ECCx8(pvt)) |
| 498 | mode = EDAC_S8ECD8ED; |
| 499 | else |
| 500 | mode = EDAC_S4ECD4ED; |
| 501 | } else { |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 502 | debugf0("ECC disabled\n"); |
Mauro Carvalho Chehab | 1c6fed8 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 503 | mode = EDAC_NONE; |
| 504 | } |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 505 | |
| 506 | /* FIXME: need to handle the error codes */ |
Mauro Carvalho Chehab | 17cb7b0 | 2009-07-20 18:48:18 -0300 | [diff] [blame] | 507 | debugf0("DOD Max limits: DIMMS: %d, %d-ranked, %d-banked " |
| 508 | "x%x x 0x%x\n", |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 509 | numdimms(pvt->info.max_dod), |
| 510 | numrank(pvt->info.max_dod >> 2), |
Mauro Carvalho Chehab | 276b824 | 2009-07-22 21:45:50 -0300 | [diff] [blame] | 511 | numbank(pvt->info.max_dod >> 4), |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 512 | numrow(pvt->info.max_dod >> 6), |
| 513 | numcol(pvt->info.max_dod >> 9)); |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 514 | |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 515 | for (i = 0; i < NUM_CHANS; i++) { |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 516 | u32 data, dimm_dod[3], value[8]; |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 517 | |
| 518 | if (!CH_ACTIVE(pvt, i)) { |
| 519 | debugf0("Channel %i is not active\n", i); |
| 520 | continue; |
| 521 | } |
| 522 | if (CH_DISABLED(pvt, i)) { |
| 523 | debugf0("Channel %i is disabled\n", i); |
| 524 | continue; |
| 525 | } |
| 526 | |
Mauro Carvalho Chehab | f122a89 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 527 | /* Devices 4-6 function 0 */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 528 | pci_read_config_dword(pvt->pci_ch[i][0], |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 529 | MC_CHANNEL_DIMM_INIT_PARAMS, &data); |
| 530 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 531 | pvt->channel[i].ranks = (data & QUAD_RANK_PRESENT) ? |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 532 | 4 : 2; |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 533 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 534 | if (data & REGISTERED_DIMM) |
| 535 | mtype = MEM_RDDR3; |
Mauro Carvalho Chehab | 14d2c08 | 2009-09-02 23:52:36 -0300 | [diff] [blame] | 536 | else |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 537 | mtype = MEM_DDR3; |
| 538 | #if 0 |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 539 | if (data & THREE_DIMMS_PRESENT) |
| 540 | pvt->channel[i].dimms = 3; |
| 541 | else if (data & SINGLE_QUAD_RANK_PRESENT) |
| 542 | pvt->channel[i].dimms = 1; |
| 543 | else |
| 544 | pvt->channel[i].dimms = 2; |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 545 | #endif |
| 546 | |
| 547 | /* Devices 4-6 function 1 */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 548 | pci_read_config_dword(pvt->pci_ch[i][1], |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 549 | MC_DOD_CH_DIMM0, &dimm_dod[0]); |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 550 | pci_read_config_dword(pvt->pci_ch[i][1], |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 551 | MC_DOD_CH_DIMM1, &dimm_dod[1]); |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 552 | pci_read_config_dword(pvt->pci_ch[i][1], |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 553 | MC_DOD_CH_DIMM2, &dimm_dod[2]); |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 554 | |
Mauro Carvalho Chehab | 1c6fed8 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 555 | debugf0("Ch%d phy rd%d, wr%d (0x%08x): " |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 556 | "%d ranks, %cDIMMs\n", |
Mauro Carvalho Chehab | 1c6fed8 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 557 | i, |
| 558 | RDLCH(pvt->info.ch_map, i), WRLCH(pvt->info.ch_map, i), |
| 559 | data, |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 560 | pvt->channel[i].ranks, |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 561 | (data & REGISTERED_DIMM) ? 'R' : 'U'); |
Mauro Carvalho Chehab | 7dd6953 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 562 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 563 | for (j = 0; j < 3; j++) { |
| 564 | u32 banks, ranks, rows, cols; |
Mauro Carvalho Chehab | 5566cb7 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 565 | u32 size, npages; |
Mauro Carvalho Chehab | 1c6fed8 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 566 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 567 | if (!DIMM_PRESENT(dimm_dod[j])) |
| 568 | continue; |
Mauro Carvalho Chehab | 1c6fed8 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 569 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 570 | banks = numbank(MC_DOD_NUMBANK(dimm_dod[j])); |
| 571 | ranks = numrank(MC_DOD_NUMRANK(dimm_dod[j])); |
| 572 | rows = numrow(MC_DOD_NUMROW(dimm_dod[j])); |
| 573 | cols = numcol(MC_DOD_NUMCOL(dimm_dod[j])); |
Mauro Carvalho Chehab | 1c6fed8 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 574 | |
Mauro Carvalho Chehab | 5566cb7 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 575 | /* DDR3 has 8 I/O banks */ |
| 576 | size = (rows * cols * banks * ranks) >> (20 - 3); |
| 577 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 578 | pvt->channel[i].dimms++; |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 579 | |
Mauro Carvalho Chehab | 17cb7b0 | 2009-07-20 18:48:18 -0300 | [diff] [blame] | 580 | debugf0("\tdimm %d %d Mb offset: %x, " |
| 581 | "bank: %d, rank: %d, row: %#x, col: %#x\n", |
| 582 | j, size, |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 583 | RANKOFFSET(dimm_dod[j]), |
| 584 | banks, ranks, rows, cols); |
| 585 | |
Mauro Carvalho Chehab | eb94fc4 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 586 | #if PAGE_SHIFT > 20 |
| 587 | npages = size >> (PAGE_SHIFT - 20); |
| 588 | #else |
| 589 | npages = size << (20 - PAGE_SHIFT); |
| 590 | #endif |
Mauro Carvalho Chehab | 5566cb7 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 591 | |
Mauro Carvalho Chehab | ba6c5c6 | 2009-07-15 09:02:32 -0300 | [diff] [blame] | 592 | csr = &mci->csrows[*csrow]; |
Mauro Carvalho Chehab | 5566cb7 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 593 | csr->first_page = last_page + 1; |
| 594 | last_page += npages; |
| 595 | csr->last_page = last_page; |
| 596 | csr->nr_pages = npages; |
| 597 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 598 | csr->page_mask = 0; |
Mauro Carvalho Chehab | eb94fc4 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 599 | csr->grain = 8; |
Mauro Carvalho Chehab | ba6c5c6 | 2009-07-15 09:02:32 -0300 | [diff] [blame] | 600 | csr->csrow_idx = *csrow; |
Mauro Carvalho Chehab | eb94fc4 | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 601 | csr->nr_channels = 1; |
| 602 | |
| 603 | csr->channels[0].chan_idx = i; |
| 604 | csr->channels[0].ce_count = 0; |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 605 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 606 | pvt->csrow_map[i][j] = *csrow; |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 607 | |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 608 | switch (banks) { |
| 609 | case 4: |
| 610 | csr->dtype = DEV_X4; |
| 611 | break; |
| 612 | case 8: |
| 613 | csr->dtype = DEV_X8; |
| 614 | break; |
| 615 | case 16: |
| 616 | csr->dtype = DEV_X16; |
| 617 | break; |
| 618 | default: |
| 619 | csr->dtype = DEV_UNKNOWN; |
| 620 | } |
| 621 | |
| 622 | csr->edac_mode = mode; |
| 623 | csr->mtype = mtype; |
| 624 | |
Mauro Carvalho Chehab | ba6c5c6 | 2009-07-15 09:02:32 -0300 | [diff] [blame] | 625 | (*csrow)++; |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | pci_read_config_dword(pdev, MC_SAG_CH_0, &value[0]); |
| 629 | pci_read_config_dword(pdev, MC_SAG_CH_1, &value[1]); |
| 630 | pci_read_config_dword(pdev, MC_SAG_CH_2, &value[2]); |
| 631 | pci_read_config_dword(pdev, MC_SAG_CH_3, &value[3]); |
| 632 | pci_read_config_dword(pdev, MC_SAG_CH_4, &value[4]); |
| 633 | pci_read_config_dword(pdev, MC_SAG_CH_5, &value[5]); |
| 634 | pci_read_config_dword(pdev, MC_SAG_CH_6, &value[6]); |
| 635 | pci_read_config_dword(pdev, MC_SAG_CH_7, &value[7]); |
Mauro Carvalho Chehab | 17cb7b0 | 2009-07-20 18:48:18 -0300 | [diff] [blame] | 636 | debugf1("\t[%i] DIVBY3\tREMOVED\tOFFSET\n", i); |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 637 | for (j = 0; j < 8; j++) |
Mauro Carvalho Chehab | 17cb7b0 | 2009-07-20 18:48:18 -0300 | [diff] [blame] | 638 | debugf1("\t\t%#x\t%#x\t%#x\n", |
Mauro Carvalho Chehab | 854d334 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 639 | (value[j] >> 27) & 0x1, |
| 640 | (value[j] >> 24) & 0x7, |
| 641 | (value[j] && ((1 << 24) - 1))); |
Mauro Carvalho Chehab | 0b2b7b7 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 642 | } |
| 643 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 644 | return 0; |
| 645 | } |
| 646 | |
| 647 | /**************************************************************************** |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 648 | Error insertion routines |
| 649 | ****************************************************************************/ |
| 650 | |
| 651 | /* The i7core has independent error injection features per channel. |
| 652 | However, to have a simpler code, we don't allow enabling error injection |
| 653 | on more than one channel. |
| 654 | Also, since a change at an inject parameter will be applied only at enable, |
| 655 | we're disabling error injection on all write calls to the sysfs nodes that |
| 656 | controls the error code injection. |
| 657 | */ |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 658 | static int disable_inject(struct mem_ctl_info *mci) |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 659 | { |
| 660 | struct i7core_pvt *pvt = mci->pvt_info; |
| 661 | |
| 662 | pvt->inject.enable = 0; |
| 663 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 664 | if (!pvt->pci_ch[pvt->inject.channel][0]) |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 665 | return -ENODEV; |
| 666 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 667 | pci_write_config_dword(pvt->pci_ch[pvt->inject.channel][0], |
Mauro Carvalho Chehab | 4157d9f | 2009-08-05 20:27:15 -0300 | [diff] [blame] | 668 | MC_CHANNEL_ERROR_INJECT, 0); |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 669 | |
| 670 | return 0; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | /* |
| 674 | * i7core inject inject.section |
| 675 | * |
| 676 | * accept and store error injection inject.section value |
| 677 | * bit 0 - refers to the lower 32-byte half cacheline |
| 678 | * bit 1 - refers to the upper 32-byte half cacheline |
| 679 | */ |
| 680 | static ssize_t i7core_inject_section_store(struct mem_ctl_info *mci, |
| 681 | const char *data, size_t count) |
| 682 | { |
| 683 | struct i7core_pvt *pvt = mci->pvt_info; |
| 684 | unsigned long value; |
| 685 | int rc; |
| 686 | |
| 687 | if (pvt->inject.enable) |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 688 | disable_inject(mci); |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 689 | |
| 690 | rc = strict_strtoul(data, 10, &value); |
| 691 | if ((rc < 0) || (value > 3)) |
Mauro Carvalho Chehab | 2068def | 2009-08-05 19:28:27 -0300 | [diff] [blame] | 692 | return -EIO; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 693 | |
| 694 | pvt->inject.section = (u32) value; |
| 695 | return count; |
| 696 | } |
| 697 | |
| 698 | static ssize_t i7core_inject_section_show(struct mem_ctl_info *mci, |
| 699 | char *data) |
| 700 | { |
| 701 | struct i7core_pvt *pvt = mci->pvt_info; |
| 702 | return sprintf(data, "0x%08x\n", pvt->inject.section); |
| 703 | } |
| 704 | |
| 705 | /* |
| 706 | * i7core inject.type |
| 707 | * |
| 708 | * accept and store error injection inject.section value |
| 709 | * bit 0 - repeat enable - Enable error repetition |
| 710 | * bit 1 - inject ECC error |
| 711 | * bit 2 - inject parity error |
| 712 | */ |
| 713 | static ssize_t i7core_inject_type_store(struct mem_ctl_info *mci, |
| 714 | const char *data, size_t count) |
| 715 | { |
| 716 | struct i7core_pvt *pvt = mci->pvt_info; |
| 717 | unsigned long value; |
| 718 | int rc; |
| 719 | |
| 720 | if (pvt->inject.enable) |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 721 | disable_inject(mci); |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 722 | |
| 723 | rc = strict_strtoul(data, 10, &value); |
| 724 | if ((rc < 0) || (value > 7)) |
Mauro Carvalho Chehab | 2068def | 2009-08-05 19:28:27 -0300 | [diff] [blame] | 725 | return -EIO; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 726 | |
| 727 | pvt->inject.type = (u32) value; |
| 728 | return count; |
| 729 | } |
| 730 | |
| 731 | static ssize_t i7core_inject_type_show(struct mem_ctl_info *mci, |
| 732 | char *data) |
| 733 | { |
| 734 | struct i7core_pvt *pvt = mci->pvt_info; |
| 735 | return sprintf(data, "0x%08x\n", pvt->inject.type); |
| 736 | } |
| 737 | |
| 738 | /* |
| 739 | * i7core_inject_inject.eccmask_store |
| 740 | * |
| 741 | * The type of error (UE/CE) will depend on the inject.eccmask value: |
| 742 | * Any bits set to a 1 will flip the corresponding ECC bit |
| 743 | * Correctable errors can be injected by flipping 1 bit or the bits within |
| 744 | * a symbol pair (2 consecutive aligned 8-bit pairs - i.e. 7:0 and 15:8 or |
| 745 | * 23:16 and 31:24). Flipping bits in two symbol pairs will cause an |
| 746 | * uncorrectable error to be injected. |
| 747 | */ |
| 748 | static ssize_t i7core_inject_eccmask_store(struct mem_ctl_info *mci, |
| 749 | const char *data, size_t count) |
| 750 | { |
| 751 | struct i7core_pvt *pvt = mci->pvt_info; |
| 752 | unsigned long value; |
| 753 | int rc; |
| 754 | |
| 755 | if (pvt->inject.enable) |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 756 | disable_inject(mci); |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 757 | |
| 758 | rc = strict_strtoul(data, 10, &value); |
| 759 | if (rc < 0) |
Mauro Carvalho Chehab | 2068def | 2009-08-05 19:28:27 -0300 | [diff] [blame] | 760 | return -EIO; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 761 | |
| 762 | pvt->inject.eccmask = (u32) value; |
| 763 | return count; |
| 764 | } |
| 765 | |
| 766 | static ssize_t i7core_inject_eccmask_show(struct mem_ctl_info *mci, |
| 767 | char *data) |
| 768 | { |
| 769 | struct i7core_pvt *pvt = mci->pvt_info; |
| 770 | return sprintf(data, "0x%08x\n", pvt->inject.eccmask); |
| 771 | } |
| 772 | |
| 773 | /* |
| 774 | * i7core_addrmatch |
| 775 | * |
| 776 | * The type of error (UE/CE) will depend on the inject.eccmask value: |
| 777 | * Any bits set to a 1 will flip the corresponding ECC bit |
| 778 | * Correctable errors can be injected by flipping 1 bit or the bits within |
| 779 | * a symbol pair (2 consecutive aligned 8-bit pairs - i.e. 7:0 and 15:8 or |
| 780 | * 23:16 and 31:24). Flipping bits in two symbol pairs will cause an |
| 781 | * uncorrectable error to be injected. |
| 782 | */ |
| 783 | static ssize_t i7core_inject_addrmatch_store(struct mem_ctl_info *mci, |
| 784 | const char *data, size_t count) |
| 785 | { |
| 786 | struct i7core_pvt *pvt = mci->pvt_info; |
| 787 | char *cmd, *val; |
| 788 | long value; |
| 789 | int rc; |
| 790 | |
| 791 | if (pvt->inject.enable) |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 792 | disable_inject(mci); |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 793 | |
| 794 | do { |
| 795 | cmd = strsep((char **) &data, ":"); |
| 796 | if (!cmd) |
| 797 | break; |
| 798 | val = strsep((char **) &data, " \n\t"); |
| 799 | if (!val) |
| 800 | return cmd - data; |
| 801 | |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 802 | if (!strcasecmp(val, "any")) |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 803 | value = -1; |
| 804 | else { |
| 805 | rc = strict_strtol(val, 10, &value); |
| 806 | if ((rc < 0) || (value < 0)) |
| 807 | return cmd - data; |
| 808 | } |
| 809 | |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 810 | if (!strcasecmp(cmd, "channel")) { |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 811 | if (value < 3) |
| 812 | pvt->inject.channel = value; |
| 813 | else |
| 814 | return cmd - data; |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 815 | } else if (!strcasecmp(cmd, "dimm")) { |
Mauro Carvalho Chehab | 276b824 | 2009-07-22 21:45:50 -0300 | [diff] [blame] | 816 | if (value < 3) |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 817 | pvt->inject.dimm = value; |
| 818 | else |
| 819 | return cmd - data; |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 820 | } else if (!strcasecmp(cmd, "rank")) { |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 821 | if (value < 4) |
| 822 | pvt->inject.rank = value; |
| 823 | else |
| 824 | return cmd - data; |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 825 | } else if (!strcasecmp(cmd, "bank")) { |
Mauro Carvalho Chehab | 276b824 | 2009-07-22 21:45:50 -0300 | [diff] [blame] | 826 | if (value < 32) |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 827 | pvt->inject.bank = value; |
| 828 | else |
| 829 | return cmd - data; |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 830 | } else if (!strcasecmp(cmd, "page")) { |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 831 | if (value <= 0xffff) |
| 832 | pvt->inject.page = value; |
| 833 | else |
| 834 | return cmd - data; |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 835 | } else if (!strcasecmp(cmd, "col") || |
| 836 | !strcasecmp(cmd, "column")) { |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 837 | if (value <= 0x3fff) |
| 838 | pvt->inject.col = value; |
| 839 | else |
| 840 | return cmd - data; |
| 841 | } |
| 842 | } while (1); |
| 843 | |
| 844 | return count; |
| 845 | } |
| 846 | |
| 847 | static ssize_t i7core_inject_addrmatch_show(struct mem_ctl_info *mci, |
| 848 | char *data) |
| 849 | { |
| 850 | struct i7core_pvt *pvt = mci->pvt_info; |
| 851 | char channel[4], dimm[4], bank[4], rank[4], page[7], col[7]; |
| 852 | |
| 853 | if (pvt->inject.channel < 0) |
| 854 | sprintf(channel, "any"); |
| 855 | else |
| 856 | sprintf(channel, "%d", pvt->inject.channel); |
| 857 | if (pvt->inject.dimm < 0) |
| 858 | sprintf(dimm, "any"); |
| 859 | else |
| 860 | sprintf(dimm, "%d", pvt->inject.dimm); |
| 861 | if (pvt->inject.bank < 0) |
| 862 | sprintf(bank, "any"); |
| 863 | else |
| 864 | sprintf(bank, "%d", pvt->inject.bank); |
| 865 | if (pvt->inject.rank < 0) |
| 866 | sprintf(rank, "any"); |
| 867 | else |
| 868 | sprintf(rank, "%d", pvt->inject.rank); |
| 869 | if (pvt->inject.page < 0) |
| 870 | sprintf(page, "any"); |
| 871 | else |
| 872 | sprintf(page, "0x%04x", pvt->inject.page); |
| 873 | if (pvt->inject.col < 0) |
| 874 | sprintf(col, "any"); |
| 875 | else |
| 876 | sprintf(col, "0x%04x", pvt->inject.col); |
| 877 | |
| 878 | return sprintf(data, "channel: %s\ndimm: %s\nbank: %s\n" |
| 879 | "rank: %s\npage: %s\ncolumn: %s\n", |
| 880 | channel, dimm, bank, rank, page, col); |
| 881 | } |
| 882 | |
Mauro Carvalho Chehab | 276b824 | 2009-07-22 21:45:50 -0300 | [diff] [blame] | 883 | static int write_and_test(struct pci_dev *dev, int where, u32 val) |
| 884 | { |
| 885 | u32 read; |
| 886 | int count; |
| 887 | |
Mauro Carvalho Chehab | 4157d9f | 2009-08-05 20:27:15 -0300 | [diff] [blame] | 888 | debugf0("setting pci %02x:%02x.%x reg=%02x value=%08x\n", |
| 889 | dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn), |
| 890 | where, val); |
| 891 | |
Mauro Carvalho Chehab | 276b824 | 2009-07-22 21:45:50 -0300 | [diff] [blame] | 892 | for (count = 0; count < 10; count++) { |
| 893 | if (count) |
Mauro Carvalho Chehab | b990538 | 2009-08-05 21:36:35 -0300 | [diff] [blame] | 894 | msleep(100); |
Mauro Carvalho Chehab | 276b824 | 2009-07-22 21:45:50 -0300 | [diff] [blame] | 895 | pci_write_config_dword(dev, where, val); |
| 896 | pci_read_config_dword(dev, where, &read); |
| 897 | |
| 898 | if (read == val) |
| 899 | return 0; |
| 900 | } |
| 901 | |
Mauro Carvalho Chehab | 4157d9f | 2009-08-05 20:27:15 -0300 | [diff] [blame] | 902 | i7core_printk(KERN_ERR, "Error during set pci %02x:%02x.%x reg=%02x " |
| 903 | "write=%08x. Read=%08x\n", |
| 904 | dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn), |
| 905 | where, val, read); |
Mauro Carvalho Chehab | 276b824 | 2009-07-22 21:45:50 -0300 | [diff] [blame] | 906 | |
| 907 | return -EINVAL; |
| 908 | } |
| 909 | |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 910 | /* |
| 911 | * This routine prepares the Memory Controller for error injection. |
| 912 | * The error will be injected when some process tries to write to the |
| 913 | * memory that matches the given criteria. |
| 914 | * The criteria can be set in terms of a mask where dimm, rank, bank, page |
| 915 | * and col can be specified. |
| 916 | * A -1 value for any of the mask items will make the MCU to ignore |
| 917 | * that matching criteria for error injection. |
| 918 | * |
| 919 | * It should be noticed that the error will only happen after a write operation |
| 920 | * on a memory that matches the condition. if REPEAT_EN is not enabled at |
| 921 | * inject mask, then it will produce just one error. Otherwise, it will repeat |
| 922 | * until the injectmask would be cleaned. |
| 923 | * |
| 924 | * FIXME: This routine assumes that MAXNUMDIMMS value of MC_MAX_DOD |
| 925 | * is reliable enough to check if the MC is using the |
| 926 | * three channels. However, this is not clear at the datasheet. |
| 927 | */ |
| 928 | static ssize_t i7core_inject_enable_store(struct mem_ctl_info *mci, |
| 929 | const char *data, size_t count) |
| 930 | { |
| 931 | struct i7core_pvt *pvt = mci->pvt_info; |
| 932 | u32 injectmask; |
| 933 | u64 mask = 0; |
| 934 | int rc; |
| 935 | long enable; |
| 936 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 937 | if (!pvt->pci_ch[pvt->inject.channel][0]) |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 938 | return 0; |
| 939 | |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 940 | rc = strict_strtoul(data, 10, &enable); |
| 941 | if ((rc < 0)) |
| 942 | return 0; |
| 943 | |
| 944 | if (enable) { |
| 945 | pvt->inject.enable = 1; |
| 946 | } else { |
| 947 | disable_inject(mci); |
| 948 | return count; |
| 949 | } |
| 950 | |
| 951 | /* Sets pvt->inject.dimm mask */ |
| 952 | if (pvt->inject.dimm < 0) |
Mauro Carvalho Chehab | 7b029d0 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 953 | mask |= 1L << 41; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 954 | else { |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 955 | if (pvt->channel[pvt->inject.channel].dimms > 2) |
Mauro Carvalho Chehab | 7b029d0 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 956 | mask |= (pvt->inject.dimm & 0x3L) << 35; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 957 | else |
Mauro Carvalho Chehab | 7b029d0 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 958 | mask |= (pvt->inject.dimm & 0x1L) << 36; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | /* Sets pvt->inject.rank mask */ |
| 962 | if (pvt->inject.rank < 0) |
Mauro Carvalho Chehab | 7b029d0 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 963 | mask |= 1L << 40; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 964 | else { |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 965 | if (pvt->channel[pvt->inject.channel].dimms > 2) |
Mauro Carvalho Chehab | 7b029d0 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 966 | mask |= (pvt->inject.rank & 0x1L) << 34; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 967 | else |
Mauro Carvalho Chehab | 7b029d0 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 968 | mask |= (pvt->inject.rank & 0x3L) << 34; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | /* Sets pvt->inject.bank mask */ |
| 972 | if (pvt->inject.bank < 0) |
Mauro Carvalho Chehab | 7b029d0 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 973 | mask |= 1L << 39; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 974 | else |
Mauro Carvalho Chehab | 7b029d0 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 975 | mask |= (pvt->inject.bank & 0x15L) << 30; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 976 | |
| 977 | /* Sets pvt->inject.page mask */ |
| 978 | if (pvt->inject.page < 0) |
Mauro Carvalho Chehab | 7b029d0 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 979 | mask |= 1L << 38; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 980 | else |
Mauro Carvalho Chehab | 7b029d0 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 981 | mask |= (pvt->inject.page & 0xffffL) << 14; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 982 | |
| 983 | /* Sets pvt->inject.column mask */ |
| 984 | if (pvt->inject.col < 0) |
Mauro Carvalho Chehab | 7b029d0 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 985 | mask |= 1L << 37; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 986 | else |
Mauro Carvalho Chehab | 7b029d0 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 987 | mask |= (pvt->inject.col & 0x3fffL); |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 988 | |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 989 | /* |
| 990 | * bit 0: REPEAT_EN |
| 991 | * bits 1-2: MASK_HALF_CACHELINE |
| 992 | * bit 3: INJECT_ECC |
| 993 | * bit 4: INJECT_ADDR_PARITY |
| 994 | */ |
| 995 | |
Mauro Carvalho Chehab | 7b029d0 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 996 | injectmask = (pvt->inject.type & 1) | |
| 997 | (pvt->inject.section & 0x3) << 1 | |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 998 | (pvt->inject.type & 0x6) << (3 - 1); |
| 999 | |
Mauro Carvalho Chehab | 276b824 | 2009-07-22 21:45:50 -0300 | [diff] [blame] | 1000 | /* Unlock writes to registers - this register is write only */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1001 | pci_write_config_dword(pvt->pci_noncore, |
Mauro Carvalho Chehab | 276b824 | 2009-07-22 21:45:50 -0300 | [diff] [blame] | 1002 | MC_CFG_CONTROL, 0x2); |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1003 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1004 | write_and_test(pvt->pci_ch[pvt->inject.channel][0], |
Mauro Carvalho Chehab | 276b824 | 2009-07-22 21:45:50 -0300 | [diff] [blame] | 1005 | MC_CHANNEL_ADDR_MATCH, mask); |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1006 | write_and_test(pvt->pci_ch[pvt->inject.channel][0], |
Mauro Carvalho Chehab | 276b824 | 2009-07-22 21:45:50 -0300 | [diff] [blame] | 1007 | MC_CHANNEL_ADDR_MATCH + 4, mask >> 32L); |
| 1008 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1009 | write_and_test(pvt->pci_ch[pvt->inject.channel][0], |
Mauro Carvalho Chehab | 276b824 | 2009-07-22 21:45:50 -0300 | [diff] [blame] | 1010 | MC_CHANNEL_ERROR_MASK, pvt->inject.eccmask); |
| 1011 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1012 | write_and_test(pvt->pci_ch[pvt->inject.channel][0], |
Mauro Carvalho Chehab | 4157d9f | 2009-08-05 20:27:15 -0300 | [diff] [blame] | 1013 | MC_CHANNEL_ERROR_INJECT, injectmask); |
Mauro Carvalho Chehab | 276b824 | 2009-07-22 21:45:50 -0300 | [diff] [blame] | 1014 | |
| 1015 | /* |
| 1016 | * This is something undocumented, based on my tests |
| 1017 | * Without writing 8 to this register, errors aren't injected. Not sure |
| 1018 | * why. |
| 1019 | */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1020 | pci_write_config_dword(pvt->pci_noncore, |
Mauro Carvalho Chehab | 276b824 | 2009-07-22 21:45:50 -0300 | [diff] [blame] | 1021 | MC_CFG_CONTROL, 8); |
| 1022 | |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 1023 | debugf0("Error inject addr match 0x%016llx, ecc 0x%08x," |
| 1024 | " inject 0x%08x\n", |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1025 | mask, pvt->inject.eccmask, injectmask); |
| 1026 | |
Mauro Carvalho Chehab | 7b029d0 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1027 | |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1028 | return count; |
| 1029 | } |
| 1030 | |
| 1031 | static ssize_t i7core_inject_enable_show(struct mem_ctl_info *mci, |
| 1032 | char *data) |
| 1033 | { |
| 1034 | struct i7core_pvt *pvt = mci->pvt_info; |
Mauro Carvalho Chehab | 7b029d0 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1035 | u32 injectmask; |
| 1036 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1037 | pci_read_config_dword(pvt->pci_ch[pvt->inject.channel][0], |
Mauro Carvalho Chehab | 4157d9f | 2009-08-05 20:27:15 -0300 | [diff] [blame] | 1038 | MC_CHANNEL_ERROR_INJECT, &injectmask); |
Mauro Carvalho Chehab | 7b029d0 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1039 | |
| 1040 | debugf0("Inject error read: 0x%018x\n", injectmask); |
| 1041 | |
| 1042 | if (injectmask & 0x0c) |
| 1043 | pvt->inject.enable = 1; |
| 1044 | |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1045 | return sprintf(data, "%d\n", pvt->inject.enable); |
| 1046 | } |
| 1047 | |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1048 | static ssize_t i7core_ce_regs_show(struct mem_ctl_info *mci, char *data) |
| 1049 | { |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1050 | unsigned i, count, total = 0; |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1051 | struct i7core_pvt *pvt = mci->pvt_info; |
| 1052 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1053 | if (!pvt->ce_count_available) { |
| 1054 | count = sprintf(data, "data unavailable\n"); |
| 1055 | return 0; |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 1056 | } |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1057 | if (!pvt->is_registered) |
| 1058 | count = sprintf(data, "all channels " |
| 1059 | "UDIMM0: %lu UDIMM1: %lu UDIMM2: %lu\n", |
| 1060 | pvt->udimm_ce_count[0], |
| 1061 | pvt->udimm_ce_count[1], |
| 1062 | pvt->udimm_ce_count[2]); |
| 1063 | else |
| 1064 | for (i = 0; i < NUM_CHANS; i++) { |
| 1065 | count = sprintf(data, "channel %d RDIMM0: %lu " |
| 1066 | "RDIMM1: %lu RDIMM2: %lu\n", |
| 1067 | i, |
| 1068 | pvt->rdimm_ce_count[i][0], |
| 1069 | pvt->rdimm_ce_count[i][1], |
| 1070 | pvt->rdimm_ce_count[i][2]); |
| 1071 | } |
| 1072 | data += count; |
| 1073 | total += count; |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1074 | |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 1075 | return total; |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1076 | } |
| 1077 | |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1078 | /* |
| 1079 | * Sysfs struct |
| 1080 | */ |
| 1081 | static struct mcidev_sysfs_attribute i7core_inj_attrs[] = { |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1082 | { |
| 1083 | .attr = { |
| 1084 | .name = "inject_section", |
| 1085 | .mode = (S_IRUGO | S_IWUSR) |
| 1086 | }, |
| 1087 | .show = i7core_inject_section_show, |
| 1088 | .store = i7core_inject_section_store, |
| 1089 | }, { |
| 1090 | .attr = { |
| 1091 | .name = "inject_type", |
| 1092 | .mode = (S_IRUGO | S_IWUSR) |
| 1093 | }, |
| 1094 | .show = i7core_inject_type_show, |
| 1095 | .store = i7core_inject_type_store, |
| 1096 | }, { |
| 1097 | .attr = { |
| 1098 | .name = "inject_eccmask", |
| 1099 | .mode = (S_IRUGO | S_IWUSR) |
| 1100 | }, |
| 1101 | .show = i7core_inject_eccmask_show, |
| 1102 | .store = i7core_inject_eccmask_store, |
| 1103 | }, { |
| 1104 | .attr = { |
| 1105 | .name = "inject_addrmatch", |
| 1106 | .mode = (S_IRUGO | S_IWUSR) |
| 1107 | }, |
| 1108 | .show = i7core_inject_addrmatch_show, |
| 1109 | .store = i7core_inject_addrmatch_store, |
| 1110 | }, { |
| 1111 | .attr = { |
| 1112 | .name = "inject_enable", |
| 1113 | .mode = (S_IRUGO | S_IWUSR) |
| 1114 | }, |
| 1115 | .show = i7core_inject_enable_show, |
| 1116 | .store = i7core_inject_enable_store, |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1117 | }, { |
| 1118 | .attr = { |
| 1119 | .name = "corrected_error_counts", |
| 1120 | .mode = (S_IRUGO | S_IWUSR) |
| 1121 | }, |
| 1122 | .show = i7core_ce_regs_show, |
| 1123 | .store = NULL, |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1124 | }, |
| 1125 | }; |
| 1126 | |
| 1127 | /**************************************************************************** |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1128 | Device initialization routines: put/get, init/exit |
| 1129 | ****************************************************************************/ |
| 1130 | |
| 1131 | /* |
| 1132 | * i7core_put_devices 'put' all the devices that we have |
| 1133 | * reserved via 'get' |
| 1134 | */ |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1135 | static void i7core_put_devices(void) |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1136 | { |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 1137 | int i, j; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1138 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1139 | for (i = 0; i < max_num_sockets; i++) { |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1140 | struct i7core_dev *i7core_dev = get_i7core_dev(i); |
| 1141 | if (!i7core_dev) |
| 1142 | continue; |
| 1143 | |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 1144 | for (j = 0; j < N_DEVS; j++) |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1145 | pci_dev_put(i7core_dev->pdev[j]); |
| 1146 | |
| 1147 | list_del(&i7core_dev->list); |
| 1148 | kfree(i7core_dev->pdev); |
| 1149 | kfree(i7core_dev); |
| 1150 | } |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1151 | } |
| 1152 | |
Keith Mannthey | bc2d724 | 2009-09-03 00:05:05 -0300 | [diff] [blame] | 1153 | static void i7core_xeon_pci_fixup(void) |
| 1154 | { |
| 1155 | struct pci_dev *pdev = NULL; |
| 1156 | int i; |
| 1157 | /* |
| 1158 | * On Xeon 55xx, the Intel Quckpath Arch Generic Non-core pci buses |
| 1159 | * aren't announced by acpi. So, we need to use a legacy scan probing |
| 1160 | * to detect them |
| 1161 | */ |
| 1162 | pdev = pci_get_device(PCI_VENDOR_ID_INTEL, |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1163 | pci_dev_descr[0].dev_id, NULL); |
Keith Mannthey | bc2d724 | 2009-09-03 00:05:05 -0300 | [diff] [blame] | 1164 | if (unlikely(!pdev)) { |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1165 | for (i = 0; i < MAX_SOCKET_BUSES; i++) |
Keith Mannthey | bc2d724 | 2009-09-03 00:05:05 -0300 | [diff] [blame] | 1166 | pcibios_scan_specific_bus(255-i); |
| 1167 | } |
| 1168 | } |
| 1169 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1170 | /* |
| 1171 | * i7core_get_devices Find and perform 'get' operation on the MCH's |
| 1172 | * device/functions we want to reference for this driver |
| 1173 | * |
| 1174 | * Need to 'get' device 16 func 1 and func 2 |
| 1175 | */ |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1176 | int i7core_get_onedevice(struct pci_dev **prev, int devno) |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1177 | { |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1178 | struct i7core_dev *i7core_dev; |
| 1179 | |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1180 | struct pci_dev *pdev = NULL; |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 1181 | u8 bus = 0; |
| 1182 | u8 socket = 0; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1183 | |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1184 | pdev = pci_get_device(PCI_VENDOR_ID_INTEL, |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1185 | pci_dev_descr[devno].dev_id, *prev); |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1186 | |
| 1187 | /* |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1188 | * On Xeon 55xx, the Intel Quckpath Arch Generic Non-core regs |
| 1189 | * is at addr 8086:2c40, instead of 8086:2c41. So, we need |
| 1190 | * to probe for the alternate address in case of failure |
| 1191 | */ |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1192 | if (pci_dev_descr[devno].dev_id == PCI_DEVICE_ID_INTEL_I7_NOCORE && !pdev) |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1193 | pdev = pci_get_device(PCI_VENDOR_ID_INTEL, |
| 1194 | PCI_DEVICE_ID_INTEL_I7_NOCORE_ALT, *prev); |
Mauro Carvalho Chehab | d1fd4fb | 2009-07-10 18:39:53 -0300 | [diff] [blame] | 1195 | |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1196 | if (!pdev) { |
| 1197 | if (*prev) { |
| 1198 | *prev = pdev; |
| 1199 | return 0; |
Mauro Carvalho Chehab | d1fd4fb | 2009-07-10 18:39:53 -0300 | [diff] [blame] | 1200 | } |
| 1201 | |
Mauro Carvalho Chehab | 310cbb7 | 2009-07-17 00:09:10 -0300 | [diff] [blame] | 1202 | /* |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1203 | * Dev 3 function 2 only exists on chips with RDIMMs |
| 1204 | * so, it is ok to not found it |
Mauro Carvalho Chehab | 310cbb7 | 2009-07-17 00:09:10 -0300 | [diff] [blame] | 1205 | */ |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1206 | if ((pci_dev_descr[devno].dev == 3) && (pci_dev_descr[devno].func == 2)) { |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1207 | *prev = pdev; |
| 1208 | return 0; |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1209 | } |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1210 | |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1211 | i7core_printk(KERN_ERR, |
| 1212 | "Device not found: dev %02x.%d PCI ID %04x:%04x\n", |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1213 | pci_dev_descr[devno].dev, pci_dev_descr[devno].func, |
| 1214 | PCI_VENDOR_ID_INTEL, pci_dev_descr[devno].dev_id); |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1215 | |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1216 | /* End of list, leave */ |
| 1217 | return -ENODEV; |
| 1218 | } |
| 1219 | bus = pdev->bus->number; |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1220 | |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1221 | if (bus == 0x3f) |
| 1222 | socket = 0; |
| 1223 | else |
| 1224 | socket = 255 - bus; |
| 1225 | |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1226 | i7core_dev = get_i7core_dev(socket); |
| 1227 | if (!i7core_dev) { |
| 1228 | i7core_dev = kzalloc(sizeof(*i7core_dev), GFP_KERNEL); |
| 1229 | if (!i7core_dev) |
| 1230 | return -ENOMEM; |
| 1231 | i7core_dev->pdev = kzalloc(sizeof(*i7core_dev->pdev) * N_DEVS, |
| 1232 | GFP_KERNEL); |
| 1233 | if (!i7core_dev->pdev) |
| 1234 | return -ENOMEM; |
| 1235 | i7core_dev->socket = socket; |
| 1236 | list_add_tail(&i7core_dev->list, &i7core_edac_list); |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1237 | } |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1238 | |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1239 | if (i7core_dev->pdev[devno]) { |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1240 | i7core_printk(KERN_ERR, |
| 1241 | "Duplicated device for " |
| 1242 | "dev %02x:%02x.%d PCI ID %04x:%04x\n", |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1243 | bus, pci_dev_descr[devno].dev, pci_dev_descr[devno].func, |
| 1244 | PCI_VENDOR_ID_INTEL, pci_dev_descr[devno].dev_id); |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1245 | pci_dev_put(pdev); |
| 1246 | return -ENODEV; |
| 1247 | } |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1248 | |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1249 | i7core_dev->pdev[devno] = pdev; |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1250 | |
| 1251 | /* Sanity check */ |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1252 | if (unlikely(PCI_SLOT(pdev->devfn) != pci_dev_descr[devno].dev || |
| 1253 | PCI_FUNC(pdev->devfn) != pci_dev_descr[devno].func)) { |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1254 | i7core_printk(KERN_ERR, |
| 1255 | "Device PCI ID %04x:%04x " |
| 1256 | "has dev %02x:%02x.%d instead of dev %02x:%02x.%d\n", |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1257 | PCI_VENDOR_ID_INTEL, pci_dev_descr[devno].dev_id, |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1258 | bus, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1259 | bus, pci_dev_descr[devno].dev, pci_dev_descr[devno].func); |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1260 | return -ENODEV; |
| 1261 | } |
| 1262 | |
| 1263 | /* Be sure that the device is enabled */ |
| 1264 | if (unlikely(pci_enable_device(pdev) < 0)) { |
| 1265 | i7core_printk(KERN_ERR, |
| 1266 | "Couldn't enable " |
| 1267 | "dev %02x:%02x.%d PCI ID %04x:%04x\n", |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1268 | bus, pci_dev_descr[devno].dev, pci_dev_descr[devno].func, |
| 1269 | PCI_VENDOR_ID_INTEL, pci_dev_descr[devno].dev_id); |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1270 | return -ENODEV; |
| 1271 | } |
| 1272 | |
| 1273 | i7core_printk(KERN_INFO, |
| 1274 | "Registered socket %d " |
| 1275 | "dev %02x:%02x.%d PCI ID %04x:%04x\n", |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1276 | socket, bus, pci_dev_descr[devno].dev, pci_dev_descr[devno].func, |
| 1277 | PCI_VENDOR_ID_INTEL, pci_dev_descr[devno].dev_id); |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1278 | |
| 1279 | *prev = pdev; |
| 1280 | |
| 1281 | return 0; |
| 1282 | } |
| 1283 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1284 | static int i7core_get_devices(void) |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1285 | { |
| 1286 | int i; |
| 1287 | struct pci_dev *pdev = NULL; |
| 1288 | |
| 1289 | for (i = 0; i < N_DEVS; i++) { |
| 1290 | pdev = NULL; |
| 1291 | do { |
| 1292 | if (i7core_get_onedevice(&pdev, i) < 0) { |
| 1293 | i7core_put_devices(); |
| 1294 | return -ENODEV; |
| 1295 | } |
| 1296 | } while (pdev); |
| 1297 | } |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1298 | |
Mauro Carvalho Chehab | c77720b | 2009-07-18 10:43:08 -0300 | [diff] [blame] | 1299 | return 0; |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1300 | } |
| 1301 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1302 | static int mci_bind_devs(struct mem_ctl_info *mci, |
| 1303 | struct i7core_dev *i7core_dev) |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1304 | { |
| 1305 | struct i7core_pvt *pvt = mci->pvt_info; |
| 1306 | struct pci_dev *pdev; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1307 | int i, func, slot; |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1308 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1309 | /* Associates i7core_dev and mci for future usage */ |
| 1310 | pvt->i7core_dev = i7core_dev; |
| 1311 | i7core_dev->mci = mci; |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1312 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1313 | pvt->is_registered = 0; |
| 1314 | for (i = 0; i < N_DEVS; i++) { |
| 1315 | pdev = i7core_dev->pdev[i]; |
| 1316 | if (!pdev) |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1317 | continue; |
| 1318 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1319 | func = PCI_FUNC(pdev->devfn); |
| 1320 | slot = PCI_SLOT(pdev->devfn); |
| 1321 | if (slot == 3) { |
| 1322 | if (unlikely(func > MAX_MCR_FUNC)) |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1323 | goto error; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1324 | pvt->pci_mcr[func] = pdev; |
| 1325 | } else if (likely(slot >= 4 && slot < 4 + NUM_CHANS)) { |
| 1326 | if (unlikely(func > MAX_CHAN_FUNC)) |
| 1327 | goto error; |
| 1328 | pvt->pci_ch[slot - 4][func] = pdev; |
| 1329 | } else if (!slot && !func) |
| 1330 | pvt->pci_noncore = pdev; |
| 1331 | else |
| 1332 | goto error; |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1333 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1334 | debugf0("Associated fn %d.%d, dev = %p, socket %d\n", |
| 1335 | PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), |
| 1336 | pdev, i7core_dev->socket); |
Mauro Carvalho Chehab | 14d2c08 | 2009-09-02 23:52:36 -0300 | [diff] [blame] | 1337 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1338 | if (PCI_SLOT(pdev->devfn) == 3 && |
| 1339 | PCI_FUNC(pdev->devfn) == 2) |
| 1340 | pvt->is_registered = 1; |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1341 | } |
Mauro Carvalho Chehab | e9bd2e7 | 2009-07-09 22:14:35 -0300 | [diff] [blame] | 1342 | |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1343 | return 0; |
| 1344 | |
| 1345 | error: |
| 1346 | i7core_printk(KERN_ERR, "Device %d, function %d " |
| 1347 | "is out of the expected range\n", |
| 1348 | slot, func); |
| 1349 | return -EINVAL; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1350 | } |
| 1351 | |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1352 | /**************************************************************************** |
| 1353 | Error check routines |
| 1354 | ****************************************************************************/ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1355 | static void i7core_rdimm_update_csrow(struct mem_ctl_info *mci, |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1356 | int chan, int dimm, int add) |
| 1357 | { |
| 1358 | char *msg; |
| 1359 | struct i7core_pvt *pvt = mci->pvt_info; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1360 | int row = pvt->csrow_map[chan][dimm], i; |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1361 | |
| 1362 | for (i = 0; i < add; i++) { |
| 1363 | msg = kasprintf(GFP_KERNEL, "Corrected error " |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1364 | "(Socket=%d channel=%d dimm=%d)", |
| 1365 | pvt->i7core_dev->socket, chan, dimm); |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1366 | |
| 1367 | edac_mc_handle_fbd_ce(mci, row, 0, msg); |
| 1368 | kfree (msg); |
| 1369 | } |
| 1370 | } |
| 1371 | |
| 1372 | static void i7core_rdimm_update_ce_count(struct mem_ctl_info *mci, |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1373 | int chan, int new0, int new1, int new2) |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1374 | { |
| 1375 | struct i7core_pvt *pvt = mci->pvt_info; |
| 1376 | int add0 = 0, add1 = 0, add2 = 0; |
| 1377 | /* Updates CE counters if it is not the first time here */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1378 | if (pvt->ce_count_available) { |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1379 | /* Updates CE counters */ |
| 1380 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1381 | add2 = new2 - pvt->rdimm_last_ce_count[chan][2]; |
| 1382 | add1 = new1 - pvt->rdimm_last_ce_count[chan][1]; |
| 1383 | add0 = new0 - pvt->rdimm_last_ce_count[chan][0]; |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1384 | |
| 1385 | if (add2 < 0) |
| 1386 | add2 += 0x7fff; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1387 | pvt->rdimm_ce_count[chan][2] += add2; |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1388 | |
| 1389 | if (add1 < 0) |
| 1390 | add1 += 0x7fff; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1391 | pvt->rdimm_ce_count[chan][1] += add1; |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1392 | |
| 1393 | if (add0 < 0) |
| 1394 | add0 += 0x7fff; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1395 | pvt->rdimm_ce_count[chan][0] += add0; |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1396 | } else |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1397 | pvt->ce_count_available = 1; |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1398 | |
| 1399 | /* Store the new values */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1400 | pvt->rdimm_last_ce_count[chan][2] = new2; |
| 1401 | pvt->rdimm_last_ce_count[chan][1] = new1; |
| 1402 | pvt->rdimm_last_ce_count[chan][0] = new0; |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1403 | |
| 1404 | /*updated the edac core */ |
| 1405 | if (add0 != 0) |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1406 | i7core_rdimm_update_csrow(mci, chan, 0, add0); |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1407 | if (add1 != 0) |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1408 | i7core_rdimm_update_csrow(mci, chan, 1, add1); |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1409 | if (add2 != 0) |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1410 | i7core_rdimm_update_csrow(mci, chan, 2, add2); |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1411 | |
| 1412 | } |
| 1413 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1414 | 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] | 1415 | { |
| 1416 | struct i7core_pvt *pvt = mci->pvt_info; |
| 1417 | u32 rcv[3][2]; |
| 1418 | int i, new0, new1, new2; |
| 1419 | |
| 1420 | /*Read DEV 3: FUN 2: MC_COR_ECC_CNT regs directly*/ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1421 | 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] | 1422 | &rcv[0][0]); |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1423 | 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] | 1424 | &rcv[0][1]); |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1425 | 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] | 1426 | &rcv[1][0]); |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1427 | 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] | 1428 | &rcv[1][1]); |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1429 | 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] | 1430 | &rcv[2][0]); |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1431 | 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] | 1432 | &rcv[2][1]); |
| 1433 | for (i = 0 ; i < 3; i++) { |
| 1434 | debugf3("MC_COR_ECC_CNT%d = 0x%x; MC_COR_ECC_CNT%d = 0x%x\n", |
| 1435 | (i * 2), rcv[i][0], (i * 2) + 1, rcv[i][1]); |
| 1436 | /*if the channel has 3 dimms*/ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1437 | if (pvt->channel[i].dimms > 2) { |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1438 | new0 = DIMM_BOT_COR_ERR(rcv[i][0]); |
| 1439 | new1 = DIMM_TOP_COR_ERR(rcv[i][0]); |
| 1440 | new2 = DIMM_BOT_COR_ERR(rcv[i][1]); |
| 1441 | } else { |
| 1442 | new0 = DIMM_TOP_COR_ERR(rcv[i][0]) + |
| 1443 | DIMM_BOT_COR_ERR(rcv[i][0]); |
| 1444 | new1 = DIMM_TOP_COR_ERR(rcv[i][1]) + |
| 1445 | DIMM_BOT_COR_ERR(rcv[i][1]); |
| 1446 | new2 = 0; |
| 1447 | } |
| 1448 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1449 | i7core_rdimm_update_ce_count(mci, i, new0, new1, new2); |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1450 | } |
| 1451 | } |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1452 | |
| 1453 | /* This function is based on the device 3 function 4 registers as described on: |
| 1454 | * Intel Xeon Processor 5500 Series Datasheet Volume 2 |
| 1455 | * http://www.intel.com/Assets/PDF/datasheet/321322.pdf |
| 1456 | * also available at: |
| 1457 | * http://www.arrownac.com/manufacturers/intel/s/nehalem/5500-datasheet-v2.pdf |
| 1458 | */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1459 | 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] | 1460 | { |
| 1461 | struct i7core_pvt *pvt = mci->pvt_info; |
| 1462 | u32 rcv1, rcv0; |
| 1463 | int new0, new1, new2; |
| 1464 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1465 | if (!pvt->pci_mcr[4]) { |
Mauro Carvalho Chehab | b990538 | 2009-08-05 21:36:35 -0300 | [diff] [blame] | 1466 | debugf0("%s MCR registers not found\n", __func__); |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1467 | return; |
| 1468 | } |
| 1469 | |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1470 | /* Corrected test errors */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1471 | pci_read_config_dword(pvt->pci_mcr[4], MC_TEST_ERR_RCV1, &rcv1); |
| 1472 | 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] | 1473 | |
| 1474 | /* Store the new values */ |
| 1475 | new2 = DIMM2_COR_ERR(rcv1); |
| 1476 | new1 = DIMM1_COR_ERR(rcv0); |
| 1477 | new0 = DIMM0_COR_ERR(rcv0); |
| 1478 | |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1479 | /* Updates CE counters if it is not the first time here */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1480 | if (pvt->ce_count_available) { |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1481 | /* Updates CE counters */ |
| 1482 | int add0, add1, add2; |
| 1483 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1484 | add2 = new2 - pvt->udimm_last_ce_count[2]; |
| 1485 | add1 = new1 - pvt->udimm_last_ce_count[1]; |
| 1486 | add0 = new0 - pvt->udimm_last_ce_count[0]; |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1487 | |
| 1488 | if (add2 < 0) |
| 1489 | add2 += 0x7fff; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1490 | pvt->udimm_ce_count[2] += add2; |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1491 | |
| 1492 | if (add1 < 0) |
| 1493 | add1 += 0x7fff; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1494 | pvt->udimm_ce_count[1] += add1; |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1495 | |
| 1496 | if (add0 < 0) |
| 1497 | add0 += 0x7fff; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1498 | pvt->udimm_ce_count[0] += add0; |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1499 | |
| 1500 | if (add0 | add1 | add2) |
| 1501 | i7core_printk(KERN_ERR, "New Corrected error(s): " |
| 1502 | "dimm0: +%d, dimm1: +%d, dimm2 +%d\n", |
| 1503 | add0, add1, add2); |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1504 | } else |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1505 | pvt->ce_count_available = 1; |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1506 | |
| 1507 | /* Store the new values */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1508 | pvt->udimm_last_ce_count[2] = new2; |
| 1509 | pvt->udimm_last_ce_count[1] = new1; |
| 1510 | pvt->udimm_last_ce_count[0] = new0; |
Mauro Carvalho Chehab | 442305b | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1511 | } |
| 1512 | |
Mauro Carvalho Chehab | 8a2f118 | 2009-07-15 19:01:08 -0300 | [diff] [blame] | 1513 | /* |
| 1514 | * According with tables E-11 and E-12 of chapter E.3.3 of Intel 64 and IA-32 |
| 1515 | * Architectures Software Developer’s Manual Volume 3B. |
Mauro Carvalho Chehab | f237fcf | 2009-07-15 19:53:24 -0300 | [diff] [blame] | 1516 | * Nehalem are defined as family 0x06, model 0x1a |
| 1517 | * |
| 1518 | * The MCA registers used here are the following ones: |
Mauro Carvalho Chehab | 8a2f118 | 2009-07-15 19:01:08 -0300 | [diff] [blame] | 1519 | * struct mce field MCA Register |
Mauro Carvalho Chehab | f237fcf | 2009-07-15 19:53:24 -0300 | [diff] [blame] | 1520 | * m->status MSR_IA32_MC8_STATUS |
| 1521 | * m->addr MSR_IA32_MC8_ADDR |
| 1522 | * m->misc MSR_IA32_MC8_MISC |
Mauro Carvalho Chehab | 8a2f118 | 2009-07-15 19:01:08 -0300 | [diff] [blame] | 1523 | * In the case of Nehalem, the error information is masked at .status and .misc |
| 1524 | * fields |
| 1525 | */ |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1526 | static void i7core_mce_output_error(struct mem_ctl_info *mci, |
| 1527 | struct mce *m) |
| 1528 | { |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1529 | struct i7core_pvt *pvt = mci->pvt_info; |
Mauro Carvalho Chehab | a639539 | 2009-07-17 10:54:23 -0300 | [diff] [blame] | 1530 | char *type, *optype, *err, *msg; |
Mauro Carvalho Chehab | 8a2f118 | 2009-07-15 19:01:08 -0300 | [diff] [blame] | 1531 | unsigned long error = m->status & 0x1ff0000l; |
Mauro Carvalho Chehab | a639539 | 2009-07-17 10:54:23 -0300 | [diff] [blame] | 1532 | u32 optypenum = (m->status >> 4) & 0x07; |
Mauro Carvalho Chehab | 8a2f118 | 2009-07-15 19:01:08 -0300 | [diff] [blame] | 1533 | u32 core_err_cnt = (m->status >> 38) && 0x7fff; |
| 1534 | u32 dimm = (m->misc >> 16) & 0x3; |
| 1535 | u32 channel = (m->misc >> 18) & 0x3; |
| 1536 | u32 syndrome = m->misc >> 32; |
| 1537 | u32 errnum = find_first_bit(&error, 32); |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1538 | int csrow; |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1539 | |
Mauro Carvalho Chehab | c5d3452 | 2009-07-17 10:28:15 -0300 | [diff] [blame] | 1540 | if (m->mcgstatus & 1) |
| 1541 | type = "FATAL"; |
| 1542 | else |
| 1543 | type = "NON_FATAL"; |
| 1544 | |
Mauro Carvalho Chehab | a639539 | 2009-07-17 10:54:23 -0300 | [diff] [blame] | 1545 | switch (optypenum) { |
Mauro Carvalho Chehab | b990538 | 2009-08-05 21:36:35 -0300 | [diff] [blame] | 1546 | case 0: |
| 1547 | optype = "generic undef request"; |
| 1548 | break; |
| 1549 | case 1: |
| 1550 | optype = "read error"; |
| 1551 | break; |
| 1552 | case 2: |
| 1553 | optype = "write error"; |
| 1554 | break; |
| 1555 | case 3: |
| 1556 | optype = "addr/cmd error"; |
| 1557 | break; |
| 1558 | case 4: |
| 1559 | optype = "scrubbing error"; |
| 1560 | break; |
| 1561 | default: |
| 1562 | optype = "reserved"; |
| 1563 | break; |
Mauro Carvalho Chehab | a639539 | 2009-07-17 10:54:23 -0300 | [diff] [blame] | 1564 | } |
| 1565 | |
Mauro Carvalho Chehab | 8a2f118 | 2009-07-15 19:01:08 -0300 | [diff] [blame] | 1566 | switch (errnum) { |
| 1567 | case 16: |
| 1568 | err = "read ECC error"; |
| 1569 | break; |
| 1570 | case 17: |
| 1571 | err = "RAS ECC error"; |
| 1572 | break; |
| 1573 | case 18: |
| 1574 | err = "write parity error"; |
| 1575 | break; |
| 1576 | case 19: |
| 1577 | err = "redundacy loss"; |
| 1578 | break; |
| 1579 | case 20: |
| 1580 | err = "reserved"; |
| 1581 | break; |
| 1582 | case 21: |
| 1583 | err = "memory range error"; |
| 1584 | break; |
| 1585 | case 22: |
| 1586 | err = "RTID out of range"; |
| 1587 | break; |
| 1588 | case 23: |
| 1589 | err = "address parity error"; |
| 1590 | break; |
| 1591 | case 24: |
| 1592 | err = "byte enable parity error"; |
| 1593 | break; |
| 1594 | default: |
| 1595 | err = "unknown"; |
| 1596 | } |
| 1597 | |
Mauro Carvalho Chehab | f237fcf | 2009-07-15 19:53:24 -0300 | [diff] [blame] | 1598 | /* FIXME: should convert addr into bank and rank information */ |
Mauro Carvalho Chehab | 8a2f118 | 2009-07-15 19:01:08 -0300 | [diff] [blame] | 1599 | msg = kasprintf(GFP_ATOMIC, |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1600 | "%s (addr = 0x%08llx, cpu=%d, Dimm=%d, Channel=%d, " |
Mauro Carvalho Chehab | a639539 | 2009-07-17 10:54:23 -0300 | [diff] [blame] | 1601 | "syndrome=0x%08x, count=%d, Err=%08llx:%08llx (%s: %s))\n", |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1602 | type, (long long) m->addr, m->cpu, dimm, channel, |
Mauro Carvalho Chehab | a639539 | 2009-07-17 10:54:23 -0300 | [diff] [blame] | 1603 | syndrome, core_err_cnt, (long long)m->status, |
| 1604 | (long long)m->misc, optype, err); |
Mauro Carvalho Chehab | 8a2f118 | 2009-07-15 19:01:08 -0300 | [diff] [blame] | 1605 | |
| 1606 | debugf0("%s", msg); |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1607 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1608 | csrow = pvt->csrow_map[channel][dimm]; |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1609 | |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1610 | /* Call the helper to output message */ |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1611 | if (m->mcgstatus & 1) |
| 1612 | edac_mc_handle_fbd_ue(mci, csrow, 0, |
| 1613 | 0 /* FIXME: should be channel here */, msg); |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1614 | else if (!pvt->is_registered) |
Mauro Carvalho Chehab | b4e8f0b | 2009-09-02 23:49:59 -0300 | [diff] [blame] | 1615 | edac_mc_handle_fbd_ce(mci, csrow, |
| 1616 | 0 /* FIXME: should be channel here */, msg); |
Mauro Carvalho Chehab | 8a2f118 | 2009-07-15 19:01:08 -0300 | [diff] [blame] | 1617 | |
| 1618 | kfree(msg); |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1619 | } |
| 1620 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1621 | /* |
Mauro Carvalho Chehab | 87d1d27 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1622 | * i7core_check_error Retrieve and process errors reported by the |
| 1623 | * hardware. Called by the Core module. |
| 1624 | */ |
| 1625 | static void i7core_check_error(struct mem_ctl_info *mci) |
| 1626 | { |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1627 | struct i7core_pvt *pvt = mci->pvt_info; |
| 1628 | int i; |
| 1629 | unsigned count = 0; |
| 1630 | struct mce *m = NULL; |
| 1631 | unsigned long flags; |
| 1632 | |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1633 | /* Copy all mce errors into a temporary buffer */ |
| 1634 | spin_lock_irqsave(&pvt->mce_lock, flags); |
| 1635 | if (pvt->mce_count) { |
| 1636 | m = kmalloc(sizeof(*m) * pvt->mce_count, GFP_ATOMIC); |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1637 | |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1638 | if (m) { |
| 1639 | count = pvt->mce_count; |
| 1640 | memcpy(m, &pvt->mce_entry, sizeof(*m) * count); |
| 1641 | } |
| 1642 | pvt->mce_count = 0; |
| 1643 | } |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1644 | |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1645 | spin_unlock_irqrestore(&pvt->mce_lock, flags); |
| 1646 | |
| 1647 | /* proccess mcelog errors */ |
| 1648 | for (i = 0; i < count; i++) |
| 1649 | i7core_mce_output_error(mci, &m[i]); |
| 1650 | |
| 1651 | kfree(m); |
| 1652 | |
| 1653 | /* check memory count errors */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1654 | if (!pvt->is_registered) |
| 1655 | i7core_udimm_check_mc_ecc_err(mci); |
| 1656 | else |
| 1657 | i7core_rdimm_check_mc_ecc_err(mci); |
Mauro Carvalho Chehab | 87d1d27 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1658 | } |
| 1659 | |
| 1660 | /* |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1661 | * i7core_mce_check_error Replicates mcelog routine to get errors |
| 1662 | * This routine simply queues mcelog errors, and |
| 1663 | * return. The error itself should be handled later |
| 1664 | * by i7core_check_error. |
| 1665 | */ |
| 1666 | static int i7core_mce_check_error(void *priv, struct mce *mce) |
| 1667 | { |
Mauro Carvalho Chehab | c5d3452 | 2009-07-17 10:28:15 -0300 | [diff] [blame] | 1668 | struct mem_ctl_info *mci = priv; |
| 1669 | struct i7core_pvt *pvt = mci->pvt_info; |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1670 | unsigned long flags; |
| 1671 | |
Mauro Carvalho Chehab | 8a2f118 | 2009-07-15 19:01:08 -0300 | [diff] [blame] | 1672 | /* |
| 1673 | * Just let mcelog handle it if the error is |
| 1674 | * outside the memory controller |
| 1675 | */ |
| 1676 | if (((mce->status & 0xffff) >> 7) != 1) |
| 1677 | return 0; |
| 1678 | |
Mauro Carvalho Chehab | f237fcf | 2009-07-15 19:53:24 -0300 | [diff] [blame] | 1679 | /* Bank 8 registers are the only ones that we know how to handle */ |
| 1680 | if (mce->bank != 8) |
| 1681 | return 0; |
| 1682 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1683 | /* Only handle if it is the right mc controller */ |
| 1684 | if (cpu_data(mce->cpu).phys_proc_id != pvt->i7core_dev->socket) |
| 1685 | return 0; |
| 1686 | |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1687 | spin_lock_irqsave(&pvt->mce_lock, flags); |
| 1688 | if (pvt->mce_count < MCE_LOG_LEN) { |
| 1689 | memcpy(&pvt->mce_entry[pvt->mce_count], mce, sizeof(*mce)); |
| 1690 | pvt->mce_count++; |
| 1691 | } |
| 1692 | spin_unlock_irqrestore(&pvt->mce_lock, flags); |
| 1693 | |
Mauro Carvalho Chehab | c5d3452 | 2009-07-17 10:28:15 -0300 | [diff] [blame] | 1694 | /* Handle fatal errors immediately */ |
| 1695 | if (mce->mcgstatus & 1) |
| 1696 | i7core_check_error(mci); |
| 1697 | |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1698 | /* Advice mcelog that the error were handled */ |
Mauro Carvalho Chehab | 8a2f118 | 2009-07-15 19:01:08 -0300 | [diff] [blame] | 1699 | return 1; |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1700 | } |
| 1701 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1702 | static int i7core_register_mci(struct i7core_dev *i7core_dev, |
| 1703 | int num_channels, int num_csrows) |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1704 | { |
| 1705 | struct mem_ctl_info *mci; |
| 1706 | struct i7core_pvt *pvt; |
Mauro Carvalho Chehab | ba6c5c6 | 2009-07-15 09:02:32 -0300 | [diff] [blame] | 1707 | int csrow = 0; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1708 | int rc; |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1709 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1710 | /* allocate a new MC control structure */ |
| 1711 | mci = edac_mc_alloc(sizeof(*pvt), num_csrows, num_channels, 0); |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1712 | if (unlikely(!mci)) |
| 1713 | return -ENOMEM; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1714 | |
| 1715 | debugf0("MC: " __FILE__ ": %s(): mci = %p\n", __func__, mci); |
| 1716 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1717 | /* record ptr to the generic device */ |
| 1718 | mci->dev = &i7core_dev->pdev[0]->dev; |
| 1719 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1720 | pvt = mci->pvt_info; |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1721 | memset(pvt, 0, sizeof(*pvt)); |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1722 | mci->mc_idx = 0; |
Mauro Carvalho Chehab | 67166af | 2009-07-15 06:56:23 -0300 | [diff] [blame] | 1723 | |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 1724 | /* |
| 1725 | * FIXME: how to handle RDDR3 at MCI level? It is possible to have |
| 1726 | * Mixed RDDR3/UDDR3 with Nehalem, provided that they are on different |
| 1727 | * memory channels |
| 1728 | */ |
| 1729 | mci->mtype_cap = MEM_FLAG_DDR3; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1730 | mci->edac_ctl_cap = EDAC_FLAG_NONE; |
| 1731 | mci->edac_cap = EDAC_FLAG_NONE; |
| 1732 | mci->mod_name = "i7core_edac.c"; |
| 1733 | mci->mod_ver = I7CORE_REVISION; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1734 | mci->ctl_name = kasprintf(GFP_KERNEL, "i7 core #%d", |
| 1735 | i7core_dev->socket); |
| 1736 | mci->dev_name = pci_name(i7core_dev->pdev[0]); |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1737 | mci->ctl_page_to_phys = NULL; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1738 | mci->mc_driver_sysfs_attributes = i7core_inj_attrs; |
Mauro Carvalho Chehab | 87d1d27 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1739 | /* Set the function pointer to an actual operation function */ |
| 1740 | mci->edac_check = i7core_check_error; |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1741 | |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1742 | /* Store pci devices at mci for faster access */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1743 | rc = mci_bind_devs(mci, i7core_dev); |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 1744 | if (unlikely(rc < 0)) |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1745 | goto fail; |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1746 | |
| 1747 | /* Get dimm basic config */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1748 | get_dimm_config(mci, &csrow); |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1749 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1750 | /* 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] | 1751 | if (unlikely(edac_mc_add_mc(mci))) { |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1752 | debugf0("MC: " __FILE__ |
| 1753 | ": %s(): failed edac_mc_add_mc()\n", __func__); |
| 1754 | /* FIXME: perhaps some code should go here that disables error |
| 1755 | * reporting if we just enabled it |
| 1756 | */ |
Mauro Carvalho Chehab | b7c7615 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1757 | |
| 1758 | rc = -EINVAL; |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1759 | goto fail; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1760 | } |
| 1761 | |
| 1762 | /* allocating generic PCI control info */ |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1763 | i7core_pci = edac_pci_create_generic_ctl(&i7core_dev->pdev[0]->dev, |
| 1764 | EDAC_MOD_STR); |
Mauro Carvalho Chehab | 41fcb7f | 2009-06-22 22:48:31 -0300 | [diff] [blame] | 1765 | if (unlikely(!i7core_pci)) { |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1766 | printk(KERN_WARNING |
| 1767 | "%s(): Unable to create PCI control\n", |
| 1768 | __func__); |
| 1769 | printk(KERN_WARNING |
| 1770 | "%s(): PCI error report via EDAC not setup\n", |
| 1771 | __func__); |
| 1772 | } |
| 1773 | |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1774 | /* Default error mask is any memory */ |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1775 | pvt->inject.channel = 0; |
Mauro Carvalho Chehab | 194a40f | 2009-06-22 22:48:28 -0300 | [diff] [blame] | 1776 | pvt->inject.dimm = -1; |
| 1777 | pvt->inject.rank = -1; |
| 1778 | pvt->inject.bank = -1; |
| 1779 | pvt->inject.page = -1; |
| 1780 | pvt->inject.col = -1; |
| 1781 | |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1782 | /* Registers on edac_mce in order to receive memory errors */ |
Mauro Carvalho Chehab | c5d3452 | 2009-07-17 10:28:15 -0300 | [diff] [blame] | 1783 | pvt->edac_mce.priv = mci; |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1784 | pvt->edac_mce.check_error = i7core_mce_check_error; |
| 1785 | spin_lock_init(&pvt->mce_lock); |
| 1786 | |
| 1787 | rc = edac_mce_register(&pvt->edac_mce); |
Mauro Carvalho Chehab | b990538 | 2009-08-05 21:36:35 -0300 | [diff] [blame] | 1788 | if (unlikely(rc < 0)) { |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1789 | debugf0("MC: " __FILE__ |
| 1790 | ": %s(): failed edac_mce_register()\n", __func__); |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1791 | } |
| 1792 | |
| 1793 | fail: |
| 1794 | edac_mc_free(mci); |
| 1795 | return rc; |
| 1796 | } |
| 1797 | |
| 1798 | /* |
| 1799 | * i7core_probe Probe for ONE instance of device to see if it is |
| 1800 | * present. |
| 1801 | * return: |
| 1802 | * 0 for FOUND a device |
| 1803 | * < 0 for error code |
| 1804 | */ |
| 1805 | static int __devinit i7core_probe(struct pci_dev *pdev, |
| 1806 | const struct pci_device_id *id) |
| 1807 | { |
| 1808 | int dev_idx = id->driver_data; |
| 1809 | int rc; |
| 1810 | struct i7core_dev *i7core_dev; |
| 1811 | |
| 1812 | /* |
| 1813 | * FIXME: All memory controllers are allocated at the first pass. |
| 1814 | */ |
| 1815 | if (unlikely(dev_idx >= 1)) |
| 1816 | return -EINVAL; |
| 1817 | |
| 1818 | /* get the pci devices we want to reserve for our use */ |
| 1819 | mutex_lock(&i7core_edac_lock); |
| 1820 | rc = i7core_get_devices(); |
| 1821 | if (unlikely(rc < 0)) |
| 1822 | goto fail0; |
| 1823 | |
| 1824 | list_for_each_entry(i7core_dev, &i7core_edac_list, list) { |
| 1825 | int channels; |
| 1826 | int csrows; |
| 1827 | |
| 1828 | /* Check the number of active and not disabled channels */ |
| 1829 | rc = i7core_get_active_channels(i7core_dev->socket, |
| 1830 | &channels, &csrows); |
| 1831 | if (unlikely(rc < 0)) |
| 1832 | goto fail1; |
| 1833 | |
| 1834 | i7core_register_mci(i7core_dev, channels, csrows); |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1835 | } |
| 1836 | |
Mauro Carvalho Chehab | ef708b5 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1837 | i7core_printk(KERN_INFO, "Driver loaded.\n"); |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1838 | |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1839 | mutex_unlock(&i7core_edac_lock); |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1840 | return 0; |
| 1841 | |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1842 | fail1: |
Mauro Carvalho Chehab | b7c7615 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1843 | i7core_put_devices(); |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1844 | fail0: |
| 1845 | mutex_unlock(&i7core_edac_lock); |
Mauro Carvalho Chehab | b7c7615 | 2009-06-22 22:48:30 -0300 | [diff] [blame] | 1846 | return rc; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | /* |
| 1850 | * i7core_remove destructor for one instance of device |
| 1851 | * |
| 1852 | */ |
| 1853 | static void __devexit i7core_remove(struct pci_dev *pdev) |
| 1854 | { |
| 1855 | struct mem_ctl_info *mci; |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1856 | struct i7core_pvt *pvt; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1857 | |
| 1858 | debugf0(__FILE__ ": %s()\n", __func__); |
| 1859 | |
| 1860 | if (i7core_pci) |
| 1861 | edac_pci_release_generic_ctl(i7core_pci); |
| 1862 | |
Mauro Carvalho Chehab | 87d1d27 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1863 | |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1864 | mci = edac_mc_del_mc(&pdev->dev); |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1865 | if (!mci) |
| 1866 | return; |
| 1867 | |
Mauro Carvalho Chehab | d538164 | 2009-07-09 22:06:41 -0300 | [diff] [blame] | 1868 | /* Unregisters on edac_mce in order to receive memory errors */ |
| 1869 | pvt = mci->pvt_info; |
| 1870 | edac_mce_unregister(&pvt->edac_mce); |
| 1871 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1872 | /* retrieve references to resources, and free those resources */ |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1873 | mutex_lock(&i7core_edac_lock); |
Mauro Carvalho Chehab | 8f33190 | 2009-06-22 22:48:29 -0300 | [diff] [blame] | 1874 | i7core_put_devices(); |
Mauro Carvalho Chehab | 6660770 | 2009-09-05 00:52:11 -0300 | [diff] [blame] | 1875 | mutex_unlock(&i7core_edac_lock); |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1876 | |
Mauro Carvalho Chehab | f474294 | 2009-09-05 02:35:08 -0300 | [diff] [blame^] | 1877 | kfree(mci->ctl_name); |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1878 | edac_mc_free(mci); |
| 1879 | } |
| 1880 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1881 | MODULE_DEVICE_TABLE(pci, i7core_pci_tbl); |
| 1882 | |
| 1883 | /* |
| 1884 | * i7core_driver pci_driver structure for this module |
| 1885 | * |
| 1886 | */ |
| 1887 | static struct pci_driver i7core_driver = { |
| 1888 | .name = "i7core_edac", |
| 1889 | .probe = i7core_probe, |
| 1890 | .remove = __devexit_p(i7core_remove), |
| 1891 | .id_table = i7core_pci_tbl, |
| 1892 | }; |
| 1893 | |
| 1894 | /* |
| 1895 | * i7core_init Module entry function |
| 1896 | * Try to initialize this module for its devices |
| 1897 | */ |
| 1898 | static int __init i7core_init(void) |
| 1899 | { |
| 1900 | int pci_rc; |
| 1901 | |
| 1902 | debugf2("MC: " __FILE__ ": %s()\n", __func__); |
| 1903 | |
| 1904 | /* Ensure that the OPSTATE is set correctly for POLL or NMI */ |
| 1905 | opstate_init(); |
| 1906 | |
Keith Mannthey | bc2d724 | 2009-09-03 00:05:05 -0300 | [diff] [blame] | 1907 | i7core_xeon_pci_fixup(); |
| 1908 | |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1909 | pci_rc = pci_register_driver(&i7core_driver); |
| 1910 | |
Mauro Carvalho Chehab | 3ef288a | 2009-09-02 23:43:33 -0300 | [diff] [blame] | 1911 | if (pci_rc >= 0) |
| 1912 | return 0; |
| 1913 | |
| 1914 | i7core_printk(KERN_ERR, "Failed to register device with error %d.\n", |
| 1915 | pci_rc); |
| 1916 | |
| 1917 | return pci_rc; |
Mauro Carvalho Chehab | a0c36a1 | 2009-06-22 22:41:15 -0300 | [diff] [blame] | 1918 | } |
| 1919 | |
| 1920 | /* |
| 1921 | * i7core_exit() Module exit function |
| 1922 | * Unregister the driver |
| 1923 | */ |
| 1924 | static void __exit i7core_exit(void) |
| 1925 | { |
| 1926 | debugf2("MC: " __FILE__ ": %s()\n", __func__); |
| 1927 | pci_unregister_driver(&i7core_driver); |
| 1928 | } |
| 1929 | |
| 1930 | module_init(i7core_init); |
| 1931 | module_exit(i7core_exit); |
| 1932 | |
| 1933 | MODULE_LICENSE("GPL"); |
| 1934 | MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>"); |
| 1935 | MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)"); |
| 1936 | MODULE_DESCRIPTION("MC Driver for Intel i7 Core memory controllers - " |
| 1937 | I7CORE_REVISION); |
| 1938 | |
| 1939 | module_param(edac_op_state, int, 0444); |
| 1940 | MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI"); |