2 * linux/drivers/s390/cio/thinint_qdio.c
4 * thin interrupt support for qdio
6 * Copyright 2000-2008 IBM Corp.
7 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>
8 * Cornelia Huck <cornelia.huck@de.ibm.com>
9 * Jan Glauber <jang@linux.vnet.ibm.com>
12 #include <asm/atomic.h>
13 #include <asm/debug.h>
21 #include "qdio_debug.h"
22 #include "qdio_perf.h"
25 * Restriction: only 63 iqdio subchannels would have its own indicator,
26 * after that, subsequent subchannels share one indicator
28 #define TIQDIO_NR_NONSHARED_IND 63
29 #define TIQDIO_NR_INDICATORS (TIQDIO_NR_NONSHARED_IND + 1)
30 #define TIQDIO_SHARED_IND 63
32 /* list of thin interrupt input queues */
33 static LIST_HEAD(tiq_list);
35 /* adapter local summary indicator */
36 static unsigned char *tiqdio_alsi;
38 /* device state change indicators */
40 u32 ind; /* u32 because of compare-and-swap performance */
41 atomic_t count; /* use count, 0 or 1 for non-shared indicators */
43 static struct indicator_t *q_indicators;
45 static void tiqdio_tasklet_fn(unsigned long data);
46 static DECLARE_TASKLET(tiqdio_tasklet, tiqdio_tasklet_fn, 0);
48 static int css_qdio_omit_svs;
50 static inline unsigned long do_clear_global_summary(void)
52 register unsigned long __fn asm("1") = 3;
53 register unsigned long __tmp asm("2");
54 register unsigned long __time asm("3");
57 " .insn rre,0xb2650000,2,0"
58 : "+d" (__fn), "=d" (__tmp), "=d" (__time));
62 /* returns addr for the device state change indicator */
63 static u32 *get_indicator(void)
67 for (i = 0; i < TIQDIO_NR_NONSHARED_IND; i++)
68 if (!atomic_read(&q_indicators[i].count)) {
69 atomic_set(&q_indicators[i].count, 1);
70 return &q_indicators[i].ind;
73 /* use the shared indicator */
74 atomic_inc(&q_indicators[TIQDIO_SHARED_IND].count);
75 return &q_indicators[TIQDIO_SHARED_IND].ind;
78 static void put_indicator(u32 *addr)
84 i = ((unsigned long)addr - (unsigned long)q_indicators) /
85 sizeof(struct indicator_t);
86 atomic_dec(&q_indicators[i].count);
89 void tiqdio_add_input_queues(struct qdio_irq *irq_ptr)
94 /* No TDD facility? If we must use SIGA-s we can also omit SVS. */
95 if (!css_qdio_omit_svs && irq_ptr->siga_flag.sync)
96 css_qdio_omit_svs = 1;
98 for_each_input_queue(irq_ptr, q, i) {
99 list_add_rcu(&q->entry, &tiq_list);
102 xchg(irq_ptr->dsci, 1);
103 tasklet_schedule(&tiqdio_tasklet);
107 * we cannot stop the tiqdio tasklet here since it is for all
108 * thinint qdio devices and it must run as long as there is a
109 * thinint device left
111 void tiqdio_remove_input_queues(struct qdio_irq *irq_ptr)
116 for (i = 0; i < irq_ptr->nr_input_qs; i++) {
117 q = irq_ptr->input_qs[i];
118 /* if establish triggered an error */
119 if (!q || !q->entry.prev || !q->entry.next)
121 list_del_rcu(&q->entry);
126 static inline int tiqdio_inbound_q_done(struct qdio_q *q)
128 unsigned char state = 0;
130 if (!atomic_read(&q->nr_buf_used))
134 get_buf_state(q, q->first_to_check, &state, 0);
136 if (state == SLSB_P_INPUT_PRIMED)
137 /* more work coming */
142 static inline int shared_ind(struct qdio_irq *irq_ptr)
144 return irq_ptr->dsci == &q_indicators[TIQDIO_SHARED_IND].ind;
147 static void __tiqdio_inbound_processing(struct qdio_q *q)
149 qdio_perf_stat_inc(&perf_stats.thinint_inbound);
150 qdio_sync_after_thinint(q);
153 * Maybe we have work on our outbound queues... at least
154 * we have to check the PCI capable queues.
156 qdio_check_outbound_after_thinint(q);
159 if (!qdio_inbound_q_moved(q))
162 qdio_kick_inbound_handler(q);
164 if (!tiqdio_inbound_q_done(q)) {
165 qdio_perf_stat_inc(&perf_stats.thinint_inbound_loop);
169 qdio_stop_polling(q);
171 * We need to check again to not lose initiative after
172 * resetting the ACK state.
174 if (!tiqdio_inbound_q_done(q)) {
175 qdio_perf_stat_inc(&perf_stats.thinint_inbound_loop2);
180 void tiqdio_inbound_processing(unsigned long data)
182 struct qdio_q *q = (struct qdio_q *)data;
184 __tiqdio_inbound_processing(q);
187 /* check for work on all inbound thinint queues */
188 static void tiqdio_tasklet_fn(unsigned long data)
192 qdio_perf_stat_inc(&perf_stats.tasklet_thinint);
195 /* protect tiq_list entries, only changed in activate or shutdown */
198 list_for_each_entry_rcu(q, &tiq_list, entry)
199 /* only process queues from changed sets */
200 if (*q->irq_ptr->dsci) {
202 /* only clear it if the indicator is non-shared */
203 if (!shared_ind(q->irq_ptr))
204 xchg(q->irq_ptr->dsci, 0);
206 * don't call inbound processing directly since
207 * that could starve other thinint queues
209 tasklet_schedule(&q->tasklet);
215 * if we used the shared indicator clear it now after all queues
218 if (atomic_read(&q_indicators[TIQDIO_SHARED_IND].count)) {
219 xchg(&q_indicators[TIQDIO_SHARED_IND].ind, 0);
223 xchg(&q_indicators[TIQDIO_SHARED_IND].ind, 1);
226 /* check for more work */
228 xchg(tiqdio_alsi, 0);
229 qdio_perf_stat_inc(&perf_stats.tasklet_thinint_loop);
235 * tiqdio_thinint_handler - thin interrupt handler for qdio
236 * @ind: pointer to adapter local summary indicator
239 static void tiqdio_thinint_handler(void *ind, void *drv_data)
241 qdio_perf_stat_inc(&perf_stats.thin_int);
244 * SVS only when needed: issue SVS to benefit from iqdio interrupt
245 * avoidance (SVS clears adapter interrupt suppression overwrite)
247 if (!css_qdio_omit_svs)
248 do_clear_global_summary();
251 * reset local summary indicator (tiqdio_alsi) to stop adapter
252 * interrupts for now, the tasklet will clean all dsci's
255 tasklet_hi_schedule(&tiqdio_tasklet);
258 static int set_subchannel_ind(struct qdio_irq *irq_ptr, int reset)
260 struct scssc_area *scssc_area;
263 scssc_area = (struct scssc_area *)irq_ptr->chsc_page;
264 memset(scssc_area, 0, PAGE_SIZE);
267 scssc_area->summary_indicator_addr = 0;
268 scssc_area->subchannel_indicator_addr = 0;
270 scssc_area->summary_indicator_addr = virt_to_phys(tiqdio_alsi);
271 scssc_area->subchannel_indicator_addr =
272 virt_to_phys(irq_ptr->dsci);
275 scssc_area->request = (struct chsc_header) {
279 scssc_area->operation_code = 0;
280 scssc_area->ks = PAGE_DEFAULT_KEY;
281 scssc_area->kc = PAGE_DEFAULT_KEY;
282 scssc_area->isc = QDIO_AIRQ_ISC;
283 scssc_area->schid = irq_ptr->schid;
285 /* enable the time delay disablement facility */
286 if (css_general_characteristics.aif_tdd)
287 scssc_area->word_with_d_bit = 0x10000000;
289 rc = chsc(scssc_area);
293 rc = chsc_error_from_response(scssc_area->response.code);
295 DBF_ERROR("%4x SSI r:%4x", irq_ptr->schid.sch_no,
296 scssc_area->response.code);
297 DBF_ERROR_HEX(&scssc_area->response, sizeof(void *));
301 DBF_EVENT("setscind");
302 DBF_HEX(&scssc_area->summary_indicator_addr, sizeof(unsigned long));
303 DBF_HEX(&scssc_area->subchannel_indicator_addr, sizeof(unsigned long));
307 /* allocate non-shared indicators and shared indicator */
308 int __init tiqdio_allocate_memory(void)
310 q_indicators = kzalloc(sizeof(struct indicator_t) * TIQDIO_NR_INDICATORS,
317 void tiqdio_free_memory(void)
322 int __init tiqdio_register_thinints(void)
324 isc_register(QDIO_AIRQ_ISC);
325 tiqdio_alsi = s390_register_adapter_interrupt(&tiqdio_thinint_handler,
326 NULL, QDIO_AIRQ_ISC);
327 if (IS_ERR(tiqdio_alsi)) {
328 DBF_EVENT("RTI:%lx", PTR_ERR(tiqdio_alsi));
330 isc_unregister(QDIO_AIRQ_ISC);
336 int qdio_establish_thinint(struct qdio_irq *irq_ptr)
338 if (!is_thinint_irq(irq_ptr))
341 /* Check for aif time delay disablement. If installed,
342 * omit SVS even under LPAR
344 if (css_general_characteristics.aif_tdd)
345 css_qdio_omit_svs = 1;
346 return set_subchannel_ind(irq_ptr, 0);
349 void qdio_setup_thinint(struct qdio_irq *irq_ptr)
351 if (!is_thinint_irq(irq_ptr))
353 irq_ptr->dsci = get_indicator();
354 DBF_HEX(&irq_ptr->dsci, sizeof(void *));
357 void qdio_shutdown_thinint(struct qdio_irq *irq_ptr)
359 if (!is_thinint_irq(irq_ptr))
362 /* reset adapter interrupt indicators */
363 put_indicator(irq_ptr->dsci);
364 set_subchannel_ind(irq_ptr, 1);
367 void __exit tiqdio_unregister_thinints(void)
369 tasklet_disable(&tiqdio_tasklet);
372 s390_unregister_adapter_interrupt(tiqdio_alsi, QDIO_AIRQ_ISC);
373 isc_unregister(QDIO_AIRQ_ISC);