^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Channel report handling code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright IBM Corp. 2000, 2009
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Author(s): Ingo Adlung <adlung@de.ibm.com>,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Martin Schwidefsky <schwidefsky@de.ibm.com>,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Cornelia Huck <cornelia.huck@de.ibm.com>,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Heiko Carstens <heiko.carstens@de.ibm.com>,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <asm/crw.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <asm/ctl_reg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "ioasm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) static DEFINE_MUTEX(crw_handler_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static crw_handler_t crw_handlers[NR_RSCS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static atomic_t crw_nr_req = ATOMIC_INIT(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static DECLARE_WAIT_QUEUE_HEAD(crw_handler_wait_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * crw_register_handler() - register a channel report word handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * @rsc: reporting source code to handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * @handler: handler to be registered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * Returns %0 on success and a negative error value otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) int crw_register_handler(int rsc, crw_handler_t handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) if ((rsc < 0) || (rsc >= NR_RSCS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) mutex_lock(&crw_handler_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) if (crw_handlers[rsc])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) rc = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) crw_handlers[rsc] = handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) mutex_unlock(&crw_handler_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * crw_unregister_handler() - unregister a channel report word handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * @rsc: reporting source code to handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) void crw_unregister_handler(int rsc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if ((rsc < 0) || (rsc >= NR_RSCS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) mutex_lock(&crw_handler_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) crw_handlers[rsc] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) mutex_unlock(&crw_handler_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * Retrieve CRWs and call function to handle event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static int crw_collect_info(void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct crw crw[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) int ccode, signal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) unsigned int chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) repeat:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) signal = wait_event_interruptible(crw_handler_wait_q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) atomic_read(&crw_nr_req) > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if (unlikely(signal))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) atomic_inc(&crw_nr_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) chain = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) crw_handler_t handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (unlikely(chain > 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct crw tmp_crw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) printk(KERN_WARNING"%s: Code does not support more "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) "than two chained crws; please report to "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) "linux390@de.ibm.com!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) ccode = stcrw(&tmp_crw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) printk(KERN_WARNING"%s: crw reports slct=%d, oflw=%d, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) __func__, tmp_crw.slct, tmp_crw.oflw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) tmp_crw.chn, tmp_crw.rsc, tmp_crw.anc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) tmp_crw.erc, tmp_crw.rsid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) printk(KERN_WARNING"%s: This was crw number %x in the "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) "chain\n", __func__, chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (ccode != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) chain = tmp_crw.chn ? chain + 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) ccode = stcrw(&crw[chain]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if (ccode != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) printk(KERN_DEBUG "crw_info : CRW reports slct=%d, oflw=%d, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) crw[chain].slct, crw[chain].oflw, crw[chain].chn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) crw[chain].rsc, crw[chain].anc, crw[chain].erc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) crw[chain].rsid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /* Check for overflows. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if (crw[chain].oflw) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) pr_debug("%s: crw overflow detected!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) mutex_lock(&crw_handler_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) for (i = 0; i < NR_RSCS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (crw_handlers[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) crw_handlers[i](NULL, NULL, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) mutex_unlock(&crw_handler_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) chain = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if (crw[0].chn && !chain) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) chain++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) mutex_lock(&crw_handler_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) handler = crw_handlers[crw[chain].rsc];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) handler(&crw[0], chain ? &crw[1] : NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) mutex_unlock(&crw_handler_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /* chain is always 0 or 1 here. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) chain = crw[chain].chn ? chain + 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) if (atomic_dec_and_test(&crw_nr_req))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) wake_up(&crw_handler_wait_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) goto repeat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) void crw_handle_channel_report(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) atomic_inc(&crw_nr_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) wake_up(&crw_handler_wait_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) void crw_wait_for_channel_report(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) crw_handle_channel_report();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) wait_event(crw_handler_wait_q, atomic_read(&crw_nr_req) == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * Machine checks for the channel subsystem must be enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * after the channel subsystem is initialized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static int __init crw_machine_check_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct task_struct *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) task = kthread_run(crw_collect_info, NULL, "kmcheck");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if (IS_ERR(task))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) return PTR_ERR(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) ctl_set_bit(14, 28); /* enable channel report MCH */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) device_initcall(crw_machine_check_init);