edac_mc.c 19 KB

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