2 * Copyright IBM Corp. 2000, 2009
3 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>
4 * Cornelia Huck <cornelia.huck@de.ibm.com>
5 * Jan Glauber <jang@linux.vnet.ibm.com>
8 #include <linux/slab.h>
9 #include <linux/kernel_stat.h>
10 #include <linux/atomic.h>
11 #include <asm/debug.h>
19 #include "qdio_debug.h"
22 * Restriction: only 63 iqdio subchannels would have its own indicator,
23 * after that, subsequent subchannels share one indicator
25 #define TIQDIO_NR_NONSHARED_IND 63
26 #define TIQDIO_NR_INDICATORS (TIQDIO_NR_NONSHARED_IND + 1)
27 #define TIQDIO_SHARED_IND 63
29 /* device state change indicators */
31 u32 ind
; /* u32 because of compare-and-swap performance */
32 atomic_t count
; /* use count, 0 or 1 for non-shared indicators */
35 /* list of thin interrupt input queues */
36 static LIST_HEAD(tiq_list
);
37 static DEFINE_MUTEX(tiq_list_lock
);
39 /* Adapter interrupt definitions */
40 static void tiqdio_thinint_handler(struct airq_struct
*airq
);
42 static struct airq_struct tiqdio_airq
= {
43 .handler
= tiqdio_thinint_handler
,
47 static struct indicator_t
*q_indicators
;
51 /* returns addr for the device state change indicator */
52 static u32
*get_indicator(void)
56 for (i
= 0; i
< TIQDIO_NR_NONSHARED_IND
; i
++)
57 if (!atomic_read(&q_indicators
[i
].count
)) {
58 atomic_set(&q_indicators
[i
].count
, 1);
59 return &q_indicators
[i
].ind
;
62 /* use the shared indicator */
63 atomic_inc(&q_indicators
[TIQDIO_SHARED_IND
].count
);
64 return &q_indicators
[TIQDIO_SHARED_IND
].ind
;
67 static void put_indicator(u32
*addr
)
73 i
= ((unsigned long)addr
- (unsigned long)q_indicators
) /
74 sizeof(struct indicator_t
);
75 atomic_dec(&q_indicators
[i
].count
);
78 void tiqdio_add_input_queues(struct qdio_irq
*irq_ptr
)
80 mutex_lock(&tiq_list_lock
);
81 list_add_rcu(&irq_ptr
->input_qs
[0]->entry
, &tiq_list
);
82 mutex_unlock(&tiq_list_lock
);
83 xchg(irq_ptr
->dsci
, 1 << 7);
86 void tiqdio_remove_input_queues(struct qdio_irq
*irq_ptr
)
90 q
= irq_ptr
->input_qs
[0];
91 /* if establish triggered an error */
92 if (!q
|| !q
->entry
.prev
|| !q
->entry
.next
)
95 mutex_lock(&tiq_list_lock
);
96 list_del_rcu(&q
->entry
);
97 mutex_unlock(&tiq_list_lock
);
101 static inline int has_multiple_inq_on_dsci(struct qdio_irq
*irq_ptr
)
103 return irq_ptr
->nr_input_qs
> 1;
106 static inline int references_shared_dsci(struct qdio_irq
*irq_ptr
)
108 return irq_ptr
->dsci
== &q_indicators
[TIQDIO_SHARED_IND
].ind
;
111 static inline int shared_ind(struct qdio_irq
*irq_ptr
)
113 return references_shared_dsci(irq_ptr
) ||
114 has_multiple_inq_on_dsci(irq_ptr
);
117 void clear_nonshared_ind(struct qdio_irq
*irq_ptr
)
119 if (!is_thinint_irq(irq_ptr
))
121 if (shared_ind(irq_ptr
))
123 xchg(irq_ptr
->dsci
, 0);
126 int test_nonshared_ind(struct qdio_irq
*irq_ptr
)
128 if (!is_thinint_irq(irq_ptr
))
130 if (shared_ind(irq_ptr
))
138 static inline u32
clear_shared_ind(void)
140 if (!atomic_read(&q_indicators
[TIQDIO_SHARED_IND
].count
))
142 return xchg(&q_indicators
[TIQDIO_SHARED_IND
].ind
, 0);
145 static inline void tiqdio_call_inq_handlers(struct qdio_irq
*irq
)
150 for_each_input_queue(irq
, q
, i
) {
151 if (!references_shared_dsci(irq
) &&
152 has_multiple_inq_on_dsci(irq
))
153 xchg(q
->irq_ptr
->dsci
, 0);
155 if (q
->u
.in
.queue_start_poll
) {
156 /* skip if polling is enabled or already in work */
157 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED
,
158 &q
->u
.in
.queue_irq_state
)) {
159 qperf_inc(q
, int_discarded
);
163 /* avoid dsci clear here, done after processing */
164 q
->u
.in
.queue_start_poll(q
->irq_ptr
->cdev
, q
->nr
,
165 q
->irq_ptr
->int_parm
);
167 if (!shared_ind(q
->irq_ptr
))
168 xchg(q
->irq_ptr
->dsci
, 0);
171 * Call inbound processing but not directly
172 * since that could starve other thinint queues.
174 tasklet_schedule(&q
->tasklet
);
180 * tiqdio_thinint_handler - thin interrupt handler for qdio
181 * @alsi: pointer to adapter local summary indicator
184 static void tiqdio_thinint_handler(struct airq_struct
*airq
)
186 u32 si_used
= clear_shared_ind();
189 last_ai_time
= S390_lowcore
.int_clock
;
190 inc_irq_stat(IRQIO_QAI
);
192 /* protect tiq_list entries, only changed in activate or shutdown */
195 /* check for work on all inbound thinint queues */
196 list_for_each_entry_rcu(q
, &tiq_list
, entry
) {
197 struct qdio_irq
*irq
;
199 /* only process queues from changed sets */
201 if (unlikely(references_shared_dsci(irq
))) {
204 } else if (!*irq
->dsci
)
207 tiqdio_call_inq_handlers(irq
);
209 qperf_inc(q
, adapter_int
);
214 static int set_subchannel_ind(struct qdio_irq
*irq_ptr
, int reset
)
216 struct chsc_scssc_area
*scssc
= (void *)irq_ptr
->chsc_page
;
217 u64 summary_indicator_addr
, subchannel_indicator_addr
;
221 summary_indicator_addr
= 0;
222 subchannel_indicator_addr
= 0;
224 summary_indicator_addr
= virt_to_phys(tiqdio_airq
.lsi_ptr
);
225 subchannel_indicator_addr
= virt_to_phys(irq_ptr
->dsci
);
228 rc
= chsc_sadc(irq_ptr
->schid
, scssc
, summary_indicator_addr
,
229 subchannel_indicator_addr
);
231 DBF_ERROR("%4x SSI r:%4x", irq_ptr
->schid
.sch_no
,
232 scssc
->response
.code
);
236 DBF_EVENT("setscind");
237 DBF_HEX(&summary_indicator_addr
, sizeof(summary_indicator_addr
));
238 DBF_HEX(&subchannel_indicator_addr
, sizeof(subchannel_indicator_addr
));
243 /* allocate non-shared indicators and shared indicator */
244 int __init
tiqdio_allocate_memory(void)
246 q_indicators
= kzalloc(sizeof(struct indicator_t
) * TIQDIO_NR_INDICATORS
,
253 void tiqdio_free_memory(void)
258 int __init
tiqdio_register_thinints(void)
262 rc
= register_adapter_interrupt(&tiqdio_airq
);
264 DBF_EVENT("RTI:%x", rc
);
270 int qdio_establish_thinint(struct qdio_irq
*irq_ptr
)
272 if (!is_thinint_irq(irq_ptr
))
274 return set_subchannel_ind(irq_ptr
, 0);
277 void qdio_setup_thinint(struct qdio_irq
*irq_ptr
)
279 if (!is_thinint_irq(irq_ptr
))
281 irq_ptr
->dsci
= get_indicator();
282 DBF_HEX(&irq_ptr
->dsci
, sizeof(void *));
285 void qdio_shutdown_thinint(struct qdio_irq
*irq_ptr
)
287 if (!is_thinint_irq(irq_ptr
))
290 /* reset adapter interrupt indicators */
291 set_subchannel_ind(irq_ptr
, 1);
292 put_indicator(irq_ptr
->dsci
);
295 void __exit
tiqdio_unregister_thinints(void)
297 WARN_ON(!list_empty(&tiq_list
));
298 unregister_adapter_interrupt(&tiqdio_airq
);