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);
34 DEFINE_MUTEX(tiq_list_lock);
36 /* adapter local summary indicator */
37 static unsigned char *tiqdio_alsi;
39 /* device state change indicators */
41 u32 ind; /* u32 because of compare-and-swap performance */
42 atomic_t count; /* use count, 0 or 1 for non-shared indicators */
44 static struct indicator_t *q_indicators;
46 static void tiqdio_tasklet_fn(unsigned long data);
47 static DECLARE_TASKLET(tiqdio_tasklet, tiqdio_tasklet_fn, 0);
49 static int css_qdio_omit_svs;
51 static inline unsigned long do_clear_global_summary(void)
53 register unsigned long __fn asm("1") = 3;
54 register unsigned long __tmp asm("2");
55 register unsigned long __time asm("3");
58 " .insn rre,0xb2650000,2,0"
59 : "+d" (__fn), "=d" (__tmp), "=d" (__time));
63 /* returns addr for the device state change indicator */
64 static u32 *get_indicator(void)
68 for (i = 0; i < TIQDIO_NR_NONSHARED_IND; i++)
69 if (!atomic_read(&q_indicators[i].count)) {
70 atomic_set(&q_indicators[i].count, 1);
71 return &q_indicators[i].ind;
74 /* use the shared indicator */
75 atomic_inc(&q_indicators[TIQDIO_SHARED_IND].count);
76 return &q_indicators[TIQDIO_SHARED_IND].ind;
79 static void put_indicator(u32 *addr)
85 i = ((unsigned long)addr - (unsigned long)q_indicators) /
86 sizeof(struct indicator_t);
87 atomic_dec(&q_indicators[i].count);
90 void tiqdio_add_input_queues(struct qdio_irq *irq_ptr)
95 /* No TDD facility? If we must use SIGA-s we can also omit SVS. */
96 if (!css_qdio_omit_svs && irq_ptr->siga_flag.sync)
97 css_qdio_omit_svs = 1;
99 mutex_lock(&tiq_list_lock);
100 for_each_input_queue(irq_ptr, q, i)
101 list_add_rcu(&q->entry, &tiq_list);
102 mutex_unlock(&tiq_list_lock);
103 xchg(irq_ptr->dsci, 1);
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)
122 mutex_lock(&tiq_list_lock);
123 list_del_rcu(&q->entry);
124 mutex_unlock(&tiq_list_lock);
129 static inline int tiqdio_inbound_q_done(struct qdio_q *q)
131 unsigned char state = 0;
133 if (!atomic_read(&q->nr_buf_used))
137 get_buf_state(q, q->first_to_check, &state, 0);
139 if (state == SLSB_P_INPUT_PRIMED)
140 /* more work coming */
145 static inline int shared_ind(struct qdio_irq *irq_ptr)
147 return irq_ptr->dsci == &q_indicators[TIQDIO_SHARED_IND].ind;
150 static void __tiqdio_inbound_processing(struct qdio_q *q)
152 qdio_perf_stat_inc(&perf_stats.thinint_inbound);
153 qdio_sync_after_thinint(q);
156 * Maybe we have work on our outbound queues... at least
157 * we have to check the PCI capable queues.
159 qdio_check_outbound_after_thinint(q);
161 if (!qdio_inbound_q_moved(q))
164 qdio_kick_handler(q);
166 if (!tiqdio_inbound_q_done(q)) {
167 qdio_perf_stat_inc(&perf_stats.thinint_inbound_loop);
168 if (likely(q->irq_ptr->state != QDIO_IRQ_STATE_STOPPED))
169 tasklet_schedule(&q->tasklet);
172 qdio_stop_polling(q);
174 * We need to check again to not lose initiative after
175 * resetting the ACK state.
177 if (!tiqdio_inbound_q_done(q)) {
178 qdio_perf_stat_inc(&perf_stats.thinint_inbound_loop2);
179 if (likely(q->irq_ptr->state != QDIO_IRQ_STATE_STOPPED))
180 tasklet_schedule(&q->tasklet);
184 void tiqdio_inbound_processing(unsigned long data)
186 struct qdio_q *q = (struct qdio_q *)data;
188 __tiqdio_inbound_processing(q);
191 /* check for work on all inbound thinint queues */
192 static void tiqdio_tasklet_fn(unsigned long data)
196 qdio_perf_stat_inc(&perf_stats.tasklet_thinint);
199 /* protect tiq_list entries, only changed in activate or shutdown */
202 list_for_each_entry_rcu(q, &tiq_list, entry)
203 /* only process queues from changed sets */
204 if (*q->irq_ptr->dsci) {
206 /* only clear it if the indicator is non-shared */
207 if (!shared_ind(q->irq_ptr))
208 xchg(q->irq_ptr->dsci, 0);
210 * don't call inbound processing directly since
211 * that could starve other thinint queues
213 tasklet_schedule(&q->tasklet);
219 * if we used the shared indicator clear it now after all queues
222 if (atomic_read(&q_indicators[TIQDIO_SHARED_IND].count)) {
223 xchg(&q_indicators[TIQDIO_SHARED_IND].ind, 0);
227 xchg(&q_indicators[TIQDIO_SHARED_IND].ind, 1);
230 /* check for more work */
232 xchg(tiqdio_alsi, 0);
233 qdio_perf_stat_inc(&perf_stats.tasklet_thinint_loop);
239 * tiqdio_thinint_handler - thin interrupt handler for qdio
240 * @ind: pointer to adapter local summary indicator
243 static void tiqdio_thinint_handler(void *ind, void *drv_data)
245 qdio_perf_stat_inc(&perf_stats.thin_int);
248 * SVS only when needed: issue SVS to benefit from iqdio interrupt
249 * avoidance (SVS clears adapter interrupt suppression overwrite)
251 if (!css_qdio_omit_svs)
252 do_clear_global_summary();
255 * reset local summary indicator (tiqdio_alsi) to stop adapter
256 * interrupts for now, the tasklet will clean all dsci's
259 tasklet_hi_schedule(&tiqdio_tasklet);
262 static int set_subchannel_ind(struct qdio_irq *irq_ptr, int reset)
264 struct scssc_area *scssc_area;
267 scssc_area = (struct scssc_area *)irq_ptr->chsc_page;
268 memset(scssc_area, 0, PAGE_SIZE);
271 scssc_area->summary_indicator_addr = 0;
272 scssc_area->subchannel_indicator_addr = 0;
274 scssc_area->summary_indicator_addr = virt_to_phys(tiqdio_alsi);
275 scssc_area->subchannel_indicator_addr =
276 virt_to_phys(irq_ptr->dsci);
279 scssc_area->request = (struct chsc_header) {
283 scssc_area->operation_code = 0;
284 scssc_area->ks = PAGE_DEFAULT_KEY;
285 scssc_area->kc = PAGE_DEFAULT_KEY;
286 scssc_area->isc = QDIO_AIRQ_ISC;
287 scssc_area->schid = irq_ptr->schid;
289 /* enable the time delay disablement facility */
290 if (css_general_characteristics.aif_tdd)
291 scssc_area->word_with_d_bit = 0x10000000;
293 rc = chsc(scssc_area);
297 rc = chsc_error_from_response(scssc_area->response.code);
299 DBF_ERROR("%4x SSI r:%4x", irq_ptr->schid.sch_no,
300 scssc_area->response.code);
301 DBF_ERROR_HEX(&scssc_area->response, sizeof(void *));
305 DBF_EVENT("setscind");
306 DBF_HEX(&scssc_area->summary_indicator_addr, sizeof(unsigned long));
307 DBF_HEX(&scssc_area->subchannel_indicator_addr, sizeof(unsigned long));
311 /* allocate non-shared indicators and shared indicator */
312 int __init tiqdio_allocate_memory(void)
314 q_indicators = kzalloc(sizeof(struct indicator_t) * TIQDIO_NR_INDICATORS,
321 void tiqdio_free_memory(void)
326 int __init tiqdio_register_thinints(void)
328 isc_register(QDIO_AIRQ_ISC);
329 tiqdio_alsi = s390_register_adapter_interrupt(&tiqdio_thinint_handler,
330 NULL, QDIO_AIRQ_ISC);
331 if (IS_ERR(tiqdio_alsi)) {
332 DBF_EVENT("RTI:%lx", PTR_ERR(tiqdio_alsi));
334 isc_unregister(QDIO_AIRQ_ISC);
340 int qdio_establish_thinint(struct qdio_irq *irq_ptr)
342 if (!is_thinint_irq(irq_ptr))
345 /* Check for aif time delay disablement. If installed,
346 * omit SVS even under LPAR
348 if (css_general_characteristics.aif_tdd)
349 css_qdio_omit_svs = 1;
350 return set_subchannel_ind(irq_ptr, 0);
353 void qdio_setup_thinint(struct qdio_irq *irq_ptr)
355 if (!is_thinint_irq(irq_ptr))
357 irq_ptr->dsci = get_indicator();
358 DBF_HEX(&irq_ptr->dsci, sizeof(void *));
361 void qdio_shutdown_thinint(struct qdio_irq *irq_ptr)
363 if (!is_thinint_irq(irq_ptr))
366 /* reset adapter interrupt indicators */
367 put_indicator(irq_ptr->dsci);
368 set_subchannel_ind(irq_ptr, 1);
371 void __exit tiqdio_unregister_thinints(void)
373 WARN_ON(!list_empty(&tiq_list));
376 s390_unregister_adapter_interrupt(tiqdio_alsi, QDIO_AIRQ_ISC);
377 isc_unregister(QDIO_AIRQ_ISC);
379 tasklet_kill(&tiqdio_tasklet);