Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Defines, structures, APIs for edac_core module |
| 3 | * |
| 4 | * (C) 2007 Linux Networx (http://lnxi.com) |
| 5 | * This file may be distributed under the terms of the |
| 6 | * GNU General Public License. |
| 7 | * |
| 8 | * Written by Thayne Harbaugh |
| 9 | * Based on work by Dan Hollis <goemon at anime dot net> and others. |
| 10 | * http://www.anime.net/~goemon/linux-ecc/ |
| 11 | * |
| 12 | * NMI handling support added by |
| 13 | * Dave Peterson <dsp@llnl.gov> <dave_peterson@pobox.com> |
| 14 | * |
| 15 | * Refactored for multi-source files: |
| 16 | * Doug Thompson <norsk5@xmission.com> |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | #ifndef _EDAC_CORE_H_ |
| 21 | #define _EDAC_CORE_H_ |
| 22 | |
| 23 | #include <linux/kernel.h> |
| 24 | #include <linux/types.h> |
| 25 | #include <linux/module.h> |
| 26 | #include <linux/spinlock.h> |
| 27 | #include <linux/smp.h> |
| 28 | #include <linux/pci.h> |
| 29 | #include <linux/time.h> |
| 30 | #include <linux/nmi.h> |
| 31 | #include <linux/rcupdate.h> |
| 32 | #include <linux/completion.h> |
| 33 | #include <linux/kobject.h> |
| 34 | #include <linux/platform_device.h> |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 35 | #include <linux/workqueue.h> |
Mauro Carvalho Chehab | ddeb354 | 2011-03-04 15:11:29 -0300 | [diff] [blame] | 36 | #include <linux/edac.h> |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 37 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 38 | #define EDAC_DEVICE_NAME_LEN 31 |
| 39 | #define EDAC_ATTRIB_VALUE_LEN 15 |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 40 | |
| 41 | #if PAGE_SHIFT < 20 |
Andrei Konovalov | 76f04f2 | 2010-12-07 07:48:00 -0500 | [diff] [blame] | 42 | #define PAGES_TO_MiB(pages) ((pages) >> (20 - PAGE_SHIFT)) |
| 43 | #define MiB_TO_PAGES(mb) ((mb) << (20 - PAGE_SHIFT)) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 44 | #else /* PAGE_SHIFT > 20 */ |
Andrei Konovalov | 76f04f2 | 2010-12-07 07:48:00 -0500 | [diff] [blame] | 45 | #define PAGES_TO_MiB(pages) ((pages) << (PAGE_SHIFT - 20)) |
Mauro Carvalho Chehab | e914460 | 2010-08-10 20:26:35 -0300 | [diff] [blame] | 46 | #define MiB_TO_PAGES(mb) ((mb) >> (PAGE_SHIFT - 20)) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 47 | #endif |
| 48 | |
| 49 | #define edac_printk(level, prefix, fmt, arg...) \ |
| 50 | printk(level "EDAC " prefix ": " fmt, ##arg) |
| 51 | |
| 52 | #define edac_mc_printk(mci, level, fmt, arg...) \ |
| 53 | printk(level "EDAC MC%d: " fmt, mci->mc_idx, ##arg) |
| 54 | |
| 55 | #define edac_mc_chipset_printk(mci, level, prefix, fmt, arg...) \ |
| 56 | printk(level "EDAC " prefix " MC%d: " fmt, mci->mc_idx, ##arg) |
| 57 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 58 | #define edac_device_printk(ctl, level, fmt, arg...) \ |
| 59 | printk(level "EDAC DEVICE%d: " fmt, ctl->dev_idx, ##arg) |
| 60 | |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 61 | #define edac_pci_printk(ctl, level, fmt, arg...) \ |
| 62 | printk(level "EDAC PCI%d: " fmt, ctl->pci_idx, ##arg) |
| 63 | |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 64 | /* prefixes for edac_printk() and edac_mc_printk() */ |
| 65 | #define EDAC_MC "MC" |
| 66 | #define EDAC_PCI "PCI" |
| 67 | #define EDAC_DEBUG "DEBUG" |
| 68 | |
Borislav Petkov | f4ce6ec | 2014-08-13 23:27:55 +0200 | [diff] [blame] | 69 | extern const char * const edac_mem_types[]; |
Borislav Petkov | 24f9a7f | 2010-10-07 18:29:15 +0200 | [diff] [blame] | 70 | |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 71 | #ifdef CONFIG_EDAC_DEBUG |
| 72 | extern int edac_debug_level; |
| 73 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 74 | #define edac_dbg(level, fmt, ...) \ |
Joe Perches | 7e88185 | 2012-04-28 16:41:46 -0300 | [diff] [blame] | 75 | do { \ |
| 76 | if (level <= edac_debug_level) \ |
| 77 | edac_printk(KERN_DEBUG, EDAC_DEBUG, \ |
| 78 | "%s: " fmt, __func__, ##__VA_ARGS__); \ |
| 79 | } while (0) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 80 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 81 | #else /* !CONFIG_EDAC_DEBUG */ |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 82 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 83 | #define edac_dbg(level, fmt, ...) \ |
Joe Perches | 7e88185 | 2012-04-28 16:41:46 -0300 | [diff] [blame] | 84 | do { \ |
| 85 | if (0) \ |
| 86 | edac_printk(KERN_DEBUG, EDAC_DEBUG, \ |
| 87 | "%s: " fmt, __func__, ##__VA_ARGS__); \ |
| 88 | } while (0) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 89 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 90 | #endif /* !CONFIG_EDAC_DEBUG */ |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 91 | |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 92 | #define PCI_VEND_DEV(vend, dev) PCI_VENDOR_ID_ ## vend, \ |
| 93 | PCI_DEVICE_ID_ ## vend ## _ ## dev |
| 94 | |
Stephen Rothwell | 17aa7e0 | 2008-05-05 13:54:19 +1000 | [diff] [blame] | 95 | #define edac_dev_name(dev) (dev)->dev_name |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 96 | |
Borislav Petkov | 7ac8bf9 | 2015-09-22 11:56:04 +0200 | [diff] [blame] | 97 | #define to_mci(k) container_of(k, struct mem_ctl_info, dev) |
| 98 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 99 | /* |
Douglas Thompson | 42a8e39 | 2007-07-19 01:50:10 -0700 | [diff] [blame] | 100 | * The following are the structures to provide for a generic |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 101 | * or abstract 'edac_device'. This set of structures and the |
| 102 | * code that implements the APIs for the same, provide for |
| 103 | * registering EDAC type devices which are NOT standard memory. |
| 104 | * |
| 105 | * CPU caches (L1 and L2) |
| 106 | * DMA engines |
David Mackey | 15ed103 | 2012-04-17 11:30:52 -0700 | [diff] [blame] | 107 | * Core CPU switches |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 108 | * Fabric switch units |
| 109 | * PCIe interface controllers |
| 110 | * other EDAC/ECC type devices that can be monitored for |
| 111 | * errors, etc. |
| 112 | * |
David Mackey | 15ed103 | 2012-04-17 11:30:52 -0700 | [diff] [blame] | 113 | * It allows for a 2 level set of hierarchy. For example: |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 114 | * |
| 115 | * cache could be composed of L1, L2 and L3 levels of cache. |
| 116 | * Each CPU core would have its own L1 cache, while sharing |
| 117 | * L2 and maybe L3 caches. |
| 118 | * |
| 119 | * View them arranged, via the sysfs presentation: |
| 120 | * /sys/devices/system/edac/.. |
| 121 | * |
| 122 | * mc/ <existing memory device directory> |
| 123 | * cpu/cpu0/.. <L1 and L2 block directory> |
| 124 | * /L1-cache/ce_count |
| 125 | * /ue_count |
| 126 | * /L2-cache/ce_count |
| 127 | * /ue_count |
| 128 | * cpu/cpu1/.. <L1 and L2 block directory> |
| 129 | * /L1-cache/ce_count |
| 130 | * /ue_count |
| 131 | * /L2-cache/ce_count |
| 132 | * /ue_count |
| 133 | * ... |
| 134 | * |
| 135 | * the L1 and L2 directories would be "edac_device_block's" |
| 136 | */ |
| 137 | |
| 138 | struct edac_device_counter { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 139 | u32 ue_count; |
| 140 | u32 ce_count; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 141 | }; |
| 142 | |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 143 | /* forward reference */ |
| 144 | struct edac_device_ctl_info; |
| 145 | struct edac_device_block; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 146 | |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 147 | /* edac_dev_sysfs_attribute structure |
| 148 | * used for driver sysfs attributes in mem_ctl_info |
| 149 | * for extra controls and attributes: |
| 150 | * like high level error Injection controls |
| 151 | */ |
| 152 | struct edac_dev_sysfs_attribute { |
| 153 | struct attribute attr; |
| 154 | ssize_t (*show)(struct edac_device_ctl_info *, char *); |
| 155 | ssize_t (*store)(struct edac_device_ctl_info *, const char *, size_t); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 156 | }; |
| 157 | |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 158 | /* edac_dev_sysfs_block_attribute structure |
Doug Thompson | b2a4ac0 | 2007-07-19 01:50:33 -0700 | [diff] [blame] | 159 | * |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 160 | * used in leaf 'block' nodes for adding controls/attributes |
Doug Thompson | b2a4ac0 | 2007-07-19 01:50:33 -0700 | [diff] [blame] | 161 | * |
| 162 | * each block in each instance of the containing control structure |
| 163 | * can have an array of the following. The show and store functions |
| 164 | * will be filled in with the show/store function in the |
| 165 | * low level driver. |
| 166 | * |
| 167 | * The 'value' field will be the actual value field used for |
| 168 | * counting |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 169 | */ |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 170 | struct edac_dev_sysfs_block_attribute { |
| 171 | struct attribute attr; |
| 172 | ssize_t (*show)(struct kobject *, struct attribute *, char *); |
| 173 | ssize_t (*store)(struct kobject *, struct attribute *, |
| 174 | const char *, size_t); |
| 175 | struct edac_device_block *block; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 176 | |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 177 | unsigned int value; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 178 | }; |
| 179 | |
| 180 | /* device block control structure */ |
| 181 | struct edac_device_block { |
| 182 | struct edac_device_instance *instance; /* Up Pointer */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 183 | char name[EDAC_DEVICE_NAME_LEN + 1]; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 184 | |
| 185 | struct edac_device_counter counters; /* basic UE and CE counters */ |
| 186 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 187 | int nr_attribs; /* how many attributes */ |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 188 | |
| 189 | /* this block's attributes, could be NULL */ |
| 190 | struct edac_dev_sysfs_block_attribute *block_attributes; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 191 | |
| 192 | /* edac sysfs device control */ |
| 193 | struct kobject kobj; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 194 | }; |
| 195 | |
| 196 | /* device instance control structure */ |
| 197 | struct edac_device_instance { |
| 198 | struct edac_device_ctl_info *ctl; /* Up pointer */ |
| 199 | char name[EDAC_DEVICE_NAME_LEN + 4]; |
| 200 | |
| 201 | struct edac_device_counter counters; /* instance counters */ |
| 202 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 203 | u32 nr_blocks; /* how many blocks */ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 204 | struct edac_device_block *blocks; /* block array */ |
| 205 | |
| 206 | /* edac sysfs device control */ |
| 207 | struct kobject kobj; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 208 | }; |
| 209 | |
Douglas Thompson | 42a8e39 | 2007-07-19 01:50:10 -0700 | [diff] [blame] | 210 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 211 | /* |
| 212 | * Abstract edac_device control info structure |
| 213 | * |
| 214 | */ |
| 215 | struct edac_device_ctl_info { |
| 216 | /* for global list of edac_device_ctl_info structs */ |
| 217 | struct list_head link; |
| 218 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 219 | struct module *owner; /* Module owner of this control struct */ |
| 220 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 221 | int dev_idx; |
| 222 | |
| 223 | /* Per instance controls for this edac_device */ |
| 224 | int log_ue; /* boolean for logging UEs */ |
| 225 | int log_ce; /* boolean for logging CEs */ |
Stepan Moskovchenko | a8349c1 | 2014-06-10 19:24:50 -0700 | [diff] [blame] | 226 | int panic_on_ce; /* boolean for panic'ing on an CE */ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 227 | int panic_on_ue; /* boolean for panic'ing on an UE */ |
| 228 | unsigned poll_msec; /* number of milliseconds to poll interval */ |
| 229 | unsigned long delay; /* number of jiffies for poll_msec */ |
Rohit Vaswani | 8cc42b5 | 2014-10-03 13:13:15 -0700 | [diff] [blame^] | 230 | bool defer_work; /* Create a deferrable work for polling */ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 231 | |
Douglas Thompson | 42a8e39 | 2007-07-19 01:50:10 -0700 | [diff] [blame] | 232 | /* Additional top controller level attributes, but specified |
| 233 | * by the low level driver. |
| 234 | * |
| 235 | * Set by the low level driver to provide attributes at the |
| 236 | * controller level, same level as 'ue_count' and 'ce_count' above. |
| 237 | * An array of structures, NULL terminated |
| 238 | * |
| 239 | * If attributes are desired, then set to array of attributes |
| 240 | * If no attributes are desired, leave NULL |
| 241 | */ |
| 242 | struct edac_dev_sysfs_attribute *sysfs_attributes; |
| 243 | |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 244 | /* pointer to main 'edac' subsys in sysfs */ |
| 245 | struct bus_type *edac_subsys; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 246 | |
| 247 | /* the internal state of this controller instance */ |
| 248 | int op_state; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 249 | /* work struct for this instance */ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 250 | struct delayed_work work; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 251 | |
| 252 | /* pointer to edac polling checking routine: |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 253 | * If NOT NULL: points to polling check routine |
| 254 | * If NULL: Then assumes INTERRUPT operation, where |
| 255 | * MC driver will receive events |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 256 | */ |
| 257 | void (*edac_check) (struct edac_device_ctl_info * edac_dev); |
| 258 | |
| 259 | struct device *dev; /* pointer to device structure */ |
| 260 | |
| 261 | const char *mod_name; /* module name */ |
| 262 | const char *ctl_name; /* edac controller name */ |
Dave Jiang | c419270 | 2007-07-19 01:49:47 -0700 | [diff] [blame] | 263 | const char *dev_name; /* pci/platform/etc... name */ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 264 | |
| 265 | void *pvt_info; /* pointer to 'private driver' info */ |
| 266 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 267 | unsigned long start_time; /* edac_device load start time (jiffies) */ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 268 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 269 | struct completion removal_complete; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 270 | |
| 271 | /* sysfs top name under 'edac' directory |
| 272 | * and instance name: |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 273 | * cpu/cpu0/... |
| 274 | * cpu/cpu1/... |
| 275 | * cpu/cpu2/... |
| 276 | * ... |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 277 | */ |
| 278 | char name[EDAC_DEVICE_NAME_LEN + 1]; |
| 279 | |
| 280 | /* Number of instances supported on this control structure |
| 281 | * and the array of those instances |
| 282 | */ |
| 283 | u32 nr_instances; |
| 284 | struct edac_device_instance *instances; |
| 285 | |
| 286 | /* Event counters for the this whole EDAC Device */ |
| 287 | struct edac_device_counter counters; |
| 288 | |
| 289 | /* edac sysfs device control for the 'name' |
| 290 | * device this structure controls |
| 291 | */ |
| 292 | struct kobject kobj; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 293 | }; |
| 294 | |
| 295 | /* To get from the instance's wq to the beginning of the ctl structure */ |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 296 | #define to_edac_mem_ctl_work(w) \ |
| 297 | container_of(w, struct mem_ctl_info, work) |
| 298 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 299 | #define to_edac_device_ctl_work(w) \ |
| 300 | container_of(w,struct edac_device_ctl_info,work) |
| 301 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 302 | /* |
| 303 | * The alloc() and free() functions for the 'edac_device' control info |
| 304 | * structure. A MC driver will allocate one of these for each edac_device |
| 305 | * it is going to control/register with the EDAC CORE. |
| 306 | */ |
| 307 | extern struct edac_device_ctl_info *edac_device_alloc_ctl_info( |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 308 | unsigned sizeof_private, |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 309 | char *edac_device_name, unsigned nr_instances, |
| 310 | char *edac_block_name, unsigned nr_blocks, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 311 | unsigned offset_value, |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 312 | struct edac_dev_sysfs_block_attribute *block_attributes, |
Doug Thompson | d45e782 | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 313 | unsigned nr_attribs, |
| 314 | int device_index); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 315 | |
| 316 | /* The offset value can be: |
| 317 | * -1 indicating no offset value |
| 318 | * 0 for zero-based block numbers |
| 319 | * 1 for 1-based block number |
| 320 | * other for other-based block number |
| 321 | */ |
| 322 | #define BLOCK_OFFSET_VALUE_OFF ((unsigned) -1) |
| 323 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 324 | extern void edac_device_free_ctl_info(struct edac_device_ctl_info *ctl_info); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 325 | |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 326 | #ifdef CONFIG_PCI |
| 327 | |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 328 | struct edac_pci_counter { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 329 | atomic_t pe_count; |
| 330 | atomic_t npe_count; |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 331 | }; |
| 332 | |
| 333 | /* |
| 334 | * Abstract edac_pci control info structure |
| 335 | * |
| 336 | */ |
| 337 | struct edac_pci_ctl_info { |
| 338 | /* for global list of edac_pci_ctl_info structs */ |
| 339 | struct list_head link; |
| 340 | |
| 341 | int pci_idx; |
| 342 | |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 343 | struct bus_type *edac_subsys; /* pointer to subsystem */ |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 344 | |
| 345 | /* the internal state of this controller instance */ |
| 346 | int op_state; |
| 347 | /* work struct for this instance */ |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 348 | struct delayed_work work; |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 349 | |
| 350 | /* pointer to edac polling checking routine: |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 351 | * If NOT NULL: points to polling check routine |
| 352 | * If NULL: Then assumes INTERRUPT operation, where |
| 353 | * MC driver will receive events |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 354 | */ |
| 355 | void (*edac_check) (struct edac_pci_ctl_info * edac_dev); |
| 356 | |
| 357 | struct device *dev; /* pointer to device structure */ |
| 358 | |
| 359 | const char *mod_name; /* module name */ |
| 360 | const char *ctl_name; /* edac controller name */ |
| 361 | const char *dev_name; /* pci/platform/etc... name */ |
| 362 | |
| 363 | void *pvt_info; /* pointer to 'private driver' info */ |
| 364 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 365 | unsigned long start_time; /* edac_pci load start time (jiffies) */ |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 366 | |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 367 | struct completion complete; |
| 368 | |
| 369 | /* sysfs top name under 'edac' directory |
| 370 | * and instance name: |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 371 | * cpu/cpu0/... |
| 372 | * cpu/cpu1/... |
| 373 | * cpu/cpu2/... |
| 374 | * ... |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 375 | */ |
| 376 | char name[EDAC_DEVICE_NAME_LEN + 1]; |
| 377 | |
| 378 | /* Event counters for the this whole EDAC Device */ |
| 379 | struct edac_pci_counter counters; |
| 380 | |
| 381 | /* edac sysfs device control for the 'name' |
| 382 | * device this structure controls |
| 383 | */ |
| 384 | struct kobject kobj; |
| 385 | struct completion kobj_complete; |
| 386 | }; |
| 387 | |
| 388 | #define to_edac_pci_ctl_work(w) \ |
| 389 | container_of(w, struct edac_pci_ctl_info,work) |
| 390 | |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 391 | /* write all or some bits in a byte-register*/ |
| 392 | static inline void pci_write_bits8(struct pci_dev *pdev, int offset, u8 value, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 393 | u8 mask) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 394 | { |
| 395 | if (mask != 0xff) { |
| 396 | u8 buf; |
| 397 | |
| 398 | pci_read_config_byte(pdev, offset, &buf); |
| 399 | value &= mask; |
| 400 | buf &= ~mask; |
| 401 | value |= buf; |
| 402 | } |
| 403 | |
| 404 | pci_write_config_byte(pdev, offset, value); |
| 405 | } |
| 406 | |
| 407 | /* write all or some bits in a word-register*/ |
| 408 | static inline void pci_write_bits16(struct pci_dev *pdev, int offset, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 409 | u16 value, u16 mask) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 410 | { |
| 411 | if (mask != 0xffff) { |
| 412 | u16 buf; |
| 413 | |
| 414 | pci_read_config_word(pdev, offset, &buf); |
| 415 | value &= mask; |
| 416 | buf &= ~mask; |
| 417 | value |= buf; |
| 418 | } |
| 419 | |
| 420 | pci_write_config_word(pdev, offset, value); |
| 421 | } |
| 422 | |
Jeff Haran | e6da46b | 2009-04-13 14:40:20 -0700 | [diff] [blame] | 423 | /* |
| 424 | * pci_write_bits32 |
| 425 | * |
| 426 | * edac local routine to do pci_write_config_dword, but adds |
| 427 | * a mask parameter. If mask is all ones, ignore the mask. |
| 428 | * Otherwise utilize the mask to isolate specified bits |
| 429 | * |
| 430 | * write all or some bits in a dword-register |
| 431 | */ |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 432 | static inline void pci_write_bits32(struct pci_dev *pdev, int offset, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 433 | u32 value, u32 mask) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 434 | { |
Jeff Haran | e6da46b | 2009-04-13 14:40:20 -0700 | [diff] [blame] | 435 | if (mask != 0xffffffff) { |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 436 | u32 buf; |
| 437 | |
| 438 | pci_read_config_dword(pdev, offset, &buf); |
| 439 | value &= mask; |
| 440 | buf &= ~mask; |
| 441 | value |= buf; |
| 442 | } |
| 443 | |
| 444 | pci_write_config_dword(pdev, offset, value); |
| 445 | } |
| 446 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 447 | #endif /* CONFIG_PCI */ |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 448 | |
Mauro Carvalho Chehab | ca0907b | 2012-05-02 14:37:00 -0300 | [diff] [blame] | 449 | struct mem_ctl_info *edac_mc_alloc(unsigned mc_num, |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 450 | unsigned n_layers, |
| 451 | struct edac_mc_layer *layers, |
| 452 | unsigned sz_pvt); |
Takashi Iwai | 4e8d230 | 2015-02-04 11:48:52 +0100 | [diff] [blame] | 453 | extern int edac_mc_add_mc_with_groups(struct mem_ctl_info *mci, |
| 454 | const struct attribute_group **groups); |
| 455 | #define edac_mc_add_mc(mci) edac_mc_add_mc_with_groups(mci, NULL) |
Doug Thompson | b8f6f97 | 2007-07-19 01:50:26 -0700 | [diff] [blame] | 456 | extern void edac_mc_free(struct mem_ctl_info *mci); |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 457 | extern struct mem_ctl_info *edac_mc_find(int idx); |
Mauro Carvalho Chehab | 939747bd | 2010-08-10 11:22:01 -0300 | [diff] [blame] | 458 | extern struct mem_ctl_info *find_mci_by_dev(struct device *dev); |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 459 | extern struct mem_ctl_info *edac_mc_del_mc(struct device *dev); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 460 | extern int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 461 | unsigned long page); |
Mauro Carvalho Chehab | e7e2483 | 2012-10-31 13:46:11 -0300 | [diff] [blame] | 462 | |
| 463 | void edac_raw_mc_handle_error(const enum hw_event_mc_err_type type, |
| 464 | struct mem_ctl_info *mci, |
| 465 | struct edac_raw_error_desc *e); |
| 466 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 467 | void edac_mc_handle_error(const enum hw_event_mc_err_type type, |
| 468 | struct mem_ctl_info *mci, |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 469 | const u16 error_count, |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 470 | const unsigned long page_frame_number, |
| 471 | const unsigned long offset_in_page, |
| 472 | const unsigned long syndrome, |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 473 | const int top_layer, |
| 474 | const int mid_layer, |
| 475 | const int low_layer, |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 476 | const char *msg, |
Mauro Carvalho Chehab | 03f7eae | 2012-06-04 11:29:25 -0300 | [diff] [blame] | 477 | const char *other_detail); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 478 | |
| 479 | /* |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 480 | * edac_device APIs |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 481 | */ |
Doug Thompson | d45e782 | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 482 | extern int edac_device_add_device(struct edac_device_ctl_info *edac_dev); |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 483 | extern struct edac_device_ctl_info *edac_device_del_device(struct device *dev); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 484 | extern void edac_device_handle_ue(struct edac_device_ctl_info *edac_dev, |
Doug Thompson | b8f6f97 | 2007-07-19 01:50:26 -0700 | [diff] [blame] | 485 | int inst_nr, int block_nr, const char *msg); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 486 | extern void edac_device_handle_ce(struct edac_device_ctl_info *edac_dev, |
Doug Thompson | b8f6f97 | 2007-07-19 01:50:26 -0700 | [diff] [blame] | 487 | int inst_nr, int block_nr, const char *msg); |
Harry Ciao | 1dc9b70 | 2009-06-17 16:27:59 -0700 | [diff] [blame] | 488 | extern int edac_device_alloc_index(void); |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 489 | extern const char *edac_layer_name[]; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 490 | |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 491 | /* |
| 492 | * edac_pci APIs |
| 493 | */ |
Doug Thompson | b8f6f97 | 2007-07-19 01:50:26 -0700 | [diff] [blame] | 494 | extern struct edac_pci_ctl_info *edac_pci_alloc_ctl_info(unsigned int sz_pvt, |
| 495 | const char *edac_pci_name); |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 496 | |
| 497 | extern void edac_pci_free_ctl_info(struct edac_pci_ctl_info *pci); |
| 498 | |
Doug Thompson | b8f6f97 | 2007-07-19 01:50:26 -0700 | [diff] [blame] | 499 | extern void edac_pci_reset_delay_period(struct edac_pci_ctl_info *pci, |
| 500 | unsigned long value); |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 501 | |
Harry Ciao | 8641a38 | 2009-04-02 16:58:47 -0700 | [diff] [blame] | 502 | extern int edac_pci_alloc_index(void); |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 503 | extern int edac_pci_add_device(struct edac_pci_ctl_info *pci, int edac_idx); |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 504 | extern struct edac_pci_ctl_info *edac_pci_del_device(struct device *dev); |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 505 | |
Doug Thompson | b8f6f97 | 2007-07-19 01:50:26 -0700 | [diff] [blame] | 506 | extern struct edac_pci_ctl_info *edac_pci_create_generic_ctl( |
| 507 | struct device *dev, |
| 508 | const char *mod_name); |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 509 | |
| 510 | extern void edac_pci_release_generic_ctl(struct edac_pci_ctl_info *pci); |
| 511 | extern int edac_pci_create_sysfs(struct edac_pci_ctl_info *pci); |
| 512 | extern void edac_pci_remove_sysfs(struct edac_pci_ctl_info *pci); |
| 513 | |
| 514 | /* |
| 515 | * edac misc APIs |
| 516 | */ |
Douglas Thompson | 494d0d5 | 2007-07-19 01:50:21 -0700 | [diff] [blame] | 517 | extern char *edac_op_state_to_string(int op_state); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 518 | |
| 519 | #endif /* _EDAC_CORE_H_ */ |