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 int css_qdio_omit_svs
;
48 static inline unsigned long do_clear_global_summary(void)
50 register unsigned long __fn
asm("1") = 3;
51 register unsigned long __tmp
asm("2");
52 register unsigned long __time
asm("3");
55 " .insn rre,0xb2650000,2,0"
56 : "+d" (__fn
), "=d" (__tmp
), "=d" (__time
));
60 /* returns addr for the device state change indicator */
61 static u32
*get_indicator(void)
65 for (i
= 0; i
< TIQDIO_NR_NONSHARED_IND
; i
++)
66 if (!atomic_read(&q_indicators
[i
].count
)) {
67 atomic_set(&q_indicators
[i
].count
, 1);
68 return &q_indicators
[i
].ind
;
71 /* use the shared indicator */
72 atomic_inc(&q_indicators
[TIQDIO_SHARED_IND
].count
);
73 return &q_indicators
[TIQDIO_SHARED_IND
].ind
;
76 static void put_indicator(u32
*addr
)
82 i
= ((unsigned long)addr
- (unsigned long)q_indicators
) /
83 sizeof(struct indicator_t
);
84 atomic_dec(&q_indicators
[i
].count
);
87 void tiqdio_add_input_queues(struct qdio_irq
*irq_ptr
)
92 /* No TDD facility? If we must use SIGA-s we can also omit SVS. */
93 if (!css_qdio_omit_svs
&& irq_ptr
->siga_flag
.sync
)
94 css_qdio_omit_svs
= 1;
96 mutex_lock(&tiq_list_lock
);
97 for_each_input_queue(irq_ptr
, q
, i
)
98 list_add_rcu(&q
->entry
, &tiq_list
);
99 mutex_unlock(&tiq_list_lock
);
100 xchg(irq_ptr
->dsci
, 1);
103 void tiqdio_remove_input_queues(struct qdio_irq
*irq_ptr
)
108 for (i
= 0; i
< irq_ptr
->nr_input_qs
; i
++) {
109 q
= irq_ptr
->input_qs
[i
];
110 /* if establish triggered an error */
111 if (!q
|| !q
->entry
.prev
|| !q
->entry
.next
)
114 mutex_lock(&tiq_list_lock
);
115 list_del_rcu(&q
->entry
);
116 mutex_unlock(&tiq_list_lock
);
121 static inline int shared_ind(struct qdio_irq
*irq_ptr
)
123 return irq_ptr
->dsci
== &q_indicators
[TIQDIO_SHARED_IND
].ind
;
127 * tiqdio_thinint_handler - thin interrupt handler for qdio
128 * @ind: pointer to adapter local summary indicator
131 static void tiqdio_thinint_handler(void *ind
, void *drv_data
)
135 qdio_perf_stat_inc(&perf_stats
.thin_int
);
138 * SVS only when needed: issue SVS to benefit from iqdio interrupt
139 * avoidance (SVS clears adapter interrupt suppression overwrite)
141 if (!css_qdio_omit_svs
)
142 do_clear_global_summary();
145 * reset local summary indicator (tiqdio_alsi) to stop adapter
150 /* protect tiq_list entries, only changed in activate or shutdown */
153 /* check for work on all inbound thinint queues */
154 list_for_each_entry_rcu(q
, &tiq_list
, entry
)
155 /* only process queues from changed sets */
156 if (*q
->irq_ptr
->dsci
) {
158 /* only clear it if the indicator is non-shared */
159 if (!shared_ind(q
->irq_ptr
))
160 xchg(q
->irq_ptr
->dsci
, 0);
162 * don't call inbound processing directly since
163 * that could starve other thinint queues
165 tasklet_schedule(&q
->tasklet
);
171 * if we used the shared indicator clear it now after all queues
174 if (atomic_read(&q_indicators
[TIQDIO_SHARED_IND
].count
)) {
175 xchg(&q_indicators
[TIQDIO_SHARED_IND
].ind
, 0);
179 xchg(&q_indicators
[TIQDIO_SHARED_IND
].ind
, 1);
183 static int set_subchannel_ind(struct qdio_irq
*irq_ptr
, int reset
)
185 struct scssc_area
*scssc_area
;
188 scssc_area
= (struct scssc_area
*)irq_ptr
->chsc_page
;
189 memset(scssc_area
, 0, PAGE_SIZE
);
192 scssc_area
->summary_indicator_addr
= 0;
193 scssc_area
->subchannel_indicator_addr
= 0;
195 scssc_area
->summary_indicator_addr
= virt_to_phys(tiqdio_alsi
);
196 scssc_area
->subchannel_indicator_addr
=
197 virt_to_phys(irq_ptr
->dsci
);
200 scssc_area
->request
= (struct chsc_header
) {
204 scssc_area
->operation_code
= 0;
205 scssc_area
->ks
= PAGE_DEFAULT_KEY
;
206 scssc_area
->kc
= PAGE_DEFAULT_KEY
;
207 scssc_area
->isc
= QDIO_AIRQ_ISC
;
208 scssc_area
->schid
= irq_ptr
->schid
;
210 /* enable the time delay disablement facility */
211 if (css_general_characteristics
.aif_tdd
)
212 scssc_area
->word_with_d_bit
= 0x10000000;
214 rc
= chsc(scssc_area
);
218 rc
= chsc_error_from_response(scssc_area
->response
.code
);
220 DBF_ERROR("%4x SSI r:%4x", irq_ptr
->schid
.sch_no
,
221 scssc_area
->response
.code
);
222 DBF_ERROR_HEX(&scssc_area
->response
, sizeof(void *));
226 DBF_EVENT("setscind");
227 DBF_HEX(&scssc_area
->summary_indicator_addr
, sizeof(unsigned long));
228 DBF_HEX(&scssc_area
->subchannel_indicator_addr
, sizeof(unsigned long));
232 /* allocate non-shared indicators and shared indicator */
233 int __init
tiqdio_allocate_memory(void)
235 q_indicators
= kzalloc(sizeof(struct indicator_t
) * TIQDIO_NR_INDICATORS
,
242 void tiqdio_free_memory(void)
247 int __init
tiqdio_register_thinints(void)
249 isc_register(QDIO_AIRQ_ISC
);
250 tiqdio_alsi
= s390_register_adapter_interrupt(&tiqdio_thinint_handler
,
251 NULL
, QDIO_AIRQ_ISC
);
252 if (IS_ERR(tiqdio_alsi
)) {
253 DBF_EVENT("RTI:%lx", PTR_ERR(tiqdio_alsi
));
255 isc_unregister(QDIO_AIRQ_ISC
);
261 int qdio_establish_thinint(struct qdio_irq
*irq_ptr
)
263 if (!is_thinint_irq(irq_ptr
))
266 /* Check for aif time delay disablement. If installed,
267 * omit SVS even under LPAR
269 if (css_general_characteristics
.aif_tdd
)
270 css_qdio_omit_svs
= 1;
271 return set_subchannel_ind(irq_ptr
, 0);
274 void qdio_setup_thinint(struct qdio_irq
*irq_ptr
)
276 if (!is_thinint_irq(irq_ptr
))
278 irq_ptr
->dsci
= get_indicator();
279 DBF_HEX(&irq_ptr
->dsci
, sizeof(void *));
282 void qdio_shutdown_thinint(struct qdio_irq
*irq_ptr
)
284 if (!is_thinint_irq(irq_ptr
))
287 /* reset adapter interrupt indicators */
288 put_indicator(irq_ptr
->dsci
);
289 set_subchannel_ind(irq_ptr
, 1);
292 void __exit
tiqdio_unregister_thinints(void)
294 WARN_ON(!list_empty(&tiq_list
));
297 s390_unregister_adapter_interrupt(tiqdio_alsi
, QDIO_AIRQ_ISC
);
298 isc_unregister(QDIO_AIRQ_ISC
);