edac_device.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. /*
  2. * edac_device.c
  3. * (C) 2007 www.douglaskthompson.com
  4. *
  5. * This file may be distributed under the terms of the
  6. * GNU General Public License.
  7. *
  8. * Written by Doug Thompson <norsk5@xmission.com>
  9. *
  10. * edac_device API implementation
  11. * 19 Jan 2007
  12. */
  13. #include <linux/module.h>
  14. #include <linux/types.h>
  15. #include <linux/smp.h>
  16. #include <linux/init.h>
  17. #include <linux/sysctl.h>
  18. #include <linux/highmem.h>
  19. #include <linux/timer.h>
  20. #include <linux/slab.h>
  21. #include <linux/jiffies.h>
  22. #include <linux/spinlock.h>
  23. #include <linux/list.h>
  24. #include <linux/ctype.h>
  25. #include <linux/workqueue.h>
  26. #include <asm/uaccess.h>
  27. #include <asm/page.h>
  28. #include "edac_core.h"
  29. #include "edac_module.h"
  30. /* lock for the list: 'edac_device_list', manipulation of this list
  31. * is protected by the 'device_ctls_mutex' lock
  32. */
  33. static DEFINE_MUTEX(device_ctls_mutex);
  34. static LIST_HEAD(edac_device_list);
  35. #ifdef CONFIG_EDAC_DEBUG
  36. static void edac_device_dump_device(struct edac_device_ctl_info *edac_dev)
  37. {
  38. debugf3("\tedac_dev = %p dev_idx=%d \n", edac_dev, edac_dev->dev_idx);
  39. debugf4("\tedac_dev->edac_check = %p\n", edac_dev->edac_check);
  40. debugf3("\tdev = %p\n", edac_dev->dev);
  41. debugf3("\tmod_name:ctl_name = %s:%s\n",
  42. edac_dev->mod_name, edac_dev->ctl_name);
  43. debugf3("\tpvt_info = %p\n\n", edac_dev->pvt_info);
  44. }
  45. #endif /* CONFIG_EDAC_DEBUG */
  46. /*
  47. * edac_device_alloc_ctl_info()
  48. * Allocate a new edac device control info structure
  49. *
  50. * The control structure is allocated in complete chunk
  51. * from the OS. It is in turn sub allocated to the
  52. * various objects that compose the struture
  53. *
  54. * The structure has a 'nr_instance' array within itself.
  55. * Each instance represents a major component
  56. * Example: L1 cache and L2 cache are 2 instance components
  57. *
  58. * Within each instance is an array of 'nr_blocks' blockoffsets
  59. */
  60. struct edac_device_ctl_info *edac_device_alloc_ctl_info(
  61. unsigned sz_private,
  62. char *edac_device_name, unsigned nr_instances,
  63. char *edac_block_name, unsigned nr_blocks,
  64. unsigned offset_value, /* zero, 1, or other based offset */
  65. struct edac_dev_sysfs_block_attribute *attrib_spec, unsigned nr_attrib,
  66. int device_index)
  67. {
  68. struct edac_device_ctl_info *dev_ctl;
  69. struct edac_device_instance *dev_inst, *inst;
  70. struct edac_device_block *dev_blk, *blk_p, *blk;
  71. struct edac_dev_sysfs_block_attribute *dev_attrib, *attrib_p, *attrib;
  72. unsigned total_size;
  73. unsigned count;
  74. unsigned instance, block, attr;
  75. void *pvt;
  76. int err;
  77. debugf4("%s() instances=%d blocks=%d\n",
  78. __func__, nr_instances, nr_blocks);
  79. /* Calculate the size of memory we need to allocate AND
  80. * determine the offsets of the various item arrays
  81. * (instance,block,attrib) from the start of an allocated structure.
  82. * We want the alignment of each item (instance,block,attrib)
  83. * to be at least as stringent as what the compiler would
  84. * provide if we could simply hardcode everything into a single struct.
  85. */
  86. dev_ctl = (struct edac_device_ctl_info *)NULL;
  87. /* Calc the 'end' offset past end of ONE ctl_info structure
  88. * which will become the start of the 'instance' array
  89. */
  90. dev_inst = edac_align_ptr(&dev_ctl[1], sizeof(*dev_inst));
  91. /* Calc the 'end' offset past the instance array within the ctl_info
  92. * which will become the start of the block array
  93. */
  94. dev_blk = edac_align_ptr(&dev_inst[nr_instances], sizeof(*dev_blk));
  95. /* Calc the 'end' offset past the dev_blk array
  96. * which will become the start of the attrib array, if any.
  97. */
  98. count = nr_instances * nr_blocks;
  99. dev_attrib = edac_align_ptr(&dev_blk[count], sizeof(*dev_attrib));
  100. /* Check for case of when an attribute array is specified */
  101. if (nr_attrib > 0) {
  102. /* calc how many nr_attrib we need */
  103. count *= nr_attrib;
  104. /* Calc the 'end' offset past the attributes array */
  105. pvt = edac_align_ptr(&dev_attrib[count], sz_private);
  106. } else {
  107. /* no attribute array specificed */
  108. pvt = edac_align_ptr(dev_attrib, sz_private);
  109. }
  110. /* 'pvt' now points to where the private data area is.
  111. * At this point 'pvt' (like dev_inst,dev_blk and dev_attrib)
  112. * is baselined at ZERO
  113. */
  114. total_size = ((unsigned long)pvt) + sz_private;
  115. /* Allocate the amount of memory for the set of control structures */
  116. dev_ctl = kzalloc(total_size, GFP_KERNEL);
  117. if (dev_ctl == NULL)
  118. return NULL;
  119. /* Adjust pointers so they point within the actual memory we
  120. * just allocated rather than an imaginary chunk of memory
  121. * located at address 0.
  122. * 'dev_ctl' points to REAL memory, while the others are
  123. * ZERO based and thus need to be adjusted to point within
  124. * the allocated memory.
  125. */
  126. dev_inst = (struct edac_device_instance *)
  127. (((char *)dev_ctl) + ((unsigned long)dev_inst));
  128. dev_blk = (struct edac_device_block *)
  129. (((char *)dev_ctl) + ((unsigned long)dev_blk));
  130. dev_attrib = (struct edac_dev_sysfs_block_attribute *)
  131. (((char *)dev_ctl) + ((unsigned long)dev_attrib));
  132. pvt = sz_private ? (((char *)dev_ctl) + ((unsigned long)pvt)) : NULL;
  133. /* Begin storing the information into the control info structure */
  134. dev_ctl->dev_idx = device_index;
  135. dev_ctl->nr_instances = nr_instances;
  136. dev_ctl->instances = dev_inst;
  137. dev_ctl->pvt_info = pvt;
  138. /* Default logging of CEs and UEs */
  139. dev_ctl->log_ce = 1;
  140. dev_ctl->log_ue = 1;
  141. /* Name of this edac device */
  142. snprintf(dev_ctl->name,sizeof(dev_ctl->name),"%s",edac_device_name);
  143. debugf4("%s() edac_dev=%p next after end=%p\n",
  144. __func__, dev_ctl, pvt + sz_private );
  145. /* Initialize every Instance */
  146. for (instance = 0; instance < nr_instances; instance++) {
  147. inst = &dev_inst[instance];
  148. inst->ctl = dev_ctl;
  149. inst->nr_blocks = nr_blocks;
  150. blk_p = &dev_blk[instance * nr_blocks];
  151. inst->blocks = blk_p;
  152. /* name of this instance */
  153. snprintf(inst->name, sizeof(inst->name),
  154. "%s%u", edac_device_name, instance);
  155. /* Initialize every block in each instance */
  156. for (block = 0; block < nr_blocks; block++) {
  157. blk = &blk_p[block];
  158. blk->instance = inst;
  159. snprintf(blk->name, sizeof(blk->name),
  160. "%s%d", edac_block_name, block+offset_value);
  161. debugf4("%s() instance=%d inst_p=%p block=#%d "
  162. "block_p=%p name='%s'\n",
  163. __func__, instance, inst, block,
  164. blk, blk->name);
  165. /* if there are NO attributes OR no attribute pointer
  166. * then continue on to next block iteration
  167. */
  168. if ((nr_attrib == 0) || (attrib_spec == NULL))
  169. continue;
  170. /* setup the attribute array for this block */
  171. blk->nr_attribs = nr_attrib;
  172. attrib_p = &dev_attrib[block*nr_instances*nr_attrib];
  173. blk->block_attributes = attrib_p;
  174. debugf4("%s() THIS BLOCK_ATTRIB=%p\n",
  175. __func__, blk->block_attributes);
  176. /* Initialize every user specified attribute in this
  177. * block with the data the caller passed in
  178. * Each block gets its own copy of pointers,
  179. * and its unique 'value'
  180. */
  181. for (attr = 0; attr < nr_attrib; attr++) {
  182. attrib = &attrib_p[attr];
  183. /* populate the unique per attrib
  184. * with the code pointers and info
  185. */
  186. attrib->attr = attrib_spec[attr].attr;
  187. attrib->show = attrib_spec[attr].show;
  188. attrib->store = attrib_spec[attr].store;
  189. attrib->block = blk; /* up link */
  190. debugf4("%s() alloc-attrib=%p attrib_name='%s' "
  191. "attrib-spec=%p spec-name=%s\n",
  192. __func__, attrib, attrib->attr.name,
  193. &attrib_spec[attr],
  194. attrib_spec[attr].attr.name
  195. );
  196. }
  197. }
  198. }
  199. /* Mark this instance as merely ALLOCATED */
  200. dev_ctl->op_state = OP_ALLOC;
  201. /*
  202. * Initialize the 'root' kobj for the edac_device controller
  203. */
  204. err = edac_device_register_sysfs_main_kobj(dev_ctl);
  205. if (err) {
  206. kfree(dev_ctl);
  207. return NULL;
  208. }
  209. /* at this point, the root kobj is valid, and in order to
  210. * 'free' the object, then the function:
  211. * edac_device_unregister_sysfs_main_kobj() must be called
  212. * which will perform kobj unregistration and the actual free
  213. * will occur during the kobject callback operation
  214. */
  215. return dev_ctl;
  216. }
  217. EXPORT_SYMBOL_GPL(edac_device_alloc_ctl_info);
  218. /*
  219. * edac_device_free_ctl_info()
  220. * frees the memory allocated by the edac_device_alloc_ctl_info()
  221. * function
  222. */
  223. void edac_device_free_ctl_info(struct edac_device_ctl_info *ctl_info)
  224. {
  225. edac_device_unregister_sysfs_main_kobj(ctl_info);
  226. }
  227. EXPORT_SYMBOL_GPL(edac_device_free_ctl_info);
  228. /*
  229. * find_edac_device_by_dev
  230. * scans the edac_device list for a specific 'struct device *'
  231. *
  232. * lock to be held prior to call: device_ctls_mutex
  233. *
  234. * Return:
  235. * pointer to control structure managing 'dev'
  236. * NULL if not found on list
  237. */
  238. static struct edac_device_ctl_info *find_edac_device_by_dev(struct device *dev)
  239. {
  240. struct edac_device_ctl_info *edac_dev;
  241. struct list_head *item;
  242. debugf0("%s()\n", __func__);
  243. list_for_each(item, &edac_device_list) {
  244. edac_dev = list_entry(item, struct edac_device_ctl_info, link);
  245. if (edac_dev->dev == dev)
  246. return edac_dev;
  247. }
  248. return NULL;
  249. }
  250. /*
  251. * add_edac_dev_to_global_list
  252. * Before calling this function, caller must
  253. * assign a unique value to edac_dev->dev_idx.
  254. *
  255. * lock to be held prior to call: device_ctls_mutex
  256. *
  257. * Return:
  258. * 0 on success
  259. * 1 on failure.
  260. */
  261. static int add_edac_dev_to_global_list(struct edac_device_ctl_info *edac_dev)
  262. {
  263. struct list_head *item, *insert_before;
  264. struct edac_device_ctl_info *rover;
  265. insert_before = &edac_device_list;
  266. /* Determine if already on the list */
  267. rover = find_edac_device_by_dev(edac_dev->dev);
  268. if (unlikely(rover != NULL))
  269. goto fail0;
  270. /* Insert in ascending order by 'dev_idx', so find position */
  271. list_for_each(item, &edac_device_list) {
  272. rover = list_entry(item, struct edac_device_ctl_info, link);
  273. if (rover->dev_idx >= edac_dev->dev_idx) {
  274. if (unlikely(rover->dev_idx == edac_dev->dev_idx))
  275. goto fail1;
  276. insert_before = item;
  277. break;
  278. }
  279. }
  280. list_add_tail_rcu(&edac_dev->link, insert_before);
  281. return 0;
  282. fail0:
  283. edac_printk(KERN_WARNING, EDAC_MC,
  284. "%s (%s) %s %s already assigned %d\n",
  285. dev_name(rover->dev), edac_dev_name(rover),
  286. rover->mod_name, rover->ctl_name, rover->dev_idx);
  287. return 1;
  288. fail1:
  289. edac_printk(KERN_WARNING, EDAC_MC,
  290. "bug in low-level driver: attempt to assign\n"
  291. " duplicate dev_idx %d in %s()\n", rover->dev_idx,
  292. __func__);
  293. return 1;
  294. }
  295. /*
  296. * del_edac_device_from_global_list
  297. */
  298. static void del_edac_device_from_global_list(struct edac_device_ctl_info
  299. *edac_device)
  300. {
  301. list_del_rcu(&edac_device->link);
  302. /* these are for safe removal of devices from global list while
  303. * NMI handlers may be traversing list
  304. */
  305. synchronize_rcu();
  306. INIT_LIST_HEAD(&edac_device->link);
  307. }
  308. /*
  309. * edac_device_workq_function
  310. * performs the operation scheduled by a workq request
  311. *
  312. * this workq is embedded within an edac_device_ctl_info
  313. * structure, that needs to be polled for possible error events.
  314. *
  315. * This operation is to acquire the list mutex lock
  316. * (thus preventing insertation or deletion)
  317. * and then call the device's poll function IFF this device is
  318. * running polled and there is a poll function defined.
  319. */
  320. static void edac_device_workq_function(struct work_struct *work_req)
  321. {
  322. struct delayed_work *d_work = to_delayed_work(work_req);
  323. struct edac_device_ctl_info *edac_dev = to_edac_device_ctl_work(d_work);
  324. mutex_lock(&device_ctls_mutex);
  325. /* If we are being removed, bail out immediately */
  326. if (edac_dev->op_state == OP_OFFLINE) {
  327. mutex_unlock(&device_ctls_mutex);
  328. return;
  329. }
  330. /* Only poll controllers that are running polled and have a check */
  331. if ((edac_dev->op_state == OP_RUNNING_POLL) &&
  332. (edac_dev->edac_check != NULL)) {
  333. edac_dev->edac_check(edac_dev);
  334. }
  335. mutex_unlock(&device_ctls_mutex);
  336. /* Reschedule the workq for the next time period to start again
  337. * if the number of msec is for 1 sec, then adjust to the next
  338. * whole one second to save timers fireing all over the period
  339. * between integral seconds
  340. */
  341. if (edac_dev->poll_msec == 1000)
  342. queue_delayed_work(edac_workqueue, &edac_dev->work,
  343. round_jiffies_relative(edac_dev->delay));
  344. else
  345. queue_delayed_work(edac_workqueue, &edac_dev->work,
  346. edac_dev->delay);
  347. }
  348. /*
  349. * edac_device_workq_setup
  350. * initialize a workq item for this edac_device instance
  351. * passing in the new delay period in msec
  352. */
  353. void edac_device_workq_setup(struct edac_device_ctl_info *edac_dev,
  354. unsigned msec)
  355. {
  356. debugf0("%s()\n", __func__);
  357. /* take the arg 'msec' and set it into the control structure
  358. * to used in the time period calculation
  359. * then calc the number of jiffies that represents
  360. */
  361. edac_dev->poll_msec = msec;
  362. edac_dev->delay = msecs_to_jiffies(msec);
  363. INIT_DELAYED_WORK(&edac_dev->work, edac_device_workq_function);
  364. /* optimize here for the 1 second case, which will be normal value, to
  365. * fire ON the 1 second time event. This helps reduce all sorts of
  366. * timers firing on sub-second basis, while they are happy
  367. * to fire together on the 1 second exactly
  368. */
  369. if (edac_dev->poll_msec == 1000)
  370. queue_delayed_work(edac_workqueue, &edac_dev->work,
  371. round_jiffies_relative(edac_dev->delay));
  372. else
  373. queue_delayed_work(edac_workqueue, &edac_dev->work,
  374. edac_dev->delay);
  375. }
  376. /*
  377. * edac_device_workq_teardown
  378. * stop the workq processing on this edac_dev
  379. */
  380. void edac_device_workq_teardown(struct edac_device_ctl_info *edac_dev)
  381. {
  382. int status;
  383. status = cancel_delayed_work(&edac_dev->work);
  384. if (status == 0) {
  385. /* workq instance might be running, wait for it */
  386. flush_workqueue(edac_workqueue);
  387. }
  388. }
  389. /*
  390. * edac_device_reset_delay_period
  391. *
  392. * need to stop any outstanding workq queued up at this time
  393. * because we will be resetting the sleep time.
  394. * Then restart the workq on the new delay
  395. */
  396. void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
  397. unsigned long value)
  398. {
  399. /* cancel the current workq request, without the mutex lock */
  400. edac_device_workq_teardown(edac_dev);
  401. /* acquire the mutex before doing the workq setup */
  402. mutex_lock(&device_ctls_mutex);
  403. /* restart the workq request, with new delay value */
  404. edac_device_workq_setup(edac_dev, value);
  405. mutex_unlock(&device_ctls_mutex);
  406. }
  407. /*
  408. * edac_device_alloc_index: Allocate a unique device index number
  409. *
  410. * Return:
  411. * allocated index number
  412. */
  413. int edac_device_alloc_index(void)
  414. {
  415. static atomic_t device_indexes = ATOMIC_INIT(0);
  416. return atomic_inc_return(&device_indexes) - 1;
  417. }
  418. EXPORT_SYMBOL_GPL(edac_device_alloc_index);
  419. /**
  420. * edac_device_add_device: Insert the 'edac_dev' structure into the
  421. * edac_device global list and create sysfs entries associated with
  422. * edac_device structure.
  423. * @edac_device: pointer to the edac_device structure to be added to the list
  424. * 'edac_device' structure.
  425. *
  426. * Return:
  427. * 0 Success
  428. * !0 Failure
  429. */
  430. int edac_device_add_device(struct edac_device_ctl_info *edac_dev)
  431. {
  432. debugf0("%s()\n", __func__);
  433. #ifdef CONFIG_EDAC_DEBUG
  434. if (edac_debug_level >= 3)
  435. edac_device_dump_device(edac_dev);
  436. #endif
  437. mutex_lock(&device_ctls_mutex);
  438. if (add_edac_dev_to_global_list(edac_dev))
  439. goto fail0;
  440. /* set load time so that error rate can be tracked */
  441. edac_dev->start_time = jiffies;
  442. /* create this instance's sysfs entries */
  443. if (edac_device_create_sysfs(edac_dev)) {
  444. edac_device_printk(edac_dev, KERN_WARNING,
  445. "failed to create sysfs device\n");
  446. goto fail1;
  447. }
  448. /* If there IS a check routine, then we are running POLLED */
  449. if (edac_dev->edac_check != NULL) {
  450. /* This instance is NOW RUNNING */
  451. edac_dev->op_state = OP_RUNNING_POLL;
  452. /*
  453. * enable workq processing on this instance,
  454. * default = 1000 msec
  455. */
  456. edac_device_workq_setup(edac_dev, 1000);
  457. } else {
  458. edac_dev->op_state = OP_RUNNING_INTERRUPT;
  459. }
  460. /* Report action taken */
  461. edac_device_printk(edac_dev, KERN_INFO,
  462. "Giving out device to module '%s' controller "
  463. "'%s': DEV '%s' (%s)\n",
  464. edac_dev->mod_name,
  465. edac_dev->ctl_name,
  466. edac_dev_name(edac_dev),
  467. edac_op_state_to_string(edac_dev->op_state));
  468. mutex_unlock(&device_ctls_mutex);
  469. return 0;
  470. fail1:
  471. /* Some error, so remove the entry from the lsit */
  472. del_edac_device_from_global_list(edac_dev);
  473. fail0:
  474. mutex_unlock(&device_ctls_mutex);
  475. return 1;
  476. }
  477. EXPORT_SYMBOL_GPL(edac_device_add_device);
  478. /**
  479. * edac_device_del_device:
  480. * Remove sysfs entries for specified edac_device structure and
  481. * then remove edac_device structure from global list
  482. *
  483. * @pdev:
  484. * Pointer to 'struct device' representing edac_device
  485. * structure to remove.
  486. *
  487. * Return:
  488. * Pointer to removed edac_device structure,
  489. * OR NULL if device not found.
  490. */
  491. struct edac_device_ctl_info *edac_device_del_device(struct device *dev)
  492. {
  493. struct edac_device_ctl_info *edac_dev;
  494. debugf0("%s()\n", __func__);
  495. mutex_lock(&device_ctls_mutex);
  496. /* Find the structure on the list, if not there, then leave */
  497. edac_dev = find_edac_device_by_dev(dev);
  498. if (edac_dev == NULL) {
  499. mutex_unlock(&device_ctls_mutex);
  500. return NULL;
  501. }
  502. /* mark this instance as OFFLINE */
  503. edac_dev->op_state = OP_OFFLINE;
  504. /* deregister from global list */
  505. del_edac_device_from_global_list(edac_dev);
  506. mutex_unlock(&device_ctls_mutex);
  507. /* clear workq processing on this instance */
  508. edac_device_workq_teardown(edac_dev);
  509. /* Tear down the sysfs entries for this instance */
  510. edac_device_remove_sysfs(edac_dev);
  511. edac_printk(KERN_INFO, EDAC_MC,
  512. "Removed device %d for %s %s: DEV %s\n",
  513. edac_dev->dev_idx,
  514. edac_dev->mod_name, edac_dev->ctl_name, edac_dev_name(edac_dev));
  515. return edac_dev;
  516. }
  517. EXPORT_SYMBOL_GPL(edac_device_del_device);
  518. static inline int edac_device_get_log_ce(struct edac_device_ctl_info *edac_dev)
  519. {
  520. return edac_dev->log_ce;
  521. }
  522. static inline int edac_device_get_log_ue(struct edac_device_ctl_info *edac_dev)
  523. {
  524. return edac_dev->log_ue;
  525. }
  526. static inline int edac_device_get_panic_on_ue(struct edac_device_ctl_info
  527. *edac_dev)
  528. {
  529. return edac_dev->panic_on_ue;
  530. }
  531. /*
  532. * edac_device_handle_ce
  533. * perform a common output and handling of an 'edac_dev' CE event
  534. */
  535. void edac_device_handle_ce(struct edac_device_ctl_info *edac_dev,
  536. int inst_nr, int block_nr, const char *msg)
  537. {
  538. struct edac_device_instance *instance;
  539. struct edac_device_block *block = NULL;
  540. if ((inst_nr >= edac_dev->nr_instances) || (inst_nr < 0)) {
  541. edac_device_printk(edac_dev, KERN_ERR,
  542. "INTERNAL ERROR: 'instance' out of range "
  543. "(%d >= %d)\n", inst_nr,
  544. edac_dev->nr_instances);
  545. return;
  546. }
  547. instance = edac_dev->instances + inst_nr;
  548. if ((block_nr >= instance->nr_blocks) || (block_nr < 0)) {
  549. edac_device_printk(edac_dev, KERN_ERR,
  550. "INTERNAL ERROR: instance %d 'block' "
  551. "out of range (%d >= %d)\n",
  552. inst_nr, block_nr,
  553. instance->nr_blocks);
  554. return;
  555. }
  556. if (instance->nr_blocks > 0) {
  557. block = instance->blocks + block_nr;
  558. block->counters.ce_count++;
  559. }
  560. /* Propagate the count up the 'totals' tree */
  561. instance->counters.ce_count++;
  562. edac_dev->counters.ce_count++;
  563. if (edac_device_get_log_ce(edac_dev))
  564. edac_device_printk(edac_dev, KERN_WARNING,
  565. "CE: %s instance: %s block: %s '%s'\n",
  566. edac_dev->ctl_name, instance->name,
  567. block ? block->name : "N/A", msg);
  568. }
  569. EXPORT_SYMBOL_GPL(edac_device_handle_ce);
  570. /*
  571. * edac_device_handle_ue
  572. * perform a common output and handling of an 'edac_dev' UE event
  573. */
  574. void edac_device_handle_ue(struct edac_device_ctl_info *edac_dev,
  575. int inst_nr, int block_nr, const char *msg)
  576. {
  577. struct edac_device_instance *instance;
  578. struct edac_device_block *block = NULL;
  579. if ((inst_nr >= edac_dev->nr_instances) || (inst_nr < 0)) {
  580. edac_device_printk(edac_dev, KERN_ERR,
  581. "INTERNAL ERROR: 'instance' out of range "
  582. "(%d >= %d)\n", inst_nr,
  583. edac_dev->nr_instances);
  584. return;
  585. }
  586. instance = edac_dev->instances + inst_nr;
  587. if ((block_nr >= instance->nr_blocks) || (block_nr < 0)) {
  588. edac_device_printk(edac_dev, KERN_ERR,
  589. "INTERNAL ERROR: instance %d 'block' "
  590. "out of range (%d >= %d)\n",
  591. inst_nr, block_nr,
  592. instance->nr_blocks);
  593. return;
  594. }
  595. if (instance->nr_blocks > 0) {
  596. block = instance->blocks + block_nr;
  597. block->counters.ue_count++;
  598. }
  599. /* Propagate the count up the 'totals' tree */
  600. instance->counters.ue_count++;
  601. edac_dev->counters.ue_count++;
  602. if (edac_device_get_log_ue(edac_dev))
  603. edac_device_printk(edac_dev, KERN_EMERG,
  604. "UE: %s instance: %s block: %s '%s'\n",
  605. edac_dev->ctl_name, instance->name,
  606. block ? block->name : "N/A", msg);
  607. if (edac_device_get_panic_on_ue(edac_dev))
  608. panic("EDAC %s: UE instance: %s block %s '%s'\n",
  609. edac_dev->ctl_name, instance->name,
  610. block ? block->name : "N/A", msg);
  611. }
  612. EXPORT_SYMBOL_GPL(edac_device_handle_ue);