edac_mc.c 22 KB

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