2 * Support for adapter interruptions
4 * Copyright IBM Corp. 1999, 2007
5 * Author(s): Ingo Adlung <adlung@de.ibm.com>
6 * Cornelia Huck <cornelia.huck@de.ibm.com>
7 * Arnd Bergmann <arndb@de.ibm.com>
8 * Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
11 #include <linux/init.h>
12 #include <linux/module.h>
13 #include <linux/slab.h>
14 #include <linux/rcupdate.h>
20 #include "cio_debug.h"
23 #define NR_AIRQS_PER_WORD sizeof(unsigned long)
24 #define NR_AIRQ_WORDS (NR_AIRQS / NR_AIRQS_PER_WORD)
27 unsigned long word
[NR_AIRQ_WORDS
];
28 unsigned char byte
[NR_AIRQS
];
29 } __attribute__((packed
));
32 adapter_int_handler_t handler
;
36 static union indicator_t indicators
[MAX_ISC
+1];
37 static struct airq_t
*airqs
[MAX_ISC
+1][NR_AIRQS
];
39 static int register_airq(struct airq_t
*airq
, u8 isc
)
43 for (i
= 0; i
< NR_AIRQS
; i
++)
44 if (!cmpxchg(&airqs
[isc
][i
], NULL
, airq
))
50 * s390_register_adapter_interrupt() - register adapter interrupt handler
51 * @handler: adapter handler to be registered
52 * @drv_data: driver data passed with each call to the handler
53 * @isc: isc for which the handler should be called
56 * Pointer to the indicator to be used on success
57 * ERR_PTR() if registration failed
59 void *s390_register_adapter_interrupt(adapter_int_handler_t handler
,
60 void *drv_data
, u8 isc
)
67 return ERR_PTR(-EINVAL
);
68 airq
= kmalloc(sizeof(struct airq_t
), GFP_KERNEL
);
73 airq
->handler
= handler
;
74 airq
->drv_data
= drv_data
;
76 ret
= register_airq(airq
, isc
);
78 snprintf(dbf_txt
, sizeof(dbf_txt
), "rairq:%d", ret
);
79 CIO_TRACE_EVENT(4, dbf_txt
);
84 return &indicators
[isc
].byte
[ret
];
86 EXPORT_SYMBOL(s390_register_adapter_interrupt
);
89 * s390_unregister_adapter_interrupt - unregister adapter interrupt handler
90 * @ind: indicator for which the handler is to be unregistered
91 * @isc: interruption subclass
93 void s390_unregister_adapter_interrupt(void *ind
, u8 isc
)
99 i
= (int) ((addr_t
) ind
) - ((addr_t
) &indicators
[isc
].byte
[0]);
100 snprintf(dbf_txt
, sizeof(dbf_txt
), "urairq:%d", i
);
101 CIO_TRACE_EVENT(4, dbf_txt
);
102 indicators
[isc
].byte
[i
] = 0;
103 airq
= xchg(&airqs
[isc
][i
], NULL
);
105 * Allow interrupts to complete. This will ensure that the airq handle
106 * is no longer referenced by any interrupt handler.
111 EXPORT_SYMBOL(s390_unregister_adapter_interrupt
);
113 #define INDICATOR_MASK (0xffUL << ((NR_AIRQS_PER_WORD - 1) * 8))
115 void do_adapter_IO(u8 isc
)
123 * Access indicator array in word-sized chunks to minimize storage
126 for (w
= 0; w
< NR_AIRQ_WORDS
; w
++) {
127 word
= indicators
[isc
].word
[w
];
128 i
= w
* NR_AIRQS_PER_WORD
;
130 * Check bytes within word for active indicators.
133 if (word
& INDICATOR_MASK
) {
134 airq
= airqs
[isc
][i
];
135 /* Make sure gcc reads from airqs only once. */
138 airq
->handler(&indicators
[isc
].byte
[i
],
142 * Reset ill-behaved indicator.
144 indicators
[isc
].byte
[i
] = 0;