1 // SPDX-License-Identifier: GPL-2.0
3 * Channel report handling code
5 * Copyright IBM Corp. 2000, 2009
12 #include <linux/mutex.h>
13 #include <linux/kthread.h>
14 #include <linux/init.h>
15 #include <linux/wait.h>
17 #include <asm/ctl_reg.h>
20 static DEFINE_MUTEX(crw_handler_mutex);
21 static crw_handler_t crw_handlers[NR_RSCS];
22 static atomic_t crw_nr_req = ATOMIC_INIT(0);
23 static DECLARE_WAIT_QUEUE_HEAD(crw_handler_wait_q);
26 * crw_register_handler() - register a channel report word handler
27 * @rsc: reporting source code to handle
28 * @handler: handler to be registered
30 * Returns %0 on success and a negative error value otherwise.
32 int crw_register_handler(int rsc, crw_handler_t handler)
36 if ((rsc < 0) || (rsc >= NR_RSCS))
38 mutex_lock(&crw_handler_mutex);
39 if (crw_handlers[rsc])
42 crw_handlers[rsc] = handler;
43 mutex_unlock(&crw_handler_mutex);
48 * crw_unregister_handler() - unregister a channel report word handler
49 * @rsc: reporting source code to handle
51 void crw_unregister_handler(int rsc)
53 if ((rsc < 0) || (rsc >= NR_RSCS))
55 mutex_lock(&crw_handler_mutex);
56 crw_handlers[rsc] = NULL;
57 mutex_unlock(&crw_handler_mutex);
61 * Retrieve CRWs and call function to handle event.
63 static int crw_collect_info(void *unused)
70 signal = wait_event_interruptible(crw_handler_wait_q,
71 atomic_read(&crw_nr_req) > 0);
73 atomic_inc(&crw_nr_req);
76 crw_handler_t handler;
78 if (unlikely(chain > 1)) {
81 printk(KERN_WARNING"%s: Code does not support more "
82 "than two chained crws; please report to "
84 ccode = stcrw(&tmp_crw);
85 printk(KERN_WARNING"%s: crw reports slct=%d, oflw=%d, "
86 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
87 __func__, tmp_crw.slct, tmp_crw.oflw,
88 tmp_crw.chn, tmp_crw.rsc, tmp_crw.anc,
89 tmp_crw.erc, tmp_crw.rsid);
90 printk(KERN_WARNING"%s: This was crw number %x in the "
91 "chain\n", __func__, chain);
94 chain = tmp_crw.chn ? chain + 1 : 0;
97 ccode = stcrw(&crw[chain]);
100 printk(KERN_DEBUG "crw_info : CRW reports slct=%d, oflw=%d, "
101 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
102 crw[chain].slct, crw[chain].oflw, crw[chain].chn,
103 crw[chain].rsc, crw[chain].anc, crw[chain].erc,
105 /* Check for overflows. */
106 if (crw[chain].oflw) {
109 pr_debug("%s: crw overflow detected!\n", __func__);
110 mutex_lock(&crw_handler_mutex);
111 for (i = 0; i < NR_RSCS; i++) {
113 crw_handlers[i](NULL, NULL, 1);
115 mutex_unlock(&crw_handler_mutex);
119 if (crw[0].chn && !chain) {
123 mutex_lock(&crw_handler_mutex);
124 handler = crw_handlers[crw[chain].rsc];
126 handler(&crw[0], chain ? &crw[1] : NULL, 0);
127 mutex_unlock(&crw_handler_mutex);
128 /* chain is always 0 or 1 here. */
129 chain = crw[chain].chn ? chain + 1 : 0;
131 if (atomic_dec_and_test(&crw_nr_req))
132 wake_up(&crw_handler_wait_q);
137 void crw_handle_channel_report(void)
139 atomic_inc(&crw_nr_req);
140 wake_up(&crw_handler_wait_q);
143 void crw_wait_for_channel_report(void)
145 crw_handle_channel_report();
146 wait_event(crw_handler_wait_q, atomic_read(&crw_nr_req) == 0);
150 * Machine checks for the channel subsystem must be enabled
151 * after the channel subsystem is initialized
153 static int __init crw_machine_check_init(void)
155 struct task_struct *task;
157 task = kthread_run(crw_collect_info, NULL, "kmcheck");
159 return PTR_ERR(task);
160 ctl_set_bit(14, 28); /* enable channel report MCH */
163 device_initcall(crw_machine_check_init);