edac.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. /*
  2. * Generic EDAC defs
  3. *
  4. * Author: Dave Jiang <[email protected]>
  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. #include <linux/numa.h>
  20. #define EDAC_DEVICE_NAME_LEN 31
  21. struct device;
  22. #define EDAC_OPSTATE_INVAL -1
  23. #define EDAC_OPSTATE_POLL 0
  24. #define EDAC_OPSTATE_NMI 1
  25. #define EDAC_OPSTATE_INT 2
  26. extern int edac_op_state;
  27. struct bus_type *edac_get_sysfs_subsys(void);
  28. static inline void opstate_init(void)
  29. {
  30. switch (edac_op_state) {
  31. case EDAC_OPSTATE_POLL:
  32. case EDAC_OPSTATE_NMI:
  33. break;
  34. default:
  35. edac_op_state = EDAC_OPSTATE_POLL;
  36. }
  37. return;
  38. }
  39. /* Max length of a DIMM label*/
  40. #define EDAC_MC_LABEL_LEN 31
  41. /* Maximum size of the location string */
  42. #define LOCATION_SIZE 256
  43. /* Defines the maximum number of labels that can be reported */
  44. #define EDAC_MAX_LABELS 8
  45. /* String used to join two or more labels */
  46. #define OTHER_LABEL " or "
  47. /**
  48. * enum dev_type - describe the type of memory DRAM chips used at the stick
  49. * @DEV_UNKNOWN: Can't be determined, or MC doesn't support detect it
  50. * @DEV_X1: 1 bit for data
  51. * @DEV_X2: 2 bits for data
  52. * @DEV_X4: 4 bits for data
  53. * @DEV_X8: 8 bits for data
  54. * @DEV_X16: 16 bits for data
  55. * @DEV_X32: 32 bits for data
  56. * @DEV_X64: 64 bits for data
  57. *
  58. * Typical values are x4 and x8.
  59. */
  60. enum dev_type {
  61. DEV_UNKNOWN = 0,
  62. DEV_X1,
  63. DEV_X2,
  64. DEV_X4,
  65. DEV_X8,
  66. DEV_X16,
  67. DEV_X32, /* Do these parts exist? */
  68. DEV_X64 /* Do these parts exist? */
  69. };
  70. #define DEV_FLAG_UNKNOWN BIT(DEV_UNKNOWN)
  71. #define DEV_FLAG_X1 BIT(DEV_X1)
  72. #define DEV_FLAG_X2 BIT(DEV_X2)
  73. #define DEV_FLAG_X4 BIT(DEV_X4)
  74. #define DEV_FLAG_X8 BIT(DEV_X8)
  75. #define DEV_FLAG_X16 BIT(DEV_X16)
  76. #define DEV_FLAG_X32 BIT(DEV_X32)
  77. #define DEV_FLAG_X64 BIT(DEV_X64)
  78. /**
  79. * enum hw_event_mc_err_type - type of the detected error
  80. *
  81. * @HW_EVENT_ERR_CORRECTED: Corrected Error - Indicates that an ECC
  82. * corrected error was detected
  83. * @HW_EVENT_ERR_UNCORRECTED: Uncorrected Error - Indicates an error that
  84. * can't be corrected by ECC, but it is not
  85. * fatal (maybe it is on an unused memory area,
  86. * or the memory controller could recover from
  87. * it for example, by re-trying the operation).
  88. * @HW_EVENT_ERR_DEFERRED: Deferred Error - Indicates an uncorrectable
  89. * error whose handling is not urgent. This could
  90. * be due to hardware data poisoning where the
  91. * system can continue operation until the poisoned
  92. * data is consumed. Preemptive measures may also
  93. * be taken, e.g. offlining pages, etc.
  94. * @HW_EVENT_ERR_FATAL: Fatal Error - Uncorrected error that could not
  95. * be recovered.
  96. * @HW_EVENT_ERR_INFO: Informational - The CPER spec defines a forth
  97. * type of error: informational logs.
  98. */
  99. enum hw_event_mc_err_type {
  100. HW_EVENT_ERR_CORRECTED,
  101. HW_EVENT_ERR_UNCORRECTED,
  102. HW_EVENT_ERR_DEFERRED,
  103. HW_EVENT_ERR_FATAL,
  104. HW_EVENT_ERR_INFO,
  105. };
  106. static inline char *mc_event_error_type(const unsigned int err_type)
  107. {
  108. switch (err_type) {
  109. case HW_EVENT_ERR_CORRECTED:
  110. return "Corrected";
  111. case HW_EVENT_ERR_UNCORRECTED:
  112. return "Uncorrected";
  113. case HW_EVENT_ERR_DEFERRED:
  114. return "Deferred";
  115. case HW_EVENT_ERR_FATAL:
  116. return "Fatal";
  117. default:
  118. case HW_EVENT_ERR_INFO:
  119. return "Info";
  120. }
  121. }
  122. /**
  123. * enum mem_type - memory types. For a more detailed reference, please see
  124. * http://en.wikipedia.org/wiki/DRAM
  125. *
  126. * @MEM_EMPTY: Empty csrow
  127. * @MEM_RESERVED: Reserved csrow type
  128. * @MEM_UNKNOWN: Unknown csrow type
  129. * @MEM_FPM: FPM - Fast Page Mode, used on systems up to 1995.
  130. * @MEM_EDO: EDO - Extended data out, used on systems up to 1998.
  131. * @MEM_BEDO: BEDO - Burst Extended data out, an EDO variant.
  132. * @MEM_SDR: SDR - Single data rate SDRAM
  133. * http://en.wikipedia.org/wiki/Synchronous_dynamic_random-access_memory
  134. * They use 3 pins for chip select: Pins 0 and 2 are
  135. * for rank 0; pins 1 and 3 are for rank 1, if the memory
  136. * is dual-rank.
  137. * @MEM_RDR: Registered SDR SDRAM
  138. * @MEM_DDR: Double data rate SDRAM
  139. * http://en.wikipedia.org/wiki/DDR_SDRAM
  140. * @MEM_RDDR: Registered Double data rate SDRAM
  141. * This is a variant of the DDR memories.
  142. * A registered memory has a buffer inside it, hiding
  143. * part of the memory details to the memory controller.
  144. * @MEM_RMBS: Rambus DRAM, used on a few Pentium III/IV controllers.
  145. * @MEM_DDR2: DDR2 RAM, as described at JEDEC JESD79-2F.
  146. * Those memories are labeled as "PC2-" instead of "PC" to
  147. * differentiate from DDR.
  148. * @MEM_FB_DDR2: Fully-Buffered DDR2, as described at JEDEC Std No. 205
  149. * and JESD206.
  150. * Those memories are accessed per DIMM slot, and not by
  151. * a chip select signal.
  152. * @MEM_RDDR2: Registered DDR2 RAM
  153. * This is a variant of the DDR2 memories.
  154. * @MEM_XDR: Rambus XDR
  155. * It is an evolution of the original RAMBUS memories,
  156. * created to compete with DDR2. Weren't used on any
  157. * x86 arch, but cell_edac PPC memory controller uses it.
  158. * @MEM_DDR3: DDR3 RAM
  159. * @MEM_RDDR3: Registered DDR3 RAM
  160. * This is a variant of the DDR3 memories.
  161. * @MEM_LRDDR3: Load-Reduced DDR3 memory.
  162. * @MEM_LPDDR3: Low-Power DDR3 memory.
  163. * @MEM_DDR4: Unbuffered DDR4 RAM
  164. * @MEM_RDDR4: Registered DDR4 RAM
  165. * This is a variant of the DDR4 memories.
  166. * @MEM_LRDDR4: Load-Reduced DDR4 memory.
  167. * @MEM_LPDDR4: Low-Power DDR4 memory.
  168. * @MEM_DDR5: Unbuffered DDR5 RAM
  169. * @MEM_RDDR5: Registered DDR5 RAM
  170. * @MEM_LRDDR5: Load-Reduced DDR5 memory.
  171. * @MEM_NVDIMM: Non-volatile RAM
  172. * @MEM_WIO2: Wide I/O 2.
  173. * @MEM_HBM2: High bandwidth Memory Gen 2.
  174. */
  175. enum mem_type {
  176. MEM_EMPTY = 0,
  177. MEM_RESERVED,
  178. MEM_UNKNOWN,
  179. MEM_FPM,
  180. MEM_EDO,
  181. MEM_BEDO,
  182. MEM_SDR,
  183. MEM_RDR,
  184. MEM_DDR,
  185. MEM_RDDR,
  186. MEM_RMBS,
  187. MEM_DDR2,
  188. MEM_FB_DDR2,
  189. MEM_RDDR2,
  190. MEM_XDR,
  191. MEM_DDR3,
  192. MEM_RDDR3,
  193. MEM_LRDDR3,
  194. MEM_LPDDR3,
  195. MEM_DDR4,
  196. MEM_RDDR4,
  197. MEM_LRDDR4,
  198. MEM_LPDDR4,
  199. MEM_DDR5,
  200. MEM_RDDR5,
  201. MEM_LRDDR5,
  202. MEM_NVDIMM,
  203. MEM_WIO2,
  204. MEM_HBM2,
  205. };
  206. #define MEM_FLAG_EMPTY BIT(MEM_EMPTY)
  207. #define MEM_FLAG_RESERVED BIT(MEM_RESERVED)
  208. #define MEM_FLAG_UNKNOWN BIT(MEM_UNKNOWN)
  209. #define MEM_FLAG_FPM BIT(MEM_FPM)
  210. #define MEM_FLAG_EDO BIT(MEM_EDO)
  211. #define MEM_FLAG_BEDO BIT(MEM_BEDO)
  212. #define MEM_FLAG_SDR BIT(MEM_SDR)
  213. #define MEM_FLAG_RDR BIT(MEM_RDR)
  214. #define MEM_FLAG_DDR BIT(MEM_DDR)
  215. #define MEM_FLAG_RDDR BIT(MEM_RDDR)
  216. #define MEM_FLAG_RMBS BIT(MEM_RMBS)
  217. #define MEM_FLAG_DDR2 BIT(MEM_DDR2)
  218. #define MEM_FLAG_FB_DDR2 BIT(MEM_FB_DDR2)
  219. #define MEM_FLAG_RDDR2 BIT(MEM_RDDR2)
  220. #define MEM_FLAG_XDR BIT(MEM_XDR)
  221. #define MEM_FLAG_DDR3 BIT(MEM_DDR3)
  222. #define MEM_FLAG_RDDR3 BIT(MEM_RDDR3)
  223. #define MEM_FLAG_LPDDR3 BIT(MEM_LPDDR3)
  224. #define MEM_FLAG_DDR4 BIT(MEM_DDR4)
  225. #define MEM_FLAG_RDDR4 BIT(MEM_RDDR4)
  226. #define MEM_FLAG_LRDDR4 BIT(MEM_LRDDR4)
  227. #define MEM_FLAG_LPDDR4 BIT(MEM_LPDDR4)
  228. #define MEM_FLAG_DDR5 BIT(MEM_DDR5)
  229. #define MEM_FLAG_RDDR5 BIT(MEM_RDDR5)
  230. #define MEM_FLAG_LRDDR5 BIT(MEM_LRDDR5)
  231. #define MEM_FLAG_NVDIMM BIT(MEM_NVDIMM)
  232. #define MEM_FLAG_WIO2 BIT(MEM_WIO2)
  233. #define MEM_FLAG_HBM2 BIT(MEM_HBM2)
  234. /**
  235. * enum edac_type - Error Detection and Correction capabilities and mode
  236. * @EDAC_UNKNOWN: Unknown if ECC is available
  237. * @EDAC_NONE: Doesn't support ECC
  238. * @EDAC_RESERVED: Reserved ECC type
  239. * @EDAC_PARITY: Detects parity errors
  240. * @EDAC_EC: Error Checking - no correction
  241. * @EDAC_SECDED: Single bit error correction, Double detection
  242. * @EDAC_S2ECD2ED: Chipkill x2 devices - do these exist?
  243. * @EDAC_S4ECD4ED: Chipkill x4 devices
  244. * @EDAC_S8ECD8ED: Chipkill x8 devices
  245. * @EDAC_S16ECD16ED: Chipkill x16 devices
  246. */
  247. enum edac_type {
  248. EDAC_UNKNOWN = 0,
  249. EDAC_NONE,
  250. EDAC_RESERVED,
  251. EDAC_PARITY,
  252. EDAC_EC,
  253. EDAC_SECDED,
  254. EDAC_S2ECD2ED,
  255. EDAC_S4ECD4ED,
  256. EDAC_S8ECD8ED,
  257. EDAC_S16ECD16ED,
  258. };
  259. #define EDAC_FLAG_UNKNOWN BIT(EDAC_UNKNOWN)
  260. #define EDAC_FLAG_NONE BIT(EDAC_NONE)
  261. #define EDAC_FLAG_PARITY BIT(EDAC_PARITY)
  262. #define EDAC_FLAG_EC BIT(EDAC_EC)
  263. #define EDAC_FLAG_SECDED BIT(EDAC_SECDED)
  264. #define EDAC_FLAG_S2ECD2ED BIT(EDAC_S2ECD2ED)
  265. #define EDAC_FLAG_S4ECD4ED BIT(EDAC_S4ECD4ED)
  266. #define EDAC_FLAG_S8ECD8ED BIT(EDAC_S8ECD8ED)
  267. #define EDAC_FLAG_S16ECD16ED BIT(EDAC_S16ECD16ED)
  268. /**
  269. * enum scrub_type - scrubbing capabilities
  270. * @SCRUB_UNKNOWN: Unknown if scrubber is available
  271. * @SCRUB_NONE: No scrubber
  272. * @SCRUB_SW_PROG: SW progressive (sequential) scrubbing
  273. * @SCRUB_SW_SRC: Software scrub only errors
  274. * @SCRUB_SW_PROG_SRC: Progressive software scrub from an error
  275. * @SCRUB_SW_TUNABLE: Software scrub frequency is tunable
  276. * @SCRUB_HW_PROG: HW progressive (sequential) scrubbing
  277. * @SCRUB_HW_SRC: Hardware scrub only errors
  278. * @SCRUB_HW_PROG_SRC: Progressive hardware scrub from an error
  279. * @SCRUB_HW_TUNABLE: Hardware scrub frequency is tunable
  280. */
  281. enum scrub_type {
  282. SCRUB_UNKNOWN = 0,
  283. SCRUB_NONE,
  284. SCRUB_SW_PROG,
  285. SCRUB_SW_SRC,
  286. SCRUB_SW_PROG_SRC,
  287. SCRUB_SW_TUNABLE,
  288. SCRUB_HW_PROG,
  289. SCRUB_HW_SRC,
  290. SCRUB_HW_PROG_SRC,
  291. SCRUB_HW_TUNABLE
  292. };
  293. #define SCRUB_FLAG_SW_PROG BIT(SCRUB_SW_PROG)
  294. #define SCRUB_FLAG_SW_SRC BIT(SCRUB_SW_SRC)
  295. #define SCRUB_FLAG_SW_PROG_SRC BIT(SCRUB_SW_PROG_SRC)
  296. #define SCRUB_FLAG_SW_TUN BIT(SCRUB_SW_SCRUB_TUNABLE)
  297. #define SCRUB_FLAG_HW_PROG BIT(SCRUB_HW_PROG)
  298. #define SCRUB_FLAG_HW_SRC BIT(SCRUB_HW_SRC)
  299. #define SCRUB_FLAG_HW_PROG_SRC BIT(SCRUB_HW_PROG_SRC)
  300. #define SCRUB_FLAG_HW_TUN BIT(SCRUB_HW_TUNABLE)
  301. /* FIXME - should have notify capabilities: NMI, LOG, PROC, etc */
  302. /* EDAC internal operation states */
  303. #define OP_ALLOC 0x100
  304. #define OP_RUNNING_POLL 0x201
  305. #define OP_RUNNING_INTERRUPT 0x202
  306. #define OP_RUNNING_POLL_INTR 0x203
  307. #define OP_OFFLINE 0x300
  308. /**
  309. * enum edac_mc_layer_type - memory controller hierarchy layer
  310. *
  311. * @EDAC_MC_LAYER_BRANCH: memory layer is named "branch"
  312. * @EDAC_MC_LAYER_CHANNEL: memory layer is named "channel"
  313. * @EDAC_MC_LAYER_SLOT: memory layer is named "slot"
  314. * @EDAC_MC_LAYER_CHIP_SELECT: memory layer is named "chip select"
  315. * @EDAC_MC_LAYER_ALL_MEM: memory layout is unknown. All memory is mapped
  316. * as a single memory area. This is used when
  317. * retrieving errors from a firmware driven driver.
  318. *
  319. * This enum is used by the drivers to tell edac_mc_sysfs what name should
  320. * be used when describing a memory stick location.
  321. */
  322. enum edac_mc_layer_type {
  323. EDAC_MC_LAYER_BRANCH,
  324. EDAC_MC_LAYER_CHANNEL,
  325. EDAC_MC_LAYER_SLOT,
  326. EDAC_MC_LAYER_CHIP_SELECT,
  327. EDAC_MC_LAYER_ALL_MEM,
  328. };
  329. /**
  330. * struct edac_mc_layer - describes the memory controller hierarchy
  331. * @type: layer type
  332. * @size: number of components per layer. For example,
  333. * if the channel layer has two channels, size = 2
  334. * @is_virt_csrow: This layer is part of the "csrow" when old API
  335. * compatibility mode is enabled. Otherwise, it is
  336. * a channel
  337. */
  338. struct edac_mc_layer {
  339. enum edac_mc_layer_type type;
  340. unsigned size;
  341. bool is_virt_csrow;
  342. };
  343. /*
  344. * Maximum number of layers used by the memory controller to uniquely
  345. * identify a single memory stick.
  346. * NOTE: Changing this constant requires not only to change the constant
  347. * below, but also to change the existing code at the core, as there are
  348. * some code there that are optimized for 3 layers.
  349. */
  350. #define EDAC_MAX_LAYERS 3
  351. struct dimm_info {
  352. struct device dev;
  353. char label[EDAC_MC_LABEL_LEN + 1]; /* DIMM label on motherboard */
  354. /* Memory location data */
  355. unsigned int location[EDAC_MAX_LAYERS];
  356. struct mem_ctl_info *mci; /* the parent */
  357. unsigned int idx; /* index within the parent dimm array */
  358. u32 grain; /* granularity of reported error in bytes */
  359. enum dev_type dtype; /* memory device type */
  360. enum mem_type mtype; /* memory dimm type */
  361. enum edac_type edac_mode; /* EDAC mode for this dimm */
  362. u32 nr_pages; /* number of pages on this dimm */
  363. unsigned int csrow, cschannel; /* Points to the old API data */
  364. u16 smbios_handle; /* Handle for SMBIOS type 17 */
  365. u32 ce_count;
  366. u32 ue_count;
  367. };
  368. /**
  369. * struct rank_info - contains the information for one DIMM rank
  370. *
  371. * @chan_idx: channel number where the rank is (typically, 0 or 1)
  372. * @ce_count: number of correctable errors for this rank
  373. * @csrow: A pointer to the chip select row structure (the parent
  374. * structure). The location of the rank is given by
  375. * the (csrow->csrow_idx, chan_idx) vector.
  376. * @dimm: A pointer to the DIMM structure, where the DIMM label
  377. * information is stored.
  378. *
  379. * FIXME: Currently, the EDAC core model will assume one DIMM per rank.
  380. * This is a bad assumption, but it makes this patch easier. Later
  381. * patches in this series will fix this issue.
  382. */
  383. struct rank_info {
  384. int chan_idx;
  385. struct csrow_info *csrow;
  386. struct dimm_info *dimm;
  387. u32 ce_count; /* Correctable Errors for this csrow */
  388. };
  389. struct csrow_info {
  390. struct device dev;
  391. /* Used only by edac_mc_find_csrow_by_page() */
  392. unsigned long first_page; /* first page number in csrow */
  393. unsigned long last_page; /* last page number in csrow */
  394. unsigned long page_mask; /* used for interleaving -
  395. * 0UL for non intlv */
  396. int csrow_idx; /* the chip-select row */
  397. u32 ue_count; /* Uncorrectable Errors for this csrow */
  398. u32 ce_count; /* Correctable Errors for this csrow */
  399. struct mem_ctl_info *mci; /* the parent */
  400. /* channel information for this csrow */
  401. u32 nr_channels;
  402. struct rank_info **channels;
  403. };
  404. /*
  405. * struct errcount_attribute - used to store the several error counts
  406. */
  407. struct errcount_attribute_data {
  408. int n_layers;
  409. int pos[EDAC_MAX_LAYERS];
  410. int layer0, layer1, layer2;
  411. };
  412. /**
  413. * struct edac_raw_error_desc - Raw error report structure
  414. * @grain: minimum granularity for an error report, in bytes
  415. * @error_count: number of errors of the same type
  416. * @type: severity of the error (CE/UE/Fatal)
  417. * @top_layer: top layer of the error (layer[0])
  418. * @mid_layer: middle layer of the error (layer[1])
  419. * @low_layer: low layer of the error (layer[2])
  420. * @page_frame_number: page where the error happened
  421. * @offset_in_page: page offset
  422. * @syndrome: syndrome of the error (or 0 if unknown or if
  423. * the syndrome is not applicable)
  424. * @msg: error message
  425. * @location: location of the error
  426. * @label: label of the affected DIMM(s)
  427. * @other_detail: other driver-specific detail about the error
  428. */
  429. struct edac_raw_error_desc {
  430. char location[LOCATION_SIZE];
  431. char label[(EDAC_MC_LABEL_LEN + 1 + sizeof(OTHER_LABEL)) * EDAC_MAX_LABELS];
  432. long grain;
  433. u16 error_count;
  434. enum hw_event_mc_err_type type;
  435. int top_layer;
  436. int mid_layer;
  437. int low_layer;
  438. unsigned long page_frame_number;
  439. unsigned long offset_in_page;
  440. unsigned long syndrome;
  441. const char *msg;
  442. const char *other_detail;
  443. };
  444. /* MEMORY controller information structure
  445. */
  446. struct mem_ctl_info {
  447. struct device dev;
  448. struct bus_type *bus;
  449. struct list_head link; /* for global list of mem_ctl_info structs */
  450. struct module *owner; /* Module owner of this control struct */
  451. unsigned long mtype_cap; /* memory types supported by mc */
  452. unsigned long edac_ctl_cap; /* Mem controller EDAC capabilities */
  453. unsigned long edac_cap; /* configuration capabilities - this is
  454. * closely related to edac_ctl_cap. The
  455. * difference is that the controller may be
  456. * capable of s4ecd4ed which would be listed
  457. * in edac_ctl_cap, but if channels aren't
  458. * capable of s4ecd4ed then the edac_cap would
  459. * not have that capability.
  460. */
  461. unsigned long scrub_cap; /* chipset scrub capabilities */
  462. enum scrub_type scrub_mode; /* current scrub mode */
  463. /* Translates sdram memory scrub rate given in bytes/sec to the
  464. internal representation and configures whatever else needs
  465. to be configured.
  466. */
  467. int (*set_sdram_scrub_rate) (struct mem_ctl_info * mci, u32 bw);
  468. /* Get the current sdram memory scrub rate from the internal
  469. representation and converts it to the closest matching
  470. bandwidth in bytes/sec.
  471. */
  472. int (*get_sdram_scrub_rate) (struct mem_ctl_info * mci);
  473. /* pointer to edac checking routine */
  474. void (*edac_check) (struct mem_ctl_info * mci);
  475. /*
  476. * Remaps memory pages: controller pages to physical pages.
  477. * For most MC's, this will be NULL.
  478. */
  479. /* FIXME - why not send the phys page to begin with? */
  480. unsigned long (*ctl_page_to_phys) (struct mem_ctl_info * mci,
  481. unsigned long page);
  482. int mc_idx;
  483. struct csrow_info **csrows;
  484. unsigned int nr_csrows, num_cschannel;
  485. /*
  486. * Memory Controller hierarchy
  487. *
  488. * There are basically two types of memory controller: the ones that
  489. * sees memory sticks ("dimms"), and the ones that sees memory ranks.
  490. * All old memory controllers enumerate memories per rank, but most
  491. * of the recent drivers enumerate memories per DIMM, instead.
  492. * When the memory controller is per rank, csbased is true.
  493. */
  494. unsigned int n_layers;
  495. struct edac_mc_layer *layers;
  496. bool csbased;
  497. /*
  498. * DIMM info. Will eventually remove the entire csrows_info some day
  499. */
  500. unsigned int tot_dimms;
  501. struct dimm_info **dimms;
  502. /*
  503. * FIXME - what about controllers on other busses? - IDs must be
  504. * unique. dev pointer should be sufficiently unique, but
  505. * BUS:SLOT.FUNC numbers may not be unique.
  506. */
  507. struct device *pdev;
  508. const char *mod_name;
  509. const char *ctl_name;
  510. const char *dev_name;
  511. void *pvt_info;
  512. unsigned long start_time; /* mci load start time (in jiffies) */
  513. /*
  514. * drivers shouldn't access those fields directly, as the core
  515. * already handles that.
  516. */
  517. u32 ce_noinfo_count, ue_noinfo_count;
  518. u32 ue_mc, ce_mc;
  519. struct completion complete;
  520. /* Additional top controller level attributes, but specified
  521. * by the low level driver.
  522. *
  523. * Set by the low level driver to provide attributes at the
  524. * controller level.
  525. * An array of structures, NULL terminated
  526. *
  527. * If attributes are desired, then set to array of attributes
  528. * If no attributes are desired, leave NULL
  529. */
  530. const struct mcidev_sysfs_attribute *mc_driver_sysfs_attributes;
  531. /* work struct for this MC */
  532. struct delayed_work work;
  533. /*
  534. * Used to report an error - by being at the global struct
  535. * makes the memory allocated by the EDAC core
  536. */
  537. struct edac_raw_error_desc error_desc;
  538. /* the internal state of this controller instance */
  539. int op_state;
  540. struct dentry *debugfs;
  541. u8 fake_inject_layer[EDAC_MAX_LAYERS];
  542. bool fake_inject_ue;
  543. u16 fake_inject_count;
  544. };
  545. #define mci_for_each_dimm(mci, dimm) \
  546. for ((dimm) = (mci)->dimms[0]; \
  547. (dimm); \
  548. (dimm) = (dimm)->idx + 1 < (mci)->tot_dimms \
  549. ? (mci)->dimms[(dimm)->idx + 1] \
  550. : NULL)
  551. /**
  552. * edac_get_dimm - Get DIMM info from a memory controller given by
  553. * [layer0,layer1,layer2] position
  554. *
  555. * @mci: MC descriptor struct mem_ctl_info
  556. * @layer0: layer0 position
  557. * @layer1: layer1 position. Unused if n_layers < 2
  558. * @layer2: layer2 position. Unused if n_layers < 3
  559. *
  560. * For 1 layer, this function returns "dimms[layer0]";
  561. *
  562. * For 2 layers, this function is similar to allocating a two-dimensional
  563. * array and returning "dimms[layer0][layer1]";
  564. *
  565. * For 3 layers, this function is similar to allocating a tri-dimensional
  566. * array and returning "dimms[layer0][layer1][layer2]";
  567. */
  568. static inline struct dimm_info *edac_get_dimm(struct mem_ctl_info *mci,
  569. int layer0, int layer1, int layer2)
  570. {
  571. int index;
  572. if (layer0 < 0
  573. || (mci->n_layers > 1 && layer1 < 0)
  574. || (mci->n_layers > 2 && layer2 < 0))
  575. return NULL;
  576. index = layer0;
  577. if (mci->n_layers > 1)
  578. index = index * mci->layers[1].size + layer1;
  579. if (mci->n_layers > 2)
  580. index = index * mci->layers[2].size + layer2;
  581. if (index < 0 || index >= mci->tot_dimms)
  582. return NULL;
  583. if (WARN_ON_ONCE(mci->dimms[index]->idx != index))
  584. return NULL;
  585. return mci->dimms[index];
  586. }
  587. #endif /* _LINUX_EDAC_H_ */