edac_mc.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. /*
  2. * edac_mc kernel module
  3. * (C) 2005, 2006 Linux Networx (http://lnxi.com)
  4. * This file may be distributed under the terms of the
  5. * GNU General Public License.
  6. *
  7. * Written by Thayne Harbaugh
  8. * Based on work by Dan Hollis <goemon at anime dot net> and others.
  9. * http://www.anime.net/~goemon/linux-ecc/
  10. *
  11. * Modified by Dave Peterson and Doug Thompson
  12. *
  13. */
  14. #include <linux/module.h>
  15. #include <linux/proc_fs.h>
  16. #include <linux/kernel.h>
  17. #include <linux/types.h>
  18. #include <linux/smp.h>
  19. #include <linux/init.h>
  20. #include <linux/sysctl.h>
  21. #include <linux/highmem.h>
  22. #include <linux/timer.h>
  23. #include <linux/slab.h>
  24. #include <linux/jiffies.h>
  25. #include <linux/spinlock.h>
  26. #include <linux/list.h>
  27. #include <linux/sysdev.h>
  28. #include <linux/ctype.h>
  29. #include <linux/edac.h>
  30. #include <asm/uaccess.h>
  31. #include <asm/page.h>
  32. #include <asm/edac.h>
  33. #include "edac_core.h"
  34. #include "edac_module.h"
  35. /* lock to memory controller's control array */
  36. static DEFINE_MUTEX(mem_ctls_mutex);
  37. static struct list_head mc_devices = LIST_HEAD_INIT(mc_devices);
  38. #ifdef CONFIG_EDAC_DEBUG
  39. static void edac_mc_dump_channel(struct channel_info *chan)
  40. {
  41. debugf4("\tchannel = %p\n", chan);
  42. debugf4("\tchannel->chan_idx = %d\n", chan->chan_idx);
  43. debugf4("\tchannel->ce_count = %d\n", chan->ce_count);
  44. debugf4("\tchannel->label = '%s'\n", chan->label);
  45. debugf4("\tchannel->csrow = %p\n\n", chan->csrow);
  46. }
  47. static void edac_mc_dump_csrow(struct csrow_info *csrow)
  48. {
  49. debugf4("\tcsrow = %p\n", csrow);
  50. debugf4("\tcsrow->csrow_idx = %d\n", csrow->csrow_idx);
  51. debugf4("\tcsrow->first_page = 0x%lx\n",
  52. csrow->first_page);
  53. debugf4("\tcsrow->last_page = 0x%lx\n", csrow->last_page);
  54. debugf4("\tcsrow->page_mask = 0x%lx\n", csrow->page_mask);
  55. debugf4("\tcsrow->nr_pages = 0x%x\n", csrow->nr_pages);
  56. debugf4("\tcsrow->nr_channels = %d\n",
  57. csrow->nr_channels);
  58. debugf4("\tcsrow->channels = %p\n", csrow->channels);
  59. debugf4("\tcsrow->mci = %p\n\n", csrow->mci);
  60. }
  61. static void edac_mc_dump_mci(struct mem_ctl_info *mci)
  62. {
  63. debugf3("\tmci = %p\n", mci);
  64. debugf3("\tmci->mtype_cap = %lx\n", mci->mtype_cap);
  65. debugf3("\tmci->edac_ctl_cap = %lx\n", mci->edac_ctl_cap);
  66. debugf3("\tmci->edac_cap = %lx\n", mci->edac_cap);
  67. debugf4("\tmci->edac_check = %p\n", mci->edac_check);
  68. debugf3("\tmci->nr_csrows = %d, csrows = %p\n",
  69. mci->nr_csrows, mci->csrows);
  70. debugf3("\tdev = %p\n", mci->dev);
  71. debugf3("\tmod_name:ctl_name = %s:%s\n",
  72. mci->mod_name, mci->ctl_name);
  73. debugf3("\tpvt_info = %p\n\n", mci->pvt_info);
  74. }
  75. #endif /* CONFIG_EDAC_DEBUG */
  76. /* 'ptr' points to a possibly unaligned item X such that sizeof(X) is 'size'.
  77. * Adjust 'ptr' so that its alignment is at least as stringent as what the
  78. * compiler would provide for X and return the aligned result.
  79. *
  80. * If 'size' is a constant, the compiler will optimize this whole function
  81. * down to either a no-op or the addition of a constant to the value of 'ptr'.
  82. */
  83. char * edac_align_ptr(void *ptr, unsigned size)
  84. {
  85. unsigned align, r;
  86. /* Here we assume that the alignment of a "long long" is the most
  87. * stringent alignment that the compiler will ever provide by default.
  88. * As far as I know, this is a reasonable assumption.
  89. */
  90. if (size > sizeof(long))
  91. align = sizeof(long long);
  92. else if (size > sizeof(int))
  93. align = sizeof(long);
  94. else if (size > sizeof(short))
  95. align = sizeof(int);
  96. else if (size > sizeof(char))
  97. align = sizeof(short);
  98. else
  99. return (char *) ptr;
  100. r = size % align;
  101. if (r == 0)
  102. return (char *) ptr;
  103. return (char *) (((unsigned long) ptr) + align - r);
  104. }
  105. /**
  106. * edac_mc_alloc: Allocate a struct mem_ctl_info structure
  107. * @size_pvt: size of private storage needed
  108. * @nr_csrows: Number of CWROWS needed for this MC
  109. * @nr_chans: Number of channels for the MC
  110. *
  111. * Everything is kmalloc'ed as one big chunk - more efficient.
  112. * Only can be used if all structures have the same lifetime - otherwise
  113. * you have to allocate and initialize your own structures.
  114. *
  115. * Use edac_mc_free() to free mc structures allocated by this function.
  116. *
  117. * Returns:
  118. * NULL allocation failed
  119. * struct mem_ctl_info pointer
  120. */
  121. struct mem_ctl_info *edac_mc_alloc(unsigned sz_pvt, unsigned nr_csrows,
  122. unsigned nr_chans)
  123. {
  124. struct mem_ctl_info *mci;
  125. struct csrow_info *csi, *csrow;
  126. struct channel_info *chi, *chp, *chan;
  127. void *pvt;
  128. unsigned size;
  129. int row, chn;
  130. /* Figure out the offsets of the various items from the start of an mc
  131. * structure. We want the alignment of each item to be at least as
  132. * stringent as what the compiler would provide if we could simply
  133. * hardcode everything into a single struct.
  134. */
  135. mci = (struct mem_ctl_info *) 0;
  136. csi = (struct csrow_info *)edac_align_ptr(&mci[1], sizeof(*csi));
  137. chi = (struct channel_info *)
  138. edac_align_ptr(&csi[nr_csrows], sizeof(*chi));
  139. pvt = edac_align_ptr(&chi[nr_chans * nr_csrows], sz_pvt);
  140. size = ((unsigned long) pvt) + sz_pvt;
  141. if ((mci = kmalloc(size, GFP_KERNEL)) == NULL)
  142. return NULL;
  143. /* Adjust pointers so they point within the memory we just allocated
  144. * rather than an imaginary chunk of memory located at address 0.
  145. */
  146. csi = (struct csrow_info *) (((char *) mci) + ((unsigned long) csi));
  147. chi = (struct channel_info *) (((char *) mci) + ((unsigned long) chi));
  148. pvt = sz_pvt ? (((char *) mci) + ((unsigned long) pvt)) : NULL;
  149. memset(mci, 0, size); /* clear all fields */
  150. mci->csrows = csi;
  151. mci->pvt_info = pvt;
  152. mci->nr_csrows = nr_csrows;
  153. for (row = 0; row < nr_csrows; row++) {
  154. csrow = &csi[row];
  155. csrow->csrow_idx = row;
  156. csrow->mci = mci;
  157. csrow->nr_channels = nr_chans;
  158. chp = &chi[row * nr_chans];
  159. csrow->channels = chp;
  160. for (chn = 0; chn < nr_chans; chn++) {
  161. chan = &chp[chn];
  162. chan->chan_idx = chn;
  163. chan->csrow = csrow;
  164. }
  165. }
  166. return mci;
  167. }
  168. EXPORT_SYMBOL_GPL(edac_mc_alloc);
  169. /**
  170. * edac_mc_free: Free a previously allocated 'mci' structure
  171. * @mci: pointer to a struct mem_ctl_info structure
  172. */
  173. void edac_mc_free(struct mem_ctl_info *mci)
  174. {
  175. kfree(mci);
  176. }
  177. EXPORT_SYMBOL_GPL(edac_mc_free);
  178. static struct mem_ctl_info *find_mci_by_dev(struct device *dev)
  179. {
  180. struct mem_ctl_info *mci;
  181. struct list_head *item;
  182. debugf3("%s()\n", __func__);
  183. list_for_each(item, &mc_devices) {
  184. mci = list_entry(item, struct mem_ctl_info, link);
  185. if (mci->dev == dev)
  186. return mci;
  187. }
  188. return NULL;
  189. }
  190. /* Return 0 on success, 1 on failure.
  191. * Before calling this function, caller must
  192. * assign a unique value to mci->mc_idx.
  193. */
  194. static int add_mc_to_global_list (struct mem_ctl_info *mci)
  195. {
  196. struct list_head *item, *insert_before;
  197. struct mem_ctl_info *p;
  198. insert_before = &mc_devices;
  199. if (unlikely((p = find_mci_by_dev(mci->dev)) != NULL))
  200. goto fail0;
  201. list_for_each(item, &mc_devices) {
  202. p = list_entry(item, struct mem_ctl_info, link);
  203. if (p->mc_idx >= mci->mc_idx) {
  204. if (unlikely(p->mc_idx == mci->mc_idx))
  205. goto fail1;
  206. insert_before = item;
  207. break;
  208. }
  209. }
  210. list_add_tail_rcu(&mci->link, insert_before);
  211. atomic_inc(&edac_handlers);
  212. return 0;
  213. fail0:
  214. edac_printk(KERN_WARNING, EDAC_MC,
  215. "%s (%s) %s %s already assigned %d\n", p->dev->bus_id,
  216. dev_name(mci), p->mod_name, p->ctl_name, p->mc_idx);
  217. return 1;
  218. fail1:
  219. edac_printk(KERN_WARNING, EDAC_MC,
  220. "bug in low-level driver: attempt to assign\n"
  221. " duplicate mc_idx %d in %s()\n", p->mc_idx, __func__);
  222. return 1;
  223. }
  224. static void complete_mc_list_del(struct rcu_head *head)
  225. {
  226. struct mem_ctl_info *mci;
  227. mci = container_of(head, struct mem_ctl_info, rcu);
  228. INIT_LIST_HEAD(&mci->link);
  229. complete(&mci->complete);
  230. }
  231. static void del_mc_from_global_list(struct mem_ctl_info *mci)
  232. {
  233. atomic_dec(&edac_handlers);
  234. list_del_rcu(&mci->link);
  235. init_completion(&mci->complete);
  236. call_rcu(&mci->rcu, complete_mc_list_del);
  237. wait_for_completion(&mci->complete);
  238. }
  239. /**
  240. * edac_mc_find: Search for a mem_ctl_info structure whose index is 'idx'.
  241. *
  242. * If found, return a pointer to the structure.
  243. * Else return NULL.
  244. *
  245. * Caller must hold mem_ctls_mutex.
  246. */
  247. struct mem_ctl_info * edac_mc_find(int idx)
  248. {
  249. struct list_head *item;
  250. struct mem_ctl_info *mci;
  251. list_for_each(item, &mc_devices) {
  252. mci = list_entry(item, struct mem_ctl_info, link);
  253. if (mci->mc_idx >= idx) {
  254. if (mci->mc_idx == idx)
  255. return mci;
  256. break;
  257. }
  258. }
  259. return NULL;
  260. }
  261. EXPORT_SYMBOL(edac_mc_find);
  262. /**
  263. * edac_mc_add_mc: Insert the 'mci' structure into the mci global list and
  264. * create sysfs entries associated with mci structure
  265. * @mci: pointer to the mci structure to be added to the list
  266. * @mc_idx: A unique numeric identifier to be assigned to the 'mci' structure.
  267. *
  268. * Return:
  269. * 0 Success
  270. * !0 Failure
  271. */
  272. /* FIXME - should a warning be printed if no error detection? correction? */
  273. int edac_mc_add_mc(struct mem_ctl_info *mci, int mc_idx)
  274. {
  275. debugf0("%s()\n", __func__);
  276. mci->mc_idx = mc_idx;
  277. #ifdef CONFIG_EDAC_DEBUG
  278. if (edac_debug_level >= 3)
  279. edac_mc_dump_mci(mci);
  280. if (edac_debug_level >= 4) {
  281. int i;
  282. for (i = 0; i < mci->nr_csrows; i++) {
  283. int j;
  284. edac_mc_dump_csrow(&mci->csrows[i]);
  285. for (j = 0; j < mci->csrows[i].nr_channels; j++)
  286. edac_mc_dump_channel(
  287. &mci->csrows[i].channels[j]);
  288. }
  289. }
  290. #endif
  291. mutex_lock(&mem_ctls_mutex);
  292. if (add_mc_to_global_list(mci))
  293. goto fail0;
  294. /* set load time so that error rate can be tracked */
  295. mci->start_time = jiffies;
  296. if (edac_create_sysfs_mci_device(mci)) {
  297. edac_mc_printk(mci, KERN_WARNING,
  298. "failed to create sysfs device\n");
  299. goto fail1;
  300. }
  301. /* Report action taken */
  302. edac_mc_printk(mci, KERN_INFO, "Giving out device to %s %s: DEV %s\n",
  303. mci->mod_name, mci->ctl_name, dev_name(mci));
  304. mutex_unlock(&mem_ctls_mutex);
  305. return 0;
  306. fail1:
  307. del_mc_from_global_list(mci);
  308. fail0:
  309. mutex_unlock(&mem_ctls_mutex);
  310. return 1;
  311. }
  312. EXPORT_SYMBOL_GPL(edac_mc_add_mc);
  313. /**
  314. * edac_mc_del_mc: Remove sysfs entries for specified mci structure and
  315. * remove mci structure from global list
  316. * @pdev: Pointer to 'struct device' representing mci structure to remove.
  317. *
  318. * Return pointer to removed mci structure, or NULL if device not found.
  319. */
  320. struct mem_ctl_info * edac_mc_del_mc(struct device *dev)
  321. {
  322. struct mem_ctl_info *mci;
  323. debugf0("MC: %s()\n", __func__);
  324. mutex_lock(&mem_ctls_mutex);
  325. if ((mci = find_mci_by_dev(dev)) == NULL) {
  326. mutex_unlock(&mem_ctls_mutex);
  327. return NULL;
  328. }
  329. edac_remove_sysfs_mci_device(mci);
  330. del_mc_from_global_list(mci);
  331. mutex_unlock(&mem_ctls_mutex);
  332. edac_printk(KERN_INFO, EDAC_MC,
  333. "Removed device %d for %s %s: DEV %s\n", mci->mc_idx,
  334. mci->mod_name, mci->ctl_name, dev_name(mci));
  335. return mci;
  336. }
  337. EXPORT_SYMBOL_GPL(edac_mc_del_mc);
  338. static void edac_mc_scrub_block(unsigned long page, unsigned long offset,
  339. u32 size)
  340. {
  341. struct page *pg;
  342. void *virt_addr;
  343. unsigned long flags = 0;
  344. debugf3("%s()\n", __func__);
  345. /* ECC error page was not in our memory. Ignore it. */
  346. if(!pfn_valid(page))
  347. return;
  348. /* Find the actual page structure then map it and fix */
  349. pg = pfn_to_page(page);
  350. if (PageHighMem(pg))
  351. local_irq_save(flags);
  352. virt_addr = kmap_atomic(pg, KM_BOUNCE_READ);
  353. /* Perform architecture specific atomic scrub operation */
  354. atomic_scrub(virt_addr + offset, size);
  355. /* Unmap and complete */
  356. kunmap_atomic(virt_addr, KM_BOUNCE_READ);
  357. if (PageHighMem(pg))
  358. local_irq_restore(flags);
  359. }
  360. /* FIXME - should return -1 */
  361. int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci, unsigned long page)
  362. {
  363. struct csrow_info *csrows = mci->csrows;
  364. int row, i;
  365. debugf1("MC%d: %s(): 0x%lx\n", mci->mc_idx, __func__, page);
  366. row = -1;
  367. for (i = 0; i < mci->nr_csrows; i++) {
  368. struct csrow_info *csrow = &csrows[i];
  369. if (csrow->nr_pages == 0)
  370. continue;
  371. debugf3("MC%d: %s(): first(0x%lx) page(0x%lx) last(0x%lx) "
  372. "mask(0x%lx)\n", mci->mc_idx, __func__,
  373. csrow->first_page, page, csrow->last_page,
  374. csrow->page_mask);
  375. if ((page >= csrow->first_page) &&
  376. (page <= csrow->last_page) &&
  377. ((page & csrow->page_mask) ==
  378. (csrow->first_page & csrow->page_mask))) {
  379. row = i;
  380. break;
  381. }
  382. }
  383. if (row == -1)
  384. edac_mc_printk(mci, KERN_ERR,
  385. "could not look up page error address %lx\n",
  386. (unsigned long) page);
  387. return row;
  388. }
  389. EXPORT_SYMBOL_GPL(edac_mc_find_csrow_by_page);
  390. /* FIXME - setable log (warning/emerg) levels */
  391. /* FIXME - integrate with evlog: http://evlog.sourceforge.net/ */
  392. void edac_mc_handle_ce(struct mem_ctl_info *mci,
  393. unsigned long page_frame_number, unsigned long offset_in_page,
  394. unsigned long syndrome, int row, int channel, const char *msg)
  395. {
  396. unsigned long remapped_page;
  397. debugf3("MC%d: %s()\n", mci->mc_idx, __func__);
  398. /* FIXME - maybe make panic on INTERNAL ERROR an option */
  399. if (row >= mci->nr_csrows || row < 0) {
  400. /* something is wrong */
  401. edac_mc_printk(mci, KERN_ERR,
  402. "INTERNAL ERROR: row out of range "
  403. "(%d >= %d)\n", row, mci->nr_csrows);
  404. edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
  405. return;
  406. }
  407. if (channel >= mci->csrows[row].nr_channels || channel < 0) {
  408. /* something is wrong */
  409. edac_mc_printk(mci, KERN_ERR,
  410. "INTERNAL ERROR: channel out of range "
  411. "(%d >= %d)\n", channel,
  412. mci->csrows[row].nr_channels);
  413. edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
  414. return;
  415. }
  416. if (edac_get_log_ce())
  417. /* FIXME - put in DIMM location */
  418. edac_mc_printk(mci, KERN_WARNING,
  419. "CE page 0x%lx, offset 0x%lx, grain %d, syndrome "
  420. "0x%lx, row %d, channel %d, label \"%s\": %s\n",
  421. page_frame_number, offset_in_page,
  422. mci->csrows[row].grain, syndrome, row, channel,
  423. mci->csrows[row].channels[channel].label, msg);
  424. mci->ce_count++;
  425. mci->csrows[row].ce_count++;
  426. mci->csrows[row].channels[channel].ce_count++;
  427. if (mci->scrub_mode & SCRUB_SW_SRC) {
  428. /*
  429. * Some MC's can remap memory so that it is still available
  430. * at a different address when PCI devices map into memory.
  431. * MC's that can't do this lose the memory where PCI devices
  432. * are mapped. This mapping is MC dependant and so we call
  433. * back into the MC driver for it to map the MC page to
  434. * a physical (CPU) page which can then be mapped to a virtual
  435. * page - which can then be scrubbed.
  436. */
  437. remapped_page = mci->ctl_page_to_phys ?
  438. mci->ctl_page_to_phys(mci, page_frame_number) :
  439. page_frame_number;
  440. edac_mc_scrub_block(remapped_page, offset_in_page,
  441. mci->csrows[row].grain);
  442. }
  443. }
  444. EXPORT_SYMBOL_GPL(edac_mc_handle_ce);
  445. void edac_mc_handle_ce_no_info(struct mem_ctl_info *mci, const char *msg)
  446. {
  447. if (edac_get_log_ce())
  448. edac_mc_printk(mci, KERN_WARNING,
  449. "CE - no information available: %s\n", msg);
  450. mci->ce_noinfo_count++;
  451. mci->ce_count++;
  452. }
  453. EXPORT_SYMBOL_GPL(edac_mc_handle_ce_no_info);
  454. void edac_mc_handle_ue(struct mem_ctl_info *mci,
  455. unsigned long page_frame_number, unsigned long offset_in_page,
  456. int row, const char *msg)
  457. {
  458. int len = EDAC_MC_LABEL_LEN * 4;
  459. char labels[len + 1];
  460. char *pos = labels;
  461. int chan;
  462. int chars;
  463. debugf3("MC%d: %s()\n", mci->mc_idx, __func__);
  464. /* FIXME - maybe make panic on INTERNAL ERROR an option */
  465. if (row >= mci->nr_csrows || row < 0) {
  466. /* something is wrong */
  467. edac_mc_printk(mci, KERN_ERR,
  468. "INTERNAL ERROR: row out of range "
  469. "(%d >= %d)\n", row, mci->nr_csrows);
  470. edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR");
  471. return;
  472. }
  473. chars = snprintf(pos, len + 1, "%s",
  474. mci->csrows[row].channels[0].label);
  475. len -= chars;
  476. pos += chars;
  477. for (chan = 1; (chan < mci->csrows[row].nr_channels) && (len > 0);
  478. chan++) {
  479. chars = snprintf(pos, len + 1, ":%s",
  480. mci->csrows[row].channels[chan].label);
  481. len -= chars;
  482. pos += chars;
  483. }
  484. if (edac_get_log_ue())
  485. edac_mc_printk(mci, KERN_EMERG,
  486. "UE page 0x%lx, offset 0x%lx, grain %d, row %d, "
  487. "labels \"%s\": %s\n", page_frame_number,
  488. offset_in_page, mci->csrows[row].grain, row, labels,
  489. msg);
  490. if (edac_get_panic_on_ue())
  491. panic("EDAC MC%d: UE page 0x%lx, offset 0x%lx, grain %d, "
  492. "row %d, labels \"%s\": %s\n", mci->mc_idx,
  493. page_frame_number, offset_in_page,
  494. mci->csrows[row].grain, row, labels, msg);
  495. mci->ue_count++;
  496. mci->csrows[row].ue_count++;
  497. }
  498. EXPORT_SYMBOL_GPL(edac_mc_handle_ue);
  499. void edac_mc_handle_ue_no_info(struct mem_ctl_info *mci, const char *msg)
  500. {
  501. if (edac_get_panic_on_ue())
  502. panic("EDAC MC%d: Uncorrected Error", mci->mc_idx);
  503. if (edac_get_log_ue())
  504. edac_mc_printk(mci, KERN_WARNING,
  505. "UE - no information available: %s\n", msg);
  506. mci->ue_noinfo_count++;
  507. mci->ue_count++;
  508. }
  509. EXPORT_SYMBOL_GPL(edac_mc_handle_ue_no_info);
  510. /*************************************************************
  511. * On Fully Buffered DIMM modules, this help function is
  512. * called to process UE events
  513. */
  514. void edac_mc_handle_fbd_ue(struct mem_ctl_info *mci,
  515. unsigned int csrow,
  516. unsigned int channela,
  517. unsigned int channelb,
  518. char *msg)
  519. {
  520. int len = EDAC_MC_LABEL_LEN * 4;
  521. char labels[len + 1];
  522. char *pos = labels;
  523. int chars;
  524. if (csrow >= mci->nr_csrows) {
  525. /* something is wrong */
  526. edac_mc_printk(mci, KERN_ERR,
  527. "INTERNAL ERROR: row out of range (%d >= %d)\n",
  528. csrow, mci->nr_csrows);
  529. edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR");
  530. return;
  531. }
  532. if (channela >= mci->csrows[csrow].nr_channels) {
  533. /* something is wrong */
  534. edac_mc_printk(mci, KERN_ERR,
  535. "INTERNAL ERROR: channel-a out of range "
  536. "(%d >= %d)\n",
  537. channela, mci->csrows[csrow].nr_channels);
  538. edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR");
  539. return;
  540. }
  541. if (channelb >= mci->csrows[csrow].nr_channels) {
  542. /* something is wrong */
  543. edac_mc_printk(mci, KERN_ERR,
  544. "INTERNAL ERROR: channel-b out of range "
  545. "(%d >= %d)\n",
  546. channelb, mci->csrows[csrow].nr_channels);
  547. edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR");
  548. return;
  549. }
  550. mci->ue_count++;
  551. mci->csrows[csrow].ue_count++;
  552. /* Generate the DIMM labels from the specified channels */
  553. chars = snprintf(pos, len + 1, "%s",
  554. mci->csrows[csrow].channels[channela].label);
  555. len -= chars; pos += chars;
  556. chars = snprintf(pos, len + 1, "-%s",
  557. mci->csrows[csrow].channels[channelb].label);
  558. if (edac_get_log_ue())
  559. edac_mc_printk(mci, KERN_EMERG,
  560. "UE row %d, channel-a= %d channel-b= %d "
  561. "labels \"%s\": %s\n", csrow, channela, channelb,
  562. labels, msg);
  563. if (edac_get_panic_on_ue())
  564. panic("UE row %d, channel-a= %d channel-b= %d "
  565. "labels \"%s\": %s\n", csrow, channela,
  566. channelb, labels, msg);
  567. }
  568. EXPORT_SYMBOL(edac_mc_handle_fbd_ue);
  569. /*************************************************************
  570. * On Fully Buffered DIMM modules, this help function is
  571. * called to process CE events
  572. */
  573. void edac_mc_handle_fbd_ce(struct mem_ctl_info *mci,
  574. unsigned int csrow,
  575. unsigned int channel,
  576. char *msg)
  577. {
  578. /* Ensure boundary values */
  579. if (csrow >= mci->nr_csrows) {
  580. /* something is wrong */
  581. edac_mc_printk(mci, KERN_ERR,
  582. "INTERNAL ERROR: row out of range (%d >= %d)\n",
  583. csrow, mci->nr_csrows);
  584. edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
  585. return;
  586. }
  587. if (channel >= mci->csrows[csrow].nr_channels) {
  588. /* something is wrong */
  589. edac_mc_printk(mci, KERN_ERR,
  590. "INTERNAL ERROR: channel out of range (%d >= %d)\n",
  591. channel, mci->csrows[csrow].nr_channels);
  592. edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
  593. return;
  594. }
  595. if (edac_get_log_ce())
  596. /* FIXME - put in DIMM location */
  597. edac_mc_printk(mci, KERN_WARNING,
  598. "CE row %d, channel %d, label \"%s\": %s\n",
  599. csrow, channel,
  600. mci->csrows[csrow].channels[channel].label,
  601. msg);
  602. mci->ce_count++;
  603. mci->csrows[csrow].ce_count++;
  604. mci->csrows[csrow].channels[channel].ce_count++;
  605. }
  606. EXPORT_SYMBOL(edac_mc_handle_fbd_ce);
  607. /*
  608. * Iterate over all MC instances and check for ECC, et al, errors
  609. */
  610. void edac_check_mc_devices(void)
  611. {
  612. struct list_head *item;
  613. struct mem_ctl_info *mci;
  614. debugf3("%s()\n", __func__);
  615. mutex_lock(&mem_ctls_mutex);
  616. list_for_each(item, &mc_devices) {
  617. mci = list_entry(item, struct mem_ctl_info, link);
  618. if (mci->edac_check != NULL)
  619. mci->edac_check(mci);
  620. }
  621. mutex_unlock(&mem_ctls_mutex);
  622. }