2 * drivers/s390/cio/airq.c
3 * Support for adapter interruptions
5 * Copyright IBM Corp. 1999,2007
6 * Author(s): Ingo Adlung <adlung@de.ibm.com>
7 * Cornelia Huck <cornelia.huck@de.ibm.com>
8 * Arnd Bergmann <arndb@de.ibm.com>
9 * Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
12 #include <linux/init.h>
13 #include <linux/module.h>
14 #include <linux/slab.h>
15 #include <linux/rcupdate.h>
21 #include "cio_debug.h"
24 #define NR_AIRQS_PER_WORD sizeof(unsigned long)
25 #define NR_AIRQ_WORDS (NR_AIRQS / NR_AIRQS_PER_WORD)
28 unsigned long word[NR_AIRQ_WORDS];
29 unsigned char byte[NR_AIRQS];
30 } __attribute__((packed));
33 adapter_int_handler_t handler;
37 static union indicator_t indicators[MAX_ISC];
38 static struct airq_t *airqs[MAX_ISC][NR_AIRQS];
40 static int register_airq(struct airq_t *airq, u8 isc)
44 for (i = 0; i < NR_AIRQS; i++)
45 if (!cmpxchg(&airqs[isc][i], NULL, airq))
51 * s390_register_adapter_interrupt() - register adapter interrupt handler
52 * @handler: adapter handler to be registered
53 * @drv_data: driver data passed with each call to the handler
54 * @isc: isc for which the handler should be called
57 * Pointer to the indicator to be used on success
58 * ERR_PTR() if registration failed
60 void *s390_register_adapter_interrupt(adapter_int_handler_t handler,
61 void *drv_data, u8 isc)
68 return ERR_PTR(-EINVAL);
69 airq = kmalloc(sizeof(struct airq_t), GFP_KERNEL);
74 airq->handler = handler;
75 airq->drv_data = drv_data;
77 ret = register_airq(airq, isc);
79 snprintf(dbf_txt, sizeof(dbf_txt), "rairq:%d", ret);
80 CIO_TRACE_EVENT(4, dbf_txt);
85 return &indicators[isc].byte[ret];
87 EXPORT_SYMBOL(s390_register_adapter_interrupt);
90 * s390_unregister_adapter_interrupt - unregister adapter interrupt handler
91 * @ind: indicator for which the handler is to be unregistered
92 * @isc: interruption subclass
94 void s390_unregister_adapter_interrupt(void *ind, u8 isc)
100 i = (int) ((addr_t) ind) - ((addr_t) &indicators[isc].byte[0]);
101 snprintf(dbf_txt, sizeof(dbf_txt), "urairq:%d", i);
102 CIO_TRACE_EVENT(4, dbf_txt);
103 indicators[isc].byte[i] = 0;
104 airq = xchg(&airqs[isc][i], NULL);
106 * Allow interrupts to complete. This will ensure that the airq handle
107 * is no longer referenced by any interrupt handler.
112 EXPORT_SYMBOL(s390_unregister_adapter_interrupt);
114 #define INDICATOR_MASK (0xffUL << ((NR_AIRQS_PER_WORD - 1) * 8))
116 void do_adapter_IO(u8 isc)
124 * Access indicator array in word-sized chunks to minimize storage
127 for (w = 0; w < NR_AIRQ_WORDS; w++) {
128 word = indicators[isc].word[w];
129 i = w * NR_AIRQS_PER_WORD;
131 * Check bytes within word for active indicators.
134 if (word & INDICATOR_MASK) {
135 airq = airqs[isc][i];
137 airq->handler(&indicators[isc].byte[i],
141 * Reset ill-behaved indicator.
143 indicators[isc].byte[i] = 0;