edac_core.h 27 KB

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