edac.h 24 KB

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