]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/edac/edac_mc.h
net/mlx5e: Fix kbuild warnings for uninitialized parameters
[mirror_ubuntu-artful-kernel.git] / drivers / edac / edac_mc.h
CommitLineData
7c9281d7 1/*
78d88e8a 2 * Defines, structures, APIs for edac_mc module
7c9281d7
DT
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 *
66c222a0
MCC
18 * Please look at Documentation/driver-api/edac.rst for more info about
19 * EDAC core structs and functions.
7c9281d7
DT
20 */
21
78d88e8a
MCC
22#ifndef _EDAC_MC_H_
23#define _EDAC_MC_H_
7c9281d7
DT
24
25#include <linux/kernel.h>
26#include <linux/types.h>
27#include <linux/module.h>
28#include <linux/spinlock.h>
29#include <linux/smp.h>
30#include <linux/pci.h>
31#include <linux/time.h>
32#include <linux/nmi.h>
33#include <linux/rcupdate.h>
34#include <linux/completion.h>
35#include <linux/kobject.h>
36#include <linux/platform_device.h>
e27e3dac 37#include <linux/workqueue.h>
ddeb3547 38#include <linux/edac.h>
7c9281d7 39
7c9281d7 40#if PAGE_SHIFT < 20
76f04f25
AK
41#define PAGES_TO_MiB(pages) ((pages) >> (20 - PAGE_SHIFT))
42#define MiB_TO_PAGES(mb) ((mb) << (20 - PAGE_SHIFT))
7c9281d7 43#else /* PAGE_SHIFT > 20 */
76f04f25 44#define PAGES_TO_MiB(pages) ((pages) << (PAGE_SHIFT - 20))
e9144601 45#define MiB_TO_PAGES(mb) ((mb) >> (PAGE_SHIFT - 20))
7c9281d7
DT
46#endif
47
48#define edac_printk(level, prefix, fmt, arg...) \
49 printk(level "EDAC " prefix ": " fmt, ##arg)
50
51#define edac_mc_printk(mci, level, fmt, arg...) \
52 printk(level "EDAC MC%d: " fmt, mci->mc_idx, ##arg)
53
54#define edac_mc_chipset_printk(mci, level, prefix, fmt, arg...) \
55 printk(level "EDAC " prefix " MC%d: " fmt, mci->mc_idx, ##arg)
56
e27e3dac
DT
57#define edac_device_printk(ctl, level, fmt, arg...) \
58 printk(level "EDAC DEVICE%d: " fmt, ctl->dev_idx, ##arg)
59
91b99041
DJ
60#define edac_pci_printk(ctl, level, fmt, arg...) \
61 printk(level "EDAC PCI%d: " fmt, ctl->pci_idx, ##arg)
62
7c9281d7
DT
63/* prefixes for edac_printk() and edac_mc_printk() */
64#define EDAC_MC "MC"
65#define EDAC_PCI "PCI"
66#define EDAC_DEBUG "DEBUG"
67
f4ce6eca 68extern const char * const edac_mem_types[];
24f9a7fe 69
7c9281d7
DT
70#ifdef CONFIG_EDAC_DEBUG
71extern int edac_debug_level;
72
956b9ba1 73#define edac_dbg(level, fmt, ...) \
7e881856
JP
74do { \
75 if (level <= edac_debug_level) \
76 edac_printk(KERN_DEBUG, EDAC_DEBUG, \
77 "%s: " fmt, __func__, ##__VA_ARGS__); \
78} while (0)
7c9281d7 79
079708b9 80#else /* !CONFIG_EDAC_DEBUG */
7c9281d7 81
956b9ba1 82#define edac_dbg(level, fmt, ...) \
7e881856
JP
83do { \
84 if (0) \
85 edac_printk(KERN_DEBUG, EDAC_DEBUG, \
86 "%s: " fmt, __func__, ##__VA_ARGS__); \
87} while (0)
7c9281d7 88
079708b9 89#endif /* !CONFIG_EDAC_DEBUG */
7c9281d7 90
7c9281d7
DT
91#define PCI_VEND_DEV(vend, dev) PCI_VENDOR_ID_ ## vend, \
92 PCI_DEVICE_ID_ ## vend ## _ ## dev
93
17aa7e03 94#define edac_dev_name(dev) (dev)->dev_name
7c9281d7 95
7ac8bf9b
BP
96#define to_mci(k) container_of(k, struct mem_ctl_info, dev)
97
e01aa14c 98/**
66c222a0
MCC
99 * edac_mc_alloc() - Allocate and partially fill a struct &mem_ctl_info.
100 *
e01aa14c
MCC
101 * @mc_num: Memory controller number
102 * @n_layers: Number of MC hierarchy layers
103 * @layers: Describes each layer as seen by the Memory Controller
104 * @sz_pvt: size of private storage needed
105 *
106 *
107 * Everything is kmalloc'ed as one big chunk - more efficient.
108 * Only can be used if all structures have the same lifetime - otherwise
109 * you have to allocate and initialize your own structures.
110 *
111 * Use edac_mc_free() to free mc structures allocated by this function.
112 *
113 * .. note::
114 *
115 * drivers handle multi-rank memories in different ways: in some
116 * drivers, one multi-rank memory stick is mapped as one entry, while, in
117 * others, a single multi-rank memory stick would be mapped into several
118 * entries. Currently, this function will allocate multiple struct dimm_info
119 * on such scenarios, as grouping the multiple ranks require drivers change.
120 *
121 * Returns:
66c222a0
MCC
122 * On success, return a pointer to struct mem_ctl_info pointer;
123 * %NULL otherwise
e01aa14c 124 */
ca0907b9 125struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
4275be63
MCC
126 unsigned n_layers,
127 struct edac_mc_layer *layers,
128 unsigned sz_pvt);
e01aa14c
MCC
129
130/**
66c222a0
MCC
131 * edac_mc_add_mc_with_groups() - Insert the @mci structure into the mci
132 * global list and create sysfs entries associated with @mci structure.
133 *
e01aa14c
MCC
134 * @mci: pointer to the mci structure to be added to the list
135 * @groups: optional attribute groups for the driver-specific sysfs entries
136 *
66c222a0
MCC
137 * Returns:
138 * 0 on Success, or an error code on failure
e01aa14c 139 */
4e8d230d
TI
140extern int edac_mc_add_mc_with_groups(struct mem_ctl_info *mci,
141 const struct attribute_group **groups);
142#define edac_mc_add_mc(mci) edac_mc_add_mc_with_groups(mci, NULL)
e01aa14c
MCC
143
144/**
66c222a0
MCC
145 * edac_mc_free() - Frees a previously allocated @mci structure
146 *
e01aa14c
MCC
147 * @mci: pointer to a struct mem_ctl_info structure
148 */
b8f6f975 149extern void edac_mc_free(struct mem_ctl_info *mci);
e01aa14c
MCC
150
151/**
66c222a0 152 * edac_mc_find() - Search for a mem_ctl_info structure whose index is @idx.
e01aa14c
MCC
153 *
154 * @idx: index to be seek
155 *
156 * If found, return a pointer to the structure.
157 * Else return NULL.
e01aa14c 158 */
079708b9 159extern struct mem_ctl_info *edac_mc_find(int idx);
e01aa14c
MCC
160
161/**
66c222a0
MCC
162 * find_mci_by_dev() - Scan list of controllers looking for the one that
163 * manages the @dev device.
e01aa14c 164 *
e01aa14c 165 * @dev: pointer to a struct device related with the MCI
66c222a0
MCC
166 *
167 * Returns: on success, returns a pointer to struct &mem_ctl_info;
168 * %NULL otherwise.
e01aa14c 169 */
939747bd 170extern struct mem_ctl_info *find_mci_by_dev(struct device *dev);
e01aa14c
MCC
171
172/**
66c222a0
MCC
173 * edac_mc_del_mc() - Remove sysfs entries for mci structure associated with
174 * @dev and remove mci structure from global list.
e01aa14c
MCC
175 *
176 * @dev: Pointer to struct &device representing mci structure to remove.
177 *
66c222a0 178 * Returns: pointer to removed mci structure, or %NULL if device not found.
e01aa14c 179 */
079708b9 180extern struct mem_ctl_info *edac_mc_del_mc(struct device *dev);
66c222a0
MCC
181
182/**
183 * edac_mc_find_csrow_by_page() - Ancillary routine to identify what csrow
184 * contains a memory page.
185 *
186 * @mci: pointer to a struct mem_ctl_info structure
187 * @page: memory page to find
188 *
189 * Returns: on success, returns the csrow. -1 if not found.
190 */
7c9281d7 191extern int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci,
079708b9 192 unsigned long page);
e7e24830 193
e01aa14c 194/**
66c222a0
MCC
195 * edac_raw_mc_handle_error() - Reports a memory event to userspace without
196 * doing anything to discover the error location.
e01aa14c
MCC
197 *
198 * @type: severity of the error (CE/UE/Fatal)
199 * @mci: a struct mem_ctl_info pointer
200 * @e: error description
201 *
202 * This raw function is used internally by edac_mc_handle_error(). It should
203 * only be called directly when the hardware error come directly from BIOS,
204 * like in the case of APEI GHES driver.
205 */
e7e24830
MCC
206void edac_raw_mc_handle_error(const enum hw_event_mc_err_type type,
207 struct mem_ctl_info *mci,
208 struct edac_raw_error_desc *e);
209
e01aa14c 210/**
66c222a0 211 * edac_mc_handle_error() - Reports a memory event to userspace.
e01aa14c
MCC
212 *
213 * @type: severity of the error (CE/UE/Fatal)
214 * @mci: a struct mem_ctl_info pointer
215 * @error_count: Number of errors of the same type
216 * @page_frame_number: mem page where the error occurred
217 * @offset_in_page: offset of the error inside the page
218 * @syndrome: ECC syndrome
219 * @top_layer: Memory layer[0] position
220 * @mid_layer: Memory layer[1] position
221 * @low_layer: Memory layer[2] position
222 * @msg: Message meaningful to the end users that
223 * explains the event
224 * @other_detail: Technical details about the event that
225 * may help hardware manufacturers and
226 * EDAC developers to analyse the event
227 */
4275be63
MCC
228void edac_mc_handle_error(const enum hw_event_mc_err_type type,
229 struct mem_ctl_info *mci,
9eb07a7f 230 const u16 error_count,
4275be63
MCC
231 const unsigned long page_frame_number,
232 const unsigned long offset_in_page,
233 const unsigned long syndrome,
53f2d028
MCC
234 const int top_layer,
235 const int mid_layer,
236 const int low_layer,
4275be63 237 const char *msg,
03f7eae8 238 const char *other_detail);
7c9281d7 239
91b99041
DJ
240/*
241 * edac misc APIs
242 */
494d0d55 243extern char *edac_op_state_to_string(int op_state);
7c9281d7 244
78d88e8a 245#endif /* _EDAC_MC_H_ */