edac_mc.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  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/ctype.h>
  28. #include <linux/edac.h>
  29. #include <linux/bitops.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. #define CREATE_TRACE_POINTS
  36. #define TRACE_INCLUDE_PATH ../../include/ras
  37. #include <ras/ras_event.h>
  38. /* lock to memory controller's control array */
  39. static DEFINE_MUTEX(mem_ctls_mutex);
  40. static LIST_HEAD(mc_devices);
  41. /*
  42. * Used to lock EDAC MC to just one module, avoiding two drivers e. g.
  43. * apei/ghes and i7core_edac to be used at the same time.
  44. */
  45. static void const *edac_mc_owner;
  46. unsigned edac_dimm_info_location(struct dimm_info *dimm, char *buf,
  47. unsigned len)
  48. {
  49. struct mem_ctl_info *mci = dimm->mci;
  50. int i, n, count = 0;
  51. char *p = buf;
  52. for (i = 0; i < mci->n_layers; i++) {
  53. n = snprintf(p, len, "%s %d ",
  54. edac_layer_name[mci->layers[i].type],
  55. dimm->location[i]);
  56. p += n;
  57. len -= n;
  58. count += n;
  59. if (!len)
  60. break;
  61. }
  62. return count;
  63. }
  64. #ifdef CONFIG_EDAC_DEBUG
  65. static void edac_mc_dump_channel(struct rank_info *chan)
  66. {
  67. edac_dbg(4, " channel->chan_idx = %d\n", chan->chan_idx);
  68. edac_dbg(4, " channel = %p\n", chan);
  69. edac_dbg(4, " channel->csrow = %p\n", chan->csrow);
  70. edac_dbg(4, " channel->dimm = %p\n", chan->dimm);
  71. }
  72. static void edac_mc_dump_dimm(struct dimm_info *dimm, int number)
  73. {
  74. char location[80];
  75. edac_dimm_info_location(dimm, location, sizeof(location));
  76. edac_dbg(4, "%s%i: %smapped as virtual row %d, chan %d\n",
  77. dimm->mci->csbased ? "rank" : "dimm",
  78. number, location, dimm->csrow, dimm->cschannel);
  79. edac_dbg(4, " dimm = %p\n", dimm);
  80. edac_dbg(4, " dimm->label = '%s'\n", dimm->label);
  81. edac_dbg(4, " dimm->nr_pages = 0x%x\n", dimm->nr_pages);
  82. edac_dbg(4, " dimm->grain = %d\n", dimm->grain);
  83. edac_dbg(4, " dimm->nr_pages = 0x%x\n", dimm->nr_pages);
  84. }
  85. static void edac_mc_dump_csrow(struct csrow_info *csrow)
  86. {
  87. edac_dbg(4, "csrow->csrow_idx = %d\n", csrow->csrow_idx);
  88. edac_dbg(4, " csrow = %p\n", csrow);
  89. edac_dbg(4, " csrow->first_page = 0x%lx\n", csrow->first_page);
  90. edac_dbg(4, " csrow->last_page = 0x%lx\n", csrow->last_page);
  91. edac_dbg(4, " csrow->page_mask = 0x%lx\n", csrow->page_mask);
  92. edac_dbg(4, " csrow->nr_channels = %d\n", csrow->nr_channels);
  93. edac_dbg(4, " csrow->channels = %p\n", csrow->channels);
  94. edac_dbg(4, " csrow->mci = %p\n", csrow->mci);
  95. }
  96. static void edac_mc_dump_mci(struct mem_ctl_info *mci)
  97. {
  98. edac_dbg(3, "\tmci = %p\n", mci);
  99. edac_dbg(3, "\tmci->mtype_cap = %lx\n", mci->mtype_cap);
  100. edac_dbg(3, "\tmci->edac_ctl_cap = %lx\n", mci->edac_ctl_cap);
  101. edac_dbg(3, "\tmci->edac_cap = %lx\n", mci->edac_cap);
  102. edac_dbg(4, "\tmci->edac_check = %p\n", mci->edac_check);
  103. edac_dbg(3, "\tmci->nr_csrows = %d, csrows = %p\n",
  104. mci->nr_csrows, mci->csrows);
  105. edac_dbg(3, "\tmci->nr_dimms = %d, dimms = %p\n",
  106. mci->tot_dimms, mci->dimms);
  107. edac_dbg(3, "\tdev = %p\n", mci->pdev);
  108. edac_dbg(3, "\tmod_name:ctl_name = %s:%s\n",
  109. mci->mod_name, mci->ctl_name);
  110. edac_dbg(3, "\tpvt_info = %p\n\n", mci->pvt_info);
  111. }
  112. #endif /* CONFIG_EDAC_DEBUG */
  113. /*
  114. * keep those in sync with the enum mem_type
  115. */
  116. const char *edac_mem_types[] = {
  117. "Empty csrow",
  118. "Reserved csrow type",
  119. "Unknown csrow type",
  120. "Fast page mode RAM",
  121. "Extended data out RAM",
  122. "Burst Extended data out RAM",
  123. "Single data rate SDRAM",
  124. "Registered single data rate SDRAM",
  125. "Double data rate SDRAM",
  126. "Registered Double data rate SDRAM",
  127. "Rambus DRAM",
  128. "Unbuffered DDR2 RAM",
  129. "Fully buffered DDR2",
  130. "Registered DDR2 RAM",
  131. "Rambus XDR",
  132. "Unbuffered DDR3 RAM",
  133. "Registered DDR3 RAM",
  134. };
  135. EXPORT_SYMBOL_GPL(edac_mem_types);
  136. /**
  137. * edac_align_ptr - Prepares the pointer offsets for a single-shot allocation
  138. * @p: pointer to a pointer with the memory offset to be used. At
  139. * return, this will be incremented to point to the next offset
  140. * @size: Size of the data structure to be reserved
  141. * @n_elems: Number of elements that should be reserved
  142. *
  143. * If 'size' is a constant, the compiler will optimize this whole function
  144. * down to either a no-op or the addition of a constant to the value of '*p'.
  145. *
  146. * The 'p' pointer is absolutely needed to keep the proper advancing
  147. * further in memory to the proper offsets when allocating the struct along
  148. * with its embedded structs, as edac_device_alloc_ctl_info() does it
  149. * above, for example.
  150. *
  151. * At return, the pointer 'p' will be incremented to be used on a next call
  152. * to this function.
  153. */
  154. void *edac_align_ptr(void **p, unsigned size, int n_elems)
  155. {
  156. unsigned align, r;
  157. void *ptr = *p;
  158. *p += size * n_elems;
  159. /*
  160. * 'p' can possibly be an unaligned item X such that sizeof(X) is
  161. * 'size'. Adjust 'p' so that its alignment is at least as
  162. * stringent as what the compiler would provide for X and return
  163. * the aligned result.
  164. * Here we assume that the alignment of a "long long" is the most
  165. * stringent alignment that the compiler will ever provide by default.
  166. * As far as I know, this is a reasonable assumption.
  167. */
  168. if (size > sizeof(long))
  169. align = sizeof(long long);
  170. else if (size > sizeof(int))
  171. align = sizeof(long);
  172. else if (size > sizeof(short))
  173. align = sizeof(int);
  174. else if (size > sizeof(char))
  175. align = sizeof(short);
  176. else
  177. return (char *)ptr;
  178. r = (unsigned long)p % align;
  179. if (r == 0)
  180. return (char *)ptr;
  181. *p += align - r;
  182. return (void *)(((unsigned long)ptr) + align - r);
  183. }
  184. static void _edac_mc_free(struct mem_ctl_info *mci)
  185. {
  186. int i, chn, row;
  187. struct csrow_info *csr;
  188. const unsigned int tot_dimms = mci->tot_dimms;
  189. const unsigned int tot_channels = mci->num_cschannel;
  190. const unsigned int tot_csrows = mci->nr_csrows;
  191. if (mci->dimms) {
  192. for (i = 0; i < tot_dimms; i++)
  193. kfree(mci->dimms[i]);
  194. kfree(mci->dimms);
  195. }
  196. if (mci->csrows) {
  197. for (row = 0; row < tot_csrows; row++) {
  198. csr = mci->csrows[row];
  199. if (csr) {
  200. if (csr->channels) {
  201. for (chn = 0; chn < tot_channels; chn++)
  202. kfree(csr->channels[chn]);
  203. kfree(csr->channels);
  204. }
  205. kfree(csr);
  206. }
  207. }
  208. kfree(mci->csrows);
  209. }
  210. kfree(mci);
  211. }
  212. /**
  213. * edac_mc_alloc: Allocate and partially fill a struct mem_ctl_info structure
  214. * @mc_num: Memory controller number
  215. * @n_layers: Number of MC hierarchy layers
  216. * layers: Describes each layer as seen by the Memory Controller
  217. * @size_pvt: size of private storage needed
  218. *
  219. *
  220. * Everything is kmalloc'ed as one big chunk - more efficient.
  221. * Only can be used if all structures have the same lifetime - otherwise
  222. * you have to allocate and initialize your own structures.
  223. *
  224. * Use edac_mc_free() to free mc structures allocated by this function.
  225. *
  226. * NOTE: drivers handle multi-rank memories in different ways: in some
  227. * drivers, one multi-rank memory stick is mapped as one entry, while, in
  228. * others, a single multi-rank memory stick would be mapped into several
  229. * entries. Currently, this function will allocate multiple struct dimm_info
  230. * on such scenarios, as grouping the multiple ranks require drivers change.
  231. *
  232. * Returns:
  233. * On failure: NULL
  234. * On success: struct mem_ctl_info pointer
  235. */
  236. struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
  237. unsigned n_layers,
  238. struct edac_mc_layer *layers,
  239. unsigned sz_pvt)
  240. {
  241. struct mem_ctl_info *mci;
  242. struct edac_mc_layer *layer;
  243. struct csrow_info *csr;
  244. struct rank_info *chan;
  245. struct dimm_info *dimm;
  246. u32 *ce_per_layer[EDAC_MAX_LAYERS], *ue_per_layer[EDAC_MAX_LAYERS];
  247. unsigned pos[EDAC_MAX_LAYERS];
  248. unsigned size, tot_dimms = 1, count = 1;
  249. unsigned tot_csrows = 1, tot_channels = 1, tot_errcount = 0;
  250. void *pvt, *p, *ptr = NULL;
  251. int i, j, row, chn, n, len, off;
  252. bool per_rank = false;
  253. BUG_ON(n_layers > EDAC_MAX_LAYERS || n_layers == 0);
  254. /*
  255. * Calculate the total amount of dimms and csrows/cschannels while
  256. * in the old API emulation mode
  257. */
  258. for (i = 0; i < n_layers; i++) {
  259. tot_dimms *= layers[i].size;
  260. if (layers[i].is_virt_csrow)
  261. tot_csrows *= layers[i].size;
  262. else
  263. tot_channels *= layers[i].size;
  264. if (layers[i].type == EDAC_MC_LAYER_CHIP_SELECT)
  265. per_rank = true;
  266. }
  267. /* Figure out the offsets of the various items from the start of an mc
  268. * structure. We want the alignment of each item to be at least as
  269. * stringent as what the compiler would provide if we could simply
  270. * hardcode everything into a single struct.
  271. */
  272. mci = edac_align_ptr(&ptr, sizeof(*mci), 1);
  273. layer = edac_align_ptr(&ptr, sizeof(*layer), n_layers);
  274. for (i = 0; i < n_layers; i++) {
  275. count *= layers[i].size;
  276. edac_dbg(4, "errcount layer %d size %d\n", i, count);
  277. ce_per_layer[i] = edac_align_ptr(&ptr, sizeof(u32), count);
  278. ue_per_layer[i] = edac_align_ptr(&ptr, sizeof(u32), count);
  279. tot_errcount += 2 * count;
  280. }
  281. edac_dbg(4, "allocating %d error counters\n", tot_errcount);
  282. pvt = edac_align_ptr(&ptr, sz_pvt, 1);
  283. size = ((unsigned long)pvt) + sz_pvt;
  284. edac_dbg(1, "allocating %u bytes for mci data (%d %s, %d csrows/channels)\n",
  285. size,
  286. tot_dimms,
  287. per_rank ? "ranks" : "dimms",
  288. tot_csrows * tot_channels);
  289. mci = kzalloc(size, GFP_KERNEL);
  290. if (mci == NULL)
  291. return NULL;
  292. /* Adjust pointers so they point within the memory we just allocated
  293. * rather than an imaginary chunk of memory located at address 0.
  294. */
  295. layer = (struct edac_mc_layer *)(((char *)mci) + ((unsigned long)layer));
  296. for (i = 0; i < n_layers; i++) {
  297. mci->ce_per_layer[i] = (u32 *)((char *)mci + ((unsigned long)ce_per_layer[i]));
  298. mci->ue_per_layer[i] = (u32 *)((char *)mci + ((unsigned long)ue_per_layer[i]));
  299. }
  300. pvt = sz_pvt ? (((char *)mci) + ((unsigned long)pvt)) : NULL;
  301. /* setup index and various internal pointers */
  302. mci->mc_idx = mc_num;
  303. mci->tot_dimms = tot_dimms;
  304. mci->pvt_info = pvt;
  305. mci->n_layers = n_layers;
  306. mci->layers = layer;
  307. memcpy(mci->layers, layers, sizeof(*layer) * n_layers);
  308. mci->nr_csrows = tot_csrows;
  309. mci->num_cschannel = tot_channels;
  310. mci->csbased = per_rank;
  311. /*
  312. * Alocate and fill the csrow/channels structs
  313. */
  314. mci->csrows = kcalloc(tot_csrows, sizeof(*mci->csrows), GFP_KERNEL);
  315. if (!mci->csrows)
  316. goto error;
  317. for (row = 0; row < tot_csrows; row++) {
  318. csr = kzalloc(sizeof(**mci->csrows), GFP_KERNEL);
  319. if (!csr)
  320. goto error;
  321. mci->csrows[row] = csr;
  322. csr->csrow_idx = row;
  323. csr->mci = mci;
  324. csr->nr_channels = tot_channels;
  325. csr->channels = kcalloc(tot_channels, sizeof(*csr->channels),
  326. GFP_KERNEL);
  327. if (!csr->channels)
  328. goto error;
  329. for (chn = 0; chn < tot_channels; chn++) {
  330. chan = kzalloc(sizeof(**csr->channels), GFP_KERNEL);
  331. if (!chan)
  332. goto error;
  333. csr->channels[chn] = chan;
  334. chan->chan_idx = chn;
  335. chan->csrow = csr;
  336. }
  337. }
  338. /*
  339. * Allocate and fill the dimm structs
  340. */
  341. mci->dimms = kcalloc(tot_dimms, sizeof(*mci->dimms), GFP_KERNEL);
  342. if (!mci->dimms)
  343. goto error;
  344. memset(&pos, 0, sizeof(pos));
  345. row = 0;
  346. chn = 0;
  347. for (i = 0; i < tot_dimms; i++) {
  348. chan = mci->csrows[row]->channels[chn];
  349. off = EDAC_DIMM_OFF(layer, n_layers, pos[0], pos[1], pos[2]);
  350. if (off < 0 || off >= tot_dimms) {
  351. edac_mc_printk(mci, KERN_ERR, "EDAC core bug: EDAC_DIMM_OFF is trying to do an illegal data access\n");
  352. goto error;
  353. }
  354. dimm = kzalloc(sizeof(**mci->dimms), GFP_KERNEL);
  355. if (!dimm)
  356. goto error;
  357. mci->dimms[off] = dimm;
  358. dimm->mci = mci;
  359. /*
  360. * Copy DIMM location and initialize it.
  361. */
  362. len = sizeof(dimm->label);
  363. p = dimm->label;
  364. n = snprintf(p, len, "mc#%u", mc_num);
  365. p += n;
  366. len -= n;
  367. for (j = 0; j < n_layers; j++) {
  368. n = snprintf(p, len, "%s#%u",
  369. edac_layer_name[layers[j].type],
  370. pos[j]);
  371. p += n;
  372. len -= n;
  373. dimm->location[j] = pos[j];
  374. if (len <= 0)
  375. break;
  376. }
  377. /* Link it to the csrows old API data */
  378. chan->dimm = dimm;
  379. dimm->csrow = row;
  380. dimm->cschannel = chn;
  381. /* Increment csrow location */
  382. if (layers[0].is_virt_csrow) {
  383. chn++;
  384. if (chn == tot_channels) {
  385. chn = 0;
  386. row++;
  387. }
  388. } else {
  389. row++;
  390. if (row == tot_csrows) {
  391. row = 0;
  392. chn++;
  393. }
  394. }
  395. /* Increment dimm location */
  396. for (j = n_layers - 1; j >= 0; j--) {
  397. pos[j]++;
  398. if (pos[j] < layers[j].size)
  399. break;
  400. pos[j] = 0;
  401. }
  402. }
  403. mci->op_state = OP_ALLOC;
  404. return mci;
  405. error:
  406. _edac_mc_free(mci);
  407. return NULL;
  408. }
  409. EXPORT_SYMBOL_GPL(edac_mc_alloc);
  410. /**
  411. * edac_mc_free
  412. * 'Free' a previously allocated 'mci' structure
  413. * @mci: pointer to a struct mem_ctl_info structure
  414. */
  415. void edac_mc_free(struct mem_ctl_info *mci)
  416. {
  417. edac_dbg(1, "\n");
  418. /* If we're not yet registered with sysfs free only what was allocated
  419. * in edac_mc_alloc().
  420. */
  421. if (!device_is_registered(&mci->dev)) {
  422. _edac_mc_free(mci);
  423. return;
  424. }
  425. /* the mci instance is freed here, when the sysfs object is dropped */
  426. edac_unregister_sysfs(mci);
  427. }
  428. EXPORT_SYMBOL_GPL(edac_mc_free);
  429. /**
  430. * find_mci_by_dev
  431. *
  432. * scan list of controllers looking for the one that manages
  433. * the 'dev' device
  434. * @dev: pointer to a struct device related with the MCI
  435. */
  436. struct mem_ctl_info *find_mci_by_dev(struct device *dev)
  437. {
  438. struct mem_ctl_info *mci;
  439. struct list_head *item;
  440. edac_dbg(3, "\n");
  441. list_for_each(item, &mc_devices) {
  442. mci = list_entry(item, struct mem_ctl_info, link);
  443. if (mci->pdev == dev)
  444. return mci;
  445. }
  446. return NULL;
  447. }
  448. EXPORT_SYMBOL_GPL(find_mci_by_dev);
  449. /*
  450. * handler for EDAC to check if NMI type handler has asserted interrupt
  451. */
  452. static int edac_mc_assert_error_check_and_clear(void)
  453. {
  454. int old_state;
  455. if (edac_op_state == EDAC_OPSTATE_POLL)
  456. return 1;
  457. old_state = edac_err_assert;
  458. edac_err_assert = 0;
  459. return old_state;
  460. }
  461. /*
  462. * edac_mc_workq_function
  463. * performs the operation scheduled by a workq request
  464. */
  465. static void edac_mc_workq_function(struct work_struct *work_req)
  466. {
  467. struct delayed_work *d_work = to_delayed_work(work_req);
  468. struct mem_ctl_info *mci = to_edac_mem_ctl_work(d_work);
  469. mutex_lock(&mem_ctls_mutex);
  470. /* if this control struct has movd to offline state, we are done */
  471. if (mci->op_state == OP_OFFLINE) {
  472. mutex_unlock(&mem_ctls_mutex);
  473. return;
  474. }
  475. /* Only poll controllers that are running polled and have a check */
  476. if (edac_mc_assert_error_check_and_clear() && (mci->edac_check != NULL))
  477. mci->edac_check(mci);
  478. mutex_unlock(&mem_ctls_mutex);
  479. /* Reschedule */
  480. queue_delayed_work(edac_workqueue, &mci->work,
  481. msecs_to_jiffies(edac_mc_get_poll_msec()));
  482. }
  483. /*
  484. * edac_mc_workq_setup
  485. * initialize a workq item for this mci
  486. * passing in the new delay period in msec
  487. *
  488. * locking model:
  489. *
  490. * called with the mem_ctls_mutex held
  491. */
  492. static void edac_mc_workq_setup(struct mem_ctl_info *mci, unsigned msec)
  493. {
  494. edac_dbg(0, "\n");
  495. /* if this instance is not in the POLL state, then simply return */
  496. if (mci->op_state != OP_RUNNING_POLL)
  497. return;
  498. INIT_DELAYED_WORK(&mci->work, edac_mc_workq_function);
  499. mod_delayed_work(edac_workqueue, &mci->work, msecs_to_jiffies(msec));
  500. }
  501. /*
  502. * edac_mc_workq_teardown
  503. * stop the workq processing on this mci
  504. *
  505. * locking model:
  506. *
  507. * called WITHOUT lock held
  508. */
  509. static void edac_mc_workq_teardown(struct mem_ctl_info *mci)
  510. {
  511. int status;
  512. if (mci->op_state != OP_RUNNING_POLL)
  513. return;
  514. status = cancel_delayed_work(&mci->work);
  515. if (status == 0) {
  516. edac_dbg(0, "not canceled, flush the queue\n");
  517. /* workq instance might be running, wait for it */
  518. flush_workqueue(edac_workqueue);
  519. }
  520. }
  521. /*
  522. * edac_mc_reset_delay_period(unsigned long value)
  523. *
  524. * user space has updated our poll period value, need to
  525. * reset our workq delays
  526. */
  527. void edac_mc_reset_delay_period(int value)
  528. {
  529. struct mem_ctl_info *mci;
  530. struct list_head *item;
  531. mutex_lock(&mem_ctls_mutex);
  532. list_for_each(item, &mc_devices) {
  533. mci = list_entry(item, struct mem_ctl_info, link);
  534. edac_mc_workq_setup(mci, (unsigned long) value);
  535. }
  536. mutex_unlock(&mem_ctls_mutex);
  537. }
  538. /* Return 0 on success, 1 on failure.
  539. * Before calling this function, caller must
  540. * assign a unique value to mci->mc_idx.
  541. *
  542. * locking model:
  543. *
  544. * called with the mem_ctls_mutex lock held
  545. */
  546. static int add_mc_to_global_list(struct mem_ctl_info *mci)
  547. {
  548. struct list_head *item, *insert_before;
  549. struct mem_ctl_info *p;
  550. insert_before = &mc_devices;
  551. p = find_mci_by_dev(mci->pdev);
  552. if (unlikely(p != NULL))
  553. goto fail0;
  554. list_for_each(item, &mc_devices) {
  555. p = list_entry(item, struct mem_ctl_info, link);
  556. if (p->mc_idx >= mci->mc_idx) {
  557. if (unlikely(p->mc_idx == mci->mc_idx))
  558. goto fail1;
  559. insert_before = item;
  560. break;
  561. }
  562. }
  563. list_add_tail_rcu(&mci->link, insert_before);
  564. atomic_inc(&edac_handlers);
  565. return 0;
  566. fail0:
  567. edac_printk(KERN_WARNING, EDAC_MC,
  568. "%s (%s) %s %s already assigned %d\n", dev_name(p->pdev),
  569. edac_dev_name(mci), p->mod_name, p->ctl_name, p->mc_idx);
  570. return 1;
  571. fail1:
  572. edac_printk(KERN_WARNING, EDAC_MC,
  573. "bug in low-level driver: attempt to assign\n"
  574. " duplicate mc_idx %d in %s()\n", p->mc_idx, __func__);
  575. return 1;
  576. }
  577. static int del_mc_from_global_list(struct mem_ctl_info *mci)
  578. {
  579. int handlers = atomic_dec_return(&edac_handlers);
  580. list_del_rcu(&mci->link);
  581. /* these are for safe removal of devices from global list while
  582. * NMI handlers may be traversing list
  583. */
  584. synchronize_rcu();
  585. INIT_LIST_HEAD(&mci->link);
  586. return handlers;
  587. }
  588. /**
  589. * edac_mc_find: Search for a mem_ctl_info structure whose index is 'idx'.
  590. *
  591. * If found, return a pointer to the structure.
  592. * Else return NULL.
  593. *
  594. * Caller must hold mem_ctls_mutex.
  595. */
  596. struct mem_ctl_info *edac_mc_find(int idx)
  597. {
  598. struct list_head *item;
  599. struct mem_ctl_info *mci;
  600. list_for_each(item, &mc_devices) {
  601. mci = list_entry(item, struct mem_ctl_info, link);
  602. if (mci->mc_idx >= idx) {
  603. if (mci->mc_idx == idx)
  604. return mci;
  605. break;
  606. }
  607. }
  608. return NULL;
  609. }
  610. EXPORT_SYMBOL(edac_mc_find);
  611. /**
  612. * edac_mc_add_mc: Insert the 'mci' structure into the mci global list and
  613. * create sysfs entries associated with mci structure
  614. * @mci: pointer to the mci structure to be added to the list
  615. *
  616. * Return:
  617. * 0 Success
  618. * !0 Failure
  619. */
  620. /* FIXME - should a warning be printed if no error detection? correction? */
  621. int edac_mc_add_mc(struct mem_ctl_info *mci)
  622. {
  623. int ret = -EINVAL;
  624. edac_dbg(0, "\n");
  625. #ifdef CONFIG_EDAC_DEBUG
  626. if (edac_debug_level >= 3)
  627. edac_mc_dump_mci(mci);
  628. if (edac_debug_level >= 4) {
  629. int i;
  630. for (i = 0; i < mci->nr_csrows; i++) {
  631. struct csrow_info *csrow = mci->csrows[i];
  632. u32 nr_pages = 0;
  633. int j;
  634. for (j = 0; j < csrow->nr_channels; j++)
  635. nr_pages += csrow->channels[j]->dimm->nr_pages;
  636. if (!nr_pages)
  637. continue;
  638. edac_mc_dump_csrow(csrow);
  639. for (j = 0; j < csrow->nr_channels; j++)
  640. if (csrow->channels[j]->dimm->nr_pages)
  641. edac_mc_dump_channel(csrow->channels[j]);
  642. }
  643. for (i = 0; i < mci->tot_dimms; i++)
  644. if (mci->dimms[i]->nr_pages)
  645. edac_mc_dump_dimm(mci->dimms[i], i);
  646. }
  647. #endif
  648. mutex_lock(&mem_ctls_mutex);
  649. if (edac_mc_owner && edac_mc_owner != mci->mod_name) {
  650. ret = -EPERM;
  651. goto fail0;
  652. }
  653. if (add_mc_to_global_list(mci))
  654. goto fail0;
  655. /* set load time so that error rate can be tracked */
  656. mci->start_time = jiffies;
  657. if (edac_create_sysfs_mci_device(mci)) {
  658. edac_mc_printk(mci, KERN_WARNING,
  659. "failed to create sysfs device\n");
  660. goto fail1;
  661. }
  662. /* If there IS a check routine, then we are running POLLED */
  663. if (mci->edac_check != NULL) {
  664. /* This instance is NOW RUNNING */
  665. mci->op_state = OP_RUNNING_POLL;
  666. edac_mc_workq_setup(mci, edac_mc_get_poll_msec());
  667. } else {
  668. mci->op_state = OP_RUNNING_INTERRUPT;
  669. }
  670. /* Report action taken */
  671. edac_mc_printk(mci, KERN_INFO, "Giving out device to '%s' '%s':"
  672. " DEV %s\n", mci->mod_name, mci->ctl_name, edac_dev_name(mci));
  673. edac_mc_owner = mci->mod_name;
  674. mutex_unlock(&mem_ctls_mutex);
  675. return 0;
  676. fail1:
  677. del_mc_from_global_list(mci);
  678. fail0:
  679. mutex_unlock(&mem_ctls_mutex);
  680. return ret;
  681. }
  682. EXPORT_SYMBOL_GPL(edac_mc_add_mc);
  683. /**
  684. * edac_mc_del_mc: Remove sysfs entries for specified mci structure and
  685. * remove mci structure from global list
  686. * @pdev: Pointer to 'struct device' representing mci structure to remove.
  687. *
  688. * Return pointer to removed mci structure, or NULL if device not found.
  689. */
  690. struct mem_ctl_info *edac_mc_del_mc(struct device *dev)
  691. {
  692. struct mem_ctl_info *mci;
  693. edac_dbg(0, "\n");
  694. mutex_lock(&mem_ctls_mutex);
  695. /* find the requested mci struct in the global list */
  696. mci = find_mci_by_dev(dev);
  697. if (mci == NULL) {
  698. mutex_unlock(&mem_ctls_mutex);
  699. return NULL;
  700. }
  701. if (!del_mc_from_global_list(mci))
  702. edac_mc_owner = NULL;
  703. mutex_unlock(&mem_ctls_mutex);
  704. /* flush workq processes */
  705. edac_mc_workq_teardown(mci);
  706. /* marking MCI offline */
  707. mci->op_state = OP_OFFLINE;
  708. /* remove from sysfs */
  709. edac_remove_sysfs_mci_device(mci);
  710. edac_printk(KERN_INFO, EDAC_MC,
  711. "Removed device %d for %s %s: DEV %s\n", mci->mc_idx,
  712. mci->mod_name, mci->ctl_name, edac_dev_name(mci));
  713. return mci;
  714. }
  715. EXPORT_SYMBOL_GPL(edac_mc_del_mc);
  716. static void edac_mc_scrub_block(unsigned long page, unsigned long offset,
  717. u32 size)
  718. {
  719. struct page *pg;
  720. void *virt_addr;
  721. unsigned long flags = 0;
  722. edac_dbg(3, "\n");
  723. /* ECC error page was not in our memory. Ignore it. */
  724. if (!pfn_valid(page))
  725. return;
  726. /* Find the actual page structure then map it and fix */
  727. pg = pfn_to_page(page);
  728. if (PageHighMem(pg))
  729. local_irq_save(flags);
  730. virt_addr = kmap_atomic(pg);
  731. /* Perform architecture specific atomic scrub operation */
  732. atomic_scrub(virt_addr + offset, size);
  733. /* Unmap and complete */
  734. kunmap_atomic(virt_addr);
  735. if (PageHighMem(pg))
  736. local_irq_restore(flags);
  737. }
  738. /* FIXME - should return -1 */
  739. int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci, unsigned long page)
  740. {
  741. struct csrow_info **csrows = mci->csrows;
  742. int row, i, j, n;
  743. edac_dbg(1, "MC%d: 0x%lx\n", mci->mc_idx, page);
  744. row = -1;
  745. for (i = 0; i < mci->nr_csrows; i++) {
  746. struct csrow_info *csrow = csrows[i];
  747. n = 0;
  748. for (j = 0; j < csrow->nr_channels; j++) {
  749. struct dimm_info *dimm = csrow->channels[j]->dimm;
  750. n += dimm->nr_pages;
  751. }
  752. if (n == 0)
  753. continue;
  754. edac_dbg(3, "MC%d: first(0x%lx) page(0x%lx) last(0x%lx) mask(0x%lx)\n",
  755. mci->mc_idx,
  756. csrow->first_page, page, csrow->last_page,
  757. csrow->page_mask);
  758. if ((page >= csrow->first_page) &&
  759. (page <= csrow->last_page) &&
  760. ((page & csrow->page_mask) ==
  761. (csrow->first_page & csrow->page_mask))) {
  762. row = i;
  763. break;
  764. }
  765. }
  766. if (row == -1)
  767. edac_mc_printk(mci, KERN_ERR,
  768. "could not look up page error address %lx\n",
  769. (unsigned long)page);
  770. return row;
  771. }
  772. EXPORT_SYMBOL_GPL(edac_mc_find_csrow_by_page);
  773. const char *edac_layer_name[] = {
  774. [EDAC_MC_LAYER_BRANCH] = "branch",
  775. [EDAC_MC_LAYER_CHANNEL] = "channel",
  776. [EDAC_MC_LAYER_SLOT] = "slot",
  777. [EDAC_MC_LAYER_CHIP_SELECT] = "csrow",
  778. [EDAC_MC_LAYER_ALL_MEM] = "memory",
  779. };
  780. EXPORT_SYMBOL_GPL(edac_layer_name);
  781. static void edac_inc_ce_error(struct mem_ctl_info *mci,
  782. bool enable_per_layer_report,
  783. const int pos[EDAC_MAX_LAYERS],
  784. const u16 count)
  785. {
  786. int i, index = 0;
  787. mci->ce_mc += count;
  788. if (!enable_per_layer_report) {
  789. mci->ce_noinfo_count += count;
  790. return;
  791. }
  792. for (i = 0; i < mci->n_layers; i++) {
  793. if (pos[i] < 0)
  794. break;
  795. index += pos[i];
  796. mci->ce_per_layer[i][index] += count;
  797. if (i < mci->n_layers - 1)
  798. index *= mci->layers[i + 1].size;
  799. }
  800. }
  801. static void edac_inc_ue_error(struct mem_ctl_info *mci,
  802. bool enable_per_layer_report,
  803. const int pos[EDAC_MAX_LAYERS],
  804. const u16 count)
  805. {
  806. int i, index = 0;
  807. mci->ue_mc += count;
  808. if (!enable_per_layer_report) {
  809. mci->ce_noinfo_count += count;
  810. return;
  811. }
  812. for (i = 0; i < mci->n_layers; i++) {
  813. if (pos[i] < 0)
  814. break;
  815. index += pos[i];
  816. mci->ue_per_layer[i][index] += count;
  817. if (i < mci->n_layers - 1)
  818. index *= mci->layers[i + 1].size;
  819. }
  820. }
  821. static void edac_ce_error(struct mem_ctl_info *mci,
  822. const u16 error_count,
  823. const int pos[EDAC_MAX_LAYERS],
  824. const char *msg,
  825. const char *location,
  826. const char *label,
  827. const char *detail,
  828. const char *other_detail,
  829. const bool enable_per_layer_report,
  830. const unsigned long page_frame_number,
  831. const unsigned long offset_in_page,
  832. long grain)
  833. {
  834. unsigned long remapped_page;
  835. char *msg_aux = "";
  836. if (*msg)
  837. msg_aux = " ";
  838. if (edac_mc_get_log_ce()) {
  839. if (other_detail && *other_detail)
  840. edac_mc_printk(mci, KERN_WARNING,
  841. "%d CE %s%son %s (%s %s - %s)\n",
  842. error_count, msg, msg_aux, label,
  843. location, detail, other_detail);
  844. else
  845. edac_mc_printk(mci, KERN_WARNING,
  846. "%d CE %s%son %s (%s %s)\n",
  847. error_count, msg, msg_aux, label,
  848. location, detail);
  849. }
  850. edac_inc_ce_error(mci, enable_per_layer_report, pos, error_count);
  851. if (mci->scrub_mode & SCRUB_SW_SRC) {
  852. /*
  853. * Some memory controllers (called MCs below) can remap
  854. * memory so that it is still available at a different
  855. * address when PCI devices map into memory.
  856. * MC's that can't do this, lose the memory where PCI
  857. * devices are mapped. This mapping is MC-dependent
  858. * and so we call back into the MC driver for it to
  859. * map the MC page to a physical (CPU) page which can
  860. * then be mapped to a virtual page - which can then
  861. * be scrubbed.
  862. */
  863. remapped_page = mci->ctl_page_to_phys ?
  864. mci->ctl_page_to_phys(mci, page_frame_number) :
  865. page_frame_number;
  866. edac_mc_scrub_block(remapped_page,
  867. offset_in_page, grain);
  868. }
  869. }
  870. static void edac_ue_error(struct mem_ctl_info *mci,
  871. const u16 error_count,
  872. const int pos[EDAC_MAX_LAYERS],
  873. const char *msg,
  874. const char *location,
  875. const char *label,
  876. const char *detail,
  877. const char *other_detail,
  878. const bool enable_per_layer_report)
  879. {
  880. char *msg_aux = "";
  881. if (*msg)
  882. msg_aux = " ";
  883. if (edac_mc_get_log_ue()) {
  884. if (other_detail && *other_detail)
  885. edac_mc_printk(mci, KERN_WARNING,
  886. "%d UE %s%son %s (%s %s - %s)\n",
  887. error_count, msg, msg_aux, label,
  888. location, detail, other_detail);
  889. else
  890. edac_mc_printk(mci, KERN_WARNING,
  891. "%d UE %s%son %s (%s %s)\n",
  892. error_count, msg, msg_aux, label,
  893. location, detail);
  894. }
  895. if (edac_mc_get_panic_on_ue()) {
  896. if (other_detail && *other_detail)
  897. panic("UE %s%son %s (%s%s - %s)\n",
  898. msg, msg_aux, label, location, detail, other_detail);
  899. else
  900. panic("UE %s%son %s (%s%s)\n",
  901. msg, msg_aux, label, location, detail);
  902. }
  903. edac_inc_ue_error(mci, enable_per_layer_report, pos, error_count);
  904. }
  905. /**
  906. * edac_raw_mc_handle_error - reports a memory event to userspace without doing
  907. * anything to discover the error location
  908. *
  909. * @type: severity of the error (CE/UE/Fatal)
  910. * @mci: a struct mem_ctl_info pointer
  911. * @e: error description
  912. *
  913. * This raw function is used internally by edac_mc_handle_error(). It should
  914. * only be called directly when the hardware error come directly from BIOS,
  915. * like in the case of APEI GHES driver.
  916. */
  917. void edac_raw_mc_handle_error(const enum hw_event_mc_err_type type,
  918. struct mem_ctl_info *mci,
  919. struct edac_raw_error_desc *e)
  920. {
  921. char detail[80];
  922. int pos[EDAC_MAX_LAYERS] = { e->top_layer, e->mid_layer, e->low_layer };
  923. /* Memory type dependent details about the error */
  924. if (type == HW_EVENT_ERR_CORRECTED) {
  925. snprintf(detail, sizeof(detail),
  926. "page:0x%lx offset:0x%lx grain:%ld syndrome:0x%lx",
  927. e->page_frame_number, e->offset_in_page,
  928. e->grain, e->syndrome);
  929. edac_ce_error(mci, e->error_count, pos, e->msg, e->location, e->label,
  930. detail, e->other_detail, e->enable_per_layer_report,
  931. e->page_frame_number, e->offset_in_page, e->grain);
  932. } else {
  933. snprintf(detail, sizeof(detail),
  934. "page:0x%lx offset:0x%lx grain:%ld",
  935. e->page_frame_number, e->offset_in_page, e->grain);
  936. edac_ue_error(mci, e->error_count, pos, e->msg, e->location, e->label,
  937. detail, e->other_detail, e->enable_per_layer_report);
  938. }
  939. }
  940. EXPORT_SYMBOL_GPL(edac_raw_mc_handle_error);
  941. /**
  942. * edac_mc_handle_error - reports a memory event to userspace
  943. *
  944. * @type: severity of the error (CE/UE/Fatal)
  945. * @mci: a struct mem_ctl_info pointer
  946. * @error_count: Number of errors of the same type
  947. * @page_frame_number: mem page where the error occurred
  948. * @offset_in_page: offset of the error inside the page
  949. * @syndrome: ECC syndrome
  950. * @top_layer: Memory layer[0] position
  951. * @mid_layer: Memory layer[1] position
  952. * @low_layer: Memory layer[2] position
  953. * @msg: Message meaningful to the end users that
  954. * explains the event
  955. * @other_detail: Technical details about the event that
  956. * may help hardware manufacturers and
  957. * EDAC developers to analyse the event
  958. */
  959. void edac_mc_handle_error(const enum hw_event_mc_err_type type,
  960. struct mem_ctl_info *mci,
  961. const u16 error_count,
  962. const unsigned long page_frame_number,
  963. const unsigned long offset_in_page,
  964. const unsigned long syndrome,
  965. const int top_layer,
  966. const int mid_layer,
  967. const int low_layer,
  968. const char *msg,
  969. const char *other_detail)
  970. {
  971. char *p;
  972. int row = -1, chan = -1;
  973. int pos[EDAC_MAX_LAYERS] = { top_layer, mid_layer, low_layer };
  974. int i, n_labels = 0;
  975. u8 grain_bits;
  976. struct edac_raw_error_desc *e = &mci->error_desc;
  977. edac_dbg(3, "MC%d\n", mci->mc_idx);
  978. /* Fills the error report buffer */
  979. memset(e, 0, sizeof (*e));
  980. e->error_count = error_count;
  981. e->top_layer = top_layer;
  982. e->mid_layer = mid_layer;
  983. e->low_layer = low_layer;
  984. e->page_frame_number = page_frame_number;
  985. e->offset_in_page = offset_in_page;
  986. e->syndrome = syndrome;
  987. e->msg = msg;
  988. e->other_detail = other_detail;
  989. /*
  990. * Check if the event report is consistent and if the memory
  991. * location is known. If it is known, enable_per_layer_report will be
  992. * true, the DIMM(s) label info will be filled and the per-layer
  993. * error counters will be incremented.
  994. */
  995. for (i = 0; i < mci->n_layers; i++) {
  996. if (pos[i] >= (int)mci->layers[i].size) {
  997. edac_mc_printk(mci, KERN_ERR,
  998. "INTERNAL ERROR: %s value is out of range (%d >= %d)\n",
  999. edac_layer_name[mci->layers[i].type],
  1000. pos[i], mci->layers[i].size);
  1001. /*
  1002. * Instead of just returning it, let's use what's
  1003. * known about the error. The increment routines and
  1004. * the DIMM filter logic will do the right thing by
  1005. * pointing the likely damaged DIMMs.
  1006. */
  1007. pos[i] = -1;
  1008. }
  1009. if (pos[i] >= 0)
  1010. e->enable_per_layer_report = true;
  1011. }
  1012. /*
  1013. * Get the dimm label/grain that applies to the match criteria.
  1014. * As the error algorithm may not be able to point to just one memory
  1015. * stick, the logic here will get all possible labels that could
  1016. * pottentially be affected by the error.
  1017. * On FB-DIMM memory controllers, for uncorrected errors, it is common
  1018. * to have only the MC channel and the MC dimm (also called "branch")
  1019. * but the channel is not known, as the memory is arranged in pairs,
  1020. * where each memory belongs to a separate channel within the same
  1021. * branch.
  1022. */
  1023. p = e->label;
  1024. *p = '\0';
  1025. for (i = 0; i < mci->tot_dimms; i++) {
  1026. struct dimm_info *dimm = mci->dimms[i];
  1027. if (top_layer >= 0 && top_layer != dimm->location[0])
  1028. continue;
  1029. if (mid_layer >= 0 && mid_layer != dimm->location[1])
  1030. continue;
  1031. if (low_layer >= 0 && low_layer != dimm->location[2])
  1032. continue;
  1033. /* get the max grain, over the error match range */
  1034. if (dimm->grain > e->grain)
  1035. e->grain = dimm->grain;
  1036. /*
  1037. * If the error is memory-controller wide, there's no need to
  1038. * seek for the affected DIMMs because the whole
  1039. * channel/memory controller/... may be affected.
  1040. * Also, don't show errors for empty DIMM slots.
  1041. */
  1042. if (e->enable_per_layer_report && dimm->nr_pages) {
  1043. if (n_labels >= EDAC_MAX_LABELS) {
  1044. e->enable_per_layer_report = false;
  1045. break;
  1046. }
  1047. n_labels++;
  1048. if (p != e->label) {
  1049. strcpy(p, OTHER_LABEL);
  1050. p += strlen(OTHER_LABEL);
  1051. }
  1052. strcpy(p, dimm->label);
  1053. p += strlen(p);
  1054. *p = '\0';
  1055. /*
  1056. * get csrow/channel of the DIMM, in order to allow
  1057. * incrementing the compat API counters
  1058. */
  1059. edac_dbg(4, "%s csrows map: (%d,%d)\n",
  1060. mci->csbased ? "rank" : "dimm",
  1061. dimm->csrow, dimm->cschannel);
  1062. if (row == -1)
  1063. row = dimm->csrow;
  1064. else if (row >= 0 && row != dimm->csrow)
  1065. row = -2;
  1066. if (chan == -1)
  1067. chan = dimm->cschannel;
  1068. else if (chan >= 0 && chan != dimm->cschannel)
  1069. chan = -2;
  1070. }
  1071. }
  1072. if (!e->enable_per_layer_report) {
  1073. strcpy(e->label, "any memory");
  1074. } else {
  1075. edac_dbg(4, "csrow/channel to increment: (%d,%d)\n", row, chan);
  1076. if (p == e->label)
  1077. strcpy(e->label, "unknown memory");
  1078. if (type == HW_EVENT_ERR_CORRECTED) {
  1079. if (row >= 0) {
  1080. mci->csrows[row]->ce_count += error_count;
  1081. if (chan >= 0)
  1082. mci->csrows[row]->channels[chan]->ce_count += error_count;
  1083. }
  1084. } else
  1085. if (row >= 0)
  1086. mci->csrows[row]->ue_count += error_count;
  1087. }
  1088. /* Fill the RAM location data */
  1089. p = e->location;
  1090. for (i = 0; i < mci->n_layers; i++) {
  1091. if (pos[i] < 0)
  1092. continue;
  1093. p += sprintf(p, "%s:%d ",
  1094. edac_layer_name[mci->layers[i].type],
  1095. pos[i]);
  1096. }
  1097. if (p > e->location)
  1098. *(p - 1) = '\0';
  1099. /* Report the error via the trace interface */
  1100. grain_bits = fls_long(e->grain) + 1;
  1101. trace_mc_event(type, e->msg, e->label, e->error_count,
  1102. mci->mc_idx, e->top_layer, e->mid_layer, e->low_layer,
  1103. PAGES_TO_MiB(e->page_frame_number) | e->offset_in_page,
  1104. grain_bits, e->syndrome, e->other_detail);
  1105. edac_raw_mc_handle_error(type, mci, e);
  1106. }
  1107. EXPORT_SYMBOL_GPL(edac_mc_handle_error);