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 <asm/atomic.h>
12 #include <asm/debug.h>
20 #include "qdio_debug.h"
23 * Restriction: only 63 iqdio subchannels would have its own indicator,
24 * after that, subsequent subchannels share one indicator
26 #define TIQDIO_NR_NONSHARED_IND 63
27 #define TIQDIO_NR_INDICATORS (TIQDIO_NR_NONSHARED_IND + 1)
28 #define TIQDIO_SHARED_IND 63
30 /* list of thin interrupt input queues */
31 static LIST_HEAD(tiq_list
);
32 DEFINE_MUTEX(tiq_list_lock
);
34 /* adapter local summary indicator */
35 static unsigned char *tiqdio_alsi
;
37 /* device state change indicators */
39 u32 ind
; /* u32 because of compare-and-swap performance */
40 atomic_t count
; /* use count, 0 or 1 for non-shared indicators */
42 static struct indicator_t
*q_indicators
;
44 static int css_qdio_omit_svs
;
46 static inline unsigned long do_clear_global_summary(void)
48 register unsigned long __fn
asm("1") = 3;
49 register unsigned long __tmp
asm("2");
50 register unsigned long __time
asm("3");
53 " .insn rre,0xb2650000,2,0"
54 : "+d" (__fn
), "=d" (__tmp
), "=d" (__time
));
58 /* returns addr for the device state change indicator */
59 static u32
*get_indicator(void)
63 for (i
= 0; i
< TIQDIO_NR_NONSHARED_IND
; i
++)
64 if (!atomic_read(&q_indicators
[i
].count
)) {
65 atomic_set(&q_indicators
[i
].count
, 1);
66 return &q_indicators
[i
].ind
;
69 /* use the shared indicator */
70 atomic_inc(&q_indicators
[TIQDIO_SHARED_IND
].count
);
71 return &q_indicators
[TIQDIO_SHARED_IND
].ind
;
74 static void put_indicator(u32
*addr
)
80 i
= ((unsigned long)addr
- (unsigned long)q_indicators
) /
81 sizeof(struct indicator_t
);
82 atomic_dec(&q_indicators
[i
].count
);
85 void tiqdio_add_input_queues(struct qdio_irq
*irq_ptr
)
90 /* No TDD facility? If we must use SIGA-s we can also omit SVS. */
91 if (!css_qdio_omit_svs
&& irq_ptr
->siga_flag
.sync
)
92 css_qdio_omit_svs
= 1;
94 mutex_lock(&tiq_list_lock
);
95 for_each_input_queue(irq_ptr
, q
, i
)
96 list_add_rcu(&q
->entry
, &tiq_list
);
97 mutex_unlock(&tiq_list_lock
);
98 xchg(irq_ptr
->dsci
, 1);
101 void tiqdio_remove_input_queues(struct qdio_irq
*irq_ptr
)
106 for (i
= 0; i
< irq_ptr
->nr_input_qs
; i
++) {
107 q
= irq_ptr
->input_qs
[i
];
108 /* if establish triggered an error */
109 if (!q
|| !q
->entry
.prev
|| !q
->entry
.next
)
112 mutex_lock(&tiq_list_lock
);
113 list_del_rcu(&q
->entry
);
114 mutex_unlock(&tiq_list_lock
);
119 static inline int shared_ind(struct qdio_irq
*irq_ptr
)
121 return irq_ptr
->dsci
== &q_indicators
[TIQDIO_SHARED_IND
].ind
;
125 * tiqdio_thinint_handler - thin interrupt handler for qdio
126 * @ind: pointer to adapter local summary indicator
129 static void tiqdio_thinint_handler(void *ind
, void *drv_data
)
134 * SVS only when needed: issue SVS to benefit from iqdio interrupt
135 * avoidance (SVS clears adapter interrupt suppression overwrite)
137 if (!css_qdio_omit_svs
)
138 do_clear_global_summary();
141 * reset local summary indicator (tiqdio_alsi) to stop adapter
146 /* protect tiq_list entries, only changed in activate or shutdown */
149 /* check for work on all inbound thinint queues */
150 list_for_each_entry_rcu(q
, &tiq_list
, entry
)
151 /* only process queues from changed sets */
152 if (*q
->irq_ptr
->dsci
) {
153 qperf_inc(q
, adapter_int
);
155 /* only clear it if the indicator is non-shared */
156 if (!shared_ind(q
->irq_ptr
))
157 xchg(q
->irq_ptr
->dsci
, 0);
159 * don't call inbound processing directly since
160 * that could starve other thinint queues
162 tasklet_schedule(&q
->tasklet
);
168 * if we used the shared indicator clear it now after all queues
171 if (atomic_read(&q_indicators
[TIQDIO_SHARED_IND
].count
)) {
172 xchg(&q_indicators
[TIQDIO_SHARED_IND
].ind
, 0);
176 xchg(&q_indicators
[TIQDIO_SHARED_IND
].ind
, 1);
180 static int set_subchannel_ind(struct qdio_irq
*irq_ptr
, int reset
)
182 struct scssc_area
*scssc_area
;
185 scssc_area
= (struct scssc_area
*)irq_ptr
->chsc_page
;
186 memset(scssc_area
, 0, PAGE_SIZE
);
189 scssc_area
->summary_indicator_addr
= 0;
190 scssc_area
->subchannel_indicator_addr
= 0;
192 scssc_area
->summary_indicator_addr
= virt_to_phys(tiqdio_alsi
);
193 scssc_area
->subchannel_indicator_addr
=
194 virt_to_phys(irq_ptr
->dsci
);
197 scssc_area
->request
= (struct chsc_header
) {
201 scssc_area
->operation_code
= 0;
202 scssc_area
->ks
= PAGE_DEFAULT_KEY
>> 4;
203 scssc_area
->kc
= PAGE_DEFAULT_KEY
>> 4;
204 scssc_area
->isc
= QDIO_AIRQ_ISC
;
205 scssc_area
->schid
= irq_ptr
->schid
;
207 /* enable the time delay disablement facility */
208 if (css_general_characteristics
.aif_tdd
)
209 scssc_area
->word_with_d_bit
= 0x10000000;
211 rc
= chsc(scssc_area
);
215 rc
= chsc_error_from_response(scssc_area
->response
.code
);
217 DBF_ERROR("%4x SSI r:%4x", irq_ptr
->schid
.sch_no
,
218 scssc_area
->response
.code
);
219 DBF_ERROR_HEX(&scssc_area
->response
, sizeof(void *));
223 DBF_EVENT("setscind");
224 DBF_HEX(&scssc_area
->summary_indicator_addr
, sizeof(unsigned long));
225 DBF_HEX(&scssc_area
->subchannel_indicator_addr
, sizeof(unsigned long));
229 /* allocate non-shared indicators and shared indicator */
230 int __init
tiqdio_allocate_memory(void)
232 q_indicators
= kzalloc(sizeof(struct indicator_t
) * TIQDIO_NR_INDICATORS
,
239 void tiqdio_free_memory(void)
244 int __init
tiqdio_register_thinints(void)
246 isc_register(QDIO_AIRQ_ISC
);
247 tiqdio_alsi
= s390_register_adapter_interrupt(&tiqdio_thinint_handler
,
248 NULL
, QDIO_AIRQ_ISC
);
249 if (IS_ERR(tiqdio_alsi
)) {
250 DBF_EVENT("RTI:%lx", PTR_ERR(tiqdio_alsi
));
252 isc_unregister(QDIO_AIRQ_ISC
);
258 int qdio_establish_thinint(struct qdio_irq
*irq_ptr
)
260 if (!is_thinint_irq(irq_ptr
))
263 /* Check for aif time delay disablement. If installed,
264 * omit SVS even under LPAR
266 if (css_general_characteristics
.aif_tdd
)
267 css_qdio_omit_svs
= 1;
268 return set_subchannel_ind(irq_ptr
, 0);
271 void qdio_setup_thinint(struct qdio_irq
*irq_ptr
)
273 if (!is_thinint_irq(irq_ptr
))
275 irq_ptr
->dsci
= get_indicator();
276 DBF_HEX(&irq_ptr
->dsci
, sizeof(void *));
279 void qdio_shutdown_thinint(struct qdio_irq
*irq_ptr
)
281 if (!is_thinint_irq(irq_ptr
))
284 /* reset adapter interrupt indicators */
285 put_indicator(irq_ptr
->dsci
);
286 set_subchannel_ind(irq_ptr
, 1);
289 void __exit
tiqdio_unregister_thinints(void)
291 WARN_ON(!list_empty(&tiq_list
));
294 s390_unregister_adapter_interrupt(tiqdio_alsi
, QDIO_AIRQ_ISC
);
295 isc_unregister(QDIO_AIRQ_ISC
);