edac_core.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  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. #ifndef _EDAC_CORE_H_
  20. #define _EDAC_CORE_H_
  21. #include <linux/kernel.h>
  22. #include <linux/types.h>
  23. #include <linux/module.h>
  24. #include <linux/spinlock.h>
  25. #include <linux/smp.h>
  26. #include <linux/pci.h>
  27. #include <linux/time.h>
  28. #include <linux/nmi.h>
  29. #include <linux/rcupdate.h>
  30. #include <linux/completion.h>
  31. #include <linux/kobject.h>
  32. #include <linux/platform_device.h>
  33. #include <linux/sysdev.h>
  34. #include <linux/workqueue.h>
  35. #define EDAC_MC_LABEL_LEN 31
  36. #define EDAC_DEVICE_NAME_LEN 31
  37. #define EDAC_ATTRIB_VALUE_LEN 15
  38. #define MC_PROC_NAME_MAX_LEN 7
  39. #if PAGE_SHIFT < 20
  40. #define PAGES_TO_MiB( pages ) ( ( pages ) >> ( 20 - PAGE_SHIFT ) )
  41. #else /* PAGE_SHIFT > 20 */
  42. #define PAGES_TO_MiB( pages ) ( ( pages ) << ( PAGE_SHIFT - 20 ) )
  43. #endif
  44. #define edac_printk(level, prefix, fmt, arg...) \
  45. printk(level "EDAC " prefix ": " fmt, ##arg)
  46. #define edac_printk_verbose(level, prefix, fmt, arg...) \
  47. printk(level "EDAC " prefix ": " "in %s, line at %d: " fmt, \
  48. __FILE__, __LINE__, ##arg)
  49. #define edac_mc_printk(mci, level, fmt, arg...) \
  50. printk(level "EDAC MC%d: " fmt, mci->mc_idx, ##arg)
  51. #define edac_mc_chipset_printk(mci, level, prefix, fmt, arg...) \
  52. printk(level "EDAC " prefix " MC%d: " fmt, mci->mc_idx, ##arg)
  53. /* edac_device printk */
  54. #define edac_device_printk(ctl, level, fmt, arg...) \
  55. printk(level "EDAC DEVICE%d: " fmt, ctl->dev_idx, ##arg)
  56. /* edac_pci printk */
  57. #define edac_pci_printk(ctl, level, fmt, arg...) \
  58. printk(level "EDAC PCI%d: " fmt, ctl->pci_idx, ##arg)
  59. /* prefixes for edac_printk() and edac_mc_printk() */
  60. #define EDAC_MC "MC"
  61. #define EDAC_PCI "PCI"
  62. #define EDAC_DEBUG "DEBUG"
  63. #ifdef CONFIG_EDAC_DEBUG
  64. extern int edac_debug_level;
  65. #ifndef CONFIG_EDAC_DEBUG_VERBOSE
  66. #define edac_debug_printk(level, fmt, arg...) \
  67. do { \
  68. if (level <= edac_debug_level) \
  69. edac_printk(KERN_DEBUG, EDAC_DEBUG, \
  70. "%s: " fmt, __func__, ##arg); \
  71. } while (0)
  72. #else /* CONFIG_EDAC_DEBUG_VERBOSE */
  73. #define edac_debug_printk(level, fmt, arg...) \
  74. do { \
  75. if (level <= edac_debug_level) \
  76. edac_printk_verbose(KERN_DEBUG, EDAC_DEBUG, fmt, \
  77. ##arg); \
  78. } while (0)
  79. #endif
  80. #define debugf0( ... ) edac_debug_printk(0, __VA_ARGS__ )
  81. #define debugf1( ... ) edac_debug_printk(1, __VA_ARGS__ )
  82. #define debugf2( ... ) edac_debug_printk(2, __VA_ARGS__ )
  83. #define debugf3( ... ) edac_debug_printk(3, __VA_ARGS__ )
  84. #define debugf4( ... ) edac_debug_printk(4, __VA_ARGS__ )
  85. #else /* !CONFIG_EDAC_DEBUG */
  86. #define debugf0( ... )
  87. #define debugf1( ... )
  88. #define debugf2( ... )
  89. #define debugf3( ... )
  90. #define debugf4( ... )
  91. #endif /* !CONFIG_EDAC_DEBUG */
  92. #define PCI_VEND_DEV(vend, dev) PCI_VENDOR_ID_ ## vend, \
  93. PCI_DEVICE_ID_ ## vend ## _ ## dev
  94. #define edac_dev_name(dev) (dev)->dev_name
  95. /* memory devices */
  96. enum dev_type {
  97. DEV_UNKNOWN = 0,
  98. DEV_X1,
  99. DEV_X2,
  100. DEV_X4,
  101. DEV_X8,
  102. DEV_X16,
  103. DEV_X32, /* Do these parts exist? */
  104. DEV_X64 /* Do these parts exist? */
  105. };
  106. #define DEV_FLAG_UNKNOWN BIT(DEV_UNKNOWN)
  107. #define DEV_FLAG_X1 BIT(DEV_X1)
  108. #define DEV_FLAG_X2 BIT(DEV_X2)
  109. #define DEV_FLAG_X4 BIT(DEV_X4)
  110. #define DEV_FLAG_X8 BIT(DEV_X8)
  111. #define DEV_FLAG_X16 BIT(DEV_X16)
  112. #define DEV_FLAG_X32 BIT(DEV_X32)
  113. #define DEV_FLAG_X64 BIT(DEV_X64)
  114. /* memory types */
  115. enum mem_type {
  116. MEM_EMPTY = 0, /* Empty csrow */
  117. MEM_RESERVED, /* Reserved csrow type */
  118. MEM_UNKNOWN, /* Unknown csrow type */
  119. MEM_FPM, /* Fast page mode */
  120. MEM_EDO, /* Extended data out */
  121. MEM_BEDO, /* Burst Extended data out */
  122. MEM_SDR, /* Single data rate SDRAM */
  123. MEM_RDR, /* Registered single data rate SDRAM */
  124. MEM_DDR, /* Double data rate SDRAM */
  125. MEM_RDDR, /* Registered Double data rate SDRAM */
  126. MEM_RMBS, /* Rambus DRAM */
  127. MEM_DDR2, /* DDR2 RAM */
  128. MEM_FB_DDR2, /* fully buffered DDR2 */
  129. MEM_RDDR2, /* Registered DDR2 RAM */
  130. MEM_XDR, /* Rambus XDR */
  131. MEM_DDR3, /* DDR3 RAM */
  132. MEM_RDDR3, /* Registered DDR3 RAM */
  133. };
  134. #define MEM_FLAG_EMPTY BIT(MEM_EMPTY)
  135. #define MEM_FLAG_RESERVED BIT(MEM_RESERVED)
  136. #define MEM_FLAG_UNKNOWN BIT(MEM_UNKNOWN)
  137. #define MEM_FLAG_FPM BIT(MEM_FPM)
  138. #define MEM_FLAG_EDO BIT(MEM_EDO)
  139. #define MEM_FLAG_BEDO BIT(MEM_BEDO)
  140. #define MEM_FLAG_SDR BIT(MEM_SDR)
  141. #define MEM_FLAG_RDR BIT(MEM_RDR)
  142. #define MEM_FLAG_DDR BIT(MEM_DDR)
  143. #define MEM_FLAG_RDDR BIT(MEM_RDDR)
  144. #define MEM_FLAG_RMBS BIT(MEM_RMBS)
  145. #define MEM_FLAG_DDR2 BIT(MEM_DDR2)
  146. #define MEM_FLAG_FB_DDR2 BIT(MEM_FB_DDR2)
  147. #define MEM_FLAG_RDDR2 BIT(MEM_RDDR2)
  148. #define MEM_FLAG_XDR BIT(MEM_XDR)
  149. #define MEM_FLAG_DDR3 BIT(MEM_DDR3)
  150. #define MEM_FLAG_RDDR3 BIT(MEM_RDDR3)
  151. /* chipset Error Detection and Correction capabilities and mode */
  152. enum edac_type {
  153. EDAC_UNKNOWN = 0, /* Unknown if ECC is available */
  154. EDAC_NONE, /* Doesnt support ECC */
  155. EDAC_RESERVED, /* Reserved ECC type */
  156. EDAC_PARITY, /* Detects parity errors */
  157. EDAC_EC, /* Error Checking - no correction */
  158. EDAC_SECDED, /* Single bit error correction, Double detection */
  159. EDAC_S2ECD2ED, /* Chipkill x2 devices - do these exist? */
  160. EDAC_S4ECD4ED, /* Chipkill x4 devices */
  161. EDAC_S8ECD8ED, /* Chipkill x8 devices */
  162. EDAC_S16ECD16ED, /* Chipkill x16 devices */
  163. };
  164. #define EDAC_FLAG_UNKNOWN BIT(EDAC_UNKNOWN)
  165. #define EDAC_FLAG_NONE BIT(EDAC_NONE)
  166. #define EDAC_FLAG_PARITY BIT(EDAC_PARITY)
  167. #define EDAC_FLAG_EC BIT(EDAC_EC)
  168. #define EDAC_FLAG_SECDED BIT(EDAC_SECDED)
  169. #define EDAC_FLAG_S2ECD2ED BIT(EDAC_S2ECD2ED)
  170. #define EDAC_FLAG_S4ECD4ED BIT(EDAC_S4ECD4ED)
  171. #define EDAC_FLAG_S8ECD8ED BIT(EDAC_S8ECD8ED)
  172. #define EDAC_FLAG_S16ECD16ED BIT(EDAC_S16ECD16ED)
  173. /* scrubbing capabilities */
  174. enum scrub_type {
  175. SCRUB_UNKNOWN = 0, /* Unknown if scrubber is available */
  176. SCRUB_NONE, /* No scrubber */
  177. SCRUB_SW_PROG, /* SW progressive (sequential) scrubbing */
  178. SCRUB_SW_SRC, /* Software scrub only errors */
  179. SCRUB_SW_PROG_SRC, /* Progressive software scrub from an error */
  180. SCRUB_SW_TUNABLE, /* Software scrub frequency is tunable */
  181. SCRUB_HW_PROG, /* HW progressive (sequential) scrubbing */
  182. SCRUB_HW_SRC, /* Hardware scrub only errors */
  183. SCRUB_HW_PROG_SRC, /* Progressive hardware scrub from an error */
  184. SCRUB_HW_TUNABLE /* Hardware scrub frequency is tunable */
  185. };
  186. #define SCRUB_FLAG_SW_PROG BIT(SCRUB_SW_PROG)
  187. #define SCRUB_FLAG_SW_SRC BIT(SCRUB_SW_SRC)
  188. #define SCRUB_FLAG_SW_PROG_SRC BIT(SCRUB_SW_PROG_SRC)
  189. #define SCRUB_FLAG_SW_TUN BIT(SCRUB_SW_SCRUB_TUNABLE)
  190. #define SCRUB_FLAG_HW_PROG BIT(SCRUB_HW_PROG)
  191. #define SCRUB_FLAG_HW_SRC BIT(SCRUB_HW_SRC)
  192. #define SCRUB_FLAG_HW_PROG_SRC BIT(SCRUB_HW_PROG_SRC)
  193. #define SCRUB_FLAG_HW_TUN BIT(SCRUB_HW_TUNABLE)
  194. /* FIXME - should have notify capabilities: NMI, LOG, PROC, etc */
  195. /* EDAC internal operation states */
  196. #define OP_ALLOC 0x100
  197. #define OP_RUNNING_POLL 0x201
  198. #define OP_RUNNING_INTERRUPT 0x202
  199. #define OP_RUNNING_POLL_INTR 0x203
  200. #define OP_OFFLINE 0x300
  201. /*
  202. * There are several things to be aware of that aren't at all obvious:
  203. *
  204. *
  205. * SOCKETS, SOCKET SETS, BANKS, ROWS, CHIP-SELECT ROWS, CHANNELS, etc..
  206. *
  207. * These are some of the many terms that are thrown about that don't always
  208. * mean what people think they mean (Inconceivable!). In the interest of
  209. * creating a common ground for discussion, terms and their definitions
  210. * will be established.
  211. *
  212. * Memory devices: The individual chip on a memory stick. These devices
  213. * commonly output 4 and 8 bits each. Grouping several
  214. * of these in parallel provides 64 bits which is common
  215. * for a memory stick.
  216. *
  217. * Memory Stick: A printed circuit board that agregates multiple
  218. * memory devices in parallel. This is the atomic
  219. * memory component that is purchaseable by Joe consumer
  220. * and loaded into a memory socket.
  221. *
  222. * Socket: A physical connector on the motherboard that accepts
  223. * a single memory stick.
  224. *
  225. * Channel: Set of memory devices on a memory stick that must be
  226. * grouped in parallel with one or more additional
  227. * channels from other memory sticks. This parallel
  228. * grouping of the output from multiple channels are
  229. * necessary for the smallest granularity of memory access.
  230. * Some memory controllers are capable of single channel -
  231. * which means that memory sticks can be loaded
  232. * individually. Other memory controllers are only
  233. * capable of dual channel - which means that memory
  234. * sticks must be loaded as pairs (see "socket set").
  235. *
  236. * Chip-select row: All of the memory devices that are selected together.
  237. * for a single, minimum grain of memory access.
  238. * This selects all of the parallel memory devices across
  239. * all of the parallel channels. Common chip-select rows
  240. * for single channel are 64 bits, for dual channel 128
  241. * bits.
  242. *
  243. * Single-Ranked stick: A Single-ranked stick has 1 chip-select row of memmory.
  244. * Motherboards commonly drive two chip-select pins to
  245. * a memory stick. A single-ranked stick, will occupy
  246. * only one of those rows. The other will be unused.
  247. *
  248. * Double-Ranked stick: A double-ranked stick has two chip-select rows which
  249. * access different sets of memory devices. The two
  250. * rows cannot be accessed concurrently.
  251. *
  252. * Double-sided stick: DEPRECATED TERM, see Double-Ranked stick.
  253. * A double-sided stick has two chip-select rows which
  254. * access different sets of memory devices. The two
  255. * rows cannot be accessed concurrently. "Double-sided"
  256. * is irrespective of the memory devices being mounted
  257. * on both sides of the memory stick.
  258. *
  259. * Socket set: All of the memory sticks that are required for for
  260. * a single memory access or all of the memory sticks
  261. * spanned by a chip-select row. A single socket set
  262. * has two chip-select rows and if double-sided sticks
  263. * are used these will occupy those chip-select rows.
  264. *
  265. * Bank: This term is avoided because it is unclear when
  266. * needing to distinguish between chip-select rows and
  267. * socket sets.
  268. *
  269. * Controller pages:
  270. *
  271. * Physical pages:
  272. *
  273. * Virtual pages:
  274. *
  275. *
  276. * STRUCTURE ORGANIZATION AND CHOICES
  277. *
  278. *
  279. *
  280. * PS - I enjoyed writing all that about as much as you enjoyed reading it.
  281. */
  282. struct channel_info {
  283. int chan_idx; /* channel index */
  284. u32 ce_count; /* Correctable Errors for this CHANNEL */
  285. char label[EDAC_MC_LABEL_LEN + 1]; /* DIMM label on motherboard */
  286. struct csrow_info *csrow; /* the parent */
  287. };
  288. struct csrow_info {
  289. unsigned long first_page; /* first page number in dimm */
  290. unsigned long last_page; /* last page number in dimm */
  291. unsigned long page_mask; /* used for interleaving -
  292. * 0UL for non intlv
  293. */
  294. u32 nr_pages; /* number of pages in csrow */
  295. u32 grain; /* granularity of reported error in bytes */
  296. int csrow_idx; /* the chip-select row */
  297. enum dev_type dtype; /* memory device type */
  298. u32 ue_count; /* Uncorrectable Errors for this csrow */
  299. u32 ce_count; /* Correctable Errors for this csrow */
  300. enum mem_type mtype; /* memory csrow type */
  301. enum edac_type edac_mode; /* EDAC mode for this csrow */
  302. struct mem_ctl_info *mci; /* the parent */
  303. struct kobject kobj; /* sysfs kobject for this csrow */
  304. /* channel information for this csrow */
  305. u32 nr_channels;
  306. struct channel_info *channels;
  307. };
  308. /* mcidev_sysfs_attribute structure
  309. * used for driver sysfs attributes and in mem_ctl_info
  310. * sysfs top level entries
  311. */
  312. struct mcidev_sysfs_attribute {
  313. struct attribute attr;
  314. ssize_t (*show)(struct mem_ctl_info *,char *);
  315. ssize_t (*store)(struct mem_ctl_info *, const char *,size_t);
  316. };
  317. /* MEMORY controller information structure
  318. */
  319. struct mem_ctl_info {
  320. struct list_head link; /* for global list of mem_ctl_info structs */
  321. struct module *owner; /* Module owner of this control struct */
  322. unsigned long mtype_cap; /* memory types supported by mc */
  323. unsigned long edac_ctl_cap; /* Mem controller EDAC capabilities */
  324. unsigned long edac_cap; /* configuration capabilities - this is
  325. * closely related to edac_ctl_cap. The
  326. * difference is that the controller may be
  327. * capable of s4ecd4ed which would be listed
  328. * in edac_ctl_cap, but if channels aren't
  329. * capable of s4ecd4ed then the edac_cap would
  330. * not have that capability.
  331. */
  332. unsigned long scrub_cap; /* chipset scrub capabilities */
  333. enum scrub_type scrub_mode; /* current scrub mode */
  334. /* Translates sdram memory scrub rate given in bytes/sec to the
  335. internal representation and configures whatever else needs
  336. to be configured.
  337. */
  338. int (*set_sdram_scrub_rate) (struct mem_ctl_info * mci, u32 * bw);
  339. /* Get the current sdram memory scrub rate from the internal
  340. representation and converts it to the closest matching
  341. bandwith in bytes/sec.
  342. */
  343. int (*get_sdram_scrub_rate) (struct mem_ctl_info * mci, u32 * bw);
  344. /* pointer to edac checking routine */
  345. void (*edac_check) (struct mem_ctl_info * mci);
  346. /*
  347. * Remaps memory pages: controller pages to physical pages.
  348. * For most MC's, this will be NULL.
  349. */
  350. /* FIXME - why not send the phys page to begin with? */
  351. unsigned long (*ctl_page_to_phys) (struct mem_ctl_info * mci,
  352. unsigned long page);
  353. int mc_idx;
  354. int nr_csrows;
  355. struct csrow_info *csrows;
  356. /*
  357. * FIXME - what about controllers on other busses? - IDs must be
  358. * unique. dev pointer should be sufficiently unique, but
  359. * BUS:SLOT.FUNC numbers may not be unique.
  360. */
  361. struct device *dev;
  362. const char *mod_name;
  363. const char *mod_ver;
  364. const char *ctl_name;
  365. const char *dev_name;
  366. char proc_name[MC_PROC_NAME_MAX_LEN + 1];
  367. void *pvt_info;
  368. u32 ue_noinfo_count; /* Uncorrectable Errors w/o info */
  369. u32 ce_noinfo_count; /* Correctable Errors w/o info */
  370. u32 ue_count; /* Total Uncorrectable Errors for this MC */
  371. u32 ce_count; /* Total Correctable Errors for this MC */
  372. unsigned long start_time; /* mci load start time (in jiffies) */
  373. /* this stuff is for safe removal of mc devices from global list while
  374. * NMI handlers may be traversing list
  375. */
  376. struct rcu_head rcu;
  377. struct completion complete;
  378. /* edac sysfs device control */
  379. struct kobject edac_mci_kobj;
  380. /* Additional top controller level attributes, but specified
  381. * by the low level driver.
  382. *
  383. * Set by the low level driver to provide attributes at the
  384. * controller level, same level as 'ue_count' and 'ce_count' above.
  385. * An array of structures, NULL terminated
  386. *
  387. * If attributes are desired, then set to array of attributes
  388. * If no attributes are desired, leave NULL
  389. */
  390. struct mcidev_sysfs_attribute *mc_driver_sysfs_attributes;
  391. /* work struct for this MC */
  392. struct delayed_work work;
  393. /* the internal state of this controller instance */
  394. int op_state;
  395. };
  396. /*
  397. * The following are the structures to provide for a generic
  398. * or abstract 'edac_device'. This set of structures and the
  399. * code that implements the APIs for the same, provide for
  400. * registering EDAC type devices which are NOT standard memory.
  401. *
  402. * CPU caches (L1 and L2)
  403. * DMA engines
  404. * Core CPU swithces
  405. * Fabric switch units
  406. * PCIe interface controllers
  407. * other EDAC/ECC type devices that can be monitored for
  408. * errors, etc.
  409. *
  410. * It allows for a 2 level set of hiearchry. For example:
  411. *
  412. * cache could be composed of L1, L2 and L3 levels of cache.
  413. * Each CPU core would have its own L1 cache, while sharing
  414. * L2 and maybe L3 caches.
  415. *
  416. * View them arranged, via the sysfs presentation:
  417. * /sys/devices/system/edac/..
  418. *
  419. * mc/ <existing memory device directory>
  420. * cpu/cpu0/.. <L1 and L2 block directory>
  421. * /L1-cache/ce_count
  422. * /ue_count
  423. * /L2-cache/ce_count
  424. * /ue_count
  425. * cpu/cpu1/.. <L1 and L2 block directory>
  426. * /L1-cache/ce_count
  427. * /ue_count
  428. * /L2-cache/ce_count
  429. * /ue_count
  430. * ...
  431. *
  432. * the L1 and L2 directories would be "edac_device_block's"
  433. */
  434. struct edac_device_counter {
  435. u32 ue_count;
  436. u32 ce_count;
  437. };
  438. /* forward reference */
  439. struct edac_device_ctl_info;
  440. struct edac_device_block;
  441. /* edac_dev_sysfs_attribute structure
  442. * used for driver sysfs attributes in mem_ctl_info
  443. * for extra controls and attributes:
  444. * like high level error Injection controls
  445. */
  446. struct edac_dev_sysfs_attribute {
  447. struct attribute attr;
  448. ssize_t (*show)(struct edac_device_ctl_info *, char *);
  449. ssize_t (*store)(struct edac_device_ctl_info *, const char *, size_t);
  450. };
  451. /* edac_dev_sysfs_block_attribute structure
  452. *
  453. * used in leaf 'block' nodes for adding controls/attributes
  454. *
  455. * each block in each instance of the containing control structure
  456. * can have an array of the following. The show and store functions
  457. * will be filled in with the show/store function in the
  458. * low level driver.
  459. *
  460. * The 'value' field will be the actual value field used for
  461. * counting
  462. */
  463. struct edac_dev_sysfs_block_attribute {
  464. struct attribute attr;
  465. ssize_t (*show)(struct kobject *, struct attribute *, char *);
  466. ssize_t (*store)(struct kobject *, struct attribute *,
  467. const char *, size_t);
  468. struct edac_device_block *block;
  469. unsigned int value;
  470. };
  471. /* device block control structure */
  472. struct edac_device_block {
  473. struct edac_device_instance *instance; /* Up Pointer */
  474. char name[EDAC_DEVICE_NAME_LEN + 1];
  475. struct edac_device_counter counters; /* basic UE and CE counters */
  476. int nr_attribs; /* how many attributes */
  477. /* this block's attributes, could be NULL */
  478. struct edac_dev_sysfs_block_attribute *block_attributes;
  479. /* edac sysfs device control */
  480. struct kobject kobj;
  481. };
  482. /* device instance control structure */
  483. struct edac_device_instance {
  484. struct edac_device_ctl_info *ctl; /* Up pointer */
  485. char name[EDAC_DEVICE_NAME_LEN + 4];
  486. struct edac_device_counter counters; /* instance counters */
  487. u32 nr_blocks; /* how many blocks */
  488. struct edac_device_block *blocks; /* block array */
  489. /* edac sysfs device control */
  490. struct kobject kobj;
  491. };
  492. /*
  493. * Abstract edac_device control info structure
  494. *
  495. */
  496. struct edac_device_ctl_info {
  497. /* for global list of edac_device_ctl_info structs */
  498. struct list_head link;
  499. struct module *owner; /* Module owner of this control struct */
  500. int dev_idx;
  501. /* Per instance controls for this edac_device */
  502. int log_ue; /* boolean for logging UEs */
  503. int log_ce; /* boolean for logging CEs */
  504. int panic_on_ue; /* boolean for panic'ing on an UE */
  505. unsigned poll_msec; /* number of milliseconds to poll interval */
  506. unsigned long delay; /* number of jiffies for poll_msec */
  507. /* Additional top controller level attributes, but specified
  508. * by the low level driver.
  509. *
  510. * Set by the low level driver to provide attributes at the
  511. * controller level, same level as 'ue_count' and 'ce_count' above.
  512. * An array of structures, NULL terminated
  513. *
  514. * If attributes are desired, then set to array of attributes
  515. * If no attributes are desired, leave NULL
  516. */
  517. struct edac_dev_sysfs_attribute *sysfs_attributes;
  518. /* pointer to main 'edac' class in sysfs */
  519. struct sysdev_class *edac_class;
  520. /* the internal state of this controller instance */
  521. int op_state;
  522. /* work struct for this instance */
  523. struct delayed_work work;
  524. /* pointer to edac polling checking routine:
  525. * If NOT NULL: points to polling check routine
  526. * If NULL: Then assumes INTERRUPT operation, where
  527. * MC driver will receive events
  528. */
  529. void (*edac_check) (struct edac_device_ctl_info * edac_dev);
  530. struct device *dev; /* pointer to device structure */
  531. const char *mod_name; /* module name */
  532. const char *ctl_name; /* edac controller name */
  533. const char *dev_name; /* pci/platform/etc... name */
  534. void *pvt_info; /* pointer to 'private driver' info */
  535. unsigned long start_time; /* edac_device load start time (jiffies) */
  536. /* these are for safe removal of mc devices from global list while
  537. * NMI handlers may be traversing list
  538. */
  539. struct rcu_head rcu;
  540. struct completion removal_complete;
  541. /* sysfs top name under 'edac' directory
  542. * and instance name:
  543. * cpu/cpu0/...
  544. * cpu/cpu1/...
  545. * cpu/cpu2/...
  546. * ...
  547. */
  548. char name[EDAC_DEVICE_NAME_LEN + 1];
  549. /* Number of instances supported on this control structure
  550. * and the array of those instances
  551. */
  552. u32 nr_instances;
  553. struct edac_device_instance *instances;
  554. /* Event counters for the this whole EDAC Device */
  555. struct edac_device_counter counters;
  556. /* edac sysfs device control for the 'name'
  557. * device this structure controls
  558. */
  559. struct kobject kobj;
  560. };
  561. /* To get from the instance's wq to the beginning of the ctl structure */
  562. #define to_edac_mem_ctl_work(w) \
  563. container_of(w, struct mem_ctl_info, work)
  564. #define to_edac_device_ctl_work(w) \
  565. container_of(w,struct edac_device_ctl_info,work)
  566. /*
  567. * The alloc() and free() functions for the 'edac_device' control info
  568. * structure. A MC driver will allocate one of these for each edac_device
  569. * it is going to control/register with the EDAC CORE.
  570. */
  571. extern struct edac_device_ctl_info *edac_device_alloc_ctl_info(
  572. unsigned sizeof_private,
  573. char *edac_device_name, unsigned nr_instances,
  574. char *edac_block_name, unsigned nr_blocks,
  575. unsigned offset_value,
  576. struct edac_dev_sysfs_block_attribute *block_attributes,
  577. unsigned nr_attribs,
  578. int device_index);
  579. /* The offset value can be:
  580. * -1 indicating no offset value
  581. * 0 for zero-based block numbers
  582. * 1 for 1-based block number
  583. * other for other-based block number
  584. */
  585. #define BLOCK_OFFSET_VALUE_OFF ((unsigned) -1)
  586. extern void edac_device_free_ctl_info(struct edac_device_ctl_info *ctl_info);
  587. #ifdef CONFIG_PCI
  588. struct edac_pci_counter {
  589. atomic_t pe_count;
  590. atomic_t npe_count;
  591. };
  592. /*
  593. * Abstract edac_pci control info structure
  594. *
  595. */
  596. struct edac_pci_ctl_info {
  597. /* for global list of edac_pci_ctl_info structs */
  598. struct list_head link;
  599. int pci_idx;
  600. struct sysdev_class *edac_class; /* pointer to class */
  601. /* the internal state of this controller instance */
  602. int op_state;
  603. /* work struct for this instance */
  604. struct delayed_work work;
  605. /* pointer to edac polling checking routine:
  606. * If NOT NULL: points to polling check routine
  607. * If NULL: Then assumes INTERRUPT operation, where
  608. * MC driver will receive events
  609. */
  610. void (*edac_check) (struct edac_pci_ctl_info * edac_dev);
  611. struct device *dev; /* pointer to device structure */
  612. const char *mod_name; /* module name */
  613. const char *ctl_name; /* edac controller name */
  614. const char *dev_name; /* pci/platform/etc... name */
  615. void *pvt_info; /* pointer to 'private driver' info */
  616. unsigned long start_time; /* edac_pci load start time (jiffies) */
  617. /* these are for safe removal of devices from global list while
  618. * NMI handlers may be traversing list
  619. */
  620. struct rcu_head rcu;
  621. struct completion complete;
  622. /* sysfs top name under 'edac' directory
  623. * and instance name:
  624. * cpu/cpu0/...
  625. * cpu/cpu1/...
  626. * cpu/cpu2/...
  627. * ...
  628. */
  629. char name[EDAC_DEVICE_NAME_LEN + 1];
  630. /* Event counters for the this whole EDAC Device */
  631. struct edac_pci_counter counters;
  632. /* edac sysfs device control for the 'name'
  633. * device this structure controls
  634. */
  635. struct kobject kobj;
  636. struct completion kobj_complete;
  637. };
  638. #define to_edac_pci_ctl_work(w) \
  639. container_of(w, struct edac_pci_ctl_info,work)
  640. /* write all or some bits in a byte-register*/
  641. static inline void pci_write_bits8(struct pci_dev *pdev, int offset, u8 value,
  642. u8 mask)
  643. {
  644. if (mask != 0xff) {
  645. u8 buf;
  646. pci_read_config_byte(pdev, offset, &buf);
  647. value &= mask;
  648. buf &= ~mask;
  649. value |= buf;
  650. }
  651. pci_write_config_byte(pdev, offset, value);
  652. }
  653. /* write all or some bits in a word-register*/
  654. static inline void pci_write_bits16(struct pci_dev *pdev, int offset,
  655. u16 value, u16 mask)
  656. {
  657. if (mask != 0xffff) {
  658. u16 buf;
  659. pci_read_config_word(pdev, offset, &buf);
  660. value &= mask;
  661. buf &= ~mask;
  662. value |= buf;
  663. }
  664. pci_write_config_word(pdev, offset, value);
  665. }
  666. /*
  667. * pci_write_bits32
  668. *
  669. * edac local routine to do pci_write_config_dword, but adds
  670. * a mask parameter. If mask is all ones, ignore the mask.
  671. * Otherwise utilize the mask to isolate specified bits
  672. *
  673. * write all or some bits in a dword-register
  674. */
  675. static inline void pci_write_bits32(struct pci_dev *pdev, int offset,
  676. u32 value, u32 mask)
  677. {
  678. if (mask != 0xffffffff) {
  679. u32 buf;
  680. pci_read_config_dword(pdev, offset, &buf);
  681. value &= mask;
  682. buf &= ~mask;
  683. value |= buf;
  684. }
  685. pci_write_config_dword(pdev, offset, value);
  686. }
  687. #endif /* CONFIG_PCI */
  688. extern struct mem_ctl_info *edac_mc_alloc(unsigned sz_pvt, unsigned nr_csrows,
  689. unsigned nr_chans, int edac_index);
  690. extern int edac_mc_add_mc(struct mem_ctl_info *mci);
  691. extern void edac_mc_free(struct mem_ctl_info *mci);
  692. extern struct mem_ctl_info *edac_mc_find(int idx);
  693. extern struct mem_ctl_info *edac_mc_del_mc(struct device *dev);
  694. extern int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci,
  695. unsigned long page);
  696. /*
  697. * The no info errors are used when error overflows are reported.
  698. * There are a limited number of error logging registers that can
  699. * be exausted. When all registers are exhausted and an additional
  700. * error occurs then an error overflow register records that an
  701. * error occured and the type of error, but doesn't have any
  702. * further information. The ce/ue versions make for cleaner
  703. * reporting logic and function interface - reduces conditional
  704. * statement clutter and extra function arguments.
  705. */
  706. extern void edac_mc_handle_ce(struct mem_ctl_info *mci,
  707. unsigned long page_frame_number,
  708. unsigned long offset_in_page,
  709. unsigned long syndrome, int row, int channel,
  710. const char *msg);
  711. extern void edac_mc_handle_ce_no_info(struct mem_ctl_info *mci,
  712. const char *msg);
  713. extern void edac_mc_handle_ue(struct mem_ctl_info *mci,
  714. unsigned long page_frame_number,
  715. unsigned long offset_in_page, int row,
  716. const char *msg);
  717. extern void edac_mc_handle_ue_no_info(struct mem_ctl_info *mci,
  718. const char *msg);
  719. extern void edac_mc_handle_fbd_ue(struct mem_ctl_info *mci, unsigned int csrow,
  720. unsigned int channel0, unsigned int channel1,
  721. char *msg);
  722. extern void edac_mc_handle_fbd_ce(struct mem_ctl_info *mci, unsigned int csrow,
  723. unsigned int channel, char *msg);
  724. /*
  725. * edac_device APIs
  726. */
  727. extern int edac_device_add_device(struct edac_device_ctl_info *edac_dev);
  728. extern struct edac_device_ctl_info *edac_device_del_device(struct device *dev);
  729. extern void edac_device_handle_ue(struct edac_device_ctl_info *edac_dev,
  730. int inst_nr, int block_nr, const char *msg);
  731. extern void edac_device_handle_ce(struct edac_device_ctl_info *edac_dev,
  732. int inst_nr, int block_nr, const char *msg);
  733. extern int edac_device_alloc_index(void);
  734. /*
  735. * edac_pci APIs
  736. */
  737. extern struct edac_pci_ctl_info *edac_pci_alloc_ctl_info(unsigned int sz_pvt,
  738. const char *edac_pci_name);
  739. extern void edac_pci_free_ctl_info(struct edac_pci_ctl_info *pci);
  740. extern void edac_pci_reset_delay_period(struct edac_pci_ctl_info *pci,
  741. unsigned long value);
  742. extern int edac_pci_alloc_index(void);
  743. extern int edac_pci_add_device(struct edac_pci_ctl_info *pci, int edac_idx);
  744. extern struct edac_pci_ctl_info *edac_pci_del_device(struct device *dev);
  745. extern struct edac_pci_ctl_info *edac_pci_create_generic_ctl(
  746. struct device *dev,
  747. const char *mod_name);
  748. extern void edac_pci_release_generic_ctl(struct edac_pci_ctl_info *pci);
  749. extern int edac_pci_create_sysfs(struct edac_pci_ctl_info *pci);
  750. extern void edac_pci_remove_sysfs(struct edac_pci_ctl_info *pci);
  751. /*
  752. * edac misc APIs
  753. */
  754. extern char *edac_op_state_to_string(int op_state);
  755. #endif /* _EDAC_CORE_H_ */