edac_mc.c 22 KB

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