edac_core.h 26 KB

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