edac_mc.c 22 KB

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