edac_mc.c 23 KB

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