tcp: tsq: add shortcut in tcp_tasklet_func()
[linux-2.6/btrfs-unstable.git] / drivers / s390 / cio / crw.c
blob3d3cd402b37680d363589c92dfb45bcf917cc815
1 /*
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>,
9 */
11 #include <linux/mutex.h>
12 #include <linux/kthread.h>
13 #include <linux/init.h>
14 #include <linux/wait.h>
15 #include <asm/crw.h>
16 #include <asm/ctl_reg.h>
17 #include "ioasm.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);
24 /**
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)
33 int rc = 0;
35 if ((rsc < 0) || (rsc >= NR_RSCS))
36 return -EINVAL;
37 mutex_lock(&crw_handler_mutex);
38 if (crw_handlers[rsc])
39 rc = -EBUSY;
40 else
41 crw_handlers[rsc] = handler;
42 mutex_unlock(&crw_handler_mutex);
43 return rc;
46 /**
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))
53 return;
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)
64 struct crw crw[2];
65 int ccode, signal;
66 unsigned int chain;
68 repeat:
69 signal = wait_event_interruptible(crw_handler_wait_q,
70 atomic_read(&crw_nr_req) > 0);
71 if (unlikely(signal))
72 atomic_inc(&crw_nr_req);
73 chain = 0;
74 while (1) {
75 crw_handler_t handler;
77 if (unlikely(chain > 1)) {
78 struct crw tmp_crw;
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);
91 if (ccode != 0)
92 break;
93 chain = tmp_crw.chn ? chain + 1 : 0;
94 continue;
96 ccode = stcrw(&crw[chain]);
97 if (ccode != 0)
98 break;
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,
103 crw[chain].rsid);
104 /* Check for overflows. */
105 if (crw[chain].oflw) {
106 int i;
108 pr_debug("%s: crw overflow detected!\n", __func__);
109 mutex_lock(&crw_handler_mutex);
110 for (i = 0; i < NR_RSCS; i++) {
111 if (crw_handlers[i])
112 crw_handlers[i](NULL, NULL, 1);
114 mutex_unlock(&crw_handler_mutex);
115 chain = 0;
116 continue;
118 if (crw[0].chn && !chain) {
119 chain++;
120 continue;
122 mutex_lock(&crw_handler_mutex);
123 handler = crw_handlers[crw[chain].rsc];
124 if (handler)
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);
132 goto repeat;
133 return 0;
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");
157 if (IS_ERR(task))
158 return PTR_ERR(task);
159 ctl_set_bit(14, 28); /* enable channel report MCH */
160 return 0;
162 device_initcall(crw_machine_check_init);