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