PageRenderTime 56ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/include/linux/edac.h

https://gitlab.com/Sean.W/am335x-pru-linux-drivers
C Header | 395 lines | 204 code | 42 blank | 149 comment | 1 complexity | 82660e8774ea73db048e5cad425e92de MD5 | raw file
  1. /*
  2. * Generic EDAC defs
  3. *
  4. * Author: Dave Jiang <djiang@mvista.com>
  5. *
  6. * 2006-2008 (c) MontaVista Software, Inc. This file is licensed under
  7. * the terms of the GNU General Public License version 2. This program
  8. * is licensed "as is" without any warranty of any kind, whether express
  9. * or implied.
  10. *
  11. */
  12. #ifndef _LINUX_EDAC_H_
  13. #define _LINUX_EDAC_H_
  14. #include <linux/atomic.h>
  15. #include <linux/sysdev.h>
  16. #define EDAC_OPSTATE_INVAL -1
  17. #define EDAC_OPSTATE_POLL 0
  18. #define EDAC_OPSTATE_NMI 1
  19. #define EDAC_OPSTATE_INT 2
  20. extern int edac_op_state;
  21. extern int edac_err_assert;
  22. extern atomic_t edac_handlers;
  23. extern struct sysdev_class edac_class;
  24. extern int edac_handler_set(void);
  25. extern void edac_atomic_assert_error(void);
  26. extern struct sysdev_class *edac_get_sysfs_class(void);
  27. extern void edac_put_sysfs_class(void);
  28. static inline void opstate_init(void)
  29. {
  30. switch (edac_op_state) {
  31. case EDAC_OPSTATE_POLL:
  32. case EDAC_OPSTATE_NMI:
  33. break;
  34. default:
  35. edac_op_state = EDAC_OPSTATE_POLL;
  36. }
  37. return;
  38. }
  39. #define EDAC_MC_LABEL_LEN 31
  40. #define MC_PROC_NAME_MAX_LEN 7
  41. /* memory devices */
  42. enum dev_type {
  43. DEV_UNKNOWN = 0,
  44. DEV_X1,
  45. DEV_X2,
  46. DEV_X4,
  47. DEV_X8,
  48. DEV_X16,
  49. DEV_X32, /* Do these parts exist? */
  50. DEV_X64 /* Do these parts exist? */
  51. };
  52. #define DEV_FLAG_UNKNOWN BIT(DEV_UNKNOWN)
  53. #define DEV_FLAG_X1 BIT(DEV_X1)
  54. #define DEV_FLAG_X2 BIT(DEV_X2)
  55. #define DEV_FLAG_X4 BIT(DEV_X4)
  56. #define DEV_FLAG_X8 BIT(DEV_X8)
  57. #define DEV_FLAG_X16 BIT(DEV_X16)
  58. #define DEV_FLAG_X32 BIT(DEV_X32)
  59. #define DEV_FLAG_X64 BIT(DEV_X64)
  60. /* memory types */
  61. enum mem_type {
  62. MEM_EMPTY = 0, /* Empty csrow */
  63. MEM_RESERVED, /* Reserved csrow type */
  64. MEM_UNKNOWN, /* Unknown csrow type */
  65. MEM_FPM, /* Fast page mode */
  66. MEM_EDO, /* Extended data out */
  67. MEM_BEDO, /* Burst Extended data out */
  68. MEM_SDR, /* Single data rate SDRAM */
  69. MEM_RDR, /* Registered single data rate SDRAM */
  70. MEM_DDR, /* Double data rate SDRAM */
  71. MEM_RDDR, /* Registered Double data rate SDRAM */
  72. MEM_RMBS, /* Rambus DRAM */
  73. MEM_DDR2, /* DDR2 RAM */
  74. MEM_FB_DDR2, /* fully buffered DDR2 */
  75. MEM_RDDR2, /* Registered DDR2 RAM */
  76. MEM_XDR, /* Rambus XDR */
  77. MEM_DDR3, /* DDR3 RAM */
  78. MEM_RDDR3, /* Registered DDR3 RAM */
  79. };
  80. #define MEM_FLAG_EMPTY BIT(MEM_EMPTY)
  81. #define MEM_FLAG_RESERVED BIT(MEM_RESERVED)
  82. #define MEM_FLAG_UNKNOWN BIT(MEM_UNKNOWN)
  83. #define MEM_FLAG_FPM BIT(MEM_FPM)
  84. #define MEM_FLAG_EDO BIT(MEM_EDO)
  85. #define MEM_FLAG_BEDO BIT(MEM_BEDO)
  86. #define MEM_FLAG_SDR BIT(MEM_SDR)
  87. #define MEM_FLAG_RDR BIT(MEM_RDR)
  88. #define MEM_FLAG_DDR BIT(MEM_DDR)
  89. #define MEM_FLAG_RDDR BIT(MEM_RDDR)
  90. #define MEM_FLAG_RMBS BIT(MEM_RMBS)
  91. #define MEM_FLAG_DDR2 BIT(MEM_DDR2)
  92. #define MEM_FLAG_FB_DDR2 BIT(MEM_FB_DDR2)
  93. #define MEM_FLAG_RDDR2 BIT(MEM_RDDR2)
  94. #define MEM_FLAG_XDR BIT(MEM_XDR)
  95. #define MEM_FLAG_DDR3 BIT(MEM_DDR3)
  96. #define MEM_FLAG_RDDR3 BIT(MEM_RDDR3)
  97. /* chipset Error Detection and Correction capabilities and mode */
  98. enum edac_type {
  99. EDAC_UNKNOWN = 0, /* Unknown if ECC is available */
  100. EDAC_NONE, /* Doesn't support ECC */
  101. EDAC_RESERVED, /* Reserved ECC type */
  102. EDAC_PARITY, /* Detects parity errors */
  103. EDAC_EC, /* Error Checking - no correction */
  104. EDAC_SECDED, /* Single bit error correction, Double detection */
  105. EDAC_S2ECD2ED, /* Chipkill x2 devices - do these exist? */
  106. EDAC_S4ECD4ED, /* Chipkill x4 devices */
  107. EDAC_S8ECD8ED, /* Chipkill x8 devices */
  108. EDAC_S16ECD16ED, /* Chipkill x16 devices */
  109. };
  110. #define EDAC_FLAG_UNKNOWN BIT(EDAC_UNKNOWN)
  111. #define EDAC_FLAG_NONE BIT(EDAC_NONE)
  112. #define EDAC_FLAG_PARITY BIT(EDAC_PARITY)
  113. #define EDAC_FLAG_EC BIT(EDAC_EC)
  114. #define EDAC_FLAG_SECDED BIT(EDAC_SECDED)
  115. #define EDAC_FLAG_S2ECD2ED BIT(EDAC_S2ECD2ED)
  116. #define EDAC_FLAG_S4ECD4ED BIT(EDAC_S4ECD4ED)
  117. #define EDAC_FLAG_S8ECD8ED BIT(EDAC_S8ECD8ED)
  118. #define EDAC_FLAG_S16ECD16ED BIT(EDAC_S16ECD16ED)
  119. /* scrubbing capabilities */
  120. enum scrub_type {
  121. SCRUB_UNKNOWN = 0, /* Unknown if scrubber is available */
  122. SCRUB_NONE, /* No scrubber */
  123. SCRUB_SW_PROG, /* SW progressive (sequential) scrubbing */
  124. SCRUB_SW_SRC, /* Software scrub only errors */
  125. SCRUB_SW_PROG_SRC, /* Progressive software scrub from an error */
  126. SCRUB_SW_TUNABLE, /* Software scrub frequency is tunable */
  127. SCRUB_HW_PROG, /* HW progressive (sequential) scrubbing */
  128. SCRUB_HW_SRC, /* Hardware scrub only errors */
  129. SCRUB_HW_PROG_SRC, /* Progressive hardware scrub from an error */
  130. SCRUB_HW_TUNABLE /* Hardware scrub frequency is tunable */
  131. };
  132. #define SCRUB_FLAG_SW_PROG BIT(SCRUB_SW_PROG)
  133. #define SCRUB_FLAG_SW_SRC BIT(SCRUB_SW_SRC)
  134. #define SCRUB_FLAG_SW_PROG_SRC BIT(SCRUB_SW_PROG_SRC)
  135. #define SCRUB_FLAG_SW_TUN BIT(SCRUB_SW_SCRUB_TUNABLE)
  136. #define SCRUB_FLAG_HW_PROG BIT(SCRUB_HW_PROG)
  137. #define SCRUB_FLAG_HW_SRC BIT(SCRUB_HW_SRC)
  138. #define SCRUB_FLAG_HW_PROG_SRC BIT(SCRUB_HW_PROG_SRC)
  139. #define SCRUB_FLAG_HW_TUN BIT(SCRUB_HW_TUNABLE)
  140. /* FIXME - should have notify capabilities: NMI, LOG, PROC, etc */
  141. /* EDAC internal operation states */
  142. #define OP_ALLOC 0x100
  143. #define OP_RUNNING_POLL 0x201
  144. #define OP_RUNNING_INTERRUPT 0x202
  145. #define OP_RUNNING_POLL_INTR 0x203
  146. #define OP_OFFLINE 0x300
  147. /*
  148. * There are several things to be aware of that aren't at all obvious:
  149. *
  150. *
  151. * SOCKETS, SOCKET SETS, BANKS, ROWS, CHIP-SELECT ROWS, CHANNELS, etc..
  152. *
  153. * These are some of the many terms that are thrown about that don't always
  154. * mean what people think they mean (Inconceivable!). In the interest of
  155. * creating a common ground for discussion, terms and their definitions
  156. * will be established.
  157. *
  158. * Memory devices: The individual chip on a memory stick. These devices
  159. * commonly output 4 and 8 bits each. Grouping several
  160. * of these in parallel provides 64 bits which is common
  161. * for a memory stick.
  162. *
  163. * Memory Stick: A printed circuit board that aggregates multiple
  164. * memory devices in parallel. This is the atomic
  165. * memory component that is purchaseable by Joe consumer
  166. * and loaded into a memory socket.
  167. *
  168. * Socket: A physical connector on the motherboard that accepts
  169. * a single memory stick.
  170. *
  171. * Channel: Set of memory devices on a memory stick that must be
  172. * grouped in parallel with one or more additional
  173. * channels from other memory sticks. This parallel
  174. * grouping of the output from multiple channels are
  175. * necessary for the smallest granularity of memory access.
  176. * Some memory controllers are capable of single channel -
  177. * which means that memory sticks can be loaded
  178. * individually. Other memory controllers are only
  179. * capable of dual channel - which means that memory
  180. * sticks must be loaded as pairs (see "socket set").
  181. *
  182. * Chip-select row: All of the memory devices that are selected together.
  183. * for a single, minimum grain of memory access.
  184. * This selects all of the parallel memory devices across
  185. * all of the parallel channels. Common chip-select rows
  186. * for single channel are 64 bits, for dual channel 128
  187. * bits.
  188. *
  189. * Single-Ranked stick: A Single-ranked stick has 1 chip-select row of memory.
  190. * Motherboards commonly drive two chip-select pins to
  191. * a memory stick. A single-ranked stick, will occupy
  192. * only one of those rows. The other will be unused.
  193. *
  194. * Double-Ranked stick: A double-ranked stick has two chip-select rows which
  195. * access different sets of memory devices. The two
  196. * rows cannot be accessed concurrently.
  197. *
  198. * Double-sided stick: DEPRECATED TERM, see Double-Ranked stick.
  199. * A double-sided stick has two chip-select rows which
  200. * access different sets of memory devices. The two
  201. * rows cannot be accessed concurrently. "Double-sided"
  202. * is irrespective of the memory devices being mounted
  203. * on both sides of the memory stick.
  204. *
  205. * Socket set: All of the memory sticks that are required for
  206. * a single memory access or all of the memory sticks
  207. * spanned by a chip-select row. A single socket set
  208. * has two chip-select rows and if double-sided sticks
  209. * are used these will occupy those chip-select rows.
  210. *
  211. * Bank: This term is avoided because it is unclear when
  212. * needing to distinguish between chip-select rows and
  213. * socket sets.
  214. *
  215. * Controller pages:
  216. *
  217. * Physical pages:
  218. *
  219. * Virtual pages:
  220. *
  221. *
  222. * STRUCTURE ORGANIZATION AND CHOICES
  223. *
  224. *
  225. *
  226. * PS - I enjoyed writing all that about as much as you enjoyed reading it.
  227. */
  228. struct channel_info {
  229. int chan_idx; /* channel index */
  230. u32 ce_count; /* Correctable Errors for this CHANNEL */
  231. char label[EDAC_MC_LABEL_LEN + 1]; /* DIMM label on motherboard */
  232. struct csrow_info *csrow; /* the parent */
  233. };
  234. struct csrow_info {
  235. unsigned long first_page; /* first page number in dimm */
  236. unsigned long last_page; /* last page number in dimm */
  237. unsigned long page_mask; /* used for interleaving -
  238. * 0UL for non intlv
  239. */
  240. u32 nr_pages; /* number of pages in csrow */
  241. u32 grain; /* granularity of reported error in bytes */
  242. int csrow_idx; /* the chip-select row */
  243. enum dev_type dtype; /* memory device type */
  244. u32 ue_count; /* Uncorrectable Errors for this csrow */
  245. u32 ce_count; /* Correctable Errors for this csrow */
  246. enum mem_type mtype; /* memory csrow type */
  247. enum edac_type edac_mode; /* EDAC mode for this csrow */
  248. struct mem_ctl_info *mci; /* the parent */
  249. struct kobject kobj; /* sysfs kobject for this csrow */
  250. /* channel information for this csrow */
  251. u32 nr_channels;
  252. struct channel_info *channels;
  253. };
  254. struct mcidev_sysfs_group {
  255. const char *name; /* group name */
  256. const struct mcidev_sysfs_attribute *mcidev_attr; /* group attributes */
  257. };
  258. struct mcidev_sysfs_group_kobj {
  259. struct list_head list; /* list for all instances within a mc */
  260. struct kobject kobj; /* kobj for the group */
  261. const struct mcidev_sysfs_group *grp; /* group description table */
  262. struct mem_ctl_info *mci; /* the parent */
  263. };
  264. /* mcidev_sysfs_attribute structure
  265. * used for driver sysfs attributes and in mem_ctl_info
  266. * sysfs top level entries
  267. */
  268. struct mcidev_sysfs_attribute {
  269. /* It should use either attr or grp */
  270. struct attribute attr;
  271. const struct mcidev_sysfs_group *grp; /* Points to a group of attributes */
  272. /* Ops for show/store values at the attribute - not used on group */
  273. ssize_t (*show)(struct mem_ctl_info *,char *);
  274. ssize_t (*store)(struct mem_ctl_info *, const char *,size_t);
  275. };
  276. /* MEMORY controller information structure
  277. */
  278. struct mem_ctl_info {
  279. struct list_head link; /* for global list of mem_ctl_info structs */
  280. struct module *owner; /* Module owner of this control struct */
  281. unsigned long mtype_cap; /* memory types supported by mc */
  282. unsigned long edac_ctl_cap; /* Mem controller EDAC capabilities */
  283. unsigned long edac_cap; /* configuration capabilities - this is
  284. * closely related to edac_ctl_cap. The
  285. * difference is that the controller may be
  286. * capable of s4ecd4ed which would be listed
  287. * in edac_ctl_cap, but if channels aren't
  288. * capable of s4ecd4ed then the edac_cap would
  289. * not have that capability.
  290. */
  291. unsigned long scrub_cap; /* chipset scrub capabilities */
  292. enum scrub_type scrub_mode; /* current scrub mode */
  293. /* Translates sdram memory scrub rate given in bytes/sec to the
  294. internal representation and configures whatever else needs
  295. to be configured.
  296. */
  297. int (*set_sdram_scrub_rate) (struct mem_ctl_info * mci, u32 bw);
  298. /* Get the current sdram memory scrub rate from the internal
  299. representation and converts it to the closest matching
  300. bandwidth in bytes/sec.
  301. */
  302. int (*get_sdram_scrub_rate) (struct mem_ctl_info * mci);
  303. /* pointer to edac checking routine */
  304. void (*edac_check) (struct mem_ctl_info * mci);
  305. /*
  306. * Remaps memory pages: controller pages to physical pages.
  307. * For most MC's, this will be NULL.
  308. */
  309. /* FIXME - why not send the phys page to begin with? */
  310. unsigned long (*ctl_page_to_phys) (struct mem_ctl_info * mci,
  311. unsigned long page);
  312. int mc_idx;
  313. int nr_csrows;
  314. struct csrow_info *csrows;
  315. /*
  316. * FIXME - what about controllers on other busses? - IDs must be
  317. * unique. dev pointer should be sufficiently unique, but
  318. * BUS:SLOT.FUNC numbers may not be unique.
  319. */
  320. struct device *dev;
  321. const char *mod_name;
  322. const char *mod_ver;
  323. const char *ctl_name;
  324. const char *dev_name;
  325. char proc_name[MC_PROC_NAME_MAX_LEN + 1];
  326. void *pvt_info;
  327. u32 ue_noinfo_count; /* Uncorrectable Errors w/o info */
  328. u32 ce_noinfo_count; /* Correctable Errors w/o info */
  329. u32 ue_count; /* Total Uncorrectable Errors for this MC */
  330. u32 ce_count; /* Total Correctable Errors for this MC */
  331. unsigned long start_time; /* mci load start time (in jiffies) */
  332. struct completion complete;
  333. /* edac sysfs device control */
  334. struct kobject edac_mci_kobj;
  335. /* list for all grp instances within a mc */
  336. struct list_head grp_kobj_list;
  337. /* Additional top controller level attributes, but specified
  338. * by the low level driver.
  339. *
  340. * Set by the low level driver to provide attributes at the
  341. * controller level, same level as 'ue_count' and 'ce_count' above.
  342. * An array of structures, NULL terminated
  343. *
  344. * If attributes are desired, then set to array of attributes
  345. * If no attributes are desired, leave NULL
  346. */
  347. const struct mcidev_sysfs_attribute *mc_driver_sysfs_attributes;
  348. /* work struct for this MC */
  349. struct delayed_work work;
  350. /* the internal state of this controller instance */
  351. int op_state;
  352. };
  353. #endif