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 <asm/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 /* list of thin interrupt input queues */
30 static LIST_HEAD(tiq_list
);
31 DEFINE_MUTEX(tiq_list_lock
);
33 /* adapter local summary indicator */
34 static unsigned char *tiqdio_alsi
;
36 /* device state change indicators */
38 u32 ind
; /* u32 because of compare-and-swap performance */
39 atomic_t count
; /* use count, 0 or 1 for non-shared indicators */
41 static struct indicator_t
*q_indicators
;
43 static int css_qdio_omit_svs
;
45 static inline unsigned long do_clear_global_summary(void)
47 register unsigned long __fn
asm("1") = 3;
48 register unsigned long __tmp
asm("2");
49 register unsigned long __time
asm("3");
52 " .insn rre,0xb2650000,2,0"
53 : "+d" (__fn
), "=d" (__tmp
), "=d" (__time
));
57 /* returns addr for the device state change indicator */
58 static u32
*get_indicator(void)
62 for (i
= 0; i
< TIQDIO_NR_NONSHARED_IND
; i
++)
63 if (!atomic_read(&q_indicators
[i
].count
)) {
64 atomic_set(&q_indicators
[i
].count
, 1);
65 return &q_indicators
[i
].ind
;
68 /* use the shared indicator */
69 atomic_inc(&q_indicators
[TIQDIO_SHARED_IND
].count
);
70 return &q_indicators
[TIQDIO_SHARED_IND
].ind
;
73 static void put_indicator(u32
*addr
)
79 i
= ((unsigned long)addr
- (unsigned long)q_indicators
) /
80 sizeof(struct indicator_t
);
81 atomic_dec(&q_indicators
[i
].count
);
84 void tiqdio_add_input_queues(struct qdio_irq
*irq_ptr
)
89 /* No TDD facility? If we must use SIGA-s we can also omit SVS. */
90 if (!css_qdio_omit_svs
&& irq_ptr
->siga_flag
.sync
)
91 css_qdio_omit_svs
= 1;
93 mutex_lock(&tiq_list_lock
);
94 for_each_input_queue(irq_ptr
, q
, i
)
95 list_add_rcu(&q
->entry
, &tiq_list
);
96 mutex_unlock(&tiq_list_lock
);
97 xchg(irq_ptr
->dsci
, 1);
100 void tiqdio_remove_input_queues(struct qdio_irq
*irq_ptr
)
105 for (i
= 0; i
< irq_ptr
->nr_input_qs
; i
++) {
106 q
= irq_ptr
->input_qs
[i
];
107 /* if establish triggered an error */
108 if (!q
|| !q
->entry
.prev
|| !q
->entry
.next
)
111 mutex_lock(&tiq_list_lock
);
112 list_del_rcu(&q
->entry
);
113 mutex_unlock(&tiq_list_lock
);
118 static inline int shared_ind(struct qdio_irq
*irq_ptr
)
120 return irq_ptr
->dsci
== &q_indicators
[TIQDIO_SHARED_IND
].ind
;
124 * tiqdio_thinint_handler - thin interrupt handler for qdio
125 * @ind: pointer to adapter local summary indicator
128 static void tiqdio_thinint_handler(void *ind
, void *drv_data
)
133 * SVS only when needed: issue SVS to benefit from iqdio interrupt
134 * avoidance (SVS clears adapter interrupt suppression overwrite)
136 if (!css_qdio_omit_svs
)
137 do_clear_global_summary();
140 * reset local summary indicator (tiqdio_alsi) to stop adapter
145 /* protect tiq_list entries, only changed in activate or shutdown */
148 /* check for work on all inbound thinint queues */
149 list_for_each_entry_rcu(q
, &tiq_list
, entry
)
150 /* only process queues from changed sets */
151 if (*q
->irq_ptr
->dsci
) {
152 qperf_inc(q
, adapter_int
);
154 /* only clear it if the indicator is non-shared */
155 if (!shared_ind(q
->irq_ptr
))
156 xchg(q
->irq_ptr
->dsci
, 0);
158 * don't call inbound processing directly since
159 * that could starve other thinint queues
161 tasklet_schedule(&q
->tasklet
);
167 * if we used the shared indicator clear it now after all queues
170 if (atomic_read(&q_indicators
[TIQDIO_SHARED_IND
].count
)) {
171 xchg(&q_indicators
[TIQDIO_SHARED_IND
].ind
, 0);
175 xchg(&q_indicators
[TIQDIO_SHARED_IND
].ind
, 1);
179 static int set_subchannel_ind(struct qdio_irq
*irq_ptr
, int reset
)
181 struct scssc_area
*scssc_area
;
184 scssc_area
= (struct scssc_area
*)irq_ptr
->chsc_page
;
185 memset(scssc_area
, 0, PAGE_SIZE
);
188 scssc_area
->summary_indicator_addr
= 0;
189 scssc_area
->subchannel_indicator_addr
= 0;
191 scssc_area
->summary_indicator_addr
= virt_to_phys(tiqdio_alsi
);
192 scssc_area
->subchannel_indicator_addr
=
193 virt_to_phys(irq_ptr
->dsci
);
196 scssc_area
->request
= (struct chsc_header
) {
200 scssc_area
->operation_code
= 0;
201 scssc_area
->ks
= PAGE_DEFAULT_KEY
>> 4;
202 scssc_area
->kc
= PAGE_DEFAULT_KEY
>> 4;
203 scssc_area
->isc
= QDIO_AIRQ_ISC
;
204 scssc_area
->schid
= irq_ptr
->schid
;
206 /* enable the time delay disablement facility */
207 if (css_general_characteristics
.aif_tdd
)
208 scssc_area
->word_with_d_bit
= 0x10000000;
210 rc
= chsc(scssc_area
);
214 rc
= chsc_error_from_response(scssc_area
->response
.code
);
216 DBF_ERROR("%4x SSI r:%4x", irq_ptr
->schid
.sch_no
,
217 scssc_area
->response
.code
);
218 DBF_ERROR_HEX(&scssc_area
->response
, sizeof(void *));
222 DBF_EVENT("setscind");
223 DBF_HEX(&scssc_area
->summary_indicator_addr
, sizeof(unsigned long));
224 DBF_HEX(&scssc_area
->subchannel_indicator_addr
, sizeof(unsigned long));
228 /* allocate non-shared indicators and shared indicator */
229 int __init
tiqdio_allocate_memory(void)
231 q_indicators
= kzalloc(sizeof(struct indicator_t
) * TIQDIO_NR_INDICATORS
,
238 void tiqdio_free_memory(void)
243 int __init
tiqdio_register_thinints(void)
245 isc_register(QDIO_AIRQ_ISC
);
246 tiqdio_alsi
= s390_register_adapter_interrupt(&tiqdio_thinint_handler
,
247 NULL
, QDIO_AIRQ_ISC
);
248 if (IS_ERR(tiqdio_alsi
)) {
249 DBF_EVENT("RTI:%lx", PTR_ERR(tiqdio_alsi
));
251 isc_unregister(QDIO_AIRQ_ISC
);
257 int qdio_establish_thinint(struct qdio_irq
*irq_ptr
)
259 if (!is_thinint_irq(irq_ptr
))
262 /* Check for aif time delay disablement. If installed,
263 * omit SVS even under LPAR
265 if (css_general_characteristics
.aif_tdd
)
266 css_qdio_omit_svs
= 1;
267 return set_subchannel_ind(irq_ptr
, 0);
270 void qdio_setup_thinint(struct qdio_irq
*irq_ptr
)
272 if (!is_thinint_irq(irq_ptr
))
274 irq_ptr
->dsci
= get_indicator();
275 DBF_HEX(&irq_ptr
->dsci
, sizeof(void *));
278 void qdio_shutdown_thinint(struct qdio_irq
*irq_ptr
)
280 if (!is_thinint_irq(irq_ptr
))
283 /* reset adapter interrupt indicators */
284 put_indicator(irq_ptr
->dsci
);
285 set_subchannel_ind(irq_ptr
, 1);
288 void __exit
tiqdio_unregister_thinints(void)
290 WARN_ON(!list_empty(&tiq_list
));
293 s390_unregister_adapter_interrupt(tiqdio_alsi
, QDIO_AIRQ_ISC
);
294 isc_unregister(QDIO_AIRQ_ISC
);