Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Intel 3000/3010 Memory Controller kernel module |
| 3 | * Copyright (C) 2007 Akamai Technologies, Inc. |
| 4 | * Shamelessly copied from: |
| 5 | * Intel D82875P Memory Controller kernel module |
| 6 | * (C) 2003 Linux Networx (http://lnxi.com) |
| 7 | * |
| 8 | * This file may be distributed under the terms of the |
| 9 | * GNU General Public License. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/pci.h> |
| 15 | #include <linux/pci_ids.h> |
Hitoshi Mitake | 7ed31e0 | 2008-02-07 00:15:02 -0800 | [diff] [blame] | 16 | #include <linux/edac.h> |
Mauro Carvalho Chehab | 78d88e8 | 2016-10-29 15:16:34 -0200 | [diff] [blame] | 17 | #include "edac_module.h" |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 18 | |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 19 | #define EDAC_MOD_STR "i3000_edac" |
| 20 | |
| 21 | #define I3000_RANKS 8 |
| 22 | #define I3000_RANKS_PER_CHANNEL 4 |
| 23 | #define I3000_CHANNELS 2 |
| 24 | |
| 25 | /* Intel 3000 register addresses - device 0 function 0 - DRAM Controller */ |
| 26 | |
| 27 | #define I3000_MCHBAR 0x44 /* MCH Memory Mapped Register BAR */ |
| 28 | #define I3000_MCHBAR_MASK 0xffffc000 |
| 29 | #define I3000_MMR_WINDOW_SIZE 16384 |
| 30 | |
Jason Uhlenkott | ce783d7 | 2008-02-07 00:14:53 -0800 | [diff] [blame] | 31 | #define I3000_EDEAP 0x70 /* Extended DRAM Error Address Pointer (8b) |
| 32 | * |
| 33 | * 7:1 reserved |
| 34 | * 0 bit 32 of address |
| 35 | */ |
| 36 | #define I3000_DEAP 0x58 /* DRAM Error Address Pointer (32b) |
| 37 | * |
| 38 | * 31:7 address |
| 39 | * 6:1 reserved |
| 40 | * 0 Error channel 0/1 |
| 41 | */ |
| 42 | #define I3000_DEAP_GRAIN (1 << 7) |
Jason Uhlenkott | 4d2b165 | 2008-02-07 00:14:54 -0800 | [diff] [blame] | 43 | |
Jason Uhlenkott | 870897a | 2008-02-07 00:15:05 -0800 | [diff] [blame] | 44 | /* |
| 45 | * Helper functions to decode the DEAP/EDEAP hardware registers. |
| 46 | * |
| 47 | * The type promotion here is deliberate; we're deriving an |
| 48 | * unsigned long pfn and offset from hardware regs which are u8/u32. |
| 49 | */ |
| 50 | |
Jason Uhlenkott | 4d2b165 | 2008-02-07 00:14:54 -0800 | [diff] [blame] | 51 | static inline unsigned long deap_pfn(u8 edeap, u32 deap) |
| 52 | { |
| 53 | deap >>= PAGE_SHIFT; |
| 54 | deap |= (edeap & 1) << (32 - PAGE_SHIFT); |
| 55 | return deap; |
| 56 | } |
| 57 | |
| 58 | static inline unsigned long deap_offset(u32 deap) |
| 59 | { |
| 60 | return deap & ~(I3000_DEAP_GRAIN - 1) & ~PAGE_MASK; |
| 61 | } |
| 62 | |
| 63 | static inline int deap_channel(u32 deap) |
| 64 | { |
| 65 | return deap & 1; |
| 66 | } |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 67 | |
Jason Uhlenkott | ce783d7 | 2008-02-07 00:14:53 -0800 | [diff] [blame] | 68 | #define I3000_DERRSYN 0x5c /* DRAM Error Syndrome (8b) |
| 69 | * |
| 70 | * 7:0 DRAM ECC Syndrome |
| 71 | */ |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 72 | |
Jason Uhlenkott | ce783d7 | 2008-02-07 00:14:53 -0800 | [diff] [blame] | 73 | #define I3000_ERRSTS 0xc8 /* Error Status Register (16b) |
| 74 | * |
| 75 | * 15:12 reserved |
| 76 | * 11 MCH Thermal Sensor Event |
| 77 | * for SMI/SCI/SERR |
| 78 | * 10 reserved |
| 79 | * 9 LOCK to non-DRAM Memory Flag (LCKF) |
| 80 | * 8 Received Refresh Timeout Flag (RRTOF) |
| 81 | * 7:2 reserved |
| 82 | * 1 Multi-bit DRAM ECC Error Flag (DMERR) |
| 83 | * 0 Single-bit DRAM ECC Error Flag (DSERR) |
| 84 | */ |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 85 | #define I3000_ERRSTS_BITS 0x0b03 /* bits which indicate errors */ |
| 86 | #define I3000_ERRSTS_UE 0x0002 |
| 87 | #define I3000_ERRSTS_CE 0x0001 |
| 88 | |
Jason Uhlenkott | ce783d7 | 2008-02-07 00:14:53 -0800 | [diff] [blame] | 89 | #define I3000_ERRCMD 0xca /* Error Command (16b) |
| 90 | * |
| 91 | * 15:12 reserved |
| 92 | * 11 SERR on MCH Thermal Sensor Event |
| 93 | * (TSESERR) |
| 94 | * 10 reserved |
| 95 | * 9 SERR on LOCK to non-DRAM Memory |
| 96 | * (LCKERR) |
| 97 | * 8 SERR on DRAM Refresh Timeout |
| 98 | * (DRTOERR) |
| 99 | * 7:2 reserved |
| 100 | * 1 SERR Multi-Bit DRAM ECC Error |
| 101 | * (DMERR) |
| 102 | * 0 SERR on Single-Bit ECC Error |
| 103 | * (DSERR) |
| 104 | */ |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 105 | |
| 106 | /* Intel MMIO register space - device 0 function 0 - MMR space */ |
| 107 | |
| 108 | #define I3000_DRB_SHIFT 25 /* 32MiB grain */ |
| 109 | |
Jason Uhlenkott | ce783d7 | 2008-02-07 00:14:53 -0800 | [diff] [blame] | 110 | #define I3000_C0DRB 0x100 /* Channel 0 DRAM Rank Boundary (8b x 4) |
| 111 | * |
| 112 | * 7:0 Channel 0 DRAM Rank Boundary Address |
| 113 | */ |
| 114 | #define I3000_C1DRB 0x180 /* Channel 1 DRAM Rank Boundary (8b x 4) |
| 115 | * |
| 116 | * 7:0 Channel 1 DRAM Rank Boundary Address |
| 117 | */ |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 118 | |
Jason Uhlenkott | ce783d7 | 2008-02-07 00:14:53 -0800 | [diff] [blame] | 119 | #define I3000_C0DRA 0x108 /* Channel 0 DRAM Rank Attribute (8b x 2) |
| 120 | * |
| 121 | * 7 reserved |
| 122 | * 6:4 DRAM odd Rank Attribute |
| 123 | * 3 reserved |
| 124 | * 2:0 DRAM even Rank Attribute |
| 125 | * |
| 126 | * Each attribute defines the page |
| 127 | * size of the corresponding rank: |
| 128 | * 000: unpopulated |
| 129 | * 001: reserved |
| 130 | * 010: 4 KB |
| 131 | * 011: 8 KB |
| 132 | * 100: 16 KB |
| 133 | * Others: reserved |
| 134 | */ |
| 135 | #define I3000_C1DRA 0x188 /* Channel 1 DRAM Rank Attribute (8b x 2) */ |
Jason Uhlenkott | 4d2b165 | 2008-02-07 00:14:54 -0800 | [diff] [blame] | 136 | |
| 137 | static inline unsigned char odd_rank_attrib(unsigned char dra) |
| 138 | { |
| 139 | return (dra & 0x70) >> 4; |
| 140 | } |
| 141 | |
| 142 | static inline unsigned char even_rank_attrib(unsigned char dra) |
| 143 | { |
| 144 | return dra & 0x07; |
| 145 | } |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 146 | |
Jason Uhlenkott | ce783d7 | 2008-02-07 00:14:53 -0800 | [diff] [blame] | 147 | #define I3000_C0DRC0 0x120 /* DRAM Controller Mode 0 (32b) |
| 148 | * |
| 149 | * 31:30 reserved |
| 150 | * 29 Initialization Complete (IC) |
| 151 | * 28:11 reserved |
| 152 | * 10:8 Refresh Mode Select (RMS) |
| 153 | * 7 reserved |
| 154 | * 6:4 Mode Select (SMS) |
| 155 | * 3:2 reserved |
| 156 | * 1:0 DRAM Type (DT) |
| 157 | */ |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 158 | |
Jason Uhlenkott | ce783d7 | 2008-02-07 00:14:53 -0800 | [diff] [blame] | 159 | #define I3000_C0DRC1 0x124 /* DRAM Controller Mode 1 (32b) |
| 160 | * |
| 161 | * 31 Enhanced Addressing Enable (ENHADE) |
| 162 | * 30:0 reserved |
| 163 | */ |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 164 | |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 165 | enum i3000p_chips { |
| 166 | I3000 = 0, |
| 167 | }; |
| 168 | |
| 169 | struct i3000_dev_info { |
| 170 | const char *ctl_name; |
| 171 | }; |
| 172 | |
| 173 | struct i3000_error_info { |
| 174 | u16 errsts; |
| 175 | u8 derrsyn; |
| 176 | u8 edeap; |
| 177 | u32 deap; |
| 178 | u16 errsts2; |
| 179 | }; |
| 180 | |
| 181 | static const struct i3000_dev_info i3000_devs[] = { |
| 182 | [I3000] = { |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 183 | .ctl_name = "i3000"}, |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 184 | }; |
| 185 | |
Douglas Thompson | f044091 | 2007-07-19 01:50:19 -0700 | [diff] [blame] | 186 | static struct pci_dev *mci_pdev; |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 187 | static int i3000_registered = 1; |
Dave Jiang | 456a2f9 | 2007-07-19 01:50:10 -0700 | [diff] [blame] | 188 | static struct edac_pci_ctl_info *i3000_pci; |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 189 | |
| 190 | static void i3000_get_error_info(struct mem_ctl_info *mci, |
Dave Jiang | 36b8289 | 2007-07-19 01:50:04 -0700 | [diff] [blame] | 191 | struct i3000_error_info *info) |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 192 | { |
| 193 | struct pci_dev *pdev; |
| 194 | |
Mauro Carvalho Chehab | fd68750 | 2012-03-16 07:44:18 -0300 | [diff] [blame] | 195 | pdev = to_pci_dev(mci->pdev); |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 196 | |
| 197 | /* |
| 198 | * This is a mess because there is no atomic way to read all the |
| 199 | * registers at once and the registers can transition from CE being |
| 200 | * overwritten by UE. |
| 201 | */ |
| 202 | pci_read_config_word(pdev, I3000_ERRSTS, &info->errsts); |
| 203 | if (!(info->errsts & I3000_ERRSTS_BITS)) |
| 204 | return; |
| 205 | pci_read_config_byte(pdev, I3000_EDEAP, &info->edeap); |
| 206 | pci_read_config_dword(pdev, I3000_DEAP, &info->deap); |
| 207 | pci_read_config_byte(pdev, I3000_DERRSYN, &info->derrsyn); |
| 208 | pci_read_config_word(pdev, I3000_ERRSTS, &info->errsts2); |
| 209 | |
| 210 | /* |
| 211 | * If the error is the same for both reads then the first set |
| 212 | * of reads is valid. If there is a change then there is a CE |
| 213 | * with no info and the second set of reads is valid and |
| 214 | * should be UE info. |
| 215 | */ |
| 216 | if ((info->errsts ^ info->errsts2) & I3000_ERRSTS_BITS) { |
Dave Jiang | 36b8289 | 2007-07-19 01:50:04 -0700 | [diff] [blame] | 217 | pci_read_config_byte(pdev, I3000_EDEAP, &info->edeap); |
| 218 | pci_read_config_dword(pdev, I3000_DEAP, &info->deap); |
| 219 | pci_read_config_byte(pdev, I3000_DERRSYN, &info->derrsyn); |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Jason Uhlenkott | ce783d7 | 2008-02-07 00:14:53 -0800 | [diff] [blame] | 222 | /* |
| 223 | * Clear any error bits. |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 224 | * (Yes, we really clear bits by writing 1 to them.) |
| 225 | */ |
Dave Jiang | 36b8289 | 2007-07-19 01:50:04 -0700 | [diff] [blame] | 226 | pci_write_bits16(pdev, I3000_ERRSTS, I3000_ERRSTS_BITS, |
| 227 | I3000_ERRSTS_BITS); |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | static int i3000_process_error_info(struct mem_ctl_info *mci, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 231 | struct i3000_error_info *info, |
| 232 | int handle_errors) |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 233 | { |
Jason Uhlenkott | 4d2b165 | 2008-02-07 00:14:54 -0800 | [diff] [blame] | 234 | int row, multi_chan, channel; |
| 235 | unsigned long pfn, offset; |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 236 | |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 237 | multi_chan = mci->csrows[0]->nr_channels - 1; |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 238 | |
| 239 | if (!(info->errsts & I3000_ERRSTS_BITS)) |
| 240 | return 0; |
| 241 | |
| 242 | if (!handle_errors) |
| 243 | return 1; |
| 244 | |
| 245 | if ((info->errsts ^ info->errsts2) & I3000_ERRSTS_BITS) { |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 246 | edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1, 0, 0, 0, |
Mauro Carvalho Chehab | 884906f | 2012-04-16 15:09:00 -0300 | [diff] [blame] | 247 | -1, -1, -1, |
Mauro Carvalho Chehab | 03f7eae | 2012-06-04 11:29:25 -0300 | [diff] [blame] | 248 | "UE overwrote CE", ""); |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 249 | info->errsts = info->errsts2; |
| 250 | } |
| 251 | |
Jason Uhlenkott | 4d2b165 | 2008-02-07 00:14:54 -0800 | [diff] [blame] | 252 | pfn = deap_pfn(info->edeap, info->deap); |
| 253 | offset = deap_offset(info->deap); |
| 254 | channel = deap_channel(info->deap); |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 255 | |
| 256 | row = edac_mc_find_csrow_by_page(mci, pfn); |
| 257 | |
| 258 | if (info->errsts & I3000_ERRSTS_UE) |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 259 | edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1, |
Mauro Carvalho Chehab | 884906f | 2012-04-16 15:09:00 -0300 | [diff] [blame] | 260 | pfn, offset, 0, |
| 261 | row, -1, -1, |
Mauro Carvalho Chehab | 03f7eae | 2012-06-04 11:29:25 -0300 | [diff] [blame] | 262 | "i3000 UE", ""); |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 263 | else |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 264 | edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1, |
Mauro Carvalho Chehab | 884906f | 2012-04-16 15:09:00 -0300 | [diff] [blame] | 265 | pfn, offset, info->derrsyn, |
| 266 | row, multi_chan ? channel : 0, -1, |
Mauro Carvalho Chehab | 03f7eae | 2012-06-04 11:29:25 -0300 | [diff] [blame] | 267 | "i3000 CE", ""); |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 268 | |
| 269 | return 1; |
| 270 | } |
| 271 | |
| 272 | static void i3000_check(struct mem_ctl_info *mci) |
| 273 | { |
| 274 | struct i3000_error_info info; |
| 275 | |
Joe Perches | 956b9ba1 | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 276 | edac_dbg(1, "MC%d\n", mci->mc_idx); |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 277 | i3000_get_error_info(mci, &info); |
| 278 | i3000_process_error_info(mci, &info, 1); |
| 279 | } |
| 280 | |
| 281 | static int i3000_is_interleaved(const unsigned char *c0dra, |
| 282 | const unsigned char *c1dra, |
| 283 | const unsigned char *c0drb, |
| 284 | const unsigned char *c1drb) |
| 285 | { |
| 286 | int i; |
| 287 | |
Jason Uhlenkott | ce783d7 | 2008-02-07 00:14:53 -0800 | [diff] [blame] | 288 | /* |
| 289 | * If the channels aren't populated identically then |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 290 | * we're not interleaved. |
| 291 | */ |
| 292 | for (i = 0; i < I3000_RANKS_PER_CHANNEL / 2; i++) |
Jason Uhlenkott | 4d2b165 | 2008-02-07 00:14:54 -0800 | [diff] [blame] | 293 | if (odd_rank_attrib(c0dra[i]) != odd_rank_attrib(c1dra[i]) || |
| 294 | even_rank_attrib(c0dra[i]) != |
| 295 | even_rank_attrib(c1dra[i])) |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 296 | return 0; |
| 297 | |
Jason Uhlenkott | ce783d7 | 2008-02-07 00:14:53 -0800 | [diff] [blame] | 298 | /* |
| 299 | * If the rank boundaries for the two channels are different |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 300 | * then we're not interleaved. |
| 301 | */ |
| 302 | for (i = 0; i < I3000_RANKS_PER_CHANNEL; i++) |
| 303 | if (c0drb[i] != c1drb[i]) |
| 304 | return 0; |
| 305 | |
| 306 | return 1; |
| 307 | } |
| 308 | |
| 309 | static int i3000_probe1(struct pci_dev *pdev, int dev_idx) |
| 310 | { |
| 311 | int rc; |
Mauro Carvalho Chehab | 084a4fc | 2012-01-27 18:38:08 -0300 | [diff] [blame] | 312 | int i, j; |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 313 | struct mem_ctl_info *mci = NULL; |
Mauro Carvalho Chehab | 884906f | 2012-04-16 15:09:00 -0300 | [diff] [blame] | 314 | struct edac_mc_layer layers[2]; |
Mauro Carvalho Chehab | a895bf8 | 2012-01-28 09:09:38 -0300 | [diff] [blame] | 315 | unsigned long last_cumul_size, nr_pages; |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 316 | int interleaved, nr_channels; |
| 317 | unsigned char dra[I3000_RANKS / 2], drb[I3000_RANKS]; |
| 318 | unsigned char *c0dra = dra, *c1dra = &dra[I3000_RANKS_PER_CHANNEL / 2]; |
| 319 | unsigned char *c0drb = drb, *c1drb = &drb[I3000_RANKS_PER_CHANNEL]; |
| 320 | unsigned long mchbar; |
Al Viro | 0bd8496 | 2007-07-26 17:36:09 +0100 | [diff] [blame] | 321 | void __iomem *window; |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 322 | |
Joe Perches | 956b9ba1 | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 323 | edac_dbg(0, "MC:\n"); |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 324 | |
Dave Jiang | 36b8289 | 2007-07-19 01:50:04 -0700 | [diff] [blame] | 325 | pci_read_config_dword(pdev, I3000_MCHBAR, (u32 *) & mchbar); |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 326 | mchbar &= I3000_MCHBAR_MASK; |
Christoph Hellwig | 4bdc0d6 | 2020-01-06 09:43:50 +0100 | [diff] [blame] | 327 | window = ioremap(mchbar, I3000_MMR_WINDOW_SIZE); |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 328 | if (!window) { |
Dave Jiang | 36b8289 | 2007-07-19 01:50:04 -0700 | [diff] [blame] | 329 | printk(KERN_ERR "i3000: cannot map mmio space at 0x%lx\n", |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 330 | mchbar); |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 331 | return -ENODEV; |
| 332 | } |
| 333 | |
Dave Jiang | 36b8289 | 2007-07-19 01:50:04 -0700 | [diff] [blame] | 334 | c0dra[0] = readb(window + I3000_C0DRA + 0); /* ranks 0,1 */ |
| 335 | c0dra[1] = readb(window + I3000_C0DRA + 1); /* ranks 2,3 */ |
| 336 | c1dra[0] = readb(window + I3000_C1DRA + 0); /* ranks 0,1 */ |
| 337 | c1dra[1] = readb(window + I3000_C1DRA + 1); /* ranks 2,3 */ |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 338 | |
| 339 | for (i = 0; i < I3000_RANKS_PER_CHANNEL; i++) { |
| 340 | c0drb[i] = readb(window + I3000_C0DRB + i); |
| 341 | c1drb[i] = readb(window + I3000_C1DRB + i); |
| 342 | } |
| 343 | |
| 344 | iounmap(window); |
| 345 | |
Jason Uhlenkott | ce783d7 | 2008-02-07 00:14:53 -0800 | [diff] [blame] | 346 | /* |
| 347 | * Figure out how many channels we have. |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 348 | * |
| 349 | * If we have what the datasheet calls "asymmetric channels" |
| 350 | * (essentially the same as what was called "virtual single |
| 351 | * channel mode" in the i82875) then it's a single channel as |
| 352 | * far as EDAC is concerned. |
| 353 | */ |
| 354 | interleaved = i3000_is_interleaved(c0dra, c1dra, c0drb, c1drb); |
| 355 | nr_channels = interleaved ? 2 : 1; |
Mauro Carvalho Chehab | 884906f | 2012-04-16 15:09:00 -0300 | [diff] [blame] | 356 | |
| 357 | layers[0].type = EDAC_MC_LAYER_CHIP_SELECT; |
| 358 | layers[0].size = I3000_RANKS / nr_channels; |
| 359 | layers[0].is_virt_csrow = true; |
| 360 | layers[1].type = EDAC_MC_LAYER_CHANNEL; |
| 361 | layers[1].size = nr_channels; |
| 362 | layers[1].is_virt_csrow = false; |
Mauro Carvalho Chehab | ca0907b | 2012-05-02 14:37:00 -0300 | [diff] [blame] | 363 | mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, 0); |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 364 | if (!mci) |
| 365 | return -ENOMEM; |
| 366 | |
Joe Perches | 956b9ba1 | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 367 | edac_dbg(3, "MC: init mci\n"); |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 368 | |
Mauro Carvalho Chehab | fd68750 | 2012-03-16 07:44:18 -0300 | [diff] [blame] | 369 | mci->pdev = &pdev->dev; |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 370 | mci->mtype_cap = MEM_FLAG_DDR2; |
| 371 | |
| 372 | mci->edac_ctl_cap = EDAC_FLAG_SECDED; |
| 373 | mci->edac_cap = EDAC_FLAG_SECDED; |
| 374 | |
| 375 | mci->mod_name = EDAC_MOD_STR; |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 376 | mci->ctl_name = i3000_devs[dev_idx].ctl_name; |
| 377 | mci->dev_name = pci_name(pdev); |
| 378 | mci->edac_check = i3000_check; |
| 379 | mci->ctl_page_to_phys = NULL; |
| 380 | |
| 381 | /* |
| 382 | * The dram rank boundary (DRB) reg values are boundary addresses |
| 383 | * for each DRAM rank with a granularity of 32MB. DRB regs are |
| 384 | * cumulative; the last one will contain the total memory |
| 385 | * contained in all ranks. |
| 386 | * |
| 387 | * If we're in interleaved mode then we're only walking through |
| 388 | * the ranks of controller 0, so we double all the values we see. |
| 389 | */ |
| 390 | for (last_cumul_size = i = 0; i < mci->nr_csrows; i++) { |
| 391 | u8 value; |
| 392 | u32 cumul_size; |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 393 | struct csrow_info *csrow = mci->csrows[i]; |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 394 | |
| 395 | value = drb[i]; |
| 396 | cumul_size = value << (I3000_DRB_SHIFT - PAGE_SHIFT); |
| 397 | if (interleaved) |
| 398 | cumul_size <<= 1; |
Joe Perches | 956b9ba1 | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 399 | edac_dbg(3, "MC: (%d) cumul_size 0x%x\n", i, cumul_size); |
Mauro Carvalho Chehab | 084a4fc | 2012-01-27 18:38:08 -0300 | [diff] [blame] | 400 | if (cumul_size == last_cumul_size) |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 401 | continue; |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 402 | |
| 403 | csrow->first_page = last_cumul_size; |
| 404 | csrow->last_page = cumul_size - 1; |
Mauro Carvalho Chehab | a895bf8 | 2012-01-28 09:09:38 -0300 | [diff] [blame] | 405 | nr_pages = cumul_size - last_cumul_size; |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 406 | last_cumul_size = cumul_size; |
Mauro Carvalho Chehab | 084a4fc | 2012-01-27 18:38:08 -0300 | [diff] [blame] | 407 | |
| 408 | for (j = 0; j < nr_channels; j++) { |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 409 | struct dimm_info *dimm = csrow->channels[j]->dimm; |
Mauro Carvalho Chehab | a895bf8 | 2012-01-28 09:09:38 -0300 | [diff] [blame] | 410 | |
| 411 | dimm->nr_pages = nr_pages / nr_channels; |
Mauro Carvalho Chehab | 084a4fc | 2012-01-27 18:38:08 -0300 | [diff] [blame] | 412 | dimm->grain = I3000_DEAP_GRAIN; |
| 413 | dimm->mtype = MEM_DDR2; |
| 414 | dimm->dtype = DEV_UNKNOWN; |
| 415 | dimm->edac_mode = EDAC_UNKNOWN; |
| 416 | } |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Jason Uhlenkott | ce783d7 | 2008-02-07 00:14:53 -0800 | [diff] [blame] | 419 | /* |
| 420 | * Clear any error bits. |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 421 | * (Yes, we really clear bits by writing 1 to them.) |
| 422 | */ |
Dave Jiang | 36b8289 | 2007-07-19 01:50:04 -0700 | [diff] [blame] | 423 | pci_write_bits16(pdev, I3000_ERRSTS, I3000_ERRSTS_BITS, |
| 424 | I3000_ERRSTS_BITS); |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 425 | |
| 426 | rc = -ENODEV; |
Doug Thompson | b8f6f97 | 2007-07-19 01:50:26 -0700 | [diff] [blame] | 427 | if (edac_mc_add_mc(mci)) { |
Joe Perches | 956b9ba1 | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 428 | edac_dbg(3, "MC: failed edac_mc_add_mc()\n"); |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 429 | goto fail; |
| 430 | } |
| 431 | |
Dave Jiang | 456a2f9 | 2007-07-19 01:50:10 -0700 | [diff] [blame] | 432 | /* allocating generic PCI control info */ |
| 433 | i3000_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR); |
| 434 | if (!i3000_pci) { |
| 435 | printk(KERN_WARNING |
| 436 | "%s(): Unable to create PCI control\n", |
| 437 | __func__); |
| 438 | printk(KERN_WARNING |
| 439 | "%s(): PCI error report via EDAC not setup\n", |
| 440 | __func__); |
| 441 | } |
| 442 | |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 443 | /* get this far and it's successful */ |
Joe Perches | 956b9ba1 | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 444 | edac_dbg(3, "MC: success\n"); |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 445 | return 0; |
| 446 | |
Jason Uhlenkott | ce783d7 | 2008-02-07 00:14:53 -0800 | [diff] [blame] | 447 | fail: |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 448 | if (mci) |
| 449 | edac_mc_free(mci); |
| 450 | |
| 451 | return rc; |
| 452 | } |
| 453 | |
| 454 | /* returns count (>= 0), or negative on error */ |
Greg Kroah-Hartman | 9b3c6e8 | 2012-12-21 13:23:51 -0800 | [diff] [blame] | 455 | static int i3000_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 456 | { |
| 457 | int rc; |
| 458 | |
Joe Perches | 956b9ba1 | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 459 | edac_dbg(0, "MC:\n"); |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 460 | |
| 461 | if (pci_enable_device(pdev) < 0) |
| 462 | return -EIO; |
| 463 | |
| 464 | rc = i3000_probe1(pdev, ent->driver_data); |
Jason Uhlenkott | ce783d7 | 2008-02-07 00:14:53 -0800 | [diff] [blame] | 465 | if (!mci_pdev) |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 466 | mci_pdev = pci_dev_get(pdev); |
| 467 | |
| 468 | return rc; |
| 469 | } |
| 470 | |
Greg Kroah-Hartman | 9b3c6e8 | 2012-12-21 13:23:51 -0800 | [diff] [blame] | 471 | static void i3000_remove_one(struct pci_dev *pdev) |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 472 | { |
| 473 | struct mem_ctl_info *mci; |
| 474 | |
Joe Perches | 956b9ba1 | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 475 | edac_dbg(0, "\n"); |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 476 | |
Dave Jiang | 456a2f9 | 2007-07-19 01:50:10 -0700 | [diff] [blame] | 477 | if (i3000_pci) |
| 478 | edac_pci_release_generic_ctl(i3000_pci); |
| 479 | |
Jason Uhlenkott | ce783d7 | 2008-02-07 00:14:53 -0800 | [diff] [blame] | 480 | mci = edac_mc_del_mc(&pdev->dev); |
| 481 | if (!mci) |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 482 | return; |
| 483 | |
| 484 | edac_mc_free(mci); |
| 485 | } |
| 486 | |
Jingoo Han | ba935f4 | 2013-12-06 10:23:08 +0100 | [diff] [blame] | 487 | static const struct pci_device_id i3000_pci_tbl[] = { |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 488 | { |
Dave Jiang | 36b8289 | 2007-07-19 01:50:04 -0700 | [diff] [blame] | 489 | PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0, |
| 490 | I3000}, |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 491 | { |
Dave Jiang | 36b8289 | 2007-07-19 01:50:04 -0700 | [diff] [blame] | 492 | 0, |
| 493 | } /* 0 terminated list. */ |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 494 | }; |
| 495 | |
| 496 | MODULE_DEVICE_TABLE(pci, i3000_pci_tbl); |
| 497 | |
| 498 | static struct pci_driver i3000_driver = { |
| 499 | .name = EDAC_MOD_STR, |
| 500 | .probe = i3000_init_one, |
Greg Kroah-Hartman | 9b3c6e8 | 2012-12-21 13:23:51 -0800 | [diff] [blame] | 501 | .remove = i3000_remove_one, |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 502 | .id_table = i3000_pci_tbl, |
| 503 | }; |
| 504 | |
| 505 | static int __init i3000_init(void) |
| 506 | { |
| 507 | int pci_rc; |
| 508 | |
Joe Perches | 956b9ba1 | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 509 | edac_dbg(3, "MC:\n"); |
Hitoshi Mitake | c3c52bc | 2008-04-29 01:03:18 -0700 | [diff] [blame] | 510 | |
Colin Ian King | 1722bc0 | 2018-11-09 13:37:57 +0000 | [diff] [blame] | 511 | /* Ensure that the OPSTATE is set correctly for POLL or NMI */ |
| 512 | opstate_init(); |
Hitoshi Mitake | c3c52bc | 2008-04-29 01:03:18 -0700 | [diff] [blame] | 513 | |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 514 | pci_rc = pci_register_driver(&i3000_driver); |
| 515 | if (pci_rc < 0) |
| 516 | goto fail0; |
| 517 | |
Jason Uhlenkott | ce783d7 | 2008-02-07 00:14:53 -0800 | [diff] [blame] | 518 | if (!mci_pdev) { |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 519 | i3000_registered = 0; |
| 520 | mci_pdev = pci_get_device(PCI_VENDOR_ID_INTEL, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 521 | PCI_DEVICE_ID_INTEL_3000_HB, NULL); |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 522 | if (!mci_pdev) { |
Joe Perches | 956b9ba1 | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 523 | edac_dbg(0, "i3000 pci_get_device fail\n"); |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 524 | pci_rc = -ENODEV; |
| 525 | goto fail1; |
| 526 | } |
| 527 | |
| 528 | pci_rc = i3000_init_one(mci_pdev, i3000_pci_tbl); |
| 529 | if (pci_rc < 0) { |
Joe Perches | 956b9ba1 | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 530 | edac_dbg(0, "i3000 init fail\n"); |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 531 | pci_rc = -ENODEV; |
| 532 | goto fail1; |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | return 0; |
| 537 | |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 538 | fail1: |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 539 | pci_unregister_driver(&i3000_driver); |
| 540 | |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 541 | fail0: |
Markus Elfring | 0a98bab | 2014-11-19 16:00:13 +0100 | [diff] [blame] | 542 | pci_dev_put(mci_pdev); |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 543 | |
| 544 | return pci_rc; |
| 545 | } |
| 546 | |
| 547 | static void __exit i3000_exit(void) |
| 548 | { |
Joe Perches | 956b9ba1 | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 549 | edac_dbg(3, "MC:\n"); |
Jason Uhlenkott | 535c6a5 | 2007-07-19 01:49:48 -0700 | [diff] [blame] | 550 | |
| 551 | pci_unregister_driver(&i3000_driver); |
| 552 | if (!i3000_registered) { |
| 553 | i3000_remove_one(mci_pdev); |
| 554 | pci_dev_put(mci_pdev); |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | module_init(i3000_init); |
| 559 | module_exit(i3000_exit); |
| 560 | |
| 561 | MODULE_LICENSE("GPL"); |
| 562 | MODULE_AUTHOR("Akamai Technologies Arthur Ulfeldt/Jason Uhlenkott"); |
| 563 | MODULE_DESCRIPTION("MC support for Intel 3000 memory hub controllers"); |
Hitoshi Mitake | 7ed31e0 | 2008-02-07 00:15:02 -0800 | [diff] [blame] | 564 | |
| 565 | module_param(edac_op_state, int, 0444); |
| 566 | MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI"); |