Commit | Line | Data |
---|---|---|
6d8ef247 MCC |
1 | /* |
2 | * Defines, structures, APIs for edac_device | |
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 | * Please look at Documentation/driver-api/edac.rst for more info about | |
19 | * EDAC core structs and functions. | |
20 | */ | |
21 | ||
22 | #ifndef _EDAC_DEVICE_H_ | |
23 | #define _EDAC_DEVICE_H_ | |
24 | ||
25 | #include <linux/completion.h> | |
26 | #include <linux/device.h> | |
27 | #include <linux/edac.h> | |
28 | #include <linux/kobject.h> | |
29 | #include <linux/list.h> | |
30 | #include <linux/types.h> | |
31 | #include <linux/sysfs.h> | |
32 | #include <linux/workqueue.h> | |
33 | ||
34 | ||
35 | /* | |
36 | * The following are the structures to provide for a generic | |
37 | * or abstract 'edac_device'. This set of structures and the | |
38 | * code that implements the APIs for the same, provide for | |
39 | * registering EDAC type devices which are NOT standard memory. | |
40 | * | |
41 | * CPU caches (L1 and L2) | |
42 | * DMA engines | |
43 | * Core CPU switches | |
44 | * Fabric switch units | |
45 | * PCIe interface controllers | |
46 | * other EDAC/ECC type devices that can be monitored for | |
47 | * errors, etc. | |
48 | * | |
49 | * It allows for a 2 level set of hierarchy. For example: | |
50 | * | |
51 | * cache could be composed of L1, L2 and L3 levels of cache. | |
52 | * Each CPU core would have its own L1 cache, while sharing | |
53 | * L2 and maybe L3 caches. | |
54 | * | |
55 | * View them arranged, via the sysfs presentation: | |
56 | * /sys/devices/system/edac/.. | |
57 | * | |
58 | * mc/ <existing memory device directory> | |
59 | * cpu/cpu0/.. <L1 and L2 block directory> | |
60 | * /L1-cache/ce_count | |
61 | * /ue_count | |
62 | * /L2-cache/ce_count | |
63 | * /ue_count | |
64 | * cpu/cpu1/.. <L1 and L2 block directory> | |
65 | * /L1-cache/ce_count | |
66 | * /ue_count | |
67 | * /L2-cache/ce_count | |
68 | * /ue_count | |
69 | * ... | |
70 | * | |
71 | * the L1 and L2 directories would be "edac_device_block's" | |
72 | */ | |
73 | ||
74 | struct edac_device_counter { | |
75 | u32 ue_count; | |
76 | u32 ce_count; | |
77 | }; | |
78 | ||
79 | /* forward reference */ | |
80 | struct edac_device_ctl_info; | |
81 | struct edac_device_block; | |
82 | ||
83 | /* edac_dev_sysfs_attribute structure | |
84 | * used for driver sysfs attributes in mem_ctl_info | |
85 | * for extra controls and attributes: | |
86 | * like high level error Injection controls | |
87 | */ | |
88 | struct edac_dev_sysfs_attribute { | |
89 | struct attribute attr; | |
90 | ssize_t (*show)(struct edac_device_ctl_info *, char *); | |
91 | ssize_t (*store)(struct edac_device_ctl_info *, const char *, size_t); | |
92 | }; | |
93 | ||
94 | /* edac_dev_sysfs_block_attribute structure | |
95 | * | |
96 | * used in leaf 'block' nodes for adding controls/attributes | |
97 | * | |
9186695e JSS |
98 | * each block in each instance of the containing control structure can |
99 | * have an array of the following. The show function will be filled in | |
100 | * with the show function in the low level driver. | |
6d8ef247 MCC |
101 | */ |
102 | struct edac_dev_sysfs_block_attribute { | |
103 | struct attribute attr; | |
104 | ssize_t (*show)(struct kobject *, struct attribute *, char *); | |
6d8ef247 MCC |
105 | }; |
106 | ||
107 | /* device block control structure */ | |
108 | struct edac_device_block { | |
109 | struct edac_device_instance *instance; /* Up Pointer */ | |
110 | char name[EDAC_DEVICE_NAME_LEN + 1]; | |
111 | ||
112 | struct edac_device_counter counters; /* basic UE and CE counters */ | |
113 | ||
114 | int nr_attribs; /* how many attributes */ | |
115 | ||
116 | /* this block's attributes, could be NULL */ | |
117 | struct edac_dev_sysfs_block_attribute *block_attributes; | |
118 | ||
119 | /* edac sysfs device control */ | |
120 | struct kobject kobj; | |
121 | }; | |
122 | ||
123 | /* device instance control structure */ | |
124 | struct edac_device_instance { | |
125 | struct edac_device_ctl_info *ctl; /* Up pointer */ | |
126 | char name[EDAC_DEVICE_NAME_LEN + 4]; | |
127 | ||
128 | struct edac_device_counter counters; /* instance counters */ | |
129 | ||
130 | u32 nr_blocks; /* how many blocks */ | |
131 | struct edac_device_block *blocks; /* block array */ | |
132 | ||
133 | /* edac sysfs device control */ | |
134 | struct kobject kobj; | |
135 | }; | |
136 | ||
137 | ||
138 | /* | |
139 | * Abstract edac_device control info structure | |
140 | * | |
141 | */ | |
142 | struct edac_device_ctl_info { | |
143 | /* for global list of edac_device_ctl_info structs */ | |
144 | struct list_head link; | |
145 | ||
146 | struct module *owner; /* Module owner of this control struct */ | |
147 | ||
148 | int dev_idx; | |
149 | ||
150 | /* Per instance controls for this edac_device */ | |
151 | int log_ue; /* boolean for logging UEs */ | |
152 | int log_ce; /* boolean for logging CEs */ | |
153 | int panic_on_ue; /* boolean for panic'ing on an UE */ | |
154 | unsigned poll_msec; /* number of milliseconds to poll interval */ | |
155 | unsigned long delay; /* number of jiffies for poll_msec */ | |
156 | ||
157 | /* Additional top controller level attributes, but specified | |
158 | * by the low level driver. | |
159 | * | |
160 | * Set by the low level driver to provide attributes at the | |
161 | * controller level, same level as 'ue_count' and 'ce_count' above. | |
162 | * An array of structures, NULL terminated | |
163 | * | |
164 | * If attributes are desired, then set to array of attributes | |
165 | * If no attributes are desired, leave NULL | |
166 | */ | |
167 | struct edac_dev_sysfs_attribute *sysfs_attributes; | |
168 | ||
169 | /* pointer to main 'edac' subsys in sysfs */ | |
f36be9ce | 170 | const struct bus_type *edac_subsys; |
6d8ef247 MCC |
171 | |
172 | /* the internal state of this controller instance */ | |
173 | int op_state; | |
174 | /* work struct for this instance */ | |
175 | struct delayed_work work; | |
176 | ||
177 | /* pointer to edac polling checking routine: | |
178 | * If NOT NULL: points to polling check routine | |
179 | * If NULL: Then assumes INTERRUPT operation, where | |
180 | * MC driver will receive events | |
181 | */ | |
182 | void (*edac_check) (struct edac_device_ctl_info * edac_dev); | |
183 | ||
184 | struct device *dev; /* pointer to device structure */ | |
185 | ||
186 | const char *mod_name; /* module name */ | |
187 | const char *ctl_name; /* edac controller name */ | |
188 | const char *dev_name; /* pci/platform/etc... name */ | |
189 | ||
190 | void *pvt_info; /* pointer to 'private driver' info */ | |
191 | ||
192 | unsigned long start_time; /* edac_device load start time (jiffies) */ | |
193 | ||
194 | struct completion removal_complete; | |
195 | ||
196 | /* sysfs top name under 'edac' directory | |
197 | * and instance name: | |
198 | * cpu/cpu0/... | |
199 | * cpu/cpu1/... | |
200 | * cpu/cpu2/... | |
201 | * ... | |
202 | */ | |
203 | char name[EDAC_DEVICE_NAME_LEN + 1]; | |
204 | ||
205 | /* Number of instances supported on this control structure | |
206 | * and the array of those instances | |
207 | */ | |
208 | u32 nr_instances; | |
209 | struct edac_device_instance *instances; | |
9fb9ce39 BP |
210 | struct edac_device_block *blocks; |
211 | struct edac_dev_sysfs_block_attribute *attribs; | |
6d8ef247 MCC |
212 | |
213 | /* Event counters for the this whole EDAC Device */ | |
214 | struct edac_device_counter counters; | |
215 | ||
216 | /* edac sysfs device control for the 'name' | |
217 | * device this structure controls | |
218 | */ | |
219 | struct kobject kobj; | |
220 | }; | |
221 | ||
222 | /* To get from the instance's wq to the beginning of the ctl structure */ | |
223 | #define to_edac_mem_ctl_work(w) \ | |
224 | container_of(w, struct mem_ctl_info, work) | |
225 | ||
226 | #define to_edac_device_ctl_work(w) \ | |
227 | container_of(w,struct edac_device_ctl_info,work) | |
228 | ||
229 | /* | |
230 | * The alloc() and free() functions for the 'edac_device' control info | |
231 | * structure. A MC driver will allocate one of these for each edac_device | |
232 | * it is going to control/register with the EDAC CORE. | |
233 | */ | |
234 | extern struct edac_device_ctl_info *edac_device_alloc_ctl_info( | |
235 | unsigned sizeof_private, | |
236 | char *edac_device_name, unsigned nr_instances, | |
237 | char *edac_block_name, unsigned nr_blocks, | |
238 | unsigned offset_value, | |
239 | struct edac_dev_sysfs_block_attribute *block_attributes, | |
240 | unsigned nr_attribs, | |
241 | int device_index); | |
242 | ||
243 | /* The offset value can be: | |
244 | * -1 indicating no offset value | |
245 | * 0 for zero-based block numbers | |
246 | * 1 for 1-based block number | |
247 | * other for other-based block number | |
248 | */ | |
249 | #define BLOCK_OFFSET_VALUE_OFF ((unsigned) -1) | |
250 | ||
251 | extern void edac_device_free_ctl_info(struct edac_device_ctl_info *ctl_info); | |
252 | ||
5336f754 | 253 | /** |
24269999 | 254 | * edac_device_add_device - Insert the 'edac_dev' structure into the |
5336f754 MCC |
255 | * edac_device global list and create sysfs entries associated with |
256 | * edac_device structure. | |
257 | * | |
258 | * @edac_dev: pointer to edac_device structure to be added to the list | |
259 | * 'edac_device' structure. | |
260 | * | |
261 | * Returns: | |
262 | * 0 on Success, or an error code on failure | |
263 | */ | |
6d8ef247 | 264 | extern int edac_device_add_device(struct edac_device_ctl_info *edac_dev); |
5336f754 MCC |
265 | |
266 | /** | |
24269999 MCC |
267 | * edac_device_del_device - Remove sysfs entries for specified edac_device |
268 | * structure and then remove edac_device structure from global list | |
5336f754 MCC |
269 | * |
270 | * @dev: | |
271 | * Pointer to struct &device representing the edac device | |
272 | * structure to remove. | |
273 | * | |
274 | * Returns: | |
275 | * Pointer to removed edac_device structure, | |
276 | * or %NULL if device not found. | |
277 | */ | |
6d8ef247 | 278 | extern struct edac_device_ctl_info *edac_device_del_device(struct device *dev); |
5336f754 MCC |
279 | |
280 | /** | |
24269999 | 281 | * edac_device_handle_ce_count - Log correctable errors. |
5336f754 MCC |
282 | * |
283 | * @edac_dev: pointer to struct &edac_device_ctl_info | |
9816b4af HH |
284 | * @inst_nr: number of the instance where the CE error happened |
285 | * @count: Number of errors to log. | |
286 | * @block_nr: number of the block where the CE error happened | |
287 | * @msg: message to be printed | |
288 | */ | |
289 | void edac_device_handle_ce_count(struct edac_device_ctl_info *edac_dev, | |
290 | unsigned int count, int inst_nr, int block_nr, | |
291 | const char *msg); | |
292 | ||
293 | /** | |
24269999 | 294 | * edac_device_handle_ue_count - Log uncorrectable errors. |
9816b4af HH |
295 | * |
296 | * @edac_dev: pointer to struct &edac_device_ctl_info | |
297 | * @inst_nr: number of the instance where the CE error happened | |
298 | * @count: Number of errors to log. | |
299 | * @block_nr: number of the block where the CE error happened | |
5336f754 MCC |
300 | * @msg: message to be printed |
301 | */ | |
9816b4af HH |
302 | void edac_device_handle_ue_count(struct edac_device_ctl_info *edac_dev, |
303 | unsigned int count, int inst_nr, int block_nr, | |
304 | const char *msg); | |
305 | ||
5336f754 | 306 | /** |
9816b4af | 307 | * edac_device_handle_ce(): Log a single correctable error |
5336f754 MCC |
308 | * |
309 | * @edac_dev: pointer to struct &edac_device_ctl_info | |
310 | * @inst_nr: number of the instance where the CE error happened | |
311 | * @block_nr: number of the block where the CE error happened | |
312 | * @msg: message to be printed | |
313 | */ | |
9816b4af HH |
314 | static inline void |
315 | edac_device_handle_ce(struct edac_device_ctl_info *edac_dev, int inst_nr, | |
316 | int block_nr, const char *msg) | |
317 | { | |
318 | edac_device_handle_ce_count(edac_dev, 1, inst_nr, block_nr, msg); | |
319 | } | |
320 | ||
321 | /** | |
322 | * edac_device_handle_ue(): Log a single uncorrectable error | |
323 | * | |
324 | * @edac_dev: pointer to struct &edac_device_ctl_info | |
325 | * @inst_nr: number of the instance where the UE error happened | |
326 | * @block_nr: number of the block where the UE error happened | |
327 | * @msg: message to be printed | |
328 | */ | |
329 | static inline void | |
330 | edac_device_handle_ue(struct edac_device_ctl_info *edac_dev, int inst_nr, | |
331 | int block_nr, const char *msg) | |
332 | { | |
333 | edac_device_handle_ue_count(edac_dev, 1, inst_nr, block_nr, msg); | |
334 | } | |
5336f754 MCC |
335 | |
336 | /** | |
337 | * edac_device_alloc_index: Allocate a unique device index number | |
338 | * | |
339 | * Returns: | |
340 | * allocated index number | |
341 | */ | |
6d8ef247 MCC |
342 | extern int edac_device_alloc_index(void); |
343 | extern const char *edac_layer_name[]; | |
9fb9ce39 BP |
344 | |
345 | /* Free the actual struct */ | |
346 | static inline void __edac_device_free_ctl_info(struct edac_device_ctl_info *ci) | |
347 | { | |
348 | if (ci) { | |
349 | kfree(ci->pvt_info); | |
350 | kfree(ci->attribs); | |
351 | kfree(ci->blocks); | |
352 | kfree(ci->instances); | |
353 | kfree(ci); | |
354 | } | |
355 | } | |
6d8ef247 | 356 | #endif |