1 // SPDX-License-Identifier: GPL-2.0
3 * Channel report handling code
5 * Copyright IBM Corp. 2000, 2009
6 * Author(s): Ingo Adlung <adlung@de.ibm.com>,
7 * Martin Schwidefsky <schwidefsky@de.ibm.com>,
8 * Cornelia Huck <cornelia.huck@de.ibm.com>,
11 #include <linux/mutex.h>
12 #include <linux/kthread.h>
13 #include <linux/init.h>
14 #include <linux/wait.h>
15 #include <asm/ctlreg.h>
19 static DEFINE_MUTEX(crw_handler_mutex
);
20 static crw_handler_t crw_handlers
[NR_RSCS
];
21 static atomic_t crw_nr_req
= ATOMIC_INIT(0);
22 static DECLARE_WAIT_QUEUE_HEAD(crw_handler_wait_q
);
25 * crw_register_handler() - register a channel report word handler
26 * @rsc: reporting source code to handle
27 * @handler: handler to be registered
29 * Returns %0 on success and a negative error value otherwise.
31 int crw_register_handler(int rsc
, crw_handler_t handler
)
35 if ((rsc
< 0) || (rsc
>= NR_RSCS
))
37 mutex_lock(&crw_handler_mutex
);
38 if (crw_handlers
[rsc
])
41 crw_handlers
[rsc
] = handler
;
42 mutex_unlock(&crw_handler_mutex
);
47 * crw_unregister_handler() - unregister a channel report word handler
48 * @rsc: reporting source code to handle
50 void crw_unregister_handler(int rsc
)
52 if ((rsc
< 0) || (rsc
>= NR_RSCS
))
54 mutex_lock(&crw_handler_mutex
);
55 crw_handlers
[rsc
] = NULL
;
56 mutex_unlock(&crw_handler_mutex
);
60 * Retrieve CRWs and call function to handle event.
62 static int crw_collect_info(void *unused
)
69 signal
= wait_event_interruptible(crw_handler_wait_q
,
70 atomic_read(&crw_nr_req
) > 0);
72 atomic_inc(&crw_nr_req
);
75 crw_handler_t handler
;
77 if (unlikely(chain
> 1)) {
80 printk(KERN_WARNING
"%s: Code does not support more "
81 "than two chained crws; please report to "
82 "linux390@de.ibm.com!\n", __func__
);
83 ccode
= stcrw(&tmp_crw
);
84 printk(KERN_WARNING
"%s: crw reports slct=%d, oflw=%d, "
85 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
86 __func__
, tmp_crw
.slct
, tmp_crw
.oflw
,
87 tmp_crw
.chn
, tmp_crw
.rsc
, tmp_crw
.anc
,
88 tmp_crw
.erc
, tmp_crw
.rsid
);
89 printk(KERN_WARNING
"%s: This was crw number %x in the "
90 "chain\n", __func__
, chain
);
93 chain
= tmp_crw
.chn
? chain
+ 1 : 0;
96 ccode
= stcrw(&crw
[chain
]);
99 printk(KERN_DEBUG
"crw_info : CRW reports slct=%d, oflw=%d, "
100 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
101 crw
[chain
].slct
, crw
[chain
].oflw
, crw
[chain
].chn
,
102 crw
[chain
].rsc
, crw
[chain
].anc
, crw
[chain
].erc
,
104 /* Check for overflows. */
105 if (crw
[chain
].oflw
) {
108 pr_debug("%s: crw overflow detected!\n", __func__
);
109 mutex_lock(&crw_handler_mutex
);
110 for (i
= 0; i
< NR_RSCS
; i
++) {
112 crw_handlers
[i
](NULL
, NULL
, 1);
114 mutex_unlock(&crw_handler_mutex
);
118 if (crw
[0].chn
&& !chain
) {
122 mutex_lock(&crw_handler_mutex
);
123 handler
= crw_handlers
[crw
[chain
].rsc
];
125 handler(&crw
[0], chain
? &crw
[1] : NULL
, 0);
126 mutex_unlock(&crw_handler_mutex
);
127 /* chain is always 0 or 1 here. */
128 chain
= crw
[chain
].chn
? chain
+ 1 : 0;
130 if (atomic_dec_and_test(&crw_nr_req
))
131 wake_up(&crw_handler_wait_q
);
136 void crw_handle_channel_report(void)
138 atomic_inc(&crw_nr_req
);
139 wake_up(&crw_handler_wait_q
);
142 void crw_wait_for_channel_report(void)
144 crw_handle_channel_report();
145 wait_event(crw_handler_wait_q
, atomic_read(&crw_nr_req
) == 0);
149 * Machine checks for the channel subsystem must be enabled
150 * after the channel subsystem is initialized
152 static int __init
crw_machine_check_init(void)
154 struct task_struct
*task
;
156 task
= kthread_run(crw_collect_info
, NULL
, "kmcheck");
158 return PTR_ERR(task
);
159 system_ctl_set_bit(14, CR14_CHANNEL_REPORT_SUBMASK_BIT
);
162 device_initcall(crw_machine_check_init
);