2 * linux/drivers/s390/cio/thinint_qdio.c
4 * Copyright 2000,2009 IBM Corp.
5 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>
6 * Cornelia Huck <cornelia.huck@de.ibm.com>
7 * Jan Glauber <jang@linux.vnet.ibm.com>
10 #include <linux/slab.h>
11 #include <linux/kernel_stat.h>
12 #include <linux/atomic.h>
13 #include <asm/debug.h>
21 #include "qdio_debug.h"
24 * Restriction: only 63 iqdio subchannels would have its own indicator,
25 * after that, subsequent subchannels share one indicator
27 #define TIQDIO_NR_NONSHARED_IND 63
28 #define TIQDIO_NR_INDICATORS (TIQDIO_NR_NONSHARED_IND + 1)
29 #define TIQDIO_SHARED_IND 63
31 /* device state change indicators */
33 u32 ind
; /* u32 because of compare-and-swap performance */
34 atomic_t count
; /* use count, 0 or 1 for non-shared indicators */
37 /* list of thin interrupt input queues */
38 static LIST_HEAD(tiq_list
);
39 static DEFINE_MUTEX(tiq_list_lock
);
41 /* adapter local summary indicator */
42 static u8
*tiqdio_alsi
;
44 static struct indicator_t
*q_indicators
;
48 /* returns addr for the device state change indicator */
49 static u32
*get_indicator(void)
53 for (i
= 0; i
< TIQDIO_NR_NONSHARED_IND
; i
++)
54 if (!atomic_read(&q_indicators
[i
].count
)) {
55 atomic_set(&q_indicators
[i
].count
, 1);
56 return &q_indicators
[i
].ind
;
59 /* use the shared indicator */
60 atomic_inc(&q_indicators
[TIQDIO_SHARED_IND
].count
);
61 return &q_indicators
[TIQDIO_SHARED_IND
].ind
;
64 static void put_indicator(u32
*addr
)
70 i
= ((unsigned long)addr
- (unsigned long)q_indicators
) /
71 sizeof(struct indicator_t
);
72 atomic_dec(&q_indicators
[i
].count
);
75 void tiqdio_add_input_queues(struct qdio_irq
*irq_ptr
)
77 mutex_lock(&tiq_list_lock
);
78 BUG_ON(irq_ptr
->nr_input_qs
< 1);
79 list_add_rcu(&irq_ptr
->input_qs
[0]->entry
, &tiq_list
);
80 mutex_unlock(&tiq_list_lock
);
81 xchg(irq_ptr
->dsci
, 1 << 7);
84 void tiqdio_remove_input_queues(struct qdio_irq
*irq_ptr
)
88 BUG_ON(irq_ptr
->nr_input_qs
< 1);
89 q
= irq_ptr
->input_qs
[0];
90 /* if establish triggered an error */
91 if (!q
|| !q
->entry
.prev
|| !q
->entry
.next
)
94 mutex_lock(&tiq_list_lock
);
95 list_del_rcu(&q
->entry
);
96 mutex_unlock(&tiq_list_lock
);
100 static inline int has_multiple_inq_on_dsci(struct qdio_irq
*irq_ptr
)
102 return irq_ptr
->nr_input_qs
> 1;
105 static inline int references_shared_dsci(struct qdio_irq
*irq_ptr
)
107 return irq_ptr
->dsci
== &q_indicators
[TIQDIO_SHARED_IND
].ind
;
110 static inline int shared_ind(struct qdio_irq
*irq_ptr
)
112 return references_shared_dsci(irq_ptr
) ||
113 has_multiple_inq_on_dsci(irq_ptr
);
116 void clear_nonshared_ind(struct qdio_irq
*irq_ptr
)
118 if (!is_thinint_irq(irq_ptr
))
120 if (shared_ind(irq_ptr
))
122 xchg(irq_ptr
->dsci
, 0);
125 int test_nonshared_ind(struct qdio_irq
*irq_ptr
)
127 if (!is_thinint_irq(irq_ptr
))
129 if (shared_ind(irq_ptr
))
137 static inline u32
clear_shared_ind(void)
139 if (!atomic_read(&q_indicators
[TIQDIO_SHARED_IND
].count
))
141 return xchg(&q_indicators
[TIQDIO_SHARED_IND
].ind
, 0);
144 static inline void tiqdio_call_inq_handlers(struct qdio_irq
*irq
)
149 for_each_input_queue(irq
, q
, i
) {
150 if (!references_shared_dsci(irq
) &&
151 has_multiple_inq_on_dsci(irq
))
152 xchg(q
->irq_ptr
->dsci
, 0);
154 if (q
->u
.in
.queue_start_poll
) {
155 /* skip if polling is enabled or already in work */
156 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED
,
157 &q
->u
.in
.queue_irq_state
)) {
158 qperf_inc(q
, int_discarded
);
162 /* avoid dsci clear here, done after processing */
163 q
->u
.in
.queue_start_poll(q
->irq_ptr
->cdev
, q
->nr
,
164 q
->irq_ptr
->int_parm
);
166 if (!shared_ind(q
->irq_ptr
))
167 xchg(q
->irq_ptr
->dsci
, 0);
170 * Call inbound processing but not directly
171 * since that could starve other thinint queues.
173 tasklet_schedule(&q
->tasklet
);
179 * tiqdio_thinint_handler - thin interrupt handler for qdio
180 * @alsi: pointer to adapter local summary indicator
183 static void tiqdio_thinint_handler(void *alsi
, void *data
)
185 u32 si_used
= clear_shared_ind();
188 last_ai_time
= S390_lowcore
.int_clock
;
189 kstat_cpu(smp_processor_id()).irqs
[IOINT_QAI
]++;
191 /* protect tiq_list entries, only changed in activate or shutdown */
194 /* check for work on all inbound thinint queues */
195 list_for_each_entry_rcu(q
, &tiq_list
, entry
) {
196 struct qdio_irq
*irq
;
198 /* only process queues from changed sets */
200 if (unlikely(references_shared_dsci(irq
))) {
203 } else if (!*irq
->dsci
)
206 tiqdio_call_inq_handlers(irq
);
208 qperf_inc(q
, adapter_int
);
213 static int set_subchannel_ind(struct qdio_irq
*irq_ptr
, int reset
)
215 struct scssc_area
*scssc_area
;
218 scssc_area
= (struct scssc_area
*)irq_ptr
->chsc_page
;
219 memset(scssc_area
, 0, PAGE_SIZE
);
222 scssc_area
->summary_indicator_addr
= 0;
223 scssc_area
->subchannel_indicator_addr
= 0;
225 scssc_area
->summary_indicator_addr
= virt_to_phys(tiqdio_alsi
);
226 scssc_area
->subchannel_indicator_addr
=
227 virt_to_phys(irq_ptr
->dsci
);
230 scssc_area
->request
= (struct chsc_header
) {
234 scssc_area
->operation_code
= 0;
235 scssc_area
->ks
= PAGE_DEFAULT_KEY
>> 4;
236 scssc_area
->kc
= PAGE_DEFAULT_KEY
>> 4;
237 scssc_area
->isc
= QDIO_AIRQ_ISC
;
238 scssc_area
->schid
= irq_ptr
->schid
;
240 /* enable the time delay disablement facility */
241 if (css_general_characteristics
.aif_tdd
)
242 scssc_area
->word_with_d_bit
= 0x10000000;
244 rc
= chsc(scssc_area
);
248 rc
= chsc_error_from_response(scssc_area
->response
.code
);
250 DBF_ERROR("%4x SSI r:%4x", irq_ptr
->schid
.sch_no
,
251 scssc_area
->response
.code
);
252 DBF_ERROR_HEX(&scssc_area
->response
, sizeof(void *));
256 DBF_EVENT("setscind");
257 DBF_HEX(&scssc_area
->summary_indicator_addr
, sizeof(unsigned long));
258 DBF_HEX(&scssc_area
->subchannel_indicator_addr
, sizeof(unsigned long));
262 /* allocate non-shared indicators and shared indicator */
263 int __init
tiqdio_allocate_memory(void)
265 q_indicators
= kzalloc(sizeof(struct indicator_t
) * TIQDIO_NR_INDICATORS
,
272 void tiqdio_free_memory(void)
277 int __init
tiqdio_register_thinints(void)
279 isc_register(QDIO_AIRQ_ISC
);
280 tiqdio_alsi
= s390_register_adapter_interrupt(&tiqdio_thinint_handler
,
281 NULL
, QDIO_AIRQ_ISC
);
282 if (IS_ERR(tiqdio_alsi
)) {
283 DBF_EVENT("RTI:%lx", PTR_ERR(tiqdio_alsi
));
285 isc_unregister(QDIO_AIRQ_ISC
);
291 int qdio_establish_thinint(struct qdio_irq
*irq_ptr
)
293 if (!is_thinint_irq(irq_ptr
))
295 return set_subchannel_ind(irq_ptr
, 0);
298 void qdio_setup_thinint(struct qdio_irq
*irq_ptr
)
300 if (!is_thinint_irq(irq_ptr
))
302 irq_ptr
->dsci
= get_indicator();
303 DBF_HEX(&irq_ptr
->dsci
, sizeof(void *));
306 void qdio_shutdown_thinint(struct qdio_irq
*irq_ptr
)
308 if (!is_thinint_irq(irq_ptr
))
311 /* reset adapter interrupt indicators */
312 set_subchannel_ind(irq_ptr
, 1);
313 put_indicator(irq_ptr
->dsci
);
316 void __exit
tiqdio_unregister_thinints(void)
318 WARN_ON(!list_empty(&tiq_list
));
321 s390_unregister_adapter_interrupt(tiqdio_alsi
, QDIO_AIRQ_ISC
);
322 isc_unregister(QDIO_AIRQ_ISC
);