edac.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  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/device.h>
  16. #include <linux/kobject.h>
  17. #include <linux/completion.h>
  18. #include <linux/workqueue.h>
  19. #include <linux/debugfs.h>
  20. struct device;
  21. #define EDAC_OPSTATE_INVAL -1
  22. #define EDAC_OPSTATE_POLL 0
  23. #define EDAC_OPSTATE_NMI 1
  24. #define EDAC_OPSTATE_INT 2
  25. extern int edac_op_state;
  26. extern int edac_err_assert;
  27. extern atomic_t edac_handlers;
  28. extern struct bus_type edac_subsys;
  29. extern int edac_handler_set(void);
  30. extern void edac_atomic_assert_error(void);
  31. extern struct bus_type *edac_get_sysfs_subsys(void);
  32. extern void edac_put_sysfs_subsys(void);
  33. static inline void opstate_init(void)
  34. {
  35. switch (edac_op_state) {
  36. case EDAC_OPSTATE_POLL:
  37. case EDAC_OPSTATE_NMI:
  38. break;
  39. default:
  40. edac_op_state = EDAC_OPSTATE_POLL;
  41. }
  42. return;
  43. }
  44. #define EDAC_MC_LABEL_LEN 31
  45. #define MC_PROC_NAME_MAX_LEN 7
  46. /**
  47. * enum dev_type - describe the type of memory DRAM chips used at the stick
  48. * @DEV_UNKNOWN: Can't be determined, or MC doesn't support detect it
  49. * @DEV_X1: 1 bit for data
  50. * @DEV_X2: 2 bits for data
  51. * @DEV_X4: 4 bits for data
  52. * @DEV_X8: 8 bits for data
  53. * @DEV_X16: 16 bits for data
  54. * @DEV_X32: 32 bits for data
  55. * @DEV_X64: 64 bits for data
  56. *
  57. * Typical values are x4 and x8.
  58. */
  59. enum dev_type {
  60. DEV_UNKNOWN = 0,
  61. DEV_X1,
  62. DEV_X2,
  63. DEV_X4,
  64. DEV_X8,
  65. DEV_X16,
  66. DEV_X32, /* Do these parts exist? */
  67. DEV_X64 /* Do these parts exist? */
  68. };
  69. #define DEV_FLAG_UNKNOWN BIT(DEV_UNKNOWN)
  70. #define DEV_FLAG_X1 BIT(DEV_X1)
  71. #define DEV_FLAG_X2 BIT(DEV_X2)
  72. #define DEV_FLAG_X4 BIT(DEV_X4)
  73. #define DEV_FLAG_X8 BIT(DEV_X8)
  74. #define DEV_FLAG_X16 BIT(DEV_X16)
  75. #define DEV_FLAG_X32 BIT(DEV_X32)
  76. #define DEV_FLAG_X64 BIT(DEV_X64)
  77. /**
  78. * enum hw_event_mc_err_type - type of the detected error
  79. *
  80. * @HW_EVENT_ERR_CORRECTED: Corrected Error - Indicates that an ECC
  81. * corrected error was detected
  82. * @HW_EVENT_ERR_UNCORRECTED: Uncorrected Error - Indicates an error that
  83. * can't be corrected by ECC, but it is not
  84. * fatal (maybe it is on an unused memory area,
  85. * or the memory controller could recover from
  86. * it for example, by re-trying the operation).
  87. * @HW_EVENT_ERR_FATAL: Fatal Error - Uncorrected error that could not
  88. * be recovered.
  89. */
  90. enum hw_event_mc_err_type {
  91. HW_EVENT_ERR_CORRECTED,
  92. HW_EVENT_ERR_UNCORRECTED,
  93. HW_EVENT_ERR_FATAL,
  94. };
  95. /**
  96. * enum mem_type - memory types. For a more detailed reference, please see
  97. * http://en.wikipedia.org/wiki/DRAM
  98. *
  99. * @MEM_EMPTY Empty csrow
  100. * @MEM_RESERVED: Reserved csrow type
  101. * @MEM_UNKNOWN: Unknown csrow type
  102. * @MEM_FPM: FPM - Fast Page Mode, used on systems up to 1995.
  103. * @MEM_EDO: EDO - Extended data out, used on systems up to 1998.
  104. * @MEM_BEDO: BEDO - Burst Extended data out, an EDO variant.
  105. * @MEM_SDR: SDR - Single data rate SDRAM
  106. * http://en.wikipedia.org/wiki/Synchronous_dynamic_random-access_memory
  107. * They use 3 pins for chip select: Pins 0 and 2 are
  108. * for rank 0; pins 1 and 3 are for rank 1, if the memory
  109. * is dual-rank.
  110. * @MEM_RDR: Registered SDR SDRAM
  111. * @MEM_DDR: Double data rate SDRAM
  112. * http://en.wikipedia.org/wiki/DDR_SDRAM
  113. * @MEM_RDDR: Registered Double data rate SDRAM
  114. * This is a variant of the DDR memories.
  115. * A registered memory has a buffer inside it, hiding
  116. * part of the memory details to the memory controller.
  117. * @MEM_RMBS: Rambus DRAM, used on a few Pentium III/IV controllers.
  118. * @MEM_DDR2: DDR2 RAM, as described at JEDEC JESD79-2F.
  119. * Those memories are labed as "PC2-" instead of "PC" to
  120. * differenciate from DDR.
  121. * @MEM_FB_DDR2: Fully-Buffered DDR2, as described at JEDEC Std No. 205
  122. * and JESD206.
  123. * Those memories are accessed per DIMM slot, and not by
  124. * a chip select signal.
  125. * @MEM_RDDR2: Registered DDR2 RAM
  126. * This is a variant of the DDR2 memories.
  127. * @MEM_XDR: Rambus XDR
  128. * It is an evolution of the original RAMBUS memories,
  129. * created to compete with DDR2. Weren't used on any
  130. * x86 arch, but cell_edac PPC memory controller uses it.
  131. * @MEM_DDR3: DDR3 RAM
  132. * @MEM_RDDR3: Registered DDR3 RAM
  133. * This is a variant of the DDR3 memories.
  134. */
  135. enum mem_type {
  136. MEM_EMPTY = 0,
  137. MEM_RESERVED,
  138. MEM_UNKNOWN,
  139. MEM_FPM,
  140. MEM_EDO,
  141. MEM_BEDO,
  142. MEM_SDR,
  143. MEM_RDR,
  144. MEM_DDR,
  145. MEM_RDDR,
  146. MEM_RMBS,
  147. MEM_DDR2,
  148. MEM_FB_DDR2,
  149. MEM_RDDR2,
  150. MEM_XDR,
  151. MEM_DDR3,
  152. MEM_RDDR3,
  153. };
  154. #define MEM_FLAG_EMPTY BIT(MEM_EMPTY)
  155. #define MEM_FLAG_RESERVED BIT(MEM_RESERVED)
  156. #define MEM_FLAG_UNKNOWN BIT(MEM_UNKNOWN)
  157. #define MEM_FLAG_FPM BIT(MEM_FPM)
  158. #define MEM_FLAG_EDO BIT(MEM_EDO)
  159. #define MEM_FLAG_BEDO BIT(MEM_BEDO)
  160. #define MEM_FLAG_SDR BIT(MEM_SDR)
  161. #define MEM_FLAG_RDR BIT(MEM_RDR)
  162. #define MEM_FLAG_DDR BIT(MEM_DDR)
  163. #define MEM_FLAG_RDDR BIT(MEM_RDDR)
  164. #define MEM_FLAG_RMBS BIT(MEM_RMBS)
  165. #define MEM_FLAG_DDR2 BIT(MEM_DDR2)
  166. #define MEM_FLAG_FB_DDR2 BIT(MEM_FB_DDR2)
  167. #define MEM_FLAG_RDDR2 BIT(MEM_RDDR2)
  168. #define MEM_FLAG_XDR BIT(MEM_XDR)
  169. #define MEM_FLAG_DDR3 BIT(MEM_DDR3)
  170. #define MEM_FLAG_RDDR3 BIT(MEM_RDDR3)
  171. /**
  172. * enum edac-type - Error Detection and Correction capabilities and mode
  173. * @EDAC_UNKNOWN: Unknown if ECC is available
  174. * @EDAC_NONE: Doesn't support ECC
  175. * @EDAC_RESERVED: Reserved ECC type
  176. * @EDAC_PARITY: Detects parity errors
  177. * @EDAC_EC: Error Checking - no correction
  178. * @EDAC_SECDED: Single bit error correction, Double detection
  179. * @EDAC_S2ECD2ED: Chipkill x2 devices - do these exist?
  180. * @EDAC_S4ECD4ED: Chipkill x4 devices
  181. * @EDAC_S8ECD8ED: Chipkill x8 devices
  182. * @EDAC_S16ECD16ED: Chipkill x16 devices
  183. */
  184. enum edac_type {
  185. EDAC_UNKNOWN = 0,
  186. EDAC_NONE,
  187. EDAC_RESERVED,
  188. EDAC_PARITY,
  189. EDAC_EC,
  190. EDAC_SECDED,
  191. EDAC_S2ECD2ED,
  192. EDAC_S4ECD4ED,
  193. EDAC_S8ECD8ED,
  194. EDAC_S16ECD16ED,
  195. };
  196. #define EDAC_FLAG_UNKNOWN BIT(EDAC_UNKNOWN)
  197. #define EDAC_FLAG_NONE BIT(EDAC_NONE)
  198. #define EDAC_FLAG_PARITY BIT(EDAC_PARITY)
  199. #define EDAC_FLAG_EC BIT(EDAC_EC)
  200. #define EDAC_FLAG_SECDED BIT(EDAC_SECDED)
  201. #define EDAC_FLAG_S2ECD2ED BIT(EDAC_S2ECD2ED)
  202. #define EDAC_FLAG_S4ECD4ED BIT(EDAC_S4ECD4ED)
  203. #define EDAC_FLAG_S8ECD8ED BIT(EDAC_S8ECD8ED)
  204. #define EDAC_FLAG_S16ECD16ED BIT(EDAC_S16ECD16ED)
  205. /**
  206. * enum scrub_type - scrubbing capabilities
  207. * @SCRUB_UNKNOWN Unknown if scrubber is available
  208. * @SCRUB_NONE: No scrubber
  209. * @SCRUB_SW_PROG: SW progressive (sequential) scrubbing
  210. * @SCRUB_SW_SRC: Software scrub only errors
  211. * @SCRUB_SW_PROG_SRC: Progressive software scrub from an error
  212. * @SCRUB_SW_TUNABLE: Software scrub frequency is tunable
  213. * @SCRUB_HW_PROG: HW progressive (sequential) scrubbing
  214. * @SCRUB_HW_SRC: Hardware scrub only errors
  215. * @SCRUB_HW_PROG_SRC: Progressive hardware scrub from an error
  216. * SCRUB_HW_TUNABLE: Hardware scrub frequency is tunable
  217. */
  218. enum scrub_type {
  219. SCRUB_UNKNOWN = 0,
  220. SCRUB_NONE,
  221. SCRUB_SW_PROG,
  222. SCRUB_SW_SRC,
  223. SCRUB_SW_PROG_SRC,
  224. SCRUB_SW_TUNABLE,
  225. SCRUB_HW_PROG,
  226. SCRUB_HW_SRC,
  227. SCRUB_HW_PROG_SRC,
  228. SCRUB_HW_TUNABLE
  229. };
  230. #define SCRUB_FLAG_SW_PROG BIT(SCRUB_SW_PROG)
  231. #define SCRUB_FLAG_SW_SRC BIT(SCRUB_SW_SRC)
  232. #define SCRUB_FLAG_SW_PROG_SRC BIT(SCRUB_SW_PROG_SRC)
  233. #define SCRUB_FLAG_SW_TUN BIT(SCRUB_SW_SCRUB_TUNABLE)
  234. #define SCRUB_FLAG_HW_PROG BIT(SCRUB_HW_PROG)
  235. #define SCRUB_FLAG_HW_SRC BIT(SCRUB_HW_SRC)
  236. #define SCRUB_FLAG_HW_PROG_SRC BIT(SCRUB_HW_PROG_SRC)
  237. #define SCRUB_FLAG_HW_TUN BIT(SCRUB_HW_TUNABLE)
  238. /* FIXME - should have notify capabilities: NMI, LOG, PROC, etc */
  239. /* EDAC internal operation states */
  240. #define OP_ALLOC 0x100
  241. #define OP_RUNNING_POLL 0x201
  242. #define OP_RUNNING_INTERRUPT 0x202
  243. #define OP_RUNNING_POLL_INTR 0x203
  244. #define OP_OFFLINE 0x300
  245. /*
  246. * Concepts used at the EDAC subsystem
  247. *
  248. * There are several things to be aware of that aren't at all obvious:
  249. *
  250. * SOCKETS, SOCKET SETS, BANKS, ROWS, CHIP-SELECT ROWS, CHANNELS, etc..
  251. *
  252. * These are some of the many terms that are thrown about that don't always
  253. * mean what people think they mean (Inconceivable!). In the interest of
  254. * creating a common ground for discussion, terms and their definitions
  255. * will be established.
  256. *
  257. * Memory devices: The individual DRAM chips on a memory stick. These
  258. * devices commonly output 4 and 8 bits each (x4, x8).
  259. * Grouping several of these in parallel provides the
  260. * number of bits that the memory controller expects:
  261. * typically 72 bits, in order to provide 64 bits +
  262. * 8 bits of ECC data.
  263. *
  264. * Memory Stick: A printed circuit board that aggregates multiple
  265. * memory devices in parallel. In general, this is the
  266. * Field Replaceable Unit (FRU) which gets replaced, in
  267. * the case of excessive errors. Most often it is also
  268. * called DIMM (Dual Inline Memory Module).
  269. *
  270. * Memory Socket: A physical connector on the motherboard that accepts
  271. * a single memory stick. Also called as "slot" on several
  272. * datasheets.
  273. *
  274. * Channel: A memory controller channel, responsible to communicate
  275. * with a group of DIMMs. Each channel has its own
  276. * independent control (command) and data bus, and can
  277. * be used independently or grouped with other channels.
  278. *
  279. * Branch: It is typically the highest hierarchy on a
  280. * Fully-Buffered DIMM memory controller.
  281. * Typically, it contains two channels.
  282. * Two channels at the same branch can be used in single
  283. * mode or in lockstep mode.
  284. * When lockstep is enabled, the cacheline is doubled,
  285. * but it generally brings some performance penalty.
  286. * Also, it is generally not possible to point to just one
  287. * memory stick when an error occurs, as the error
  288. * correction code is calculated using two DIMMs instead
  289. * of one. Due to that, it is capable of correcting more
  290. * errors than on single mode.
  291. *
  292. * Single-channel: The data accessed by the memory controller is contained
  293. * into one dimm only. E. g. if the data is 64 bits-wide,
  294. * the data flows to the CPU using one 64 bits parallel
  295. * access.
  296. * Typically used with SDR, DDR, DDR2 and DDR3 memories.
  297. * FB-DIMM and RAMBUS use a different concept for channel,
  298. * so this concept doesn't apply there.
  299. *
  300. * Double-channel: The data size accessed by the memory controller is
  301. * interlaced into two dimms, accessed at the same time.
  302. * E. g. if the DIMM is 64 bits-wide (72 bits with ECC),
  303. * the data flows to the CPU using a 128 bits parallel
  304. * access.
  305. *
  306. * Chip-select row: This is the name of the DRAM signal used to select the
  307. * DRAM ranks to be accessed. Common chip-select rows for
  308. * single channel are 64 bits, for dual channel 128 bits.
  309. * It may not be visible by the memory controller, as some
  310. * DIMM types have a memory buffer that can hide direct
  311. * access to it from the Memory Controller.
  312. *
  313. * Single-Ranked stick: A Single-ranked stick has 1 chip-select row of memory.
  314. * Motherboards commonly drive two chip-select pins to
  315. * a memory stick. A single-ranked stick, will occupy
  316. * only one of those rows. The other will be unused.
  317. *
  318. * Double-Ranked stick: A double-ranked stick has two chip-select rows which
  319. * access different sets of memory devices. The two
  320. * rows cannot be accessed concurrently.
  321. *
  322. * Double-sided stick: DEPRECATED TERM, see Double-Ranked stick.
  323. * A double-sided stick has two chip-select rows which
  324. * access different sets of memory devices. The two
  325. * rows cannot be accessed concurrently. "Double-sided"
  326. * is irrespective of the memory devices being mounted
  327. * on both sides of the memory stick.
  328. *
  329. * Socket set: All of the memory sticks that are required for
  330. * a single memory access or all of the memory sticks
  331. * spanned by a chip-select row. A single socket set
  332. * has two chip-select rows and if double-sided sticks
  333. * are used these will occupy those chip-select rows.
  334. *
  335. * Bank: This term is avoided because it is unclear when
  336. * needing to distinguish between chip-select rows and
  337. * socket sets.
  338. *
  339. * Controller pages:
  340. *
  341. * Physical pages:
  342. *
  343. * Virtual pages:
  344. *
  345. *
  346. * STRUCTURE ORGANIZATION AND CHOICES
  347. *
  348. *
  349. *
  350. * PS - I enjoyed writing all that about as much as you enjoyed reading it.
  351. */
  352. /**
  353. * enum edac_mc_layer - memory controller hierarchy layer
  354. *
  355. * @EDAC_MC_LAYER_BRANCH: memory layer is named "branch"
  356. * @EDAC_MC_LAYER_CHANNEL: memory layer is named "channel"
  357. * @EDAC_MC_LAYER_SLOT: memory layer is named "slot"
  358. * @EDAC_MC_LAYER_CHIP_SELECT: memory layer is named "chip select"
  359. *
  360. * This enum is used by the drivers to tell edac_mc_sysfs what name should
  361. * be used when describing a memory stick location.
  362. */
  363. enum edac_mc_layer_type {
  364. EDAC_MC_LAYER_BRANCH,
  365. EDAC_MC_LAYER_CHANNEL,
  366. EDAC_MC_LAYER_SLOT,
  367. EDAC_MC_LAYER_CHIP_SELECT,
  368. };
  369. /**
  370. * struct edac_mc_layer - describes the memory controller hierarchy
  371. * @layer: layer type
  372. * @size: number of components per layer. For example,
  373. * if the channel layer has two channels, size = 2
  374. * @is_virt_csrow: This layer is part of the "csrow" when old API
  375. * compatibility mode is enabled. Otherwise, it is
  376. * a channel
  377. */
  378. struct edac_mc_layer {
  379. enum edac_mc_layer_type type;
  380. unsigned size;
  381. bool is_virt_csrow;
  382. };
  383. /*
  384. * Maximum number of layers used by the memory controller to uniquely
  385. * identify a single memory stick.
  386. * NOTE: Changing this constant requires not only to change the constant
  387. * below, but also to change the existing code at the core, as there are
  388. * some code there that are optimized for 3 layers.
  389. */
  390. #define EDAC_MAX_LAYERS 3
  391. /**
  392. * EDAC_DIMM_OFF - Macro responsible to get a pointer offset inside a pointer array
  393. * for the element given by [layer0,layer1,layer2] position
  394. *
  395. * @layers: a struct edac_mc_layer array, describing how many elements
  396. * were allocated for each layer
  397. * @n_layers: Number of layers at the @layers array
  398. * @layer0: layer0 position
  399. * @layer1: layer1 position. Unused if n_layers < 2
  400. * @layer2: layer2 position. Unused if n_layers < 3
  401. *
  402. * For 1 layer, this macro returns &var[layer0] - &var
  403. * For 2 layers, this macro is similar to allocate a bi-dimensional array
  404. * and to return "&var[layer0][layer1] - &var"
  405. * For 3 layers, this macro is similar to allocate a tri-dimensional array
  406. * and to return "&var[layer0][layer1][layer2] - &var"
  407. *
  408. * A loop could be used here to make it more generic, but, as we only have
  409. * 3 layers, this is a little faster.
  410. * By design, layers can never be 0 or more than 3. If that ever happens,
  411. * a NULL is returned, causing an OOPS during the memory allocation routine,
  412. * with would point to the developer that he's doing something wrong.
  413. */
  414. #define EDAC_DIMM_OFF(layers, nlayers, layer0, layer1, layer2) ({ \
  415. int __i; \
  416. if ((nlayers) == 1) \
  417. __i = layer0; \
  418. else if ((nlayers) == 2) \
  419. __i = (layer1) + ((layers[1]).size * (layer0)); \
  420. else if ((nlayers) == 3) \
  421. __i = (layer2) + ((layers[2]).size * ((layer1) + \
  422. ((layers[1]).size * (layer0)))); \
  423. else \
  424. __i = -EINVAL; \
  425. __i; \
  426. })
  427. /**
  428. * EDAC_DIMM_PTR - Macro responsible to get a pointer inside a pointer array
  429. * for the element given by [layer0,layer1,layer2] position
  430. *
  431. * @layers: a struct edac_mc_layer array, describing how many elements
  432. * were allocated for each layer
  433. * @var: name of the var where we want to get the pointer
  434. * (like mci->dimms)
  435. * @n_layers: Number of layers at the @layers array
  436. * @layer0: layer0 position
  437. * @layer1: layer1 position. Unused if n_layers < 2
  438. * @layer2: layer2 position. Unused if n_layers < 3
  439. *
  440. * For 1 layer, this macro returns &var[layer0]
  441. * For 2 layers, this macro is similar to allocate a bi-dimensional array
  442. * and to return "&var[layer0][layer1]"
  443. * For 3 layers, this macro is similar to allocate a tri-dimensional array
  444. * and to return "&var[layer0][layer1][layer2]"
  445. */
  446. #define EDAC_DIMM_PTR(layers, var, nlayers, layer0, layer1, layer2) ({ \
  447. typeof(*var) __p; \
  448. int ___i = EDAC_DIMM_OFF(layers, nlayers, layer0, layer1, layer2); \
  449. if (___i < 0) \
  450. __p = NULL; \
  451. else \
  452. __p = (var)[___i]; \
  453. __p; \
  454. })
  455. struct dimm_info {
  456. struct device dev;
  457. char label[EDAC_MC_LABEL_LEN + 1]; /* DIMM label on motherboard */
  458. /* Memory location data */
  459. unsigned location[EDAC_MAX_LAYERS];
  460. struct mem_ctl_info *mci; /* the parent */
  461. u32 grain; /* granularity of reported error in bytes */
  462. enum dev_type dtype; /* memory device type */
  463. enum mem_type mtype; /* memory dimm type */
  464. enum edac_type edac_mode; /* EDAC mode for this dimm */
  465. u32 nr_pages; /* number of pages on this dimm */
  466. unsigned csrow, cschannel; /* Points to the old API data */
  467. };
  468. /**
  469. * struct rank_info - contains the information for one DIMM rank
  470. *
  471. * @chan_idx: channel number where the rank is (typically, 0 or 1)
  472. * @ce_count: number of correctable errors for this rank
  473. * @csrow: A pointer to the chip select row structure (the parent
  474. * structure). The location of the rank is given by
  475. * the (csrow->csrow_idx, chan_idx) vector.
  476. * @dimm: A pointer to the DIMM structure, where the DIMM label
  477. * information is stored.
  478. *
  479. * FIXME: Currently, the EDAC core model will assume one DIMM per rank.
  480. * This is a bad assumption, but it makes this patch easier. Later
  481. * patches in this series will fix this issue.
  482. */
  483. struct rank_info {
  484. int chan_idx;
  485. struct csrow_info *csrow;
  486. struct dimm_info *dimm;
  487. u32 ce_count; /* Correctable Errors for this csrow */
  488. };
  489. struct csrow_info {
  490. struct device dev;
  491. /* Used only by edac_mc_find_csrow_by_page() */
  492. unsigned long first_page; /* first page number in csrow */
  493. unsigned long last_page; /* last page number in csrow */
  494. unsigned long page_mask; /* used for interleaving -
  495. * 0UL for non intlv */
  496. int csrow_idx; /* the chip-select row */
  497. u32 ue_count; /* Uncorrectable Errors for this csrow */
  498. u32 ce_count; /* Correctable Errors for this csrow */
  499. u32 nr_pages; /* combined pages count of all channels */
  500. struct mem_ctl_info *mci; /* the parent */
  501. /* channel information for this csrow */
  502. u32 nr_channels;
  503. struct rank_info **channels;
  504. };
  505. /*
  506. * struct errcount_attribute - used to store the several error counts
  507. */
  508. struct errcount_attribute_data {
  509. int n_layers;
  510. int pos[EDAC_MAX_LAYERS];
  511. int layer0, layer1, layer2;
  512. };
  513. /* MEMORY controller information structure
  514. */
  515. struct mem_ctl_info {
  516. struct device dev;
  517. struct bus_type bus;
  518. struct list_head link; /* for global list of mem_ctl_info structs */
  519. struct module *owner; /* Module owner of this control struct */
  520. unsigned long mtype_cap; /* memory types supported by mc */
  521. unsigned long edac_ctl_cap; /* Mem controller EDAC capabilities */
  522. unsigned long edac_cap; /* configuration capabilities - this is
  523. * closely related to edac_ctl_cap. The
  524. * difference is that the controller may be
  525. * capable of s4ecd4ed which would be listed
  526. * in edac_ctl_cap, but if channels aren't
  527. * capable of s4ecd4ed then the edac_cap would
  528. * not have that capability.
  529. */
  530. unsigned long scrub_cap; /* chipset scrub capabilities */
  531. enum scrub_type scrub_mode; /* current scrub mode */
  532. /* Translates sdram memory scrub rate given in bytes/sec to the
  533. internal representation and configures whatever else needs
  534. to be configured.
  535. */
  536. int (*set_sdram_scrub_rate) (struct mem_ctl_info * mci, u32 bw);
  537. /* Get the current sdram memory scrub rate from the internal
  538. representation and converts it to the closest matching
  539. bandwidth in bytes/sec.
  540. */
  541. int (*get_sdram_scrub_rate) (struct mem_ctl_info * mci);
  542. /* pointer to edac checking routine */
  543. void (*edac_check) (struct mem_ctl_info * mci);
  544. /*
  545. * Remaps memory pages: controller pages to physical pages.
  546. * For most MC's, this will be NULL.
  547. */
  548. /* FIXME - why not send the phys page to begin with? */
  549. unsigned long (*ctl_page_to_phys) (struct mem_ctl_info * mci,
  550. unsigned long page);
  551. int mc_idx;
  552. struct csrow_info **csrows;
  553. unsigned nr_csrows, num_cschannel;
  554. /*
  555. * Memory Controller hierarchy
  556. *
  557. * There are basically two types of memory controller: the ones that
  558. * sees memory sticks ("dimms"), and the ones that sees memory ranks.
  559. * All old memory controllers enumerate memories per rank, but most
  560. * of the recent drivers enumerate memories per DIMM, instead.
  561. * When the memory controller is per rank, mem_is_per_rank is true.
  562. */
  563. unsigned n_layers;
  564. struct edac_mc_layer *layers;
  565. bool mem_is_per_rank;
  566. /*
  567. * DIMM info. Will eventually remove the entire csrows_info some day
  568. */
  569. unsigned tot_dimms;
  570. struct dimm_info **dimms;
  571. /*
  572. * FIXME - what about controllers on other busses? - IDs must be
  573. * unique. dev pointer should be sufficiently unique, but
  574. * BUS:SLOT.FUNC numbers may not be unique.
  575. */
  576. struct device *pdev;
  577. const char *mod_name;
  578. const char *mod_ver;
  579. const char *ctl_name;
  580. const char *dev_name;
  581. char proc_name[MC_PROC_NAME_MAX_LEN + 1];
  582. void *pvt_info;
  583. unsigned long start_time; /* mci load start time (in jiffies) */
  584. /*
  585. * drivers shouldn't access those fields directly, as the core
  586. * already handles that.
  587. */
  588. u32 ce_noinfo_count, ue_noinfo_count;
  589. u32 ue_mc, ce_mc;
  590. u32 *ce_per_layer[EDAC_MAX_LAYERS], *ue_per_layer[EDAC_MAX_LAYERS];
  591. struct completion complete;
  592. /* Additional top controller level attributes, but specified
  593. * by the low level driver.
  594. *
  595. * Set by the low level driver to provide attributes at the
  596. * controller level.
  597. * An array of structures, NULL terminated
  598. *
  599. * If attributes are desired, then set to array of attributes
  600. * If no attributes are desired, leave NULL
  601. */
  602. const struct mcidev_sysfs_attribute *mc_driver_sysfs_attributes;
  603. /* work struct for this MC */
  604. struct delayed_work work;
  605. /* the internal state of this controller instance */
  606. int op_state;
  607. #ifdef CONFIG_EDAC_DEBUG
  608. struct dentry *debugfs;
  609. u8 fake_inject_layer[EDAC_MAX_LAYERS];
  610. u32 fake_inject_ue;
  611. u16 fake_inject_count;
  612. #endif
  613. __u8 csbased : 1, /* csrow-based memory controller */
  614. __resv : 7;
  615. };
  616. #endif