![]() |
|
|||
0001 /* 0002 * Defines, structures, APIs for edac_device 0003 * 0004 * (C) 2007 Linux Networx (http://lnxi.com) 0005 * This file may be distributed under the terms of the 0006 * GNU General Public License. 0007 * 0008 * Written by Thayne Harbaugh 0009 * Based on work by Dan Hollis <goemon at anime dot net> and others. 0010 * http://www.anime.net/~goemon/linux-ecc/ 0011 * 0012 * NMI handling support added by 0013 * Dave Peterson <dsp@llnl.gov> <dave_peterson@pobox.com> 0014 * 0015 * Refactored for multi-source files: 0016 * Doug Thompson <norsk5@xmission.com> 0017 * 0018 * Please look at Documentation/driver-api/edac.rst for more info about 0019 * EDAC core structs and functions. 0020 */ 0021 0022 #ifndef _EDAC_DEVICE_H_ 0023 #define _EDAC_DEVICE_H_ 0024 0025 #include <linux/completion.h> 0026 #include <linux/device.h> 0027 #include <linux/edac.h> 0028 #include <linux/kobject.h> 0029 #include <linux/list.h> 0030 #include <linux/types.h> 0031 #include <linux/sysfs.h> 0032 #include <linux/workqueue.h> 0033 0034 0035 /* 0036 * The following are the structures to provide for a generic 0037 * or abstract 'edac_device'. This set of structures and the 0038 * code that implements the APIs for the same, provide for 0039 * registering EDAC type devices which are NOT standard memory. 0040 * 0041 * CPU caches (L1 and L2) 0042 * DMA engines 0043 * Core CPU switches 0044 * Fabric switch units 0045 * PCIe interface controllers 0046 * other EDAC/ECC type devices that can be monitored for 0047 * errors, etc. 0048 * 0049 * It allows for a 2 level set of hierarchy. For example: 0050 * 0051 * cache could be composed of L1, L2 and L3 levels of cache. 0052 * Each CPU core would have its own L1 cache, while sharing 0053 * L2 and maybe L3 caches. 0054 * 0055 * View them arranged, via the sysfs presentation: 0056 * /sys/devices/system/edac/.. 0057 * 0058 * mc/ <existing memory device directory> 0059 * cpu/cpu0/.. <L1 and L2 block directory> 0060 * /L1-cache/ce_count 0061 * /ue_count 0062 * /L2-cache/ce_count 0063 * /ue_count 0064 * cpu/cpu1/.. <L1 and L2 block directory> 0065 * /L1-cache/ce_count 0066 * /ue_count 0067 * /L2-cache/ce_count 0068 * /ue_count 0069 * ... 0070 * 0071 * the L1 and L2 directories would be "edac_device_block's" 0072 */ 0073 0074 struct edac_device_counter { 0075 u32 ue_count; 0076 u32 ce_count; 0077 }; 0078 0079 /* forward reference */ 0080 struct edac_device_ctl_info; 0081 struct edac_device_block; 0082 0083 /* edac_dev_sysfs_attribute structure 0084 * used for driver sysfs attributes in mem_ctl_info 0085 * for extra controls and attributes: 0086 * like high level error Injection controls 0087 */ 0088 struct edac_dev_sysfs_attribute { 0089 struct attribute attr; 0090 ssize_t (*show)(struct edac_device_ctl_info *, char *); 0091 ssize_t (*store)(struct edac_device_ctl_info *, const char *, size_t); 0092 }; 0093 0094 /* edac_dev_sysfs_block_attribute structure 0095 * 0096 * used in leaf 'block' nodes for adding controls/attributes 0097 * 0098 * each block in each instance of the containing control structure 0099 * can have an array of the following. The show and store functions 0100 * will be filled in with the show/store function in the 0101 * low level driver. 0102 * 0103 * The 'value' field will be the actual value field used for 0104 * counting 0105 */ 0106 struct edac_dev_sysfs_block_attribute { 0107 struct attribute attr; 0108 ssize_t (*show)(struct kobject *, struct attribute *, char *); 0109 ssize_t (*store)(struct kobject *, struct attribute *, 0110 const char *, size_t); 0111 struct edac_device_block *block; 0112 0113 unsigned int value; 0114 }; 0115 0116 /* device block control structure */ 0117 struct edac_device_block { 0118 struct edac_device_instance *instance; /* Up Pointer */ 0119 char name[EDAC_DEVICE_NAME_LEN + 1]; 0120 0121 struct edac_device_counter counters; /* basic UE and CE counters */ 0122 0123 int nr_attribs; /* how many attributes */ 0124 0125 /* this block's attributes, could be NULL */ 0126 struct edac_dev_sysfs_block_attribute *block_attributes; 0127 0128 /* edac sysfs device control */ 0129 struct kobject kobj; 0130 }; 0131 0132 /* device instance control structure */ 0133 struct edac_device_instance { 0134 struct edac_device_ctl_info *ctl; /* Up pointer */ 0135 char name[EDAC_DEVICE_NAME_LEN + 4]; 0136 0137 struct edac_device_counter counters; /* instance counters */ 0138 0139 u32 nr_blocks; /* how many blocks */ 0140 struct edac_device_block *blocks; /* block array */ 0141 0142 /* edac sysfs device control */ 0143 struct kobject kobj; 0144 }; 0145 0146 0147 /* 0148 * Abstract edac_device control info structure 0149 * 0150 */ 0151 struct edac_device_ctl_info { 0152 /* for global list of edac_device_ctl_info structs */ 0153 struct list_head link; 0154 0155 struct module *owner; /* Module owner of this control struct */ 0156 0157 int dev_idx; 0158 0159 /* Per instance controls for this edac_device */ 0160 int log_ue; /* boolean for logging UEs */ 0161 int log_ce; /* boolean for logging CEs */ 0162 int panic_on_ue; /* boolean for panic'ing on an UE */ 0163 unsigned poll_msec; /* number of milliseconds to poll interval */ 0164 unsigned long delay; /* number of jiffies for poll_msec */ 0165 0166 /* Additional top controller level attributes, but specified 0167 * by the low level driver. 0168 * 0169 * Set by the low level driver to provide attributes at the 0170 * controller level, same level as 'ue_count' and 'ce_count' above. 0171 * An array of structures, NULL terminated 0172 * 0173 * If attributes are desired, then set to array of attributes 0174 * If no attributes are desired, leave NULL 0175 */ 0176 struct edac_dev_sysfs_attribute *sysfs_attributes; 0177 0178 /* pointer to main 'edac' subsys in sysfs */ 0179 struct bus_type *edac_subsys; 0180 0181 /* the internal state of this controller instance */ 0182 int op_state; 0183 /* work struct for this instance */ 0184 struct delayed_work work; 0185 0186 /* pointer to edac polling checking routine: 0187 * If NOT NULL: points to polling check routine 0188 * If NULL: Then assumes INTERRUPT operation, where 0189 * MC driver will receive events 0190 */ 0191 void (*edac_check) (struct edac_device_ctl_info * edac_dev); 0192 0193 struct device *dev; /* pointer to device structure */ 0194 0195 const char *mod_name; /* module name */ 0196 const char *ctl_name; /* edac controller name */ 0197 const char *dev_name; /* pci/platform/etc... name */ 0198 0199 void *pvt_info; /* pointer to 'private driver' info */ 0200 0201 unsigned long start_time; /* edac_device load start time (jiffies) */ 0202 0203 struct completion removal_complete; 0204 0205 /* sysfs top name under 'edac' directory 0206 * and instance name: 0207 * cpu/cpu0/... 0208 * cpu/cpu1/... 0209 * cpu/cpu2/... 0210 * ... 0211 */ 0212 char name[EDAC_DEVICE_NAME_LEN + 1]; 0213 0214 /* Number of instances supported on this control structure 0215 * and the array of those instances 0216 */ 0217 u32 nr_instances; 0218 struct edac_device_instance *instances; 0219 struct edac_device_block *blocks; 0220 struct edac_dev_sysfs_block_attribute *attribs; 0221 0222 /* Event counters for the this whole EDAC Device */ 0223 struct edac_device_counter counters; 0224 0225 /* edac sysfs device control for the 'name' 0226 * device this structure controls 0227 */ 0228 struct kobject kobj; 0229 }; 0230 0231 /* To get from the instance's wq to the beginning of the ctl structure */ 0232 #define to_edac_mem_ctl_work(w) \ 0233 container_of(w, struct mem_ctl_info, work) 0234 0235 #define to_edac_device_ctl_work(w) \ 0236 container_of(w,struct edac_device_ctl_info,work) 0237 0238 /* 0239 * The alloc() and free() functions for the 'edac_device' control info 0240 * structure. A MC driver will allocate one of these for each edac_device 0241 * it is going to control/register with the EDAC CORE. 0242 */ 0243 extern struct edac_device_ctl_info *edac_device_alloc_ctl_info( 0244 unsigned sizeof_private, 0245 char *edac_device_name, unsigned nr_instances, 0246 char *edac_block_name, unsigned nr_blocks, 0247 unsigned offset_value, 0248 struct edac_dev_sysfs_block_attribute *block_attributes, 0249 unsigned nr_attribs, 0250 int device_index); 0251 0252 /* The offset value can be: 0253 * -1 indicating no offset value 0254 * 0 for zero-based block numbers 0255 * 1 for 1-based block number 0256 * other for other-based block number 0257 */ 0258 #define BLOCK_OFFSET_VALUE_OFF ((unsigned) -1) 0259 0260 extern void edac_device_free_ctl_info(struct edac_device_ctl_info *ctl_info); 0261 0262 /** 0263 * edac_device_add_device - Insert the 'edac_dev' structure into the 0264 * edac_device global list and create sysfs entries associated with 0265 * edac_device structure. 0266 * 0267 * @edac_dev: pointer to edac_device structure to be added to the list 0268 * 'edac_device' structure. 0269 * 0270 * Returns: 0271 * 0 on Success, or an error code on failure 0272 */ 0273 extern int edac_device_add_device(struct edac_device_ctl_info *edac_dev); 0274 0275 /** 0276 * edac_device_del_device - Remove sysfs entries for specified edac_device 0277 * structure and then remove edac_device structure from global list 0278 * 0279 * @dev: 0280 * Pointer to struct &device representing the edac device 0281 * structure to remove. 0282 * 0283 * Returns: 0284 * Pointer to removed edac_device structure, 0285 * or %NULL if device not found. 0286 */ 0287 extern struct edac_device_ctl_info *edac_device_del_device(struct device *dev); 0288 0289 /** 0290 * edac_device_handle_ce_count - Log correctable errors. 0291 * 0292 * @edac_dev: pointer to struct &edac_device_ctl_info 0293 * @inst_nr: number of the instance where the CE error happened 0294 * @count: Number of errors to log. 0295 * @block_nr: number of the block where the CE error happened 0296 * @msg: message to be printed 0297 */ 0298 void edac_device_handle_ce_count(struct edac_device_ctl_info *edac_dev, 0299 unsigned int count, int inst_nr, int block_nr, 0300 const char *msg); 0301 0302 /** 0303 * edac_device_handle_ue_count - Log uncorrectable errors. 0304 * 0305 * @edac_dev: pointer to struct &edac_device_ctl_info 0306 * @inst_nr: number of the instance where the CE error happened 0307 * @count: Number of errors to log. 0308 * @block_nr: number of the block where the CE error happened 0309 * @msg: message to be printed 0310 */ 0311 void edac_device_handle_ue_count(struct edac_device_ctl_info *edac_dev, 0312 unsigned int count, int inst_nr, int block_nr, 0313 const char *msg); 0314 0315 /** 0316 * edac_device_handle_ce(): Log a single correctable error 0317 * 0318 * @edac_dev: pointer to struct &edac_device_ctl_info 0319 * @inst_nr: number of the instance where the CE error happened 0320 * @block_nr: number of the block where the CE error happened 0321 * @msg: message to be printed 0322 */ 0323 static inline void 0324 edac_device_handle_ce(struct edac_device_ctl_info *edac_dev, int inst_nr, 0325 int block_nr, const char *msg) 0326 { 0327 edac_device_handle_ce_count(edac_dev, 1, inst_nr, block_nr, msg); 0328 } 0329 0330 /** 0331 * edac_device_handle_ue(): Log a single uncorrectable error 0332 * 0333 * @edac_dev: pointer to struct &edac_device_ctl_info 0334 * @inst_nr: number of the instance where the UE error happened 0335 * @block_nr: number of the block where the UE error happened 0336 * @msg: message to be printed 0337 */ 0338 static inline void 0339 edac_device_handle_ue(struct edac_device_ctl_info *edac_dev, int inst_nr, 0340 int block_nr, const char *msg) 0341 { 0342 edac_device_handle_ue_count(edac_dev, 1, inst_nr, block_nr, msg); 0343 } 0344 0345 /** 0346 * edac_device_alloc_index: Allocate a unique device index number 0347 * 0348 * Returns: 0349 * allocated index number 0350 */ 0351 extern int edac_device_alloc_index(void); 0352 extern const char *edac_layer_name[]; 0353 0354 /* Free the actual struct */ 0355 static inline void __edac_device_free_ctl_info(struct edac_device_ctl_info *ci) 0356 { 0357 if (ci) { 0358 kfree(ci->pvt_info); 0359 kfree(ci->attribs); 0360 kfree(ci->blocks); 0361 kfree(ci->instances); 0362 kfree(ci); 0363 } 0364 } 0365 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |