2 * Channel report handling code
4 * Copyright IBM Corp. 2000,2009
5 * Author(s): Ingo Adlung <adlung@de.ibm.com>,
6 * Martin Schwidefsky <schwidefsky@de.ibm.com>,
7 * Cornelia Huck <cornelia.huck@de.ibm.com>,
8 * Heiko Carstens <heiko.carstens@de.ibm.com>,
11 #include <linux/semaphore.h>
12 #include <linux/mutex.h>
13 #include <linux/kthread.h>
14 #include <linux/init.h>
17 static struct semaphore crw_semaphore
;
18 static DEFINE_MUTEX(crw_handler_mutex
);
19 static crw_handler_t crw_handlers
[NR_RSCS
];
22 * crw_register_handler() - register a channel report word handler
23 * @rsc: reporting source code to handle
24 * @handler: handler to be registered
26 * Returns %0 on success and a negative error value otherwise.
28 int crw_register_handler(int rsc
, crw_handler_t handler
)
32 if ((rsc
< 0) || (rsc
>= NR_RSCS
))
34 mutex_lock(&crw_handler_mutex
);
35 if (crw_handlers
[rsc
])
38 crw_handlers
[rsc
] = handler
;
39 mutex_unlock(&crw_handler_mutex
);
44 * crw_unregister_handler() - unregister a channel report word handler
45 * @rsc: reporting source code to handle
47 void crw_unregister_handler(int rsc
)
49 if ((rsc
< 0) || (rsc
>= NR_RSCS
))
51 mutex_lock(&crw_handler_mutex
);
52 crw_handlers
[rsc
] = NULL
;
53 mutex_unlock(&crw_handler_mutex
);
57 * Retrieve CRWs and call function to handle event.
59 static int crw_collect_info(void *unused
)
67 ignore
= down_interruptible(&crw_semaphore
);
70 crw_handler_t handler
;
72 if (unlikely(chain
> 1)) {
75 printk(KERN_WARNING
"%s: Code does not support more "
76 "than two chained crws; please report to "
77 "linux390@de.ibm.com!\n", __func__
);
78 ccode
= stcrw(&tmp_crw
);
79 printk(KERN_WARNING
"%s: crw reports slct=%d, oflw=%d, "
80 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
81 __func__
, tmp_crw
.slct
, tmp_crw
.oflw
,
82 tmp_crw
.chn
, tmp_crw
.rsc
, tmp_crw
.anc
,
83 tmp_crw
.erc
, tmp_crw
.rsid
);
84 printk(KERN_WARNING
"%s: This was crw number %x in the "
85 "chain\n", __func__
, chain
);
88 chain
= tmp_crw
.chn
? chain
+ 1 : 0;
91 ccode
= stcrw(&crw
[chain
]);
94 printk(KERN_DEBUG
"crw_info : CRW reports slct=%d, oflw=%d, "
95 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
96 crw
[chain
].slct
, crw
[chain
].oflw
, crw
[chain
].chn
,
97 crw
[chain
].rsc
, crw
[chain
].anc
, crw
[chain
].erc
,
99 /* Check for overflows. */
100 if (crw
[chain
].oflw
) {
103 pr_debug("%s: crw overflow detected!\n", __func__
);
104 mutex_lock(&crw_handler_mutex
);
105 for (i
= 0; i
< NR_RSCS
; i
++) {
107 crw_handlers
[i
](NULL
, NULL
, 1);
109 mutex_unlock(&crw_handler_mutex
);
113 if (crw
[0].chn
&& !chain
) {
117 mutex_lock(&crw_handler_mutex
);
118 handler
= crw_handlers
[crw
[chain
].rsc
];
120 handler(&crw
[0], chain
? &crw
[1] : NULL
, 0);
121 mutex_unlock(&crw_handler_mutex
);
122 /* chain is always 0 or 1 here. */
123 chain
= crw
[chain
].chn
? chain
+ 1 : 0;
129 void crw_handle_channel_report(void)
135 * Separate initcall needed for semaphore initialization since
136 * crw_handle_channel_report might be called before crw_machine_check_init.
138 static int __init
crw_init_semaphore(void)
140 init_MUTEX_LOCKED(&crw_semaphore
);
143 pure_initcall(crw_init_semaphore
);
146 * Machine checks for the channel subsystem must be enabled
147 * after the channel subsystem is initialized
149 static int __init
crw_machine_check_init(void)
151 struct task_struct
*task
;
153 task
= kthread_run(crw_collect_info
, NULL
, "kmcheck");
155 return PTR_ERR(task
);
156 ctl_set_bit(14, 28); /* enable channel report MCH */
159 device_initcall(crw_machine_check_init
);