edac.h 24 KB

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