2 * Defines, structures, APIs for edac_device
4 * (C) 2007 Linux Networx (http://lnxi.com)
5 * This file may be distributed under the terms of the
6 * GNU General Public License.
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/
12 * NMI handling support added by
13 * Dave Peterson <dsp@llnl.gov> <dave_peterson@pobox.com>
15 * Refactored for multi-source files:
16 * Doug Thompson <norsk5@xmission.com>
18 * Please look at Documentation/driver-api/edac.rst for more info about
19 * EDAC core structs and functions.
22 #ifndef _EDAC_DEVICE_H_
23 #define _EDAC_DEVICE_H_
25 #include <linux/device.h>
26 #include <linux/edac.h>
27 #include <linux/kobject.h>
28 #include <linux/list.h>
29 #include <linux/types.h>
30 #include <linux/sysfs.h>
31 #include <linux/workqueue.h>
35 * The following are the structures to provide for a generic
36 * or abstract 'edac_device'. This set of structures and the
37 * code that implements the APIs for the same, provide for
38 * registering EDAC type devices which are NOT standard memory.
40 * CPU caches (L1 and L2)
44 * PCIe interface controllers
45 * other EDAC/ECC type devices that can be monitored for
48 * It allows for a 2 level set of hierarchy. For example:
50 * cache could be composed of L1, L2 and L3 levels of cache.
51 * Each CPU core would have its own L1 cache, while sharing
52 * L2 and maybe L3 caches.
54 * View them arranged, via the sysfs presentation:
55 * /sys/devices/system/edac/..
57 * mc/ <existing memory device directory>
58 * cpu/cpu0/.. <L1 and L2 block directory>
63 * cpu/cpu1/.. <L1 and L2 block directory>
70 * the L1 and L2 directories would be "edac_device_block's"
73 struct edac_device_counter
{
78 /* forward reference */
79 struct edac_device_ctl_info
;
80 struct edac_device_block
;
82 /* edac_dev_sysfs_attribute structure
83 * used for driver sysfs attributes in mem_ctl_info
84 * for extra controls and attributes:
85 * like high level error Injection controls
87 struct edac_dev_sysfs_attribute
{
88 struct attribute attr
;
89 ssize_t (*show
)(struct edac_device_ctl_info
*, char *);
90 ssize_t (*store
)(struct edac_device_ctl_info
*, const char *, size_t);
93 /* edac_dev_sysfs_block_attribute structure
95 * used in leaf 'block' nodes for adding controls/attributes
97 * each block in each instance of the containing control structure can
98 * have an array of the following. The show function will be filled in
99 * with the show function in the low level driver.
101 struct edac_dev_sysfs_block_attribute
{
102 struct attribute attr
;
103 ssize_t (*show
)(struct kobject
*, struct attribute
*, char *);
106 /* device block control structure */
107 struct edac_device_block
{
108 struct edac_device_instance
*instance
; /* Up Pointer */
109 char name
[EDAC_DEVICE_NAME_LEN
+ 1];
111 struct edac_device_counter counters
; /* basic UE and CE counters */
113 int nr_attribs
; /* how many attributes */
115 /* this block's attributes, could be NULL */
116 struct edac_dev_sysfs_block_attribute
*block_attributes
;
118 /* edac sysfs device control */
122 /* device instance control structure */
123 struct edac_device_instance
{
124 struct edac_device_ctl_info
*ctl
; /* Up pointer */
125 char name
[EDAC_DEVICE_NAME_LEN
+ 4];
127 struct edac_device_counter counters
; /* instance counters */
129 u32 nr_blocks
; /* how many blocks */
130 struct edac_device_block
*blocks
; /* block array */
132 /* edac sysfs device control */
138 * Abstract edac_device control info structure
141 struct edac_device_ctl_info
{
142 /* for global list of edac_device_ctl_info structs */
143 struct list_head link
;
145 struct module
*owner
; /* Module owner of this control struct */
149 /* Per instance controls for this edac_device */
150 int log_ue
; /* boolean for logging UEs */
151 int log_ce
; /* boolean for logging CEs */
152 int panic_on_ue
; /* boolean for panic'ing on an UE */
153 unsigned poll_msec
; /* number of milliseconds to poll interval */
154 unsigned long delay
; /* number of jiffies for poll_msec */
156 /* Additional top controller level attributes, but specified
157 * by the low level driver.
159 * Set by the low level driver to provide attributes at the
160 * controller level, same level as 'ue_count' and 'ce_count' above.
161 * An array of structures, NULL terminated
163 * If attributes are desired, then set to array of attributes
164 * If no attributes are desired, leave NULL
166 struct edac_dev_sysfs_attribute
*sysfs_attributes
;
168 /* pointer to main 'edac' subsys in sysfs */
169 const struct bus_type
*edac_subsys
;
171 /* the internal state of this controller instance */
173 /* work struct for this instance */
174 struct delayed_work work
;
176 /* pointer to edac polling checking routine:
177 * If NOT NULL: points to polling check routine
178 * If NULL: Then assumes INTERRUPT operation, where
179 * MC driver will receive events
181 void (*edac_check
) (struct edac_device_ctl_info
* edac_dev
);
183 struct device
*dev
; /* pointer to device structure */
185 const char *mod_name
; /* module name */
186 const char *ctl_name
; /* edac controller name */
187 const char *dev_name
; /* pci/platform/etc... name */
189 void *pvt_info
; /* pointer to 'private driver' info */
191 unsigned long start_time
; /* edac_device load start time (jiffies) */
193 /* sysfs top name under 'edac' directory
200 char name
[EDAC_DEVICE_NAME_LEN
+ 1];
202 /* Number of instances supported on this control structure
203 * and the array of those instances
206 struct edac_device_instance
*instances
;
207 struct edac_device_block
*blocks
;
209 /* Event counters for the this whole EDAC Device */
210 struct edac_device_counter counters
;
212 /* edac sysfs device control for the 'name'
213 * device this structure controls
218 /* To get from the instance's wq to the beginning of the ctl structure */
219 #define to_edac_mem_ctl_work(w) \
220 container_of(w, struct mem_ctl_info, work)
222 #define to_edac_device_ctl_work(w) \
223 container_of(w,struct edac_device_ctl_info,work)
226 * The alloc() and free() functions for the 'edac_device' control info
227 * structure. A MC driver will allocate one of these for each edac_device
228 * it is going to control/register with the EDAC CORE.
230 extern struct edac_device_ctl_info
*edac_device_alloc_ctl_info(
231 unsigned sizeof_private
,
232 char *edac_device_name
, unsigned nr_instances
,
233 char *edac_block_name
, unsigned nr_blocks
,
234 unsigned offset_value
,
237 /* The offset value can be:
238 * -1 indicating no offset value
239 * 0 for zero-based block numbers
240 * 1 for 1-based block number
241 * other for other-based block number
243 #define BLOCK_OFFSET_VALUE_OFF ((unsigned) -1)
245 extern void edac_device_free_ctl_info(struct edac_device_ctl_info
*ctl_info
);
248 * edac_device_add_device - Insert the 'edac_dev' structure into the
249 * edac_device global list and create sysfs entries associated with
250 * edac_device structure.
252 * @edac_dev: pointer to edac_device structure to be added to the list
253 * 'edac_device' structure.
256 * 0 on Success, or an error code on failure
258 extern int edac_device_add_device(struct edac_device_ctl_info
*edac_dev
);
261 * edac_device_del_device - Remove sysfs entries for specified edac_device
262 * structure and then remove edac_device structure from global list
265 * Pointer to struct &device representing the edac device
266 * structure to remove.
269 * Pointer to removed edac_device structure,
270 * or %NULL if device not found.
272 extern struct edac_device_ctl_info
*edac_device_del_device(struct device
*dev
);
275 * edac_device_handle_ce_count - Log correctable errors.
277 * @edac_dev: pointer to struct &edac_device_ctl_info
278 * @inst_nr: number of the instance where the CE error happened
279 * @count: Number of errors to log.
280 * @block_nr: number of the block where the CE error happened
281 * @msg: message to be printed
283 void edac_device_handle_ce_count(struct edac_device_ctl_info
*edac_dev
,
284 unsigned int count
, int inst_nr
, int block_nr
,
288 * edac_device_handle_ue_count - Log uncorrectable errors.
290 * @edac_dev: pointer to struct &edac_device_ctl_info
291 * @inst_nr: number of the instance where the CE error happened
292 * @count: Number of errors to log.
293 * @block_nr: number of the block where the CE error happened
294 * @msg: message to be printed
296 void edac_device_handle_ue_count(struct edac_device_ctl_info
*edac_dev
,
297 unsigned int count
, int inst_nr
, int block_nr
,
301 * edac_device_handle_ce(): Log a single correctable error
303 * @edac_dev: pointer to struct &edac_device_ctl_info
304 * @inst_nr: number of the instance where the CE error happened
305 * @block_nr: number of the block where the CE error happened
306 * @msg: message to be printed
309 edac_device_handle_ce(struct edac_device_ctl_info
*edac_dev
, int inst_nr
,
310 int block_nr
, const char *msg
)
312 edac_device_handle_ce_count(edac_dev
, 1, inst_nr
, block_nr
, msg
);
316 * edac_device_handle_ue(): Log a single uncorrectable error
318 * @edac_dev: pointer to struct &edac_device_ctl_info
319 * @inst_nr: number of the instance where the UE error happened
320 * @block_nr: number of the block where the UE error happened
321 * @msg: message to be printed
324 edac_device_handle_ue(struct edac_device_ctl_info
*edac_dev
, int inst_nr
,
325 int block_nr
, const char *msg
)
327 edac_device_handle_ue_count(edac_dev
, 1, inst_nr
, block_nr
, msg
);
331 * edac_device_alloc_index: Allocate a unique device index number
334 * allocated index number
336 extern int edac_device_alloc_index(void);
337 extern const char *edac_layer_name
[];
339 /* Free the actual struct */
340 static inline void __edac_device_free_ctl_info(struct edac_device_ctl_info
*ci
)
345 kfree(ci
->instances
);